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