Skip to content

Commit 3428aaf

Browse files
authored
Merge pull request #46 from netlify/feat/next-version-check
Validate Next.js version
2 parents 97cc69a + 97a983d commit 3428aaf

File tree

3 files changed

+149
-16
lines changed

3 files changed

+149
-16
lines changed

helpers/validateNextUsage.js

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const { lt: ltVersion, gte: gteVersion } = require('semver')
2+
const { yellowBright } = require('chalk')
3+
14
// Ensure Next.js is available.
25
// We use `peerDependencies` instead of `dependencies` so that users can choose
36
// the Next.js version. However, this requires them to install "next" in their
@@ -8,8 +11,24 @@ const validateNextUsage = function (failBuild) {
811
'This site does not seem to be using Next.js. Please run "npm install next" or "yarn next" in the repository.',
912
)
1013
}
14+
15+
// Old Next.js versions are not supported
16+
const { version } = require('next/package.json')
17+
if (ltVersion(version, MIN_VERSION)) {
18+
return failBuild(`Please upgrade to Next.js ${MIN_VERSION} or later`)
19+
}
20+
21+
// Recent Next.js versions are sometimes unstable and we might not officially
22+
// support them yet. However, they might still work for some users, so we
23+
// only print a warning
24+
if (gteVersion(version, MIN_EXPERIMENTAL_VERSION)) {
25+
console.log(yellowBright(`** Warning: support for Next.js >=${MIN_EXPERIMENTAL_VERSION} is experimental **`))
26+
}
1127
}
1228

29+
const MIN_VERSION = '9.5.3'
30+
const MIN_EXPERIMENTAL_VERSION = '10.0.0'
31+
1332
const hasPackage = function (packageName) {
1433
try {
1534
require(packageName)

package-lock.json

+127-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
},
2525
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
2626
"dependencies": {
27+
"chalk": "^4.1.0",
2728
"cpx": "^1.5.0",
2829
"find-up": "^4.1.0",
2930
"make-dir": "^3.1.0",
30-
"next-on-netlify": "^2.6.0"
31+
"next-on-netlify": "^2.6.0",
32+
"semver": "^7.3.2"
3133
},
3234
"devDependencies": {
3335
"@netlify/eslint-config-node": "^0.3.0",

0 commit comments

Comments
 (0)