Skip to content

Commit 5c46357

Browse files
jjangga0214mrjoelkemp
authored andcommitted
fix(tsConfig): path mapping by filing-cabinet
A PR pending in filingc-cabinet should be merged and published before this to be merged. REF: dependents/node-filing-cabinet#100
1 parent c5b726c commit 5c46357

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var list = dependencyTree.toList({
4444
* `requireConfig`: path to a requirejs config for AMD modules (allows for the result of aliased module paths)
4545
* `webpackConfig`: path to a webpack config for aliased modules
4646
* `tsConfig`: path to a typescript config (or a preloaded object representing the typescript config)
47+
* `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.
4748
* `nodeModulesConfig`: config for resolving entry file for node_modules
4849
* `visited`: object used for avoiding redundant subtree generations via memoization.
4950
* `nonExistent`: array used for storing the list of partial paths that do not exist

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const Config = require('./lib/Config');
2525
* @param {Boolean} [options.noTypeDefinitions] For TypeScript imports, whether to resolve to `*.js` instead of `*.d.ts`.
2626
* @return {Object}
2727
*/
28-
module.exports = function(options) {
28+
module.exports = function (options) {
2929
const config = new Config(options);
3030

3131
if (!fs.existsSync(config.filename)) {
@@ -67,7 +67,7 @@ module.exports = function(options) {
6767
*
6868
* Params are those of module.exports
6969
*/
70-
module.exports.toList = function(options) {
70+
module.exports.toList = function (options) {
7171
options.isListForm = true;
7272

7373
return module.exports(options);
@@ -81,7 +81,7 @@ module.exports.toList = function(options) {
8181
* @param {Config} config
8282
* @return {Array}
8383
*/
84-
module.exports._getDependencies = function(config) {
84+
module.exports._getDependencies = function (config) {
8585
let dependencies;
8686
const precinctOptions = config.detectiveConfig;
8787
precinctOptions.includeCore = false;
@@ -111,6 +111,7 @@ module.exports._getDependencies = function(config) {
111111
webpackConfig: config.webpackConfig,
112112
nodeModulesConfig: config.nodeModulesConfig,
113113
tsConfig: config.tsConfig,
114+
tsConfigPath: config.tsConfigPath,
114115
noTypeDefinitions: config.noTypeDefinitions
115116
});
116117

@@ -158,7 +159,7 @@ function traverse(config) {
158159
if (config.filter) {
159160
debug('using filter function to filter out dependencies');
160161
debug('unfiltered number of dependencies: ' + dependencies.length);
161-
dependencies = dependencies.filter(function(filePath) {
162+
dependencies = dependencies.filter(function (filePath) {
162163
return config.filter(filePath, config.filename);
163164
});
164165
debug('filtered number of dependencies: ' + dependencies.length);

lib/Config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ class Config {
2323
if (!this.directory) { throw new Error('directory not given'); }
2424
if (this.filter && typeof this.filter !== 'function') { throw new Error('filter must be a function'); }
2525

26+
this.tsConfigPath = options.tsConfigPath
2627
if ('string' === typeof this.tsConfig) {
2728
debug('preparsing the ts config into an object for performance');
2829
const ts = require('typescript');
2930
const tsParsedConfig = ts.readJsonConfigFile(this.tsConfig, ts.sys.readFile);
3031
const obj = ts.parseJsonSourceFileConfigFileContent(tsParsedConfig, ts.sys, path.dirname(this.tsConfig));
32+
this.tsConfigPath = this.tsConfigPath || this.tsConfig
3133
this.tsConfig = obj.raw;
3234
}
3335

@@ -39,7 +41,7 @@ class Config {
3941
debug('visited: ', this.visited);
4042
}
4143

42-
clone () {
44+
clone() {
4345
return new Config(this);
4446
}
4547
}

0 commit comments

Comments
 (0)