Improve top level await coverage (#64508)

## What?

- Changes webpack output target to `es6` (required for `async function`
output)
- Adds tests for top level await in server components and client
components (App Router)
- Converted the async-modules tests to `test/e2e`
- Has one skipped test that @gnoff is going to look into. This shouldn't
block merging this PR 👍


Adds additional tests for top level `await`.

Since [Next.js
13.4.5](https://github.com/vercel/next.js/releases/tag/v13.4.5) webpack
has top level await support enabled by default.

Similarly Turbopack supports top level await by default as well.

TLDR: You can remove `topLevelAwait: true` from the webpack
configuration.


In writing these tests I found that client components are missing some
kind of handling for top level await (async modules) so I've raised that
to @gnoff who is going to have a look.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-3126
Fixes https://github.com/vercel/next.js/issues/43382
This commit is contained in:
Tim Neutkens 2024-04-17 17:44:40 +02:00 committed by GitHub
parent dccc6ece46
commit 1fd93eed90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 2817 additions and 564 deletions

View file

@ -42,3 +42,4 @@ test/development/basic/hmr/components/parse-error.js
packages/next-swc/docs/assets/**/*
test/lib/amp-validator-wasm.js
test/production/pages-dir/production/fixture/amp-validator-wasm.js
test/e2e/async-modules/amp-validator-wasm.js

View file

@ -39,3 +39,4 @@ bench/nested-deps/components/**/*
**/.tina/__generated__/**
test/lib/amp-validator-wasm.js
test/production/pages-dir/production/fixture/amp-validator-wasm.js
test/e2e/async-modules/amp-validator-wasm.js

View file

@ -18,7 +18,7 @@ export const base = curry(function base(
? 'node18.17' // Same version defined in packages/next/package.json#engines
: ctx.isEdgeRuntime
? ['web', 'es6']
: ['web', 'es5']
: ['web', 'es6']
// https://webpack.js.org/configuration/devtool/#development
if (ctx.isDevelopment) {

View file

@ -9,7 +9,7 @@ import * as Log from '../../build/output/log'
type DesiredCompilerOptionsShape = {
[K in keyof CompilerOptions]:
| { suggested: any }
| { suggested: any; reason?: string }
| {
parsedValue?: any
parsedValues?: Array<any>
@ -23,6 +23,11 @@ function getDesiredCompilerOptions(
tsOptions?: CompilerOptions
): DesiredCompilerOptionsShape {
const o: DesiredCompilerOptionsShape = {
target: {
suggested: 'ES2017',
reason:
'For top-level `await`. Note: Next.js only polyfills for the esmodules target.',
},
// These are suggested values and will be set when not present in the
// tsconfig.json
lib: { suggested: ['dom', 'dom.iterable', 'esnext'] },
@ -168,7 +173,12 @@ export async function writeConfigurationDefaults(
}
userTsConfig.compilerOptions[optionKey] = check.suggested
suggestedActions.push(
cyan(optionKey) + ' was set to ' + bold(check.suggested)
cyan(optionKey) +
' was set to ' +
bold(check.suggested) +
check.reason
? ` (${check.reason})`
: ''
)
}
} else if ('value' in check) {

View file

@ -0,0 +1,6 @@
'use client'
const appValue = await Promise.resolve('hello')
export default function Page() {
return <p id="app-router-client-component-value">{appValue}</p>
}

View file

@ -0,0 +1,5 @@
const appValue = await Promise.resolve('hello')
export default function Page() {
return <p id="app-router-value">{appValue}</p>
}

View file

@ -0,0 +1,16 @@
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}

View file

@ -0,0 +1,21 @@
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
describe('Async modules', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('app router server component async module', async () => {
const browser = await next.browser('/app-router')
expect(await browser.elementByCss('#app-router-value').text()).toBe('hello')
})
// TODO: Investigate/fix issue with React loading async modules failing.
// Rename app/app-router/client-component/skipped-page.tsx to app/app-router/client-component/page.tsx to run this test.
it.skip('app router client component async module', async () => {
const browser = await next.browser('/app-router/client')
expect(
await browser.elementByCss('#app-router-client-component-value').text()
).toBe('hello')
})
})

View file

@ -0,0 +1 @@
module.exports = {}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,60 @@
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
describe('Async modules', () => {
const { next, isNextDev: dev } = nextTestSetup({
files: __dirname,
})
it('ssr async page modules', async () => {
const $ = await next.render$('/')
expect($('#app-value').text()).toBe('hello')
expect($('#page-value').text()).toBe('42')
})
it('csr async page modules', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('#app-value').text()).toBe('hello')
expect(await browser.elementByCss('#page-value').text()).toBe('42')
expect(await browser.elementByCss('#doc-value').text()).toBe('doc value')
})
it('works on async api routes', async () => {
const res = await next.fetch('/api/hello')
expect(res.status).toBe(200)
const result = await res.json()
expect(result).toHaveProperty('value', 42)
})
it('works with getServerSideProps', async () => {
const browser = await next.browser('/gssp')
expect(await browser.elementByCss('#gssp-value').text()).toBe('42')
})
it('works with getStaticProps', async () => {
const browser = await next.browser('/gsp')
expect(await browser.elementByCss('#gsp-value').text()).toBe('42')
})
it('can render async 404 pages', async () => {
const browser = await next.browser('/dhiuhefoiahjeoij')
expect(await browser.elementByCss('#content-404').text()).toBe("hi y'all")
})
// TODO: investigate this test flaking
it.skip('can render async AMP pages', async () => {
const browser = await next.browser('/config')
await check(
() => browser.elementByCss('#amp-timeago').text(),
'just now',
true
)
})
;(dev ? it.skip : it)('can render async error page', async () => {
const browser = await next.browser('/make-error')
expect(await browser.elementByCss('#content-error').text()).toBe(
'hello error'
)
})
})

View file

@ -0,0 +1,7 @@
module.exports = {
experimental: {
amp: {
validator: require.resolve('./amp-validator-wasm.js'),
},
},
}

View file

@ -37,6 +37,7 @@ describe('tsconfig module: preserve', () => {
"{
"compilerOptions": {
"module": "preserve",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",

View file

@ -1,12 +0,0 @@
module.exports = {
webpack: (config) => {
config.experiments = config.experiments || {}
config.experiments.topLevelAwait = true
return config
},
experimental: {
amp: {
validator: require.resolve('../../lib/amp-validator-wasm.js'),
},
},
}

View file

@ -1,136 +0,0 @@
/* eslint-env jest */
import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
import {
fetchViaHTTP,
renderViaHTTP,
findPort,
killApp,
launchApp,
nextBuild,
nextStart,
check,
} from 'next-test-utils'
import { join } from 'path'
let app
let appPort
const appDir = join(__dirname, '../')
function runTests(dev = false) {
it('ssr async page modules', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
expect($('#app-value').text()).toBe('hello')
expect($('#page-value').text()).toBe('42')
})
it('csr async page modules', async () => {
let browser
try {
browser = await webdriver(appPort, '/')
expect(await browser.elementByCss('#app-value').text()).toBe('hello')
expect(await browser.elementByCss('#page-value').text()).toBe('42')
expect(await browser.elementByCss('#doc-value').text()).toBe('doc value')
} finally {
if (browser) await browser.close()
}
})
it('works on async api routes', async () => {
const res = await fetchViaHTTP(appPort, '/api/hello')
expect(res.status).toBe(200)
const result = await res.json()
expect(result).toHaveProperty('value', 42)
})
it('works with getServerSideProps', async () => {
let browser
try {
browser = await webdriver(appPort, '/gssp')
expect(await browser.elementByCss('#gssp-value').text()).toBe('42')
} finally {
if (browser) await browser.close()
}
})
it('works with getStaticProps', async () => {
let browser
try {
browser = await webdriver(appPort, '/gsp')
expect(await browser.elementByCss('#gsp-value').text()).toBe('42')
} finally {
if (browser) await browser.close()
}
})
it('can render async 404 pages', async () => {
let browser
try {
browser = await webdriver(appPort, '/dhiuhefoiahjeoij')
expect(await browser.elementByCss('#content-404').text()).toBe("hi y'all")
} finally {
if (browser) await browser.close()
}
})
// TODO: investigate this test flaking
it.skip('can render async AMP pages', async () => {
let browser
try {
browser = await webdriver(appPort, '/config')
await check(
() => browser.elementByCss('#amp-timeago').text(),
'just now',
true
)
} finally {
if (browser) await browser.close()
}
})
;(dev ? it.skip : it)('can render async error page', async () => {
let browser
try {
browser = await webdriver(appPort, '/make-error')
expect(await browser.elementByCss('#content-error').text()).toBe(
'hello error'
)
} finally {
if (browser) await browser.close()
}
})
}
describe('Async modules', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests(true)
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests()
}
)
})

View file

@ -25,43 +25,44 @@ import path from 'path'
const { code } = await nextBuild(appDir)
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
"{
"compilerOptions": {
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
"exclude": [
"node_modules"
]
}
"
`)
})
it('Works with an empty tsconfig.json (docs)', async () => {
@ -79,43 +80,44 @@ import path from 'path'
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
"{
"compilerOptions": {
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
"exclude": [
"node_modules"
]
}
"
`)
})
it('Updates an existing tsconfig.json without losing comments', async () => {
@ -145,51 +147,52 @@ import path from 'path'
// Weird comma placement until this issue is resolved:
// https://github.com/kaelzhang/node-comment-json/issues/21
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"// top-level comment
{
// in-object comment 1
"compilerOptions": {
// in-object comment
"esModuleInterop": true, // this should be true
"module": "esnext" // should not be umd
// end-object comment
"// top-level comment
{
// in-object comment 1
"compilerOptions": {
// in-object comment
"esModuleInterop": true, // this should be true
"module": "esnext" // should not be umd
// end-object comment
,
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
}
// in-object comment 2
,
"lib": [
"dom",
"dom.iterable",
"esnext"
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
"exclude": [
"node_modules"
]
}
// in-object comment 2
,
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
// end comment
"
`)
// end comment
"
`)
})
it('allows you to set commonjs module mode', async () => {
@ -204,43 +207,44 @@ import path from 'path'
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"lib": [
"dom",
"dom.iterable",
"esnext"
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
"exclude": [
"node_modules"
]
}
"
`)
})
it('allows you to set es2020 module mode', async () => {
@ -255,43 +259,44 @@ import path from 'path'
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "es2020",
"lib": [
"dom",
"dom.iterable",
"esnext"
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "es2020",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
"exclude": [
"node_modules"
]
}
"
`)
})
it('allows you to set node16 moduleResolution mode', async () => {
@ -310,43 +315,44 @@ import path from 'path'
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"moduleResolution": "node16",
"module": "node16",
"lib": [
"dom",
"dom.iterable",
"esnext"
"{
"compilerOptions": {
"esModuleInterop": true,
"moduleResolution": "node16",
"module": "node16",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
"exclude": [
"node_modules"
]
}
"
`)
})
it('allows you to set bundler moduleResolution mode', async () => {
@ -365,43 +371,44 @@ import path from 'path'
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"moduleResolution": "bundler",
"lib": [
"dom",
"dom.iterable",
"esnext"
"{
"compilerOptions": {
"esModuleInterop": true,
"moduleResolution": "bundler",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
"exclude": [
"node_modules"
]
}
"
`)
})
it('allows you to set target mode', async () => {
@ -417,44 +424,44 @@ import path from 'path'
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"target": "es2022",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
"{
"compilerOptions": {
"target": "es2022",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": 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 set node16 module mode', async () => {
@ -473,43 +480,44 @@ import path from 'path'
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "node16",
"moduleResolution": "node16",
"lib": [
"dom",
"dom.iterable",
"esnext"
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "node16",
"moduleResolution": "node16",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
"exclude": [
"node_modules"
]
}
"
`)
})
it('allows you to set verbatimModuleSyntax true without adding isolatedModules', async () => {
@ -528,43 +536,44 @@ import path from 'path'
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"verbatimModuleSyntax": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
"{
"compilerOptions": {
"verbatimModuleSyntax": true,
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
"exclude": [
"node_modules"
]
}
"
`)
})
it('allows you to set verbatimModuleSyntax true via extends without adding isolatedModules', async () => {
@ -588,6 +597,7 @@ import path from 'path'
"{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
@ -681,9 +691,16 @@ import path from 'path'
expect(stderr + stdout).not.toContain('moduleResolution')
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(
`"{ "extends": "./tsconfig.base.json" }"`
)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "ES2017",
"strictNullChecks": true
}
}
"
`)
})
it('creates compilerOptions when you extend another config', async () => {
@ -743,15 +760,16 @@ import path from 'path'
expect(code).toBe(0)
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"incremental": true,
"strictNullChecks": true
"{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "ES2017",
"incremental": true,
"strictNullChecks": true
}
}
}
"
`)
"
`)
})
// TODO: Enable this test when repo has upgraded to TypeScript 5.4. Currently tested as E2E: tsconfig-module-preserve
@ -773,40 +791,40 @@ import path from 'path'
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"
]
}
"
`)
"{
"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"
]
}
"
`)
})
}
)