From 1d115745e422779f5715b19bbebadc6ba0eec3ef Mon Sep 17 00:00:00 2001 From: "Anders D. Johnson" Date: Fri, 15 Jul 2022 22:21:45 -0500 Subject: [PATCH 1/4] feat: identifiers --- index.js | 36 ++++++++++++++++++++++++++++++------ lib/Config.js | 1 + 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 54b16b2..70a796f 100644 --- a/index.js +++ b/index.js @@ -44,6 +44,13 @@ module.exports = function(options) { debug('list form of results requested'); tree = Array.from(results); + } else if (config.identifiers) { + debug('identifiers form of results requested'); + + tree = [{ + path: config.filename, + children: results + }] } else { debug('object form of results requested'); @@ -102,8 +109,10 @@ module.exports._getDependencies = function(config) { for (let i = 0, l = dependencies.length; i < l; i++) { const dep = dependencies[i]; + const depPath = dep.path || dep; + const result = cabinet({ - partial: dep, + partial: depPath, filename: config.filename, directory: config.directory, ast: precinct.ast, @@ -114,8 +123,13 @@ module.exports._getDependencies = function(config) { noTypeDefinitions: config.noTypeDefinitions }); + const resultDep = typeof dep === 'string' ? dep : { + ...dep, + path: result + } + if (!result) { - debug('skipping an empty filepath resolution for partial: ' + dep); + debug('skipping an empty filepath resolution for partial: ' + depPath); config.nonExistent.push(dep); continue; } @@ -128,7 +142,7 @@ module.exports._getDependencies = function(config) { continue; } - resolvedDependencies.push(result); + resolvedDependencies.push(resultDep); } return resolvedDependencies; @@ -139,7 +153,7 @@ module.exports._getDependencies = function(config) { * @return {Object|Set} */ function traverse(config) { - let subTree = config.isListForm ? new Set() : {}; + let subTree = config.isListForm ? new Set() : config.identifiers ? [] : {}; debug('traversing ' + config.filename); @@ -166,15 +180,25 @@ function traverse(config) { for (let i = 0, l = dependencies.length; i < l; i++) { const d = dependencies[i]; + + // If `identifiers: true` was passed, we'll get results objects with `path`, otherwise strings. + const depPath = d.path || d; + const localConfig = config.clone(); - localConfig.filename = d; + localConfig.filename = depPath; if (localConfig.isListForm) { for (let item of traverse(localConfig)) { subTree.add(item); } + } else if (localConfig.identifiers) { + subTree.push({ + path: depPath, + identifiers: d.identifiers, + children: traverse(localConfig) + }) } else { - subTree[d] = traverse(localConfig); + subTree[depPath] = traverse(localConfig); } } diff --git a/lib/Config.js b/lib/Config.js index 4be5d58..2e39344 100644 --- a/lib/Config.js +++ b/lib/Config.js @@ -16,6 +16,7 @@ class Config { this.detectiveConfig = options.detective || options.detectiveConfig || {}; this.tsConfig = options.tsConfig; this.noTypeDefinitions = options.noTypeDefinitions; + this.identifiers = options.identifiers; this.filter = options.filter; From 9d7abedaf04269b425223d2f7fcccd0291525a69 Mon Sep 17 00:00:00 2001 From: "Anders D. Johnson" Date: Fri, 15 Jul 2022 22:22:56 -0500 Subject: [PATCH 2/4] wip --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 70a796f..c4a5bb5 100644 --- a/index.js +++ b/index.js @@ -126,7 +126,7 @@ module.exports._getDependencies = function(config) { const resultDep = typeof dep === 'string' ? dep : { ...dep, path: result - } + }; if (!result) { debug('skipping an empty filepath resolution for partial: ' + depPath); From 92097c3616558d7d082028633d13583315dc61be Mon Sep 17 00:00:00 2001 From: "Anders D. Johnson" Date: Fri, 15 Jul 2022 22:34:16 -0500 Subject: [PATCH 3/4] format --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c4a5bb5..df465d7 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ module.exports = function(options) { tree = [{ path: config.filename, children: results - }] + }]; } else { debug('object form of results requested'); @@ -196,7 +196,7 @@ function traverse(config) { path: depPath, identifiers: d.identifiers, children: traverse(localConfig) - }) + }); } else { subTree[depPath] = traverse(localConfig); } From d5973473a13f936a56d0adcc9f67d0736dbdd7c1 Mon Sep 17 00:00:00 2001 From: "Anders D. Johnson" Date: Fri, 15 Jul 2022 22:35:41 -0500 Subject: [PATCH 4/4] wip --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index df465d7..886c5ac 100644 --- a/index.js +++ b/index.js @@ -123,7 +123,7 @@ module.exports._getDependencies = function(config) { noTypeDefinitions: config.noTypeDefinitions }); - const resultDep = typeof dep === 'string' ? dep : { + const resultDep = typeof dep === 'string' ? result : { ...dep, path: result };