Skip to content

Commit

Permalink
next-upgrade: do not add --turbopack flag when --turbo exists in …
Browse files Browse the repository at this point in the history
…`next dev` (#71730)

### Why?

1. When `next dev --turbo` existed, it added `--turbopack` since it was
looking for existing `--turbopack` only.
2. When there's no `"dev"` script found in package.json, inform the user
we weren't able to enable Turbopack for them.


- https://github.com/vercel/next.js/releases/tag/v15.0.1-canary.3

## Test Plan

### Suggest Turbopack

```
pnpm test:upgrade-fixture bin/__testfixtures__/suggest-turbopack
```

```diff
   "scripts": {
-    "dev": "next dev"
+    "dev": "next dev --turbopack"
   },
```

### Change `--turbo` to `--turbopack`

```
pnpm test:upgrade-fixture bin/__testfixtures__/change-turbo-to-turbopack
```

CLI output includes:
```
✔ Replaced "--turbo" with "--turbopack" in your dev script.
```

```diff
   "scripts": {
-    "dev": "next dev --turbo"
+    "dev": "next dev --turbopack"
   },
```
  • Loading branch information
devjiwonchoi authored Oct 23, 2024
1 parent babc6a0 commit 6fba7b2
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions packages/next-codemod/bin/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,23 +412,34 @@ function isUsingAppDir(projectPath: string): boolean {
*/
async function suggestTurbopack(packageJson: any): Promise<void> {
const devScript: string = packageJson.scripts['dev']
if (devScript?.includes('--turbopack')) return

const responseTurbopack = await prompts(
{
type: 'confirm',
name: 'enable',
message: 'Enable Turbopack for next dev?',
initial: true,
},
{ onCancel }
)

if (!responseTurbopack.enable) {
if (!devScript) {
console.log(
`${pc.red('⨯')} Could not find a "dev" script in your package.json.`
)
return
}

if (devScript.includes('next dev')) {
// covers "--turbopack" as well
if (devScript.includes('--turbo')) {
return
}

const responseTurbopack = await prompts(
{
type: 'confirm',
name: 'enable',
message: `Enable Turbopack for ${pc.bold('next dev')}?`,
initial: true,
},
{ onCancel }
)

if (!responseTurbopack.enable) {
return
}

packageJson.scripts['dev'] = devScript.replace(
'next dev',
'next dev --turbopack'
Expand Down

0 comments on commit 6fba7b2

Please sign in to comment.