From 4573320b648cb48bcf8a1fe20e6d371029914462 Mon Sep 17 00:00:00 2001 From: "Anders D. Johnson" Date: Fri, 15 Jul 2022 23:47:38 -0500 Subject: [PATCH 1/3] feat: tree path --- index.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 54b16b2..b4dd2ef 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,11 @@ module.exports = function(options) { return config.isListForm ? [] : {}; } - const results = traverse(config); + const params = { + treePath: [] + }; + + const results = traverse(config, params); debug('traversal complete', results); dedupeNonExistent(config.nonExistent); @@ -81,10 +85,11 @@ module.exports.toList = function(options) { * @param {Config} config * @return {Array} */ -module.exports._getDependencies = function(config) { +module.exports._getDependencies = function(config, params) { let dependencies; const precinctOptions = config.detectiveConfig; precinctOptions.includeCore = false; + precinctOptions.treePath = params.treePath; try { dependencies = precinct.paperwork(config.filename, precinctOptions); @@ -136,9 +141,10 @@ module.exports._getDependencies = function(config) { /** * @param {Config} config + * @param {Object} params * @return {Object|Set} */ -function traverse(config) { +function traverse(config, params) { let subTree = config.isListForm ? new Set() : {}; debug('traversing ' + config.filename); @@ -148,7 +154,7 @@ function traverse(config) { return config.visited[config.filename]; } - let dependencies = module.exports._getDependencies(config); + let dependencies = module.exports._getDependencies(config, params); debug('cabinet-resolved all dependencies: ', dependencies); // Prevents cycles by eagerly marking the current file as read @@ -169,12 +175,17 @@ function traverse(config) { const localConfig = config.clone(); localConfig.filename = d; + const newParams = { + ...params, + treePath: [...(params.treePath ? params.treePath : []), config.filename] + }; + if (localConfig.isListForm) { - for (let item of traverse(localConfig)) { + for (let item of traverse(localConfig, newParams)) { subTree.add(item); } } else { - subTree[d] = traverse(localConfig); + subTree[d] = traverse(localConfig, newParams); } } From 41df3eeebb6e5b3d20cf53f75b3e5cc54da276d1 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 9 May 2023 15:35:55 +0300 Subject: [PATCH 2/3] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 34ba13d..f9983a1 100644 --- a/index.js +++ b/index.js @@ -181,7 +181,7 @@ function traverse(config = {}, params = {}) { subTree.add(item); } } else { - subTree[d] = traverse(localConfig, newParams); + subTree[dep] = traverse(localConfig, newParams); } } From 0473373329e19a5178898467af83db47d89e0ad0 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 9 May 2023 15:36:27 +0300 Subject: [PATCH 3/3] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f9983a1..2c35110 100644 --- a/index.js +++ b/index.js @@ -171,7 +171,7 @@ function traverse(config = {}, params = {}) { const newParams = { ...params, treePath: [ - ...(params.treePath ? params.treePath : []), + ...(params.treePath ?? []), config.filename ] };