Skip to content

Commit

Permalink
NodeVersion.js: do not use callbacks, simplify calling style in serve…
Browse files Browse the repository at this point in the history
…r.js
  • Loading branch information
muxator committed Feb 18, 2019
1 parent 36addd2 commit 9d9b7c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
21 changes: 11 additions & 10 deletions src/node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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) {
Expand Down
13 changes: 5 additions & 8 deletions src/node/utils/NodeVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ')');
};

/**
Expand All @@ -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();
};

0 comments on commit 9d9b7c9

Please sign in to comment.