Skip to content

Commit f1a06bd

Browse files
committed
Add a runtime checking for node version.
1 parent 3bfd27e commit f1a06bd

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "depsync",
3-
"version": "1.3.13",
3+
"version": "1.3.14",
44
"author": "Dom Chen",
55
"homepage": "https://github.com/domchen/depsync",
66
"description": "Automatically synchronize the dependencies of a project by the DEPS configuration file.",

src/Config.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,6 @@ function filterByPlatform(items, hostPlatform) {
138138
return list;
139139
}
140140

141-
function compareVersion(versionA, versionB) {
142-
if (versionA === versionB) {
143-
return 0;
144-
}
145-
let listA = versionA.split(".");
146-
let listB = versionB.split(".");
147-
let length = Math.max(listA.length, listB.length);
148-
for (let i = 0; i < length; i++) {
149-
if (listA.length <= i) {
150-
return -1;
151-
}
152-
let a = parseInt(listA[i]);
153-
if (listB.length <= i) {
154-
return 1;
155-
}
156-
let b = parseInt(listB[i]);
157-
if (a === b) {
158-
continue;
159-
}
160-
return a > b ? 1 : -1;
161-
}
162-
return 0;
163-
}
164-
165141
function parse(configFileName, version, platform) {
166142
if (!fs.existsSync(configFileName)) {
167143
return null;
@@ -171,15 +147,15 @@ function parse(configFileName, version, platform) {
171147
try {
172148
data = JSON.parse(jsonText);
173149
} catch (e) {
174-
if (jsonText.trimLeft().indexOf("{") === 0) {
150+
if (jsonText.trim().indexOf("{") === 0) {
175151
Utils.error("The DEPS config file is not a valid JSON file: " + configFileName);
176152
}
177153
return null;
178154
}
179155
let projectPath = path.dirname(configFileName);
180156
let config = {};
181157
config.version = data.version ? data.version : "0.0.0";
182-
if (compareVersion(version, config.version) < 0) {
158+
if (Utils.compareVersion(version, config.version) < 0) {
183159
Utils.error("The DEPS config requires a higher version of depsync tool: " + configFileName);
184160
Utils.error("Requires version: " + config.version);
185161
Utils.error("Current version: " + version);

src/Program.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ function makePadding(paddingLength) {
6363

6464

6565
function run(args) {
66+
let version = process.versions.node;
67+
if (Utils.compareVersion(version, "14.14.0") < 0) {
68+
Utils.error("Node.js version must be greater than or equal to 14.14.0\n");
69+
process.exit(1);
70+
}
6671
let commandOptions = CommandLine.parse(args);
6772
if (commandOptions.errors.length > 0) {
6873
Utils.error(commandOptions.errors.join("\n") + "\n");

src/Utils.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,30 @@ function execSafe(cmd, dir) {
223223
}
224224
}
225225

226+
function compareVersion(versionA, versionB) {
227+
if (versionA === versionB) {
228+
return 0;
229+
}
230+
let listA = versionA.split(".");
231+
let listB = versionB.split(".");
232+
let length = Math.max(listA.length, listB.length);
233+
for (let i = 0; i < length; i++) {
234+
if (listA.length <= i) {
235+
return -1;
236+
}
237+
let a = parseInt(listA[i]);
238+
if (listB.length <= i) {
239+
return 1;
240+
}
241+
let b = parseInt(listB[i]);
242+
if (a === b) {
243+
continue;
244+
}
245+
return a > b ? 1 : -1;
246+
}
247+
return 0;
248+
}
249+
226250
function addLineBreaker() {
227251
hasLineBreaker = true;
228252
}
@@ -237,4 +261,5 @@ exports.exec = exec;
237261
exports.execSafe = execSafe;
238262
exports.log = log;
239263
exports.error = error;
264+
exports.compareVersion = compareVersion;
240265
exports.addLineBreaker = addLineBreaker;

0 commit comments

Comments
 (0)