diff --git a/bin.js b/bin.js index 21a09d9..63518d4 100755 --- a/bin.js +++ b/bin.js @@ -1,33 +1,10 @@ #!/usr/bin/env node -var minimist = require('minimist') -var prebuildify = require('./index') -var argv = minimist(process.argv.slice(2), { - alias: { - name: 'n', - target: 't', - version: 'v', - all: 'a', - napi: 'n-api', - stripBin: 'strip-bin', - nodeGyp: 'node-gyp', - tagUv: 'tag-uv', - tagArmv: 'tag-armv', - tagLibc: 'tag-libc', - electronCompat: 'electron-compat', - cache: 'c' - }, - boolean: ['quiet', 'strip', 'napi', 'debug', 'all', 'electron-compat'], - default: { - napi: true - } -}) - -argv.targets = [].concat(argv.target || []) -argv.cwd = argv.cwd || argv._[0] || '.' +var prebuildify = require('./index') +var parseArgs = require('./parse.js') -prebuildify(argv, function (err) { +prebuildify(parseArgs(process.argv.slice(2)), function (err) { if (err) { console.error(err.message || err) process.exit(1) diff --git a/index.js b/index.js index 7729aaf..ac7d574 100644 --- a/index.js +++ b/index.js @@ -35,6 +35,11 @@ function prebuildify (opts, cb) { opts.out = opts.cwd } + // if we supply some targets manually, disable the napi build + if (opts.targets.length !== 0) { + opts.napi = false; + } + var targets = resolveTargets(opts.targets, opts.all, opts.napi, opts.electronCompat) if (!targets.length) { diff --git a/package.json b/package.json index 9b89d71..fe165e9 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ }, "files": [ "bin.js", - "index.js" + "index.js", + "parse.js" ], "scripts": { "lint": "standard", diff --git a/parse.js b/parse.js new file mode 100644 index 0000000..141a202 --- /dev/null +++ b/parse.js @@ -0,0 +1,33 @@ + +var minimist = require('minimist') + +module.exports = parseArgs + +function parseArgs(argv) { + + var options = minimist(argv, { + alias: { + name: 'n', + target: 't', + version: 'v', + all: 'a', + napi: 'n-api', + stripBin: 'strip-bin', + nodeGyp: 'node-gyp', + tagUv: 'tag-uv', + tagArmv: 'tag-armv', + tagLibc: 'tag-libc', + electronCompat: 'electron-compat', + cache: 'c' + }, + boolean: ['quiet', 'strip', 'napi', 'debug', 'all', 'electron-compat'], + default: { + napi: true + } + }) + + options.targets = [].concat(options.target || []) + options.cwd = options.cwd || options._[0] || '.' + + return options +} diff --git a/test/api.js b/test/api.js index bd6731c..24b408e 100644 --- a/test/api.js +++ b/test/api.js @@ -2,6 +2,8 @@ var test = require('tape') var path = require('path') var os = require('os') var prebuildify = require('../') +var parseArgs = require('../parse.js') + var gt8 = process.version.match(/^v(\d+)\./)[1] > 8 test('build with current node version', function (t) { @@ -54,3 +56,25 @@ gt8 && test('prefers locally installed node-gyp bin', function (t) { t.end() }) }) + + +test('real world scenario: abi tags', function (t) { + + var parsedOpts = parseArgs(["-t", process.version]) + + prebuildify(parsedOpts, function (err) { + t.ifError(err) + t.doesNotThrow(function () { + var folder = os.platform() + '-' + os.arch() + var name = [ + 'addon', + 'abi' + process.versions.modules, + 'node' + ].join('.') + var addon = require(path.join(__dirname, 'package', 'prebuilds', folder, name)) + t.equal(addon.check(), 'prebuildify') + }) + t.end() + }) +}) +