Skip to content

Commit

Permalink
Add a runtime checking for node version.
Browse files Browse the repository at this point in the history
  • Loading branch information
domchen committed Nov 28, 2023
1 parent 3bfd27e commit f1a06bd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "depsync",
"version": "1.3.13",
"version": "1.3.14",
"author": "Dom Chen",
"homepage": "https://github.com/domchen/depsync",
"description": "Automatically synchronize the dependencies of a project by the DEPS configuration file.",
Expand Down
28 changes: 2 additions & 26 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,6 @@ function filterByPlatform(items, hostPlatform) {
return list;
}

function compareVersion(versionA, versionB) {
if (versionA === versionB) {
return 0;
}
let listA = versionA.split(".");
let listB = versionB.split(".");
let length = Math.max(listA.length, listB.length);
for (let i = 0; i < length; i++) {
if (listA.length <= i) {
return -1;
}
let a = parseInt(listA[i]);
if (listB.length <= i) {
return 1;
}
let b = parseInt(listB[i]);
if (a === b) {
continue;
}
return a > b ? 1 : -1;
}
return 0;
}

function parse(configFileName, version, platform) {
if (!fs.existsSync(configFileName)) {
return null;
Expand All @@ -171,15 +147,15 @@ function parse(configFileName, version, platform) {
try {
data = JSON.parse(jsonText);
} catch (e) {
if (jsonText.trimLeft().indexOf("{") === 0) {
if (jsonText.trim().indexOf("{") === 0) {
Utils.error("The DEPS config file is not a valid JSON file: " + configFileName);
}
return null;
}
let projectPath = path.dirname(configFileName);
let config = {};
config.version = data.version ? data.version : "0.0.0";
if (compareVersion(version, config.version) < 0) {
if (Utils.compareVersion(version, config.version) < 0) {
Utils.error("The DEPS config requires a higher version of depsync tool: " + configFileName);
Utils.error("Requires version: " + config.version);
Utils.error("Current version: " + version);
Expand Down
5 changes: 5 additions & 0 deletions src/Program.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ function makePadding(paddingLength) {


function run(args) {
let version = process.versions.node;
if (Utils.compareVersion(version, "14.14.0") < 0) {
Utils.error("Node.js version must be greater than or equal to 14.14.0\n");
process.exit(1);
}
let commandOptions = CommandLine.parse(args);
if (commandOptions.errors.length > 0) {
Utils.error(commandOptions.errors.join("\n") + "\n");
Expand Down
25 changes: 25 additions & 0 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ function execSafe(cmd, dir) {
}
}

function compareVersion(versionA, versionB) {
if (versionA === versionB) {
return 0;
}
let listA = versionA.split(".");
let listB = versionB.split(".");
let length = Math.max(listA.length, listB.length);
for (let i = 0; i < length; i++) {
if (listA.length <= i) {
return -1;
}
let a = parseInt(listA[i]);
if (listB.length <= i) {
return 1;
}
let b = parseInt(listB[i]);
if (a === b) {
continue;
}
return a > b ? 1 : -1;
}
return 0;
}

function addLineBreaker() {
hasLineBreaker = true;
}
Expand All @@ -237,4 +261,5 @@ exports.exec = exec;
exports.execSafe = execSafe;
exports.log = log;
exports.error = error;
exports.compareVersion = compareVersion;
exports.addLineBreaker = addLineBreaker;

0 comments on commit f1a06bd

Please sign in to comment.