Fix codemod upgrades inside pnpm workspaces #102611
<!-- __NEXT_TEST_REPORT_COMMENT__ -->
Failing CI jobs
Commit: 4876cf533bdb164ae26dd002e38f3199f2b308b0 | About building and testing Next.js
<!-- vercel-agent-verified-review-status -->
<!-- vercel-agent-review-parts:3Zjhctu4EcdfZQc308YeUhRlW5ZUx5ncJXeT1nGuTi7XNsxEILgUEZMAC4CSNZl0-qmv0Om3Pkif5l6gr9BZkLRkx845H9r08smkTCwW2B_-i913zKBAWTs2e8XOuIIjgyV3comhkxVCxh3Sw_2EjYajcRiPwmH8Ih7NDqaz_dFgeHDwp4Qdv2gwgGEMj1AAfQb9B_Dd0xdH0RWTxyxgowqmlgXs1e7uGfIMXIEgdIZgcClxBQZrbRz89Le_7-6-vlc4V9tZFC3RCCwHQlfdY_SXiC9QOXqVuRTcSa1sNIyfTs5exsNvTiffPP3d5NHkdPo4_v2j0x9Pd9jrgNUGcy6QzV69DphtqoqbNZuxF50Plc5-baGpF4ZnCEqvYGWkQwv__tc_3bpGGxnkwoFeojEyQwvc-QWstDm3NRcIRmsHhrsCDbiCK5DKf8HrOklm_lEhN2gd1KqukiS8HJskgzWvSsi18f8LQJurA7g45wv67q3VClaFtgjzy_F2DotSpxYq7kTRz-rN0bP2PnU2oOKKL9DYAKzTdS3Vol_LQjq_iiQZwBMHvLQauBBYOwvzMOwMhJ2BOX1G-2dFgVlTYgZzhRfuchfD0MdpDgVXmc5zv62l1ufWe8ah1OI8lyVu7RRwldFrzQ0qB5k0KJw2Eik44LT_jkDxjgb-85pbizd62A_oIuzXBYYrcGhd1CjpWpSkSJKwcztJwtroqnY2SQb0Hf2xoFsXCwKXJuVlCdNDb8h6D_rd2NDkgaD1NjUU3ILSwBunK-4wg9byDKQDaUEQV5iBVuUa0rWfquKq4SXk8sI1Btulmkb90DOKmNkOEkckBGA1PIH2VNAMBXdgZYZk0CDPKNL9biTJgAXszw1af3rY7B0rpUJLghD6dRCHkBquRAE6h1yq7FkP_yNpwPFztHeieiVdo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3GdP0yj7gXG6KVuqv9oC8K4QxaPpZ4MoHk3Dk3jvCxYoyoV9FdmVe7fB5GWHEuamLKU4t_VTe0EjuHhHXa4blUFudLVVkPpSqr0hVxWNE7zTM6GV41K1F0Svj9rAmht1E4mUDU86k9-3jj7tvCSjNEFe8gUZtc40widV7oAqMRiPpnRdp-5MW7ygdd6FT65dKZlPD_2-Xb8K7oHC1aYOp-v_x4n3WG1jf_Bfxz6yRkSilNG1ub86iQ-I-8PD69zfNuIXCn53itv-Q3cIvHR1pYflFclWidwilas-OzdKUZB9QyZJ7s3fvDl9_IcXb14-Pnv-5NnpPEl2POSS2jwkeWs4V3rVF_QrD-ZNTPs6snfpJRpLzApdofWH6JPgGcfjzwfPOB6HJ-O9vU-Ch3qHDmv7MzXtVs-SaJEiaqGJ_E5fJ2b4UWIeaYXbvGzYeM5VluoLsEg9t6ub3UIVjweHtmfq4-T_b1x-SOer6_fOYNTrqyVeb1xABQfx_9UKzrA22vv7QUuQXlI6g_eGO4EXf6kWFjxAGf144woHk836XgdMade3U8gwpYLPJFVn3gZmge911h8K1-7uSz8htFF92Tce24G7u3BkqWfbmXu43ev31WV706Jdy2SeX26h_4wbn5elo0qEthLSZmF9W5qafuqnv_7DtUEwPiH2PRX6wlIPNJPCQbfwdpK6KUsw6HueNIzbrhHd1iJ2kLDjByRc9XE_kByS9spIapsStZJgeNWJ0l1ErB10ZxnbYe__Aw -->
<img src="https://agents-vade-review.vercel.sh/review-status-approved.svg" width="16" valign="middle" title="Reviewed, all passed" alt=""> Vercel Agent Verified Review <sup title="A code review: it reads the diff and the code around it to find bugs. It doesn’t run or test the app. Its verdict approves the pull request or asks for changes.">?</sup> approved this pull request.
<sub>4876cf5 • Ran <relative-time datetime="2026-12-01T12:59:42.055Z">Tue, 01 Dec 2026 12:59:42 GMT</relative-time> • 2m 9s • Read the code review report ↗</sub>
<details>
<summary>Summary</summary>
<sub> </sub>
The codemod's upgrade now writes @types/react overrides at the workspace root rather than in the app\: the nearest pnpm\-workspace\.yaml for pnpm, or the nearest package\.json whose workspaces globs match the app for the other package managers, stopping at the git root\. It also accepts --package-manager\. The scheduled next upgrade --agent handoff now looks for a lockfile in the app and in parent directories up to the repo root, and passes --package-manager to the codemod\. I ran test/unit/agentic\-upgrade\-prompts\.test\.ts on the head and all 97 tests pass\. The codemod's root lookup has no automated test\: it is covered only by the manual fixture, and runUpgrade needs the network, so I verified that side by reading the code\.
</details>
<details>
<summary>Questions for the author (2)</summary>
<sub> </sub>
packages globs include the app, while the npm/Yarn/Bun branch does check\. Is that on purpose, because pnpm treats any directory under a pnpm\-workspace\.yaml as part of the workspace?pnpm.overrides are applied to a throwaway {} and never written anywhere\. Should the code warn in that case?</details>
<details open>
<summary>Checked (6)</summary>
<sub> </sub>
| | Check | Location |
| :-: | :-- | :-- |
| <img src="https://agents-vade-review.vercel.sh/review-status-approved.svg" width="16" valign="middle" title="Passed" alt=""> <samp>Passed</samp> | For npm, Yarn and Bun, a parent package\.json is the root only when its workspaces globs match the app \(fixes earlier f1\)\.<br><sub><i>Read the globby match, which compares each resolved match with cwd, including the workspaces.packages object form\.</i></sub> | upgrade.ts:858 |
| <img src="https://agents-vade-review.vercel.sh/review-status-approved.svg" width="16" valign="middle" title="Passed" alt=""> <samp>Passed</samp> | The search for the overrides root stops at the git root, after checking that directory itself\.<br><sub><i>Read the matcher\: it checks the workspace condition first and returns findUp\.stop only after that, when .git exists\.</i></sub> | upgrade.ts:891 |
| <img src="https://agents-vade-review.vercel.sh/review-status-approved.svg" width="16" valign="middle" title="Passed" alt=""> <samp>Passed</samp> | When overrides go to a pnpm v11 workspace yaml, the root package\.json is rewritten only if an override actually changed it\.<br><sub><i>Read the JSON\.stringify before/after comparison that guards writeFileSync\.</i></sub> | upgrade.ts:468 |
| <img src="https://agents-vade-review.vercel.sh/review-status-approved.svg" width="16" valign="middle" title="Passed" alt=""> <samp>Passed</samp> | An invalid \-\-package\-manager value is rejected with BadInput before any file is touched\.<br><sub><i>Read the guard at the top of runUpgrade, which runs before any file reads or writes\.</i></sub> | upgrade.ts:129 |
| <img src="https://agents-vade-review.vercel.sh/review-status-approved.svg" width="16" valign="middle" title="Passed" alt=""> <samp>Passed</samp> | The handoff passes \-\-package\-manager only for scheduled runs, and only with a value found from a lockfile, so the command can only contain npm, pnpm or yarn\.<br><sub><i>Read findLockfilePackageManager and the flag construction at line 629\. Ran pnpm testonly test/unit/agentic\-upgrade\-prompts\.test\.ts\: 97 pass, including the 3 new lockfile cases\.</i></sub> | next-upgrade.ts:159 |
| <img src="https://agents-vade-review.vercel.sh/review-status-approved.svg" width="16" valign="middle" title="Passed" alt=""> <samp>Passed</samp> | The codemod the handoff runs is the same release as the running next \(__NEXT_VERSION\), so it already knows the new flag\.<br><sub><i>Read where codemodVersion comes from\.</i></sub> | next-upgrade.ts:616 |
</details>
<details>
<summary>Review steps</summary>
<sub> </sub>
| | Step | Time |
| :-: | :-- | --: |
| <img src="https://vercel.com/static/status/ready.svg" width="10" valign="middle" title="Done" alt=""> | Sandbox set up | <samp>16.7s</samp> |
| <img src="https://vercel.com/static/status/ready.svg" width="10" valign="middle" title="Done" alt=""> | Agent review: 2 commands run | <samp>1m 51s</samp> |
| <img src="https://vercel.com/static/status/ready.svg" width="10" valign="middle" title="Done" alt=""> | Repros run on the head and the base (0), findings graded (0) | <samp>1.8s</samp> |
</details>
[!NOTE]
Unverified · Minor — Root package\.json is rewritten even when pnpm v11 leaves it unchanged
> With pnpm v11\+ in a workspace,writeOverridesFieldputs the overrides in the rootpnpm-workspace.yamland returns without changing the rootpackage.json\. The code then writes the rootpackage.jsonanyway, asJSON.stringify(…, null, 2) + os.EOL\. A root manifest indented with tabs or 4 spaces, or with CRLF or no final newline, gets a whole\-file formatting diff for no reason\.
> Needs your judgment: the review traced this through the code but couldn’t run anything to prove it.
<!-- vercel-agent-verified-review-finding:f1 -->
<!-- vercel-agent-verified-review-decision:COMMENT:verdict -->
🤖 Fixed in 61573e816a9: the root package.json is now rewritten only when an override actually changed it, so pnpm v11 leaves its formatting alone.
[!NOTE]
Unverified · Minor — Overrides go to a parent workspace that doesn't include the app
> findOverridesDir treats any ancestor package\.json that hasworkspaces\(up to \.git\) as the app's root\. It never checks that the app matches those workspace globs\. Take an app indocs/under a root withworkspaces: ["packages/*"]\: npm's config only adopts a parent as localPrefix when cwd is one of its mapped workspaces \(@npmcli/config lib/index\.js, mapWorkspaces around line 738\), sonpm installindocs/treats it as a standalone project\. The overrides now land in the root package\.json, which that install ignores\. Before this change they were written to the app's package\.json and took effect, so for this layout the change is a regression\.
> Needs your judgment: the review traced this through the code but couldn’t run anything to prove it.
<!-- vercel-agent-verified-review-finding:f1 -->
<!-- vercel-agent-verified-review-decision:COMMENT:verdict -->
🤖 Fixed: for npm, Yarn, and Bun, a parent package.json now counts as the workspace root only when its workspaces patterns match the app directory (expanded with globby, negations included). An app outside them keeps its overrides in its own package.json as before.
Approved these changes.
devjiwonchoi
Why?
Running
@next/codemod upgradefrom an app inside a pnpm 11+ workspace created<app>/pnpm-workspace.yaml, sopnpm installfailed with"ui@workspace:*" ... no package named "ui" is present in the workspace.How?
The codemod now writes overrides at the workspace root (the nearest
pnpm-workspace.yamlfor pnpm, the nearestpackage.jsonwithworkspacesotherwise, stopping at the git root) and accepts--package-managerto skip detection. The schedulednext upgrade --agenthandoff finds the lockfile in the app or a parent directory up to the repository root and passes--package-managerto the codemod, since undernpxit would otherwise pick npm.