singularity-forge/native/scripts/sync-platform-versions.cjs
Juan Francisco Lebrero 9b0f31e39a fix: use version ranges for native engine optional dependencies (#286)
The v2.10.5 release broke on darwin-arm64 because the main package
was published before the native CI built and published the platform
packages. With exact version pinning, npm silently skips the
optional dep when the version doesn't exist, causing a fatal crash.

Change to >=2.10.2 range so npm installs the latest available
binary. The native API is stable across patch versions.

Also stop sync-platform-versions.cjs from overwriting the ranges
back to exact versions during CI.
2026-03-13 16:20:44 -06:00

53 lines
1.7 KiB
JavaScript

#!/usr/bin/env node
/**
* Synchronize platform package versions with the root package version.
*
* Reads version from root package.json, writes it to all platform
* package.json files and updates optionalDependencies in root package.json.
*/
const fs = require("fs");
const path = require("path");
const rootDir = path.resolve(__dirname, "..", "..");
const npmDir = path.resolve(__dirname, "..", "npm");
const rootPkgPath = path.join(rootDir, "package.json");
const rootPkg = JSON.parse(fs.readFileSync(rootPkgPath, "utf-8"));
const version = rootPkg.version;
console.log(`[sync-platform-versions] Syncing to version ${version}`);
const platformPackages = [
"darwin-arm64",
"darwin-x64",
"linux-x64-gnu",
"linux-arm64-gnu",
"win32-x64-msvc",
];
// Update each platform package.json
for (const platform of platformPackages) {
const pkgPath = path.join(npmDir, platform, "package.json");
if (!fs.existsSync(pkgPath)) {
console.warn(` Skipping ${platform}: ${pkgPath} not found`);
continue;
}
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
if (pkg.version !== version) {
console.log(` ${platform}: ${pkg.version} -> ${version}`);
pkg.version = version;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
} else {
console.log(` ${platform}: already ${version}`);
}
}
// Skip updating root optionalDependencies — they use a >=2.10.2 range
// intentionally so that npm can fall back to the latest available
// platform binary when the exact version hasn't been published yet
// (e.g. main package published before native CI finishes).
console.log(" root optionalDependencies: using range specifiers (not updating)");
console.log("[sync-platform-versions] Done.");