Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle Override of napi on manually specifying targets #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions bin.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"files": [
"bin.js",
"index.js"
"index.js",
"parse.js"
],
"scripts": {
"lint": "standard",
Expand Down
33 changes: 33 additions & 0 deletions parse.js
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
})
})