Skip to content

Commit

Permalink
tag prebuilds with pkg name
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Jan 7, 2024
1 parent 9a2bf62 commit 7b6dcbd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var prebuildify = require('./index')

var argv = minimist(process.argv.slice(2), {
alias: {
name: 'n',
target: 't',
version: 'v',
all: 'a',
Expand Down
34 changes: 26 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ function prebuildify (opts, cb) {
// over the local .bin folder. Counter that by (again) adding .bin to PATH.
opts.env = npmRunPath.env({ env: opts.env, cwd: opts.cwd })

mkdirp(opts.builds, function (err) {
addName(opts, function (err) {
if (err) return cb(err)
loop(opts, function (err) {
mkdirp(opts.builds, function (err) {
if (err) return cb(err)
loop(opts, function (err) {
if (err) return cb(err)

if (opts.artifacts) return copyRecursive(opts.artifacts, opts.builds, cb)
return cb()
if (opts.artifacts) return copyRecursive(opts.artifacts, opts.builds, cb)
return cb()
})
})
})
}
Expand Down Expand Up @@ -108,12 +111,27 @@ function loop (opts, cb) {
})
}

function addName (opts, cb) {
if (opts.name) return cb()
fs.readFile(path.join(opts.cwd, 'package.json'), 'utf-8', function (err, pkg) {
if (err) return cb()
try {
opts.name = JSON.parse(pkg).name
} catch (err) {
// do nothing
}
cb()
})
}

function encodeName (name) {
return name.replace(/\//g, '+')
}

function prebuildName (target, opts) {
var tags = [target.runtime]
var tags = [encodeName(opts.name || target.runtime)]

if (opts.napi) {
tags.push('napi')
} else {
if (!opts.napi) {
tags.push('abi' + abi.getAbi(target.target, target.runtime))
}

Expand Down
6 changes: 3 additions & 3 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('build with current node version', function (t) {
t.ifError(err)
t.doesNotThrow(function () {
var folder = os.platform() + '-' + os.arch()
var name = 'node.abi' + process.versions.modules + '.node'
var name = 'addon.abi' + process.versions.modules + '.node'
var addon = require(path.join(__dirname, 'package', 'prebuilds', folder, name))
t.equal(addon.check(), 'prebuildify')
})
Expand All @@ -25,14 +25,14 @@ test('uv, armv and libc tags', function (t) {
cwd: path.join(__dirname, 'package'),
targets: [{ runtime: 'node', target: process.version }],
tagUv: 123,
tagArmv: true, // Should be excluded (unless you run these tests on ARM)
tagArmv: false, // Should be excluded (unless you run these tests on ARM)
tagLibc: true // Should be glibc (unless you run these tests on Alpine)
}, function (err) {
t.ifError(err)
t.doesNotThrow(function () {
var folder = os.platform() + '-' + os.arch()
var name = [
'node',
'addon',
'abi' + process.versions.modules,
'uv123',
'glibc',
Expand Down

0 comments on commit 7b6dcbd

Please sign in to comment.