@sonar/scan
Version:
SonarQube/SonarCloud Scanner for the JavaScript world
72 lines (71 loc) • 2.62 kB
JavaScript
;
/*
* sonar-scanner-npm
* Copyright (C) 2022-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSupportedOS = exports.isMac = exports.isWindows = exports.isLinux = exports.getArch = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const logging_1 = require("./logging");
function getArch() {
return process.arch;
}
exports.getArch = getArch;
function isLinux() {
return process.platform === 'linux';
}
exports.isLinux = isLinux;
function isWindows() {
return process.platform === 'win32';
}
exports.isWindows = isWindows;
function isMac() {
return process.platform === 'darwin';
}
exports.isMac = isMac;
/**
* @see https://github.com/microsoft/vscode/blob/64874113ad3c59e8d045f75dc2ef9d33d13f3a03/src/vs/platform/extensionManagement/common/extensionManagementUtil.ts#L171C1-L190C1
*/
function isAlpineLinux() {
if (!isLinux()) {
return false;
}
let content;
try {
const fileContent = fs_extra_1.default.readFileSync('/etc/os-release');
content = fileContent.toString();
}
catch (error) {
try {
const fileContent = fs_extra_1.default.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() {
return isAlpineLinux() ? 'alpine' : process.platform;
}
exports.getSupportedOS = getSupportedOS;