Skip to content

Commit 2a1ffb9

Browse files
committed
build: parse the prebuild arch via npmrc
1 parent 6f5715a commit 2a1ffb9

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

script/prebuild.mts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
import {execaCommandSync} from "execa"
22

3+
type Options = {
4+
arch: string
5+
}
6+
7+
function toString(value: string | undefined): string | undefined {
8+
switch (value) {
9+
case undefined:
10+
case "":
11+
return undefined
12+
default:
13+
return value
14+
}
15+
}
16+
17+
function parserOptions(): Options {
18+
return {
19+
arch: toString(process.env.npm_config_arch) ?? process.arch,
20+
}
21+
}
22+
323
async function main() {
4-
console.log("Building distribution binary...")
24+
const opts = parserOptions()
25+
26+
console.log("Building distribution binary with options ", opts)
527

6-
const prebuildArch = getNodearch()
28+
const prebuildArch = getNodearch(opts)
729

30+
// TODO test the triple feature
831
if (typeof process.env.TRIPLE === "string") {
932
const TRIPLE = process.env.TRIPLE
1033

@@ -45,18 +68,16 @@ main().catch(e => {
4568
throw e
4669
})
4770

48-
function getNodearch(): string {
49-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions
50-
const arch = process.env.ARCH || process.arch
51-
switch (arch) {
71+
function getNodearch(opts: Options): string {
72+
switch (opts.arch) {
5273
case "x86": {
5374
return "ia32"
5475
}
5576
case "x86_64": {
5677
return "x64"
5778
}
5879
default: {
59-
return arch
80+
return opts.arch
6081
}
6182
}
6283
}

0 commit comments

Comments
 (0)