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`
  • Loading branch information
devjiwonchoi committed Oct 23, 2024
1 parent bbad635 commit bb2ffde
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 bb2ffde

Please sign in to comment.