Skip to content
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
29 changes: 5 additions & 24 deletions package-lock.json

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

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
"lib/**/*.js",
"lib/**/*.d.ts",
"binding.gyp",
"scripts/install.js",
"src",
"bin",
"LICENSE"
],
"scripts": {
"install": "node scripts/install.js",
"build:cpp": "node-gyp rebuild",
"build:ts": "tsc -p tsconfig.json",
"build": "npm run build:cpp && npm run build:ts",
Expand All @@ -48,7 +50,8 @@
"prepublishOnly": "npm run package"
},
"dependencies": {
"node-addon-api": "^8.8.0"
"node-addon-api": "^8.8.0",
"node-gyp": "^12.4.0"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.3",
Expand All @@ -57,12 +60,11 @@
"@semantic-release/npm": "^13.1.5",
"@semantic-release/release-notes-generator": "^14.1.0",
"@types/node": "^26.0.0",
"node-gyp": "^12.4.0",
"semantic-release": "^24.2.0",
"tsx": "^4.19.2",
"typescript": "^6.0.3"
},
"gypfile": true,
"gypfile": false,
"release": {
"branches": [
"main",
Expand Down
35 changes: 35 additions & 0 deletions scripts/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env node
"use strict";

// Runs as this package's "install" lifecycle script (see package.json —
// "gypfile" is deliberately false so npm never auto-triggers node-gyp on its
// own). If a prebuild matching this platform/arch is already staged in
// bin/<triplet>/ (true for any npm-installed copy on a supported platform —
// see scripts/package/package.sh), there is nothing to build: skip straight
// to exit 0. Only platforms without a published prebuild fall through to an
// actual native build, which is the only case that needs a C++ toolchain,
// pkg-config, libmnl-dev, and libsodium-dev installed.

const { existsSync } = require("node:fs");
const { join } = require("node:path");
const { execFileSync } = require("node:child_process");

const ARCH_TO_TRIPLET = {
x64: "x86_64-linux-gnu",
arm64: "aarch64-linux-gnu",
};

const triplet = process.platform === "linux" ? ARCH_TO_TRIPLET[process.arch] : undefined;
const prebuildPath = triplet ? join(__dirname, "..", "bin", triplet, "node-wireguard.node") : undefined;

if (prebuildPath && existsSync(prebuildPath)) {
console.log(`node-wireguard: using the bundled prebuild for ${triplet} — skipping the native build.`);
process.exit(0);
}

console.log(
`node-wireguard: no bundled prebuild for platform=${process.platform} arch=${process.arch} — building from ` +
"source (requires a C++17 toolchain, pkg-config, libmnl-dev, libsodium-dev).",
);

execFileSync(process.execPath, [require.resolve("node-gyp/bin/node-gyp.js"), "rebuild"], { stdio: "inherit" });