Unverified Commit 5a2d24ea authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

create-next-app: remove App Router prompt and always use App Router (#100850)

`create-next-app` no longer asks "Would you like to use App Router?
(recommended)". New projects always use the App Router.

**Why**

The App Router is the recommended default, and the interactive prompt
only offered a way to pick the Pages Router by accident. A saved `app:
false` preference from an earlier run also kept silently producing Pages
Router projects.

**Approach**

- Remove the App Router toggle prompt and set `opts.app = true` unless
`--no-app` or `--api` is passed.
- Drop `app` from the defaults/preferences display, so the "recommended
defaults" and "reuse previous settings" summaries no longer list "App
Router" / "Pages Router".
- Saved `app` preferences are ignored. `--no-app` remains as the
explicit opt-out, so the existing Pages templates and their tests are
unchanged.

**Validation**

- `prompts.test.ts`: removed the App Router prompt from the customize
flow; the "reuse previous settings" test with a saved `app: false` now
expects an `app/` directory.
- Type-checked `packages/create-next-app/index.ts` with no new errors.
The create-next-app e2e tests were not run locally.

**Docs**

Removed the prompt line and "App Router" from the recommended defaults
summary in the installation guide and the `create-next-app` CLI
reference.

---------
Co-authored-by: 's avatarroboeve[bot] <311457182+roboeve[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTim Neutkens <6324199+timneutkens@users.noreply.github.com>
parent 94ea1c21
...@@ -86,7 +86,7 @@ On installation, you'll see the following prompts: ...@@ -86,7 +86,7 @@ On installation, you'll see the following prompts:
```txt filename="Terminal" ```txt filename="Terminal"
What is your project named? my-app What is your project named? my-app
Would you like to use the recommended Next.js defaults? Would you like to use the recommended Next.js defaults?
Yes, use recommended defaults - TypeScript, ESLint, No React Compiler, Tailwind CSS, No src/ directory, App Router, Cache Components, AGENTS.md Yes, use recommended defaults - TypeScript, ESLint, No React Compiler, Tailwind CSS, No src/ directory, Cache Components, AGENTS.md
No, reuse previous settings No, reuse previous settings
No, customize settings - Choose your own preferences No, customize settings - Choose your own preferences
``` ```
...@@ -99,7 +99,6 @@ Which linter would you like to use? ESLint / Biome / None ...@@ -99,7 +99,6 @@ Which linter would you like to use? ESLint / Biome / None
Would you like to use React Compiler? No / Yes Would you like to use React Compiler? No / Yes
Would you like to use Tailwind CSS? No / Yes Would you like to use Tailwind CSS? No / Yes
Would you like your code inside a `src/` directory? No / Yes Would you like your code inside a `src/` directory? No / Yes
Would you like to use App Router? (recommended) No / Yes
Would you like to use Cache Components? No / Yes Would you like to use Cache Components? No / Yes
Would you like to customize the import alias (`@/*` by default)? No / Yes Would you like to customize the import alias (`@/*` by default)? No / Yes
What import alias would you like configured? @/* What import alias would you like configured? @/*
......
...@@ -90,7 +90,7 @@ On installation, you'll see the following prompts: ...@@ -90,7 +90,7 @@ On installation, you'll see the following prompts:
```txt filename="Terminal" ```txt filename="Terminal"
What is your project named? my-app What is your project named? my-app
Would you like to use the recommended Next.js defaults? Would you like to use the recommended Next.js defaults?
Yes, use recommended defaults - TypeScript, ESLint, No React Compiler, Tailwind CSS, No src/ directory, App Router, Cache Components, AGENTS.md, Agent feedback Yes, use recommended defaults - TypeScript, ESLint, No React Compiler, Tailwind CSS, No src/ directory, Cache Components, AGENTS.md, Agent feedback
No, reuse previous settings No, reuse previous settings
No, customize settings - Choose your own preferences No, customize settings - Choose your own preferences
``` ```
...@@ -103,7 +103,6 @@ Which linter would you like to use? ESLint / Biome / None ...@@ -103,7 +103,6 @@ Which linter would you like to use? ESLint / Biome / None
Would you like to use React Compiler? No / Yes Would you like to use React Compiler? No / Yes
Would you like to use Tailwind CSS? No / Yes Would you like to use Tailwind CSS? No / Yes
Would you like your code inside a `src/` directory? No / Yes Would you like your code inside a `src/` directory? No / Yes
Would you like to use App Router? (recommended) No / Yes
Would you like to use Cache Components? No / Yes Would you like to use Cache Components? No / Yes
Would you like to customize the import alias (`@/*` by default)? No / Yes Would you like to customize the import alias (`@/*` by default)? No / Yes
What import alias would you like configured? @/* What import alias would you like configured? @/*
......
...@@ -145,7 +145,10 @@ const packageManager: PackageManager = !!opts.useNpm ...@@ -145,7 +145,10 @@ const packageManager: PackageManager = !!opts.useNpm
: getPkgManager() : getPkgManager()
async function run(): Promise<void> { async function run(): Promise<void> {
const conf = new Conf({ projectName: 'create-next-app' }) const conf = new Conf({
projectName: 'create-next-app',
cwd: process.env.NEXT_PRIVATE_TEST_CONFIG_DIR,
})
if (opts.resetPreferences) { if (opts.resetPreferences) {
const { resetPreferences } = await prompts({ const { resetPreferences } = await prompts({
...@@ -248,7 +251,6 @@ async function run(): Promise<void> { ...@@ -248,7 +251,6 @@ async function run(): Promise<void> {
eslint: false, eslint: false,
linter: 'eslint', linter: 'eslint',
tailwind: true, tailwind: true,
app: true,
srcDir: false, srcDir: false,
importAlias: '@/*', importAlias: '@/*',
customizeImportAlias: false, customizeImportAlias: false,
...@@ -296,11 +298,6 @@ async function run(): Promise<void> { ...@@ -296,11 +298,6 @@ async function run(): Promise<void> {
values: { true: 'src/ directory', false: 'No src/ directory' }, values: { true: 'src/ directory', false: 'No src/ directory' },
flags: { true: '--src-dir', false: '--no-src-dir' }, flags: { true: '--src-dir', false: '--no-src-dir' },
}, },
{
key: 'app',
values: { true: 'App Router', false: 'Pages Router' },
flags: { true: '--app', false: '--no-app' },
},
{ {
key: 'cacheComponents', key: 'cacheComponents',
values: { true: 'Cache Components', false: 'No Cache Components' }, values: { true: 'Cache Components', false: 'No Cache Components' },
...@@ -591,23 +588,10 @@ async function run(): Promise<void> { ...@@ -591,23 +588,10 @@ async function run(): Promise<void> {
} }
} }
// New projects always use the App Router. Saved preferences from older
// versions are ignored; only an explicit --no-app opts out.
if (!opts.app && !args.includes('--no-app') && !opts.api) { if (!opts.app && !args.includes('--no-app') && !opts.api) {
if (skipPrompt) { opts.app = true
opts.app = getPrefOrDefault('app')
} else {
const styledAppDir = blue('App Router')
const { app } = await prompts({
onState: onPromptState,
type: 'toggle',
name: 'app',
message: `Would you like to use ${styledAppDir}? (recommended)`,
initial: getPrefOrDefault('app'),
active: 'Yes',
inactive: 'No',
})
opts.app = Boolean(app)
preferences.app = Boolean(app)
}
} }
// Cache Components is an App Router feature, so only offer it when the App // Cache Components is an App Router feature, so only offer it when the App
......
import { mkdir, readFile, writeFile } from 'fs/promises' import { chmod, mkdir, readFile, writeFile } from 'fs/promises'
import { join } from 'path' import { join } from 'path'
import { import {
writeAgentFeedbackFiles, writeAgentFeedbackFiles,
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
import { import {
resolveNextTgzFilename, resolveNextTgzFilename,
run, run,
getPreferencesDir,
useTempDir, useTempDir,
projectFilesShouldExist, projectFilesShouldExist,
projectFilesShouldNotExist, projectFilesShouldNotExist,
...@@ -51,7 +52,10 @@ describe('create-next-app', () => { ...@@ -51,7 +52,10 @@ describe('create-next-app', () => {
const Conf = require('next/dist/compiled/conf') const Conf = require('next/dist/compiled/conf')
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const conf = new Conf({ projectName: 'create-next-app' }) const conf = new Conf({
projectName: 'create-next-app',
cwd: getPreferencesDir(cwd),
})
conf.clear() conf.clear()
const projectName = 'cache-components' const projectName = 'cache-components'
const res = await run( const res = await run(
...@@ -124,6 +128,11 @@ describe('create-next-app', () => { ...@@ -124,6 +128,11 @@ describe('create-next-app', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'dir-not-writable' const projectName = 'dir-not-writable'
// Create writable preferences before restricting the app's parent directory.
await mkdir(getPreferencesDir(cwd))
try {
await chmod(cwd, 0o500)
// if the folder isn't able to be write restricted we can't test so skip // if the folder isn't able to be write restricted we can't test so skip
if ( if (
...@@ -159,7 +168,10 @@ describe('create-next-app', () => { ...@@ -159,7 +168,10 @@ describe('create-next-app', () => {
expect(res.stderr).toMatch(expectedErrorMessage) expect(res.stderr).toMatch(expectedErrorMessage)
expect(res.exitCode).toBe(1) expect(res.exitCode).toBe(1)
}, 0o500).catch((err) => { } finally {
await chmod(cwd, 0o700)
}
}).catch((err) => {
if (!expectedErrorMessage.test(err.message)) { if (!expectedErrorMessage.test(err.message)) {
throw err throw err
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import { execSync, spawn, SpawnOptions } from 'child_process' import { execSync, spawn, SpawnOptions } from 'child_process'
import { existsSync, readFileSync } from 'fs' import { existsSync, readFileSync } from 'fs'
import { join, resolve } from 'path' import { join, resolve } from 'path'
import { fileURLToPath } from 'url'
import glob from 'glob' import glob from 'glob'
import Conf from 'next/dist/compiled/conf' import Conf from 'next/dist/compiled/conf'
...@@ -25,6 +26,11 @@ import { serializeTestPkgPathsEnv } from './test-pkg-paths' ...@@ -25,6 +26,11 @@ import { serializeTestPkgPathsEnv } from './test-pkg-paths'
const cli = require.resolve('create-next-app/dist/index.js') const cli = require.resolve('create-next-app/dist/index.js')
// Keep saved preferences inside each fixture so concurrent runs cannot reset
// or overwrite one another's settings.
export const getPreferencesDir = (cwd: string | URL = process.cwd()) =>
resolve(cwd instanceof URL ? fileURLToPath(cwd) : cwd, '.create-next-app')
/** /**
* Run the built version of `create-next-app` with the given arguments. * Run the built version of `create-next-app` with the given arguments.
*/ */
...@@ -34,7 +40,8 @@ export const createNextApp = ( ...@@ -34,7 +40,8 @@ export const createNextApp = (
testVersion?: string, testVersion?: string,
clearPreferences: boolean = true clearPreferences: boolean = true
) => { ) => {
const conf = new Conf({ projectName: 'create-next-app' }) const configDir = getPreferencesDir(options?.cwd)
const conf = new Conf({ projectName: 'create-next-app', cwd: configDir })
if (clearPreferences) { if (clearPreferences) {
conf.clear() conf.clear()
} }
...@@ -64,7 +71,8 @@ export const createNextApp = ( ...@@ -64,7 +71,8 @@ export const createNextApp = (
...options, ...options,
env: { env: {
...cloneEnv, ...cloneEnv,
...options.env, ...options?.env,
NEXT_PRIVATE_TEST_CONFIG_DIR: configDir,
}, },
}) })
} }
......
...@@ -4,6 +4,7 @@ import { join } from 'path' ...@@ -4,6 +4,7 @@ import { join } from 'path'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
import { import {
createNextApp, createNextApp,
getPreferencesDir,
projectFilesShouldExist, projectFilesShouldExist,
resolveNextTgzFilename, resolveNextTgzFilename,
useTempDir, useTempDir,
...@@ -296,7 +297,10 @@ describe('create-next-app prompts', () => { ...@@ -296,7 +297,10 @@ describe('create-next-app prompts', () => {
const Conf = require('next/dist/compiled/conf') const Conf = require('next/dist/compiled/conf')
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const conf = new Conf({ projectName: 'create-next-app' }) const conf = new Conf({
projectName: 'create-next-app',
cwd: getPreferencesDir(cwd),
})
conf.clear() conf.clear()
if (saved !== undefined) { if (saved !== undefined) {
conf.set('preferences', { cacheComponents: saved }) conf.set('preferences', { cacheComponents: saved })
...@@ -337,7 +341,6 @@ describe('create-next-app prompts', () => { ...@@ -337,7 +341,6 @@ describe('create-next-app prompts', () => {
'Would you like to use React Compiler?', 'Would you like to use React Compiler?',
'Would you like to use Tailwind CSS?', 'Would you like to use Tailwind CSS?',
'Would you like your code inside a', 'Would you like your code inside a',
'Would you like to use App Router?',
'Would you like to use Cache Components?', 'Would you like to use Cache Components?',
'Would you like to customize the import alias', 'Would you like to customize the import alias',
'Would you like to include AGENTS.md', 'Would you like to include AGENTS.md',
...@@ -368,7 +371,10 @@ describe('create-next-app prompts', () => { ...@@ -368,7 +371,10 @@ describe('create-next-app prompts', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
// Manually set preferences to simulate a previous run // Manually set preferences to simulate a previous run
const conf = new Conf({ projectName: 'create-next-app' }) const conf = new Conf({
projectName: 'create-next-app',
cwd: getPreferencesDir(cwd),
})
conf.set('preferences', { conf.set('preferences', {
typescript: false, typescript: false,
eslint: true, eslint: true,
...@@ -417,7 +423,7 @@ describe('create-next-app prompts', () => { ...@@ -417,7 +423,7 @@ describe('create-next-app prompts', () => {
cwd, cwd,
projectName, projectName,
files: [ files: [
'pages', // pages router (not app) 'app', // always App Router, even with a saved `app: false`
'package.json', 'package.json',
'jsconfig.json', // javascript 'jsconfig.json', // javascript
], ],
......
...@@ -3,6 +3,7 @@ import { join } from 'path' ...@@ -3,6 +3,7 @@ import { join } from 'path'
import { spawn } from 'child_process' import { spawn } from 'child_process'
import { fetchViaHTTP, findPort, killApp } from 'next-test-utils' import { fetchViaHTTP, findPort, killApp } from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { getPreferencesDir } from './lib/utils'
import { import {
resolveTestPkgPaths, resolveTestPkgPaths,
serializeTestPkgPathsEnv, serializeTestPkgPathsEnv,
...@@ -46,6 +47,7 @@ export const run = async ( ...@@ -46,6 +47,7 @@ export const run = async (
options: options:
| execa.Options | execa.Options
| { | {
cwd?: string
reject?: boolean reject?: boolean
env?: Record<string, string> env?: Record<string, string>
} }
...@@ -68,6 +70,7 @@ export const run = async ( ...@@ -68,6 +70,7 @@ export const run = async (
// when running tests directly (without `run-tests.js`). // when running tests directly (without `run-tests.js`).
NEXT_TEST_PKG_PATHS: serializeTestPkgPathsEnv(), NEXT_TEST_PKG_PATHS: serializeTestPkgPathsEnv(),
...options.env, ...options.env,
NEXT_PRIVATE_TEST_CONFIG_DIR: getPreferencesDir(options.cwd),
NEXT_PRIVATE_TEST_VERSION: nextJSVersion, NEXT_PRIVATE_TEST_VERSION: nextJSVersion,
}, },
}) })
...@@ -213,6 +216,7 @@ export async function tryNextDev({ ...@@ -213,6 +216,7 @@ export async function tryNextDev({
export { export {
createNextApp, createNextApp,
getPreferencesDir,
projectFilesShouldExist, projectFilesShouldExist,
projectFilesShouldNotExist, projectFilesShouldNotExist,
projectShouldHaveNoGitChanges, projectShouldHaveNoGitChanges,
......
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