UNPKG

sonarqube-scanner

Version:
47 lines (46 loc) 1.96 kB
"use strict"; /* * sonar-scanner-npm * Copyright (C) SonarSource Sàrl * mailto:info AT sonarsource DOT com * * You can redistribute and/or modify this program under the terms of * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the Sonar Source-Available License for more details. * * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ Object.defineProperty(exports, "__esModule", { value: true }); exports.locateExecutableFromPath = locateExecutableFromPath; const constants_1 = require("./constants"); const deps_1 = require("./deps"); const logging_1 = require("./logging"); const platform_1 = require("./platform"); /** * Verify that a given executable is accessible from the PATH. * We use where.exe on Windows to check for the existence of the command to avoid * search path vulnerabilities. Otherwise, Windows would search the current directory * for the executable. */ async function locateExecutableFromPath(executable) { const { execAsync } = (0, deps_1.getDeps)(); try { (0, logging_1.log)(logging_1.LogLevel.INFO, `Trying to find ${executable}`); const child = await execAsync(`${(0, platform_1.isWindows)() ? constants_1.WINDOWS_WHERE_EXE_PATH : 'which'} ${executable}`); const stdout = child.stdout?.trim(); if (stdout.length) { return stdout; } (0, logging_1.log)(logging_1.LogLevel.INFO, 'Local install of SonarScanner CLI found.'); return null; } catch (error) { (0, logging_1.log)(logging_1.LogLevel.INFO, `Local install of SonarScanner CLI (${executable}) not found`); return null; } }