Skip to content

Commit

Permalink
Bring back changes to customizeAlias from #49063
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed May 2, 2023
1 parent 6641f20 commit d600238
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
36 changes: 25 additions & 11 deletions packages/create-next-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ async function run(): Promise<void> {
tailwind: true,
srcDir: false,
importAlias: '@/*',
customizeImportAlias: false,
}
const getPrefOrDefault = (field: string) =>
preferences[field] ?? defaults[field]
Expand Down Expand Up @@ -340,19 +341,32 @@ async function run(): Promise<void> {
program.importAlias = '@/*'
} else {
const styledImportAlias = chalk.hex('#007acc')('import alias')
const { importAlias } = await prompts({
const { customizeImportAlias } = await prompts({
onState: onPromptState,
type: 'text',
name: 'importAlias',
message: `What ${styledImportAlias} would you like configured?`,
initial: getPrefOrDefault('importAlias'),
validate: (value) =>
/.+\/\*/.test(value)
? true
: 'Import alias must follow the pattern <prefix>/*',
type: 'toggle',
name: 'customizeImportAlias',
message: `Would you like to customize the default ${styledImportAlias}?`,
initial: getPrefOrDefault('customizeImportAlias'),
active: 'Yes',
inactive: 'No',
})
program.importAlias = importAlias
preferences.importAlias = importAlias
if (!customizeImportAlias) {
program.importAlias = '@/*'
} else {
const { importAlias } = await prompts({
onState: onPromptState,
type: 'text',
name: 'importAlias',
message: `What ${styledImportAlias} would you like configured?`,
initial: getPrefOrDefault('importAlias'),
validate: (value) =>
/.+\/\*/.test(value)
? true
: 'Import alias must follow the pattern <prefix>/*',
})
program.importAlias = importAlias
preferences.importAlias = importAlias
}
}
}
}
Expand Down
18 changes: 16 additions & 2 deletions test/integration/create-next-app/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ import {
import { Span } from 'next/dist/trace'

import { useTempDir } from '../../../test/lib/use-temp-dir'
import { fetchViaHTTP, findPort, killApp, launchApp } from 'next-test-utils'
import {
check,
fetchViaHTTP,
findPort,
killApp,
launchApp,
} from 'next-test-utils'
import resolveFrom from 'resolve-from'
import { createNextInstall } from '../../../test/lib/create-next-install'
import ansiEscapes from 'ansi-escapes'

const startsWithoutError = async (
appDir: string,
Expand Down Expand Up @@ -272,11 +279,18 @@ describe('create-next-app templates', () => {
/**
* Bind the exit listener.
*/
await new Promise<void>((resolve) => {
await new Promise<void>(async (resolve) => {
childProcess.on('exit', async (exitCode) => {
expect(exitCode).toBe(0)
resolve()
})
let output = ''
childProcess.stdout.on('data', (data) => {
output += data
process.stdout.write(data)
})
childProcess.stdin.write(ansiEscapes.cursorForward() + '\n')
await check(() => output, /What import alias would you like configured/)
childProcess.stdin.write('@/something/*\n')
})

Expand Down

0 comments on commit d600238

Please sign in to comment.