From 4573320b648cb48bcf8a1fe20e6d371029914462 Mon Sep 17 00:00:00 2001 From: "Anders D. Johnson" Date: Fri, 15 Jul 2022 23:47:38 -0500 Subject: [PATCH] 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); } }