From b3dc6a97861e7219b76b6f172293d9e0484a1e7e Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Fri, 5 Aug 2022 13:50:32 +0200 Subject: [PATCH 1/2] Support cross-installing of prebuilt packages via npm_config_* vars --- bin.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/bin.js b/bin.js index 36bd515..7f0f436 100755 --- a/bin.js +++ b/bin.js @@ -4,13 +4,22 @@ var proc = require('child_process') var os = require('os') var path = require('path') +var targetMismatch = (process.env.npm_config_platform && process.platform !== process.env.npm_config_platform) || + (process.env.npm_config_arch && process.arch !== process.env.npm_config_arch) + if (!buildFromSource()) { - proc.exec('node-gyp-build-test', function (err, stdout, stderr) { - if (err) { - if (verbose()) console.error(stderr) - preinstall() - } - }) + if (targetMismatch) { + // If the target is mismatched, then we can't test built output, and we can't build from source either. + // Instead, we just check whether a matching prebuild exists, and fail if it doesn't. + require('./index').path(process.cwd()) + } else { + proc.exec('node-gyp-build-test', function (err, stdout, stderr) { + if (err) { + if (verbose()) console.error(stderr) + preinstall() + } + }) + } } else { preinstall() } From 2c1cccff9af54747d519f9b585de73ef831b26ba Mon Sep 17 00:00:00 2001 From: Tim Perry <1526883+pimterry@users.noreply.github.com> Date: Fri, 5 Aug 2022 15:31:04 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Vincent Weevers --- bin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin.js b/bin.js index 7f0f436..fc130b4 100755 --- a/bin.js +++ b/bin.js @@ -9,9 +9,9 @@ var targetMismatch = (process.env.npm_config_platform && process.platform !== pr if (!buildFromSource()) { if (targetMismatch) { - // If the target is mismatched, then we can't test built output, and we can't build from source either. + // If the target is mismatched, then we can't test prebuilds. // Instead, we just check whether a matching prebuild exists, and fail if it doesn't. - require('./index').path(process.cwd()) + require('./index').path() } else { proc.exec('node-gyp-build-test', function (err, stdout, stderr) { if (err) {