Skip to content

Commit 28cf456

Browse files
committed
fix: make postinstall script production specific + check in build script dists
1 parent 97ee8e6 commit 28cf456

File tree

5 files changed

+211
-3
lines changed

5 files changed

+211
-3
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ build-tmp-napi-v*
1313
test.js
1414
.cache/
1515
test/typings-compatibility/
16-
/script/*js
1716
/script/*.d.ts
1817
/script/*.d.*ts
1918
/script/*js.map

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@
8282
"tsconfig.json"
8383
],
8484
"scripts": {
85-
"install": "(npm run build.js || echo __skipping_js_build__) && cross-env npm_config_build_from_source=true aminya-node-gyp-build",
86-
"clean": "shx rm -rf ./build ./lib/ ./prebuilds ./script/*.js ./script/*.mjs ./script/*.js.map ./script/*.mjs.map ./script/*.d.ts ./script/*.d.mts ./script/*.cjs ./scripts/*.cjs.map ./scripts/*.d.cts ./script/*.tsbuildinfo",
85+
"install": "cross-env npm_config_build_from_source=true aminya-node-gyp-build",
86+
"prepare": "pnpm run build.js",
87+
"clean": "shx rm -rf ./build ./lib/ ./prebuilds",
88+
"clean.script": "shx rm -rf ./script/*.js ./script/*.mjs ./script/*.js.map ./script/*.mjs.map ./script/*.d.ts ./script/*.d.mts ./script/*.cjs ./scripts/*.cjs.map ./scripts/*.d.cts ./script/*.tsbuildinfo",
8789
"clean.release": "shx rm -rf ./build/Release",
8890
"clean.temp": "shx rm -rf ./tmp && shx mkdir -p ./tmp",
8991
"build.library": "tsc -p ./src/tsconfig.json",

script/build.js

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/prebuild.mjs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { execaCommandSync } from "execa";
2+
import * as buildUtils from "./utils.js";
3+
const { toString } = buildUtils;
4+
function parserOptions() {
5+
return {
6+
arch: toString(process.env.npm_config_arch) ?? process.arch,
7+
};
8+
}
9+
async function main() {
10+
const opts = parserOptions();
11+
console.log("Building distribution binary with options ", opts);
12+
const prebuildArch = getNodearch(opts);
13+
process.env.ARCH = prebuildArch;
14+
process.env.npm_config_arch = prebuildArch;
15+
process.env.npm_config_target_arch = prebuildArch;
16+
process.env.PREBUILD_arch = prebuildArch;
17+
// TODO test the triple feature
18+
if (typeof process.env.TRIPLE === "string") {
19+
const TRIPLE = process.env.TRIPLE;
20+
const GCC = process.env.GCC;
21+
process.env.CC = `${TRIPLE}-gcc-${GCC}`;
22+
process.env.CXX = `${TRIPLE}-g++-${GCC}`;
23+
const STRIP = `${TRIPLE}-strip`;
24+
process.env.PREBUILD_STRIP_BIN = STRIP;
25+
process.env.ZMQ_BUILD_OPTIONS = `--host=${TRIPLE}`;
26+
}
27+
// use the current node version to build the prebuild
28+
// If the distribution for that particular architecture is not available, updated your Node:
29+
// https://nodejs.org/dist/
30+
const nodeVersion = process.version.replace("v", "");
31+
let prebuildScript = `prebuildify --napi --arch=${prebuildArch} --strip --tag-libc -t ${nodeVersion}`;
32+
if (typeof process.env.ALPINE_CHROOT === "string") {
33+
prebuildScript = `/alpine/enter-chroot ${prebuildScript}`;
34+
}
35+
execaCommandSync(prebuildScript, {
36+
env: process.env,
37+
shell: true,
38+
windowsHide: true,
39+
stdio: "inherit",
40+
encoding: "utf8",
41+
});
42+
}
43+
main().catch(e => {
44+
throw e;
45+
});
46+
function getNodearch(opts) {
47+
switch (opts.arch) {
48+
case "x86": {
49+
return "ia32";
50+
}
51+
case "x86_64": {
52+
return "x64";
53+
}
54+
default: {
55+
return opts.arch;
56+
}
57+
}
58+
}
59+
//# sourceMappingURL=prebuild.mjs.map

script/utils.js

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)