fix(init): let pnpm 11+ install the scaffold by skipping esbuild's build script

Closed
OK
2mo ago
+308-4

pnpm dlx e2e init on pnpm 11+ scaffolds a project that cannot install: e2e depends on tsx, tsx on esbuild, and pnpm 11+ fails any install with an undecided build script (ERR_PNPM_IGNORED_BUILDS: esbuild@0.28.2). pnpm install --frozen-lockfile in CI fails the same way. npm 11 only warns; bun is fine.

  • esbuild's postinstall is not needed. It hard-links the CLI binary over the JS shim and prints the binary's version. tsx calls the JS API, and lib/main.js finds the binary in the @esbuild/<platform> optional dependency at run time. Checked: with the build skipped, tsx runs .ts files and the scaffolded example passes.
  • So init records the build as skipped, not allowed: allowBuilds: { esbuild: false }. That is the least privilege and the shape pnpm approve-builds writes for a denied build. pnpm reads allowBuilds only from pnpm-workspace.yaml (checked on pnpm 12.6: a pnpm.allowBuilds field in package.json still fails the install). pnpm 10.34 and 11.28 honor it too.
  • Dropping tsx is not an option this close to the release: config and test loading run on its ESM API (packages/e2e/src/config/load.ts).
  • It runs only on pnpm 11+. The major comes from the packageManager pin, then the invoking agent (pnpm dlx), then pnpm --version. pnpm 10 only warns about ignored builds, and pnpm 9 and 10.2.1 refuse a pnpm-workspace.yaml without packages (packages field missing or empty), so older versions get no file.
  • The new code is packages/e2e/src/cli/init/pnpm-builds.ts. It changes the nearest pnpm-workspace.yaml:
    • missing: creates it
    • has no allowBuilds: appends the block
    • has a block allowBuilds: adds esbuild: false, keeping the file's indentation, comments, CRLF, and BOM
    • already sets esbuild to true or false, or has dangerouslyAllowAllBuilds: true: leaves it alone
    • holds the placeholder a failed install leaves (esbuild: set this to true or false): sets it to false, so re-running init repairs a project main scaffolded
    • is a workspace root above the project, or has an inline allowBuilds: no edit, a warning naming the entry to add, and an outro that says the entry is still missing
    • names esbuild by version (esbuild@0.25.0: true) with no bare boolean: no edit, since pnpm lets a bare esbuild: false override a versioned true. The warning names the versioned entry to add (esbuild@0.28.2: false)
    • cannot be read: invalid-project, exit 2, before any write
# e2e runs TypeScript through tsx, which calls esbuild's JavaScript API;
# that finds the esbuild binary without the build script, so pnpm skips it.
allowBuilds:
  esbuild: false

pnpm dlx still shows pnpm's own "Choose which packages to build" prompt while it fetches e2e into its cache. Enter (build nothing) works. That prompt is pnpm's and init cannot answer it.

Verified

Ran it locally: yes

  • pnpm pack of every published package from main and from this branch, each set served by its own verdaccio (4410 main, 4411 branch; e2e and @e2e-dev/* not proxied). In a fresh /tmp dir, pnpm dlx e2e init (pnpm 12.6.0) with every prompt left at its default and Yes to install. Then pnpm install --frozen-lockfile from an empty node_modules, then APP_URL=http://127.0.0.1:4420 pnpm test:e2e against a static page.
  • Upgrade path: branch pnpm dlx e2e init --yes over main's failed scaffold changed the placeholder to esbuild: false, and install and run then passed.
  • @e2e-dev/mobile on the branch's config installs clean, and esbuild is the only ignored build across web, mobile, and ai.
  • Built CLI init --yes for each version: pnpm 12 writes the file and installs. pnpm 10.2.1 and 9 get no file and install (10 prints its ignored-builds warning). npm gets no file and installs.
  • pnpm 12 installs every edited file shape the unit tests produce (placeholder, comment in block, BOM, 4-space indent).
mainthis branch
pnpm dlx e2e init, Yes to installERR_PNPM_IGNORED_BUILDS / Installation failed (exit 1); retry with pnpm install, exit 2, no Next:Created pnpm-workspace.yaml, install Done, Next: APP_URL=http://localhost:3000 pnpm test:e2e, exit 0
pnpm install --frozen-lockfileexit 1, Ignored build scripts: esbuild@0.28.2exit 0
pnpm test:e2ecannot run✓ app opens, 1 passed

Not run locally: testbed and web benchmark suites. This change touches only e2e init, and CI runs both.