Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 88a2d81

Browse files
refactor: simplify NodePathTester
1 parent 110e920 commit 88a2d81

File tree

1 file changed

+10
-43
lines changed

1 file changed

+10
-43
lines changed

lib/node-path-tester.js

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,15 @@ import { exec, execSync } from 'child_process';
44
import which from 'which';
55

66
const NodePathTester = {
7-
_timeout: null,
8-
_bin: null,
97
_knownGoodValues: new Map(),
108

11-
schedule (bin) {
12-
// Assume it's valid until we know otherwise.
13-
this.valid = true;
14-
if (this._timeout !== null) {
15-
clearTimeout(this._timeout);
16-
this._timeout = null;
17-
}
18-
19-
// When an Atom window loads, we get the main config first; then any config
20-
// overrides from project-config or atomic-management a couple seconds
21-
// later; then any further overrides from `.linter-eslint` files a couple
22-
// seconds after that.
23-
//
24-
// So we wait a few seconds before we try this version of Node, lest we
25-
// complain about a version that isn't even the correct setting for this
26-
// project.
27-
return new Promise((resolve, reject) => {
28-
this._timeout = setTimeout(() => {
29-
this.test(bin).then(resolve).catch(reject);
30-
}, 3000);
31-
});
32-
},
33-
34-
// Tries to discern the absolute path to the user's `node` binary. TODO:
35-
// Handle relative paths, not just the bare value `node`.
9+
// Tries to discern the absolute path to the user's `node` binary.
10+
// TODO: Handle relative paths, not just the bare value `node`.
3611
resolve (bin) {
37-
if (bin.startsWith('/') && existsSync(bin) ) { return Promise.resolve(bin); }
38-
return new Promise((resolve, reject) => {
39-
which(bin, (err, resolvedPath) => {
40-
if (err) {
41-
reject(err);
42-
} else {
43-
resolve(resolvedPath);
44-
}
45-
});
46-
});
12+
if (bin.startsWith('/') && existsSync(bin) ) {
13+
return Promise.resolve(bin);
14+
}
15+
return which(bin);
4716
},
4817

4918
testSync (bin) {
@@ -59,20 +28,18 @@ const NodePathTester = {
5928
},
6029

6130
test (bin) {
62-
console.log(`actually testing ${bin}`);
6331
if (this._knownGoodValues.has(bin)) {
64-
return Promise.resolve(
65-
this._knownGoodValues.get(bin)
66-
);
32+
return Promise.resolve(this._knownGoodValues.get(bin));
6733
}
34+
// Assume it's valid until we know otherwise.
35+
this.valid = true;
6836
return new Promise((resolve, reject) => {
6937
exec(`${bin} --version`, (err, stdout) => {
7038
if (err) {
71-
console.log(`nope`);
39+
console.log('error!');
7240
this.valid = false;
7341
reject(err);
7442
} else {
75-
7643
this._knownGoodValues.set(bin, stdout);
7744
resolve(stdout);
7845
}

0 commit comments

Comments
 (0)