MCPcopy Create free account
hub / github.com/dmno-dev/bumpy / expandGlob

Function expandGlob

packages/bumpy/src/core/workspace.ts:55–99  ·  view source on GitHub ↗
(baseDir: string, parts: string[])

Source from the content-addressed store, hash-verified

53}
54
55async function expandGlob(baseDir: string, parts: string[]): Promise<string[]> {
56 if (parts.length === 0) {
57 // Check if this dir has a package.json
58 if (await exists(resolve(baseDir, 'package.json'))) {
59 return [baseDir];
60 }
61 return [];
62 }
63
64 const [current, ...rest] = parts;
65 if (current === '*') {
66 // Match any single directory
67 const entries = await safeReaddir(baseDir);
68 const results: string[] = [];
69 for (const entry of entries) {
70 const entryPath = resolve(baseDir, entry);
71 if (await isDirectory(entryPath)) {
72 results.push(...(await expandGlob(entryPath, rest)));
73 }
74 }
75 return results;
76 } else if (current === '**') {
77 // Match any depth
78 const results: string[] = [];
79 // Try matching at this level (skip the **)
80 results.push(...(await expandGlob(baseDir, rest)));
81 // Try descending into subdirs
82 const entries = await safeReaddir(baseDir);
83 for (const entry of entries) {
84 if (entry.startsWith('.') || entry === 'node_modules') continue;
85 const entryPath = resolve(baseDir, entry);
86 if (await isDirectory(entryPath)) {
87 results.push(...(await expandGlob(entryPath, parts))); // keep the ** in pattern
88 }
89 }
90 return results;
91 } else {
92 // Literal directory name
93 const next = resolve(baseDir, current!);
94 if (await isDirectory(next)) {
95 return expandGlob(next, rest);
96 }
97 return [];
98 }
99}
100
101async function safeReaddir(dir: string): Promise<string[]> {
102 try {

Callers 1

resolveGlobFunction · 0.85

Calls 3

existsFunction · 0.90
safeReaddirFunction · 0.85
isDirectoryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…