Skip to content

Commit

Permalink
build: parse the prebuild arch via npmrc
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 19, 2024
1 parent ec3620c commit 3db42f8
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions script/prebuild.mts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -45,18 +68,16 @@ 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"
}
case "x86_64": {
return "x64"
}
default: {
return arch
return opts.arch
}
}
}

0 comments on commit 3db42f8

Please sign in to comment.