Skip to content

Commit 76c0cf0

Browse files
committed
[next-upgrade] Fall back to npx if yarn dlx is not available
1 parent 5b97f1f commit 76c0cf0

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

packages/next-codemod/bin/upgrade.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export async function runUpgrade(
203203

204204
let shouldRunReactCodemods = false
205205
let shouldRunReactTypesCodemods = false
206-
let execCommand = 'npx'
206+
let execCommand = 'npx --yes'
207207
// The following React codemods are for React 19
208208
if (
209209
!shouldStayOnReact18 &&
@@ -213,13 +213,7 @@ export async function runUpgrade(
213213
shouldRunReactCodemods = await suggestReactCodemods()
214214
shouldRunReactTypesCodemods = await suggestReactTypesCodemods()
215215

216-
const execCommandMap = {
217-
yarn: 'yarn dlx',
218-
pnpm: 'pnpx',
219-
bun: 'bunx',
220-
npm: 'npx',
221-
}
222-
execCommand = execCommandMap[packageManager]
216+
execCommand = getNpxCommand(packageManager)
223217
}
224218

225219
fs.writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2))
@@ -740,3 +734,17 @@ function warnDependenciesOutOfRange(
740734
})
741735
}
742736
}
737+
738+
function getNpxCommand(pkgManager: PackageManager) {
739+
let command = 'npx --yes'
740+
if (pkgManager === 'pnpm') {
741+
command = 'pnpm --silent dlx'
742+
} else if (pkgManager === 'yarn') {
743+
try {
744+
execSync('yarn dlx --help', { stdio: 'ignore', cwd })
745+
command = 'yarn --quiet dlx'
746+
} catch {}
747+
}
748+
749+
return command
750+
}

0 commit comments

Comments
 (0)