diff --git a/packages/next/lib/eslint/runLintCheck.ts b/packages/next/lib/eslint/runLintCheck.ts index 5a654d9f9e2538a..a7229a6f5911259 100644 --- a/packages/next/lib/eslint/runLintCheck.ts +++ b/packages/next/lib/eslint/runLintCheck.ts @@ -34,8 +34,12 @@ function isValidSeverity(severity: string): severity is Severity { } const requiredPackages = [ - { file: 'eslint', pkg: 'eslint' }, - { file: 'eslint-config-next', pkg: 'eslint-config-next' }, + { file: 'eslint', pkg: 'eslint', exportsRestrict: false }, + { + file: 'eslint-config-next', + pkg: 'eslint-config-next', + exportsRestrict: false, + }, ] async function cliPrompt() { diff --git a/packages/next/lib/has-necessary-dependencies.ts b/packages/next/lib/has-necessary-dependencies.ts index 55097d400f9a8ce..8f1129beef8bd10 100644 --- a/packages/next/lib/has-necessary-dependencies.ts +++ b/packages/next/lib/has-necessary-dependencies.ts @@ -1,6 +1,10 @@ +import { existsSync } from 'fs' +import { join, relative } from 'path' + export interface MissingDependency { file: string pkg: string + exportsRestrict: boolean } export type NecessaryDependencies = { @@ -15,13 +19,33 @@ export async function hasNecessaryDependencies( let resolutions = new Map() const missingPackages = requiredPackages.filter((p) => { try { - resolutions.set(p.pkg, require.resolve(p.file, { paths: [baseDir] })) + if (p.exportsRestrict) { + const pkgPath = require.resolve(`${p.pkg}/package.json`, { + paths: [baseDir], + }) + const fileNameToVerify = relative(p.pkg, p.file) + if (fileNameToVerify) { + const fileToVerify = join(pkgPath, '..', fileNameToVerify) + if (existsSync(fileToVerify)) { + resolutions.set(p.pkg, join(pkgPath, '..')) + } else { + return true + } + } else { + resolutions.set(p.pkg, pkgPath) + } + } else { + resolutions.set(p.pkg, require.resolve(p.file, { paths: [baseDir] })) + } return false - } catch (_) { + } catch (e) { + console.error(e) return true } }) + console.log(resolutions) + return { resolved: resolutions, missing: missingPackages, diff --git a/packages/next/lib/verify-partytown-setup.ts b/packages/next/lib/verify-partytown-setup.ts index b1c89e0b1095671..cabae4723d9bfb6 100644 --- a/packages/next/lib/verify-partytown-setup.ts +++ b/packages/next/lib/verify-partytown-setup.ts @@ -61,7 +61,13 @@ export async function verifyPartytownSetup( try { const partytownDeps: NecessaryDependencies = await hasNecessaryDependencies( dir, - [{ file: '@builder.io/partytown', pkg: '@builder.io/partytown' }] + [ + { + file: '@builder.io/partytown', + pkg: '@builder.io/partytown', + exportsRestrict: false, + }, + ] ) if (partytownDeps.missing?.length > 0) { diff --git a/packages/next/lib/verifyTypeScriptSetup.ts b/packages/next/lib/verifyTypeScriptSetup.ts index d5035872882de70..01939302caae771 100644 --- a/packages/next/lib/verifyTypeScriptSetup.ts +++ b/packages/next/lib/verifyTypeScriptSetup.ts @@ -17,9 +17,17 @@ import { missingDepsError } from './typescript/missingDependencyError' import { NextConfigComplete } from '../server/config-shared' const requiredPackages = [ - { file: 'typescript', pkg: 'typescript' }, - { file: '@types/react/index.d.ts', pkg: '@types/react' }, - { file: '@types/node/index.d.ts', pkg: '@types/node' }, + { file: 'typescript', pkg: 'typescript', exportsRestrict: false }, + { + file: '@types/react/index.d.ts', + pkg: '@types/react', + exportsRestrict: true, + }, + { + file: '@types/node/index.d.ts', + pkg: '@types/node', + exportsRestrict: false, + }, ] export async function verifyTypeScriptSetup(