fix(init): let pnpm 11+ install the scaffold by skipping esbuild's build script
Closed
OK
2mo ago+308+308+012345678901234567890123456789-4-4-0123456789
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.jsfinds the binary in the@esbuild/<platform>optional dependency at run time. Checked: with the build skipped, tsx runs.tsfiles and the scaffolded example passes. - So init records the build as skipped, not allowed:
allowBuilds: { esbuild: false }. That is the least privilege and the shapepnpm approve-buildswrites for a denied build. pnpm readsallowBuildsonly frompnpm-workspace.yaml(checked on pnpm 12.6: apnpm.allowBuildsfield inpackage.jsonstill 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
packageManagerpin, then the invoking agent (pnpm dlx), thenpnpm --version. pnpm 10 only warns about ignored builds, and pnpm 9 and 10.2.1 refuse apnpm-workspace.yamlwithoutpackages(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 nearestpnpm-workspace.yaml:- missing: creates it
- has no
allowBuilds: appends the block - has a block
allowBuilds: addsesbuild: false, keeping the file's indentation, comments, CRLF, and BOM - already sets esbuild to
trueorfalse, or hasdangerouslyAllowAllBuilds: true: leaves it alone - holds the placeholder a failed install leaves (
esbuild: set this to true or false): sets it tofalse, 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 bareesbuild: falseoverride a versionedtrue. 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 packof every published package from main and from this branch, each set served by its own verdaccio (4410 main, 4411 branch;e2eand@e2e-dev/*not proxied). In a fresh/tmpdir,pnpm dlx e2e init(pnpm 12.6.0) with every prompt left at its default and Yes to install. Thenpnpm install --frozen-lockfilefrom an emptynode_modules, thenAPP_URL=http://127.0.0.1:4420 pnpm test:e2eagainst a static page.- Upgrade path: branch
pnpm dlx e2e init --yesover main's failed scaffold changed the placeholder toesbuild: false, and install and run then passed. @e2e-dev/mobileon the branch's config installs clean, and esbuild is the only ignored build across web, mobile, andai.- Built CLI
init --yesfor 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).
| main | this branch | |
|---|---|---|
pnpm dlx e2e init, Yes to install | ERR_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-lockfile | exit 1, Ignored build scripts: esbuild@0.28.2 | exit 0 |
pnpm test:e2e | cannot run | ✓ app opens, 1 passed |
Not run locally: testbed and web benchmark suites. This change touches only e2e init, and CI runs both.