Automatically detect Pijul executable under .cargo directory
[?]
Jan 25, 2021, 8:29 PM
Q5X2TMMI6PMBU3OKWC4EQAYGBOXYLFY3QQ2B7EHY5ASJHK5AUKXACDependencies
- [2]
B4SKYP3YAdd repository model and add steps to initialize it - [3]
4PN3R2LYFix lint/style issues - [4]
WHFIIX4YImprove documentation and add Pijul installation configuration - [5]
TKKT6D4CAdd failure loop to installation selection - [*]
NCBEWRYEInitialize Repository
Change contents
- edit in src/extension.ts at line 3
import * as fs from 'fs';import * as os from 'os';import * as path from 'path'; - replacement in src/extension.ts at line 26
// We need a path to proceed, ask the user to select one or stop activation// First, check if Pijul can be found in the .cargo directorytry {path = await searchPijulCargoDirectory(outputChannel);if (path) {return await checkPijulExecutable(path);}} catch (_) {path = undefined;}// TODO: Search in nix installation location// Since we need a path to proceed, ask the user to select one or stop activation if// Pijul wasn't found in the .cargo directory. - edit in src/extension.ts at line 80
}}return await checkPijulExecutable(path);}/*** Search for a pijul executable under the user's .cargo directory* @param outputChannel The output channel where logging information should be sent*/async function searchPijulCargoDirectory (outputChannel: vscode.OutputChannel): Promise<string | undefined> {outputChannel.appendLine('Looking for Pijul installation in .cargo...');const cargoBin = path.join(os.homedir(), '.cargo', 'bin');// I can't find an async version of this functionif (fs.existsSync(cargoBin)) {let cargoPijul = path.join(cargoBin, 'pijul');if (fs.existsSync(cargoPijul)) {return cargoPijul;}// Instead of checking if we're on windows or unix, just check if either existscargoPijul = cargoPijul + '.exe';if (fs.existsSync(cargoPijul)) {return cargoPijul; - edit in src/extension.ts at line 105
return undefined;} - edit in src/extension.ts at line 109
/*** Check if a Pijul executable is compatible with the extension by running `pijul --version`* @param path The path of the Pijul executable that will be checked*/async function checkPijulExecutable (path: string): Promise<IPijul> { - replacement in src/extension.ts at line 115
const pathDefined = path ?? 'pijul';const child = cp.spawn(pathDefined, ['--version']);const child = cp.spawn(path, ['--version']); - replacement in src/extension.ts at line 120
child.on('error', () => reject(new Error(`Error checking version at ${pathDefined}`)));child.on('error', () => reject(new Error(`Error checking version at ${path}`))); - replacement in src/extension.ts at line 125
reject(new Error(`Error checking version at ${pathDefined}`));reject(new Error(`Error checking version at ${path}`)); - replacement in src/extension.ts at line 127
resolve({ path: pathDefined, version: tokens[1] });resolve({ path: path, version: tokens[1] });