Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
6fe3a18f
Commit
6fe3a18f
authored
May 23, 2024
by
JJ Kasper
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'canary' into next-15-rc
parents
7dbaa894
41a80533
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
52 deletions
+31
-52
has-necessary-dependencies.ts
packages/next/src/lib/has-necessary-dependencies.ts
+16
-0
verify-typescript-setup.ts
packages/next/src/lib/verify-typescript-setup.ts
+12
-43
index.test.ts
test/production/ci-missing-typescript-deps/index.test.ts
+3
-9
No files found.
packages/next/src/lib/has-necessary-dependencies.ts
View file @
6fe3a18f
...
@@ -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
}
}
...
...
packages/next/src/lib/verify-typescript-setup.ts
View file @
6fe3a18f
...
@@ -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,18 +91,16 @@ export async function verifyTypeScriptSetup({
...
@@ -120,18 +91,16 @@ 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`
+
(
err
as
any
).
command
+
(
err
as
any
).
command
+
'
\
n'
'
\
n'
)
)
}
throw
err
}
}
)
throw
err
})
deps
=
await
hasNecessaryDependencies
(
dir
,
requiredPackages
)
deps
=
await
hasNecessaryDependencies
(
dir
,
requiredPackages
)
}
}
...
...
test/production/ci-missing-typescript-deps/index.test.ts
View file @
6fe3a18f
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment