Skip to content

Commit adfc844

Browse files
committed
fix(build): unwrap default-only exports in @InQuirer modules
- Add footer to @InQuirer packages to unwrap { default: fn } -> fn - Remove KNOWN_DEFAULT_ONLY_MODULES whitelist (no longer needed) - confirm/input/password now export functions directly - search/select/checkbox keep named exports (Separator) + default - Ensures CJS compatibility without .default accessor
1 parent 7c55895 commit adfc844

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

scripts/build-externals/esbuild-config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ export function getPackageSpecificOptions(packageName) {
171171
} else if (packageName.startsWith('@inquirer/')) {
172172
// Inquirer packages have heavy dependencies we might not need.
173173
opts.external = [...(opts.external || []), 'rxjs/operators']
174+
// Inquirer packages export default only - unwrap for CJS compatibility
175+
opts.footer = {
176+
js: 'if (module.exports && module.exports.default && Object.keys(module.exports).length === 1) { module.exports = module.exports.default; }',
177+
}
174178
} else if (packageName === '@socketregistry/packageurl-js') {
175179
// packageurl-js imports from socket-lib, creating a circular dependency.
176180
// Mark socket-lib imports as external to avoid bundling issues.
@@ -270,6 +274,9 @@ export function getEsbuildConfig(entryPoint, outfile, packageOpts = {}) {
270274
// Banner for generated code
271275
banner: {
272276
js: '"use strict";',
277+
...packageOpts.banner,
273278
},
279+
// Footer for generated code (if needed)
280+
...(packageOpts.footer && { footer: packageOpts.footer }),
274281
}
275282
}

scripts/validate/external-exports.mjs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ const { pluralize } = require('#socketsecurity/lib/words')
2323

2424
const logger = getDefaultLogger()
2525

26-
// Modules that only export { default } but are correctly handled in code
27-
// via .default accessor (e.g., confirmExport.default ?? confirmExport)
28-
const KNOWN_DEFAULT_ONLY_MODULES = new Set([
29-
'@inquirer/confirm.js',
30-
'@inquirer/input.js',
31-
'@inquirer/password.js',
32-
'@inquirer/search.js',
33-
'@inquirer/select.js',
34-
])
35-
3626
/**
3727
* Get all .js files and directories in the external directory.
3828
*/
@@ -90,16 +80,6 @@ function checkExternalExport(filePath) {
9080

9181
// If only key is 'default', it's wrapped incorrectly
9282
if (keys.length === 1 && keys[0] === 'default') {
93-
// Check if this is a known module that's correctly handled in code
94-
if (KNOWN_DEFAULT_ONLY_MODULES.has(normalizedPath)) {
95-
return {
96-
path: normalizedPath,
97-
ok: true,
98-
keys: 'default-only (handled)',
99-
note: 'Uses .default accessor in code',
100-
}
101-
}
102-
10383
return {
10484
path: normalizedPath,
10585
ok: false,

0 commit comments

Comments
 (0)