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
583b5b9d
Unverified
Commit
583b5b9d
authored
Jun 08, 2021
by
JJ Kasper
Committed by
GitHub
Jun 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add warning for older TypeScript versions (#25867)
parent
23ca042c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
116 additions
and
0 deletions
+116
-0
verifyTypeScriptSetup.ts
packages/next/lib/verifyTypeScriptSetup.ts
+8
-0
index.js
...ript-version-warning/app/node_modules/typescript/index.js
+5
-0
package.json
...-version-warning/app/node_modules/typescript/package.json
+5
-0
index.tsx
...ntegration/typescript-version-warning/app/pages/index.tsx
+3
-0
tsconfig.json
.../integration/typescript-version-warning/app/tsconfig.json
+19
-0
index.test.js
...integration/typescript-version-warning/test/index.test.js
+76
-0
No files found.
packages/next/lib/verifyTypeScriptSetup.ts
View file @
583b5b9d
...
@@ -4,8 +4,10 @@ import {
...
@@ -4,8 +4,10 @@ import {
hasNecessaryDependencies
,
hasNecessaryDependencies
,
NecessaryDependencies
,
NecessaryDependencies
,
}
from
'./has-necessary-dependencies'
}
from
'./has-necessary-dependencies'
import
semver
from
'next/dist/compiled/semver'
import
{
CompileError
}
from
'./compile-error'
import
{
CompileError
}
from
'./compile-error'
import
{
FatalError
}
from
'./fatal-error'
import
{
FatalError
}
from
'./fatal-error'
import
*
as
log
from
'../build/output/log'
import
{
getTypeScriptIntent
}
from
'./typescript/getTypeScriptIntent'
import
{
getTypeScriptIntent
}
from
'./typescript/getTypeScriptIntent'
import
{
TypeCheckResult
}
from
'./typescript/runTypeCheck'
import
{
TypeCheckResult
}
from
'./typescript/runTypeCheck'
...
@@ -38,6 +40,12 @@ export async function verifyTypeScriptSetup(
...
@@ -38,6 +40,12 @@ export async function verifyTypeScriptSetup(
// Load TypeScript after we're sure it exists:
// Load TypeScript after we're sure it exists:
const
ts
=
(
await
import
(
deps
.
resolved
))
as
typeof
import
(
'typescript'
)
const
ts
=
(
await
import
(
deps
.
resolved
))
as
typeof
import
(
'typescript'
)
if
(
semver
.
lt
(
ts
.
version
,
'4.3.2'
))
{
log
.
warn
(
`Minimum recommended TypeScript version is v4.3.2, older versions can potentially be incompatible with Next.js. Detected:
${
ts
.
version
}
`
)
}
// Reconfigure (or create) the user's `tsconfig.json` for them:
// Reconfigure (or create) the user's `tsconfig.json` for them:
await
writeConfigurationDefaults
(
ts
,
tsConfigPath
,
firstTimeSetup
)
await
writeConfigurationDefaults
(
ts
,
tsConfigPath
,
firstTimeSetup
)
// Write out the necessary `next-env.d.ts` file to correctly register
// Write out the necessary `next-env.d.ts` file to correctly register
...
...
test/integration/typescript-version-warning/app/node_modules/typescript/index.js
0 → 100644
View file @
583b5b9d
const
mod
=
require
(
'../../../../../../node_modules/typescript'
)
mod
.
version
=
'3.8.3'
module
.
exports
=
mod
test/integration/typescript-version-warning/app/node_modules/typescript/package.json
0 → 100644
View file @
583b5b9d
{
"name"
:
"typescript"
,
"version"
:
"3.8.3"
,
"main"
:
"./index.js"
}
test/integration/typescript-version-warning/app/pages/index.tsx
0 → 100644
View file @
583b5b9d
export
default
function
Page
(
props
)
{
return
<
p
>
hello world
</
p
>
}
test/integration/typescript-version-warning/app/tsconfig.json
0 → 100644
View file @
583b5b9d
{
"compilerOptions"
:
{
"target"
:
"es5"
,
"lib"
:
[
"dom"
,
"dom.iterable"
,
"esnext"
],
"allowJs"
:
true
,
"skipLibCheck"
:
true
,
"strict"
:
false
,
"forceConsistentCasingInFileNames"
:
true
,
"noEmit"
:
true
,
"esModuleInterop"
:
true
,
"module"
:
"esnext"
,
"moduleResolution"
:
"node"
,
"resolveJsonModule"
:
true
,
"isolatedModules"
:
true
,
"jsx"
:
"preserve"
},
"include"
:
[
"next-env.d.ts"
,
"**/*.ts"
,
"**/*.tsx"
],
"exclude"
:
[
"node_modules"
]
}
test/integration/typescript-version-warning/test/index.test.js
0 → 100644
View file @
583b5b9d
/* eslint-env jest */
import
fs
from
'fs-extra'
import
{
join
}
from
'path'
import
{
nextBuild
,
findPort
,
launchApp
,
killApp
}
from
'next-test-utils'
jest
.
setTimeout
(
1000
*
60
*
2
)
const
appDir
=
join
(
__dirname
,
'../app'
)
describe
(
'Minimum TypeScript Warning'
,
()
=>
{
it
(
'should show warning during next build with old version'
,
async
()
=>
{
const
res
=
await
nextBuild
(
appDir
,
[],
{
stderr
:
true
,
stdout
:
true
,
})
expect
(
res
.
stdout
+
res
.
stderr
).
toContain
(
'Minimum recommended TypeScript version is'
)
})
it
(
'should show warning during next dev with old version'
,
async
()
=>
{
let
output
=
''
const
handleOutput
=
(
msg
)
=>
{
output
+=
msg
}
const
app
=
await
launchApp
(
appDir
,
await
findPort
(),
{
onStdout
:
handleOutput
,
onStderr
:
handleOutput
,
})
await
killApp
(
app
)
expect
(
output
).
toContain
(
'Minimum recommended TypeScript version is'
)
})
it
(
'should not show warning during next build with new version'
,
async
()
=>
{
await
fs
.
rename
(
join
(
appDir
,
'node_modules/typescript'
),
join
(
appDir
,
'node_modules/typescript-back'
)
)
const
res
=
await
nextBuild
(
appDir
,
[],
{
stderr
:
true
,
stdout
:
true
,
})
await
fs
.
rename
(
join
(
appDir
,
'node_modules/typescript-back'
),
join
(
appDir
,
'node_modules/typescript'
)
)
expect
(
res
.
stdout
+
res
.
stderr
).
toContain
(
'Minimum recommended TypeScript version is'
)
})
it
(
'should not show warning during next dev with new version'
,
async
()
=>
{
let
output
=
''
const
handleOutput
=
(
msg
)
=>
{
output
+=
msg
}
await
fs
.
rename
(
join
(
appDir
,
'node_modules/typescript'
),
join
(
appDir
,
'node_modules/typescript-back'
)
)
const
app
=
await
launchApp
(
appDir
,
await
findPort
(),
{
onStdout
:
handleOutput
,
onStderr
:
handleOutput
,
})
await
killApp
(
app
)
await
fs
.
rename
(
join
(
appDir
,
'node_modules/typescript-back'
),
join
(
appDir
,
'node_modules/typescript'
)
)
expect
(
output
).
toContain
(
'Minimum recommended TypeScript version is'
)
})
})
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