← Back to Pull requests

Fix codemod upgrades inside pnpm workspaces #102611

Open
devjiwonchoi opened this pull request with 305 lines diff across 9 files
View on GitHub
devjiwonchoi devjiwonchoi commented on Nov 30, 2026 22:54 UTC
Author

Why?

Running @next/codemod upgrade from an app inside a pnpm 11+ workspace created <app>/pnpm-workspace.yaml, so pnpm install failed 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.yaml for pnpm, the nearest package.json with workspaces otherwise, stopping at the git root) and accepts --package-manager to skip detection. The scheduled next upgrade --agent handoff finds the lockfile in the app or a parent directory up to the repository root and passes --package-manager to the codemod, since under npx it would otherwise pick npm.

Diff: 305 lines (+290 / -15) across 9 files Reviewer: devjiwonchoi Review duration: 2993m
All Vouch review confidence checks passed
Residual risk 0.13 = Change Risk (0.63) × (1 − Review Confidence (0.80)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.63 · 305 lines diff across 9 files
0.63
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.84 · 5 substantive comment(s)
0.84
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
80%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.342
Self Review self_review
0.140
Real PR Conversation Timeline
8 items
github-actions[bot] github-actions[bot] commented on Nov 30, 2026 22:55 UTC
Bot
vercel[bot] vercel[bot] commented on Dec 01, 2026 12:14 UTC
Bot

<!-- vercel-agent-verified-review-status -->
<!-- vercel-agent-review-parts:3Zjhctu4EcdfZQc308YeUhRlW5ZUx5ncJXeT1nGuTi7XNsxEILgUEZMAC4CSNZl0-qmv0Om3Pkif5l6gr9BZkLRkx845H9r08smkTCwW2B_-i913zKBAWTs2e8XOuIIjgyV3comhkxVCxh3Sw_2EjYajcRiPwmH8Ih7NDqa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_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>

  • The pnpm branch of findOverridesDir takes the nearest pnpm\-workspace\.yaml without checking that its 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?

  • For pnpm &lt; 11, when the workspace root has a pnpm\-workspace\.yaml but no package\.json, the 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>

    | &nbsp;&nbsp;&nbsp;&nbsp; | 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>

    | &nbsp;&nbsp;&nbsp;&nbsp; | 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>

    vercel[bot] vercel[bot] commented on code on Dec 01, 2026 12:14 UTC
    Code Review
    packages/next-codemod/bin/upgrade.ts:1
    @@ -452,7 +464,28 @@ export async function runUpgrade(
         overrides['@types/react-dom'] = versionMapping['@types/react-dom'].version
       }
     
    -  writeOverridesField(appPackageJson, packageManager, overrides)
    +  // A workspace reads overrides from its root only, so write them there.
    +  const overridesDir = findOverridesDir(packageManager)
    +  if (overridesDir === cwd) {
    +    writeOverridesField(appPackageJson, packageManager, overrides, cwd)
    +  } else {
    +    const rootPackageJsonPath = path.join(overridesDir, 'package.json')
    +    const rootPackageJson = fs.existsSync(rootPackageJsonPath)
    +      ? JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'))
    +      : null
    +    writeOverridesField(
    +      rootPackageJson ?? {},
    +      packageManager,
    +      overrides,
    +      overridesDir
    +    )
    +    if (rootPackageJson !== null && Object.keys(overrides).length > 0) {

    [!NOTE]

    Unverified · Minor — Root package\.json is rewritten even when pnpm v11 leaves it unchanged

    > With pnpm v11\+ in a workspace, writeOverridesField puts the overrides in the root pnpm-workspace.yaml and returns without changing the root package.json\. The code then writes the root package.json anyway, as JSON.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 -->

    devjiwonchoi devjiwonchoi commented on code on Dec 01, 2026 12:31 UTC
    Code Review
    packages/next-codemod/bin/upgrade.ts:1
    @@ -452,7 +464,28 @@ export async function runUpgrade(
         overrides['@types/react-dom'] = versionMapping['@types/react-dom'].version
       }
     
    -  writeOverridesField(appPackageJson, packageManager, overrides)
    +  // A workspace reads overrides from its root only, so write them there.
    +  const overridesDir = findOverridesDir(packageManager)
    +  if (overridesDir === cwd) {
    +    writeOverridesField(appPackageJson, packageManager, overrides, cwd)
    +  } else {
    +    const rootPackageJsonPath = path.join(overridesDir, 'package.json')
    +    const rootPackageJson = fs.existsSync(rootPackageJsonPath)
    +      ? JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'))
    +      : null
    +    writeOverridesField(
    +      rootPackageJson ?? {},
    +      packageManager,
    +      overrides,
    +      overridesDir
    +    )
    +    if (rootPackageJson !== null && Object.keys(overrides).length > 0) {

    🤖 Fixed in 61573e816a9: the root package.json is now rewritten only when an override actually changed it, so pnpm v11 leaves its formatting alone.

    vercel[bot] vercel[bot] commented on code on Dec 01, 2026 12:33 UTC
    Code Review
    packages/next-codemod/bin/upgrade.ts:1
    @@ -802,10 +841,51 @@ async function suggestReactTypesCodemods(
       return runReactTypesCodemod
     }
     
    +/**
    + * The directory whose manifest holds overrides: the workspace root when the
    + * app is a workspace member, otherwise the app. pnpm's root is the nearest
    + * `pnpm-workspace.yaml`; npm, Yarn and Bun use the nearest `package.json` with
    + * `workspaces`. The search stops at the git root.
    + */
    +function findOverridesDir(packageManager: PackageManager): string {
    +  const found = findUp.sync(
    +    (directory) => {
    +      if (packageManager === 'pnpm') {
    +        if (fs.existsSync(path.join(directory, 'pnpm-workspace.yaml'))) {
    +          return directory
    +        }
    +      } else {
    +        const manifestPath = path.join(directory, 'package.json')
    +        if (fs.existsSync(manifestPath)) {
    +          try {
    +            const { workspaces } = JSON.parse(
    +              fs.readFileSync(manifestPath, 'utf8')

    [!NOTE]

    Unverified · Minor — Overrides go to a parent workspace that doesn't include the app

    > findOverridesDir treats any ancestor package\.json that has workspaces \(up to \.git\) as the app's root\. It never checks that the app matches those workspace globs\. Take an app in docs/ under a root with workspaces: ["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\), so npm install in docs/ 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 -->

    devjiwonchoi devjiwonchoi commented on code on Dec 01, 2026 12:57 UTC
    Code Review
    packages/next-codemod/bin/upgrade.ts:1
    @@ -802,10 +841,51 @@ async function suggestReactTypesCodemods(
       return runReactTypesCodemod
     }
     
    +/**
    + * The directory whose manifest holds overrides: the workspace root when the
    + * app is a workspace member, otherwise the app. pnpm's root is the nearest
    + * `pnpm-workspace.yaml`; npm, Yarn and Bun use the nearest `package.json` with
    + * `workspaces`. The search stops at the git root.
    + */
    +function findOverridesDir(packageManager: PackageManager): string {
    +  const found = findUp.sync(
    +    (directory) => {
    +      if (packageManager === 'pnpm') {
    +        if (fs.existsSync(path.join(directory, 'pnpm-workspace.yaml'))) {
    +          return directory
    +        }
    +      } else {
    +        const manifestPath = path.join(directory, 'package.json')
    +        if (fs.existsSync(manifestPath)) {
    +          try {
    +            const { workspaces } = JSON.parse(
    +              fs.readFileSync(manifestPath, 'utf8')

    🤖 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.

    vercel[bot] vercel[bot] approved these changes on Dec 01, 2026 12:59 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    devjiwonchoi devjiwonchoi
    Labels
    risk: low confidence: 80% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 63.0% (MEDIUM) · Higher = larger blast radius
    63.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 80% · Lower = rushed or shallow review
    80%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.6% · Safe to merge
    12.6%
    Repository