Skip to content

Commit

Permalink
feat: tree path
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersDJohnson committed Jul 16, 2022
1 parent c5b726c commit 4573320
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 4573320

Please sign in to comment.