dependency-tree 11.1.1 → 11.3.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/index.js +24 -0
- package/package.json +8 -8
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');
|
|
@@ -162,6 +163,7 @@ function traverse(config = {}) {
|
|
|
162
163
|
for (const dependency of dependencies) {
|
|
163
164
|
const localConfig = config.clone();
|
|
164
165
|
localConfig.filename = dependency;
|
|
166
|
+
localConfig.directory = getDirectory(localConfig);
|
|
165
167
|
|
|
166
168
|
if (localConfig.isListForm) {
|
|
167
169
|
for (const item of traverse(localConfig)) {
|
|
@@ -193,3 +195,25 @@ function dedupeNonExistent(nonExistent) {
|
|
|
193
195
|
i++;
|
|
194
196
|
}
|
|
195
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-tree",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.3.0",
|
|
4
4
|
"description": "Get the dependency tree of a module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"commander": "^12.1.0",
|
|
53
|
-
"filing-cabinet": "^5.0
|
|
53
|
+
"filing-cabinet": "^5.1.0",
|
|
54
54
|
"precinct": "^12.2.0",
|
|
55
|
-
"typescript": "^5.
|
|
55
|
+
"typescript": "^5.9.3"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"c8": "^10.1.3",
|
|
59
|
-
"debug": "^4.4.
|
|
60
|
-
"mocha": "^11.
|
|
61
|
-
"mock-fs": "^5.
|
|
62
|
-
"resolve": "^1.22.
|
|
63
|
-
"sinon": "^19.0.
|
|
59
|
+
"debug": "^4.4.3",
|
|
60
|
+
"mocha": "^11.7.5",
|
|
61
|
+
"mock-fs": "^5.5.0",
|
|
62
|
+
"resolve": "^1.22.11",
|
|
63
|
+
"sinon": "^19.0.5",
|
|
64
64
|
"xo": "^0.60.0"
|
|
65
65
|
},
|
|
66
66
|
"xo": {
|