From 12f48a4644f8c95e31f36771bddc1b3235b464cb Mon Sep 17 00:00:00 2001 From: Stefan Probst Date: Thu, 17 Aug 2023 09:25:42 +0200 Subject: [PATCH 1/3] fix: check verbatimModuleSyntax in tsconfig extends before adding isolatedModules --- .../next/src/lib/typescript/writeConfigurationDefaults.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/next/src/lib/typescript/writeConfigurationDefaults.ts b/packages/next/src/lib/typescript/writeConfigurationDefaults.ts index 7404ff48fca1d..f008c831b80fb 100644 --- a/packages/next/src/lib/typescript/writeConfigurationDefaults.ts +++ b/packages/next/src/lib/typescript/writeConfigurationDefaults.ts @@ -19,7 +19,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 @@ -79,7 +79,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: { @@ -138,7 +138,7 @@ export async function writeConfigurationDefaults( isFirstTimeSetup = true } - const desiredCompilerOptions = getDesiredCompilerOptions(ts, userTsConfig) + const desiredCompilerOptions = getDesiredCompilerOptions(ts, tsOptions) const suggestedActions: string[] = [] const requiredActions: string[] = [] From 4fbc8284a4315fd52c572cc3147ee6a010624074 Mon Sep 17 00:00:00 2001 From: Stefan Probst Date: Thu, 17 Aug 2023 09:40:50 +0200 Subject: [PATCH 2/3] test: add integration test --- .../tsconfig-verifier/test/index.test.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/integration/tsconfig-verifier/test/index.test.js b/test/integration/tsconfig-verifier/test/index.test.js index fdb648b46ee10..139570d31e479 100644 --- a/test/integration/tsconfig-verifier/test/index.test.js +++ b/test/integration/tsconfig-verifier/test/index.test.js @@ -566,6 +566,63 @@ describe('tsconfig.json verifier', () => { `) }) + 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) From 7bca4e771d12ae18defc8ced6a9974854ca6581a Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Sat, 7 Oct 2023 06:57:13 -0700 Subject: [PATCH 3/3] lint --- test/integration/tsconfig-verifier/test/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/tsconfig-verifier/test/index.test.js b/test/integration/tsconfig-verifier/test/index.test.js index 8798acd975885..9738c31d16adf 100644 --- a/test/integration/tsconfig-verifier/test/index.test.js +++ b/test/integration/tsconfig-verifier/test/index.test.js @@ -570,7 +570,7 @@ 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 } }` @@ -583,7 +583,7 @@ import path from 'path' }) expect(stderr + stdout).not.toContain('isolatedModules') expect(code).toBe(0) - + expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(` "{ \\"extends\\": \\"./tsconfig.base.json\\",