Skip to content

Commit 14cfe09

Browse files
committed
update tsconfig gen
1 parent 06402e0 commit 14cfe09

File tree

11 files changed

+90
-92
lines changed

11 files changed

+90
-92
lines changed

packages/next/src/lib/typescript/writeConfigurationDefaults.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ describe('writeConfigurationDefaults()', () => {
8484
"node_modules",
8585
],
8686
"include": [
87-
"next-env.d.ts",
8887
".next/types/**/*.ts",
8988
".next/dev/types/**/*.ts",
9089
"**/*.mts",
@@ -107,7 +106,7 @@ describe('writeConfigurationDefaults()', () => {
107106
- strict was set to false
108107
- noEmit was set to true
109108
- incremental was set to true
110-
- include was set to ['next-env.d.ts', '.next/types/**/*.ts', '.next/dev/types/**/*.ts', '**/*.mts', '**/*.ts', '**/*.tsx']
109+
- include was set to ['.next/types/**/*.ts', '.next/dev/types/**/*.ts', '**/*.mts', '**/*.ts', '**/*.tsx']
111110
- plugins was updated to add { name: 'next' }
112111
- exclude was set to ['node_modules']
113112

packages/next/src/lib/typescript/writeConfigurationDefaults.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,12 @@ export async function writeConfigurationDefaults(
283283

284284
if (!('include' in userTsConfig)) {
285285
// Always include .next/types for dynamic types (image imports, route types, etc.)
286-
userTsConfig.include = [
287-
'next-env.d.ts',
288-
...nextAppTypes,
289-
'**/*.mts',
290-
'**/*.ts',
291-
'**/*.tsx',
292-
]
286+
userTsConfig.include = [...nextAppTypes, '**/*.mts', '**/*.ts', '**/*.tsx']
293287
suggestedActions.push(
294288
cyan('include') +
295289
' was set to ' +
296290
bold(
297-
`['next-env.d.ts', ${nextAppTypes.map((type) => `'${type}'`).join(', ')}, '**/*.mts', '**/*.ts', '**/*.tsx']`
291+
`[${nextAppTypes.map((type) => `'${type}'`).join(', ')}, '**/*.mts', '**/*.ts', '**/*.tsx']`
298292
)
299293
)
300294
} else {

test/e2e/tsconfig-module-preserve/index.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ describe('tsconfig module: preserve', () => {
5656
"jsx": "react-jsx"
5757
},
5858
"include": [
59-
"next-env.d.ts",
6059
".next/types/**/*.ts",
6160
".next/dev/types/**/*.ts",
6261
"**/*.mts",

test/integration/typescript-app-type-declarations/next-env.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/integration/typescript-app-type-declarations/test/index.test.ts

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,63 @@ import { findPort, launchApp, killApp } from 'next-test-utils'
55
import { promises as fs } from 'fs'
66

77
const appDir = join(__dirname, '..')
8-
const appTypeDeclarations = join(appDir, 'next-env.d.ts')
8+
const rootTypeDeclarations = join(appDir, 'next-env.d.ts')
9+
const distTypeDeclarations = join(appDir, '.next/types/next-env.d.ts')
910

1011
describe('TypeScript App Type Declarations', () => {
11-
it('should write a new next-env.d.ts if none exist', async () => {
12-
const prevContent = await fs.readFile(appTypeDeclarations, 'utf8')
12+
it('should not create next-env.d.ts in project root', async () => {
13+
// Ensure no next-env.d.ts exists before starting
1314
try {
14-
await fs.unlink(appTypeDeclarations)
15-
const appPort = await findPort()
16-
let app
17-
try {
18-
app = await launchApp(appDir, appPort, {})
19-
const content = await fs.readFile(appTypeDeclarations, 'utf8')
20-
expect(content).toEqual(prevContent)
21-
} finally {
22-
await killApp(app)
23-
}
15+
await fs.unlink(rootTypeDeclarations)
16+
} catch {
17+
// File doesn't exist, which is fine
18+
}
19+
20+
const appPort = await findPort()
21+
let app
22+
try {
23+
app = await launchApp(appDir, appPort, {})
24+
// Verify next-env.d.ts was NOT created in project root
25+
await expect(fs.access(rootTypeDeclarations)).rejects.toThrow()
2426
} finally {
25-
await fs.writeFile(appTypeDeclarations, prevContent)
27+
await killApp(app)
2628
}
2729
})
2830

29-
it('should overwrite next-env.d.ts if an incorrect one exists', async () => {
30-
const prevContent = await fs.readFile(appTypeDeclarations, 'utf8')
31+
it('should not modify existing next-env.d.ts in project root', async () => {
32+
const existingContent = '// custom next-env.d.ts content\n'
33+
await fs.writeFile(rootTypeDeclarations, existingContent)
34+
const prevStat = await fs.stat(rootTypeDeclarations)
35+
36+
const appPort = await findPort()
37+
let app
3138
try {
32-
await fs.writeFile(appTypeDeclarations, prevContent + 'modification')
33-
const appPort = await findPort()
34-
let app
35-
try {
36-
app = await launchApp(appDir, appPort, {})
37-
const content = await fs.readFile(appTypeDeclarations, 'utf8')
38-
expect(content).toEqual(prevContent)
39-
} finally {
40-
await killApp(app)
41-
}
39+
app = await launchApp(appDir, appPort, {})
40+
// Verify next-env.d.ts was NOT modified
41+
const stat = await fs.stat(rootTypeDeclarations)
42+
expect(stat.mtime).toEqual(prevStat.mtime)
43+
const content = await fs.readFile(rootTypeDeclarations, 'utf8')
44+
expect(content).toEqual(existingContent)
4245
} finally {
43-
await fs.writeFile(appTypeDeclarations, prevContent)
46+
await killApp(app)
47+
// Clean up
48+
await fs.unlink(rootTypeDeclarations).catch(() => {})
4449
}
4550
})
4651

47-
it('should not touch an existing correct next-env.d.ts', async () => {
48-
const prevStat = await fs.stat(appTypeDeclarations)
52+
it('should overwrite next-env.d.ts in .next/types if incorrect', async () => {
53+
// Create .next/types directory and write incorrect content
54+
await fs.mkdir(join(appDir, '.next/types'), { recursive: true })
55+
await fs.writeFile(distTypeDeclarations, '// incorrect content\n')
56+
4957
const appPort = await findPort()
5058
let app
5159
try {
5260
app = await launchApp(appDir, appPort, {})
53-
const stat = await fs.stat(appTypeDeclarations)
54-
expect(stat.mtime).toEqual(prevStat.mtime)
61+
// Verify next-env.d.ts was overwritten with correct content
62+
const content = await fs.readFile(distTypeDeclarations, 'utf8')
63+
expect(content).not.toEqual('// incorrect content\n')
64+
expect(content).toContain('/// <reference types="next" />')
5565
} finally {
5666
await killApp(app)
5767
}

test/integration/typescript-app-type-declarations/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"isolatedModules": true
1818
},
1919
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx"],
20-
"include": ["next-env.d.ts", "components", "pages"]
20+
"include": ["components", "pages", ".next/types/**/*.ts"]
2121
}

test/production/typescript-basic/typechecking/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"@/*": ["./*"]
2323
}
2424
},
25-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
25+
"include": ["**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
2626
"exclude": ["node_modules"]
2727
}

test/rspack-build-tests-manifest.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19987,17 +19987,6 @@
1998719987
"flakey": [],
1998819988
"runtimeError": false
1998919989
},
19990-
"test/integration/typescript-app-type-declarations/test/index.test.ts": {
19991-
"passed": [
19992-
"TypeScript App Type Declarations should not touch an existing correct next-env.d.ts",
19993-
"TypeScript App Type Declarations should overwrite next-env.d.ts if an incorrect one exists",
19994-
"TypeScript App Type Declarations should write a new next-env.d.ts if none exist"
19995-
],
19996-
"failed": [],
19997-
"pending": [],
19998-
"flakey": [],
19999-
"runtimeError": false
20000-
},
2000119990
"test/integration/typescript-baseurl/test/index.test.ts": {
2000219991
"passed": ["TypeScript Features default behavior should render the page"],
2000319992
"failed": [],
@@ -22069,5 +22058,16 @@
2206922058
"pending": [],
2207022059
"flakey": [],
2207122060
"runtimeError": false
22061+
},
22062+
"test/integration/typescript-app-type-declarations/test/index.test.ts": {
22063+
"passed": [
22064+
"TypeScript App Type Declarations should not create next-env.d.ts in project root",
22065+
"TypeScript App Type Declarations should not modify existing next-env.d.ts in project root",
22066+
"TypeScript App Type Declarations should overwrite next-env.d.ts in .next/types if incorrect"
22067+
],
22068+
"failed": [],
22069+
"pending": [],
22070+
"flakey": [],
22071+
"runtimeError": false
2207222072
}
2207322073
}

test/rspack-dev-tests-manifest.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21974,17 +21974,6 @@
2197421974
"flakey": [],
2197521975
"runtimeError": false
2197621976
},
21977-
"test/integration/typescript-app-type-declarations/test/index.test.ts": {
21978-
"passed": [
21979-
"TypeScript App Type Declarations should not touch an existing correct next-env.d.ts",
21980-
"TypeScript App Type Declarations should overwrite next-env.d.ts if an incorrect one exists",
21981-
"TypeScript App Type Declarations should write a new next-env.d.ts if none exist"
21982-
],
21983-
"failed": [],
21984-
"pending": [],
21985-
"flakey": [],
21986-
"runtimeError": false
21987-
},
2198821977
"test/integration/typescript-baseurl/test/index.test.ts": {
2198921978
"passed": ["TypeScript Features default behavior should render the page"],
2199021979
"failed": [],
@@ -22178,5 +22167,16 @@
2217822167
],
2217922168
"flakey": [],
2218022169
"runtimeError": false
22170+
},
22171+
"test/integration/typescript-app-type-declarations/test/index.test.ts": {
22172+
"passed": [
22173+
"TypeScript App Type Declarations should not create next-env.d.ts in project root",
22174+
"TypeScript App Type Declarations should not modify existing next-env.d.ts in project root",
22175+
"TypeScript App Type Declarations should overwrite next-env.d.ts in .next/types if incorrect"
22176+
],
22177+
"failed": [],
22178+
"pending": [],
22179+
"flakey": [],
22180+
"runtimeError": false
2218122181
}
2218222182
}

test/turbopack-build-tests-manifest.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17865,17 +17865,6 @@
1786517865
"flakey": [],
1786617866
"runtimeError": false
1786717867
},
17868-
"test/integration/typescript-app-type-declarations/test/index.test.ts": {
17869-
"passed": [
17870-
"TypeScript App Type Declarations should not touch an existing correct next-env.d.ts",
17871-
"TypeScript App Type Declarations should overwrite next-env.d.ts if an incorrect one exists",
17872-
"TypeScript App Type Declarations should write a new next-env.d.ts if none exist"
17873-
],
17874-
"failed": [],
17875-
"pending": [],
17876-
"flakey": [],
17877-
"runtimeError": false
17878-
},
1787917868
"test/integration/typescript-baseurl/test/index.test.ts": {
1788017869
"passed": ["TypeScript Features default behavior should render the page"],
1788117870
"failed": [],
@@ -19631,5 +19620,16 @@
1963119620
"pending": [],
1963219621
"flakey": [],
1963319622
"runtimeError": false
19623+
},
19624+
"test/integration/typescript-app-type-declarations/test/index.test.ts": {
19625+
"passed": [
19626+
"TypeScript App Type Declarations should not create next-env.d.ts in project root",
19627+
"TypeScript App Type Declarations should not modify existing next-env.d.ts in project root",
19628+
"TypeScript App Type Declarations should overwrite next-env.d.ts in .next/types if incorrect"
19629+
],
19630+
"failed": [],
19631+
"pending": [],
19632+
"flakey": [],
19633+
"runtimeError": false
1963419634
}
1963519635
}

0 commit comments

Comments
 (0)