fix(codemod): write pnpm overrides to the workspace root - #97412
Open
unrevised6419 wants to merge 1 commit into
Open
unrevised6419 wants to merge 1 commit into
unrevised6419 wants to merge 1 commit into
Conversation
`next upgrade` wrote pnpm-workspace.yaml next to the app's package.json. In a pnpm monorepo that file declares a nested workspace root, cutting the app off from the real root so workspace:* dependencies stop resolving. Walk up to the existing pnpm-workspace.yaml instead, matching how pnpm locates the workspace root, and scope the @types/react overrides to the upgraded package with pnpm's <package>><dependency> selector so sibling packages keep their own resolution. Skip the rewrite when the overrides are already up to date, since js-yaml cannot round-trip comments.
unrevised6419
marked this pull request as ready for review
August 15, 2026 12:21
Author
|
Question: Should we switch from using |
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.
What?
next upgradecreated apnpm-workspace.yamlin the directory it was runfrom. In a pnpm monorepo that is the app package, so the file now lands in the
workspace root instead, and the
@types/react/@types/react-domoverridesit writes are scoped to the package being upgraded.
Why?
The presence of
pnpm-workspace.yamlis what defines a pnpm workspace root.Writing one next to an app's
package.jsondeclared a nested root: the appwas cut off from the real one and stopped resolving its
workspace:*dependencies on sibling packages.
Overrides in a shared root apply to the whole workspace, so hoisting them
without scoping would force the upgraded app's
@types/reactversion ontounrelated packages.
Introduced in #94690.
How?
pnpm-workspace.yaml,the way pnpm locates the workspace root, and write there. With no manifest
anywhere above, the project is standalone and the file is still created in
place — unchanged for single-package projects.
<package>><dependency>selector, e.g.'@fixture/web>@types/react': 19.2.18, so siblings keep their ownresolution. Falls back to an unqualified key with a warning if the app's
package.jsonhas noname.would set.
js-yamlcannot round-trip comments, and re-running the upgradeshould not repeatedly strip them from a file the tool does not own.
lost comments.
Verified on a real 13-package pnpm workspace running pnpm v11.21.0, upgrading
its Next.js app from 16.2.9 to 16.3.1: no
pnpm-workspace.yamlwas createdbeside the app, the root manifest gained the scoped overrides,
pnpm installcompleted across all 13 projects, and the app's
node_moduleskept itsworkspace symlinks.
Also verified on a throwaway two-package workspace, where a second run with
unchanged versions wrote nothing and printed no warning, and a run after
clearing the
overrides:block re-emitted it.Known limitation, not changed here: an actual write still drops comments from
the manifest. Preserving them means swapping
js-yamlforyaml.Fixing a bug
fixes #numberbin/__testfixtures__/pnpm-v11-workspace-overrides/,following the existing manual fixture convention in that directory:
pnpm test:upgrade-fixture bin/__testfixtures__/pnpm-v11-workspace-overrides/apps/web latestFixes #98941