Repository navigation
Modern Tooling, Part 5: PNPM - #5388
Merged
Merged
Conversation
The patch targeted size-limit 11.0.1 and nothing referenced it. There is no resolutions field in any package.json, yarn.lock resolves size-limit to 11.2.0 with no patch: protocol entry, and node_modules/size-limit/get-config.js on disk still has the unpatched require.resolve calls. The size CI job passes against the unpatched copy. Deleting it rather than converting it to pnpm.patchedDependencies, because converting would apply a patch that Yarn has not been applying.
Adds pnpm-workspace.yaml and drops .yarnrc.yml and the root "workspaces" field. pnpm 11 reads none of its settings from .npmrc or from a "pnpm" field in package.json, so every translated Yarn setting lives in pnpm-workspace.yaml. Yarn -> pnpm setting translations, each verified against the resulting tree: nodeLinker: node-modules -> nodeLinker: hoisted enableTransparentWorkspaces: false -> linkWorkspacePackages: false (Yarn does not auto-install peers) -> autoInstallPeers: false (Yarn runs install scripts) -> allowBuilds map enableGlobalCache: false -> no equivalent, dropped compressionLevel / yarnPath -> Yarn-only, dropped autoInstallPeers is the one that matters. Left at pnpm's default it added 54 packages the repo never had, including a complete Next.js pulled in by docs' next-redux-wrapper peer range and Jest 30 pulled in by @testing-library/react-render-stream. With it off the package set matches Yarn. .yarn/releases/yarn-4.4.1.cjs stays tracked: examples/publish-ci/* are still Yarn 4 and point their yarnPath at it.
…o ^2.0.0 The range was "^1.6.0 || ^2.0.0". Yarn resolved it to 2.11.2. pnpm dedupes it against @rtk-query/codegen-openapi's "^1.6.0" and picks 1.9.7 for both, which silently drops this package's tests from RTK 2.x to RTK 1.x. Its 15 tests pass either way, which is why the drift is invisible without diffing the lockfile. The peerDependencies range stays "^1.7.1 || ^2.0.0" - this only changes what the package is developed and tested against.
Generated with `pnpm import` then re-resolved after autoInstallPeers was turned off. lockfileVersion 9.0, 11 importers. Package set vs yarn.lock: 2011 -> 1986 names, 0 packages present only in pnpm, 25 present only in Yarn - the entire node-gyp closure, which pnpm does not need. 42 names differ in the set of duplicate copies kept; all are dedupes, and no package the repo declares directly changed version. Two resolutions verified by hand because they are the reason enableTransparentWorkspaces was set: @rtk-query/codegen-openapi @reduxjs/toolkit ^1.6.0 -> registry 1.9.7 the four examples' workspace:^ -> link to packages/toolkit Only the root yarn.lock is deleted. The five examples/publish-ci/* lockfiles are untouched.
- `yarn workspaces foreach -A --include X run Y` -> `pnpm -r --filter X run Y`. pnpm runs `-r` topologically by default, so `--topological-dev` and `-t` have no counterpart to write. Filter globs must be double-quoted, not single-quoted: pnpm runs scripts through cmd.exe on Windows, which does not strip single quotes, and the filter then matches nothing. - Dropped `--include '@rtk-incubator/*'` from test:packages. It matched no workspace under Yarn either; pnpm errors on a filter that matches nothing. - `$INIT_CWD` removed from the toolkit's `run-build`. pnpm always runs a script with cwd set to the package directory, so `--config=./tsdown.config.mts` is correct from any invocation point. All 53 dist files are byte-identical. - `yarn tsc` -> `pnpm exec tsc`. pnpm has no bin fallback for `pnpm <binary>`. - msw pinned to 2.1.5 in the toolkit and in codegen-openapi. Both declared `^2.1.x`, and Yarn's lockfile resolved them to 2.1.5. pnpm deduped them onto the 2.6.6 that examples/query/react/infinite-queries asks for, which changed the Response content-type msw emits (`text/plain;charset=UTF-8`) and broke 12 fetchBaseQuery and createApi tests. Pinning keeps this migration to a package manager change. Upgrading to msw 2.6.x and fixing those assertions is worth doing separately. - codegen-openapi's cli tests shell out to the `cli` script and assert stderr is empty. `pnpm run` echoes a `$ <command>` banner to stderr where Yarn did not, so the invocation is now `pnpm --silent cli`.
Adds `pnpm/action-setup@v6.0.10` before every `actions/setup-node` that uses `cache: 'pnpm'` (v4 does not support pnpm 11), and translates the yarn commands. Non-obvious translations: - `yarn <binary>` -> `pnpm exec <binary>`; pnpm has no `node_modules/.bin` fallback. - `yarn info <pkg>` -> `pnpm list <pkg>`; `pnpm info` is `pnpm view` and hits the registry. - `yarn up <pkg>@<range>` -> `pnpm update -r <pkg>@<range>`. - `yarn pack` -> `pnpm pack --out package.tgz`; pnpm defaults to `<name>-<version>.tgz`. - `npm --workspace=<name> pkg set` -> plain `npm pkg set` inside the package dir, since the root `workspaces` field went away with yarn. - pkg-pr-new's `--yarn` -> `--pnpm`; the adjacent `--packageManager=` list is unrelated. - `corepack enable` removed from release-commit.yml; action-setup replaces it. `size.yml` gains an explicit `pnpm/action-setup` with a pinned version. The action installs deps itself and pnpm is not preinstalled on runners, and it measures the PR base commit, whose `packageManager` may still say yarn. The publish-ci job loses its `cache:` input. `setup-node`'s cache runs the package manager at the repository root regardless of the job's working-directory, and the root is pnpm now. test-type-portability installs into each example with `pnpm add --ignore-workspace --ignore-scripts --node-linker=hoisted` and invokes `tsc` directly. pnpm otherwise links `@reduxjs/toolkit` to the workspace sources instead of installing the tarball, the isolated layout makes immer unnameable (TS2883), and `pnpm run` performs an implicit workspace install that undoes the artifact install.
CONTRIBUTING.md and the rtk-codemods README now describe pnpm. The user-facing install snippets (`yarn add @reduxjs/toolkit`, `yarn global add @reduxjs/rtk-codemods`) are unchanged - they are about consumers, not this repo. Also drops the `yarn update-docs` line from the codemods README; no such script exists in that package.
Each of the five examples becomes its own detached pnpm project: a
`pnpm-workspace.yaml` with `packages: []` stops pnpm walking up to the repo
root, and `packageManager: pnpm@11.22.0` pins the version without corepack.
Detaching them is what makes `pnpm add ./package.tgz` install the packed
artifact for real instead of linking `packages/toolkit`.
- `nodeLinker: hoisted` in each, matching the root, so Metro and Turbopack see
a flat tree with no symlinks.
- `allowBuilds: {msw: true}` in next and vite; nothing else needs a postinstall.
- Script translations: `yarn <bin>` -> `pnpm exec <bin>`, `yarn <script>` ->
`pnpm <script>`. Same in both playwright.config.ts webServer commands.
- CI: `pnpm/action-setup` before `setup-node`, `pnpm install
--no-frozen-lockfile` in place of `YARN_ENABLE_IMMUTABLE_INSTALLS: false`,
`yarn info` -> `pnpm list`.
- msw resolved 1.3.2 -> 1.3.5 from the unchanged `^1.3.2` range, which refreshes
the version comment in the two generated `mockServiceWorker.js` files.
Nothing uses Yarn now, so `.yarn/releases/yarn-4.4.1.cjs` and the `.gitignore`
exception that kept it are gone.
Verified locally: all five install, build, and pass their own tests, including
both Playwright suites; `check-bundle` matches the committed module snapshots
for next and vite; and the full remove/add/test artifact sequence was rehearsed
by hand in the node example against a real `pnpm pack` tarball.
`pnpm update -r @types/react@^18` does not behave like `yarn up`. Yarn took the highest version satisfying the range; pnpm picks "the version preferred by your manifests and already installed dependencies" and only warns. That is 18.3.12 here, which lacks the `useRef<T>(initialValue?: undefined)` overload DefinitelyTyped added in 18.3.13 so React 19 style code keeps compiling against React 18 types. RTK uses that style in `query/react/buildHooks.ts`, so the React ^18 leg of `test-dist` failed with five errors on the branch while passing on master. The source is fine and unchanged; only the resolved typings differed. Neither `--resolution-mode=highest` nor a `pnpm-workspace.yaml` override with a range value changes pnpm's choice. Both were tried. An exact spec is the only thing that does. Verified locally: with 18.3.31 installed, the job's own typecheck command exits 0. The `test-type-portability` matrix keeps its `^18` ranges. Those jobs compile the examples against the built declaration files rather than RTK source, so they never reach the affected code and already pass.
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
@reduxjs/rtk-codemods
@rtk-query/codegen-openapi
@rtk-query/graphql-request-base-query
@reduxjs/toolkit
commit: |
The `test-dist` matrix was already pinned for this reason; the `test-types` matrix was missed. `pnpm update -r @types/react@^18` does not pick the highest version in the range the way `yarn up` did - it resolves to 18.3.12, which lacks the `useRef<T>(initialValue?: undefined)` overload that `query/react/buildHooks.ts` relies on. All three React 18 legs failed to compile with TS2769 and TS2322.
`pnpm exec` runs a dependency-status check before the command, and that check installs with `--frozen-lockfile`. The two steps before this one install with `--ignore-workspace`, so the example's `package.json` no longer matches the root lockfile and the check aborts with ERR_PNPM_OUTDATED_LOCKFILE.
…ject directory The CLI builds its `createRequire` from `__filename`, so it only ever looked for `esbuild-runner` and `ts-node` alongside its own installed location. Under Yarn the codegen test installed the packed tarball into `packages/rtk-query-codegen-openapi/node_modules`, so walking up from there found the loaders. pnpm's hoisted linker installs it into the root `node_modules` instead, where `esbuild-runner` is not present, because it peers on an esbuild version that cannot hoist. With `esbuild-runner` unreachable the CLI fell through to the `ts-node` branch, which forces `module: 'commonjs'`. The package's own tsconfig sets `moduleResolution: 'Bundler'`, and that combination is TS5095, so every test that runs the CLI against a TypeScript config file failed. Look for the loaders in the directory the CLI is generating into first, then fall back to the CLI's own location. That is where a consumer's loaders live too, so this fixes the same failure for anyone whose package manager hoists differently than the CLI expects. Also stop marking TypeScript support available when neither loader is found. `ts` was set unconditionally, so the "neither esbuild-runner nor ts-node are installed" error could never fire and a `.ts` config failed later with a raw syntax error instead.
`size-limit` resolves its plugins with a bare import from its own directory, so they have to be reachable from wherever it is installed. pnpm's hoisted linker puts `size-limit` in the root `node_modules` but keeps `@size-limit/webpack` in `packages/toolkit/node_modules`, because it peers on `@swc/core` and `esbuild` and a peer-resolved package stays with its importer. The size job failed with ERR_MODULE_NOT_FOUND for both the head and the base measurement. Declaring it at the root as well puts a copy where `size-limit` can find it. `packages/toolkit` keeps its own entry, since that is the package the size budget belongs to.
Seven tracked pins: the root `packageManager`, the five `publish-ci` examples, and the `version` input in `size.yml`. That last one is pinned separately because the size job checks out the PR base commit, whose `package.json` may still say yarn, so it does not follow the root bump.
`pnpm/action-setup` is now maintenance-only for pnpm 10 and older; its README points pnpm 11+ users at `pnpm/setup`, which downloads pnpm's self-contained release binary instead of installing it through npm. Thirteen call sites across five workflows. Every one sets `install: false`, because `pnpm/setup` defaults to running `pnpm install` itself and each job already installs on its own terms — `--frozen-lockfile` in `publish.yml`, `--no-frozen-lockfile` in the publish-ci examples, plain `pnpm install` elsewhere. `size.yml` needs it for a different reason: that job deliberately has no install step, because the size-limit action installs for both the head and the base commit, and an install at setup time would run against the wrong tree. `actions/setup-node` stays. `pnpm/setup` can absorb it through the `runtime` input, but that is a separate change and this one is already wide.
Under Yarn, vitest resolved its own vite range to 8.0.5 while the examples' `vite: ^7` pins resolved separately to 7.3.1, so the test suites ran on vite 8. pnpm prefers versions already requested by workspace members when resolving transitive ranges, so vitest's range deduped onto the examples' 7.3.1 and the migration silently downgraded vite. Declare `vite: ^8` at the workspace root and move the four examples (`examples/query/react/infinite-queries` and the three `examples/type-portability/*` projects) from `^7` to `^8`. The lockfile now carries a single vite@8.2.2. `@vitejs/plugin-react ^5` moves to 5.2.0, which added vite 8 to its peer range. vite 8 lists esbuild as an optional peer at `^0.27 || ^0.28`; the toolkit and codegen packages still pin `^0.25.1` for their own use, so `pnpm peers check` reports it. vite 8 does not need esbuild unless configured to use it, and all four package test suites pass.
The tree carried esbuild 0.25.12 (pinned by the toolkit and codegen packages) alongside 0.27.7 (wanted by tsx, vite and @size-limit/webpack). Under the hoisted linker pnpm hoists `esbuild` and each `@esbuild/<platform>` binary package independently, so on Netlify it hoisted the 0.25.12 binary to the root and nested esbuild 0.27.7 under tsx with no matching binary beside it. tsx's esbuild then found the wrong binary and the toolkit build died in `tsx scripts/fixUniqueSymbolExports.mts` with "Host version 0.27.7 does not match binary version 0.25.12". The toolkit's `esbuild` devDependency was tsup's and nothing has used it since tsup was removed, so it goes. The codegen package still needs esbuild for esbuild-runner, which peers on `esbuild: *`, so its range moves to ^0.27.0. Every dependent now agrees on 0.27.7, there is one set of `@esbuild/*` packages, and vite 8's esbuild peer range is satisfied. `pnpm dedupe` then folded lightningcss 1.32.0 (@docusaurus/faster wants ^1.27.0) onto the 1.33.0 vite 8 requires, and along the way collapsed stale duplicate resolutions of @types/react-dom, nanoid, postcss and semver that were already within their declared ranges. Verified locally: `pnpm build` in packages/toolkit runs the tsx scripts to completion, the codegen suite passes (100 tests, esbuild-runner on 0.27.7), and `pnpm peers check` reports no esbuild issues.
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR migrates Yarn to PNPM
Stack created with GitHub Stacks CLI • Give Feedback 💬