Skip to content

Commit 72ddc75

Browse files
committed
fix(build): handle multi-line import statements in fix-esm-imports
The existing regex `[^'"\n]*` excluded newlines, so imports that span multiple lines — common after destructuring a dozen named exports across visual formatting — silently kept their extension-less form. Downstream ESM loaders reject those paths (Node, vitest) which broke test runs and production startup on certain module entry points. Widen the middle capture to `[\s\S]*?` (non-greedy, newline-aware) while still anchoring to the start-of-line `import`/`export` keyword and the trailing `from` + quote. The non-greedy quantifier prevents cross-statement over-matching when multiple imports appear in the same file. Discovered via wilds-ai vitest run against @framers/agentos@0.2.0 npm artifact (cognitive_substrate/GMI.js line 17 referenced './IGMI' without .js). Four other dist files had the same shape. A republish of the affected agentos version should include this fix so downstream consumers don't need to patch node_modules locally.
1 parent a2030ba commit 72ddc75

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

scripts/fix-esm-imports.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ function rewriteSpecifiers(filePath) {
7272
let changed = false;
7373

7474
const patterns = [
75-
/(^\s*(?:import|export)\s[^'"\n]*from\s+['"])([^'"]+)(['"])/gm,
75+
// Multi-line aware: `[\s\S]*?` matches anything including newlines, non-greedy, so
76+
// imports with destructuring across multiple lines (e.g. `import { A,\n B\n} from './X'`)
77+
// are caught. Anchored to start-of-line by `^` + `m` flag and terminated by the `from`
78+
// keyword before a quote.
79+
/(^\s*(?:import|export)\s[\s\S]*?from\s+['"])([^'"]+)(['"])/gm,
7680
/(import\(\s*['"])([^'"]+)(['"]\s*\))/g
7781
];
7882

0 commit comments

Comments
 (0)