« get me outta code hell

find: configure directories w/ getMatchableDirectories - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-30 11:18:57 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-30 14:30:05 -0400
commit825f0b3130a7141baf9111b6e7a783004a66b5fb (patch)
tree89c82959c33e2cf2439e6e871760e19f45408fe8
parentba887971ccfc8b0e76d6a06253c507b4597ca0dc (diff)
find: configure directories w/ getMatchableDirectories
-rw-r--r--src/find.js14
1 files changed, 13 insertions, 1 deletions
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') {