fix pnpm inject on macos (#4605)
This commit is contained in:
parent
59a5428654
commit
420177ff04
1 changed files with 8 additions and 37 deletions
|
|
@ -19,14 +19,13 @@
|
||||||
import "./checkNodeVersion.js";
|
import "./checkNodeVersion.js";
|
||||||
|
|
||||||
import { execFileSync, execSync } from "child_process";
|
import { execFileSync, execSync } from "child_process";
|
||||||
import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, cpSync, rmSync } from "fs";
|
||||||
import { dirname, join } from "path";
|
import { dirname, join } from "path";
|
||||||
import { Readable } from "stream";
|
import { Readable } from "stream";
|
||||||
import { finished } from "stream/promises";
|
import { finished } from "stream/promises";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
const BASE_URL = "https://github.com/Vencord/Installer/releases/latest/download/";
|
const BASE_URL = "https://github.com/Vencord/Installer/releases/latest/download/";
|
||||||
const INSTALLER_PATH_DARWIN = "VencordInstaller.app/Contents/MacOS/VencordInstaller";
|
|
||||||
|
|
||||||
const BASE_DIR = join(dirname(fileURLToPath(import.meta.url)), "..");
|
const BASE_DIR = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
const FILE_DIR = join(BASE_DIR, "dist", "Installer");
|
const FILE_DIR = join(BASE_DIR, "dist", "Installer");
|
||||||
|
|
@ -37,7 +36,7 @@ function getFilename() {
|
||||||
case "win32":
|
case "win32":
|
||||||
return "VencordInstallerCli.exe";
|
return "VencordInstallerCli.exe";
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return "VencordInstaller.MacOS.zip";
|
return "VencordInstallerCli-darwin";
|
||||||
case "linux":
|
case "linux":
|
||||||
return "VencordInstallerCli-linux";
|
return "VencordInstallerCli-linux";
|
||||||
default:
|
default:
|
||||||
|
|
@ -51,10 +50,7 @@ async function ensureBinary() {
|
||||||
|
|
||||||
mkdirSync(FILE_DIR, { recursive: true });
|
mkdirSync(FILE_DIR, { recursive: true });
|
||||||
|
|
||||||
const downloadName = join(FILE_DIR, filename);
|
const outputFile = join(FILE_DIR, filename);
|
||||||
const outputFile = process.platform === "darwin"
|
|
||||||
? join(FILE_DIR, "VencordInstaller")
|
|
||||||
: downloadName;
|
|
||||||
|
|
||||||
const etag = existsSync(outputFile) && existsSync(ETAG_FILE)
|
const etag = existsSync(outputFile) && existsSync(ETAG_FILE)
|
||||||
? readFileSync(ETAG_FILE, "utf-8")
|
? readFileSync(ETAG_FILE, "utf-8")
|
||||||
|
|
@ -76,36 +72,11 @@ async function ensureBinary() {
|
||||||
|
|
||||||
writeFileSync(ETAG_FILE, res.headers.get("etag"));
|
writeFileSync(ETAG_FILE, res.headers.get("etag"));
|
||||||
|
|
||||||
if (process.platform === "darwin") {
|
const body = Readable.fromWeb(res.body);
|
||||||
console.log("Unzipping...");
|
await finished(body.pipe(createWriteStream(outputFile, {
|
||||||
const zip = new Uint8Array(await res.arrayBuffer());
|
mode: 0o755,
|
||||||
|
autoClose: true
|
||||||
const ff = await import("fflate");
|
})));
|
||||||
const bytes = ff.unzipSync(zip, {
|
|
||||||
filter: f => f.name === INSTALLER_PATH_DARWIN
|
|
||||||
})[INSTALLER_PATH_DARWIN];
|
|
||||||
|
|
||||||
writeFileSync(outputFile, bytes, { mode: 0o755 });
|
|
||||||
|
|
||||||
console.log("Overriding security policy for installer binary (this is required to run it)");
|
|
||||||
console.log("xattr might error, that's okay");
|
|
||||||
|
|
||||||
const logAndRun = cmd => {
|
|
||||||
console.log("Running", cmd);
|
|
||||||
try {
|
|
||||||
execSync(cmd);
|
|
||||||
} catch { }
|
|
||||||
};
|
|
||||||
logAndRun(`sudo spctl --add '${outputFile}' --label "Vencord Installer"`);
|
|
||||||
logAndRun(`sudo xattr -d com.apple.quarantine '${outputFile}'`);
|
|
||||||
} else {
|
|
||||||
// WHY DOES NODE FETCH RETURN A WEB STREAM OH MY GOD
|
|
||||||
const body = Readable.fromWeb(res.body);
|
|
||||||
await finished(body.pipe(createWriteStream(outputFile, {
|
|
||||||
mode: 0o755,
|
|
||||||
autoClose: true
|
|
||||||
})));
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Finished downloading!");
|
console.log("Finished downloading!");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue