Skip to content

Commit 1f03869

Browse files
committed
fix(build): bundle @npmcli/package-json with subpath exports
Fix the bundling system to create standalone bundles for @npmcli/package-json and its subpath imports (lib/read-package, lib/sort), resolving module not found errors in the editable package.json workflow. Build changes: - Add subpaths field to scoped package config for bundling subpath exports - Enhance orchestrator to bundle subpaths as standalone files - Remove directory copying (replaced with proper bundles) Source changes: - Create entry point for @npmcli/package-json main export - Add entry points for lib/read-package and lib/sort subpaths This produces 33 bundled packages (up from 31): - dist/external/@npmcli/package-json.js (236KB) - dist/external/@npmcli/package-json/lib/read-package.js (2.4KB) - dist/external/@npmcli/package-json/lib/sort.js (2.2KB) All bundles are zero-dependency standalone modules created by esbuild. Fixes: test/packages/operations.test.ts editable package.json tests
1 parent 7652e59 commit 1f03869

5 files changed

Lines changed: 28 additions & 3 deletions

File tree

scripts/build-externals/config.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ export const externalPackages = [
3434

3535
// Scoped packages need special handling.
3636
export const scopedPackages = [
37-
{ scope: '@npmcli', name: 'promise-spawn', bundle: true },
37+
{
38+
scope: '@npmcli',
39+
packages: ['package-json', 'promise-spawn'],
40+
bundle: true,
41+
subpaths: ['package-json/lib/read-package.js', 'package-json/lib/sort.js'],
42+
},
3843
{
3944
scope: '@inquirer',
4045
packages: [

scripts/build-externals/orchestrator.mjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ensureDir } from './copy-files.mjs'
1212

1313
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1414
const rootDir = path.resolve(__dirname, '..', '..')
15-
const _srcExternalDir = path.join(rootDir, 'src', 'external')
1615
const distExternalDir = path.join(rootDir, 'dist', 'external')
1716

1817
/**
@@ -43,7 +42,7 @@ async function bundleAllPackages(options = {}) {
4342
}
4443

4544
// Bundle scoped packages.
46-
for (const { name, optional, packages, scope } of scopedPackages) {
45+
for (const { name, optional, packages, scope, subpaths } of scopedPackages) {
4746
const scopeDir = path.join(distExternalDir, scope)
4847
await ensureDir(scopeDir)
4948

@@ -106,6 +105,24 @@ async function bundleAllPackages(options = {}) {
106105
}
107106
}
108107
}
108+
109+
// Bundle subpath exports (e.g., @npmcli/package-json/lib/read-package)
110+
if (subpaths) {
111+
for (const subpath of subpaths) {
112+
const outputPath = path.join(distExternalDir, scope, subpath)
113+
const packageName = `${scope}/${subpath}`
114+
// Ensure parent directory exists
115+
await ensureDir(path.dirname(outputPath))
116+
const size = await bundlePackage(packageName, outputPath, {
117+
quiet,
118+
rootDir,
119+
})
120+
if (size) {
121+
bundledCount++
122+
totalSize += size
123+
}
124+
}
125+
}
109126
}
110127

111128
return { bundledCount, totalSize }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@npmcli/package-json')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Entry point for bundling @npmcli/package-json/lib/read-package
12
module.exports = require('@npmcli/package-json/lib/read-package.js')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Entry point for bundling @npmcli/package-json/lib/sort
12
module.exports = require('@npmcli/package-json/lib/sort.js')

0 commit comments

Comments
 (0)