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 7ca3ab5..151cbd1 100755 --- a/bin.js +++ b/bin.js @@ -5,7 +5,8 @@ var os = require('os') var path = require('path') if (!buildFromSource()) { - proc.exec('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() @@ -30,35 +31,19 @@ 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) - }) }) } 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(path.join(__dirname, 'index.js')) + load() + } catch (err) { + // report the error and fall to a build + console.error(err.message) build() - }) -} - -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 () { 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('./')() +}