2021-01-21 21:06:52 +00:00
'use strict' ;
2018-07-27 01:45:06 +02:00
/ * *
* Checks related to Node runtime version
* /
/ *
2018-08-22 00:12:53 +02:00
* 2018 - muxator
*
2018-07-27 01:45:06 +02:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS-IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* /
2019-02-08 19:10:49 +01:00
const semver = require ( 'semver' ) ;
2018-07-27 01:45:06 +02:00
/ * *
* Quits if Etherpad is not running on a given minimum Node version
*
* @ param { String } minNodeVersion Minimum required Node version
* /
2021-01-21 21:06:52 +00:00
exports . enforceMinNodeVersion = ( minNodeVersion ) => {
2018-07-27 01:45:06 +02:00
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 ) ) {
2020-11-23 13:24:19 -05:00
console . error ( ` Running Etherpad on Node ${ currentNodeVersion } is not supported. Please upgrade at least to Node ${ minNodeVersion } ` ) ;
2019-02-19 00:46:37 +01:00
process . exit ( 1 ) ;
2018-07-27 01:45:06 +02:00
}
2019-02-19 00:46:37 +01:00
2020-11-23 13:24:19 -05:00
console . debug ( ` Running on Node ${ currentNodeVersion } (minimum required Node version: ${ minNodeVersion } ) ` ) ;
2018-07-27 01:45:06 +02:00
} ;
2018-07-27 01:51:28 +02:00
/ * *
* Prints a warning if running on a supported but deprecated Node version
*
2021-01-21 21:06:52 +00:00
* @ 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
2018-07-27 01:51:28 +02:00
* /
2021-01-21 21:06:52 +00:00
exports . checkDeprecationStatus = ( lowestNonDeprecatedNodeVersion , epRemovalVersion ) => {
2018-07-27 01:51:28 +02:00
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 } ` ) ;
}
} ;