NodeVersion.js: do not use callbacks, simplify calling style in server.js

pull/3558/head
muxator 2019-02-19 00:46:37 +01:00
parent 36addd2205
commit 9d9b7c9faf
2 changed files with 16 additions and 18 deletions

View File

@ -28,6 +28,17 @@ var log4js = require('log4js')
log4js.replaceConsole();
/*
* early check for version compatibility before calling
* any modules that require newer versions of NodeJS
*/
NodeVersion.enforceMinNodeVersion('6.9.0');
/*
* Since Etherpad 1.8.0, at least NodeJS 8.9.0 will be required
*/
NodeVersion.checkDeprecationStatus('8.9.0', '1.8.0');
/*
* start up stats counting system
*/
@ -43,16 +54,6 @@ var settings
var npm = require("npm/lib/npm.js");
async.waterfall([
function(callback)
{
NodeVersion.enforceMinNodeVersion('6.9.0', callback);
},
function(callback)
{
NodeVersion.checkDeprecationStatus('8.9.0', '1.8.0', callback);
},
// load npm
function(callback) {
npm.load({}, function(er) {

View File

@ -24,19 +24,18 @@ const semver = require('semver');
* Quits if Etherpad is not running on a given minimum Node version
*
* @param {String} minNodeVersion Minimum required Node version
* @param {Function} callback Standard callback function
*/
exports.enforceMinNodeVersion = function(minNodeVersion, callback) {
exports.enforceMinNodeVersion = function(minNodeVersion) {
const currentNodeVersion = process.version;
// we cannot use template literals, since we still do not know if we are
// running under Node >= 4.0
if (semver.lt(currentNodeVersion, minNodeVersion)) {
console.error('Running Etherpad on Node ' + currentNodeVersion + ' is not supported. Please upgrade at least to Node ' + minNodeVersion);
} else {
console.debug('Running on Node ' + currentNodeVersion + ' (minimum required Node version: ' + minNodeVersion + ')');
callback();
process.exit(1);
}
console.debug('Running on Node ' + currentNodeVersion + ' (minimum required Node version: ' + minNodeVersion + ')');
};
/**
@ -45,12 +44,10 @@ exports.enforceMinNodeVersion = function(minNodeVersion, callback) {
* @param {String} lowestNonDeprecatedNodeVersion all Node version less than this one are deprecated
* @param {Function} epRemovalVersion Etherpad version that will remove support for deprecated Node releases
*/
exports.checkDeprecationStatus = function(lowestNonDeprecatedNodeVersion, epRemovalVersion, callback) {
exports.checkDeprecationStatus = function(lowestNonDeprecatedNodeVersion, epRemovalVersion) {
const currentNodeVersion = process.version;
if (semver.lt(currentNodeVersion, lowestNonDeprecatedNodeVersion)) {
console.warn(`Support for Node ${currentNodeVersion} will be removed in Etherpad ${epRemovalVersion}. Please consider updating at least to Node ${lowestNonDeprecatedNodeVersion}`);
}
callback();
};