Skip to content

Commit 4573320

Browse files
feat: tree path
1 parent c5b726c commit 4573320

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

index.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ module.exports = function(options) {
3333
return config.isListForm ? [] : {};
3434
}
3535

36-
const results = traverse(config);
36+
const params = {
37+
treePath: []
38+
};
39+
40+
const results = traverse(config, params);
3741
debug('traversal complete', results);
3842

3943
dedupeNonExistent(config.nonExistent);
@@ -81,10 +85,11 @@ module.exports.toList = function(options) {
8185
* @param {Config} config
8286
* @return {Array}
8387
*/
84-
module.exports._getDependencies = function(config) {
88+
module.exports._getDependencies = function(config, params) {
8589
let dependencies;
8690
const precinctOptions = config.detectiveConfig;
8791
precinctOptions.includeCore = false;
92+
precinctOptions.treePath = params.treePath;
8893

8994
try {
9095
dependencies = precinct.paperwork(config.filename, precinctOptions);
@@ -136,9 +141,10 @@ module.exports._getDependencies = function(config) {
136141

137142
/**
138143
* @param {Config} config
144+
* @param {Object} params
139145
* @return {Object|Set}
140146
*/
141-
function traverse(config) {
147+
function traverse(config, params) {
142148
let subTree = config.isListForm ? new Set() : {};
143149

144150
debug('traversing ' + config.filename);
@@ -148,7 +154,7 @@ function traverse(config) {
148154
return config.visited[config.filename];
149155
}
150156

151-
let dependencies = module.exports._getDependencies(config);
157+
let dependencies = module.exports._getDependencies(config, params);
152158

153159
debug('cabinet-resolved all dependencies: ', dependencies);
154160
// Prevents cycles by eagerly marking the current file as read
@@ -169,12 +175,17 @@ function traverse(config) {
169175
const localConfig = config.clone();
170176
localConfig.filename = d;
171177

178+
const newParams = {
179+
...params,
180+
treePath: [...(params.treePath ? params.treePath : []), config.filename]
181+
};
182+
172183
if (localConfig.isListForm) {
173-
for (let item of traverse(localConfig)) {
184+
for (let item of traverse(localConfig, newParams)) {
174185
subTree.add(item);
175186
}
176187
} else {
177-
subTree[d] = traverse(localConfig);
188+
subTree[d] = traverse(localConfig, newParams);
178189
}
179190
}
180191

0 commit comments

Comments
 (0)