Skip to content

chore: migrate from yarn to pnpm - #129

Merged
roderickhsiao merged 2 commits into
mainfrom
v2-pnpm
Sep 4, 2026
Merged

roderickhsiao merged 2 commits into
mainfrom
v2-pnpm

Conversation

@roderickhsiao

@roderickhsiao roderickhsiao commented Sep 4, 2026 •

Copy link
Copy Markdown
Owner

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.lock is replaced outright rather than regenerated.

What changed

  • yarn.lock → pnpm-lock.yaml. packageManager pinned to pnpm@10.14.0, plus engines.node: ">=20" to match .nvmrc and the CI matrix.
  • yarn's resolutions has no meaning to pnpm — the jackspeak pin moved to pnpm.overrides.
  • Scripts call pnpm run / pnpm exec instead of npm run / yarn.
  • CI uses pnpm/action-setup@v4, pnpm install --frozen-lockfile, and setup-node's pnpm store cache; actions/checkout and actions/setup-node bumped v2 → v4.

Two latent bugs pnpm's strict linking surfaced

@babel/preset-react was never declared. All four env blocks in .babelrc require it, but it only ever resolved through yarn's flat hoisting. Under pnpm the storybook build fails with Cannot find package '@babel/preset-react'. Now an explicit devDependency (pinned ^7.24.0 — v8 requires Babel 8). @storybook/test@8.6.18 added alongside it, since @storybook/react's dist imports it at build time.

prepublish was doubling as an install hook. npm's legacy prepublish fires on install as well as publish, which is how CI happened to have a populated dist/ for its bundlesize step — nothing ever built it explicitly. pnpm does not run that lifecycle at all. Renamed to prepublishOnly (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 (its brotli-size → iltorb native binding). Allowed explicitly via pnpm.onlyBuiltDependencies rather than globally.

Verification

Full CI sequence run locally on Node 22 / pnpm 10.14.0:

  • pnpm install — clean, no missing peers
  • pnpm run test:ci — 6/6 pass
  • pnpm exec tsc --noEmit — no errors
  • bash .scripts/prepublish.sh — cjs/es/umd/next + .d.ts all emit
  • pnpm run bundlesize — 4/4 pass
  • pnpm 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:

  1. tsc clobbers the babel cjs build. .scripts/user/prepublish.sh runs tsc --build tsconfig.publish.json, which inherits outDir: dist, noEmit: false and target: ESNext — so it overwrites dist/index.js (babel's ES5 cjs output) with its own ESNext emit. The published main has never actually been the babel build.
  2. module points at CommonJS. The es env in .babelrc sets targets.esmodules but not modules: false, so dist/es/index.js ships require/exports.__esModule despite being the declared ESM entry point.

Both are fixed in react-aspect-ratio#131, stacked on this branch.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 via packageManager and engines.node.
  • Update ancillary docs/ignore rules to reflect pnpm (README install 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.

Comment on lines +38 to 40
- name: Build
run: bash .scripts/prepublish.sh
- name: Bundle size

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread package.json
"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",

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

- 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>
.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>
@roderickhsiao
roderickhsiao merged commit f163869 into main Sep 4, 2026
2 checks passed
@roderickhsiao
roderickhsiao deleted the v2-pnpm branch September 4, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants