Skip to content

Commit 53f9d07

Browse files
authored
Merge pull request #652 from zeromq/postinstall [skip ci]
2 parents 97ee8e6 + dbcb918 commit 53f9d07

File tree

5 files changed

+215
-6
lines changed

5 files changed

+215
-6
lines changed

.gitignore

-1
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

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "6.0.2",
44
"description": "Next-generation ZeroMQ bindings for Node.js",
55
"main": "lib/index.js",
6-
"types": "lib/index.d.ts",
76
"type": "commonjs",
7+
"types": "lib/index.d.ts",
88
"typesVersions": {
9-
">=3.7": {
9+
"<=3.7": {
1010
"lib/*": [
1111
"lib/ts3.7/*"
1212
]
@@ -82,11 +82,14 @@
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",
89-
"build.library": "tsc -p ./src/tsconfig.json",
91+
"build.library": "tsc -p ./src/tsconfig.json && run-s build.downlevel",
92+
"build.downlevel": "downlevel-dts ./lib ./lib/ts3.7",
9093
"build.script": "tsc -p ./script/tsconfig.esm.json && tsc -p ./script/tsconfig.json",
9194
"build.js": "run-p build.script build.library",
9295
"build.doc": "typedoc --options ./typedoc.json && minify-all -s docs-unminified -d docs --jsCompressor terser && shx rm -rf docs-unminified",

script/build.js

+118
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/prebuild.mjs

+59
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

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)