From bf50031355e91d1f4cd4d891051f049bb35d5a20 Mon Sep 17 00:00:00 2001 From: Isaac Aderogba Date: Mon, 25 Nov 2024 12:46:51 +0000 Subject: [PATCH 1/3] feat: prefer npm_config_target and npm_config_runtime when determining abi and runtime --- node-gyp-build.js | 6 +++++- package.json | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/node-gyp-build.js b/node-gyp-build.js index 76b96e1..0c61638 100644 --- a/node-gyp-build.js +++ b/node-gyp-build.js @@ -1,6 +1,7 @@ var fs = require('fs') var path = require('path') var os = require('os') +var nodeAbi = require("node-abi") // Workaround to fix webpack's build warnings: 'the request of a dependency is an expression' var runtimeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require // eslint-disable-line @@ -9,6 +10,7 @@ var vars = (process.config && process.config.variables) || {} var prebuildsOnly = !!process.env.PREBUILDS_ONLY var abi = process.versions.modules // TODO: support old node where this is undef var runtime = isElectron() ? 'electron' : (isNwjs() ? 'node-webkit' : 'node') +var abi = process.env.npm_config_target ? nodeAbi.getAbi(process.env.npm_config_target, runtime) : process.versions.modules // TODO: support old node where this is undef var arch = process.env.npm_config_arch || os.arch() var platform = process.env.npm_config_platform || os.platform() @@ -44,6 +46,7 @@ load.resolve = load.path = function (dir) { var nearby = resolve(path.dirname(process.execPath)) if (nearby) return nearby + var electronVersion = runtime === "electron" && process.env.npm_config_target ? process.env.npm_config_target : process.versions.electron; var target = [ 'platform=' + platform, 'arch=' + arch, @@ -53,7 +56,7 @@ load.resolve = load.path = function (dir) { armv ? 'armv=' + armv : '', 'libc=' + libc, 'node=' + process.versions.node, - process.versions.electron ? 'electron=' + process.versions.electron : '', + electronVersion ? 'electron=' + electronVersion : '', typeof __webpack_require__ === 'function' ? 'webpack=true' : '' // eslint-disable-line ].filter(Boolean).join(' ') @@ -188,6 +191,7 @@ function isNwjs () { } function isElectron () { + if (process.env.npm_config_runtime === "electron") return true if (process.versions && process.versions.electron) return true if (process.env.ELECTRON_RUN_AS_NODE) return true return typeof window !== 'undefined' && window.process && window.process.type === 'renderer' diff --git a/package.json b/package.json index 6f6f28b..db5fe33 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,9 @@ "default": "os" } }, + "dependencies": { + "node-abi": "^3.71.0" + }, "devDependencies": { "array-shuffle": "^1.0.1", "standard": "^14.0.0", From bb78a290daaa0f7e2ecd02ecfe092dd2b0e6dd00 Mon Sep 17 00:00:00 2001 From: Isaac Aderogba Date: Mon, 25 Nov 2024 13:05:14 +0000 Subject: [PATCH 2/3] fix: remove previously-defined abi variable --- node-gyp-build.js | 1 - 1 file changed, 1 deletion(-) diff --git a/node-gyp-build.js b/node-gyp-build.js index 0c61638..f6ceeaa 100644 --- a/node-gyp-build.js +++ b/node-gyp-build.js @@ -8,7 +8,6 @@ var runtimeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_r var vars = (process.config && process.config.variables) || {} var prebuildsOnly = !!process.env.PREBUILDS_ONLY -var abi = process.versions.modules // TODO: support old node where this is undef var runtime = isElectron() ? 'electron' : (isNwjs() ? 'node-webkit' : 'node') var abi = process.env.npm_config_target ? nodeAbi.getAbi(process.env.npm_config_target, runtime) : process.versions.modules // TODO: support old node where this is undef From 66e01b173efb9e842d9eba75058697d497616cda Mon Sep 17 00:00:00 2001 From: Isaac Aderogba Date: Tue, 26 Nov 2024 09:21:40 +0000 Subject: [PATCH 3/3] feat: for completeness sake, also respect nodeVersion when logging error --- node-gyp-build.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node-gyp-build.js b/node-gyp-build.js index f6ceeaa..a43c753 100644 --- a/node-gyp-build.js +++ b/node-gyp-build.js @@ -45,7 +45,9 @@ load.resolve = load.path = function (dir) { var nearby = resolve(path.dirname(process.execPath)) if (nearby) return nearby - var electronVersion = runtime === "electron" && process.env.npm_config_target ? process.env.npm_config_target : process.versions.electron; + var nodeVersion = runtime !== "electron" && process.env.npm_config_target ? process.env.npm_config_target : process.versions.node + var electronVersion = runtime === "electron" && process.env.npm_config_target ? process.env.npm_config_target : process.versions.electron + var target = [ 'platform=' + platform, 'arch=' + arch, @@ -54,7 +56,7 @@ load.resolve = load.path = function (dir) { 'uv=' + uv, armv ? 'armv=' + armv : '', 'libc=' + libc, - 'node=' + process.versions.node, + 'node=' + nodeVersion, electronVersion ? 'electron=' + electronVersion : '', typeof __webpack_require__ === 'function' ? 'webpack=true' : '' // eslint-disable-line ].filter(Boolean).join(' ')