Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: keep dynamic import edges on block-comment and generator-method lines in import reach

[._.]/ Adam Eivye63b8499012d
diff --git a/scripts/lib/importReach.js b/scripts/lib/importReach.js
index c8436d68ab..81ca4731e8 100644
--- a/scripts/lib/importReach.js
+++ b/scripts/lib/importReach.js
@@ -28,11 +28,17 @@ import { globToRegExp, toWorkspacePath, workspaceTestGlobs } from './workspaceTe
const MODULE_SOURCE_RE = /\.[cm]?[jt]sx?$/i;
const RESOLVE_EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', '.mts', '.cts'];
const DYNAMIC_IMPORT_RE = /\bimport\s*\(\s*(['"`])([^'"`]+?)\1\s*[,)]/g;
-const COMMENT_LINE_RE = /^\s*(?:\/\/|\/?\*)/;
+// `*` opens a comment continuation only when followed by space, `/` or EOL; `*gen() {}` is code.
+const COMMENT_LINE_RE = /^\s*(?:\/\/|\*(?:[\s/]|$))/;
+const LEADING_BLOCK_COMMENT_RE = /^\s*\/\*.*?\*\//;
+const OPEN_BLOCK_COMMENT_RE = /^\s*\/\*/;
/** `{ static, dynamic }` relative and bare specifiers, in source order. */
export function importSpecifiersFromSource(src) {
- const code = src.split('\n').filter((line) => !COMMENT_LINE_RE.test(line)).join('\n');
+ const code = src.split('\n')
+ .map((line) => line.replace(LEADING_BLOCK_COMMENT_RE, ''))
+ .filter((line) => !COMMENT_LINE_RE.test(line) && !OPEN_BLOCK_COMMENT_RE.test(line))
+ .join('\n');
const dynamic = [];
for (const match of code.matchAll(DYNAMIC_IMPORT_RE)) {
if (!match[2].includes('${')) dynamic.push(match[2]);
diff --git a/scripts/lib/importReach.test.js b/scripts/lib/importReach.test.js
index 79a22c19af..086ce3e3df 100644
--- a/scripts/lib/importReach.test.js
+++ b/scripts/lib/importReach.test.js
@@ -15,10 +15,14 @@ const SOURCES = new Map([
'// await import(\'./ghost.js\') in a comment is not an edge',
"export const load = (name) => import(`./${name}.js`);",
"export async function rare() { return (await import('./heavy.js')).run(); }",
+ "/* lazy */ export const lazyLeaf = () => import('./lazyLeaf.js');",
+ "export const gen = {\n *walk() { return import('./genLeaf.js'); }\n};",
].join('\n')],
['svc/heavy.js', "import { core } from './core.js';\nexport const run = () => core;\n"],
['svc/core.js', 'export const core = 1;\n'],
['svc/leaf.js', 'export const leaf = 1;\n'],
+ ['svc/lazyLeaf.js', 'export const a = 1;\n'],
+ ['svc/genLeaf.js', 'export const b = 1;\n'],
['svc/ghost.js', 'export const ghost = 1;\n'],
['svc/caller.test.js', "import { load } from './caller.js';\n"],
['svc/core.test.js', "import { core } from './core';\n"],
@@ -28,7 +32,7 @@ const graph = buildImportGraph([...SOURCES.keys()], (rel) => SOURCES.get(rel) ??
describe('importReachReport', () => {
it('counts a dynamic edge for selection while the static view stops at it', () => {
- expect([...graph.get('svc/caller.js').dynamic]).toEqual(['svc/heavy.js']);
+ expect([...graph.get('svc/caller.js').dynamic]).toEqual(['svc/heavy.js', 'svc/lazyLeaf.js', 'svc/genLeaf.js']);
const { rows, selected } = importReachReport(graph, ['svc/core.js', 'svc/heavy.js', 'svc/ghost.js'], isTest);
expect(rows).toEqual([
// core.test.js resolves `./core` without an extension, like Vite.