From 825f0b3130a7141baf9111b6e7a783004a66b5fb Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 30 Jan 2024 11:18:57 -0400 Subject: find: configure directories w/ getMatchableDirectories --- src/find.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/find.js b/src/find.js index b5ca70b2..db35e0d8 100644 --- a/src/find.js +++ b/src/find.js @@ -23,6 +23,11 @@ export function processAllAvailableMatches(data, { (Object.hasOwn(thing, 'name') ? [thing.name] : []), + + getMatchableDirectories = thing => + (Object.hasOwn(thing, 'directory') + ? [thing.directory] + : [null]), } = {}) { const byName = Object.create(null); const byDirectory = Object.create(null); @@ -31,7 +36,14 @@ export function processAllAvailableMatches(data, { for (const thing of data) { if (!include(thing)) continue; - byDirectory[thing.directory] = thing; + for (const directory of getMatchableDirectories(thing)) { + if (typeof directory !== 'string') { + logWarn`Unexpected ${typeAppearance(directory)} returned in directories for ${inspect(thing)}`; + continue; + } + + byDirectory[directory] = thing; + } for (const name of getMatchableNames(thing)) { if (typeof name !== 'string') { -- cgit 1.3.0-6-gf8a5