Take platform and arch in the lib headless helpers

hasFactorioHeadless(version, platform, arch) replaces the host's
hasArm64Headless, and factorioHeadlessUrl takes the platform too and
throws when Factorio has no headless build for it, which for now is
every platform except Linux. headlessUrl is marked deprecated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-18 11:15:40 +00:00
1 parent 5aaea1f213
commit 62f17a20af
3 files changed
+70 -16

No files matched your search

+2 -6
View File
@@ -191,10 +191,6 @@ function factorioArch(): lib.FactorioHeadlessArch {
return process.platform === "linux" && process.arch === "arm64" ? "arm64" : "x64";
}
function hasArm64Headless(version: lib.FullVersion) {
return lib.integerFullVersion(version) >= lib.integerFullVersion(lib.minimumArm64HeadlessVersion);
}
// Factorio downloads in progress by target directory, shared by every server in the process
const downloadsInProgress = new Map<string, Promise<void>>();
@@ -221,7 +217,7 @@ export async function checkForUpdates(
const arch = factorioArch();
const matching = availableVersions.filter(v => matchesTarget(v.version));
const latestVersion = matching
.filter(v => arch !== "arm64" || hasArm64Headless(v.version))
.filter(v => process.platform !== "linux" || lib.hasFactorioHeadless(v.version, "linux", arch))
.sort((v1, v2) => versionOrder(v1.version, v2.version))
[0];
@@ -268,7 +264,7 @@ export async function checkForUpdates(
logger.info(`A newer version of factorio is available (${v}), waiting for download...`);
} else {
logger.info(`A newer version of factorio is available (${v}), starting download...`);
download = downloadAndExtractTar(lib.factorioHeadlessUrl(v, arch), dst).finally(() => {
download = downloadAndExtractTar(lib.factorioHeadlessUrl(v, "linux", arch), dst).finally(() => {
downloadsInProgress.delete(dst);
});
downloadsInProgress.set(dst, download);
+38 -6
View File
@@ -1,5 +1,5 @@
import { Static, Type } from "@sinclair/typebox";
import { FullVersionSchema, integerFullVersion, isFullVersion } from "../data/version.js";
import { FullVersion, FullVersionSchema, integerFullVersion, isFullVersion } from "../data/version.js";
const ARCHIVE_URL = "https://factorio.com/download/archive/";
@@ -9,25 +9,57 @@ const ARCHIVE_URL = "https://factorio.com/download/archive/";
export const ExternalFactorioVersionSchema = Type.Object({
stable: Type.Boolean(),
version: FullVersionSchema,
/** @deprecated Linux x64 only, use {@link factorioHeadlessUrl} instead. */
headlessUrl: Type.String(),
});
export type ExternalFactorioVersion = Static<typeof ExternalFactorioVersionSchema>;
/** CPU architectures Factorio publishes Linux headless builds for */
/** Platforms Factorio may publish headless builds for, named as in Node's process.platform */
export type FactorioHeadlessPlatform = "linux" | "win32";
/** CPU architectures Factorio may publish headless builds for, named as in Node's process.arch */
export type FactorioHeadlessArch = "x64" | "arm64";
/** First Factorio version with an ARM64 Linux headless build */
export const minimumArm64HeadlessVersion = "2.1.18";
/**
* Download URL of the Linux headless build of a Factorio version
* Check if Factorio publishes a headless build of a version
*
* @param version - Factorio version to check.
* @param platform - Platform of the build.
* @param arch - CPU architecture of the build.
* @returns true if the build can be downloaded.
*/
export function hasFactorioHeadless(
version: FullVersion,
platform: FactorioHeadlessPlatform,
arch: FactorioHeadlessArch,
) {
if (platform !== "linux") {
return false;
}
return arch === "x64" || integerFullVersion(version) >= integerFullVersion(minimumArm64HeadlessVersion);
}
/**
* Download URL of the headless build of a Factorio version
*
* @param version - Factorio version to download.
* @param platform - Platform of the build.
* @param arch - CPU architecture of the build.
* @returns URL redirecting to the tarball.
* @returns URL redirecting to the archive.
* @throws Error if Factorio has no headless build for the platform and arch.
*/
export function factorioHeadlessUrl(version: string, arch: FactorioHeadlessArch = "x64") {
export function factorioHeadlessUrl(
version: FullVersion,
platform: FactorioHeadlessPlatform,
arch: FactorioHeadlessArch,
) {
if (!hasFactorioHeadless(version, platform, arch)) {
throw new Error(`Factorio ${version} has no headless build for ${platform} ${arch}`);
}
const build = arch === "arm64" ? "linux-arm64" : "linux64";
return `https://www.factorio.com/get-download/${version}/headless/${build}`;
}
@@ -78,7 +110,7 @@ function parseFactorioVersions(html: string): ExternalFactorioVersion[] {
versions.set(version, {
version: version,
stable: kind === "stable",
headlessUrl: factorioHeadlessUrl(version),
headlessUrl: factorioHeadlessUrl(version, "linux", "x64"),
});
}
}