From a9fab89725eb6fa9ab30ee581083fd97f1aea10b Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Mon, 16 Aug 2021 13:22:35 +0900 Subject: [PATCH 1/9] fix(tsConfig): path mapping by filing-cabinet A PR pending in filingc-cabinet should be merged and published before this to be merged. REF: https://github.com/dependents/node-filing-cabinet/pull/100 --- README.md | 1 + index.js | 1 + lib/config.js | 2 ++ 3 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 933dc3f..4910f86 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/index.js b/index.js index 5522395..0fda51d 100644 --- a/index.js +++ b/index.js @@ -106,6 +106,7 @@ module.exports._getDependencies = function(config = {}) { webpackConfig: config.webpackConfig, nodeModulesConfig: config.nodeModulesConfig, tsConfig: config.tsConfig, + tsConfigPath: config.tsConfigPath, noTypeDefinitions: config.noTypeDefinitions }); diff --git a/lib/config.js b/lib/config.js index 7c8b6c3..f9a1a66 100644 --- a/lib/config.js +++ b/lib/config.js @@ -18,6 +18,7 @@ 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; @@ -31,6 +32,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.tsConfigPath || this.tsConfig this.tsConfig = obj.raw; } From 99d9916ee7a32a6f2e6e702d85fd43edf0341033 Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Mon, 30 May 2022 12:25:32 +0900 Subject: [PATCH 2/9] refactor: revert style --- lib/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index f9a1a66..7ffac8b 100644 --- a/lib/config.js +++ b/lib/config.js @@ -44,7 +44,7 @@ module.exports = class Config { debug('visited: ', this.visited); } - clone() { + clone () { return new Config(this); } }; From e4216f4a43cb51d0e02d2d74c138ab58c1285cbb Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Wed, 20 Jul 2022 12:49:31 +0900 Subject: [PATCH 3/9] build(deps): upgrade node-filing-cabinet --- package-lock.json | 23 +++++++++++++++++++---- package.json | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5b32fc1..285e58b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10061,7 +10061,7 @@ "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.1", "once": "^1.3.0", "path-is-absolute": "^1.0.0" }, @@ -10767,6 +10767,12 @@ "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==" }, + "JSV": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/JSV/-/JSV-4.0.2.tgz", + "integrity": "sha1-0Hf2glVx+CEy+d/67Vh7QCn+/1c=", + "dev": true + }, "just-extend": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", @@ -10828,9 +10834,9 @@ } }, "lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true }, "lodash-es": { @@ -12096,6 +12102,15 @@ "integrity": "sha512-XkD+zwiqXHikFZm4AX/7JSCXA98U5Db4AFd5XUg/+9UNtnH75+Z9KxtpYiJZx36mUDVOwH83pl7yvCer6ewM3w==", "dev": true }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, "string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", diff --git a/package.json b/package.json index a20250a..b548398 100644 --- a/package.json +++ b/package.json @@ -98,4 +98,4 @@ "unicorn/prevent-abbreviations": "off" } } -} +} \ No newline at end of file From a703003cbe52d3f96ffecbafb0881ec727a4eea9 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 7 May 2023 14:21:45 +0300 Subject: [PATCH 4/9] Update Config.js --- lib/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index 7ffac8b..11a387d 100644 --- a/lib/config.js +++ b/lib/config.js @@ -18,9 +18,9 @@ module.exports = class Config { this.nodeModulesConfig = options.nodeModulesConfig; this.detectiveConfig = options.detective || options.detectiveConfig || {}; this.tsConfig = options.tsConfig; + this.tsConfigPath = options.tsConfigPath; this.tsConfigPath = options.tsConfigPath this.noTypeDefinitions = options.noTypeDefinitions; - this.filter = options.filter; if (!this.filename) throw new Error('filename not given'); From 48fd753a48afe15ac3c6486ad05cddaac4b5f702 Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Sat, 27 May 2023 17:14:32 +0900 Subject: [PATCH 5/9] style: fix config.js --- lib/config.js | 6 +++--- package-lock.json | 23 ++++------------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/lib/config.js b/lib/config.js index 11a387d..da1a5bb 100644 --- a/lib/config.js +++ b/lib/config.js @@ -19,7 +19,7 @@ module.exports = class Config { this.detectiveConfig = options.detective || options.detectiveConfig || {}; this.tsConfig = options.tsConfig; this.tsConfigPath = options.tsConfigPath; - this.tsConfigPath = options.tsConfigPath + this.tsConfigPath = options.tsConfigPath; this.noTypeDefinitions = options.noTypeDefinitions; this.filter = options.filter; @@ -32,7 +32,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.tsConfigPath || this.tsConfig + this.tsConfigPath = this.tsConfigPath || this.tsConfig; this.tsConfig = obj.raw; } @@ -44,7 +44,7 @@ module.exports = class Config { debug('visited: ', this.visited); } - clone () { + clone() { return new Config(this); } }; diff --git a/package-lock.json b/package-lock.json index 285e58b..5b32fc1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10061,7 +10061,7 @@ "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", - "minimatch": "^3.1.1", + "minimatch": "^3.0.4", "once": "^1.3.0", "path-is-absolute": "^1.0.0" }, @@ -10767,12 +10767,6 @@ "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==" }, - "JSV": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/JSV/-/JSV-4.0.2.tgz", - "integrity": "sha1-0Hf2glVx+CEy+d/67Vh7QCn+/1c=", - "dev": true - }, "just-extend": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", @@ -10834,9 +10828,9 @@ } }, "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, "lodash-es": { @@ -12102,15 +12096,6 @@ "integrity": "sha512-XkD+zwiqXHikFZm4AX/7JSCXA98U5Db4AFd5XUg/+9UNtnH75+Z9KxtpYiJZx36mUDVOwH83pl7yvCer6ewM3w==", "dev": true }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - }, "string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", From 9abebef06104ae187b7ae5915c3fa3bfcd80dcd5 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 27 May 2023 14:14:16 +0300 Subject: [PATCH 6/9] Update config.js --- lib/config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index da1a5bb..71eecf8 100644 --- a/lib/config.js +++ b/lib/config.js @@ -19,7 +19,6 @@ module.exports = class Config { this.detectiveConfig = options.detective || options.detectiveConfig || {}; this.tsConfig = options.tsConfig; this.tsConfigPath = options.tsConfigPath; - this.tsConfigPath = options.tsConfigPath; this.noTypeDefinitions = options.noTypeDefinitions; this.filter = options.filter; From bd2fc83c0d4b2368c5d751952f509115e3e34c39 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 27 May 2023 14:14:29 +0300 Subject: [PATCH 7/9] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b548398..a20250a 100644 --- a/package.json +++ b/package.json @@ -98,4 +98,4 @@ "unicorn/prevent-abbreviations": "off" } } -} \ No newline at end of file +} From ffa769a471d55852c3415ebef9d7e7327c30e5d3 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 24 Apr 2024 18:22:40 +0300 Subject: [PATCH 8/9] fix logical-assignment-operators error --- lib/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index 71eecf8..b0ba90a 100644 --- a/lib/config.js +++ b/lib/config.js @@ -31,7 +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.tsConfigPath || this.tsConfig; + this.tsConfigPath ||= this.tsConfig; this.tsConfig = obj.raw; } From 19b99c7b60a27da5943aa764207602e9af4a1da2 Mon Sep 17 00:00:00 2001 From: Craig Spaeth Date: Wed, 31 Jul 2024 15:35:19 -0400 Subject: [PATCH 9/9] Add test to 138 --- test/test.mjs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test.mjs b/test/test.mjs index c2c0b09..aa705d8 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -964,6 +964,18 @@ describe('dependencyTree', () => { assert.equal(typeof config.tsConfig, 'object'); }); + + it('includes the tsConfigPath so filing-cabinet can still resolve compilerOptions.paths correctly', () => { + const directory = path.join(__dirname, 'fixtures/ts'); + const tsConfigPath = path.join(directory, '.tsconfig'); + const config = new Config({ + filename: 'foo', + directory: 'bar', + tsConfig: tsConfigPath + }); + + assert.equal(config.tsConfigPath, tsConfigPath); + }); }); describe('when cloning', () => {