From d7694cdcdfb8e8ed5991fd636c08060cc6e006f7 Mon Sep 17 00:00:00 2001 From: juliusmarminge Date: Fri, 5 Apr 2024 14:08:22 +0200 Subject: [PATCH 1/7] allow `module: Preserve` tsconfig option --- package.json | 2 +- .../typescript/writeConfigurationDefaults.ts | 66 +++++++------ packages/next/src/server/render.tsx | 2 +- pnpm-lock.yaml | 92 +++++++++---------- .../tsconfig-verifier/test/index.test.js | 62 ++++++++++++- 5 files changed, 145 insertions(+), 79 deletions(-) diff --git a/package.json b/package.json index b2acf0497946c..78f411bd395fe 100644 --- a/package.json +++ b/package.json @@ -232,7 +232,7 @@ "tree-kill": "1.2.2", "tsec": "0.2.1", "turbo": "1.12.5", - "typescript": "5.2.2", + "typescript": "5.4.4", "unfetch": "4.2.0", "wait-port": "0.2.2", "webpack": "5.90.0", diff --git a/packages/next/src/lib/typescript/writeConfigurationDefaults.ts b/packages/next/src/lib/typescript/writeConfigurationDefaults.ts index 5e257188565e6..262015e4bbeec 100644 --- a/packages/next/src/lib/typescript/writeConfigurationDefaults.ts +++ b/packages/next/src/lib/typescript/writeConfigurationDefaults.ts @@ -40,14 +40,11 @@ function getDesiredCompilerOptions( // These values are required and cannot be changed by the user // Keep this in sync with the webpack config // 'parsedValue' matches the output value from ts.parseJsonConfigFileContent() - esModuleInterop: { - value: true, - reason: 'requirement for SWC / babel', - }, module: { parsedValue: ts.ModuleKind.ESNext, // All of these values work: parsedValues: [ + ts.ModuleKind.Preserve, ts.ModuleKind.ES2020, ts.ModuleKind.ESNext, ts.ModuleKind.CommonJS, @@ -58,28 +55,45 @@ function getDesiredCompilerOptions( value: 'esnext', reason: 'for dynamic import() support', }, - moduleResolution: { - // In TypeScript 5.0, `NodeJs` has renamed to `Node10` - parsedValue: - ts.ModuleResolutionKind.Bundler ?? - ts.ModuleResolutionKind.NodeNext ?? - (ts.ModuleResolutionKind as any).Node10 ?? - ts.ModuleResolutionKind.NodeJs, - // All of these values work: - parsedValues: [ - (ts.ModuleResolutionKind as any).Node10 ?? - ts.ModuleResolutionKind.NodeJs, - // only newer TypeScript versions have this field, it - // will be filtered for new versions of TypeScript - (ts.ModuleResolutionKind as any).Node12, - ts.ModuleResolutionKind.Node16, - ts.ModuleResolutionKind.NodeNext, - ts.ModuleResolutionKind.Bundler, - ].filter((val) => typeof val !== 'undefined'), - value: 'node', - reason: 'to match webpack resolution', - }, - resolveJsonModule: { value: true, reason: 'to match webpack resolution' }, + ...(tsOptions?.module === ts.ModuleKind.Preserve + ? { + // TypeScript 5.4 introduced `Preserve`. Using `Preserve` implies + // - `moduleResolution` is `Bundler` + // - `esModuleInterop` is `true` + // - `resolveJsonModule` is `true` + // This means that if the user is using Preserve, they don't need these options + } + : { + esModuleInterop: { + value: true, + reason: 'requirement for SWC / babel', + }, + moduleResolution: { + // In TypeScript 5.0, `NodeJs` has renamed to `Node10` + parsedValue: + ts.ModuleResolutionKind.Bundler ?? + ts.ModuleResolutionKind.NodeNext ?? + (ts.ModuleResolutionKind as any).Node10 ?? + ts.ModuleResolutionKind.NodeJs, + // All of these values work: + parsedValues: [ + (ts.ModuleResolutionKind as any).Node10 ?? + ts.ModuleResolutionKind.NodeJs, + // only newer TypeScript versions have this field, it + // will be filtered for new versions of TypeScript + (ts.ModuleResolutionKind as any).Node12, + ts.ModuleResolutionKind.Node16, + ts.ModuleResolutionKind.NodeNext, + ts.ModuleResolutionKind.Bundler, + ].filter((val) => typeof val !== 'undefined'), + value: 'node', + reason: 'to match webpack resolution', + }, + resolveJsonModule: { + value: true, + reason: 'to match webpack resolution', + }, + }), ...(tsOptions?.verbatimModuleSyntax === true ? undefined : { diff --git a/packages/next/src/server/render.tsx b/packages/next/src/server/render.tsx index c57a2e3da5330..4f8cbdd7e1018 100644 --- a/packages/next/src/server/render.tsx +++ b/packages/next/src/server/render.tsx @@ -1348,7 +1348,7 @@ export async function renderToHTMLImpl( (initialStream: ReactReadableStream, suffix?: string) => { return continueFizzStream(initialStream, { suffix, - inlinedDataStream: serverComponentsInlinedTransformStream?.readable, + inlinedDataStream: (serverComponentsInlinedTransformStream as any)?.readable, isStaticGeneration: true, // this must be called inside bodyResult so appWrappers is // up to date when `wrapApp` is called diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0bb9687c9ccd7..1397745af0c1b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -178,10 +178,10 @@ importers: version: 2.0.3 '@typescript-eslint/eslint-plugin': specifier: 6.14.0 - version: 6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.2.2) + version: 6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.4.4) '@typescript-eslint/parser': specifier: 6.14.0 - version: 6.14.0(eslint@8.56.0)(typescript@5.2.2) + version: 6.14.0(eslint@8.56.0)(typescript@5.4.4) '@vercel/fetch': specifier: 6.1.1 version: 6.1.1(@types/node-fetch@2.6.1)(node-fetch@2.6.7) @@ -256,7 +256,7 @@ importers: version: 2.29.1(@typescript-eslint/parser@6.14.0)(eslint@8.56.0) eslint-plugin-jest: specifier: 27.6.3 - version: 27.6.3(@typescript-eslint/eslint-plugin@6.14.0)(eslint@8.56.0)(jest@29.7.0)(typescript@5.2.2) + version: 27.6.3(@typescript-eslint/eslint-plugin@6.14.0)(eslint@8.56.0)(jest@29.7.0)(typescript@5.4.4) eslint-plugin-jsdoc: specifier: 48.0.4 version: 48.0.4(eslint@8.56.0) @@ -535,13 +535,13 @@ importers: version: 1.2.2 tsec: specifier: 0.2.1 - version: 0.2.1(@bazel/bazelisk@1.18.0)(typescript@5.2.2) + version: 0.2.1(@bazel/bazelisk@1.18.0)(typescript@5.4.4) turbo: specifier: 1.12.5 version: 1.12.5 typescript: - specifier: 5.2.2 - version: 5.2.2 + specifier: 5.4.4 + version: 5.4.4 unfetch: specifier: 4.2.0 version: 4.2.0 @@ -1243,7 +1243,7 @@ importers: version: 2.4.4(webpack@5.90.0) msw: specifier: 1.3.0 - version: 1.3.0(typescript@5.2.2) + version: 1.3.0(typescript@5.4.4) nanoid: specifier: 3.1.32 version: 3.1.32 @@ -7234,7 +7234,7 @@ packages: dev: true optional: true - /@typescript-eslint/eslint-plugin@6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.2.2): + /@typescript-eslint/eslint-plugin@6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.4.4): resolution: {integrity: sha512-1ZJBykBCXaSHG94vMMKmiHoL0MhNHKSVlcHVYZNw+BKxufhqQVTOawNpwwI1P5nIFZ/4jLVop0mcY6mJJDFNaw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7246,10 +7246,10 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.5.1 - '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.2.2) + '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.4.4) '@typescript-eslint/scope-manager': 6.14.0 - '@typescript-eslint/type-utils': 6.14.0(eslint@8.56.0)(typescript@5.2.2) - '@typescript-eslint/utils': 6.14.0(eslint@8.56.0)(typescript@5.2.2) + '@typescript-eslint/type-utils': 6.14.0(eslint@8.56.0)(typescript@5.4.4) + '@typescript-eslint/utils': 6.14.0(eslint@8.56.0)(typescript@5.4.4) '@typescript-eslint/visitor-keys': 6.14.0 debug: 4.3.4 eslint: 8.56.0 @@ -7257,8 +7257,8 @@ packages: ignore: 5.2.4 natural-compare: 1.4.0 semver: 7.5.4 - ts-api-utils: 1.0.1(typescript@5.2.2) - typescript: 5.2.2 + ts-api-utils: 1.0.1(typescript@5.4.4) + typescript: 5.4.4 transitivePeerDependencies: - supports-color dev: true @@ -7284,7 +7284,7 @@ packages: - supports-color dev: false - /@typescript-eslint/parser@6.14.0(eslint@8.56.0)(typescript@5.2.2): + /@typescript-eslint/parser@6.14.0(eslint@8.56.0)(typescript@5.4.4): resolution: {integrity: sha512-QjToC14CKacd4Pa7JK4GeB/vHmWFJckec49FR4hmIRf97+KXole0T97xxu9IFiPxVQ1DBWrQ5wreLwAGwWAVQA==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7296,11 +7296,11 @@ packages: dependencies: '@typescript-eslint/scope-manager': 6.14.0 '@typescript-eslint/types': 6.14.0 - '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.2.2) + '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.4.4) '@typescript-eslint/visitor-keys': 6.14.0 debug: 4.3.4 eslint: 8.56.0 - typescript: 5.2.2 + typescript: 5.4.4 transitivePeerDependencies: - supports-color dev: true @@ -7320,7 +7320,7 @@ packages: '@typescript-eslint/types': 6.14.0 '@typescript-eslint/visitor-keys': 6.14.0 - /@typescript-eslint/type-utils@6.14.0(eslint@8.56.0)(typescript@5.2.2): + /@typescript-eslint/type-utils@6.14.0(eslint@8.56.0)(typescript@5.4.4): resolution: {integrity: sha512-x6OC9Q7HfYKqjnuNu5a7kffIYs3No30isapRBJl1iCHLitD8O0lFbRcVGiOcuyN837fqXzPZ1NS10maQzZMKqw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7330,12 +7330,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.2.2) - '@typescript-eslint/utils': 6.14.0(eslint@8.56.0)(typescript@5.2.2) + '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.4.4) + '@typescript-eslint/utils': 6.14.0(eslint@8.56.0)(typescript@5.4.4) debug: 4.3.4 eslint: 8.56.0 - ts-api-utils: 1.0.1(typescript@5.2.2) - typescript: 5.2.2 + ts-api-utils: 1.0.1(typescript@5.4.4) + typescript: 5.4.4 transitivePeerDependencies: - supports-color dev: true @@ -7349,7 +7349,7 @@ packages: resolution: {integrity: sha512-uty9H2K4Xs8E47z3SnXEPRNDfsis8JO27amp2GNCnzGETEW3yTqEIVg5+AI7U276oGF/tw6ZA+UesxeQ104ceA==} engines: {node: ^16.0.0 || >=18.0.0} - /@typescript-eslint/typescript-estree@5.62.0(typescript@5.2.2): + /@typescript-eslint/typescript-estree@5.62.0(typescript@5.4.4): resolution: {integrity: sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -7364,8 +7364,8 @@ packages: globby: 11.1.0 is-glob: 4.0.3 semver: 7.3.7 - tsutils: 3.21.0(typescript@5.2.2) - typescript: 5.2.2 + tsutils: 3.21.0(typescript@5.4.4) + typescript: 5.4.4 transitivePeerDependencies: - supports-color dev: true @@ -7391,7 +7391,7 @@ packages: - supports-color dev: false - /@typescript-eslint/typescript-estree@6.14.0(typescript@5.2.2): + /@typescript-eslint/typescript-estree@6.14.0(typescript@5.4.4): resolution: {integrity: sha512-yPkaLwK0yH2mZKFE/bXkPAkkFgOv15GJAUzgUVonAbv0Hr4PK/N2yaA/4XQbTZQdygiDkpt5DkxPELqHguNvyw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7406,13 +7406,13 @@ packages: globby: 11.1.0 is-glob: 4.0.3 semver: 7.5.4 - ts-api-utils: 1.0.1(typescript@5.2.2) - typescript: 5.2.2 + ts-api-utils: 1.0.1(typescript@5.4.4) + typescript: 5.4.4 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils@5.62.0(eslint@8.56.0)(typescript@5.2.2): + /@typescript-eslint/utils@5.62.0(eslint@8.56.0)(typescript@5.4.4): resolution: {integrity: sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -7423,7 +7423,7 @@ packages: '@types/semver': 7.5.6 '@typescript-eslint/scope-manager': 5.62.0 '@typescript-eslint/types': 5.62.0 - '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.2.2) + '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.4.4) eslint: 8.56.0 eslint-scope: 5.1.1 semver: 7.3.7 @@ -7432,7 +7432,7 @@ packages: - typescript dev: true - /@typescript-eslint/utils@6.14.0(eslint@8.56.0)(typescript@5.2.2): + /@typescript-eslint/utils@6.14.0(eslint@8.56.0)(typescript@5.4.4): resolution: {integrity: sha512-XwRTnbvRr7Ey9a1NT6jqdKX8y/atWG+8fAIu3z73HSP8h06i3r/ClMhmaF/RGWGW1tHJEwij1uEg2GbEmPYvYg==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7443,7 +7443,7 @@ packages: '@types/semver': 7.5.0 '@typescript-eslint/scope-manager': 6.14.0 '@typescript-eslint/types': 6.14.0 - '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.2.2) + '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.4.4) eslint: 8.56.0 semver: 7.5.4 transitivePeerDependencies: @@ -11595,7 +11595,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.2.2) + '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.4.4) debug: 3.2.7 eslint: 8.56.0 eslint-import-resolver-node: 0.3.9 @@ -11659,7 +11659,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.2.2) + '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.4.4) array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.2 @@ -11684,7 +11684,7 @@ packages: - supports-color dev: true - /eslint-plugin-jest@27.6.3(@typescript-eslint/eslint-plugin@6.14.0)(eslint@8.56.0)(jest@29.7.0)(typescript@5.2.2): + /eslint-plugin-jest@27.6.3(@typescript-eslint/eslint-plugin@6.14.0)(eslint@8.56.0)(jest@29.7.0)(typescript@5.4.4): resolution: {integrity: sha512-+YsJFVH6R+tOiO3gCJon5oqn4KWc+mDq2leudk8mrp8RFubLOo9CVyi3cib4L7XMpxExmkmBZQTPDYVBzgpgOA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} peerDependencies: @@ -11697,8 +11697,8 @@ packages: jest: optional: true dependencies: - '@typescript-eslint/eslint-plugin': 6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.2.2) - '@typescript-eslint/utils': 5.62.0(eslint@8.56.0)(typescript@5.2.2) + '@typescript-eslint/eslint-plugin': 6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.4.4) + '@typescript-eslint/utils': 5.62.0(eslint@8.56.0)(typescript@5.4.4) eslint: 8.56.0 jest: 29.7.0(@types/node@20.2.5) transitivePeerDependencies: @@ -17878,7 +17878,7 @@ packages: isarray: 1.0.0 dev: true - /msw@1.3.0(typescript@5.2.2): + /msw@1.3.0(typescript@5.4.4): resolution: {integrity: sha512-nnWAZlQyQOKeYRblCpseT1kSPt1aF5e/jHz1hn/18IxbsMFreSVV1cJriT0uV+YG6+wvwFRMHXU3zVuMvuwERQ==} engines: {node: '>=14'} hasBin: true @@ -17907,7 +17907,7 @@ packages: path-to-regexp: 6.2.1 strict-event-emitter: 0.4.6 type-fest: 2.19.0 - typescript: 5.2.2 + typescript: 5.4.4 yargs: 17.5.1 transitivePeerDependencies: - encoding @@ -23897,13 +23897,13 @@ packages: typescript: 4.8.2 dev: false - /ts-api-utils@1.0.1(typescript@5.2.2): + /ts-api-utils@1.0.1(typescript@5.4.4): resolution: {integrity: sha512-lC/RGlPmwdrIBFTX59wwNzqh7aR2otPNPR/5brHZm/XKFYKsfqxihXUe9pU3JI+3vGkl+vyCoNNnPhJn3aLK1A==} engines: {node: '>=16.13.0'} peerDependencies: typescript: '>=4.2.0' dependencies: - typescript: 5.2.2 + typescript: 5.4.4 dev: true /tsconfig-paths@3.14.2: @@ -23924,7 +23924,7 @@ packages: strip-bom: 3.0.0 dev: true - /tsec@0.2.1(@bazel/bazelisk@1.18.0)(typescript@5.2.2): + /tsec@0.2.1(@bazel/bazelisk@1.18.0)(typescript@5.4.4): resolution: {integrity: sha512-RP9vhbRbRI9VH4CfOlQvo5W9HdfiPKq0gdiUOWI5oKmLaZKNFN8CsPwBfT5ySmhnKNwmmAS/BtY3WoTfABwwig==} hasBin: true peerDependencies: @@ -23934,7 +23934,7 @@ packages: '@bazel/bazelisk': 1.18.0 glob: 7.1.7 minimatch: 3.1.2 - typescript: 5.2.2 + typescript: 5.4.4 dev: true /tslib@1.11.1: @@ -23963,14 +23963,14 @@ packages: /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} - /tsutils@3.21.0(typescript@5.2.2): + /tsutils@3.21.0(typescript@5.4.4): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} peerDependencies: typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' dependencies: tslib: 1.14.1 - typescript: 5.2.2 + typescript: 5.4.4 dev: true /tty-browserify@0.0.1: @@ -24175,8 +24175,8 @@ packages: engines: {node: '>=4.2.0'} hasBin: true - /typescript@5.2.2: - resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==} + /typescript@5.4.4: + resolution: {integrity: sha512-dGE2Vv8cpVvw28v8HCPqyb08EzbBURxDpuhJvTrusShUfGnhHBafDsLdS1EhhxyL6BJQE+2cT3dDPAv+MQ6oLw==} engines: {node: '>=14.17'} hasBin: true dev: true diff --git a/test/integration/tsconfig-verifier/test/index.test.js b/test/integration/tsconfig-verifier/test/index.test.js index 3b8481ce188ab..c42710487001f 100644 --- a/test/integration/tsconfig-verifier/test/index.test.js +++ b/test/integration/tsconfig-verifier/test/index.test.js @@ -37,8 +37,8 @@ import path from 'path' "strict": false, "noEmit": true, "incremental": true, - "esModuleInterop": true, "module": "esnext", + "esModuleInterop": true, "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, @@ -91,8 +91,8 @@ import path from 'path' "strict": false, "noEmit": true, "incremental": true, - "esModuleInterop": true, "module": "esnext", + "esModuleInterop": true, "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, @@ -430,8 +430,8 @@ import path from 'path' "strict": false, "noEmit": true, "incremental": true, - "esModuleInterop": true, "module": "esnext", + "esModuleInterop": true, "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, @@ -541,8 +541,8 @@ import path from 'path' "strict": false, "noEmit": true, "incremental": true, - "esModuleInterop": true, "module": "esnext", + "esModuleInterop": true, "moduleResolution": "node", "resolveJsonModule": true, "jsx": "preserve", @@ -598,8 +598,8 @@ import path from 'path' "strict": false, "noEmit": true, "incremental": true, - "esModuleInterop": true, "module": "esnext", + "esModuleInterop": true, "moduleResolution": "node", "resolveJsonModule": true, "jsx": "preserve", @@ -753,5 +753,57 @@ import path from 'path' " `) }) + + it('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => { + expect(await exists(tsConfig)).toBe(false) + + await writeFile( + tsConfig, + `{ "compilerOptions": { "module": "preserve" } }` + ) + await new Promise((resolve) => setTimeout(resolve, 500)) + const { code, stderr, stdout } = await nextBuild(appDir, undefined, { + stderr: true, + stdout: true, + }) + expect(stderr + stdout).not.toContain('moduleResolution') + expect(code).toBe(0) + + expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(` + "{ + "compilerOptions": { + "module": "preserve", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "noEmit": true, + "incremental": true, + "isolatedModules": true, + "jsx": "preserve", + "plugins": [ + { + "name": "next" + } + ], + "strictNullChecks": true + }, + "include": [ + "next-env.d.ts", + ".next/types/**/*.ts", + "**/*.ts", + "**/*.tsx" + ], + "exclude": [ + "node_modules" + ] + } + " + `) + }) } ) From ec915f6e2bef2aa83fc618b777a1b3241c17ee3a Mon Sep 17 00:00:00 2001 From: juliusmarminge Date: Fri, 5 Apr 2024 14:12:26 +0200 Subject: [PATCH 2/7] check other options too --- test/integration/tsconfig-verifier/test/index.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/integration/tsconfig-verifier/test/index.test.js b/test/integration/tsconfig-verifier/test/index.test.js index c42710487001f..2b59f32250202 100644 --- a/test/integration/tsconfig-verifier/test/index.test.js +++ b/test/integration/tsconfig-verifier/test/index.test.js @@ -767,6 +767,8 @@ import path from 'path' stdout: true, }) expect(stderr + stdout).not.toContain('moduleResolution') + expect(stderr + stdout).not.toContain('esModuleInterop') + expect(stderr + stdout).not.toContain('resolveJsonModule') expect(code).toBe(0) expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(` From edb4f11420669487097254d08c23fb2b40bc269a Mon Sep 17 00:00:00 2001 From: juliusmarminge Date: Fri, 5 Apr 2024 14:42:05 +0200 Subject: [PATCH 3/7] revert ts bump and test using e2e for now --- package.json | 2 +- .../typescript/writeConfigurationDefaults.ts | 6 +- packages/next/src/server/render.tsx | 2 +- pnpm-lock.yaml | 92 +++++++++---------- .../tsconfig-module-preserve/index.test.ts | 58 ++++++++++++ .../tsconfig-verifier/test/index.test.js | 3 +- 6 files changed, 112 insertions(+), 51 deletions(-) create mode 100644 test/e2e/tsconfig-module-preserve/index.test.ts diff --git a/package.json b/package.json index 78f411bd395fe..b2acf0497946c 100644 --- a/package.json +++ b/package.json @@ -232,7 +232,7 @@ "tree-kill": "1.2.2", "tsec": "0.2.1", "turbo": "1.12.5", - "typescript": "5.4.4", + "typescript": "5.2.2", "unfetch": "4.2.0", "wait-port": "0.2.2", "webpack": "5.90.0", diff --git a/packages/next/src/lib/typescript/writeConfigurationDefaults.ts b/packages/next/src/lib/typescript/writeConfigurationDefaults.ts index 262015e4bbeec..ef0718fab1b6f 100644 --- a/packages/next/src/lib/typescript/writeConfigurationDefaults.ts +++ b/packages/next/src/lib/typescript/writeConfigurationDefaults.ts @@ -44,7 +44,7 @@ function getDesiredCompilerOptions( parsedValue: ts.ModuleKind.ESNext, // All of these values work: parsedValues: [ - ts.ModuleKind.Preserve, + semver.gte(ts.version, '5.4.0') && (ts.ModuleKind as any).Preserve, ts.ModuleKind.ES2020, ts.ModuleKind.ESNext, ts.ModuleKind.CommonJS, @@ -55,7 +55,9 @@ function getDesiredCompilerOptions( value: 'esnext', reason: 'for dynamic import() support', }, - ...(tsOptions?.module === ts.ModuleKind.Preserve + // TODO: Semver check not needed once Next.js repo uses 5.4. + ...(semver.gte(ts.version, '5.4.0') && + tsOptions?.module === (ts.ModuleKind as any).Preserve ? { // TypeScript 5.4 introduced `Preserve`. Using `Preserve` implies // - `moduleResolution` is `Bundler` diff --git a/packages/next/src/server/render.tsx b/packages/next/src/server/render.tsx index 4f8cbdd7e1018..c57a2e3da5330 100644 --- a/packages/next/src/server/render.tsx +++ b/packages/next/src/server/render.tsx @@ -1348,7 +1348,7 @@ export async function renderToHTMLImpl( (initialStream: ReactReadableStream, suffix?: string) => { return continueFizzStream(initialStream, { suffix, - inlinedDataStream: (serverComponentsInlinedTransformStream as any)?.readable, + inlinedDataStream: serverComponentsInlinedTransformStream?.readable, isStaticGeneration: true, // this must be called inside bodyResult so appWrappers is // up to date when `wrapApp` is called diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1397745af0c1b..0bb9687c9ccd7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -178,10 +178,10 @@ importers: version: 2.0.3 '@typescript-eslint/eslint-plugin': specifier: 6.14.0 - version: 6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.4.4) + version: 6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.2.2) '@typescript-eslint/parser': specifier: 6.14.0 - version: 6.14.0(eslint@8.56.0)(typescript@5.4.4) + version: 6.14.0(eslint@8.56.0)(typescript@5.2.2) '@vercel/fetch': specifier: 6.1.1 version: 6.1.1(@types/node-fetch@2.6.1)(node-fetch@2.6.7) @@ -256,7 +256,7 @@ importers: version: 2.29.1(@typescript-eslint/parser@6.14.0)(eslint@8.56.0) eslint-plugin-jest: specifier: 27.6.3 - version: 27.6.3(@typescript-eslint/eslint-plugin@6.14.0)(eslint@8.56.0)(jest@29.7.0)(typescript@5.4.4) + version: 27.6.3(@typescript-eslint/eslint-plugin@6.14.0)(eslint@8.56.0)(jest@29.7.0)(typescript@5.2.2) eslint-plugin-jsdoc: specifier: 48.0.4 version: 48.0.4(eslint@8.56.0) @@ -535,13 +535,13 @@ importers: version: 1.2.2 tsec: specifier: 0.2.1 - version: 0.2.1(@bazel/bazelisk@1.18.0)(typescript@5.4.4) + version: 0.2.1(@bazel/bazelisk@1.18.0)(typescript@5.2.2) turbo: specifier: 1.12.5 version: 1.12.5 typescript: - specifier: 5.4.4 - version: 5.4.4 + specifier: 5.2.2 + version: 5.2.2 unfetch: specifier: 4.2.0 version: 4.2.0 @@ -1243,7 +1243,7 @@ importers: version: 2.4.4(webpack@5.90.0) msw: specifier: 1.3.0 - version: 1.3.0(typescript@5.4.4) + version: 1.3.0(typescript@5.2.2) nanoid: specifier: 3.1.32 version: 3.1.32 @@ -7234,7 +7234,7 @@ packages: dev: true optional: true - /@typescript-eslint/eslint-plugin@6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.4.4): + /@typescript-eslint/eslint-plugin@6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.2.2): resolution: {integrity: sha512-1ZJBykBCXaSHG94vMMKmiHoL0MhNHKSVlcHVYZNw+BKxufhqQVTOawNpwwI1P5nIFZ/4jLVop0mcY6mJJDFNaw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7246,10 +7246,10 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.5.1 - '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.4.4) + '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.2.2) '@typescript-eslint/scope-manager': 6.14.0 - '@typescript-eslint/type-utils': 6.14.0(eslint@8.56.0)(typescript@5.4.4) - '@typescript-eslint/utils': 6.14.0(eslint@8.56.0)(typescript@5.4.4) + '@typescript-eslint/type-utils': 6.14.0(eslint@8.56.0)(typescript@5.2.2) + '@typescript-eslint/utils': 6.14.0(eslint@8.56.0)(typescript@5.2.2) '@typescript-eslint/visitor-keys': 6.14.0 debug: 4.3.4 eslint: 8.56.0 @@ -7257,8 +7257,8 @@ packages: ignore: 5.2.4 natural-compare: 1.4.0 semver: 7.5.4 - ts-api-utils: 1.0.1(typescript@5.4.4) - typescript: 5.4.4 + ts-api-utils: 1.0.1(typescript@5.2.2) + typescript: 5.2.2 transitivePeerDependencies: - supports-color dev: true @@ -7284,7 +7284,7 @@ packages: - supports-color dev: false - /@typescript-eslint/parser@6.14.0(eslint@8.56.0)(typescript@5.4.4): + /@typescript-eslint/parser@6.14.0(eslint@8.56.0)(typescript@5.2.2): resolution: {integrity: sha512-QjToC14CKacd4Pa7JK4GeB/vHmWFJckec49FR4hmIRf97+KXole0T97xxu9IFiPxVQ1DBWrQ5wreLwAGwWAVQA==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7296,11 +7296,11 @@ packages: dependencies: '@typescript-eslint/scope-manager': 6.14.0 '@typescript-eslint/types': 6.14.0 - '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.4.4) + '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.2.2) '@typescript-eslint/visitor-keys': 6.14.0 debug: 4.3.4 eslint: 8.56.0 - typescript: 5.4.4 + typescript: 5.2.2 transitivePeerDependencies: - supports-color dev: true @@ -7320,7 +7320,7 @@ packages: '@typescript-eslint/types': 6.14.0 '@typescript-eslint/visitor-keys': 6.14.0 - /@typescript-eslint/type-utils@6.14.0(eslint@8.56.0)(typescript@5.4.4): + /@typescript-eslint/type-utils@6.14.0(eslint@8.56.0)(typescript@5.2.2): resolution: {integrity: sha512-x6OC9Q7HfYKqjnuNu5a7kffIYs3No30isapRBJl1iCHLitD8O0lFbRcVGiOcuyN837fqXzPZ1NS10maQzZMKqw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7330,12 +7330,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.4.4) - '@typescript-eslint/utils': 6.14.0(eslint@8.56.0)(typescript@5.4.4) + '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.2.2) + '@typescript-eslint/utils': 6.14.0(eslint@8.56.0)(typescript@5.2.2) debug: 4.3.4 eslint: 8.56.0 - ts-api-utils: 1.0.1(typescript@5.4.4) - typescript: 5.4.4 + ts-api-utils: 1.0.1(typescript@5.2.2) + typescript: 5.2.2 transitivePeerDependencies: - supports-color dev: true @@ -7349,7 +7349,7 @@ packages: resolution: {integrity: sha512-uty9H2K4Xs8E47z3SnXEPRNDfsis8JO27amp2GNCnzGETEW3yTqEIVg5+AI7U276oGF/tw6ZA+UesxeQ104ceA==} engines: {node: ^16.0.0 || >=18.0.0} - /@typescript-eslint/typescript-estree@5.62.0(typescript@5.4.4): + /@typescript-eslint/typescript-estree@5.62.0(typescript@5.2.2): resolution: {integrity: sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -7364,8 +7364,8 @@ packages: globby: 11.1.0 is-glob: 4.0.3 semver: 7.3.7 - tsutils: 3.21.0(typescript@5.4.4) - typescript: 5.4.4 + tsutils: 3.21.0(typescript@5.2.2) + typescript: 5.2.2 transitivePeerDependencies: - supports-color dev: true @@ -7391,7 +7391,7 @@ packages: - supports-color dev: false - /@typescript-eslint/typescript-estree@6.14.0(typescript@5.4.4): + /@typescript-eslint/typescript-estree@6.14.0(typescript@5.2.2): resolution: {integrity: sha512-yPkaLwK0yH2mZKFE/bXkPAkkFgOv15GJAUzgUVonAbv0Hr4PK/N2yaA/4XQbTZQdygiDkpt5DkxPELqHguNvyw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7406,13 +7406,13 @@ packages: globby: 11.1.0 is-glob: 4.0.3 semver: 7.5.4 - ts-api-utils: 1.0.1(typescript@5.4.4) - typescript: 5.4.4 + ts-api-utils: 1.0.1(typescript@5.2.2) + typescript: 5.2.2 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils@5.62.0(eslint@8.56.0)(typescript@5.4.4): + /@typescript-eslint/utils@5.62.0(eslint@8.56.0)(typescript@5.2.2): resolution: {integrity: sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -7423,7 +7423,7 @@ packages: '@types/semver': 7.5.6 '@typescript-eslint/scope-manager': 5.62.0 '@typescript-eslint/types': 5.62.0 - '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.4.4) + '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.2.2) eslint: 8.56.0 eslint-scope: 5.1.1 semver: 7.3.7 @@ -7432,7 +7432,7 @@ packages: - typescript dev: true - /@typescript-eslint/utils@6.14.0(eslint@8.56.0)(typescript@5.4.4): + /@typescript-eslint/utils@6.14.0(eslint@8.56.0)(typescript@5.2.2): resolution: {integrity: sha512-XwRTnbvRr7Ey9a1NT6jqdKX8y/atWG+8fAIu3z73HSP8h06i3r/ClMhmaF/RGWGW1tHJEwij1uEg2GbEmPYvYg==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -7443,7 +7443,7 @@ packages: '@types/semver': 7.5.0 '@typescript-eslint/scope-manager': 6.14.0 '@typescript-eslint/types': 6.14.0 - '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.4.4) + '@typescript-eslint/typescript-estree': 6.14.0(typescript@5.2.2) eslint: 8.56.0 semver: 7.5.4 transitivePeerDependencies: @@ -11595,7 +11595,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.4.4) + '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.2.2) debug: 3.2.7 eslint: 8.56.0 eslint-import-resolver-node: 0.3.9 @@ -11659,7 +11659,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.4.4) + '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.2.2) array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.2 @@ -11684,7 +11684,7 @@ packages: - supports-color dev: true - /eslint-plugin-jest@27.6.3(@typescript-eslint/eslint-plugin@6.14.0)(eslint@8.56.0)(jest@29.7.0)(typescript@5.4.4): + /eslint-plugin-jest@27.6.3(@typescript-eslint/eslint-plugin@6.14.0)(eslint@8.56.0)(jest@29.7.0)(typescript@5.2.2): resolution: {integrity: sha512-+YsJFVH6R+tOiO3gCJon5oqn4KWc+mDq2leudk8mrp8RFubLOo9CVyi3cib4L7XMpxExmkmBZQTPDYVBzgpgOA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} peerDependencies: @@ -11697,8 +11697,8 @@ packages: jest: optional: true dependencies: - '@typescript-eslint/eslint-plugin': 6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.4.4) - '@typescript-eslint/utils': 5.62.0(eslint@8.56.0)(typescript@5.4.4) + '@typescript-eslint/eslint-plugin': 6.14.0(@typescript-eslint/parser@6.14.0)(eslint@8.56.0)(typescript@5.2.2) + '@typescript-eslint/utils': 5.62.0(eslint@8.56.0)(typescript@5.2.2) eslint: 8.56.0 jest: 29.7.0(@types/node@20.2.5) transitivePeerDependencies: @@ -17878,7 +17878,7 @@ packages: isarray: 1.0.0 dev: true - /msw@1.3.0(typescript@5.4.4): + /msw@1.3.0(typescript@5.2.2): resolution: {integrity: sha512-nnWAZlQyQOKeYRblCpseT1kSPt1aF5e/jHz1hn/18IxbsMFreSVV1cJriT0uV+YG6+wvwFRMHXU3zVuMvuwERQ==} engines: {node: '>=14'} hasBin: true @@ -17907,7 +17907,7 @@ packages: path-to-regexp: 6.2.1 strict-event-emitter: 0.4.6 type-fest: 2.19.0 - typescript: 5.4.4 + typescript: 5.2.2 yargs: 17.5.1 transitivePeerDependencies: - encoding @@ -23897,13 +23897,13 @@ packages: typescript: 4.8.2 dev: false - /ts-api-utils@1.0.1(typescript@5.4.4): + /ts-api-utils@1.0.1(typescript@5.2.2): resolution: {integrity: sha512-lC/RGlPmwdrIBFTX59wwNzqh7aR2otPNPR/5brHZm/XKFYKsfqxihXUe9pU3JI+3vGkl+vyCoNNnPhJn3aLK1A==} engines: {node: '>=16.13.0'} peerDependencies: typescript: '>=4.2.0' dependencies: - typescript: 5.4.4 + typescript: 5.2.2 dev: true /tsconfig-paths@3.14.2: @@ -23924,7 +23924,7 @@ packages: strip-bom: 3.0.0 dev: true - /tsec@0.2.1(@bazel/bazelisk@1.18.0)(typescript@5.4.4): + /tsec@0.2.1(@bazel/bazelisk@1.18.0)(typescript@5.2.2): resolution: {integrity: sha512-RP9vhbRbRI9VH4CfOlQvo5W9HdfiPKq0gdiUOWI5oKmLaZKNFN8CsPwBfT5ySmhnKNwmmAS/BtY3WoTfABwwig==} hasBin: true peerDependencies: @@ -23934,7 +23934,7 @@ packages: '@bazel/bazelisk': 1.18.0 glob: 7.1.7 minimatch: 3.1.2 - typescript: 5.4.4 + typescript: 5.2.2 dev: true /tslib@1.11.1: @@ -23963,14 +23963,14 @@ packages: /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} - /tsutils@3.21.0(typescript@5.4.4): + /tsutils@3.21.0(typescript@5.2.2): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} peerDependencies: typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' dependencies: tslib: 1.14.1 - typescript: 5.4.4 + typescript: 5.2.2 dev: true /tty-browserify@0.0.1: @@ -24175,8 +24175,8 @@ packages: engines: {node: '>=4.2.0'} hasBin: true - /typescript@5.4.4: - resolution: {integrity: sha512-dGE2Vv8cpVvw28v8HCPqyb08EzbBURxDpuhJvTrusShUfGnhHBafDsLdS1EhhxyL6BJQE+2cT3dDPAv+MQ6oLw==} + /typescript@5.2.2: + resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==} engines: {node: '>=14.17'} hasBin: true dev: true diff --git a/test/e2e/tsconfig-module-preserve/index.test.ts b/test/e2e/tsconfig-module-preserve/index.test.ts new file mode 100644 index 0000000000000..698b4bac91b10 --- /dev/null +++ b/test/e2e/tsconfig-module-preserve/index.test.ts @@ -0,0 +1,58 @@ +import { nextTestSetup } from 'e2e-utils' +import { readFile } from 'fs-extra' +import path from 'path' + +describe('tsconfig module: Preserve', () => { + const { next } = nextTestSetup({ + files: { + 'tsconfig.json': JSON.stringify({ + compilerOptions: { module: 'preserve' }, + }), + 'pages/index.js': ` + export default function Page() { + return

hello world

+ } + `, + }, + dependencies: { + typescript: '5.4.4', + }, + }) + + it('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => { + await next.stop() + expect(next.cliOutput).not.toContain('moduleResolution') + expect(next.cliOutput).not.toContain('esModuleInterop') + expect(next.cliOutput).not.toContain('resolveJsonModule') + + const tsconfig = path.join(next.testDir, 'tsconfig.json') + expect(await readFile(tsconfig, 'utf8')).toMatchInlineSnapshot(` + "{ + "compilerOptions": { + "module": "preserve", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "noEmit": true, + "incremental": true, + "isolatedModules": true, + "jsx": "preserve" + }, + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx" + ], + "exclude": [ + "node_modules" + ] + } + " + `) + }) +}) diff --git a/test/integration/tsconfig-verifier/test/index.test.js b/test/integration/tsconfig-verifier/test/index.test.js index 2b59f32250202..caa609dd32187 100644 --- a/test/integration/tsconfig-verifier/test/index.test.js +++ b/test/integration/tsconfig-verifier/test/index.test.js @@ -754,7 +754,8 @@ import path from 'path' `) }) - it('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => { + // TODO: Enable this test when repo has upgraded to TypeScript 5.4. Currently tested as E2E + it.skip('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => { expect(await exists(tsConfig)).toBe(false) await writeFile( From 474837dd09e976eabcb05fec771d4899dd9377bc Mon Sep 17 00:00:00 2001 From: juliusmarminge Date: Fri, 5 Apr 2024 14:43:48 +0200 Subject: [PATCH 4/7] comment where to find e2e test --- test/integration/tsconfig-verifier/test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/tsconfig-verifier/test/index.test.js b/test/integration/tsconfig-verifier/test/index.test.js index caa609dd32187..42b787965247e 100644 --- a/test/integration/tsconfig-verifier/test/index.test.js +++ b/test/integration/tsconfig-verifier/test/index.test.js @@ -754,7 +754,7 @@ import path from 'path' `) }) - // TODO: Enable this test when repo has upgraded to TypeScript 5.4. Currently tested as E2E + // TODO: Enable this test when repo has upgraded to TypeScript 5.4. Currently tested as E2E: tsconfig-module-preserve it.skip('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => { expect(await exists(tsConfig)).toBe(false) From 28b0b1875b5e563b5391df9afdcea28c37a85d56 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 8 Apr 2024 12:00:41 +0200 Subject: [PATCH 5/7] update test --- test/e2e/tsconfig-module-preserve/index.test.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/e2e/tsconfig-module-preserve/index.test.ts b/test/e2e/tsconfig-module-preserve/index.test.ts index 698b4bac91b10..0d28f75ab2e04 100644 --- a/test/e2e/tsconfig-module-preserve/index.test.ts +++ b/test/e2e/tsconfig-module-preserve/index.test.ts @@ -1,6 +1,4 @@ import { nextTestSetup } from 'e2e-utils' -import { readFile } from 'fs-extra' -import path from 'path' describe('tsconfig module: Preserve', () => { const { next } = nextTestSetup({ @@ -20,13 +18,11 @@ describe('tsconfig module: Preserve', () => { }) it('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => { - await next.stop() expect(next.cliOutput).not.toContain('moduleResolution') expect(next.cliOutput).not.toContain('esModuleInterop') expect(next.cliOutput).not.toContain('resolveJsonModule') - const tsconfig = path.join(next.testDir, 'tsconfig.json') - expect(await readFile(tsconfig, 'utf8')).toMatchInlineSnapshot(` + expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(` "{ "compilerOptions": { "module": "preserve", From 5913592586d170cb5916c9290eb68e999c20f951 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 8 Apr 2024 12:22:49 +0200 Subject: [PATCH 6/7] update test --- .../e2e/tsconfig-module-preserve/index.test.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/e2e/tsconfig-module-preserve/index.test.ts b/test/e2e/tsconfig-module-preserve/index.test.ts index 0d28f75ab2e04..2aa459aa8f315 100644 --- a/test/e2e/tsconfig-module-preserve/index.test.ts +++ b/test/e2e/tsconfig-module-preserve/index.test.ts @@ -1,6 +1,8 @@ import { nextTestSetup } from 'e2e-utils' +import { retry } from 'next-test-utils' +import stripAnsi from 'strip-ansi' -describe('tsconfig module: Preserve', () => { +describe('tsconfig module: preserve', () => { const { next } = nextTestSetup({ files: { 'tsconfig.json': JSON.stringify({ @@ -18,9 +20,17 @@ describe('tsconfig module: Preserve', () => { }) it('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => { - expect(next.cliOutput).not.toContain('moduleResolution') - expect(next.cliOutput).not.toContain('esModuleInterop') - expect(next.cliOutput).not.toContain('resolveJsonModule') + let output = stripAnsi(next.cliOutput) + expect(output).not.toContain('moduleResolution') + expect(output).not.toContain('esModuleInterop') + expect(output).not.toContain('resolveJsonModule') + + await retry(() => { + output = stripAnsi(next.cliOutput) + expect(output).toContain( + 'The following mandatory changes were made to your tsconfig.json' + ) + }) expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(` "{ From aac9d2c0fb134799f9cabeb39d73f07865b7dd18 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 8 Apr 2024 13:00:06 +0200 Subject: [PATCH 7/7] stablize test --- test/e2e/tsconfig-module-preserve/index.test.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/e2e/tsconfig-module-preserve/index.test.ts b/test/e2e/tsconfig-module-preserve/index.test.ts index 2aa459aa8f315..2b41847662381 100644 --- a/test/e2e/tsconfig-module-preserve/index.test.ts +++ b/test/e2e/tsconfig-module-preserve/index.test.ts @@ -8,7 +8,7 @@ describe('tsconfig module: preserve', () => { 'tsconfig.json': JSON.stringify({ compilerOptions: { module: 'preserve' }, }), - 'pages/index.js': ` + 'pages/index.tsx': ` export default function Page() { return

hello world

} @@ -20,10 +20,7 @@ describe('tsconfig module: preserve', () => { }) it('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => { - let output = stripAnsi(next.cliOutput) - expect(output).not.toContain('moduleResolution') - expect(output).not.toContain('esModuleInterop') - expect(output).not.toContain('resolveJsonModule') + let output = '' await retry(() => { output = stripAnsi(next.cliOutput) @@ -32,6 +29,10 @@ describe('tsconfig module: preserve', () => { ) }) + expect(output).not.toContain('moduleResolution') + expect(output).not.toContain('esModuleInterop') + expect(output).not.toContain('resolveJsonModule') + expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(` "{ "compilerOptions": {