fix: package sharp for both macOS architectures (#1344)

This commit is contained in:
ZacharyZcR
2026-08-27 06:38:33 +08:00
committed by GitHub
parent 302ac19e6c
commit f848dee343
4 changed files with 256 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
const fs = require("node:fs");
const path = require("node:path");
const { execFileSync } = require("node:child_process");
function findPackage(start) {
let directory = path.dirname(start);
while (directory !== path.dirname(directory)) {
const manifest = path.join(directory, "package.json");
if (fs.existsSync(manifest)) return JSON.parse(fs.readFileSync(manifest));
directory = path.dirname(directory);
}
throw new Error("Could not locate the installed sharp package manifest");
}
const sharpPackage = findPackage(require.resolve("sharp"));
const packages = [
"@img/sharp-darwin-arm64",
"@img/sharp-darwin-x64",
"@img/sharp-libvips-darwin-arm64",
"@img/sharp-libvips-darwin-x64",
].map((name) => `${name}@${sharpPackage.optionalDependencies[name]}`);
execFileSync(
process.platform === "win32" ? "npm.cmd" : "npm",
["install", "--force", "--no-save", ...packages],
{ stdio: "inherit" },
);