Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't add isolateModules to tsconfig when extending from tsconfig with verbatimModuleSyntax #54164

Merged
merged 8 commits into from
Oct 7, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type DesiredCompilerOptionsShape = {

function getDesiredCompilerOptions(
ts: typeof import('typescript'),
userTsConfig?: { compilerOptions?: CompilerOptions }
tsOptions?: CompilerOptions
): DesiredCompilerOptionsShape {
const o: DesiredCompilerOptionsShape = {
// These are suggested values and will be set when not present in the
Expand Down Expand Up @@ -80,7 +80,7 @@ function getDesiredCompilerOptions(
reason: 'to match webpack resolution',
},
resolveJsonModule: { value: true, reason: 'to match webpack resolution' },
...(userTsConfig?.compilerOptions?.verbatimModuleSyntax === true
...(tsOptions?.verbatimModuleSyntax === true
? undefined
: {
isolatedModules: {
Expand Down Expand Up @@ -139,7 +139,7 @@ export async function writeConfigurationDefaults(
isFirstTimeSetup = true
}

const desiredCompilerOptions = getDesiredCompilerOptions(ts, userTsConfig)
const desiredCompilerOptions = getDesiredCompilerOptions(ts, tsOptions)

const suggestedActions: string[] = []
const requiredActions: string[] = []
Expand Down
57 changes: 57 additions & 0 deletions test/integration/tsconfig-verifier/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,63 @@ import path from 'path'
`)
})

it('allows you to set verbatimModuleSyntax true via extends without adding isolatedModules', async () => {
expect(await exists(tsConfig)).toBe(false)
expect(await exists(tsConfigBase)).toBe(false)

await writeFile(
tsConfigBase,
`{ "compilerOptions": { "verbatimModuleSyntax": true } }`
)
await writeFile(tsConfig, `{ "extends": "./tsconfig.base.json" }`)
await new Promise((resolve) => setTimeout(resolve, 500))
const { code, stderr, stdout } = await nextBuild(appDir, undefined, {
stderr: true,
stdout: true,
})
expect(stderr + stdout).not.toContain('isolatedModules')
expect(code).toBe(0)

expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
\\"extends\\": \\"./tsconfig.base.json\\",
\\"compilerOptions\\": {
\\"lib\\": [
\\"dom\\",
\\"dom.iterable\\",
\\"esnext\\"
],
\\"allowJs\\": true,
\\"skipLibCheck\\": true,
\\"strict\\": false,
\\"noEmit\\": true,
\\"incremental\\": true,
\\"esModuleInterop\\": true,
\\"module\\": \\"esnext\\",
\\"moduleResolution\\": \\"node\\",
\\"resolveJsonModule\\": true,
\\"jsx\\": \\"preserve\\",
\\"plugins\\": [
{
\\"name\\": \\"next\\"
}
],
\\"strictNullChecks\\": true
},
\\"include\\": [
\\"next-env.d.ts\\",
\\".next/types/**/*.ts\\",
\\"**/*.ts\\",
\\"**/*.tsx\\"
],
\\"exclude\\": [
\\"node_modules\\"
]
}
"
`)
})

it('allows you to extend another configuration file', async () => {
expect(await exists(tsConfig)).toBe(false)
expect(await exists(tsConfigBase)).toBe(false)
Expand Down
Loading