mirror of
https://github.com/strapi/strapi.git
synced 2025-11-07 05:38:13 +00:00
use supported versions from generated package.json
This commit is contained in:
parent
826e3ecf34
commit
ef35dbb2f7
@ -1,26 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const { red, green, bold } = require('chalk');
|
||||
const { red, green, bold, yellow } = require('chalk');
|
||||
const semver = require('semver');
|
||||
const packageJSON = require('../resources/json/common/package.json');
|
||||
|
||||
module.exports = function checkBeforeInstall() {
|
||||
const currentNodeVersion = process.versions.node;
|
||||
const minNodeVersion = '14.19.1'; // greater than or equal to this
|
||||
const maxNodeVersion = '17.0.0'; // less than this
|
||||
const { engines } = packageJSON({ strapiDependencies: [] });
|
||||
|
||||
if (
|
||||
!semver.gte(currentNodeVersion, minNodeVersion) ||
|
||||
!semver.lt(currentNodeVersion, maxNodeVersion)
|
||||
) {
|
||||
console.error(red(`You are running ${bold(`node ${currentNodeVersion}`)}`));
|
||||
console.error(
|
||||
`Strapi requires ${bold(green(`node >=${minNodeVersion} and <${maxNodeVersion}`))}`
|
||||
);
|
||||
// error if the node version isn't supported
|
||||
if (!semver.satisfies(currentNodeVersion, engines.node)) {
|
||||
console.error(red(`You are running ${bold(`Node.js ${currentNodeVersion}`)}`));
|
||||
console.error(`Strapi requires ${bold(green(`Node.js ${engines.node}`))}`);
|
||||
console.error('Please make sure to use the right version of Node.');
|
||||
}
|
||||
|
||||
// only exit on lower version; higher version is allowed to proceed with only the warning
|
||||
if (!semver.gte(currentNodeVersion, minNodeVersion)) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// warn if not using a LTS version
|
||||
else if (!semver.satisfies(currentNodeVersion, '14.x.x || 16.x.x || 18.x.x || 20.x.x')) {
|
||||
console.warn(yellow(`You are running ${bold(`Node.js ${currentNodeVersion}`)}`));
|
||||
console.warn(
|
||||
`Strapi only supports ${bold(
|
||||
green('LTS versions of Node.js')
|
||||
)}, other versions may not be compatible.`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user