UNPKG

sonarqube-scanner

Version:
71 lines (70 loc) 2.41 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.getArch = getArch; exports.isLinux = isLinux; exports.isWindows = isWindows; exports.isMac = isMac; exports.getSupportedOS = getSupportedOS; const deps_1 = require("./deps"); const logging_1 = require("./logging"); function getArch() { const { process } = (0, deps_1.getDeps)(); return process.arch; } function isLinux() { const { process } = (0, deps_1.getDeps)(); return process.platform === 'linux'; } function isWindows() { const { process } = (0, deps_1.getDeps)(); return process.platform === 'win32'; } function isMac() { const { process } = (0, deps_1.getDeps)(); return process.platform === 'darwin'; } /** * @see https://github.com/microsoft/vscode/blob/64874113ad3c59e8d045f75dc2ef9d33d13f3a03/src/vs/platform/extensionManagement/common/extensionManagementUtil.ts#L171C1-L190C1 */ function isAlpineLinux() { const { fs } = (0, deps_1.getDeps)(); if (!isLinux()) { return false; } let content; try { const fileContent = fs.readFileSync('/etc/os-release'); content = fileContent.toString(); } catch (error) { try { const fileContent = fs.readFileSync('/usr/lib/os-release'); content = fileContent.toString(); } catch (error) { (0, logging_1.log)(logging_1.LogLevel.WARN, 'Failed to read /etc/os-release or /usr/lib/os-release'); } } const match = /^ID=([^\r\n]*)/m.exec(content ?? ''); return !!content && (match ? match[1] === 'alpine' : false); } function getSupportedOS() { const { process } = (0, deps_1.getDeps)(); return isAlpineLinux() ? 'alpine' : process.platform; }