Unverified Commit dc1901a2 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

next-upgrade: change `--turbo` to `--turbopack` if applicable (#71737)

parent dfa35c46
Change `--turbo` to `--turbopack` in `next dev` script.
{
"name": "change-turbo-to-turbopack",
"scripts": {
"dev": "next dev --turbo"
},
"dependencies": {
"next": "15.0.0-canary.0",
"react": "19.0.0-rc.0",
"react-dom": "19.0.0-rc.0"
}
}
Suggest adding `--turbopack` to `next dev` script.
{
"name": "suggest-turbopack",
"scripts": {
"dev": "next dev"
},
"dependencies": {
"next": "15.0.0-canary.0",
"react": "19.0.0-rc.0",
"react-dom": "19.0.0-rc.0"
}
}
......@@ -177,7 +177,7 @@ export async function runUpgrade(
)
if (compareVersions(targetNextVersion, '15.0.0-canary') >= 0) {
await suggestTurbopack(appPackageJson)
await suggestTurbopack(appPackageJson, targetNextVersion)
}
const codemods = await suggestCodemods(
......@@ -410,12 +410,21 @@ function isUsingAppDir(projectPath: string): boolean {
* 3. Otherwise, we ask the user to manually add `--turbopack` to their dev command,
* showing the current dev command as the initial value.
*/
async function suggestTurbopack(packageJson: any): Promise<void> {
async function suggestTurbopack(
packageJson: any,
targetNextVersion: string
): Promise<void> {
const devScript: string = packageJson.scripts['dev']
// Turbopack flag was changed from `--turbo` to `--turbopack` in v15.0.1-canary.3
// PR: https://github.com/vercel/next.js/pull/71657
// Release: https://github.com/vercel/next.js/releases/tag/v15.0.1-canary.3
const isAfterTurbopackFlagChange =
compareVersions(targetNextVersion, '15.0.1-canary.3') >= 0
const turboPackFlag = isAfterTurbopackFlagChange ? '--turbopack' : '--turbo'
if (!devScript) {
console.log(
`${pc.red('⨯')} Could not find a "dev" script in your package.json.`
`${pc.yellow('⚠')} No "dev" script found in your package.json. Skipping Turbopack suggestion.`
)
return
}
......@@ -423,6 +432,15 @@ async function suggestTurbopack(packageJson: any): Promise<void> {
if (devScript.includes('next dev')) {
// covers "--turbopack" as well
if (devScript.includes('--turbo')) {
if (isAfterTurbopackFlagChange && !devScript.includes('--turbopack')) {
console.log() // new line
console.log(
`${pc.green('✔')} Replaced "--turbo" with "--turbopack" in your dev script.`
)
console.log() // new line
packageJson.scripts['dev'] = devScript.replace('--turbo', '--turbopack')
return
}
return
}
......@@ -442,7 +460,7 @@ async function suggestTurbopack(packageJson: any): Promise<void> {
packageJson.scripts['dev'] = devScript.replace(
'next dev',
'next dev --turbopack'
`next dev ${turboPackFlag}`
)
return
}
......@@ -455,7 +473,7 @@ async function suggestTurbopack(packageJson: any): Promise<void> {
{
type: 'text',
name: 'customDevScript',
message: 'Please manually add "--turbopack" to your dev command.',
message: `Please manually add "${turboPackFlag}" to your dev command.`,
initial: devScript,
},
{ onCancel }
......
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