Skip to content

Commit f759fae

Browse files
committed
fix: always use phnode if system node is lower version
1 parent 98c050a commit f759fae

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src-node/ESLint/service.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,29 @@ function sendToESLintProcess(jsObj) {
2727
}
2828
}
2929

30-
// Function to check if Node.js is installed
30+
function isVersionGreater(versionA, versionB) {
31+
try{
32+
const partsA = versionA.split('.').map(Number);
33+
const partsB = versionB.split('.').map(Number);
34+
35+
for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
36+
const partA = partsA[i] || 0;
37+
const partB = partsB[i] || 0;
38+
39+
if (partA > partB) {
40+
return true;
41+
} else if (partA < partB) {
42+
return false;
43+
}
44+
}
45+
} catch (e) {
46+
console.error("error comparing nodejs versions: ", versionA, versionB, e);
47+
}
48+
return false;
49+
}
50+
51+
// We always use phnode if the system node is lower than phnode version. our supported eslint versions 7-latest runs
52+
// on phnode 20. If user has the latest node, we will use that for future proofing.
3153
function getNodeJSBinPath() {
3254
return new Promise((resolve) => {
3355
if(nodeBinPath){
@@ -39,8 +61,16 @@ function getNodeJSBinPath() {
3961
console.error('System Node.js is not installed, using PHNode for ESLint');
4062
nodeBinPath = process.argv[0]; // phnode itself
4163
} else {
42-
console.log(`Node.js is installed. Version: ${stdout.trim()}`);
43-
nodeBinPath = "node"; // system node
64+
const systemNodeVersion = stdout.trim().substring(1); // remove the 'v' prefix
65+
const currentNodeVersion = process.version.substring(1); // remove the 'v' prefix
66+
67+
if (isVersionGreater(systemNodeVersion, currentNodeVersion)) {
68+
console.log(`System Node.js (${systemNodeVersion}) is newer than phnode(${currentNodeVersion}). Using system Node.js.`);
69+
nodeBinPath = "node"; // system node
70+
} else {
71+
console.log(`phnode (${currentNodeVersion}) is same/newer than system nodejs. using phnode.`);
72+
nodeBinPath = process.argv[0]; // current node process path
73+
}
4474
}
4575
resolve(nodeBinPath);
4676
});
@@ -172,4 +202,6 @@ async function lintFile(text, fullFilePath, projectFullPath) {
172202
});
173203
}
174204

205+
getNodeJSBinPath();
206+
175207
exports.lintFile = lintFile;

src/command/KeyBindingManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ define(function (require, exports, module) {
15551555
} else {
15561556
if(!_isReservedShortcuts(shortcut)) {
15571557
userKeyMap.overrides[shortcut] = commandID;
1558-
}
1558+
} // else we should show an error message here, but not doing it for now.
15591559
}
15601560
const textContent = JSON.stringify(userKeyMap, null, 4);
15611561
await deferredToPromise(FileUtils.writeText(file, textContent, true));

0 commit comments

Comments
 (0)