Skip to content

Commit a690786

Browse files
committed
fix(build): remove module2.module.exports from external bundles
The external bundling process was generating invalid CommonJS code with `module2.module.exports = X;` which causes "Cannot set properties of undefined" errors when loading @InQuirer modules. This adds pattern detection and removal of these invalid lines in the fix-commonjs-exports.mjs script that runs after bundling. Fixes prompt tests that were failing in CI.
1 parent 4c91d8a commit a690786

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

scripts/fix-commonjs-exports.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,25 @@ async function processDirectory(dir, verbose = false) {
350350
// If parsing fails, skip AST-based fixes for this file
351351
}
352352

353+
// Fix module2.module.exports pattern (from external bundling)
354+
// This is always incorrect and causes "Cannot set properties of undefined"
355+
if (content.includes('module2.module.exports')) {
356+
// Find and remove all occurrences of module2.module.exports lines
357+
// Pattern matches: " module2.module.exports = value;\n"
358+
const pattern =
359+
/[ \t]*module2\.module\.exports\s*=\s*[^;]+;[ \t]*\n?/g
360+
const matches = [...content.matchAll(pattern)]
361+
362+
// Process matches in reverse order to maintain correct indices
363+
for (let i = matches.length - 1; i >= 0; i--) {
364+
const match = matches[i]
365+
const start = match.index
366+
const end = start + match[0].length
367+
s.remove(start, end)
368+
modified = true
369+
}
370+
}
371+
353372
// Fix relative paths ONLY for files in the root dist directory
354373
const isRootFile = path.dirname(fullPath) === distDir
355374
if (

0 commit comments

Comments
 (0)