From 3fe1454e5c9b993d18f5220cad48683f37d75c3c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 18 Nov 2022 13:05:50 -0800 Subject: [PATCH 1/6] fix: fix the preinstall function logic --- bin.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin.js b/bin.js index 7ca3ab5..e6277ff 100755 --- a/bin.js +++ b/bin.js @@ -37,11 +37,15 @@ function build () { } function preinstall () { - if (!process.argv[2]) return build() - exec(process.argv[2]).on('exit', function (code) { - if (code) process.exit(code) + try { + // try to load the prebuild + const load = require("node-gyp-build/index.js") + load() + } catch (err) { + // report the error and fall to a build + console.error(err.message) build() - }) + } } function exec (cmd) { From 40e26bff6f66892c6b398afa936afb5a0b6d724b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 18 Nov 2022 15:27:34 -0800 Subject: [PATCH 2/6] test: run standard --fix --- bin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin.js b/bin.js index e6277ff..afbef13 100755 --- a/bin.js +++ b/bin.js @@ -39,7 +39,7 @@ function build () { function preinstall () { try { // try to load the prebuild - const load = require("node-gyp-build/index.js") + const load = require('node-gyp-build/index.js') load() } catch (err) { // report the error and fall to a build From 2c0dbc1e9e9184d34f7338e0b18e718d2978802c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Nov 2022 22:27:05 -0800 Subject: [PATCH 3/6] fix: remove the rest of process.argv executions --- bin.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/bin.js b/bin.js index afbef13..0c7309b 100755 --- a/bin.js +++ b/bin.js @@ -30,9 +30,6 @@ function build () { proc.spawn(args[0], args.slice(1), { stdio: 'inherit', shell: win32, windowsHide: true }).on('exit', function (code) { if (code || !process.argv[3]) process.exit(code) - exec(process.argv[3]).on('exit', function (code) { - process.exit(code) - }) }) } @@ -48,23 +45,6 @@ function preinstall () { } } -function exec (cmd) { - if (process.platform !== 'win32') { - var shell = os.platform() === 'android' ? 'sh' : true - return proc.spawn(cmd, [], { - shell, - stdio: 'inherit' - }) - } - - return proc.spawn(cmd, [], { - windowsVerbatimArguments: true, - stdio: 'inherit', - shell: true, - windowsHide: true - }) -} - function buildFromSource () { return hasFlag('--build-from-source') || process.env.npm_config_build_from_source === 'true' } From 9bcfec92f9f825c3decf4e038f88e75567a43828 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Nov 2022 23:23:00 -0800 Subject: [PATCH 4/6] fix: fix spawning node-gyp-build-test --- .gitattributes | 1 + bin.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcadb2c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf diff --git a/bin.js b/bin.js index 0c7309b..f8ed811 100755 --- a/bin.js +++ b/bin.js @@ -5,7 +5,7 @@ var os = require('os') var path = require('path') if (!buildFromSource()) { - proc.exec('node-gyp-build-test', function (err, stdout, stderr) { + proc.exec(process.execPath, ['node-gyp-build-test'], function (err, stdout, stderr) { if (err) { if (verbose()) console.error(stderr) preinstall() From 4a173b44268085f66e5431fb5b552ea77e38c048 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Nov 2022 23:31:00 -0800 Subject: [PATCH 5/6] fix: use absolute paths for the scripts --- bin.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin.js b/bin.js index f8ed811..151cbd1 100755 --- a/bin.js +++ b/bin.js @@ -5,7 +5,8 @@ var os = require('os') var path = require('path') if (!buildFromSource()) { - proc.exec(process.execPath, ['node-gyp-build-test'], function (err, stdout, stderr) { + proc.exec(process.execPath, [path.join(__dirname, 'build-test.js')], function (err, stdout, stderr) { + console.log(stdout) if (err) { if (verbose()) console.error(stderr) preinstall() @@ -36,7 +37,7 @@ function build () { function preinstall () { try { // try to load the prebuild - const load = require('node-gyp-build/index.js') + const load = require(path.join(__dirname, 'index.js')) load() } catch (err) { // report the error and fall to a build From cfb83ce99138201d09350b6dcb2d94c764de87f0 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Nov 2022 23:39:04 -0800 Subject: [PATCH 6/6] fix: add logging for the build-test execution --- build-test.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build-test.js b/build-test.js index b6622a5..aa06cbb 100755 --- a/build-test.js +++ b/build-test.js @@ -3,6 +3,8 @@ process.env.NODE_ENV = 'test' var path = require('path') + +// find the test command from package.json prebuild.test entry var test = null try { @@ -15,5 +17,12 @@ try { // do nothing } -if (test) require(path.join(process.cwd(), test)) -else require('./')() +if (test) { + const testPath = path.join(process.cwd(), test) + console.log(`Running require("${testPath}")`) + require(testPath) +} +else { + console.log(`Running require("./")() at ${process.cwd()}`) + require('./')() +}