Automatically detect Pijul executable under .cargo directory

[?]
Jan 25, 2021, 8:29 PM
Q5X2TMMI6PMBU3OKWC4EQAYGBOXYLFY3QQ2B7EHY5ASJHK5AUKXAC

Dependencies

  • [2] B4SKYP3Y Add repository model and add steps to initialize it
  • [3] 4PN3R2LY Fix lint/style issues
  • [4] WHFIIX4Y Improve documentation and add Pijul installation configuration
  • [5] TKKT6D4C Add failure loop to installation selection
  • [*] NCBEWRYE Initialize Repository

Change contents

  • edit in src/extension.ts at line 3
    [3.37]
    [3.37]
    import * as fs from 'fs';
    import * as os from 'os';
    import * as path from 'path';
  • replacement in src/extension.ts at line 26
    [2.1758][3.225:305](),[3.186][3.225:305](),[3.225][3.225:305]()
    // We need a path to proceed, ask the user to select one or stop activation
    [2.1758]
    [3.187]
    // First, check if Pijul can be found in the .cargo directory
    try {
    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
    [3.1069]
    [3.1826]
    }
    }
    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 function
    if (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 exists
    cargoPijul = cargoPijul + '.exe';
    if (fs.existsSync(cargoPijul)) {
    return cargoPijul;
  • edit in src/extension.ts at line 105
    [3.1836]
    [3.1836]
    return undefined;
    }
  • edit in src/extension.ts at line 109
    [3.1837]
    [3.1070]
    /**
    * 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
    [3.1128][3.1128:1225]()
    const pathDefined = path ?? 'pijul';
    const child = cp.spawn(pathDefined, ['--version']);
    [3.1128]
    [3.641]
    const child = cp.spawn(path, ['--version']);
  • replacement in src/extension.ts at line 120
    [3.1289][3.1289:1381]()
    child.on('error', () => reject(new Error(`Error checking version at ${pathDefined}`)));
    [3.1289]
    [3.1381]
    child.on('error', () => reject(new Error(`Error checking version at ${path}`)));
  • replacement in src/extension.ts at line 125
    [2.1802][3.1545:1616](),[3.1545][3.1545:1616]()
    reject(new Error(`Error checking version at ${pathDefined}`));
    [2.1802]
    [3.935]
    reject(new Error(`Error checking version at ${path}`));
  • replacement in src/extension.ts at line 127
    [3.950][3.1617:1677]()
    resolve({ path: pathDefined, version: tokens[1] });
    [3.950]
    [3.1061]
    resolve({ path: path, version: tokens[1] });