Unverified Commit 431178bf authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

update tsconfig correctly when compilerOptions is not set yet (#30355)

A tsconfig like:

```
{
  "extends": "..."
}
```

currently fails the build if the config that is extended from has not the expected configuration (and we want to update it)

Fixes: https://github.com/vercel/next.js/issues/30360
parent 718003c8
...@@ -117,6 +117,9 @@ export async function writeConfigurationDefaults( ...@@ -117,6 +117,9 @@ export async function writeConfigurationDefaults(
const check = desiredCompilerOptions[optionKey] const check = desiredCompilerOptions[optionKey]
if ('suggested' in check) { if ('suggested' in check) {
if (!(optionKey in tsOptions)) { if (!(optionKey in tsOptions)) {
if (!userTsConfig.compilerOptions) {
userTsConfig.compilerOptions = {}
}
userTsConfig.compilerOptions[optionKey] = check.suggested userTsConfig.compilerOptions[optionKey] = check.suggested
suggestedActions.push( suggestedActions.push(
chalk.cyan(optionKey) + ' was set to ' + chalk.bold(check.suggested) chalk.cyan(optionKey) + ' was set to ' + chalk.bold(check.suggested)
...@@ -131,6 +134,9 @@ export async function writeConfigurationDefaults( ...@@ -131,6 +134,9 @@ export async function writeConfigurationDefaults(
? check.parsedValue === ev ? check.parsedValue === ev
: check.value === ev) : check.value === ev)
) { ) {
if (!userTsConfig.compilerOptions) {
userTsConfig.compilerOptions = {}
}
userTsConfig.compilerOptions[optionKey] = check.value userTsConfig.compilerOptions[optionKey] = check.value
requiredActions.push( requiredActions.push(
chalk.cyan(optionKey) + chalk.cyan(optionKey) +
......
...@@ -315,4 +315,61 @@ describe('tsconfig.json verifier', () => { ...@@ -315,4 +315,61 @@ describe('tsconfig.json verifier', () => {
`"{ \\"extends\\": \\"./tsconfig.base.json\\" }"` `"{ \\"extends\\": \\"./tsconfig.base.json\\" }"`
) )
}) })
it('creates compilerOptions when you extend another config', async () => {
expect(await exists(tsConfig)).toBe(false)
expect(await exists(tsConfigBase)).toBe(false)
await writeFile(
tsConfigBase,
`
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
`
)
await new Promise((resolve) => setTimeout(resolve, 500))
await writeFile(tsConfig, `{ "extends": "./tsconfig.base.json" }`)
await new Promise((resolve) => setTimeout(resolve, 500))
const { code } = await nextBuild(appDir)
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
\\"extends\\": \\"./tsconfig.base.json\\",
\\"compilerOptions\\": {
\\"incremental\\": true
}
}
"
`)
})
}) })
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