Skip to content

Commit 87fc1b9

Browse files
authored
Fix duplicate .next/types include on Windows (#85400)
1 parent 8cdd4ea commit 87fc1b9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { readFileSync, writeFileSync } from 'fs'
2+
import * as path from 'path'
23
import { bold, cyan, white } from '../picocolors'
34
import * as CommentJson from 'next/dist/compiled/comment-json'
45
import semver from 'next/dist/compiled/semver'
@@ -267,7 +268,11 @@ export async function writeConfigurationDefaults(
267268
}
268269
}
269270

270-
const nextAppTypes: string[] = [`${distDir}/types/**/*.ts`]
271+
const distDirPosix =
272+
path.win32.sep === path.sep
273+
? distDir.replaceAll(path.win32.sep, path.posix.sep)
274+
: distDir
275+
const nextAppTypes: string[] = [`${distDirPosix}/types/**/*.ts`]
271276

272277
// When isolatedDevBuild is enabled, Next.js uses different distDir paths:
273278
// - Development: "{distDir}/dev"
@@ -279,10 +284,10 @@ export async function writeConfigurationDefaults(
279284
process.env.NODE_ENV === 'development'
280285
? // In dev, distDir is "{distDir}/dev", which is already in the array above, but we also need "{distDir}/types".
281286
// Here we remove "/dev" at the end of distDir for consistency.
282-
`${distDir.replace(/\/dev$/, '')}/types/**/*.ts`
287+
`${distDirPosix.replace(/\/dev$/, '')}/types/**/*.ts`
283288
: // In build, distDir is "{distDir}", which is already in the array above, but we also need "{distDir}/dev/types".
284289
// Here we add "/dev" at the end of distDir for consistency.
285-
`${distDir}/dev/types/**/*.ts`
290+
`${distDirPosix}/dev/types/**/*.ts`
286291
)
287292
// Sort the array to ensure consistent order.
288293
nextAppTypes.sort((a, b) => a.length - b.length)

0 commit comments

Comments
 (0)