Files
Termix/scripts/install-linux-sharp.cjs
T
alexcastgonzandClaude Sonnet 5.5 9778b6e56a fix(build): ship the arm64 and armv7l sharp binaries in the Linux builds (#1771)
The Linux job runs on x64, so npm ci only installs @img/sharp-linux-x64 and
@img/sharp-libvips-linux-x64. The arm64 and armv7l AppImages then carry x64
binaries and fail to load sharp on start. Install the arm packages at the
versions sharp declares, as the Windows and macOS jobs already do.

Fixes #1769

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 20:47:11 -06:00

41 lines
1.3 KiB
JavaScript

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");
}
// The build runs on x64 but ships arm64 and armv7l too, so npm ci alone
// only installs the x64 binaries.
function linuxSharpPackages(sharpPackage) {
return ["x64", "arm64", "arm"].flatMap((arch) =>
[`@img/sharp-linux-${arch}`, `@img/sharp-libvips-linux-${arch}`].map(
(name) => {
const version = sharpPackage.optionalDependencies?.[name];
if (!version) {
throw new Error(`sharp does not declare ${name} as a dependency`);
}
return `${name}@${version}`;
},
),
);
}
module.exports = { linuxSharpPackages };
if (require.main === module) {
const sharpPackage = findPackage(require.resolve("sharp"));
execFileSync(
"npm",
["install", "--force", "--no-save", ...linuxSharpPackages(sharpPackage)],
{ stdio: "inherit" },
);
}