Commit 6fe3a18f authored by JJ Kasper's avatar JJ Kasper

Merge branch 'canary' into next-15-rc

parents 7dbaa894 41a80533
...@@ -4,7 +4,23 @@ import { dirname, join, relative } from 'path' ...@@ -4,7 +4,23 @@ import { dirname, join, relative } from 'path'
export interface MissingDependency { export interface MissingDependency {
file: string file: string
/**
* The package's package.json (e.g. require(`${pkg}/package.json`)) MUST resolve.
* If `exportsRestrict` is false, `${file}` MUST also resolve.
*/
pkg: string pkg: string
/**
* If true, the pkg's package.json needs to be resolvable.
* If true, will resolve `file` relative to the real path of the package.json.
*
* For example, `{ file: '@types/react/index.d.ts', pkg: '@types/react', exportsRestrict: true }`
* will try to resolve '@types/react/package.json' first and then assume `@types/react/index.d.ts`
* resolves to `path.join(dirname(resolvedPackageJsonPath), 'index.d.ts')`.
*
* If false, will resolve `file` relative to the baseDir.
* ForFor example, `{ file: '@types/react/index.d.ts', pkg: '@types/react', exportsRestrict: true }`
* will try to resolve `@types/react/index.d.ts` directly.
*/
exportsRestrict: boolean exportsRestrict: boolean
} }
......
...@@ -2,10 +2,7 @@ import { bold, cyan, red, yellow } from './picocolors' ...@@ -2,10 +2,7 @@ import { bold, cyan, red, yellow } from './picocolors'
import path from 'path' import path from 'path'
import { hasNecessaryDependencies } from './has-necessary-dependencies' import { hasNecessaryDependencies } from './has-necessary-dependencies'
import type { import type { NecessaryDependencies } from './has-necessary-dependencies'
MissingDependency,
NecessaryDependencies,
} from './has-necessary-dependencies'
import semver from 'next/dist/compiled/semver' import semver from 'next/dist/compiled/semver'
import { CompileError } from './compile-error' import { CompileError } from './compile-error'
import * as log from '../build/output/log' import * as log from '../build/output/log'
...@@ -72,37 +69,11 @@ export async function verifyTypeScriptSetup({ ...@@ -72,37 +69,11 @@ export async function verifyTypeScriptSetup({
requiredPackages requiredPackages
) )
const missingTypeDeps: MissingDependency[] = [] if (deps.missing?.length > 0) {
const missingDepsExceptTypes: MissingDependency[] = []
for (const dep of deps.missing) {
if (dep.pkg.startsWith('@types/')) {
missingTypeDeps.push(dep)
} else {
missingDepsExceptTypes.push(dep)
}
}
// Just warn for potentially missing type deps.
// TODO: Fix false-positive in `hasNecessaryDependencies` when `overrides` are used in package managers
if (missingTypeDeps.length > 0) {
console.log(
bold(
yellow(
`It looks like you're trying to use TypeScript but do not have the required type package(s) installed.`
)
) +
'\n' +
'This may be a bug in Next.js. Please file an issue.\n' +
'Make sure the following type packages are installed:\n' +
missingTypeDeps.map((dep) => ` ${cyan(dep.pkg)}`).join('\n')
)
}
if (missingDepsExceptTypes.length > 0) {
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, missingDepsExceptTypes) missingDepsError(dir, deps.missing)
} }
console.log( console.log(
bold( bold(
...@@ -120,8 +91,7 @@ export async function verifyTypeScriptSetup({ ...@@ -120,8 +91,7 @@ export async function verifyTypeScriptSetup({
) + ) +
'\n' '\n'
) )
await installDependencies(dir, missingDepsExceptTypes, true).catch( await installDependencies(dir, deps.missing, true).catch((err) => {
(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` +
...@@ -130,8 +100,7 @@ export async function verifyTypeScriptSetup({ ...@@ -130,8 +100,7 @@ export async function verifyTypeScriptSetup({
) )
} }
throw err throw err
} })
)
deps = await hasNecessaryDependencies(dir, requiredPackages) deps = await hasNecessaryDependencies(dir, requiredPackages)
} }
......
...@@ -68,15 +68,9 @@ describe('ci-missing-typescript-deps', () => { ...@@ -68,15 +68,9 @@ describe('ci-missing-typescript-deps', () => {
}) })
try { try {
const nextBuild = await next.build() const nextBuild = await next.build()
// build doesn't fail because types/ may not be installed. expect(nextBuild.cliOutput).toContain(
expect(nextBuild.cliOutput.split('\n')).toEqual( // matching the part of the success message that isn't colored.
expect.arrayContaining([ `We detected TypeScript in your project and created`
'This may be a bug in Next.js. Please file an issue.',
'Make sure the following type packages are installed:',
// In cyan color but this changes between CI and local.
// TODO: Use picocolors in tests to ensure we can test local and CI.
expect.stringContaining('@types/react'),
])
) )
} finally { } finally {
await next.destroy() await next.destroy()
......
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