Skip to content

Commit dc1901a

Browse files
authored
next-upgrade: change --turbo to --turbopack if applicable (#71737)
1 parent dfa35c4 commit dc1901a

File tree

7 files changed

+47
-5
lines changed

7 files changed

+47
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change `--turbo` to `--turbopack` in `next dev` script.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "change-turbo-to-turbopack",
3+
"scripts": {
4+
"dev": "next dev --turbo"
5+
},
6+
"dependencies": {
7+
"next": "15.0.0-canary.0",
8+
"react": "19.0.0-rc.0",
9+
"react-dom": "19.0.0-rc.0"
10+
}
11+
}

packages/next-codemod/bin/__testfixtures__/change-turbo-to-turbopack/pnpm-workspace.yaml

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Suggest adding `--turbopack` to `next dev` script.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "suggest-turbopack",
3+
"scripts": {
4+
"dev": "next dev"
5+
},
6+
"dependencies": {
7+
"next": "15.0.0-canary.0",
8+
"react": "19.0.0-rc.0",
9+
"react-dom": "19.0.0-rc.0"
10+
}
11+
}

packages/next-codemod/bin/__testfixtures__/suggest-turbopack/pnpm-workspace.yaml

Whitespace-only changes.

packages/next-codemod/bin/upgrade.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export async function runUpgrade(
177177
)
178178

179179
if (compareVersions(targetNextVersion, '15.0.0-canary') >= 0) {
180-
await suggestTurbopack(appPackageJson)
180+
await suggestTurbopack(appPackageJson, targetNextVersion)
181181
}
182182

183183
const codemods = await suggestCodemods(
@@ -410,19 +410,37 @@ function isUsingAppDir(projectPath: string): boolean {
410410
* 3. Otherwise, we ask the user to manually add `--turbopack` to their dev command,
411411
* showing the current dev command as the initial value.
412412
*/
413-
async function suggestTurbopack(packageJson: any): Promise<void> {
413+
async function suggestTurbopack(
414+
packageJson: any,
415+
targetNextVersion: string
416+
): Promise<void> {
414417
const devScript: string = packageJson.scripts['dev']
418+
// Turbopack flag was changed from `--turbo` to `--turbopack` in v15.0.1-canary.3
419+
// PR: https://github.com/vercel/next.js/pull/71657
420+
// Release: https://github.com/vercel/next.js/releases/tag/v15.0.1-canary.3
421+
const isAfterTurbopackFlagChange =
422+
compareVersions(targetNextVersion, '15.0.1-canary.3') >= 0
423+
const turboPackFlag = isAfterTurbopackFlagChange ? '--turbopack' : '--turbo'
415424

416425
if (!devScript) {
417426
console.log(
418-
`${pc.red('⨯')} Could not find a "dev" script in your package.json.`
427+
`${pc.yellow('⚠')} No "dev" script found in your package.json. Skipping Turbopack suggestion.`
419428
)
420429
return
421430
}
422431

423432
if (devScript.includes('next dev')) {
424433
// covers "--turbopack" as well
425434
if (devScript.includes('--turbo')) {
435+
if (isAfterTurbopackFlagChange && !devScript.includes('--turbopack')) {
436+
console.log() // new line
437+
console.log(
438+
`${pc.green('✔')} Replaced "--turbo" with "--turbopack" in your dev script.`
439+
)
440+
console.log() // new line
441+
packageJson.scripts['dev'] = devScript.replace('--turbo', '--turbopack')
442+
return
443+
}
426444
return
427445
}
428446

@@ -442,7 +460,7 @@ async function suggestTurbopack(packageJson: any): Promise<void> {
442460

443461
packageJson.scripts['dev'] = devScript.replace(
444462
'next dev',
445-
'next dev --turbopack'
463+
`next dev ${turboPackFlag}`
446464
)
447465
return
448466
}
@@ -455,7 +473,7 @@ async function suggestTurbopack(packageJson: any): Promise<void> {
455473
{
456474
type: 'text',
457475
name: 'customDevScript',
458-
message: 'Please manually add "--turbopack" to your dev command.',
476+
message: `Please manually add "${turboPackFlag}" to your dev command.`,
459477
initial: devScript,
460478
},
461479
{ onCancel }

0 commit comments

Comments
 (0)