From 2bc7411e4da9b7d6ae91ad35143f3bcc4a2cbe43 Mon Sep 17 00:00:00 2001 From: Tim Strazzere Date: Thu, 7 Mar 2024 10:49:05 -0800 Subject: [PATCH 1/2] (fix) Ensure runtime and napi are emitted as needed. Per issue #79 there seems to be a regression introduced in 7b6dcbd which caused the `target.runtime` to no longer be emitted when a name is used. A name is also _always_ used even if not passed, as it will grab a name from the `package.json`. This commit also dropped including the `napi` tag, which is still utilized downstream. This change fixes the regression and follows this logic; 1. Emit `name` as a tag (this will always be true due to `addName` function logic) 2. Emit `runtime` as a tag always 3. Emit `napi` as a tag if option enabled (likely always true, as it if defaulted to true) --- index.js | 12 ++++++++++-- test/api.js | 27 ++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index ca9829a..f7dac27 100644 --- a/index.js +++ b/index.js @@ -129,9 +129,17 @@ function encodeName (name) { } function prebuildName (target, opts) { - var tags = [encodeName(opts.name || target.runtime)] + var tags = [] - if (!opts.napi) { + if (opts.name) { + tags.push(encodeName(opts.name)) + } + + tags.push(target.runtime) + + if (opts.napi) { + tags.push('napi') + } else { tags.push('abi' + abi.getAbi(target.target, target.runtime)) } diff --git a/test/api.js b/test/api.js index bd6731c..cbfc7df 100644 --- a/test/api.js +++ b/test/api.js @@ -12,7 +12,31 @@ test('build with current node version', function (t) { t.ifError(err) t.doesNotThrow(function () { var folder = os.platform() + '-' + os.arch() - var name = 'addon.abi' + process.versions.modules + '.node' + var name = 'addon.node.abi' + process.versions.modules + '.node' + var addon = require(path.join(__dirname, 'package', 'prebuilds', folder, name)) + t.equal(addon.check(), 'prebuildify') + }) + t.end() + }) +}) + +test('runtime napi flags', function (t) { + prebuildify({ + cwd: path.join(__dirname, 'package'), + targets: [{ runtime: 'node', target: process.version }], + napi: true, + 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 = [ + 'addon', + 'node', + 'napi', + 'glibc', + 'node' + ].join('.') var addon = require(path.join(__dirname, 'package', 'prebuilds', folder, name)) t.equal(addon.check(), 'prebuildify') }) @@ -33,6 +57,7 @@ test('uv, armv and libc tags', function (t) { var folder = os.platform() + '-' + os.arch() var name = [ 'addon', + 'node', 'abi' + process.versions.modules, 'uv123', 'glibc', From d1d2de820a448b49e2068be5fa46d0a69f838eee Mon Sep 17 00:00:00 2001 From: Tim Strazzere Date: Mon, 11 Mar 2024 09:33:01 -0700 Subject: [PATCH 2/2] Do not emit runtime if name available --- index.js | 8 +------- test/api.js | 4 +--- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index f7dac27..732e835 100644 --- a/index.js +++ b/index.js @@ -129,13 +129,7 @@ function encodeName (name) { } function prebuildName (target, opts) { - var tags = [] - - if (opts.name) { - tags.push(encodeName(opts.name)) - } - - tags.push(target.runtime) + var tags = [encodeName(opts.name || target.runtime)] if (opts.napi) { tags.push('napi') diff --git a/test/api.js b/test/api.js index cbfc7df..a8e378d 100644 --- a/test/api.js +++ b/test/api.js @@ -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 = 'addon.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') }) @@ -32,7 +32,6 @@ test('runtime napi flags', function (t) { var folder = os.platform() + '-' + os.arch() var name = [ 'addon', - 'node', 'napi', 'glibc', 'node' @@ -57,7 +56,6 @@ test('uv, armv and libc tags', function (t) { var folder = os.platform() + '-' + os.arch() var name = [ 'addon', - 'node', 'abi' + process.versions.modules, 'uv123', 'glibc',