dependency-tree 12.0.0 → 12.0.1
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 +48 -18
- package/package.json +6 -9
package/index.js
CHANGED
|
@@ -21,7 +21,7 @@ function dependencyTree(options = {}) {
|
|
|
21
21
|
return config.isListForm ? [] : {};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const results = traverse(config);
|
|
24
|
+
const results = config.isListForm ? traverseList(config) : traverse(config);
|
|
25
25
|
debug('traversal complete', results);
|
|
26
26
|
|
|
27
27
|
dedupeNonExistent(config.nonExistent);
|
|
@@ -30,7 +30,7 @@ function dependencyTree(options = {}) {
|
|
|
30
30
|
let tree;
|
|
31
31
|
if (config.isListForm) {
|
|
32
32
|
debug('list form of results requested');
|
|
33
|
-
tree =
|
|
33
|
+
tree = results;
|
|
34
34
|
} else {
|
|
35
35
|
debug('object form of results requested');
|
|
36
36
|
tree = {
|
|
@@ -112,10 +112,10 @@ function getDependencies(config) {
|
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
114
|
* @param {Config} config
|
|
115
|
-
* @returns {Object
|
|
115
|
+
* @returns {Object}
|
|
116
116
|
*/
|
|
117
117
|
function traverse(config) {
|
|
118
|
-
const subTree =
|
|
118
|
+
const subTree = {};
|
|
119
119
|
|
|
120
120
|
debug(`traversing ${config.filename}`);
|
|
121
121
|
|
|
@@ -128,7 +128,7 @@ function traverse(config) {
|
|
|
128
128
|
|
|
129
129
|
debug('cabinet-resolved all dependencies: ', dependencies);
|
|
130
130
|
// Eagerly mark the current file before recursing so any re-entrant visit exits early
|
|
131
|
-
config.visited[config.filename] =
|
|
131
|
+
config.visited[config.filename] = {};
|
|
132
132
|
|
|
133
133
|
if (config.filter) {
|
|
134
134
|
debug('using filter function to filter out dependencies');
|
|
@@ -142,24 +142,54 @@ function traverse(config) {
|
|
|
142
142
|
const localConfig = config.clone();
|
|
143
143
|
localConfig.filename = dependency;
|
|
144
144
|
localConfig.directory = getLocalConfigDirectory(localConfig);
|
|
145
|
+
subTree[dependency] = traverse(localConfig);
|
|
146
|
+
}
|
|
145
147
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
config.visited[config.filename] = subTree;
|
|
149
|
+
|
|
150
|
+
return subTree;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @param {Config} config
|
|
155
|
+
* @returns {Array<string>}
|
|
156
|
+
*/
|
|
157
|
+
function traverseList(config) {
|
|
158
|
+
const result = [];
|
|
159
|
+
traverseListHelper(config, result);
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @param {Config} config
|
|
165
|
+
* @param {Array<string>} result
|
|
166
|
+
*/
|
|
167
|
+
function traverseListHelper(config, result) {
|
|
168
|
+
if (config.visited[config.filename]) return;
|
|
169
|
+
|
|
170
|
+
// Eagerly mark the current file before recursing so any re-entrant visit exits early
|
|
171
|
+
config.visited[config.filename] = [];
|
|
172
|
+
|
|
173
|
+
let dependencies = getDependencies(config);
|
|
174
|
+
|
|
175
|
+
debug('cabinet-resolved all dependencies: ', dependencies);
|
|
176
|
+
|
|
177
|
+
if (config.filter) {
|
|
178
|
+
debug('using filter function to filter out dependencies');
|
|
179
|
+
debug(`unfiltered number of dependencies: ${dependencies.length}`);
|
|
180
|
+
// eslint-disable-next-line unicorn/no-array-method-this-argument, unicorn/no-array-callback-reference
|
|
181
|
+
dependencies = dependencies.filter(filePath => config.filter(filePath, config.filename));
|
|
182
|
+
debug(`filtered number of dependencies: ${dependencies.length}`);
|
|
153
183
|
}
|
|
154
184
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
185
|
+
for (const dependency of dependencies) {
|
|
186
|
+
const localConfig = config.clone();
|
|
187
|
+
localConfig.filename = dependency;
|
|
188
|
+
localConfig.directory = getLocalConfigDirectory(localConfig);
|
|
189
|
+
traverseListHelper(localConfig, result);
|
|
160
190
|
}
|
|
161
191
|
|
|
162
|
-
|
|
192
|
+
result.push(config.filename);
|
|
163
193
|
}
|
|
164
194
|
|
|
165
195
|
// Dedupe in-place so the caller's array reference stays valid
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dependency-tree",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.1",
|
|
4
4
|
"description": "Get the dependency tree of a module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"check:types": "npm run generate:types && git diff HEAD --exit-code types/index.d.ts",
|
|
24
24
|
"lint": "xo",
|
|
25
25
|
"fix": "xo --fix",
|
|
26
|
-
"
|
|
27
|
-
"test": "npm run lint && npm run check:types &&
|
|
28
|
-
"test:ci": "
|
|
26
|
+
"vitest": "vitest",
|
|
27
|
+
"test": "npm run lint && npm run check:types && vitest run",
|
|
28
|
+
"test:ci": "vitest run --coverage"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
@@ -63,12 +63,9 @@
|
|
|
63
63
|
"typescript": "^6.0.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"
|
|
66
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
67
67
|
"debug": "^4.4.3",
|
|
68
|
-
"
|
|
69
|
-
"mocha": "^11.7.5",
|
|
70
|
-
"mock-fs": "^5.5.0",
|
|
71
|
-
"sinon": "^22.0.0",
|
|
68
|
+
"vitest": "^4.1.7",
|
|
72
69
|
"xo": "^2.0.2"
|
|
73
70
|
}
|
|
74
71
|
}
|