Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tsConfig): path mapping by filing-cabinet #138

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const list = dependencyTree.toList({
* `requireConfig`: path to a requirejs config for AMD modules (allows for the result of aliased module paths)
* `webpackConfig`: path to a webpack config for aliased modules
* `tsConfig`: path to a typescript config (or a preloaded object representing the typescript config)
* `tsConfigPath`: a (virtual) path to typescript config file when `tsConfig` option is given as an object, not a string. Needed to calculate [Path Mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping). If not given when `tsConfig` is an object, **Path Mapping** is ignored. This is not needed when `tsConfig` is given as a path string.
* `nodeModulesConfig`: config for resolving entry file for node_modules
* `visited`: object used for avoiding redundant subtree generations via memoization.
* `nonExistent`: array used for storing the list of partial paths that do not exist
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ module.exports._getDependencies = function(config = {}) {
webpackConfig: config.webpackConfig,
nodeModulesConfig: config.nodeModulesConfig,
tsConfig: config.tsConfig,
tsConfigPath: config.tsConfigPath,
noTypeDefinitions: config.noTypeDefinitions
});

Expand Down
3 changes: 2 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = class Config {
this.nodeModulesConfig = options.nodeModulesConfig;
this.detectiveConfig = options.detective || options.detectiveConfig || {};
this.tsConfig = options.tsConfig;
this.tsConfigPath = options.tsConfigPath;
this.noTypeDefinitions = options.noTypeDefinitions;

this.filter = options.filter;

if (!this.filename) throw new Error('filename not given');
Expand All @@ -31,6 +31,7 @@ module.exports = class Config {
const ts = require('typescript');
const tsParsedConfig = ts.readJsonConfigFile(this.tsConfig, ts.sys.readFile);
const obj = ts.parseJsonSourceFileConfigFileContent(tsParsedConfig, ts.sys, path.dirname(this.tsConfig));
this.tsConfigPath ||= this.tsConfig;
this.tsConfig = obj.raw;
}

Expand Down