Unverified Commit 5da108bc authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update default eslint choice for CNA setup (#42371)

This ensures we continue to default to ESLint be configured for new
projects so that our lint checks are enabled for new projects.

## 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 cd897b5c
...@@ -156,53 +156,59 @@ async function run(): Promise<void> { ...@@ -156,53 +156,59 @@ 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.
*/ */
if (!example && !program.typescript && !program.javascript) { if (!example) {
if (ciInfo.isCI) { if (ciInfo.isCI) {
// default to JavaScript in CI as we can't prompt to // default to JavaScript in CI as we can't prompt to
// prevent breaking setup flows // prevent breaking setup flows
program.javascript = true program.javascript = true
program.typescript = false program.typescript = false
program.eslint = false program.eslint = true
} else { } else {
const styledTypeScript = chalk.hex('#007acc')('TypeScript') if (!program.typescript && !program.javascript) {
const { typescript } = await prompts( const styledTypeScript = chalk.hex('#007acc')('TypeScript')
{ const { typescript } = await prompts(
type: 'toggle', {
name: 'typescript', type: 'toggle',
message: `Would you like to use ${styledTypeScript} with this project?`, name: 'typescript',
initial: true, message: `Would you like to use ${styledTypeScript} with this project?`,
active: 'Yes', initial: true,
inactive: 'No', active: 'Yes',
}, inactive: 'No',
{
/**
* User inputs Ctrl+C or Ctrl+D to exit the prompt. We should close the
* process and not write to the file system.
*/
onCancel: () => {
console.error('Exiting.')
process.exit(1)
}, },
} {
) /**
* User inputs Ctrl+C or Ctrl+D to exit the prompt. We should close the
* process and not write to the file system.
*/
onCancel: () => {
console.error('Exiting.')
process.exit(1)
},
}
)
/**
* Depending on the prompt response, set the appropriate program flags.
*/
program.typescript = Boolean(typescript)
program.javascript = !Boolean(typescript)
}
if (!program.eslint) { if (
!process.argv.includes('--eslint') &&
!process.argv.includes('--no-eslint')
) {
const styledEslint = chalk.hex('#007acc')('ESLint') const styledEslint = chalk.hex('#007acc')('ESLint')
const { eslint } = await prompts({ const { eslint } = await prompts({
type: 'toggle', type: 'toggle',
name: 'eslint', name: 'eslint',
message: `Would you like to use ${styledEslint} with this project?`, message: `Would you like to use ${styledEslint} with this project?`,
initial: false, initial: true,
active: 'Yes', active: 'Yes',
inactive: 'No', inactive: 'No',
}) })
program.eslint = Boolean(eslint) program.eslint = Boolean(eslint)
} }
/**
* Depending on the prompt response, set the appropriate program flags.
*/
program.typescript = Boolean(typescript)
program.javascript = !Boolean(typescript)
} }
} }
......
...@@ -53,13 +53,19 @@ export const projectSpecification: ProjectSpecification = { ...@@ -53,13 +53,19 @@ export const projectSpecification: ProjectSpecification = {
js: { js: {
deps: [], deps: [],
devDeps: [], devDeps: [],
files: ['app/page.jsx', 'app/layout.jsx', 'pages/api/hello.js'], files: [
'app/page.jsx',
'app/head.jsx',
'app/layout.jsx',
'pages/api/hello.js',
],
}, },
ts: { ts: {
deps: ['@types/node', '@types/react', '@types/react-dom', 'typescript'], deps: ['@types/node', '@types/react', '@types/react-dom', 'typescript'],
devDeps: [], devDeps: [],
files: [ files: [
'app/page.tsx', 'app/page.tsx',
'app/head.tsx',
'app/layout.tsx', 'app/layout.tsx',
'pages/api/hello.ts', 'pages/api/hello.ts',
'tsconfig.json', 'tsconfig.json',
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import { ChildProcess, spawn, SpawnOptions } from 'child_process' import { ChildProcess, spawn, SpawnOptions } from 'child_process'
import { existsSync } from 'fs' import { existsSync } from 'fs'
import { resolve } from 'path' import { resolve } from 'path'
import glob from 'glob'
import { getProjectSetting, projectSpecification } from './specification' import { getProjectSetting, projectSpecification } from './specification'
import { CustomTemplateOptions, ProjectDeps, ProjectFiles } from './types' import { CustomTemplateOptions, ProjectDeps, ProjectFiles } from './types'
...@@ -18,7 +19,21 @@ const cli = require.resolve('create-next-app/dist/index.js') ...@@ -18,7 +19,21 @@ const cli = require.resolve('create-next-app/dist/index.js')
*/ */
export const createNextApp = (args: string[], options?: SpawnOptions) => { export const createNextApp = (args: string[], options?: SpawnOptions) => {
console.log(`[TEST] $ ${cli} ${args.join(' ')}`, { options }) console.log(`[TEST] $ ${cli} ${args.join(' ')}`, { options })
return spawn('node', [cli].concat(args), options ?? {}) return spawn('node', [cli].concat(args), {
...options,
env: {
...process.env,
...options.env,
// unset CI env as this skips the auto-install behavior
// being tested
CI: '',
CIRCLECI: '',
GITHUB_ACTIONS: '',
CONTINUOUS_INTEGRATION: '',
RUN_ID: '',
BUILD_NUMBER: '',
},
})
} }
/** /**
...@@ -46,7 +61,16 @@ export const projectFilesShouldExist = ({ ...@@ -46,7 +61,16 @@ export const projectFilesShouldExist = ({
}: ProjectFiles) => { }: ProjectFiles) => {
const projectRoot = resolve(cwd, projectName) const projectRoot = resolve(cwd, projectName)
for (const file of files) { for (const file of files) {
expect(existsSync(resolve(projectRoot, file))).toBe(true) try {
expect(existsSync(resolve(projectRoot, file))).toBe(true)
} catch (err) {
require('console').error(
`missing expected file ${file}`,
glob.sync('**/*', { cwd, ignore: '**/node_modules/**' }),
files
)
throw err
}
} }
} }
...@@ -57,7 +81,16 @@ export const projectFilesShouldNotExist = ({ ...@@ -57,7 +81,16 @@ export const projectFilesShouldNotExist = ({
}: ProjectFiles) => { }: ProjectFiles) => {
const projectRoot = resolve(cwd, projectName) const projectRoot = resolve(cwd, projectName)
for (const file of files) { for (const file of files) {
expect(existsSync(resolve(projectRoot, file))).toBe(false) try {
expect(existsSync(resolve(projectRoot, file))).toBe(false)
} catch (err) {
require('console').error(
`unexpected file present ${file}`,
glob.sync('**/*', { cwd, ignore: '**/node_modules/**' }),
files
)
throw err
}
} }
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import { import {
createNextApp, createNextApp,
projectFilesShouldNotExist, projectFilesShouldExist,
shouldBeJavascriptProject, shouldBeJavascriptProject,
shouldBeTemplateProject, shouldBeTemplateProject,
shouldBeTypescriptProject, shouldBeTypescriptProject,
...@@ -33,21 +33,24 @@ describe('create-next-app templates', () => { ...@@ -33,21 +33,24 @@ describe('create-next-app templates', () => {
/** /**
* Bind the exit listener. * Bind the exit listener.
*/ */
childProcess.on('exit', (exitCode) => { await new Promise<void>((resolve) => {
expect(exitCode).toBe(0) childProcess.on('exit', (exitCode) => {
expect(exitCode).toBe(0)
/**
* Verify it correctly emitted a TS project by looking for tsconfig.
*/
projectFilesShouldExist({
cwd,
projectName,
files: ['tsconfig.json'],
})
resolve()
})
/** /**
* Verify it correctly emitted a TS project by looking for tsconfig. * Simulate "Y" for TypeScript.
*/ */
projectFilesShouldNotExist({ childProcess.stdin.write('N\n')
cwd,
projectName,
files: ['tsconfig.json'],
})
}) })
/**
* Simulate "Y" for TypeScript.
*/
childProcess.stdin.write('N\n')
}) })
}) })
......
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