Skip to content

Commit ad1e7d0

Browse files
jfcherngskovhus
authored andcommitted
refactor: use "which" package to find binary in a cross-platform way
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
1 parent 1229989 commit ad1e7d0

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

server/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"urijs": "^1.19.11",
2727
"vscode-languageserver": "^6.1.1",
2828
"vscode-languageserver-textdocument": "^1.0.1",
29-
"web-tree-sitter": "^0.20.5"
29+
"web-tree-sitter": "^0.20.5",
30+
"which": "^2.0.2"
3031
},
3132
"scripts": {
3233
"prepublishOnly": "cd ../ && yarn run compile"
@@ -35,6 +36,7 @@
3536
"@types/fuzzy-search": "2.1.2",
3637
"@types/glob": "8.0.0",
3738
"@types/turndown": "5.0.1",
38-
"@types/urijs": "1.19.19"
39+
"@types/urijs": "1.19.19",
40+
"@types/which": "2.0.1"
3941
}
4042
}

server/src/linter.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { spawn } from 'child_process'
22
import * as LSP from 'vscode-languageserver'
3+
import which = require('which')
34

45
import * as config from './config'
5-
import { execShellScript } from './util/sh'
66

77
function formatMessage(comment: ShellcheckComment): string {
88
return (comment.code ? `SC${comment.code}: ` : '') + comment.message
@@ -14,18 +14,7 @@ type LinterOptions = {
1414
}
1515

1616
export async function getLinterExecutablePath(): Promise<string | null> {
17-
const pathFromConfig = config.getShellcheckPath()
18-
19-
if (pathFromConfig) {
20-
return pathFromConfig
21-
}
22-
23-
try {
24-
const path = (await execShellScript('which shellcheck')).trim()
25-
return path === '' ? null : path
26-
} catch (e) {
27-
return null
28-
}
17+
return config.getShellcheckPath() || (await which('shellcheck'))
2918
}
3019

3120
export class Linter {

server/yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
resolved "https://registry.yarnpkg.com/@types/urijs/-/urijs-1.19.19.tgz#2789369799907fc11e2bc6e3a00f6478c2281b95"
4444
integrity sha512-FDJNkyhmKLw7uEvTxx5tSXfPeQpO0iy73Ry+PmYZJvQy0QIWX8a7kJ4kLWRf+EbTPJEPDSgPXHaM7pzr5lmvCg==
4545

46+
"@types/which@2.0.1":
47+
version "2.0.1"
48+
resolved "https://registry.yarnpkg.com/@types/which/-/which-2.0.1.tgz#27ecd67f915b7c3d6ba552135bb1eecd66e63501"
49+
integrity sha512-Jjakcv8Roqtio6w1gr0D7y6twbhx6gGgFGF5BLwajPpnOIOxFkakFhCq+LmyyeAz7BX6ULrjBOxdKaCDy+4+dQ==
50+
4651
asynckit@^0.4.0:
4752
version "0.4.0"
4853
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@@ -121,6 +126,11 @@ inherits@2:
121126
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
122127
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
123128

129+
isexe@^2.0.0:
130+
version "2.0.0"
131+
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
132+
integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==
133+
124134
mime-db@1.52.0:
125135
version "1.52.0"
126136
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
@@ -224,6 +234,13 @@ whatwg-url@^5.0.0:
224234
tr46 "~0.0.3"
225235
webidl-conversions "^3.0.0"
226236

237+
which@^2.0.2:
238+
version "2.0.2"
239+
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
240+
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
241+
dependencies:
242+
isexe "^2.0.0"
243+
227244
wrappy@1:
228245
version "1.0.2"
229246
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"

0 commit comments

Comments
 (0)