Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make postinstall script production specific + check in build script dists #652

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ build-tmp-napi-v*
test.js
.cache/
test/typings-compatibility/
/script/*js
/script/*.d.ts
/script/*.d.*ts
/script/*js.map
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "6.0.2",
"description": "Next-generation ZeroMQ bindings for Node.js",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "commonjs",
"types": "lib/index.d.ts",
"typesVersions": {
">=3.7": {
"<=3.7": {
"lib/*": [
"lib/ts3.7/*"
]
Expand Down Expand Up @@ -82,11 +82,14 @@
"tsconfig.json"
],
"scripts": {
"install": "(npm run build.js || echo __skipping_js_build__) && cross-env npm_config_build_from_source=true aminya-node-gyp-build",
"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",
"install": "cross-env npm_config_build_from_source=true aminya-node-gyp-build",
"prepare": "pnpm run build.js",
"clean": "shx rm -rf ./build ./lib/ ./prebuilds",
"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",
"clean.release": "shx rm -rf ./build/Release",
"clean.temp": "shx rm -rf ./tmp && shx mkdir -p ./tmp",
"build.library": "tsc -p ./src/tsconfig.json",
"build.library": "tsc -p ./src/tsconfig.json && run-s build.downlevel",
"build.downlevel": "downlevel-dts ./lib ./lib/ts3.7",
"build.script": "tsc -p ./script/tsconfig.esm.json && tsc -p ./script/tsconfig.json",
"build.js": "run-p build.script build.library",
"build.doc": "typedoc --options ./typedoc.json && minify-all -s docs-unminified -d docs --jsCompressor terser && shx rm -rf docs-unminified",
Expand Down
118 changes: 118 additions & 0 deletions script/build.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions script/prebuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { execaCommandSync } from "execa";
import * as buildUtils from "./utils.js";
const { toString } = buildUtils;
function parserOptions() {
return {
arch: toString(process.env.npm_config_arch) ?? process.arch,
};
}
async function main() {
const opts = parserOptions();
console.log("Building distribution binary with options ", opts);
const prebuildArch = getNodearch(opts);
process.env.ARCH = prebuildArch;
process.env.npm_config_arch = prebuildArch;
process.env.npm_config_target_arch = prebuildArch;
process.env.PREBUILD_arch = prebuildArch;
// TODO test the triple feature
if (typeof process.env.TRIPLE === "string") {
const TRIPLE = process.env.TRIPLE;
const GCC = process.env.GCC;
process.env.CC = `${TRIPLE}-gcc-${GCC}`;
process.env.CXX = `${TRIPLE}-g++-${GCC}`;
const STRIP = `${TRIPLE}-strip`;
process.env.PREBUILD_STRIP_BIN = STRIP;
process.env.ZMQ_BUILD_OPTIONS = `--host=${TRIPLE}`;
}
// use the current node version to build the prebuild
// If the distribution for that particular architecture is not available, updated your Node:
// https://nodejs.org/dist/
const nodeVersion = process.version.replace("v", "");
let prebuildScript = `prebuildify --napi --arch=${prebuildArch} --strip --tag-libc -t ${nodeVersion}`;
if (typeof process.env.ALPINE_CHROOT === "string") {
prebuildScript = `/alpine/enter-chroot ${prebuildScript}`;
}
execaCommandSync(prebuildScript, {
env: process.env,
shell: true,
windowsHide: true,
stdio: "inherit",
encoding: "utf8",
});
}
main().catch(e => {
throw e;
});
function getNodearch(opts) {
switch (opts.arch) {
case "x86": {
return "ia32";
}
case "x86_64": {
return "x64";
}
default: {
return opts.arch;
}
}
}
//# sourceMappingURL=prebuild.mjs.map
30 changes: 30 additions & 0 deletions script/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.