Skip to content

Commit 7ac1d0b

Browse files
committed
optimize scan depencies
1 parent 92b238a commit 7ac1d0b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

index.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,17 @@ function* scanCacheDependencies(
189189
}).scanImports(readFileSync(target));
190190
for (const imp of imports) {
191191
if (imp.kind === "import-statement") {
192-
const path = Bun.fileURLToPath(import.meta.resolve(imp.path, target));
192+
const path = require.resolve(
193+
Bun.fileURLToPath(import.meta.resolve(imp.path, target))
194+
);
193195
if (
194196
path.includes("/node_modules/") ||
195197
excludes.some((x) => path.match(x))
196198
)
197199
continue;
198-
const resolved = Object.keys(require.cache).find((x) =>
199-
x.startsWith(path)
200-
);
201-
if (resolved) {
202-
yield resolved;
203-
yield* scanCacheDependencies(resolved, excludes);
200+
if (path in require.cache) {
201+
yield path;
202+
yield* scanCacheDependencies(path, excludes);
204203
}
205204
}
206205
}

0 commit comments

Comments
 (0)