feat!: add `engines.node` field and node.js version check (#1197)

This commit is contained in:
pooya parsa 2021-10-18 21:31:15 +02:00 committed by GitHub
parent 0b634e19a3
commit d8d10febd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 46 additions and 1 deletions

View File

@ -54,5 +54,8 @@
"unbuild": "^0.5.7",
"vue-router": "next"
},
"packageManager": "yarn@3.0.2"
"packageManager": "yarn@3.0.2",
"engines": {
"node": "^14.18.0 || ^16.11.0"
}
}

View File

@ -41,5 +41,8 @@
"@types/node-fetch": "^3.0.2",
"unbuild": "latest",
"vue-router": "3"
},
"engines": {
"node": "^14.18.0 || ^16.11.0"
}
}

View File

@ -38,5 +38,8 @@
"ufo": "^0.7.9",
"unctx": "^1.0.2",
"untyped": "^0.2.9"
},
"engines": {
"node": "^14.18.0 || ^16.11.0"
}
}

View File

@ -77,5 +77,8 @@
"@types/node-fetch": "^3.0.2",
"@types/serve-static": "^1.13.10",
"unbuild": "latest"
},
"engines": {
"node": "^14.18.0 || ^16.11.0"
}
}

View File

@ -28,6 +28,7 @@
"@types/clear": "^0",
"@types/mri": "^1.1.1",
"@types/rimraf": "^3",
"@types/semver": "^7",
"chokidar": "^3.5.2",
"clear": "^0.1.0",
"clipboardy": "^3.0.0",
@ -48,5 +49,11 @@
"superb": "^4.0.0",
"tiged": "^2.12.0",
"unbuild": "latest"
},
"engines": {
"node": "^14.18.0 || ^16.11.0"
},
"dependencies": {
"semver": "^7.3.5"
}
}

View File

@ -1,6 +1,7 @@
import mri from 'mri'
import { red, cyan } from 'colorette'
import consola from 'consola'
import { checkEngines } from './utils/engines'
import { commands, Command, NuxtCommand } from './commands'
import { showHelp } from './utils/help'
import { showBanner } from './utils/banner'
@ -22,6 +23,9 @@ async function _main () {
command = 'usage'
}
// Check Node.js version in background
setTimeout(() => { checkEngines() }, 1000)
if (command === 'usage') {
console.log(`\nUsage: ${cyan(`npx nuxi ${Object.keys(commands).join('|')} [args]`)}\n`)
process.exit(1)

View File

@ -0,0 +1,11 @@
import { engines } from '../../package.json'
export async function checkEngines () {
const semver = await import('semver').then(r => r.default || r)
const currentNode = process.versions.node
const nodeRange = engines.node
if (!semver.satisfies(process.versions.node, engines.node)) {
console.warn(`Current version of Node.js (\`${currentNode}\`) is unsupported and might cause issues.\n Please upgrade to a compatible version (${nodeRange}).`)
}
}

View File

@ -53,5 +53,8 @@
"@vue/reactivity": "3.2.20",
"@vue/shared": "3.2.20",
"vue": "3.2.20"
},
"engines": {
"node": "^14.18.0 || ^16.11.0"
}
}

View File

@ -33,5 +33,8 @@
"ufo": "^0.7.9",
"vite": "^2.6.9",
"vue": "3.2.20"
},
"engines": {
"node": "^14.18.0 || ^16.11.0"
}
}

View File

@ -64,5 +64,8 @@
"@types/webpack-hot-middleware": "^2.25.5",
"@types/webpack-virtual-modules": "^0",
"unbuild": "latest"
},
"engines": {
"node": "^14.18.0 || ^16.11.0"
}
}

View File

@ -13713,6 +13713,7 @@ fsevents@~2.3.2:
"@types/clear": ^0
"@types/mri": ^1.1.1
"@types/rimraf": ^3
"@types/semver": ^7
chokidar: ^3.5.2
clear: ^0.1.0
clipboardy: ^3.0.0
@ -13731,6 +13732,7 @@ fsevents@~2.3.2:
pkg-types: ^0.2.1
rimraf: ^3.0.2
scule: ^0.2.1
semver: ^7.3.5
superb: ^4.0.0
tiged: ^2.12.0
unbuild: latest