Unverified Commit cf3d73a4 authored by Vũ Văn Dũng's avatar Vũ Văn Dũng Committed by GitHub

Add the default import alias to create-next-app prompt for clarity (#55896)



### Why?

Whenever I run `create-next-app` and reach this question

```
Would you like to customize the default import alias? No / Yes
```

I always have to select "No", because I don't remember what this default import alias here is. [It _is_ documented to be `@/*`](https://nextjs.org/docs/app/api-reference/create-next-app#non-interactive), but the documentation is relatively hidden and not many people know about it – it's also easy to forget.

Even more confusingly, the next question ("What import alias would you like configured?") doesn't have this `@/*` as the default answer, but the user's last choice as the default answer instead (which could be different from `@/*` – making people wonder if Next.js changed their defaults overnight).

I suppose it would be better to just make it clear in the prompt itself, so people with skill issues who happen to forget that default value (like me) can still confidently select "Yes" if they want `@/*`, without having to do "No" and manually type `@/*` again.

### How

```diff
- Would you like to customize the default import alias?
+ Would you like to customize the default import alias (@/*)?
```
parent 00d9080d
......@@ -30,7 +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 customize the default import alias? No / Yes
Would you like to customize the default import alias (@/*)? No / Yes
What import alias would you like configured? @/*
```
......
......@@ -31,14 +31,14 @@ bunx create-next-app
You will then be asked the following prompts:
```bash filename="Terminal"
```txt filename="Terminal"
What is your project named? my-app
Would you like to use TypeScript? No / Yes
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 customize the default import alias? No / Yes
Would you like to customize the default import alias (@/*)? No / Yes
```
Once you've answered the prompts, a new project will be created with the correct configuration depending on your answers.
......
......@@ -246,6 +246,7 @@ async function run(): Promise<void> {
typescript: true,
eslint: true,
tailwind: true,
app: true,
srcDir: false,
importAlias: '@/*',
customizeImportAlias: false,
......@@ -357,7 +358,7 @@ async function run(): Promise<void> {
if (!process.argv.includes('--app') && !process.argv.includes('--no-app')) {
if (ciInfo.isCI) {
program.app = true
program.app = getPrefOrDefault('app')
} else {
const styledAppDir = blue('App Router')
const { appRouter } = await prompts({
......@@ -365,7 +366,7 @@ async function run(): Promise<void> {
type: 'toggle',
name: 'appRouter',
message: `Would you like to use ${styledAppDir}? (recommended)`,
initial: true,
initial: getPrefOrDefault('app'),
active: 'Yes',
inactive: 'No',
})
......@@ -378,7 +379,8 @@ async function run(): Promise<void> {
!program.importAlias.length
) {
if (ciInfo.isCI) {
program.importAlias = '@/*'
// We don't use preferences here because the default value is @/* regardless of existing preferences
program.importAlias = defaults.importAlias
} else {
const styledImportAlias = blue('import alias')
......@@ -386,14 +388,15 @@ async function run(): Promise<void> {
onState: onPromptState,
type: 'toggle',
name: 'customizeImportAlias',
message: `Would you like to customize the default ${styledImportAlias}?`,
message: `Would you like to customize the default ${styledImportAlias} (${defaults.importAlias})?`,
initial: getPrefOrDefault('customizeImportAlias'),
active: 'Yes',
inactive: 'No',
})
if (!customizeImportAlias) {
program.importAlias = '@/*'
// We don't use preferences here because the default value is @/* regardless of existing preferences
program.importAlias = defaults.importAlias
} else {
const { importAlias } = await prompts({
onState: onPromptState,
......
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