Files
a7c24aca6f feat: allow module: Preserve tsconfig option (#64110)
Fixes #64018

Adds support for modern configurations introduced in TS 5.4

Expected output: not modifying the `module`, `esModuleInterop` configs
since `module: preserve` is present

```
   We detected TypeScript in your project and reconfigured your tsconfig.json file for you. Strict-mode is set to false
 by default.
   The following suggested values were added to your tsconfig.json. These values can be changed to fit your project's n
eeds:

        - lib was set to dom,dom.iterable,esnext
        - allowJs was set to true
        - skipLibCheck was set to true
        - strict was set to false
        - noEmit was set to true
        - incremental was set to true
        - include was set to ['next-env.d.ts', '**/*.ts', '**/*.tsx']
        - exclude was set to ['node_modules']

   The following mandatory changes were made to your tsconfig.json:

        - isolatedModules was set to true (requirement for SWC / Babel)
        - jsx was set to preserve (next.js implements its own optimized jsx transform)
```

---------

Co-authored-by: Jiachi Liu <[email protected]>
2024-04-08 11:30:04 +00:00

66 lines
1.6 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
import stripAnsi from 'strip-ansi'
describe('tsconfig module: preserve', () => {
const { next } = nextTestSetup({
files: {
'tsconfig.json': JSON.stringify({
compilerOptions: { module: 'preserve' },
}),
'pages/index.tsx': `
export default function Page() {
return <p>hello world</p>
}
`,
},
dependencies: {
typescript: '5.4.4',
},
})
it('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => {
let output = ''
await retry(() => {
output = stripAnsi(next.cliOutput)
expect(output).toContain(
'The following mandatory changes were made to your tsconfig.json'
)
})
expect(output).not.toContain('moduleResolution')
expect(output).not.toContain('esModuleInterop')
expect(output).not.toContain('resolveJsonModule')
expect(await next.readFile('tsconfig.json')).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"
]
}
"
`)
})
})