Repository navigation
chore: migrate from yarn to pnpm - #129
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A couple of pnpm command invocations won’t reliably forward script arguments and the CI build step can mask build failures without -e, which can break Storybook publishing and reduce CI reliability.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR migrates the repo’s package manager from Yarn to pnpm, updating developer scripts and CI to use pnpm while also addressing pnpm-specific dependency/linking and lifecycle-script behavior.
Changes:
- Replace Yarn usage with pnpm across scripts and CI (install, test, typecheck, bundlesize).
- Add pnpm-specific configuration (
pnpm.overrides,pnpm.onlyBuiltDependencies) and pin toolchain viapackageManagerandengines.node. - Update ancillary docs/ignore rules to reflect pnpm (
READMEinstall snippet,.npmignore).
File summaries
| File | Description |
|---|---|
| README.md | Updates installation instructions to include pnpm. |
| package.json | Switches scripts to pnpm, adds missing devDependencies, and adds pnpm/engine/packageManager config. |
| .scripts/user/prepublish.sh | Uses pnpm exec for the publish-time TypeScript build. |
| .scripts/publish_storybook.sh | Switches storybook build invocation from yarn to pnpm. |
| .npmignore | Ignores pnpm-lock.yaml and .npmrc instead of yarn.lock. |
| .github/workflows/build.yml | Migrates CI to pnpm, adds explicit build step before bundlesize, and bumps core actions versions. |
Review details
- Files reviewed: 6/8 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| - name: Build | ||
| run: bash .scripts/prepublish.sh | ||
| - name: Bundle size |
There was a problem hiding this comment.
Good catch, fixed in c24268e — the script now sets set -e.
Verified both directions by appending a syntax error to src/index.tsx and running the script:
| exit code | |
|---|---|
| broken build, before | 0 |
| broken build, after | 1 |
| good build, after | 0 |
So CI's Build step really would have gone green on a broken build.
|
|
||
| # run our compile script, discussed above | ||
| yarn build-storybook -o .out | ||
| pnpm run build-storybook -o .out |
There was a problem hiding this comment.
Not applicable to pnpm 10 — it forwards these without --. Tested against pnpm 10.14.0 with a script that echoes $@:
pnpm run echoargs -o .out -> RECEIVED: -o .out
pnpm run echoargs --watch -> RECEIVED: --watch
pnpm run echoargs -- --watch -> RECEIVED: -- --watch
-o is not intercepted as a pnpm flag, and adding -- is actively worse: the literal -- is passed through to the underlying command. Leaving as written.
| "test-watch": "npm run testonly --watch", | ||
| "test": "npm run lint && npm run testonly", | ||
| "test:ci": "npm run lint && npm run testonly:ci", | ||
| "test-watch": "pnpm run testonly --watch", |
There was a problem hiding this comment.
Same as the publish_storybook.sh thread — pnpm 10 forwards --watch without --, and adding -- would pass a literal -- to jest.
Worth noting the opposite is true of what this line used to be: npm run testonly --watch genuinely did not forward, because npm does require --. So jest watch mode was silently broken before and the move to pnpm fixes it.
04828c3 to
0d76959
Compare
- Replace yarn.lock with pnpm-lock.yaml; pin packageManager to pnpm@10.14.0 and add engines.node >=20 to match .nvmrc and CI. - yarn's `resolutions` has no meaning to pnpm — moved to `pnpm.overrides`. - Declare @babel/preset-react. Every env block in .babelrc requires it but it was never a dependency; yarn's flat hoisting hid that. pnpm's strict linking surfaced it as a storybook build failure. - Add @storybook/test@8.6.18 to satisfy the @storybook/react peer that its dist imports at build time. - Allow the native builds bundlesize needs (iltorb) via pnpm.onlyBuiltDependencies; pnpm 10 blocks lifecycle scripts by default. - Rename `prepublish` to `prepublishOnly`. npm's legacy `prepublish` also fired on install, which is how CI happened to have a dist/ for the bundlesize step; pnpm does not run it at all. CI now builds explicitly before measuring. - CI: pnpm/action-setup, --frozen-lockfile, pnpm store caching, checkout/setup-node v4. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
0d76959 to
a5532f4
Compare
.scripts/prepublish.sh ran four babel invocations and a tsc build with no set -e, so a failure was masked by the next command succeeding and the script exited 0. Verified: with a deliberate syntax error in src/index.tsx the script exits 0 before this change and 1 after. This matters now that CI runs the script as its Build step — a broken build would have gone green. Flagged in review on [react-aspect-ratio#129](#129). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Stacked on react-aspect-ratio#128 — base is
v2-major, so review that one first. This also resolves the "regenerate the lockfile" follow-up noted there:yarn.lockis replaced outright rather than regenerated.What changed
yarn.lock→pnpm-lock.yaml.packageManagerpinned topnpm@10.14.0, plusengines.node: ">=20"to match.nvmrcand the CI matrix.resolutionshas no meaning to pnpm — thejackspeakpin moved topnpm.overrides.pnpm run/pnpm execinstead ofnpm run/yarn.pnpm/action-setup@v4,pnpm install --frozen-lockfile, and setup-node's pnpm store cache;actions/checkoutandactions/setup-nodebumped v2 → v4.Two latent bugs pnpm's strict linking surfaced
@babel/preset-reactwas never declared. All four env blocks in.babelrcrequire it, but it only ever resolved through yarn's flat hoisting. Under pnpm the storybook build fails withCannot find package '@babel/preset-react'. Now an explicit devDependency (pinned^7.24.0— v8 requires Babel 8).@storybook/test@8.6.18added alongside it, since@storybook/react's dist imports it at build time.prepublishwas doubling as an install hook. npm's legacyprepublishfires on install as well as publish, which is how CI happened to have a populateddist/for itsbundlesizestep — nothing ever built it explicitly. pnpm does not run that lifecycle at all. Renamed toprepublishOnly(honored by npm, yarn and pnpm, publish only) and CI now has an explicit Build step before Bundle size.Also: pnpm 10 blocks dependency lifecycle scripts by default, which broke
bundlesize(itsbrotli-size→iltorbnative binding). Allowed explicitly viapnpm.onlyBuiltDependenciesrather than globally.Verification
Full CI sequence run locally on Node 22 / pnpm 10.14.0:
pnpm install— clean, no missing peerspnpm run test:ci— 6/6 passpnpm exec tsc --noEmit— no errorsbash .scripts/prepublish.sh— cjs/es/umd/next +.d.tsall emitpnpm run bundlesize— 4/4 passpnpm run build-storybook— builds (this is what caught the missing preset)Pre-existing packaging bugs found, deliberately not fixed here
Both predate this PR and predate v2; flagging rather than folding into a package-manager migration:
tscclobbers the babel cjs build..scripts/user/prepublish.shrunstsc --build tsconfig.publish.json, which inheritsoutDir: dist,noEmit: falseandtarget: ESNext— so it overwritesdist/index.js(babel's ES5 cjs output) with its own ESNext emit. The publishedmainhas never actually been the babel build.modulepoints at CommonJS. Theesenv in.babelrcsetstargets.esmodulesbut notmodules: false, sodist/es/index.jsshipsrequire/exports.__esModuledespite being the declared ESM entry point.Both are fixed in react-aspect-ratio#131, stacked on this branch.
🤖 Generated with Claude Code