From 7fa7a2f40f8d2b55d43dfcd736418952170a3fe2 Mon Sep 17 00:00:00 2001 From: Jim Schlight Date: Mon, 13 Jan 2025 14:22:40 -0800 Subject: [PATCH 1/8] Fix typos and md lint errors Fixes #6 --- README.md | 20 ++++++++++---------- index.js | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f056002..e12d5d3 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,24 @@ [![npm](https://img.shields.io/npm/v/napi-build-utils.svg)](https://www.npmjs.com/package/napi-build-utils) ![Node version](https://img.shields.io/node/v/prebuild.svg) -[![Build Status](https://travis-ci.org/inspiredware/napi-build-utils.svg?branch=master)](https://travis-ci.org/inspiredware/napi-build-utils) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![Build Status](https://travis-ci.org/inspiredware/napi-build-utils.svg?branch=master)](https://travis-ci.org/inspiredware/napi-build-utils) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) A set of utilities to assist developers of tools that build [N-API](https://nodejs.org/api/n-api.html#n_api_n_api) native add-ons. ## Background -This module is targeted to developers creating tools that build N-API native add-ons. +This module is targeted to developers creating tools that build N-API native add-ons. -It implements a set of functions that aid in determining the N-API version supported by the currently running Node instance and the set of N-API versions against which the N-API native add-on is designed to be built. Other functions determine whether a particular N-API version can be built and can issue console warnings for unsupported N-API versions. +It implements a set of functions that aid in determining the N-API version supported by the currently running Node instance and the set of N-API versions against which the N-API native add-on is designed to be built. Other functions determine whether a particular N-API version can be built and can issue console warnings for unsupported N-API versions. -Unlike the modules this code is designed to facilitate building, this module is written entirely in JavaScript. +Unlike the modules this code is designed to facilitate building, this module is written entirely in JavaScript. ## Quick start ```bash -$ npm install napi-build-utils +npm install napi-build-utils ``` The module exports a set of functions documented [here](./index.md). For example: @@ -37,11 +37,11 @@ Native modules that are designed to work with [N-API](https://nodejs.org/api/n-a "binary": { "napi_versions": [2,3] } -``` +``` -In the absence of a need to compile against a specific N-API version, the value `3` is a good choice as this is the N-API version that was supported when N-API left experimental status. +In the absence of a need to compile against a specific N-API version, the value `3` is a good choice as this is the N-API version that was supported when N-API left experimental status. -Modules that are built against a specific N-API version will continue to operate indefinitely, even as later versions of N-API are introduced. +Modules that are built against a specific N-API version will continue to operate indefinitely, even as later versions of N-API are introduced. ## Support diff --git a/index.js b/index.js index 1643994..ada278a 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,7 @@ exports.isSupportedVersion = function (napiVersion) { /** * Determines whether the specified N-API version is supported by the package. - * The N-API version must be preseent in the `package.json` + * The N-API version must be present in the `package.json` * `binary.napi_versions` array. * * @param {number} napiVersion The N-API version to check. @@ -134,7 +134,7 @@ exports.logMissingNapiVersions = function (target, prebuild, log) { * Determines whether the specified N-API version exists in the prebuild * configuration object. * - * Note that this function is speicifc to the `prebuild` and `prebuild-install` + * Note that this function is specific to the `prebuild` and `prebuild-install` * packages. * * @param {Object} prebuild A config object created by the `prebuild` package. From 98fa3e961ce98eebd8811cac811b84f4856e45c2 Mon Sep 17 00:00:00 2001 From: Jim Schlight Date: Thu, 16 Jan 2025 15:14:24 -0800 Subject: [PATCH 2/8] Add GitHub Action for npm tests Fixes #6 --- .github/workflows/run-npm-tests.yml | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/run-npm-tests.yml diff --git a/.github/workflows/run-npm-tests.yml b/.github/workflows/run-npm-tests.yml new file mode 100644 index 0000000..3298868 --- /dev/null +++ b/.github/workflows/run-npm-tests.yml @@ -0,0 +1,31 @@ +name: Run npm Tests + +on: + workflow_dispatch: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [22, 23] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test \ No newline at end of file From 99ff9a5c07d37d0d58094eff2831c48a344fec45 Mon Sep 17 00:00:00 2001 From: Jim Schlight Date: Thu, 16 Jan 2025 15:20:49 -0800 Subject: [PATCH 3/8] Update GitHub Action to register it Fixes #6 --- .github/workflows/run-npm-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-npm-tests.yml b/.github/workflows/run-npm-tests.yml index 3298868..19910df 100644 --- a/.github/workflows/run-npm-tests.yml +++ b/.github/workflows/run-npm-tests.yml @@ -3,7 +3,7 @@ name: Run npm Tests on: workflow_dispatch: push: - branches: [ "main" ] + branches: [ "main", "jschlight/issue6" ] pull_request: branches: [ "main" ] From 1bfd1c4122b24acd531a6d2d83d7b116fb49f6c6 Mon Sep 17 00:00:00 2001 From: Jim Schlight Date: Thu, 16 Jan 2025 15:25:25 -0800 Subject: [PATCH 4/8] Update code for Node-API v10 Fixes #6 --- index.js | 11 ++++++----- index.md | 4 ++-- package.json | 3 ++- test/test.js | 7 +++++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index ada278a..d143d5d 100644 --- a/index.js +++ b/index.js @@ -56,7 +56,7 @@ exports.isSupportedVersion = function (napiVersion) { */ exports.packageSupportsVersion = function (napiVersion) { if (pkg.binary && pkg.binary.napi_versions && - pkg.binary.napi_versions instanceof Array) { + pkg.binary.napi_versions instanceof Array) { // integer array for (var i = 0; i < pkg.binary.napi_versions.length; i++) { if (pkg.binary.napi_versions[i] === napiVersion) return true }; @@ -165,10 +165,11 @@ var prebuildExists = function (prebuild, napiVersion) { */ exports.getBestNapiBuildVersion = function () { var bestNapiBuildVersion = 0 - var napiBuildVersions = exports.getNapiBuildVersions(pkg) + var napiBuildVersions = exports.getNapiBuildVersions(pkg) // array of integer strings if (napiBuildVersions) { var ourNapiVersion = exports.getNapiVersion() - napiBuildVersions.forEach(function (napiBuildVersion) { + napiBuildVersions.forEach(function (napiBuildVersionStr) { + var napiBuildVersion = parseInt(napiBuildVersionStr, 10) if (napiBuildVersion > bestNapiBuildVersion && napiBuildVersion <= ourNapiVersion) { bestNapiBuildVersion = napiBuildVersion @@ -181,7 +182,7 @@ exports.getBestNapiBuildVersion = function () { /** * Returns an array of N-API versions supported by the package. * - * @returns {Array} + * @returns {Array|undefined} */ exports.getNapiBuildVersions = function () { var napiBuildVersions = [] @@ -204,7 +205,7 @@ exports.getNapiBuildVersions = function () { * @returns {string|undefined} */ exports.getNapiVersion = function () { - var version = process.versions.napi // string, can be undefined + var version = process.versions.napi // integer string, can be undefined if (!version) { // this code should never need to be updated if (versionArray[0] === 9 && versionArray[1] >= 3) version = '2' // 9.3.0+ else if (versionArray[0] === 8) version = '1' // 8.0.0+ diff --git a/index.md b/index.md index ce8d3e8..6bb26b7 100644 --- a/index.md +++ b/index.md @@ -13,7 +13,7 @@ The main repository can be found * [.isSupportedVersion(napiVersion)](#module_napi-build-utils.isSupportedVersion) ⇒ boolean * [.logUnsupportedVersion(napiVersion, log)](#module_napi-build-utils.logUnsupportedVersion) * [.getBestNapiBuildVersion()](#module_napi-build-utils.getBestNapiBuildVersion) ⇒ number \| undefined - * [.getNapiBuildVersions()](#module_napi-build-utils.getNapiBuildVersions) ⇒ Array.<string> + * [.getNapiBuildVersions()](#module_napi-build-utils.getNapiBuildVersions) ⇒ [ 'Array' ].<string> * [.getNapiVersion()](#module_napi-build-utils.getNapiVersion) ⇒ string \| undefined @@ -68,7 +68,7 @@ supported by the current Node instance. **Kind**: static method of [napi-build-utils](#module_napi-build-utils) -### napi-build-utils.getNapiBuildVersions() ⇒ Array.<string> +### napi-build-utils.getNapiBuildVersions() ⇒ [ 'Array' ].<string> Returns an array of N-API versions supported by the package. **Kind**: static method of [napi-build-utils](#module_napi-build-utils) diff --git a/package.json b/package.json index 76cc948..be70640 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "napi_versions": [ 2, 2, - 3 + 3, + 10 ] } } diff --git a/test/test.js b/test/test.js index c8e3ed4..33ba248 100644 --- a/test/test.js +++ b/test/test.js @@ -20,7 +20,7 @@ describe('napi-build-utils', function () { manifest.binary.should.have.property('note') manifest.binary.should.have.property('napi_versions') manifest.binary.napi_versions.should.be.instanceof(Array) - manifest.binary.napi_versions.length.should.equal(3) + manifest.binary.napi_versions.length.should.equal(4) }) it('isNapiRuntime', () => { let isNapi = utils.isNapiRuntime('napi') @@ -40,9 +40,10 @@ describe('napi-build-utils', function () { it('getNapiBuildVersions', function () { let buildVersions = utils.getNapiBuildVersions() buildVersions.should.be.instanceof(Array) - buildVersions.length.should.equal(2) + buildVersions.length.should.equal(3) buildVersions[0].should.equal('2') buildVersions[1].should.equal('3') + buildVersions[2].should.equal('10') }) it('packageSupportsVersion', function () { utils.packageSupportsVersion(1).should.equal(false) @@ -74,6 +75,8 @@ describe('napi-build-utils', function () { bestBuildVersion.should.equal(2) } else if (napiVersion === 3) { bestBuildVersion.should.equal(3) + } else if (napiVersion >= 10) { + bestBuildVersion.should.equal(10) } else { bestBuildVersion.should.equal(3) } From 9d3740d95ad4f6a9f477e25c78d410fcdfb7d4c2 Mon Sep 17 00:00:00 2001 From: Jim Schlight Date: Thu, 16 Jan 2025 15:33:40 -0800 Subject: [PATCH 5/8] Remove obsolete CI files Fixes #6 --- .travis.yml | 14 -------------- appveyor.yml | 42 ------------------------------------------ 2 files changed, 56 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a52b490..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: node_js - -os: - - linux - - osx - -node_js: - - 13 - - 12 - - 11 - - 10 - - 9 - - 8 - - 6 diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 8457a27..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,42 +0,0 @@ -# http://www.appveyor.com/docs/appveyor-yml - -# Don't actually build -build: off - -# Skip tag builds -skip_tags: true - -# Set build version format -version: "{build}" - -# Set up build environment -environment: - # Test against these versions of Node.js - matrix: - - nodejs_version: "13" - - nodejs_version: "12" - - nodejs_version: "11" - - nodejs_version: "10" - - nodejs_version: "9" - - nodejs_version: "8" - - nodejs_version: "6" - -# Build on both platforms -platform: - - x86 - - x64 - -# Install scripts (runs after repo cloning) -install: - # Get the latest version of $env:nodejs_version - - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:platform - # Output useful info for debugging - - node --version - - npm --version - # Install modules - - npm install - -# Post-install test scripts -test_script: - # Run module tests - - npm test From 446561288c19a799e1dd715cca74c8ea81b7a3f8 Mon Sep 17 00:00:00 2001 From: Jim Schlight Date: Thu, 16 Jan 2025 15:45:05 -0800 Subject: [PATCH 6/8] Update README FIxes #6 --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e12d5d3..a126c74 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,17 @@ [![npm](https://img.shields.io/npm/v/napi-build-utils.svg)](https://www.npmjs.com/package/napi-build-utils) ![Node version](https://img.shields.io/node/v/prebuild.svg) -[![Build Status](https://travis-ci.org/inspiredware/napi-build-utils.svg?branch=master)](https://travis-ci.org/inspiredware/napi-build-utils) +[![Build Status](https://github.com/inspiredware/napi-build-utils/actions/workflows/run-npm-tests.yml/badge.svg?branch=jschlight/issue6)](https://travis-ci.org/inspiredware/napi-build-utils) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -A set of utilities to assist developers of tools that build [N-API](https://nodejs.org/api/n-api.html#n_api_n_api) native add-ons. +A set of utilities to assist developers of tools that build [Node-API](https://nodejs.org/api/n-api.html#n_api_n_api) native add-ons. ## Background -This module is targeted to developers creating tools that build N-API native add-ons. +This module is targeted to developers creating tools that build Node-API native add-ons. -It implements a set of functions that aid in determining the N-API version supported by the currently running Node instance and the set of N-API versions against which the N-API native add-on is designed to be built. Other functions determine whether a particular N-API version can be built and can issue console warnings for unsupported N-API versions. +It implements a set of functions that aid in determining the Node-API version supported by the currently running Node instance and the set of Node-API versions against which the Node-API native add-on is designed to be built. Other functions determine whether a particular Node-API version can be built and can issue console warnings for unsupported Node-API versions. Unlike the modules this code is designed to facilitate building, this module is written entirely in JavaScript. @@ -26,12 +26,12 @@ The module exports a set of functions documented [here](./index.md). For example ```javascript var napiBuildUtils = require('napi-build-utils'); -var napiVersion = napiBuildUtils.getNapiVersion(); // N-API version supported by Node, or undefined. +var napiVersion = napiBuildUtils.getNapiVersion(); // Node-API version supported by Node, or undefined. ``` -## Declaring supported N-API versions +## Declaring supported Node-API versions -Native modules that are designed to work with [N-API](https://nodejs.org/api/n-api.html#n_api_n_api) must explicitly declare the N-API version(s) against which they are coded to build. This is accomplished by including a `binary.napi_versions` property in the module's `package.json` file. For example: +Native modules that are designed to work with [Node-API](https://nodejs.org/api/n-api.html#n_api_n_api) must explicitly declare the Node-API version(s) against which they are coded to build. This is accomplished by including a `binary.napi_versions` property in the module's `package.json` file. For example: ```json "binary": { @@ -39,9 +39,9 @@ Native modules that are designed to work with [N-API](https://nodejs.org/api/n-a } ``` -In the absence of a need to compile against a specific N-API version, the value `3` is a good choice as this is the N-API version that was supported when N-API left experimental status. +In the absence of a need to compile against a specific Node-API version, the value `3` is a good choice as this is the Node-API version that was supported when Node-API left experimental status. -Modules that are built against a specific N-API version will continue to operate indefinitely, even as later versions of N-API are introduced. +Modules that are built against a specific Node-API version will continue to operate indefinitely, even as later versions of Node-API are introduced. ## Support From 985269833dd91e7603edc8b915bea5095588a399 Mon Sep 17 00:00:00 2001 From: Jim Schlight Date: Thu, 16 Jan 2025 18:57:20 -0800 Subject: [PATCH 7/8] Update README, remove dev branch dependencies Fixes #6 --- .github/workflows/run-npm-tests.yml | 2 +- README.md | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-npm-tests.yml b/.github/workflows/run-npm-tests.yml index 19910df..3298868 100644 --- a/.github/workflows/run-npm-tests.yml +++ b/.github/workflows/run-npm-tests.yml @@ -3,7 +3,7 @@ name: Run npm Tests on: workflow_dispatch: push: - branches: [ "main", "jschlight/issue6" ] + branches: [ "main" ] pull_request: branches: [ "main" ] diff --git a/README.md b/README.md index a126c74..7c29b68 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![npm](https://img.shields.io/npm/v/napi-build-utils.svg)](https://www.npmjs.com/package/napi-build-utils) ![Node version](https://img.shields.io/node/v/prebuild.svg) -[![Build Status](https://github.com/inspiredware/napi-build-utils/actions/workflows/run-npm-tests.yml/badge.svg?branch=jschlight/issue6)](https://travis-ci.org/inspiredware/napi-build-utils) +![Build Status](https://github.com/inspiredware/napi-build-utils/actions/workflows/run-npm-tests.yml/badge.svg) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) @@ -43,6 +43,10 @@ In the absence of a need to compile against a specific Node-API version, the val Modules that are built against a specific Node-API version will continue to operate indefinitely, even as later versions of Node-API are introduced. +## History + +**v2.0.0** This version was introduced to address a limitation when the Node-API version reached `10` in NodeJS `v23.6.0`. There was no change in the API, but a SemVer bump to `2.0.0` was made out of an abundance of caution. + ## Support -If you run into problems or limitations, please file an issue and we'll take a look. Pull requests are also welcome. +If you run into problems or limitations, please file an issue and we'll take a look. Pull requests are also welcome. From 8377c1c1e9f3e0a0e904ec31a4aa5058c4ab1785 Mon Sep 17 00:00:00 2001 From: Jim Schlight Date: Thu, 16 Jan 2025 19:02:46 -0800 Subject: [PATCH 8/8] Bump package version to 2.0.0 FIxes #6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be70640..3c118f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "napi-build-utils", - "version": "1.0.2", + "version": "2.0.0", "description": "A set of utilities to assist developers of tools that build N-API native add-ons", "main": "index.js", "scripts": {