From 3db42f8307b0fef514bb3c390b5d74578ca93da1 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 18 Jun 2024 22:19:49 -0700 Subject: [PATCH] build: parse the prebuild arch via npmrc --- script/prebuild.mts | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/script/prebuild.mts b/script/prebuild.mts index d7dd86bb..aa74ce5b 100644 --- a/script/prebuild.mts +++ b/script/prebuild.mts @@ -1,10 +1,33 @@ import {execaCommandSync} from "execa" +type Options = { + arch: string +} + +function toString(value: string | undefined): string | undefined { + switch (value) { + case undefined: + case "": + return undefined + default: + return value + } +} + +function parserOptions(): Options { + return { + arch: toString(process.env.npm_config_arch) ?? process.arch, + } +} + async function main() { - console.log("Building distribution binary...") + const opts = parserOptions() + + console.log("Building distribution binary with options ", opts) - const prebuildArch = getNodearch() + const prebuildArch = getNodearch(opts) + // TODO test the triple feature if (typeof process.env.TRIPLE === "string") { const TRIPLE = process.env.TRIPLE @@ -45,10 +68,8 @@ main().catch(e => { throw e }) -function getNodearch(): string { - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions - const arch = process.env.ARCH || process.arch - switch (arch) { +function getNodearch(opts: Options): string { + switch (opts.arch) { case "x86": { return "ia32" } @@ -56,7 +77,7 @@ function getNodearch(): string { return "x64" } default: { - return arch + return opts.arch } } }