Unverified Commit b7ea0a5a authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add prompt for ESLint to CNA (#42218)

Following up https://github.com/vercel/next.js/pull/42012 this adds an
additional prompt for include ESLint config/dependencies or not. As
discussed, this also removes the slow down from doing separate
`dependencies` and `devDependencies` installs since this separation is
no longer required now that we have `output: 'standalone'` which ensures
only actual necessary dependency files are used for production builds.

<details>

<summary>Before</summary>


https://user-images.githubusercontent.com/22380829/198953290-116b422d-4359-4aa9-9d82-b3265fde7b3f.mp4


</details>

<details>

<summary>After</summary>




https://user-images.githubusercontent.com/22380829/198953347-20dbf897-92b3-45ea-a9d2-cfb61622251d.mp4



</details>

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 2280a2dd
...@@ -45,6 +45,18 @@ Options: ...@@ -45,6 +45,18 @@ Options:
Initialize as a JavaScript project. Initialize as a JavaScript project.
--eslint
Initialize with eslint config.
--no-eslint
Initialize without eslint config.
--experimental-app
Initialize as a `app/` directory project.
--use-npm --use-npm
Explicitly tell the CLI to bootstrap the app using npm Explicitly tell the CLI to bootstrap the app using npm
......
...@@ -34,6 +34,7 @@ export async function createApp({ ...@@ -34,6 +34,7 @@ export async function createApp({
example, example,
examplePath, examplePath,
typescript, typescript,
eslint,
experimentalApp, experimentalApp,
}: { }: {
appPath: string appPath: string
...@@ -41,6 +42,7 @@ export async function createApp({ ...@@ -41,6 +42,7 @@ export async function createApp({
example?: string example?: string
examplePath?: string examplePath?: string
typescript: boolean typescript: boolean
eslint: boolean
experimentalApp: boolean experimentalApp: boolean
}): Promise<void> { }): Promise<void> {
let repoInfo: RepoInfo | undefined let repoInfo: RepoInfo | undefined
...@@ -216,6 +218,7 @@ export async function createApp({ ...@@ -216,6 +218,7 @@ export async function createApp({
mode, mode,
packageManager, packageManager,
isOnline, isOnline,
eslint,
}) })
} }
......
...@@ -32,6 +32,13 @@ const program = new Commander.Command(packageJson.name) ...@@ -32,6 +32,13 @@ const program = new Commander.Command(packageJson.name)
` `
Initialize as a JavaScript project. Initialize as a JavaScript project.
`
)
.option(
'--eslint',
`
Initialize with eslint config.
` `
) )
.option( .option(
...@@ -148,9 +155,6 @@ async function run(): Promise<void> { ...@@ -148,9 +155,6 @@ async function run(): Promise<void> {
/** /**
* If the user does not provide the necessary flags, prompt them for whether * If the user does not provide the necessary flags, prompt them for whether
* to use TS or JS. * to use TS or JS.
*
* @todo Allow appDir to support TS or JS, currently TS-only and disables all
* --ts, --js features.
*/ */
if (!example && !program.typescript && !program.javascript) { if (!example && !program.typescript && !program.javascript) {
if (ciInfo.isCI) { if (ciInfo.isCI) {
...@@ -158,6 +162,7 @@ async function run(): Promise<void> { ...@@ -158,6 +162,7 @@ async function run(): Promise<void> {
// prevent breaking setup flows // prevent breaking setup flows
program.javascript = true program.javascript = true
program.typescript = false program.typescript = false
program.eslint = false
} else { } else {
const styledTypeScript = chalk.hex('#007acc')('TypeScript') const styledTypeScript = chalk.hex('#007acc')('TypeScript')
const { typescript } = await prompts( const { typescript } = await prompts(
...@@ -180,6 +185,19 @@ async function run(): Promise<void> { ...@@ -180,6 +185,19 @@ async function run(): Promise<void> {
}, },
} }
) )
if (!program.eslint) {
const styledEslint = chalk.hex('#007acc')('ESLint')
const { eslint } = await prompts({
type: 'toggle',
name: 'eslint',
message: `Would you like to use ${styledEslint} with this project?`,
initial: false,
active: 'Yes',
inactive: 'No',
})
program.eslint = Boolean(eslint)
}
/** /**
* Depending on the prompt response, set the appropriate program flags. * Depending on the prompt response, set the appropriate program flags.
*/ */
...@@ -195,6 +213,7 @@ async function run(): Promise<void> { ...@@ -195,6 +213,7 @@ async function run(): Promise<void> {
example: example && example !== 'default' ? example : undefined, example: example && example !== 'default' ? example : undefined,
examplePath: program.examplePath, examplePath: program.examplePath,
typescript: program.typescript, typescript: program.typescript,
eslint: program.eslint,
experimentalApp: program.experimentalApp, experimentalApp: program.experimentalApp,
}) })
} catch (reason) { } catch (reason) {
...@@ -218,6 +237,7 @@ async function run(): Promise<void> { ...@@ -218,6 +237,7 @@ async function run(): Promise<void> {
appPath: resolvedProjectPath, appPath: resolvedProjectPath,
packageManager, packageManager,
typescript: program.typescript, typescript: program.typescript,
eslint: program.eslint,
experimentalApp: program.experimentalApp, experimentalApp: program.experimentalApp,
}) })
} }
......
...@@ -29,6 +29,7 @@ export const installTemplate = async ({ ...@@ -29,6 +29,7 @@ export const installTemplate = async ({
isOnline, isOnline,
template, template,
mode, mode,
eslint,
}: InstallTemplateArgs) => { }: InstallTemplateArgs) => {
console.log(chalk.bold(`Using ${packageManager}.`)) console.log(chalk.bold(`Using ${packageManager}.`))
...@@ -62,21 +63,24 @@ export const installTemplate = async ({ ...@@ -62,21 +63,24 @@ export const installTemplate = async ({
* Default dependencies. * Default dependencies.
*/ */
const dependencies = ['react', 'react-dom', 'next'] const dependencies = ['react', 'react-dom', 'next']
/**
* Default devDependencies.
*/
const devDependencies = ['eslint', 'eslint-config-next']
/** /**
* TypeScript projects will have type definitions and other devDependencies. * TypeScript projects will have type definitions and other devDependencies.
*/ */
if (mode === 'ts') { if (mode === 'ts') {
devDependencies.push( dependencies.push(
'typescript', 'typescript',
'@types/react', '@types/react',
'@types/node', '@types/node',
'@types/react-dom' '@types/react-dom'
) )
} }
/**
* Default eslint dependencies.
*/
if (eslint) {
dependencies.push('eslint', 'eslint-config-next')
}
/** /**
* Install package.json dependencies if they exist. * Install package.json dependencies if they exist.
*/ */
...@@ -90,24 +94,10 @@ export const installTemplate = async ({ ...@@ -90,24 +94,10 @@ export const installTemplate = async ({
await install(root, dependencies, installFlags) await install(root, dependencies, installFlags)
} }
/**
* Install package.json devDependencies if they exist.
*/
if (devDependencies.length) {
console.log()
console.log('Installing devDependencies:')
for (const devDependency of devDependencies) {
console.log(`- ${chalk.cyan(devDependency)}`)
}
console.log()
const devInstallFlags = { devDependencies: true, ...installFlags }
await install(root, devDependencies, devInstallFlags)
}
/** /**
* Copy the template files to the target directory. * Copy the template files to the target directory.
*/ */
console.log('\nInitializing project with template: ', template, '\n') console.log('\nInitializing project with template:', template, '\n')
const templatePath = path.join(__dirname, template, mode) const templatePath = path.join(__dirname, template, mode)
await cpy('**', root, { await cpy('**', root, {
parents: true, parents: true,
...@@ -129,6 +119,11 @@ export const installTemplate = async ({ ...@@ -129,6 +119,11 @@ export const installTemplate = async ({
} }
}, },
}) })
if (!eslint) {
// remove un-necessary template file if eslint is not desired
await fs.promises.unlink(path.join(root, '.eslintrc.json'))
}
} }
export * from './types' export * from './types'
...@@ -17,4 +17,5 @@ export interface InstallTemplateArgs { ...@@ -17,4 +17,5 @@ export interface InstallTemplateArgs {
template: TemplateType template: TemplateType
mode: TemplateMode mode: TemplateMode
eslint: boolean
} }
...@@ -36,7 +36,10 @@ describe('create next app', () => { ...@@ -36,7 +36,10 @@ describe('create next app', () => {
const pkg = path.join(cwd, projectName, 'package.json') const pkg = path.join(cwd, projectName, 'package.json')
fs.writeFileSync(pkg, '{ "foo": "bar" }') fs.writeFileSync(pkg, '{ "foo": "bar" }')
const res = await run([projectName, '--js'], { cwd, reject: false }) const res = await run([projectName, '--js', '--eslint'], {
cwd,
reject: false,
})
expect(res.exitCode).toBe(1) expect(res.exitCode).toBe(1)
expect(res.stdout).toMatch(/contains files that could conflict/) expect(res.stdout).toMatch(/contains files that could conflict/)
}) })
...@@ -48,7 +51,7 @@ describe('create next app', () => { ...@@ -48,7 +51,7 @@ describe('create next app', () => {
it('empty directory', async () => { it('empty directory', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'empty-directory' const projectName = 'empty-directory'
const res = await run([projectName, '--js'], { cwd }) const res = await run([projectName, '--js', '--eslint'], { cwd })
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
shouldBeJavascriptProject({ cwd, projectName, template: 'default' }) shouldBeJavascriptProject({ cwd, projectName, template: 'default' })
...@@ -60,7 +63,7 @@ describe('create next app', () => { ...@@ -60,7 +63,7 @@ describe('create next app', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'invalid-example-name' const projectName = 'invalid-example-name'
const res = await run( const res = await run(
[projectName, '--js', '--example', 'not a real example'], [projectName, '--js', '--eslint', '--example', 'not a real example'],
{ {
cwd, cwd,
reject: false, reject: false,
...@@ -79,9 +82,12 @@ describe('create next app', () => { ...@@ -79,9 +82,12 @@ describe('create next app', () => {
it('valid example', async () => { it('valid example', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'valid-example' const projectName = 'valid-example'
const res = await run([projectName, '--js', '--example', 'basic-css'], { const res = await run(
cwd, [projectName, '--js', '--eslint', '--example', 'basic-css'],
}) {
cwd,
}
)
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
projectFilesShouldExist({ projectFilesShouldExist({
cwd, cwd,
...@@ -100,7 +106,7 @@ describe('create next app', () => { ...@@ -100,7 +106,7 @@ describe('create next app', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'valid-example-without-package-json' const projectName = 'valid-example-without-package-json'
const res = await run( const res = await run(
[projectName, '--js', '--example', 'with-docker-compose'], [projectName, '--js', '--eslint', '--example', 'with-docker-compose'],
{ {
cwd, cwd,
} }
...@@ -119,7 +125,13 @@ describe('create next app', () => { ...@@ -119,7 +125,13 @@ describe('create next app', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'github-app' const projectName = 'github-app'
const res = await run( const res = await run(
[projectName, '--js', '--example', `${exampleRepo}/${examplePath}`], [
projectName,
'--js',
'--eslint',
'--example',
`${exampleRepo}/${examplePath}`,
],
{ {
cwd, cwd,
} }
...@@ -146,6 +158,7 @@ describe('create next app', () => { ...@@ -146,6 +158,7 @@ describe('create next app', () => {
[ [
projectName, projectName,
'--js', '--js',
'--eslint',
'--example', '--example',
'https://github.com/vercel/nextjs-portfolio-starter/', 'https://github.com/vercel/nextjs-portfolio-starter/',
], ],
...@@ -175,6 +188,7 @@ describe('create next app', () => { ...@@ -175,6 +188,7 @@ describe('create next app', () => {
[ [
projectName, projectName,
'--js', '--js',
'--eslint',
'--example', '--example',
exampleRepo, exampleRepo,
'--example-path', '--example-path',
...@@ -206,6 +220,7 @@ describe('create next app', () => { ...@@ -206,6 +220,7 @@ describe('create next app', () => {
[ [
projectName, projectName,
'--js', '--js',
'--eslint',
'--example', '--example',
`${exampleRepo}/${examplePath}`, `${exampleRepo}/${examplePath}`,
'--example-path', '--example-path',
...@@ -237,7 +252,13 @@ describe('create next app', () => { ...@@ -237,7 +252,13 @@ describe('create next app', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'fail-example' const projectName = 'fail-example'
const res = await run( const res = await run(
[projectName, '--js', '--example', '__internal-testing-retry'], [
projectName,
'--js',
'--eslint',
'--example',
'__internal-testing-retry',
],
{ {
cwd, cwd,
input: '\n', input: '\n',
...@@ -253,9 +274,12 @@ describe('create next app', () => { ...@@ -253,9 +274,12 @@ describe('create next app', () => {
it('should allow an example named default', async () => { it('should allow an example named default', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'default-example' const projectName = 'default-example'
const res = await run([projectName, '--js', '--example', 'default'], { const res = await run(
cwd, [projectName, '--js', '--eslint', '--example', 'default'],
}) {
cwd,
}
)
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
shouldBeJavascriptProject({ cwd, projectName, template: 'default' }) shouldBeJavascriptProject({ cwd, projectName, template: 'default' })
...@@ -265,7 +289,7 @@ describe('create next app', () => { ...@@ -265,7 +289,7 @@ describe('create next app', () => {
it('should exit if example flag is empty', async () => { it('should exit if example flag is empty', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'no-example-provided' const projectName = 'no-example-provided'
const res = await run([projectName, '--js', '--example'], { const res = await run([projectName, '--js', '--eslint', '--example'], {
cwd, cwd,
reject: false, reject: false,
}) })
...@@ -277,7 +301,10 @@ describe('create next app', () => { ...@@ -277,7 +301,10 @@ describe('create next app', () => {
it('should exit if the folder is not writable', async () => { it('should exit if the folder is not writable', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'not-writable' const projectName = 'not-writable'
const res = await run([projectName, '--js'], { cwd, reject: false }) const res = await run([projectName, '--js', '--eslint'], {
cwd,
reject: false,
})
if (process.platform === 'win32') { if (process.platform === 'win32') {
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
...@@ -311,7 +338,7 @@ describe('create next app', () => { ...@@ -311,7 +338,7 @@ describe('create next app', () => {
delete env.npm_config_user_agent delete env.npm_config_user_agent
} }
const res = await run(['.', '--js'], { const res = await run(['.', '--js', '--eslint'], {
cwd, cwd,
env, env,
extendEnv: false, extendEnv: false,
...@@ -327,7 +354,10 @@ describe('create next app', () => { ...@@ -327,7 +354,10 @@ describe('create next app', () => {
it('should ask the user for a name for the project if none supplied', async () => { it('should ask the user for a name for the project if none supplied', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'test-project' const projectName = 'test-project'
const res = await run(['--js'], { cwd, input: `${projectName}\n` }) const res = await run(['--js', '--eslint'], {
cwd,
input: `${projectName}\n`,
})
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
shouldBeJavascriptProject({ cwd, projectName, template: 'default' }) shouldBeJavascriptProject({ cwd, projectName, template: 'default' })
...@@ -337,7 +367,9 @@ describe('create next app', () => { ...@@ -337,7 +367,9 @@ describe('create next app', () => {
it('should use npm as the package manager on supplying --use-npm', async () => { it('should use npm as the package manager on supplying --use-npm', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'use-npm' const projectName = 'use-npm'
const res = await run([projectName, '--js', '--use-npm'], { cwd }) const res = await run([projectName, '--js', '--eslint', '--use-npm'], {
cwd,
})
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
shouldBeJavascriptProject({ cwd, projectName, template: 'default' }) shouldBeJavascriptProject({ cwd, projectName, template: 'default' })
...@@ -351,6 +383,7 @@ describe('create next app', () => { ...@@ -351,6 +383,7 @@ describe('create next app', () => {
[ [
projectName, projectName,
'--js', '--js',
'--eslint',
'--use-npm', '--use-npm',
'--example', '--example',
`${exampleRepo}/${examplePath}`, `${exampleRepo}/${examplePath}`,
...@@ -376,7 +409,9 @@ describe('create next app', () => { ...@@ -376,7 +409,9 @@ describe('create next app', () => {
it('should use pnpm as the package manager on supplying --use-pnpm', async () => { it('should use pnpm as the package manager on supplying --use-pnpm', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'use-pnpm' const projectName = 'use-pnpm'
const res = await run([projectName, '--js', '--use-pnpm'], { cwd }) const res = await run([projectName, '--js', '--eslint', '--use-pnpm'], {
cwd,
})
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
projectFilesShouldExist({ projectFilesShouldExist({
...@@ -408,6 +443,7 @@ describe('create next app', () => { ...@@ -408,6 +443,7 @@ describe('create next app', () => {
[ [
projectName, projectName,
'--js', '--js',
'--eslint',
'--use-pnpm', '--use-pnpm',
'--example', '--example',
`${exampleRepo}/${examplePath}`, `${exampleRepo}/${examplePath}`,
...@@ -433,7 +469,7 @@ describe('create next app', () => { ...@@ -433,7 +469,7 @@ describe('create next app', () => {
it('should infer npm as the package manager', async () => { it('should infer npm as the package manager', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'infer-package-manager-npm' const projectName = 'infer-package-manager-npm'
const res = await run([projectName, '--js'], { const res = await run([projectName, '--js', '--eslint'], {
cwd, cwd,
env: { ...process.env, npm_config_user_agent: 'npm' }, env: { ...process.env, npm_config_user_agent: 'npm' },
}) })
...@@ -456,7 +492,13 @@ describe('create next app', () => { ...@@ -456,7 +492,13 @@ describe('create next app', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'infer-package-manager-npm' const projectName = 'infer-package-manager-npm'
const res = await run( const res = await run(
[projectName, '--js', '--example', `${exampleRepo}/${examplePath}`], [
projectName,
'--js',
'--eslint',
'--example',
`${exampleRepo}/${examplePath}`,
],
{ cwd, env: { ...process.env, npm_config_user_agent: 'npm' } } { cwd, env: { ...process.env, npm_config_user_agent: 'npm' } }
) )
...@@ -483,7 +525,7 @@ describe('create next app', () => { ...@@ -483,7 +525,7 @@ describe('create next app', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'infer-package-manager-yarn' const projectName = 'infer-package-manager-yarn'
const res = await run([projectName, '--js'], { const res = await run([projectName, '--js', '--eslint'], {
cwd, cwd,
env: { ...process.env, npm_config_user_agent: 'yarn' }, env: { ...process.env, npm_config_user_agent: 'yarn' },
}) })
...@@ -513,7 +555,13 @@ describe('create next app', () => { ...@@ -513,7 +555,13 @@ describe('create next app', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'infer-package-manager-npm' const projectName = 'infer-package-manager-npm'
const res = await run( const res = await run(
[projectName, '--js', '--example', `${exampleRepo}/${examplePath}`], [
projectName,
'--js',
'--eslint',
'--example',
`${exampleRepo}/${examplePath}`,
],
{ cwd, env: { ...process.env, npm_config_user_agent: 'yarn' } } { cwd, env: { ...process.env, npm_config_user_agent: 'yarn' } }
) )
...@@ -540,7 +588,7 @@ describe('create next app', () => { ...@@ -540,7 +588,7 @@ describe('create next app', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'infer-package-manager' const projectName = 'infer-package-manager'
const res = await run([projectName, '--js'], { const res = await run([projectName, '--js', '--eslint'], {
cwd, cwd,
env: { ...process.env, npm_config_user_agent: 'pnpm' }, env: { ...process.env, npm_config_user_agent: 'pnpm' },
}) })
...@@ -571,7 +619,13 @@ it('should infer pnpm as the package manager with example', async () => { ...@@ -571,7 +619,13 @@ it('should infer pnpm as the package manager with example', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'infer-package-manager-npm' const projectName = 'infer-package-manager-npm'
const res = await run( const res = await run(
[projectName, '--js', '--example', `${exampleRepo}/${examplePath}`], [
projectName,
'--js',
'--eslint',
'--example',
`${exampleRepo}/${examplePath}`,
],
{ cwd, env: { ...process.env, npm_config_user_agent: 'pnpm' } } { cwd, env: { ...process.env, npm_config_user_agent: 'pnpm' } }
) )
......
...@@ -28,8 +28,8 @@ export const projectSpecification: ProjectSpecification = { ...@@ -28,8 +28,8 @@ export const projectSpecification: ProjectSpecification = {
'node_modules/next', 'node_modules/next',
'.gitignore', '.gitignore',
], ],
deps: ['next', 'react', 'react-dom'], deps: ['next', 'react', 'react-dom', 'eslint', 'eslint-config-next'],
devDeps: ['eslint', 'eslint-config-next'], devDeps: [],
}, },
default: { default: {
js: { js: {
...@@ -45,13 +45,8 @@ export const projectSpecification: ProjectSpecification = { ...@@ -45,13 +45,8 @@ export const projectSpecification: ProjectSpecification = {
'tsconfig.json', 'tsconfig.json',
'next-env.d.ts', 'next-env.d.ts',
], ],
deps: [], deps: ['@types/node', '@types/react', '@types/react-dom', 'typescript'],
devDeps: [ devDeps: [],
'@types/node',
'@types/react',
'@types/react-dom',
'typescript',
],
}, },
}, },
app: { app: {
...@@ -61,13 +56,8 @@ export const projectSpecification: ProjectSpecification = { ...@@ -61,13 +56,8 @@ export const projectSpecification: ProjectSpecification = {
files: ['app/page.jsx', 'app/layout.jsx', 'pages/api/hello.js'], files: ['app/page.jsx', 'app/layout.jsx', 'pages/api/hello.js'],
}, },
ts: { ts: {
deps: [], deps: ['@types/node', '@types/react', '@types/react-dom', 'typescript'],
devDeps: [ devDeps: [],
'@types/node',
'@types/react',
'@types/react-dom',
'typescript',
],
files: [ files: [
'app/page.tsx', 'app/page.tsx',
'app/layout.tsx', 'app/layout.tsx',
......
...@@ -69,7 +69,7 @@ export const projectDepsShouldBe = ({ ...@@ -69,7 +69,7 @@ export const projectDepsShouldBe = ({
}: ProjectDeps) => { }: ProjectDeps) => {
const projectRoot = resolve(cwd, projectName) const projectRoot = resolve(cwd, projectName)
const pkgJson = require(resolve(projectRoot, 'package.json')) const pkgJson = require(resolve(projectRoot, 'package.json'))
expect(Object.keys(pkgJson[type]).sort()).toEqual(deps.sort()) expect(Object.keys(pkgJson[type] || {}).sort()).toEqual(deps.sort())
} }
export const shouldBeTemplateProject = ({ export const shouldBeTemplateProject = ({
......
...@@ -25,7 +25,7 @@ describe('create-next-app templates', () => { ...@@ -25,7 +25,7 @@ describe('create-next-app templates', () => {
/** /**
* Start the create-next-app call. * Start the create-next-app call.
*/ */
const childProcess = createNextApp([projectName], { cwd }) const childProcess = createNextApp([projectName, '--eslint'], { cwd })
/** /**
* Wait for the prompt to display. * Wait for the prompt to display.
*/ */
...@@ -54,7 +54,9 @@ describe('create-next-app templates', () => { ...@@ -54,7 +54,9 @@ describe('create-next-app templates', () => {
it('should create TS projects with --ts, --typescript', async () => { it('should create TS projects with --ts, --typescript', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'typescript-test' const projectName = 'typescript-test'
const childProcess = createNextApp([projectName, '--ts'], { cwd }) const childProcess = createNextApp([projectName, '--ts', '--eslint'], {
cwd,
})
const exitCode = await spawnExitPromise(childProcess) const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
...@@ -65,7 +67,9 @@ describe('create-next-app templates', () => { ...@@ -65,7 +67,9 @@ describe('create-next-app templates', () => {
it('should create JS projects with --js, --javascript', async () => { it('should create JS projects with --js, --javascript', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'javascript-test' const projectName = 'javascript-test'
const childProcess = createNextApp([projectName, '--js'], { cwd }) const childProcess = createNextApp([projectName, '--js', '--eslint'], {
cwd,
})
const exitCode = await spawnExitPromise(childProcess) const exitCode = await spawnExitPromise(childProcess)
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
...@@ -79,7 +83,7 @@ describe('create-next-app --experimental-app-dir', () => { ...@@ -79,7 +83,7 @@ describe('create-next-app --experimental-app-dir', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'appdir-test' const projectName = 'appdir-test'
const childProcess = createNextApp( const childProcess = createNextApp(
[projectName, '--ts', '--experimental-app'], [projectName, '--ts', '--experimental-app', '--eslint'],
{ {
cwd, cwd,
} }
...@@ -95,7 +99,7 @@ describe('create-next-app --experimental-app-dir', () => { ...@@ -95,7 +99,7 @@ describe('create-next-app --experimental-app-dir', () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'appdir-test' const projectName = 'appdir-test'
const childProcess = createNextApp( const childProcess = createNextApp(
[projectName, '--js', '--experimental-app'], [projectName, '--js', '--experimental-app', '--eslint'],
{ {
cwd, cwd,
} }
......
...@@ -10,7 +10,10 @@ export async function useTempDir( ...@@ -10,7 +10,10 @@ export async function useTempDir(
fn: (folder: string) => void | Promise<void>, fn: (folder: string) => void | Promise<void>,
mode?: string | number mode?: string | number
) { ) {
const folder = path.join(os.tmpdir(), Math.random().toString(36).slice(2)) const folder = path.join(
os.tmpdir(),
'next-test-' + Math.random().toString(36).slice(2)
)
await fs.mkdirp(folder) await fs.mkdirp(folder)
if (mode) { if (mode) {
......
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