-
Notifications
You must be signed in to change notification settings - Fork 96
/
check-node.js
30 lines (23 loc) · 1 KB
/
check-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2015-2024 MariaDB Corporation Ab
'use strict';
const hasMinVersion = function (nodeVersionStr, connectorRequirement) {
const versNode = nodeVersionStr.split('.');
const versReq = connectorRequirement.split('.');
const majorNode = Number(versNode[0]);
const majorReq = Number(versReq[0]);
if (majorNode > majorReq) return true;
if (majorNode < majorReq) return false;
if (versReq.length === 1) return true;
const minorNode = Number(versNode[1]);
const minorReq = Number(versReq[1]);
return minorNode >= minorReq;
};
module.exports.hasMinVersion = hasMinVersion;
const requirement = require('./package.json').engines.node;
const connectorRequirement = requirement.replace('>=', '').trim();
const currentNodeVersion = process.version.replace('v', '');
if (!hasMinVersion(currentNodeVersion, connectorRequirement)) {
console.error(`please upgrade node: mariadb requires at least version ${connectorRequirement}`);
process.exit(1);
}