/** * The facts about this host that decide whether a native Module Package v1 can run on it * (ADR 0049): operating system, CPU, C library family and version, and Node-API version. * * Everything comes from Node.js itself (`process.platform`, `process.arch`, `process.versions`, and * the diagnostic report's `glibcVersionRuntime`), never from running a system command. A fact Node * cannot report is left undefined, and every check that needs it fails closed. */ export interface ModulePackageHost { readonly platform: string; readonly arch: string; /** The C library on Linux: glibc with its runtime version, or undefined when it cannot be proven * to be glibc (musl reports none). */ readonly libc?: { readonly family: "glibc"; readonly version: string }; /** `process.versions.napi`: the highest Node-API version this Node.js provides. */ readonly nodeApi?: number; /** `process.versions.modules`: the ABI an ABI-specific addon must have been built for. */ readonly nodeAbi?: string; } function glibcVersion(): string | undefined { try { const header = (process.report?.getReport() as { header?: { glibcVersionRuntime?: unknown } }) ?.header; const version = header?.glibcVersionRuntime; return typeof version === "string" && /^\d+\.\d+(?:\.\d+)?$/u.test(version) ? version : undefined; } catch { return undefined; } } export function currentModulePackageHost(): ModulePackageHost { const libc = process.platform === "linux" ? glibcVersion() : undefined; const nodeApi = Number(process.versions.napi); return Object.freeze({ arch: process.arch, ...(libc === undefined ? {} : { libc: Object.freeze({ family: "glibc" as const, version: libc }) }), ...(Number.isInteger(nodeApi) && nodeApi > 0 ? { nodeApi } : {}), ...(typeof process.versions.modules === "string" ? { nodeAbi: process.versions.modules } : {}), platform: process.platform, }); } /** The native targets this platform can verify, with what each requires of a host. */ export const MODULE_PACKAGE_NATIVE_TARGETS: ReadonlyMap< string, { readonly platform: string; readonly arch: string; readonly libc: "glibc"; readonly elfMachine: number; } > = new Map([ ["linux-x64-glibc", { arch: "x64", elfMachine: 62, libc: "glibc", platform: "linux" }], ]);