From 2e57c5b255ceaaee0c8ed47b4b00c5a0c0de199a Mon Sep 17 00:00:00 2001 From: Arindam Majumder Date: Sat, 18 May 2024 15:03:39 +0000 Subject: [PATCH 01/14] feat: Add option to enable Turbopack with create-next-app Signed-off-by: Arindam Majumder --- .../02-api-reference/06-create-next-app.mdx | 1 + packages/create-next-app/create-app.ts | 12 ++++++++++++ packages/create-next-app/index.ts | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/docs/02-app/02-api-reference/06-create-next-app.mdx b/docs/02-app/02-api-reference/06-create-next-app.mdx index 7590067d62c2d..5dcceb8648268 100644 --- a/docs/02-app/02-api-reference/06-create-next-app.mdx +++ b/docs/02-app/02-api-reference/06-create-next-app.mdx @@ -39,6 +39,7 @@ Would you like to use Tailwind CSS? No / Yes Would you like to use `src/` directory? No / Yes Would you like to use App Router? (recommended) No / Yes Would you like to customize the default import alias (@/*)? No / Yes +Would you like to use Turbopack for next dev? (RC) No / Yes ``` Once you've answered the prompts, a new project will be created with the correct configuration depending on your answers. diff --git a/packages/create-next-app/create-app.ts b/packages/create-next-app/create-app.ts index cbd7d2110b25d..bef3b0b7e6637 100644 --- a/packages/create-next-app/create-app.ts +++ b/packages/create-next-app/create-app.ts @@ -36,6 +36,7 @@ export async function createApp({ importAlias, skipInstall, empty, + turbo, }: { appPath: string packageManager: PackageManager @@ -49,6 +50,7 @@ export async function createApp({ importAlias: string skipInstall: boolean empty: boolean + turbo: boolean }): Promise { let repoInfo: RepoInfo | undefined const mode: TemplateMode = typescript ? 'ts' : 'js' @@ -237,6 +239,16 @@ export async function createApp({ console.log() } + if (hasPackageJson) { + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) + if (turbo) { + packageJson.scripts.dev = 'next dev --turbo' + } else { + packageJson.scripts.dev = 'next dev' + } + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)) + } + let cdpath: string if (path.join(originalDirectory, appName) === appPath) { cdpath = appName diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 972d8237986d2..eb2502a83f5ac 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -439,6 +439,24 @@ async function run(): Promise { } } } + if (!process.argv.includes('--turbo') && !process.argv.includes('--no-turbo')) { + if (ciInfo.isCI) { + program.turbo = getPrefOrDefault('turbo') + } else { + const styledTurbo = blue('Turbopack') + const { turbo } = await prompts({ + onState: onPromptState, + type: 'toggle', + name: 'turbo', + message: `Would you like to use ${styledTurbo} for next dev? (RC)`, + initial: getPrefOrDefault('turbo'), + active: 'Yes', + inactive: 'No', + }) + program.turbo = Boolean(turbo) + preferences.turbo = Boolean(turbo) + } + } } try { From 3ab23347ec8decc06a6e73848414c201f922be04 Mon Sep 17 00:00:00 2001 From: Arindam Majumder Date: Sat, 18 May 2024 16:22:00 +0000 Subject: [PATCH 02/14] fix: Add more checks and docs update Signed-off-by: Arindam Majumder --- .../02-api-reference/06-create-next-app.mdx | 4 ++++ packages/create-next-app/README.md | 4 ++++ packages/create-next-app/index.ts | 21 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/02-app/02-api-reference/06-create-next-app.mdx b/docs/02-app/02-api-reference/06-create-next-app.mdx index 5dcceb8648268..55cbd66a6ae61 100644 --- a/docs/02-app/02-api-reference/06-create-next-app.mdx +++ b/docs/02-app/02-api-reference/06-create-next-app.mdx @@ -81,6 +81,10 @@ Options: Initialize inside a `src/` directory. + --turbo + + Enable Turbopack by default for development. + --import-alias Specify import alias to use (default "@/*"). diff --git a/packages/create-next-app/README.md b/packages/create-next-app/README.md index ddb56d3577329..d6488cb8b699b 100644 --- a/packages/create-next-app/README.md +++ b/packages/create-next-app/README.md @@ -59,6 +59,10 @@ Options: Initialize inside a `src/` directory. + --turbo + + Enable Turbopack by default for development. + --import-alias Specify import alias to use (default "@/*"). diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index eb2502a83f5ac..351dc2c6e7cb3 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -272,6 +272,7 @@ async function run(): Promise { importAlias: '@/*', customizeImportAlias: false, empty: false, + turbo: false, } const getPrefOrDefault = (field: string) => preferences[field] ?? defaults[field] @@ -395,7 +396,24 @@ async function run(): Promise { program.app = Boolean(appRouter) } } - + if (!process.argv.includes('--turbo') && !process.argv.includes('--no-turbo')) { + if (ciInfo.isCI) { + program.turbo = getPrefOrDefault('turbo') + } else { + const styledTurbo = blue('Turbopack') + const { turbo } = await prompts({ + onState: onPromptState, + type: 'toggle', + name: 'turbo', + message: `Would you like to use ${styledTurbo} for next dev? (RC)`, + initial: getPrefOrDefault('turbo'), + active: 'Yes', + inactive: 'No', + }) + program.turbo = Boolean(turbo) + preferences.turbo = Boolean(turbo) + } + } const importAliasPattern = /^[^*"]+\/\*\s*$/ if ( typeof program.importAlias !== 'string' || @@ -473,6 +491,7 @@ async function run(): Promise { importAlias: program.importAlias, skipInstall: program.skipInstall, empty: program.empty, + turbo: program.turbo, }) } catch (reason) { if (!(reason instanceof DownloadError)) { From 695a90565c3080f8e2ae4a88302be149fd4b5508 Mon Sep 17 00:00:00 2001 From: Arindam Majumder <109217591+Arindam200@users.noreply.github.com> Date: Sat, 18 May 2024 21:58:00 +0530 Subject: [PATCH 03/14] Update docs/02-app/02-api-reference/06-create-next-app.mdx Co-authored-by: Lee Robinson --- docs/02-app/02-api-reference/06-create-next-app.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/02-app/02-api-reference/06-create-next-app.mdx b/docs/02-app/02-api-reference/06-create-next-app.mdx index 55cbd66a6ae61..db786a61947d9 100644 --- a/docs/02-app/02-api-reference/06-create-next-app.mdx +++ b/docs/02-app/02-api-reference/06-create-next-app.mdx @@ -39,7 +39,7 @@ Would you like to use Tailwind CSS? No / Yes Would you like to use `src/` directory? No / Yes Would you like to use App Router? (recommended) No / Yes Would you like to customize the default import alias (@/*)? No / Yes -Would you like to use Turbopack for next dev? (RC) No / Yes +Would you like to use Turbopack for `next dev`? (RC) No / Yes ``` Once you've answered the prompts, a new project will be created with the correct configuration depending on your answers. From f7e7b5d67299dad789354868a6730601efd7096a Mon Sep 17 00:00:00 2001 From: Arindam Majumder <109217591+Arindam200@users.noreply.github.com> Date: Sat, 18 May 2024 21:58:19 +0530 Subject: [PATCH 04/14] Update packages/create-next-app/index.ts Co-authored-by: Lee Robinson --- packages/create-next-app/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 351dc2c6e7cb3..0ddfc3c2a15a3 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -405,7 +405,7 @@ async function run(): Promise { onState: onPromptState, type: 'toggle', name: 'turbo', - message: `Would you like to use ${styledTurbo} for next dev? (RC)`, + message: `Would you like to use ${styledTurbo} for `next dev`? (RC)`, initial: getPrefOrDefault('turbo'), active: 'Yes', inactive: 'No', From 62869c1462d7313a013e0596a6faff1458505c3d Mon Sep 17 00:00:00 2001 From: Arindam Majumder <109217591+Arindam200@users.noreply.github.com> Date: Sat, 18 May 2024 21:58:39 +0530 Subject: [PATCH 05/14] Update packages/create-next-app/index.ts Co-authored-by: Lee Robinson --- packages/create-next-app/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 0ddfc3c2a15a3..1f02b346bebfd 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -466,7 +466,7 @@ async function run(): Promise { onState: onPromptState, type: 'toggle', name: 'turbo', - message: `Would you like to use ${styledTurbo} for next dev? (RC)`, + message: `Would you like to use ${styledTurbo} for `next dev`? (RC)`, initial: getPrefOrDefault('turbo'), active: 'Yes', inactive: 'No', From eb955080a77b367ebb59b5ad9ffba04ce6db8737 Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Sun, 19 May 2024 02:28:45 +0900 Subject: [PATCH 06/14] test: add turbo flag --- .../create-next-app/templates/app.test.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/integration/create-next-app/templates/app.test.ts b/test/integration/create-next-app/templates/app.test.ts index 05738c7a8ad89..839aa3749ce02 100644 --- a/test/integration/create-next-app/templates/app.test.ts +++ b/test/integration/create-next-app/templates/app.test.ts @@ -1,3 +1,4 @@ +import { join } from 'node:path' import { createNextApp, projectShouldHaveNoGitChanges, @@ -222,4 +223,32 @@ describe.skip('create-next-app --app (App Router)', () => { }) }) }) + + it('should enable turbopack on --turbo flag', async () => { + await useTempDir(async (cwd) => { + const projectName = 'app-turbo' + const childProcess = createNextApp( + [ + projectName, + '--ts', + '--app', + '--eslint', + '--turbo', + '--no-src-dir', + '--no-tailwind', + '--no-import-alias', + ], + { + cwd, + }, + testVersion + ) + + const exitCode = await spawnExitPromise(childProcess) + expect(exitCode).toBe(0) + const projectRoot = join(cwd, projectName) + const pkgJson = require(join(projectRoot, 'package.json')) + expect(pkgJson.scripts.dev).toBe('next dev --turbo') + }) + }) }) From 10e8cfb10a9bfc335d4871b7c515203662e138ca Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Sun, 19 May 2024 02:37:02 +0900 Subject: [PATCH 07/14] chore: port #65925 --- packages/create-next-app/create-app.ts | 11 +------- packages/create-next-app/index.ts | 31 ++++++++------------- packages/create-next-app/templates/index.ts | 3 +- packages/create-next-app/templates/types.ts | 1 + 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/packages/create-next-app/create-app.ts b/packages/create-next-app/create-app.ts index bef3b0b7e6637..cb4efb39e8201 100644 --- a/packages/create-next-app/create-app.ts +++ b/packages/create-next-app/create-app.ts @@ -231,6 +231,7 @@ export async function createApp({ srcDir, importAlias, skipInstall, + turbo, }) } @@ -239,16 +240,6 @@ export async function createApp({ console.log() } - if (hasPackageJson) { - const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) - if (turbo) { - packageJson.scripts.dev = 'next dev --turbo' - } else { - packageJson.scripts.dev = 'next dev' - } - fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)) - } - let cdpath: string if (path.join(originalDirectory, appName) === appPath) { cdpath = appName diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 1f02b346bebfd..5070833e1e0b0 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -83,6 +83,12 @@ const program = new Commander.Command(packageJson.name) ` Initialize inside a \`src/\` directory. +` + ) + .option( + '--turbo', + ` + Enable Turbopack by default for development. ` ) .option( @@ -396,7 +402,8 @@ async function run(): Promise { program.app = Boolean(appRouter) } } - if (!process.argv.includes('--turbo') && !process.argv.includes('--no-turbo')) { + + if (!program.turbo && !process.argv.includes('--no-turbo')) { if (ciInfo.isCI) { program.turbo = getPrefOrDefault('turbo') } else { @@ -405,7 +412,7 @@ async function run(): Promise { onState: onPromptState, type: 'toggle', name: 'turbo', - message: `Would you like to use ${styledTurbo} for `next dev`? (RC)`, + message: `Would you like to use ${styledTurbo} for ${`next dev`}?`, initial: getPrefOrDefault('turbo'), active: 'Yes', inactive: 'No', @@ -414,6 +421,7 @@ async function run(): Promise { preferences.turbo = Boolean(turbo) } } + const importAliasPattern = /^[^*"]+\/\*\s*$/ if ( typeof program.importAlias !== 'string' || @@ -457,24 +465,6 @@ async function run(): Promise { } } } - if (!process.argv.includes('--turbo') && !process.argv.includes('--no-turbo')) { - if (ciInfo.isCI) { - program.turbo = getPrefOrDefault('turbo') - } else { - const styledTurbo = blue('Turbopack') - const { turbo } = await prompts({ - onState: onPromptState, - type: 'toggle', - name: 'turbo', - message: `Would you like to use ${styledTurbo} for `next dev`? (RC)`, - initial: getPrefOrDefault('turbo'), - active: 'Yes', - inactive: 'No', - }) - program.turbo = Boolean(turbo) - preferences.turbo = Boolean(turbo) - } - } } try { @@ -522,6 +512,7 @@ async function run(): Promise { importAlias: program.importAlias, skipInstall: program.skipInstall, empty: program.empty, + turbo: program.turbo, }) } conf.set('preferences', preferences) diff --git a/packages/create-next-app/templates/index.ts b/packages/create-next-app/templates/index.ts index 0dc12dd0fde45..53b6fe87fab10 100644 --- a/packages/create-next-app/templates/index.ts +++ b/packages/create-next-app/templates/index.ts @@ -39,6 +39,7 @@ export const installTemplate = async ({ srcDir, importAlias, skipInstall, + turbo, }: InstallTemplateArgs) => { console.log(bold(`Using ${packageManager}.`)); @@ -174,7 +175,7 @@ export const installTemplate = async ({ version: "0.1.0", private: true, scripts: { - dev: "next dev", + dev: `next dev${turbo ? " --turbo" : ""}`, build: "next build", start: "next start", lint: "next lint", diff --git a/packages/create-next-app/templates/types.ts b/packages/create-next-app/templates/types.ts index 7d215900da89d..1837495ab8a08 100644 --- a/packages/create-next-app/templates/types.ts +++ b/packages/create-next-app/templates/types.ts @@ -29,4 +29,5 @@ export interface InstallTemplateArgs { srcDir: boolean; importAlias: string; skipInstall: boolean; + turbo: boolean; } From a8b2c95d9a0dc7ff59b63355eb13082c9a8f52db Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Sun, 19 May 2024 02:37:12 +0900 Subject: [PATCH 08/14] docs: add help message --- docs/01-getting-started/01-installation.mdx | 1 + docs/02-app/02-api-reference/06-create-next-app.mdx | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/01-getting-started/01-installation.mdx b/docs/01-getting-started/01-installation.mdx index 40121f65e3f8a..7882d271c313c 100644 --- a/docs/01-getting-started/01-installation.mdx +++ b/docs/01-getting-started/01-installation.mdx @@ -30,6 +30,7 @@ Would you like to use ESLint? No / Yes Would you like to use Tailwind CSS? No / Yes Would you like to use `src/` directory? No / Yes Would you like to use App Router? (recommended) No / Yes +Would you like to use Turbopack for `next dev`? No / Yes Would you like to customize the default import alias (@/*)? No / Yes What import alias would you like configured? @/* ``` diff --git a/docs/02-app/02-api-reference/06-create-next-app.mdx b/docs/02-app/02-api-reference/06-create-next-app.mdx index db786a61947d9..faa5bd766b1f6 100644 --- a/docs/02-app/02-api-reference/06-create-next-app.mdx +++ b/docs/02-app/02-api-reference/06-create-next-app.mdx @@ -38,6 +38,7 @@ Would you like to use ESLint? No / Yes Would you like to use Tailwind CSS? No / Yes Would you like to use `src/` directory? No / Yes Would you like to use App Router? (recommended) No / Yes +Would you like to use Turbopack for `next dev`? No / Yes Would you like to customize the default import alias (@/*)? No / Yes Would you like to use Turbopack for `next dev`? (RC) No / Yes ``` From 5589b2c41a3d92c4b52e20f32808a3c0c487c1b0 Mon Sep 17 00:00:00 2001 From: Jiwon Choi Date: Sun, 19 May 2024 02:41:47 +0900 Subject: [PATCH 09/14] chore: no need --no-turbo --- packages/create-next-app/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 5070833e1e0b0..03a767bdb6e02 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -403,7 +403,7 @@ async function run(): Promise { } } - if (!program.turbo && !process.argv.includes('--no-turbo')) { + if (!program.turbo) { if (ciInfo.isCI) { program.turbo = getPrefOrDefault('turbo') } else { From b412ba688e35339a774acba4d444a65ed87c7189 Mon Sep 17 00:00:00 2001 From: Arindam Majumder <109217591+Arindam200@users.noreply.github.com> Date: Sat, 18 May 2024 23:35:47 +0530 Subject: [PATCH 10/14] Update docs/02-app/02-api-reference/06-create-next-app.mdx Co-authored-by: Jiwon Choi --- docs/02-app/02-api-reference/06-create-next-app.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/02-app/02-api-reference/06-create-next-app.mdx b/docs/02-app/02-api-reference/06-create-next-app.mdx index faa5bd766b1f6..32775cbd6735e 100644 --- a/docs/02-app/02-api-reference/06-create-next-app.mdx +++ b/docs/02-app/02-api-reference/06-create-next-app.mdx @@ -40,7 +40,6 @@ Would you like to use `src/` directory? No / Yes Would you like to use App Router? (recommended) No / Yes Would you like to use Turbopack for `next dev`? No / Yes Would you like to customize the default import alias (@/*)? No / Yes -Would you like to use Turbopack for `next dev`? (RC) No / Yes ``` Once you've answered the prompts, a new project will be created with the correct configuration depending on your answers. From b86c5dc0420231098333c900bcf2c371e31e6f75 Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Sun, 19 May 2024 03:48:53 +0900 Subject: [PATCH 11/14] fix(CI): some it tests out of describe and added --no-turbo --- packages/create-next-app/index.ts | 2 +- .../integration/create-next-app/index.test.ts | 2 + .../package-manager/bun.test.ts | 114 +++++++++--------- .../package-manager/npm.test.ts | 2 + .../package-manager/pnpm.test.ts | 114 +++++++++--------- .../package-manager/yarn.test.ts | 114 +++++++++--------- .../create-next-app/prompts.test.ts | 4 + 7 files changed, 183 insertions(+), 169 deletions(-) diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 03a767bdb6e02..5070833e1e0b0 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -403,7 +403,7 @@ async function run(): Promise { } } - if (!program.turbo) { + if (!program.turbo && !process.argv.includes('--no-turbo')) { if (ciInfo.isCI) { program.turbo = getPrefOrDefault('turbo') } else { diff --git a/test/integration/create-next-app/index.test.ts b/test/integration/create-next-app/index.test.ts index 12491062b9d9e..c55efaa918a53 100644 --- a/test/integration/create-next-app/index.test.ts +++ b/test/integration/create-next-app/index.test.ts @@ -30,6 +30,7 @@ describe.skip('create-next-app', () => { projectName, '--ts', '--app', + '--no-turbo', '--no-eslint', '--no-tailwind', '--no-src-dir', @@ -99,6 +100,7 @@ describe.skip('create-next-app', () => { projectName, '--ts', '--app', + '--no-turbo', '--no-eslint', '--no-tailwind', '--no-src-dir', diff --git a/test/integration/create-next-app/package-manager/bun.test.ts b/test/integration/create-next-app/package-manager/bun.test.ts index 45be95ab3c4d5..6529b6ab71a13 100644 --- a/test/integration/create-next-app/package-manager/bun.test.ts +++ b/test/integration/create-next-app/package-manager/bun.test.ts @@ -36,6 +36,7 @@ describe.skip('create-next-app with package manager bun', () => { '--ts', '--app', '--use-bun', + '--no-turbo', '--no-eslint', '--no-src-dir', '--no-tailwind', @@ -55,72 +56,73 @@ describe.skip('create-next-app with package manager bun', () => { }) }) }) -}) -it('should use bun when user-agent is bun', async () => { - await useTempDir(async (cwd) => { - const projectName = 'user-agent-bun' - const res = await run( - [ - projectName, - '--ts', - '--app', - '--no-eslint', - '--no-src-dir', - '--no-tailwind', - '--no-import-alias', - ], - nextInstall.installDir, - { - cwd, - env: { npm_config_user_agent: 'bun' }, - } - ) + it('should use bun when user-agent is bun', async () => { + await useTempDir(async (cwd) => { + const projectName = 'user-agent-bun' + const res = await run( + [ + projectName, + '--ts', + '--app', + '--no-turbo', + '--no-eslint', + '--no-src-dir', + '--no-tailwind', + '--no-import-alias', + ], + nextInstall.installDir, + { + cwd, + env: { npm_config_user_agent: 'bun' }, + } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) -}) -it('should use bun for --use-bun flag with example', async () => { - await useTempDir(async (cwd) => { - const projectName = 'use-bun-with-example' - const res = await run( - [projectName, '--use-bun', '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, - { cwd } - ) + it('should use bun for --use-bun flag with example', async () => { + await useTempDir(async (cwd) => { + const projectName = 'use-bun-with-example' + const res = await run( + [projectName, '--use-bun', '--example', FULL_EXAMPLE_PATH], + nextInstall.installDir, + { cwd } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) -}) -it('should use bun when user-agent is bun with example', async () => { - await useTempDir(async (cwd) => { - const projectName = 'user-agent-bun-with-example' - const res = await run( - [projectName, '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, - { - cwd, - env: { npm_config_user_agent: 'bun' }, - } - ) + it('should use bun when user-agent is bun with example', async () => { + await useTempDir(async (cwd) => { + const projectName = 'user-agent-bun-with-example' + const res = await run( + [projectName, '--example', FULL_EXAMPLE_PATH], + nextInstall.installDir, + { + cwd, + env: { npm_config_user_agent: 'bun' }, + } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) }) diff --git a/test/integration/create-next-app/package-manager/npm.test.ts b/test/integration/create-next-app/package-manager/npm.test.ts index 20babd843035e..5baaeca0fbe90 100644 --- a/test/integration/create-next-app/package-manager/npm.test.ts +++ b/test/integration/create-next-app/package-manager/npm.test.ts @@ -29,6 +29,7 @@ describe.skip('create-next-app with package manager npm', () => { '--ts', '--app', '--use-npm', + '--no-turbo', '--no-eslint', '--no-src-dir', '--no-tailwind', @@ -58,6 +59,7 @@ it('should use npm when user-agent is npm', async () => { projectName, '--ts', '--app', + '--no-turbo', '--no-eslint', '--no-src-dir', '--no-tailwind', diff --git a/test/integration/create-next-app/package-manager/pnpm.test.ts b/test/integration/create-next-app/package-manager/pnpm.test.ts index 02112d8d87318..1a51a41836e6a 100644 --- a/test/integration/create-next-app/package-manager/pnpm.test.ts +++ b/test/integration/create-next-app/package-manager/pnpm.test.ts @@ -37,6 +37,7 @@ describe.skip('create-next-app with package manager pnpm', () => { '--ts', '--app', '--use-pnpm', + '--no-turbo', '--no-eslint', '--no-src-dir', '--no-tailwind', @@ -56,72 +57,73 @@ describe.skip('create-next-app with package manager pnpm', () => { }) }) }) -}) -it('should use pnpm when user-agent is pnpm', async () => { - await useTempDir(async (cwd) => { - const projectName = 'user-agent-pnpm' - const res = await run( - [ - projectName, - '--ts', - '--app', - '--no-eslint', - '--no-src-dir', - '--no-tailwind', - '--no-import-alias', - ], - nextInstall.installDir, - { - cwd, - env: { npm_config_user_agent: 'pnpm' }, - } - ) + it('should use pnpm when user-agent is pnpm', async () => { + await useTempDir(async (cwd) => { + const projectName = 'user-agent-pnpm' + const res = await run( + [ + projectName, + '--ts', + '--app', + '--no-turbo', + '--no-eslint', + '--no-src-dir', + '--no-tailwind', + '--no-import-alias', + ], + nextInstall.installDir, + { + cwd, + env: { npm_config_user_agent: 'pnpm' }, + } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) -}) -it('should use pnpm for --use-pnpm flag with example', async () => { - await useTempDir(async (cwd) => { - const projectName = 'use-pnpm-with-example' - const res = await run( - [projectName, '--use-pnpm', '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, - { cwd } - ) + it('should use pnpm for --use-pnpm flag with example', async () => { + await useTempDir(async (cwd) => { + const projectName = 'use-pnpm-with-example' + const res = await run( + [projectName, '--use-pnpm', '--example', FULL_EXAMPLE_PATH], + nextInstall.installDir, + { cwd } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) -}) -it('should use pnpm when user-agent is pnpm with example', async () => { - await useTempDir(async (cwd) => { - const projectName = 'user-agent-pnpm-with-example' - const res = await run( - [projectName, '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, - { - cwd, - env: { npm_config_user_agent: 'pnpm' }, - } - ) + it('should use pnpm when user-agent is pnpm with example', async () => { + await useTempDir(async (cwd) => { + const projectName = 'user-agent-pnpm-with-example' + const res = await run( + [projectName, '--example', FULL_EXAMPLE_PATH], + nextInstall.installDir, + { + cwd, + env: { npm_config_user_agent: 'pnpm' }, + } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) }) diff --git a/test/integration/create-next-app/package-manager/yarn.test.ts b/test/integration/create-next-app/package-manager/yarn.test.ts index b507a19b6d20c..4211ee23deab4 100644 --- a/test/integration/create-next-app/package-manager/yarn.test.ts +++ b/test/integration/create-next-app/package-manager/yarn.test.ts @@ -30,6 +30,7 @@ describe.skip('create-next-app with package manager yarn', () => { '--ts', '--app', '--use-yarn', + '--no-turbo', '--no-eslint', '--no-src-dir', '--no-tailwind', @@ -49,72 +50,73 @@ describe.skip('create-next-app with package manager yarn', () => { }) }) }) -}) -it('should use yarn when user-agent is yarn', async () => { - await useTempDir(async (cwd) => { - const projectName = 'user-agent-yarn' - const res = await run( - [ - projectName, - '--ts', - '--app', - '--no-eslint', - '--no-src-dir', - '--no-tailwind', - '--no-import-alias', - ], - 'canary', - { - cwd, - env: { npm_config_user_agent: 'yarn' }, - } - ) + it('should use yarn when user-agent is yarn', async () => { + await useTempDir(async (cwd) => { + const projectName = 'user-agent-yarn' + const res = await run( + [ + projectName, + '--ts', + '--app', + '--no-turbo', + '--no-eslint', + '--no-src-dir', + '--no-tailwind', + '--no-import-alias', + ], + 'canary', + { + cwd, + env: { npm_config_user_agent: 'yarn' }, + } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) -}) -it('should use yarn for --use-yarn flag with example', async () => { - await useTempDir(async (cwd) => { - const projectName = 'use-yarn-with-example' - const res = await run( - [projectName, '--use-yarn', '--example', FULL_EXAMPLE_PATH], - 'canary', - { cwd } - ) + it('should use yarn for --use-yarn flag with example', async () => { + await useTempDir(async (cwd) => { + const projectName = 'use-yarn-with-example' + const res = await run( + [projectName, '--use-yarn', '--example', FULL_EXAMPLE_PATH], + 'canary', + { cwd } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) -}) -it('should use yarn when user-agent is yarn with example', async () => { - await useTempDir(async (cwd) => { - const projectName = 'user-agent-yarn-with-example' - const res = await run( - [projectName, '--example', FULL_EXAMPLE_PATH], - 'canary', - { - cwd, - env: { npm_config_user_agent: 'yarn' }, - } - ) + it('should use yarn when user-agent is yarn with example', async () => { + await useTempDir(async (cwd) => { + const projectName = 'user-agent-yarn-with-example' + const res = await run( + [projectName, '--example', FULL_EXAMPLE_PATH], + 'canary', + { + cwd, + env: { npm_config_user_agent: 'yarn' }, + } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) }) diff --git a/test/integration/create-next-app/prompts.test.ts b/test/integration/create-next-app/prompts.test.ts index b360eb3cfb8ac..07bc45dfd3d6c 100644 --- a/test/integration/create-next-app/prompts.test.ts +++ b/test/integration/create-next-app/prompts.test.ts @@ -22,6 +22,7 @@ describe.skip('create-next-app prompts', () => { '--ts', '--app', '--eslint', + '--no-turbo', '--no-src-dir', '--no-tailwind', '--no-import-alias', @@ -59,6 +60,7 @@ describe.skip('create-next-app prompts', () => { projectName, '--app', '--eslint', + '--no-turbo', '--no-tailwind', '--no-src-dir', '--no-import-alias', @@ -95,6 +97,7 @@ describe.skip('create-next-app prompts', () => { '--ts', '--app', '--eslint', + '--no-turbo', '--no-src-dir', '--no-import-alias', ], @@ -130,6 +133,7 @@ describe.skip('create-next-app prompts', () => { '--ts', '--app', '--eslint', + '--no-turbo', '--no-tailwind', '--no-src-dir', ], From 6048467c526e7e65e34b7eb993a2eee8ea4182f5 Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Sun, 19 May 2024 03:50:01 +0900 Subject: [PATCH 12/14] fix: npm it test to describe --- .../package-manager/npm.test.ts | 114 +++++++++--------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/test/integration/create-next-app/package-manager/npm.test.ts b/test/integration/create-next-app/package-manager/npm.test.ts index 5baaeca0fbe90..fe87dcc11c17d 100644 --- a/test/integration/create-next-app/package-manager/npm.test.ts +++ b/test/integration/create-next-app/package-manager/npm.test.ts @@ -49,73 +49,73 @@ describe.skip('create-next-app with package manager npm', () => { }) }) }) -}) -it('should use npm when user-agent is npm', async () => { - await useTempDir(async (cwd) => { - const projectName = 'user-agent-npm' - const res = await run( - [ - projectName, - '--ts', - '--app', - '--no-turbo', - '--no-eslint', - '--no-src-dir', - '--no-tailwind', - '--no-import-alias', - ], - nextInstall.installDir, - { - cwd, - env: { npm_config_user_agent: 'npm' }, - } - ) + it('should use npm when user-agent is npm', async () => { + await useTempDir(async (cwd) => { + const projectName = 'user-agent-npm' + const res = await run( + [ + projectName, + '--ts', + '--app', + '--no-turbo', + '--no-eslint', + '--no-src-dir', + '--no-tailwind', + '--no-import-alias', + ], + nextInstall.installDir, + { + cwd, + env: { npm_config_user_agent: 'npm' }, + } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) -}) -it('should use npm for --use-npm flag with example', async () => { - await useTempDir(async (cwd) => { - const projectName = 'use-npm-with-example' - const res = await run( - [projectName, '--use-npm', '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, - { cwd } - ) + it('should use npm for --use-npm flag with example', async () => { + await useTempDir(async (cwd) => { + const projectName = 'use-npm-with-example' + const res = await run( + [projectName, '--use-npm', '--example', FULL_EXAMPLE_PATH], + nextInstall.installDir, + { cwd } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) -}) -it('should use npm when user-agent is npm with example', async () => { - await useTempDir(async (cwd) => { - const projectName = 'user-agent-npm-with-example' - const res = await run( - [projectName, '--example', FULL_EXAMPLE_PATH], - nextInstall.installDir, - { - cwd, - env: { npm_config_user_agent: 'npm' }, - } - ) + it('should use npm when user-agent is npm with example', async () => { + await useTempDir(async (cwd) => { + const projectName = 'user-agent-npm-with-example' + const res = await run( + [projectName, '--example', FULL_EXAMPLE_PATH], + nextInstall.installDir, + { + cwd, + env: { npm_config_user_agent: 'npm' }, + } + ) - expect(res.exitCode).toBe(0) - projectFilesShouldExist({ - cwd, - projectName, - files, + expect(res.exitCode).toBe(0) + projectFilesShouldExist({ + cwd, + projectName, + files, + }) }) }) }) From 970f972c79c90180cab22e9b2701eee3c8382db6 Mon Sep 17 00:00:00 2001 From: Jiwon Choi Date: Sun, 19 May 2024 11:30:48 +0900 Subject: [PATCH 13/14] Update packages/create-next-app/index.ts Co-authored-by: Lee Robinson --- packages/create-next-app/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 5070833e1e0b0..0df821e913870 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -88,6 +88,7 @@ const program = new Commander.Command(packageJson.name) .option( '--turbo', ` + Enable Turbopack by default for development. ` ) From eec8c7bcb92b1616f585f8ec450740b308bf1c9e Mon Sep 17 00:00:00 2001 From: samcx Date: Mon, 20 May 2024 11:44:28 -0700 Subject: [PATCH 14/14] test(create-next-app): update app/page.test.ts --- .../create-next-app/templates/app.test.ts | 4 +-- .../create-next-app/templates/pages.test.ts | 31 ++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/test/integration/create-next-app/templates/app.test.ts b/test/integration/create-next-app/templates/app.test.ts index 839aa3749ce02..fc6defe293ea5 100644 --- a/test/integration/create-next-app/templates/app.test.ts +++ b/test/integration/create-next-app/templates/app.test.ts @@ -8,7 +8,7 @@ import { useTempDir, } from '../utils' -let testVersion +let testVersion: string beforeAll(async () => { if (testVersion) return // TODO: investigate moving this post publish or create deployed GH#57025 @@ -224,7 +224,7 @@ describe.skip('create-next-app --app (App Router)', () => { }) }) - it('should enable turbopack on --turbo flag', async () => { + it('should enable turbopack dev with --turbo flag', async () => { await useTempDir(async (cwd) => { const projectName = 'app-turbo' const childProcess = createNextApp( diff --git a/test/integration/create-next-app/templates/pages.test.ts b/test/integration/create-next-app/templates/pages.test.ts index 4fbcbf5a3cf21..e16ca49a6a057 100644 --- a/test/integration/create-next-app/templates/pages.test.ts +++ b/test/integration/create-next-app/templates/pages.test.ts @@ -1,3 +1,4 @@ +import { join } from 'node:path' import { createNextApp, projectShouldHaveNoGitChanges, @@ -7,7 +8,7 @@ import { useTempDir, } from '../utils' -let testVersion +let testVersion: string beforeAll(async () => { // TODO: investigate moving this post publish or create deployed GH#57025 // tarballs to avoid these failing while a publish is in progress @@ -232,4 +233,32 @@ describe.skip('create-next-app --no-app (Pages Router)', () => { }) }) }) + + it('should enable turbopack dev with --turbo flag', async () => { + await useTempDir(async (cwd) => { + const projectName = 'pages-turbo' + const childProcess = createNextApp( + [ + projectName, + '--ts', + '--no-app', + '--eslint', + '--turbo', + '--no-src-dir', + '--no-tailwind', + '--no-import-alias', + ], + { + cwd, + }, + testVersion + ) + + const exitCode = await spawnExitPromise(childProcess) + expect(exitCode).toBe(0) + const projectRoot = join(cwd, projectName) + const pkgJson = require(join(projectRoot, 'package.json')) + expect(pkgJson.scripts.dev).toBe('next dev --turbo') + }) + }) })