dependency-tree 11.1.0 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/index.js +25 -0
- package/lib/config.js +2 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ const list = dependencyTree.toList({
|
|
|
50
50
|
* `requireConfig`: path to a requirejs config for AMD modules (allows for the result of aliased module paths)
|
|
51
51
|
* `webpackConfig`: path to a webpack config for aliased modules
|
|
52
52
|
* `tsConfig`: path to a typescript config (or a preloaded object representing the typescript config)
|
|
53
|
+
* `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.
|
|
53
54
|
* `nodeModulesConfig`: config for resolving entry file for node_modules
|
|
54
55
|
* `visited`: object used for avoiding redundant subtree generations via memoization.
|
|
55
56
|
* `nonExistent`: array used for storing the list of partial paths that do not exist
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
4
5
|
const { debuglog } = require('node:util');
|
|
5
6
|
const cabinet = require('filing-cabinet');
|
|
6
7
|
const precinct = require('precinct');
|
|
@@ -106,6 +107,7 @@ module.exports._getDependencies = function(config = {}) {
|
|
|
106
107
|
webpackConfig: config.webpackConfig,
|
|
107
108
|
nodeModulesConfig: config.nodeModulesConfig,
|
|
108
109
|
tsConfig: config.tsConfig,
|
|
110
|
+
tsConfigPath: config.tsConfigPath,
|
|
109
111
|
noTypeDefinitions: config.noTypeDefinitions
|
|
110
112
|
});
|
|
111
113
|
|
|
@@ -161,6 +163,7 @@ function traverse(config = {}) {
|
|
|
161
163
|
for (const dependency of dependencies) {
|
|
162
164
|
const localConfig = config.clone();
|
|
163
165
|
localConfig.filename = dependency;
|
|
166
|
+
localConfig.directory = getDirectory(localConfig);
|
|
164
167
|
|
|
165
168
|
if (localConfig.isListForm) {
|
|
166
169
|
for (const item of traverse(localConfig)) {
|
|
@@ -192,3 +195,25 @@ function dedupeNonExistent(nonExistent) {
|
|
|
192
195
|
i++;
|
|
193
196
|
}
|
|
194
197
|
}
|
|
198
|
+
|
|
199
|
+
// If the file is in a node module, use the root directory of the module
|
|
200
|
+
function getDirectory(localConfig) {
|
|
201
|
+
if (!localConfig.filename.includes('node_modules')) {
|
|
202
|
+
return localConfig.directory;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return getProjectPath(path.dirname(localConfig.filename)) || localConfig.directory;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function getProjectPath(filename) {
|
|
209
|
+
try {
|
|
210
|
+
const nodeModuleParts = filename.split('node_modules');
|
|
211
|
+
const packageSubPathPath = nodeModuleParts.pop().split(path.sep).filter(Boolean);
|
|
212
|
+
const packageName = packageSubPathPath[0].startsWith('@') ? `${packageSubPathPath[0]}${path.sep}${packageSubPathPath[1]}` : packageSubPathPath[0];
|
|
213
|
+
|
|
214
|
+
return path.normalize([...nodeModuleParts, `${path.sep}${packageName}`].join('node_modules'));
|
|
215
|
+
} catch {
|
|
216
|
+
debug(`Could not determine the root directory of package file ${filename}. Using default`);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
}
|
package/lib/config.js
CHANGED
|
@@ -18,8 +18,8 @@ module.exports = class Config {
|
|
|
18
18
|
this.nodeModulesConfig = options.nodeModulesConfig;
|
|
19
19
|
this.detectiveConfig = options.detective || options.detectiveConfig || {};
|
|
20
20
|
this.tsConfig = options.tsConfig;
|
|
21
|
+
this.tsConfigPath = options.tsConfigPath;
|
|
21
22
|
this.noTypeDefinitions = options.noTypeDefinitions;
|
|
22
|
-
|
|
23
23
|
this.filter = options.filter;
|
|
24
24
|
|
|
25
25
|
if (!this.filename) throw new Error('filename not given');
|
|
@@ -31,6 +31,7 @@ module.exports = class Config {
|
|
|
31
31
|
const ts = require('typescript');
|
|
32
32
|
const tsParsedConfig = ts.readJsonConfigFile(this.tsConfig, ts.sys.readFile);
|
|
33
33
|
const obj = ts.parseJsonSourceFileConfigFileContent(tsParsedConfig, ts.sys, path.dirname(this.tsConfig));
|
|
34
|
+
this.tsConfigPath ||= this.tsConfig;
|
|
34
35
|
this.tsConfig = obj.raw;
|
|
35
36
|
}
|
|
36
37
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-tree",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.2.0",
|
|
4
4
|
"description": "Get the dependency tree of a module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -52,15 +52,15 @@
|
|
|
52
52
|
"commander": "^12.1.0",
|
|
53
53
|
"filing-cabinet": "^5.0.3",
|
|
54
54
|
"precinct": "^12.2.0",
|
|
55
|
-
"typescript": "^5.
|
|
55
|
+
"typescript": "^5.8.3"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"c8": "^10.1.3",
|
|
59
|
-
"debug": "^4.4.
|
|
60
|
-
"mocha": "^11.
|
|
61
|
-
"mock-fs": "^5.
|
|
59
|
+
"debug": "^4.4.1",
|
|
60
|
+
"mocha": "^11.7.0",
|
|
61
|
+
"mock-fs": "^5.5.0",
|
|
62
62
|
"resolve": "^1.22.10",
|
|
63
|
-
"sinon": "^19.0.
|
|
63
|
+
"sinon": "^19.0.5",
|
|
64
64
|
"xo": "^0.60.0"
|
|
65
65
|
},
|
|
66
66
|
"xo": {
|