|
16 | 16 | * SPDX-License-Identifier: Apache-2.0 |
17 | 17 | ***********************************************************************/ |
18 | 18 |
|
19 | | -import { existsSync } from 'node:fs'; |
20 | | -import { homedir } from 'node:os'; |
21 | | -import { join, resolve } from 'node:path'; |
22 | | - |
23 | | -const localBinDir = '/usr/local/bin'; |
24 | | - |
25 | | -/** |
26 | | - * Calculate the system path of the binary |
27 | | - * @returns |
28 | | - */ |
29 | | -export function getSystemBinaryPath(binaryName: string): string { |
30 | | - switch (process.platform) { |
31 | | - case 'win32': |
32 | | - return join( |
33 | | - homedir(), |
34 | | - 'AppData', |
35 | | - 'Local', |
36 | | - 'Microsoft', |
37 | | - 'WindowsApps', |
38 | | - binaryName.endsWith('.exe') ? binaryName : `${binaryName}.exe`, |
39 | | - ); |
40 | | - case 'darwin': |
41 | | - case 'linux': |
42 | | - return join(localBinDir, binaryName); |
43 | | - default: |
44 | | - throw new Error(`unsupported platform: ${process.platform}.`); |
45 | | - } |
46 | | -} |
47 | | - |
48 | | -/** |
49 | | - * Given an executable name, it will find where it is installed on the system. |
50 | | - * It first try to search it in the system-wide folder, then in the extension storage |
51 | | - * @param executable |
52 | | - */ |
53 | | -export async function whereBinary(storagePath: string, binaryName: string): Promise<string> { |
54 | | - const macadamSystemWidePath = getSystemBinaryPath(binaryName); |
55 | | - if (existsSync(macadamSystemWidePath)) { |
56 | | - return macadamSystemWidePath; |
57 | | - } |
58 | | - |
59 | | - const macadamStoragePath = resolve(storagePath, 'bin', binaryName); |
60 | | - if (existsSync(macadamStoragePath)) { |
61 | | - return macadamStoragePath; |
62 | | - } |
63 | | - |
64 | | - // if it's not installed either in the extension storage path or system wide throw an error |
65 | | - throw new Error('no macadam binary found'); |
66 | | -} |
67 | | - |
68 | 19 | export function getErrorMessage(err: unknown): string { |
69 | 20 | if (err && typeof err === 'object' && 'message' in err) { |
70 | 21 | return String(err.message); |
|
0 commit comments