Unverified Commit b15a3f62 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Pin test and auto-installed TypeScript to 5.8.2 (#93107)

## Summary
- pin the shared test harness and affected TypeScript tests to
`typescript@5.8.2`
- pin Next.js TypeScript auto-install paths to `typescript@5.8.2` so
missing deps do not resolve to v6
- lock the first-time TypeScript test fixture to the same exact version

## Testing
- `pnpm exec tsc -v`
- `pnpm why typescript --depth 0`
- `pnpm types:test-lib` *(still fails on existing declaration/type
surface errors, but no longer fails on the TS6 `moduleResolution=node10`
deprecation)*
parent 3f1b7b75
...@@ -6,6 +6,7 @@ import { readFile } from 'node:fs/promises' ...@@ -6,6 +6,7 @@ import { readFile } from 'node:fs/promises'
import { deregisterHook, registerHook, requireFromString } from './require-hook' import { deregisterHook, registerHook, requireFromString } from './require-hook'
import { warn } from '../output/log' import { warn } from '../output/log'
import { installDependencies } from '../../lib/install-dependencies' import { installDependencies } from '../../lib/install-dependencies'
import { getTypeScriptPackageSpec } from '../../lib/typescript/required-packages'
function resolveSWCOptions( function resolveSWCOptions(
cwd: string, cwd: string,
...@@ -47,18 +48,20 @@ async function verifyTypeScriptSetup(cwd: string, configFileName: string) { ...@@ -47,18 +48,20 @@ async function verifyTypeScriptSetup(cwd: string, configFileName: string) {
`Installing TypeScript as it was not found while loading "${configFileName}".` `Installing TypeScript as it was not found while loading "${configFileName}".`
) )
await installDependencies(cwd, [{ pkg: 'typescript' }], true).catch( await installDependencies(
(err) => { cwd,
if (err && typeof err === 'object' && 'command' in err) { [{ pkg: getTypeScriptPackageSpec('typescript') }],
console.error( true
`Failed to install TypeScript, please install it manually to continue:\n` + ).catch((err) => {
(err as any).command + if (err && typeof err === 'object' && 'command' in err) {
'\n' console.error(
) `Failed to install TypeScript, please install it manually to continue:\n` +
} (err as any).command +
throw err '\n'
)
} }
) throw err
})
} }
} }
} }
......
export const requiredTypeScriptVersion = '5.8.2'
export const requiredNodeTypesVersion = '20.17.6'
export function getTypeScriptPackageSpec(pkg: string) {
switch (pkg) {
case 'typescript':
return `${pkg}@${requiredTypeScriptVersion}`
case '@types/node':
return `${pkg}@${requiredNodeTypesVersion}`
default:
return pkg
}
}
...@@ -9,6 +9,7 @@ import * as log from '../build/output/log' ...@@ -9,6 +9,7 @@ import * as log from '../build/output/log'
import { getTypeScriptIntent } from './typescript/getTypeScriptIntent' import { getTypeScriptIntent } from './typescript/getTypeScriptIntent'
import type { TypeCheckResult } from './typescript/runTypeCheck' import type { TypeCheckResult } from './typescript/runTypeCheck'
import { getTypeScriptPackageSpec } from './typescript/required-packages'
import { writeAppTypeDeclarations } from './typescript/writeAppTypeDeclarations' import { writeAppTypeDeclarations } from './typescript/writeAppTypeDeclarations'
import { writeConfigurationDefaults } from './typescript/writeConfigurationDefaults' import { writeConfigurationDefaults } from './typescript/writeConfigurationDefaults'
import { installDependencies } from './install-dependencies' import { installDependencies } from './install-dependencies'
...@@ -70,10 +71,15 @@ export async function verifyTypeScriptSetup({ ...@@ -70,10 +71,15 @@ export async function verifyTypeScriptSetup({
) )
if (deps.missing?.length > 0) { if (deps.missing?.length > 0) {
const missingPackages = deps.missing.map((pkg) => ({
...pkg,
pkg: getTypeScriptPackageSpec(pkg.pkg),
}))
if (isCI) { if (isCI) {
// we don't attempt auto install in CI to avoid side-effects // we don't attempt auto install in CI to avoid side-effects
// and instead log the error for installing needed packages // and instead log the error for installing needed packages
missingDepsError(dir, deps.missing) missingDepsError(dir, missingPackages)
} }
console.log( console.log(
bold( bold(
...@@ -91,7 +97,7 @@ export async function verifyTypeScriptSetup({ ...@@ -91,7 +97,7 @@ export async function verifyTypeScriptSetup({
) + ) +
'\n' '\n'
) )
await installDependencies(dir, deps.missing, true).catch((err) => { await installDependencies(dir, missingPackages, true).catch((err) => {
if (err && typeof err === 'object' && 'command' in err) { if (err && typeof err === 'object' && 'command' in err) {
console.error( console.error(
`Failed to install required TypeScript dependencies, please install them manually to continue:\n` + `Failed to install required TypeScript dependencies, please install them manually to continue:\n` +
......
...@@ -13,7 +13,7 @@ describe('Error overlay - RSC build errors', () => { ...@@ -13,7 +13,7 @@ describe('Error overlay - RSC build errors', () => {
'react-tweet': '^3.2.0', 'react-tweet': '^3.2.0',
'@mdx-js/react': '^2.3.0', '@mdx-js/react': '^2.3.0',
tailwindcss: '^3.2.6', tailwindcss: '^3.2.6',
typescript: 'latest', typescript: '5.8.2',
'@types/react': '^18.0.28', '@types/react': '^18.0.28',
'@types/react-dom': '^18.0.10', '@types/react-dom': '^18.0.10',
'image-size': '^1.0.2', 'image-size': '^1.0.2',
......
...@@ -8,9 +8,9 @@ describe('useDefineForClassFields SWC option', () => { ...@@ -8,9 +8,9 @@ describe('useDefineForClassFields SWC option', () => {
files: join(__dirname, 'fixture'), files: join(__dirname, 'fixture'),
dependencies: { dependencies: {
mobx: '6.3.7', mobx: '6.3.7',
typescript: 'latest', typescript: '5.8.2',
'@types/react': 'latest', '@types/react': 'latest',
'@types/node': 'latest', '@types/node': '20.17.6',
'mobx-react': '7.2.1', 'mobx-react': '7.2.1',
}, },
}) })
......
...@@ -12,9 +12,9 @@ describe('correct tsconfig.json defaults', () => { ...@@ -12,9 +12,9 @@ describe('correct tsconfig.json defaults', () => {
}, },
skipStart: true, skipStart: true,
dependencies: { dependencies: {
typescript: 'latest', typescript: '5.8.2',
'@types/react': 'latest', '@types/react': 'latest',
'@types/node': 'latest', '@types/node': '20.17.6',
}, },
}) })
}) })
......
...@@ -36,9 +36,9 @@ describe('jsconfig-path-reloading', () => { ...@@ -36,9 +36,9 @@ describe('jsconfig-path-reloading', () => {
}), }),
}, },
dependencies: { dependencies: {
typescript: 'latest', typescript: '5.8.2',
'@types/react': 'latest', '@types/react': 'latest',
'@types/node': 'latest', '@types/node': '20.17.6',
}, },
}) })
......
...@@ -36,9 +36,9 @@ describe('tsconfig-path-reloading', () => { ...@@ -36,9 +36,9 @@ describe('tsconfig-path-reloading', () => {
}), }),
}, },
dependencies: { dependencies: {
typescript: 'latest', typescript: '5.8.2',
'@types/react': 'latest', '@types/react': 'latest',
'@types/node': 'latest', '@types/node': '20.17.6',
}, },
}) })
......
...@@ -9,9 +9,9 @@ describe('navigation between pages and app dir', () => { ...@@ -9,9 +9,9 @@ describe('navigation between pages and app dir', () => {
next = await createNext({ next = await createNext({
files: new FileRef(__dirname), files: new FileRef(__dirname),
dependencies: { dependencies: {
typescript: 'latest', typescript: '5.8.2',
'@types/react': 'latest', '@types/react': 'latest',
'@types/node': 'latest', '@types/node': '20.17.6',
}, },
}) })
}) })
......
...@@ -4,9 +4,9 @@ describe('redirects and rewrites', () => { ...@@ -4,9 +4,9 @@ describe('redirects and rewrites', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
dependencies: { dependencies: {
typescript: 'latest', typescript: '5.8.2',
'@types/react': 'latest', '@types/react': 'latest',
'@types/node': 'latest', '@types/node': '20.17.6',
}, },
}) })
......
...@@ -14,6 +14,6 @@ ...@@ -14,6 +14,6 @@
"devDependencies": { "devDependencies": {
"@types/react": "^18", "@types/react": "^18",
"@types/react-dom": "^18", "@types/react-dom": "^18",
"typescript": "^5" "typescript": "5.8.2"
} }
} }
...@@ -61,6 +61,8 @@ type OmitFirstArgument<F> = F extends ( ...@@ -61,6 +61,8 @@ type OmitFirstArgument<F> = F extends (
// Do not rename or format. sync-react script relies on this line. // Do not rename or format. sync-react script relies on this line.
// prettier-ignore // prettier-ignore
const nextjsReactPeerVersion = "19.1.0"; const nextjsReactPeerVersion = "19.1.0";
const latestSupportedTypeScriptVersion = '5.8.2'
const latestSupportedNodeTypesVersion = '20.17.6'
export class NextInstance { export class NextInstance {
protected files: ResolvedFileConfig protected files: ResolvedFileConfig
...@@ -213,8 +215,8 @@ export class NextInstance { ...@@ -213,8 +215,8 @@ export class NextInstance {
'react-dom': reactVersion, 'react-dom': reactVersion,
'@types/react': '^19.1.1', '@types/react': '^19.1.1',
'@types/react-dom': '^19.1.2', '@types/react-dom': '^19.1.2',
typescript: 'latest', typescript: latestSupportedTypeScriptVersion,
'@types/node': 'latest', '@types/node': latestSupportedNodeTypesVersion,
...this.dependencies, ...this.dependencies,
...this.packageJson?.dependencies, ...this.packageJson?.dependencies,
} }
......
...@@ -130,13 +130,13 @@ describe('eslint plugin deps', () => { ...@@ -130,13 +130,13 @@ describe('eslint plugin deps', () => {
'eslint-config-prettier': 'latest', 'eslint-config-prettier': 'latest',
'eslint-plugin-import': 'latest', 'eslint-plugin-import': 'latest',
'eslint-plugin-react': 'latest', 'eslint-plugin-react': 'latest',
'@types/node': 'latest', '@types/node': '20.17.6',
'@types/react': 'latest', '@types/react': 'latest',
'@types/react-dom': 'latest', '@types/react-dom': 'latest',
// Use minimum peer dep version instead of v9 of eslint to avoid breaking changes // Use minimum peer dep version instead of v9 of eslint to avoid breaking changes
eslint: '8.56.0', eslint: '8.56.0',
'eslint-config-next': 'latest', 'eslint-config-next': 'latest',
typescript: 'latest', typescript: '5.8.2',
}, },
packageJson: { packageJson: {
scripts: { scripts: {
......
...@@ -11,9 +11,9 @@ describe('Does not override tsconfig moduleResolution field during build', () => ...@@ -11,9 +11,9 @@ describe('Does not override tsconfig moduleResolution field during build', () =>
pkg: new FileRef(join(__dirname, 'pkg')), pkg: new FileRef(join(__dirname, 'pkg')),
}, },
dependencies: { dependencies: {
typescript: 'latest', typescript: '5.8.2',
'@types/react': 'latest', '@types/react': 'latest',
'@types/node': 'latest', '@types/node': '20.17.6',
pkg: './pkg', pkg: './pkg',
}, },
}) })
......
...@@ -11,8 +11,8 @@ describe('TypeScript basic', () => { ...@@ -11,8 +11,8 @@ describe('TypeScript basic', () => {
files: new FileRef(path.join(__dirname, 'app')), files: new FileRef(path.join(__dirname, 'app')),
dependencies: { dependencies: {
'@next/bundle-analyzer': 'canary', '@next/bundle-analyzer': 'canary',
typescript: 'latest', typescript: '5.8.2',
'@types/node': 'latest', '@types/node': '20.17.6',
'@types/react': 'latest', '@types/react': 'latest',
'@types/react-dom': 'latest', '@types/react-dom': 'latest',
}, },
......
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