Unverified Commit b821f423 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Revert "dx: avoid next-env.d.ts change in dev" (#88153)

Reverting since it produced merge conflicts with in-progress
[strict-route-types
project](https://linear.app/vercel/project/nextjs-strict-route-types-2f0a70110d5d/overview):

The lesson learned from the earlier PR was that this is a risky change.
We'll land a similar change flagged in
https://github.com/vercel/next.js/pull/87768
parent 79040a31
...@@ -20,7 +20,6 @@ import { hrtimeDurationToString } from './duration-to-string' ...@@ -20,7 +20,6 @@ import { hrtimeDurationToString } from './duration-to-string'
function verifyTypeScriptSetup( function verifyTypeScriptSetup(
dir: string, dir: string,
distDir: string, distDir: string,
distDirRoot: string | undefined,
typeCheckPreflight: boolean, typeCheckPreflight: boolean,
tsconfigPath: string | undefined, tsconfigPath: string | undefined,
disableStaticImages: boolean, disableStaticImages: boolean,
...@@ -51,7 +50,6 @@ function verifyTypeScriptSetup( ...@@ -51,7 +50,6 @@ function verifyTypeScriptSetup(
.verifyTypeScriptSetup({ .verifyTypeScriptSetup({
dir, dir,
distDir, distDir,
distDirRoot,
typeCheckPreflight, typeCheckPreflight,
tsconfigPath, tsconfigPath,
disableStaticImages, disableStaticImages,
...@@ -119,7 +117,6 @@ export async function startTypeChecking({ ...@@ -119,7 +117,6 @@ export async function startTypeChecking({
verifyTypeScriptSetup( verifyTypeScriptSetup(
dir, dir,
config.distDir, config.distDir,
config.distDirRoot,
!ignoreTypeScriptErrors, !ignoreTypeScriptErrors,
config.typescript.tsconfigPath, config.typescript.tsconfigPath,
config.images.disableStaticImages, config.images.disableStaticImages,
......
...@@ -140,7 +140,6 @@ async function runPlaywright( ...@@ -140,7 +140,6 @@ async function runPlaywright(
const { version: typeScriptVersion } = await verifyTypeScriptSetup({ const { version: typeScriptVersion } = await verifyTypeScriptSetup({
dir: baseDir, dir: baseDir,
distDir: nextConfig.distDir, distDir: nextConfig.distDir,
distDirRoot: nextConfig.distDirRoot,
typeCheckPreflight: false, typeCheckPreflight: false,
tsconfigPath: nextConfig.typescript.tsconfigPath, tsconfigPath: nextConfig.typescript.tsconfigPath,
disableStaticImages: nextConfig.images.disableStaticImages, disableStaticImages: nextConfig.images.disableStaticImages,
......
...@@ -57,7 +57,6 @@ const nextTypegen = async ( ...@@ -57,7 +57,6 @@ const nextTypegen = async (
await verifyTypeScriptSetup({ await verifyTypeScriptSetup({
dir: baseDir, dir: baseDir,
distDir: nextConfig.distDir, distDir: nextConfig.distDir,
distDirRoot: nextConfig.distDirRoot,
typeCheckPreflight: false, typeCheckPreflight: false,
tsconfigPath: nextConfig.typescript.tsconfigPath, tsconfigPath: nextConfig.typescript.tsconfigPath,
disableStaticImages: nextConfig.images.disableStaticImages, disableStaticImages: nextConfig.images.disableStaticImages,
......
...@@ -5,15 +5,12 @@ import { promises as fs } from 'fs' ...@@ -5,15 +5,12 @@ import { promises as fs } from 'fs'
export async function writeAppTypeDeclarations({ export async function writeAppTypeDeclarations({
baseDir, baseDir,
distDir, distDir,
distDirRoot,
imageImportsEnabled, imageImportsEnabled,
hasPagesDir, hasPagesDir,
hasAppDir, hasAppDir,
}: { }: {
baseDir: string baseDir: string
distDir: string distDir: string
/** The original distDir before any modifications (e.g., for isolatedDevBuild). Used for stable type imports. */
distDirRoot?: string
imageImportsEnabled: boolean imageImportsEnabled: boolean
hasPagesDir: boolean hasPagesDir: boolean
hasAppDir: boolean hasAppDir: boolean
...@@ -60,12 +57,10 @@ export async function writeAppTypeDeclarations({ ...@@ -60,12 +57,10 @@ export async function writeAppTypeDeclarations({
) )
} }
// Use distDirRoot for stable path that doesn't change between dev/build modes const routeTypesPath = path.posix.join(
const stableDistDir = (distDirRoot ?? distDir).replaceAll( distDir.replaceAll(path.win32.sep, path.posix.sep),
path.win32.sep, 'types/routes.d.ts'
path.posix.sep
) )
const routeTypesPath = path.posix.join(stableDistDir, 'types/routes.d.ts')
// Use ESM import instead of triple-slash reference for better ESLint compatibility // Use ESM import instead of triple-slash reference for better ESLint compatibility
directives.push(`import "./${routeTypesPath}";`) directives.push(`import "./${routeTypesPath}";`)
......
...@@ -36,7 +36,6 @@ const requiredPackages = [ ...@@ -36,7 +36,6 @@ const requiredPackages = [
export async function verifyTypeScriptSetup({ export async function verifyTypeScriptSetup({
dir, dir,
distDir, distDir,
distDirRoot,
cacheDir, cacheDir,
tsconfigPath, tsconfigPath,
typeCheckPreflight, typeCheckPreflight,
...@@ -50,8 +49,6 @@ export async function verifyTypeScriptSetup({ ...@@ -50,8 +49,6 @@ export async function verifyTypeScriptSetup({
}: { }: {
dir: string dir: string
distDir: string distDir: string
/** The original distDir before any modifications (e.g., for isolatedDevBuild). */
distDirRoot?: string
cacheDir?: string cacheDir?: string
tsconfigPath: string | undefined tsconfigPath: string | undefined
typeCheckPreflight: boolean typeCheckPreflight: boolean
...@@ -146,7 +143,6 @@ export async function verifyTypeScriptSetup({ ...@@ -146,7 +143,6 @@ export async function verifyTypeScriptSetup({
await writeAppTypeDeclarations({ await writeAppTypeDeclarations({
baseDir: dir, baseDir: dir,
distDir, distDir,
distDirRoot,
imageImportsEnabled: !disableStaticImages, imageImportsEnabled: !disableStaticImages,
hasPagesDir, hasPagesDir,
hasAppDir, hasAppDir,
......
...@@ -395,28 +395,3 @@ export async function writeValidatorFile( ...@@ -395,28 +395,3 @@ export async function writeValidatorFile(
: generateValidatorFile(manifest) : generateValidatorFile(manifest)
) )
} }
/**
* Writes a proxy routes.d.ts file at the stable path that re-exports from
* the actual dev types location. This allows next-env.d.ts to always reference
* the same stable path regardless of dev/build mode.
*
* @param stableTypesDir - The stable types directory (e.g., .next/types)
* @param devTypesRelativePath - Relative path from stable dir to dev types (e.g., ../dev/types/routes.d.ts)
*/
export async function writeRouteTypesProxy(
stableTypesDir: string,
devTypesRelativePath: string
) {
if (!fs.existsSync(stableTypesDir)) {
await fs.promises.mkdir(stableTypesDir, { recursive: true })
}
const proxyFilePath = path.join(stableTypesDir, 'routes.d.ts')
const proxyContent = `// This file re-exports route types from the dev types location.
// This provides a stable import path for next-env.d.ts across dev/build modes.
export * from '${devTypesRelativePath}';
`
await fs.promises.writeFile(proxyFilePath, proxyContent)
}
...@@ -85,7 +85,6 @@ import { ...@@ -85,7 +85,6 @@ import {
createRouteTypesManifest, createRouteTypesManifest,
writeRouteTypesManifest, writeRouteTypesManifest,
writeValidatorFile, writeValidatorFile,
writeRouteTypesProxy,
} from './route-types-utils' } from './route-types-utils'
import { writeCacheLifeTypes } from './cache-life-type-utils' import { writeCacheLifeTypes } from './cache-life-type-utils'
import { isParallelRouteSegment } from '../../../shared/lib/segment' import { isParallelRouteSegment } from '../../../shared/lib/segment'
...@@ -144,7 +143,6 @@ async function verifyTypeScript(opts: SetupOpts) { ...@@ -144,7 +143,6 @@ async function verifyTypeScript(opts: SetupOpts) {
const verifyResult = await verifyTypeScriptSetup({ const verifyResult = await verifyTypeScriptSetup({
dir: opts.dir, dir: opts.dir,
distDir: opts.nextConfig.distDir, distDir: opts.nextConfig.distDir,
distDirRoot: opts.nextConfig.distDirRoot,
typeCheckPreflight: false, typeCheckPreflight: false,
tsconfigPath: opts.nextConfig.typescript.tsconfigPath, tsconfigPath: opts.nextConfig.typescript.tsconfigPath,
disableStaticImages: opts.nextConfig.images.disableStaticImages, disableStaticImages: opts.nextConfig.images.disableStaticImages,
...@@ -268,17 +266,6 @@ async function startWatcher( ...@@ -268,17 +266,6 @@ async function startWatcher(
opts.nextConfig opts.nextConfig
) )
// When isolatedDevBuild is enabled, write a proxy file at the stable path
// that re-exports from the dev types location
if (opts.nextConfig.experimental.isolatedDevBuild) {
const stableTypesDir = path.join(
opts.dir,
opts.nextConfig.distDirRoot,
'types'
)
await writeRouteTypesProxy(stableTypesDir, '../dev/types/routes.d.ts')
}
const routesManifestPath = path.join(distDir, ROUTES_MANIFEST) const routesManifestPath = path.join(distDir, ROUTES_MANIFEST)
const routesManifest: DevRoutesManifest = { const routesManifest: DevRoutesManifest = {
version: 3, version: 3,
......
...@@ -23,32 +23,4 @@ describe('isolated-dev-build', () => { ...@@ -23,32 +23,4 @@ describe('isolated-dev-build', () => {
expect(await browser.elementByCss('p').text()).toBe('hello updated world') expect(await browser.elementByCss('p').text()).toBe('hello updated world')
}) })
}) })
it('should use stable path in next-env.d.ts that does not change between dev/build', async () => {
const nextEnvContent = await next.readFile('next-env.d.ts')
// Snapshot ensures next-env.d.ts content stays stable
expect(nextEnvContent).toMatchInlineSnapshot(`
"/// <reference types="next" />
/// <reference types="next/image-types/global" />
import "./.next/types/routes.d.ts";
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
"
`)
})
it('should create proxy routes.d.ts at stable path that re-exports from dev types', async () => {
// The proxy file should re-export from the dev types location
const proxyContent = await next.readFile('.next/types/routes.d.ts')
expect(proxyContent).toMatchInlineSnapshot(`
"// This file re-exports route types from the dev types location.
// This provides a stable import path for next-env.d.ts across dev/build modes.
export * from '../dev/types/routes.d.ts';
"
`)
// The actual dev types should exist
expect(await next.hasFile('.next/dev/types/routes.d.ts')).toBe(true)
})
}) })
/// <reference types="next" /> /// <reference types="next" />
/// <reference types="next/image-types/global" /> /// <reference types="next/image-types/global" />
import './.next/types/routes.d.ts' import './.next/dev/types/routes.d.ts'
// NOTE: This file should not be edited // NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information. // see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
/// <reference types="next" /> /// <reference types="next" />
/// <reference types="next/image-types/global" /> /// <reference types="next/image-types/global" />
import "./.next/types/routes.d.ts"; import "./.next/dev/types/routes.d.ts";
// NOTE: This file should not be edited // NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information. // see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment