Skip to content

Commit ccf9d2b

Browse files
committed
fix(build/externals): honor thin wrappers for .js-suffixed subpaths
`bundlePackage` appended `.js` unconditionally when computing the `src/external/{packageName}.js` wrapper path. For subpaths whose literal name already ends in `.js` (e.g. `@npmcli/package-json/lib/read-package.js` — the package's own exports map uses that literal path), this produced `src/external/@npmcli/package-json/lib/read-package.js.js`, which doesn't exist. `existsSync` returned false and the bundler silently skipped the hand-written wrapper, bundling upstream directly. Any customization intended for the wrapper layer (custom re-exports, additional stubs) was invisibly discarded. Strips an existing `.js` before appending so both subpath styles resolve to the same wrapper.
1 parent bcbdc86 commit ccf9d2b

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

scripts/build-externals/bundler.mts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ export async function bundlePackage(packageName, outputPath, options = {}) {
4343
let packagePath
4444

4545
// First, check if src/external/{packageName}.js exists - use as entry point.
46-
// Preserve scope for scoped packages like @socketregistry/yocto-spinner
47-
const srcExternalPath = path.join(
48-
rootDir,
49-
'src',
50-
'external',
51-
`${packageName}.js`,
52-
)
46+
// Preserve scope for scoped packages like @socketregistry/yocto-spinner.
47+
// Subpath entries may already end in `.js` (e.g. `@npmcli/package-json/
48+
// lib/read-package.js` — the package's own exports map uses that literal
49+
// path). Strip an existing `.js` before appending so we don't look for
50+
// `read-package.js.js` and silently skip the thin wrapper.
51+
const wrapperName = packageName.endsWith('.js')
52+
? packageName
53+
: `${packageName}.js`
54+
const srcExternalPath = path.join(rootDir, 'src', 'external', wrapperName)
5355
if (existsSync(srcExternalPath)) {
5456
packagePath = srcExternalPath
5557
if (!quiet) {

0 commit comments

Comments
 (0)