mirror of
https://github.com/googleworkspace/cli.git
synced 2026-09-14 16:47:13 +08:00
86c08cfc0d
* chore: remove cargo-dist, use native fetch for npm installer * fix: harden npm scripts — spawnSync, signal handling, binary-exists check * fix: address PR review comments - Add null body guard for fetch response - Fix PowerShell Expand-Archive path quoting vulnerability - Sanitize error output to prevent ANSI escape injection - Add proxy support limitation note - Fix upgrade bug: use .version marker so npm update downloads new binary - Downgrade changeset from minor to patch (chore, not feature) - Update AGENTS.md: remove stale cargo-dist reference from labels * fix: use flat archives for consistent tar/zip extraction Both tar.gz and zip archives now contain files at root (no nested directory). Removes --strip-components 1 from install.js since it is no longer needed. This makes extraction consistent across platforms. --------- Co-authored-by: jpoehnelt-bot <jpoehnelt-bot@users.noreply.github.com>
87 lines
2.0 KiB
JavaScript
87 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
"use strict";
|
|
|
|
const os = require("os");
|
|
const path = require("path");
|
|
const fs = require("fs");
|
|
const { spawnSync } = require("child_process");
|
|
|
|
const { supportedPlatforms } = require("./package.json");
|
|
|
|
/**
|
|
* Map Node.js os.type() and os.arch() to Rust-style target triples.
|
|
*/
|
|
function getPlatformKey() {
|
|
const rawOs = os.type();
|
|
const rawArch = os.arch();
|
|
|
|
let osType;
|
|
switch (rawOs) {
|
|
case "Windows_NT":
|
|
osType = "pc-windows-msvc";
|
|
break;
|
|
case "Darwin":
|
|
osType = "apple-darwin";
|
|
break;
|
|
case "Linux":
|
|
osType = "unknown-linux-gnu";
|
|
break;
|
|
default:
|
|
throw new Error(`Unsupported operating system: ${rawOs}`);
|
|
}
|
|
|
|
let arch;
|
|
switch (rawArch) {
|
|
case "x64":
|
|
arch = "x86_64";
|
|
break;
|
|
case "arm64":
|
|
arch = "aarch64";
|
|
break;
|
|
default:
|
|
throw new Error(`Unsupported architecture: ${rawArch}`);
|
|
}
|
|
|
|
// On Linux, try to detect musl libc
|
|
if (rawOs === "Linux") {
|
|
try {
|
|
const result = spawnSync("ldd", ["--version"], {
|
|
encoding: "utf8",
|
|
stdio: ["pipe", "pipe", "pipe"],
|
|
});
|
|
// musl ldd prints version info to stderr
|
|
const output = (result.stdout || "") + (result.stderr || "");
|
|
if (output.toLowerCase().includes("musl")) {
|
|
osType = "unknown-linux-musl";
|
|
}
|
|
} catch {
|
|
// If ldd fails, assume glibc
|
|
}
|
|
}
|
|
|
|
const key = `${arch}-${osType}`;
|
|
|
|
if (!supportedPlatforms[key]) {
|
|
// Try musl fallback on Linux if glibc binary is not available
|
|
if (rawOs === "Linux") {
|
|
const muslKey = `${arch}-unknown-linux-musl`;
|
|
if (supportedPlatforms[muslKey]) {
|
|
return muslKey;
|
|
}
|
|
}
|
|
throw new Error(
|
|
`Unsupported platform: ${key}\nSupported platforms: ${Object.keys(supportedPlatforms).join(", ")}`,
|
|
);
|
|
}
|
|
|
|
return key;
|
|
}
|
|
|
|
function getPlatform() {
|
|
const key = getPlatformKey();
|
|
return supportedPlatforms[key];
|
|
}
|
|
|
|
module.exports = { getPlatform, getPlatformKey };
|