@@ -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