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 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/README.md b/README.md index f056002..7c29b68 100644 --- a/README.md +++ b/README.md @@ -2,47 +2,51 @@ [![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://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) -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. +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: ```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": { "napi_versions": [2,3] } -``` +``` + +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 Node-API version will continue to operate indefinitely, even as later versions of Node-API are introduced. -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. +## History -Modules that are built against a specific N-API version will continue to operate indefinitely, even as later versions of N-API are introduced. +**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. 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 diff --git a/index.js b/index.js index 1643994..d143d5d 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. @@ -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 }; @@ -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. @@ -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..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": { @@ -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) }