From d1c9b3e17d3d81fde7439479c34f2fc720b81d84 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 Jun 2026 19:47:42 +0000 Subject: [PATCH] fix: skip native build when a bundled prebuild matches the platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit npm's automatic node-gyp invocation (triggered by binding.gyp + gypfile) ran unconditionally on every install, even when bin// already had a matching prebuild for this platform/arch — forcing every consumer on a supported architecture to have a full C++ toolchain, pkg-config, libmnl-dev, and libsodium-dev installed just to skip straight back to that same prebuild at runtime. Sets "gypfile": false and replaces it with an explicit "install" script that checks for a matching prebuild first and only falls back to `node-gyp rebuild` (now a regular dependency, not a devDependency, since this fallback path needs to work for consumers too) when none exists — unsupported architectures and local development (no bin/ prebuild present) are unaffected and still build from source as before. --- package-lock.json | 29 +++++------------------------ package.json | 8 +++++--- scripts/install.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 scripts/install.js diff --git a/package-lock.json b/package-lock.json index e0fdd0a..987429f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,20 @@ { "name": "@sourceregistry/node-wireguard", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@sourceregistry/node-wireguard", - "version": "1.0.0", + "version": "1.0.1", + "hasInstallScript": true, "license": "Apache-2.0", "os": [ "linux" ], "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", @@ -21,7 +23,6 @@ "@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" @@ -551,7 +552,6 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/@isaacs/fs-minipass/-/fs-minipass-4.0.1.tgz", "integrity": "sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w==", - "dev": true, "license": "ISC", "dependencies": { "minipass": "^7.0.4" @@ -1253,7 +1253,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-4.0.0.tgz", "integrity": "sha512-a1wflyaL0tHtJSmLSOVybYhy22vRih4eduhhrkcjgrWGnRfrZtovJ2FRjxuTtkkj47O/baf0R86QU5OuYpz8fA==", - "dev": true, "license": "ISC", "engines": { "node": "^20.17.0 || >=22.9.0" @@ -1420,7 +1419,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/chownr/-/chownr-3.0.0.tgz", "integrity": "sha512-+IxzY9BZOQd/XuYPRmrvEVjF/nqj5kgT4kEq7VofrDoM1MxoRjEWkrCC3EtLi59TVawxTAn+orJwFQcrqEN1+g==", - "dev": true, "license": "BlueOak-1.0.0", "engines": { "node": ">=18" @@ -2036,7 +2034,6 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz", "integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -2158,14 +2155,12 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.3.tgz", "integrity": "sha512-ZgEeZXj30q+I0EN+CbSSpIyPaJ5HVQD18Z1m+u1FXbAeT94mr1zw50q4q6jiiC447Nl/YTcIYSAftiGqetwXCA==", - "dev": true, "license": "Apache-2.0" }, "node_modules/fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", - "dev": true, "license": "MIT", "engines": { "node": ">=12.0.0" @@ -2336,7 +2331,6 @@ "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", - "dev": true, "license": "ISC" }, "node_modules/handlebars": { @@ -2621,7 +2615,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-4.0.0.tgz", "integrity": "sha512-FFUtZMpoZ8RqHS3XeXEmHWLA4thH+ZxCv2lOiPIn1Xc7CxrqhWzNSDzD+/chS/zbYezmiwWLdQC09JdQKmthOw==", - "dev": true, "license": "BlueOak-1.0.0", "engines": { "node": ">=20" @@ -2968,7 +2961,6 @@ "version": "7.1.3", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.3.tgz", "integrity": "sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==", - "dev": true, "license": "BlueOak-1.0.0", "engines": { "node": ">=16 || 14 >=14.17" @@ -2978,7 +2970,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-3.1.0.tgz", "integrity": "sha512-KZxYo1BUkWD2TVFLr0MQoM8vUUigWD3LlD83a/75BqC+4qE0Hb1Vo5v1FgcfaNXvfXzr+5EhQ6ing/CaBijTlw==", - "dev": true, "license": "MIT", "dependencies": { "minipass": "^7.1.2" @@ -3049,7 +3040,6 @@ "version": "12.4.0", "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-12.4.0.tgz", "integrity": "sha512-OMcPNvqTCFUnNaBlmdgq+lfNqY7gTiSmNRDjY3uAXRyudeKZEZxu3CLtjMQrx4zZxCX2b/mpNqTtwuCJgXhHkw==", - "dev": true, "license": "MIT", "dependencies": { "env-paths": "^2.2.0", @@ -3074,7 +3064,6 @@ "version": "9.0.0", "resolved": "https://registry.npmjs.org/nopt/-/nopt-9.0.0.tgz", "integrity": "sha512-Zhq3a+yFKrYwSBluL4H9XP3m3y5uvQkB/09CwDruCiRmR/UJYnn9W4R48ry0uGC70aeTPKLynBtscP9efFFcPw==", - "dev": true, "license": "ISC", "dependencies": { "abbrev": "^4.0.0" @@ -5286,7 +5275,6 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -5339,7 +5327,6 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/proc-log/-/proc-log-6.1.0.tgz", "integrity": "sha512-iG+GYldRf2BQ0UDUAd6JQ/RwzaQy6mXmsk/IzlYyal4A4SNFw54MeH4/tLkF4I5WoWG9SQwuqWzS99jaFQHBuQ==", - "dev": true, "license": "ISC", "engines": { "node": "^20.17.0 || >=22.9.0" @@ -8449,7 +8436,6 @@ "version": "7.8.5", "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", - "dev": true, "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -8854,7 +8840,6 @@ "version": "7.5.16", "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.16.tgz", "integrity": "sha512-56adEpPMouktRlBLXiaYFFzZ/3+JXa8P9n7WbR+ibIjtviN55mEaOkiysCnPnWm+7kkui1Dn8J9l+g6zV8731w==", - "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "@isaacs/fs-minipass": "^4.0.0", @@ -8976,7 +8961,6 @@ "version": "0.2.17", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", - "dev": true, "license": "MIT", "dependencies": { "fdir": "^6.5.0", @@ -9089,7 +9073,6 @@ "version": "6.27.0", "resolved": "https://registry.npmjs.org/undici/-/undici-6.27.0.tgz", "integrity": "sha512-YmfV3YnEDzXRC5lZ2jWtWWHKGUm1zIt8AhesR1tens+HTNv+YZlN/dp6G727LOvMJ8xjP9Be7Y2Sdr96LDm+pg==", - "dev": true, "license": "MIT", "engines": { "node": ">=18.17" @@ -9197,7 +9180,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/which/-/which-6.0.1.tgz", "integrity": "sha512-oGLe46MIrCRqX7ytPUf66EAYvdeMIZYn3WaocqqKZAxrBpkqHfL/qvTyJ/bTk5+AqHCjXmrv3CEWgy368zhRUg==", - "dev": true, "license": "ISC", "dependencies": { "isexe": "^4.0.0" @@ -9258,7 +9240,6 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-5.0.0.tgz", "integrity": "sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==", - "dev": true, "license": "BlueOak-1.0.0", "engines": { "node": ">=18" diff --git a/package.json b/package.json index 6fe0359..f77bc9a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", diff --git a/scripts/install.js b/scripts/install.js new file mode 100644 index 0000000..2af262e --- /dev/null +++ b/scripts/install.js @@ -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// (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" });