Unverified Commit 7bc06f4a authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Prefer the declared package manager during upgrades (#99471)

### Why?

Running a codemod through `npx` can select npm even when the app
declares Yarn, pnpm, or Bun, causing dependency installation to fail.

### How?

Read `package.json#packageManager` before `npm_config_user_agent`. Keep
the existing user-agent, lockfile, and npm fallbacks unchanged.

Add shared checks for installation and recovery after an interrupted
upgrade.
parent f260d466
...@@ -56,6 +56,7 @@ Canary installations support `latest` and `experimental-future` without advisory ...@@ -56,6 +56,7 @@ Canary installations support `latest` and `experimental-future` without advisory
with a reason. with a reason.
- [ ] Run the repository's checks, build when supported, and test affected - [ ] Run the repository's checks, build when supported, and test affected
runtime behavior. runtime behavior.
- [ ] Complete the verification checklist in `shared.md`.
## Deliver ## Deliver
......
...@@ -18,6 +18,8 @@ installed and target Next.js versions differ, complete the version guide first. ...@@ -18,6 +18,8 @@ installed and target Next.js versions differ, complete the version guide first.
opt-outs and TODO markers after repair. opt-outs and TODO markers after repair.
- [ ] Run the repository's checks, build when supported, and test affected - [ ] Run the repository's checks, build when supported, and test affected
runtime behavior. Verify each adoption before moving to the next. runtime behavior. Verify each adoption before moving to the next.
- [ ] Complete the verification checklist in `shared.md` for each adoption
before moving to the next.
## Deliver ## Deliver
......
...@@ -18,6 +18,7 @@ follow a major-version migration guide for this same-major update. ...@@ -18,6 +18,7 @@ follow a major-version migration guide for this same-major update.
- [ ] Confirm the installed version with `next --version`. - [ ] Confirm the installed version with `next --version`.
- [ ] Verify the app works with the updated dependencies and resolve any issues - [ ] Verify the app works with the updated dependencies and resolve any issues
caused by the update. caused by the update.
- [ ] Complete the verification checklist in `shared.md`.
## Deliver ## Deliver
......
--- ---
title: Shared agentic Next.js upgrade checks and delivery title: Shared agentic Next.js upgrade checks and delivery
description: Duplicate checks and delivery for all agentic Next.js upgrade policies. description: Duplicate checks, verification, and delivery for all agentic Next.js upgrade policies.
version: draft version: draft
--- ---
...@@ -28,6 +28,23 @@ provider lookup. If a check is unavailable or fails, report which work could ...@@ -28,6 +28,23 @@ provider lookup. If a check is unavailable or fails, report which work could
not be checked and continue the upgrade. Stop before changing files only if not be checked and continue the upgrade. Stop before changing files only if
you find equivalent work. you find equivalent work.
## Verify
Complete this checklist after updating dependencies and for each Future Defaults
adoption, before moving on to delivery or the next adoption.
- [ ] Confirm dependencies install successfully with the app's package manager
from its install root (the workspace root for a monorepo). Detect the
manager from `package.json` and workspace configuration, using lockfiles
as supporting evidence. Preserve its configured version and dependency
policies.
- [ ] If an upgrade or adoption command failed, inspect its partial changes,
resolve the failure, and complete any remaining steps before running
checks. Do not repeat completed codemods.
- [ ] Confirm the installed Next.js version with `next --version` using the
app's package manager. It must match the exact target in the prompt.
- [ ] Resolve issues caused by the update or adoption before continuing.
## After all upgrade and adoption steps: commit and deliver ## After all upgrade and adoption steps: commit and deliver
- [ ] If the app is in a Git repository, commit the verified version update - [ ] If the app is in a Git repository, commit the verified version update
......
import findUp from 'find-up' import findUp from 'find-up'
import execa from 'execa' import execa from 'execa'
import { execSync } from 'node:child_process' import { execSync } from 'node:child_process'
import { basename } from 'node:path' import { existsSync, readFileSync } from 'node:fs'
import { basename, join } from 'node:path'
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun' export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun'
...@@ -54,6 +55,19 @@ export function getPnpmMajorVersion(): number | null { ...@@ -54,6 +55,19 @@ export function getPnpmMajorVersion(): number | null {
export function getPkgManager(baseDir: string): PackageManager { export function getPkgManager(baseDir: string): PackageManager {
try { try {
// The app's declared manager takes precedence over the command launcher.
const manifestPath = join(baseDir, 'package.json')
if (existsSync(manifestPath)) {
const { packageManager } = JSON.parse(readFileSync(manifestPath, 'utf8'))
const match =
typeof packageManager === 'string'
? packageManager.match(/^(npm|pnpm|yarn|bun)@/)
: null
if (match) {
return match[1] as PackageManager
}
}
const userAgent = process.env.npm_config_user_agent const userAgent = process.env.npm_config_user_agent
if (userAgent) { if (userAgent) {
if (userAgent.startsWith('yarn')) { if (userAgent.startsWith('yarn')) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment