napi-build-utils
Advanced tools
Comparing version
15
index.js
@@ -50,3 +50,3 @@ 'use strict' | ||
* 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. | ||
@@ -60,3 +60,3 @@ * | ||
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++) { | ||
@@ -139,3 +139,3 @@ if (pkg.binary.napi_versions[i] === napiVersion) return true | ||
* | ||
* 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. | ||
@@ -171,6 +171,7 @@ * | ||
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 && | ||
@@ -188,3 +189,3 @@ napiBuildVersion <= ourNapiVersion) { | ||
* | ||
* @returns {Array<string>} | ||
* @returns {Array<string>|undefined} | ||
*/ | ||
@@ -212,3 +213,3 @@ exports.getNapiBuildVersions = function () { | ||
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 | ||
@@ -215,0 +216,0 @@ if (versionArray[0] === 9 && versionArray[1] >= 3) version = '2' // 9.3.0+ |
{ | ||
"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", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"lint": "standard", | ||
"prepublishOnly": "npm run test && npm run doc" | ||
"prepublishOnly": "npm run test" | ||
}, | ||
@@ -39,5 +39,6 @@ "keywords": [ | ||
2, | ||
3 | ||
3, | ||
10 | ||
] | ||
} | ||
} |
@@ -5,15 +5,15 @@ # napi-build-utils | ||
 | ||
[](https://travis-ci.org/inspiredware/napi-build-utils) | ||
[](http://standardjs.com/) | ||
[](https://opensource.org/licenses/MIT) | ||
 | ||
[](http://standardjs.com/) | ||
[](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. | ||
@@ -23,3 +23,3 @@ ## Quick start | ||
```bash | ||
$ npm install napi-build-utils | ||
npm install napi-build-utils | ||
``` | ||
@@ -31,8 +31,8 @@ | ||
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: | ||
@@ -43,10 +43,14 @@ ```json | ||
} | ||
``` | ||
``` | ||
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. | ||
## 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. |
6
20%202
0.5%53
8.16%12670
-18.38%