Skip to content

Validate Next.js version #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions helpers/validateNextUsage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { lt: ltVersion, gte: gteVersion } = require('semver')
const { yellowBright } = require('chalk')

// Ensure Next.js is available.
// We use `peerDependencies` instead of `dependencies` so that users can choose
// the Next.js version. However, this requires them to install "next" in their
Expand All @@ -8,8 +11,24 @@ const validateNextUsage = function (failBuild) {
'This site does not seem to be using Next.js. Please run "npm install next" or "yarn next" in the repository.',
)
}

// Old Next.js versions are not supported
const { version } = require('next/package.json')
if (ltVersion(version, MIN_VERSION)) {
return failBuild(`Please upgrade to Next.js ${MIN_VERSION} or later`)
}

// Recent Next.js versions are sometimes unstable and we might not officially
// support them yet. However, they might still work for some users, so we
// only print a warning
if (gteVersion(version, MIN_EXPERIMENTAL_VERSION)) {
console.log(yellowBright(`** Warning: support for Next.js >=${MIN_EXPERIMENTAL_VERSION} is experimental **`))
}
}

const MIN_VERSION = '9.5.3'
const MIN_EXPERIMENTAL_VERSION = '10.0.0'

const hasPackage = function (packageName) {
try {
require(packageName)
Expand Down
142 changes: 127 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
},
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
"dependencies": {
"chalk": "^4.1.0",
"cpx": "^1.5.0",
"find-up": "^4.1.0",
"make-dir": "^3.1.0",
"next-on-netlify": "^2.6.0"
"next-on-netlify": "^2.6.0",
"semver": "^7.3.2"
},
"devDependencies": {
"@netlify/eslint-config-node": "^0.3.0",
Expand Down