next.js
1353c788 - Always consult `npm_config_user_agent` first (#95879)

Commit
23 days ago
Always consult `npm_config_user_agent` first (#95879) The `getPkgManager` helpers previously consulted the filesystem first for files hinting at the used package manager. Only if none were found did we check `process.env.npm_config_user_agent` and then shelled out to testing which package manager is available. This change makes all helpers check the `npm_config_user_agent` environment variable first. The variable is set by the package manager that invoked the process, so when present it is both the cheapest and the most direct signal, avoiding filesystem access and subprocess spawns entirely. `create-next-app` already used this user-agent-first approach and is unchanged. The check order is now consistent across all three implementations: yarn, pnpm, bun, npm for the user agent (the `packages/next` variant has no `bun` in its `PackageManager` type and falls through to lockfile detection there), and the same order for the codemod's lockfile walk, which previously prioritized `package-lock.json`. Because the invoking package manager now takes precedence over lockfile inference, running `npx next ...` or `npx @next/codemod ...` inside a pnpm or yarn app is now detected as npm. Use `pnpx` (or `pnpm dlx`) and `yarn dlx` instead so the detected package manager matches the project.
Author
Parents
Loading