Skip to content

Commit 22b449b

Browse files
authored
Fix default value handling for CNA in CI (vercel#42596)
Fixes: vercel#42592 ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md`
1 parent 7bbc1ae commit 22b449b

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

packages/create-next-app/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,13 @@ async function run(): Promise<void> {
157157
* to use TS or JS.
158158
*/
159159
if (!example) {
160-
if (ciInfo.isCI) {
161-
// default to JavaScript in CI as we can't prompt to
162-
// prevent breaking setup flows
163-
program.javascript = true
164-
program.typescript = false
165-
program.eslint = true
166-
} else {
167-
if (!program.typescript && !program.javascript) {
160+
if (!program.typescript && !program.javascript) {
161+
if (ciInfo.isCI) {
162+
// default to JavaScript in CI as we can't prompt to
163+
// prevent breaking setup flows
164+
program.typescript = false
165+
program.javascript = true
166+
} else {
168167
const styledTypeScript = chalk.hex('#007acc')('TypeScript')
169168
const { typescript } = await prompts(
170169
{
@@ -186,18 +185,21 @@ async function run(): Promise<void> {
186185
},
187186
}
188187
)
189-
190188
/**
191189
* Depending on the prompt response, set the appropriate program flags.
192190
*/
193191
program.typescript = Boolean(typescript)
194192
program.javascript = !Boolean(typescript)
195193
}
194+
}
196195

197-
if (
198-
!process.argv.includes('--eslint') &&
199-
!process.argv.includes('--no-eslint')
200-
) {
196+
if (
197+
!process.argv.includes('--eslint') &&
198+
!process.argv.includes('--no-eslint')
199+
) {
200+
if (ciInfo.isCI) {
201+
program.eslint = true
202+
} else {
201203
const styledEslint = chalk.hex('#007acc')('ESLint')
202204
const { eslint } = await prompts({
203205
type: 'toggle',

test/integration/create-next-app/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const createNextApp = (args: string[], options?: SpawnOptions) => {
2323
...options,
2424
env: {
2525
...process.env,
26-
...options.env,
2726
// unset CI env as this skips the auto-install behavior
2827
// being tested
2928
CI: '',
@@ -32,6 +31,7 @@ export const createNextApp = (args: string[], options?: SpawnOptions) => {
3231
CONTINUOUS_INTEGRATION: '',
3332
RUN_ID: '',
3433
BUILD_NUMBER: '',
34+
...options.env,
3535
},
3636
})
3737
}

test/integration/create-next-app/templates.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ describe('create-next-app templates', () => {
6767
})
6868
})
6969

70+
it('should create TS projects with --ts, --typescript with CI=1', async () => {
71+
await useTempDir(async (cwd) => {
72+
const projectName = 'typescript-test'
73+
const childProcess = createNextApp([projectName, '--ts', '--eslint'], {
74+
cwd,
75+
env: {
76+
...process.env,
77+
CI: '1',
78+
GITHUB_ACTIONS: '1',
79+
},
80+
})
81+
const exitCode = await spawnExitPromise(childProcess)
82+
83+
expect(exitCode).toBe(0)
84+
shouldBeTypescriptProject({ cwd, projectName, template: 'default' })
85+
})
86+
})
87+
7088
it('should create JS projects with --js, --javascript', async () => {
7189
await useTempDir(async (cwd) => {
7290
const projectName = 'javascript-test'

0 commit comments

Comments
 (0)