Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- add test, that uses "real worlds scenario" by using really parsed options, not just artificially generated options
- to make this tests possible, I had to factor the function, that parses teh args out, and make a separate file
  • Loading branch information
Totto16 committed May 27, 2024
1 parent 7c86817 commit fdf9a22
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 27 deletions.
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()
})
})

0 comments on commit fdf9a22

Please sign in to comment.