diff options
| author | pack <pack@packgekko.xyz> | 2026-08-09 10:37:07 +0000 |
|---|---|---|
| committer | pack <pack@packgekko.xyz> | 2026-08-09 10:37:07 +0000 |
| commit | 55a4f1fc869e41aca748c63d3018f0448b1606e0 (patch) | |
| tree | d132d1d01772b6d53faee3e63c534dea5706b78a /node_modules/napi-build-utils | |
| download | crud-55a4f1fc869e41aca748c63d3018f0448b1606e0.tar.gz | |
first commit
Diffstat (limited to '')
| -rw-r--r-- | node_modules/napi-build-utils/.github/workflows/run-npm-tests.yml | 31 | ||||
| -rw-r--r-- | node_modules/napi-build-utils/LICENSE | 21 | ||||
| -rw-r--r-- | node_modules/napi-build-utils/README.md | 52 | ||||
| -rw-r--r-- | node_modules/napi-build-utils/index.js | 214 | ||||
| -rw-r--r-- | node_modules/napi-build-utils/index.md | 0 | ||||
| -rw-r--r-- | node_modules/napi-build-utils/package.json | 42 |
6 files changed, 360 insertions, 0 deletions
diff --git a/node_modules/napi-build-utils/.github/workflows/run-npm-tests.yml b/node_modules/napi-build-utils/.github/workflows/run-npm-tests.yml new file mode 100644 index 0000000..3298868 --- /dev/null +++ b/node_modules/napi-build-utils/.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/node_modules/napi-build-utils/LICENSE b/node_modules/napi-build-utils/LICENSE new file mode 100644 index 0000000..8e0248a --- /dev/null +++ b/node_modules/napi-build-utils/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 inspiredware + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/napi-build-utils/README.md b/node_modules/napi-build-utils/README.md new file mode 100644 index 0000000..7c29b68 --- /dev/null +++ b/node_modules/napi-build-utils/README.md @@ -0,0 +1,52 @@ +# napi-build-utils + +[](https://www.npmjs.com/package/napi-build-utils) + + +[](http://standardjs.com/) +[](https://opensource.org/licenses/MIT) + +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 Node-API native add-ons. + +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. + +## Quick start + +```bash +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(); // Node-API version supported by Node, or undefined. +``` + +## Declaring supported Node-API versions + +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. + +## 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. diff --git a/node_modules/napi-build-utils/index.js b/node_modules/napi-build-utils/index.js new file mode 100644 index 0000000..d143d5d --- /dev/null +++ b/node_modules/napi-build-utils/index.js @@ -0,0 +1,214 @@ +'use strict' +// Copyright (c) 2018 inspiredware + +var path = require('path') +var pkg = require(path.resolve('package.json')) + +var versionArray = process.version + .substr(1) + .replace(/-.*$/, '') + .split('.') + .map(function (item) { + return +item + }) + +/** + * + * 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. + * + * The main repository can be found + * [here](https://github.com/inspiredware/napi-build-utils#napi-build-utils). + * + * @module napi-build-utils + */ + +/** + * Implements a consistent name of `napi` for N-API runtimes. + * + * @param {string} runtime The runtime string. + * @returns {boolean} + */ +exports.isNapiRuntime = function (runtime) { + return runtime === 'napi' +} + +/** + * Determines whether the specified N-API version is supported + * by both the currently running Node instance and the package. + * + * @param {string} napiVersion The N-API version to check. + * @returns {boolean} + */ +exports.isSupportedVersion = function (napiVersion) { + var version = parseInt(napiVersion, 10) + return version <= exports.getNapiVersion() && exports.packageSupportsVersion(version) +} + +/** + * Determines whether the specified N-API version is supported by the package. + * The N-API version must be present in the `package.json` + * `binary.napi_versions` array. + * + * @param {number} napiVersion The N-API version to check. + * @returns {boolean} + * @private + */ +exports.packageSupportsVersion = function (napiVersion) { + if (pkg.binary && pkg.binary.napi_versions && + 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 + }; + }; + return false +} + +/** + * Issues a warning to the supplied log if the N-API version is not supported + * by the current Node instance or if the N-API version is not supported + * by the package. + * + * @param {string} napiVersion The N-API version to check. + * @param {Object} log The log object to which the warnings are to be issued. + * Must implement the `warn` method. + */ +exports.logUnsupportedVersion = function (napiVersion, log) { + if (!exports.isSupportedVersion(napiVersion)) { + if (exports.packageSupportsVersion(napiVersion)) { + log.warn('This Node instance does not support N-API version ' + napiVersion) + } else { + log.warn('This package does not support N-API version ' + napiVersion) + } + } +} + +/** + * Issues warnings to the supplied log for those N-API versions not supported + * by the N-API runtime or the package. + * + * Note that this function is specific to the + * [`prebuild`](https://github.com/prebuild/prebuild#prebuild) package. + * + * `target` is the list of targets to be built and is determined in one of + * three ways from the command line arguments: + * (1) `--target` specifies a specific target to build. + * (2) `--all` specifies all N-API versions supported by the package. + * (3) Neither of these specifies to build the single "best version available." + * + * `prebuild` is an array of objects in the form `{runtime: 'napi', target: '2'}`. + * The array contains the list of N-API versions that are supported by both the + * package being built and the currently running Node instance. + * + * The objective of this function is to issue a warning for those items that appear + * in the `target` argument but not in the `prebuild` argument. + * If a specific target is supported by the package (`packageSupportsVersion`) but + * but note in `prebuild`, the assumption is that the target is not supported by + * Node. + * + * @param {(Array<string>|string)} target The N-API version(s) to check. Target is + * @param {Array<Object>} prebuild A config object created by the `prebuild` package. + * @param {Object} log The log object to which the warnings are to be issued. + * Must implement the `warn` method. + * @private + */ +exports.logMissingNapiVersions = function (target, prebuild, log) { + if (exports.getNapiBuildVersions()) { + var targets = [].concat(target) + targets.forEach(function (napiVersion) { + if (!prebuildExists(prebuild, napiVersion)) { + if (exports.packageSupportsVersion(parseInt(napiVersion, 10))) { + log.warn('This Node instance does not support N-API version ' + napiVersion) + } else { + log.warn('This package does not support N-API version ' + napiVersion) + } + } + }) + } else { + log.error('Builds with runtime \'napi\' require a binary.napi_versions ' + + 'property on the package.json file') + } +} + +/** + * Determines whether the specified N-API version exists in the prebuild + * configuration object. + * + * Note that this function is specific to the `prebuild` and `prebuild-install` + * packages. + * + * @param {Object} prebuild A config object created by the `prebuild` package. + * @param {string} napiVersion The N-APi version to be checked. + * @return {boolean} + * @private + */ +var prebuildExists = function (prebuild, napiVersion) { + if (prebuild) { + for (var i = 0; i < prebuild.length; i++) { + if (prebuild[i].target === napiVersion) return true + } + } + return false +} + +/** + * Returns the best N-API version to build given the highest N-API + * version supported by the current Node instance and the N-API versions + * supported by the package, or undefined if a suitable N-API version + * cannot be determined. + * + * The best build version is the greatest N-API version supported by + * the package that is less than or equal to the highest N-API version + * supported by the current Node instance. + * + * @returns {number|undefined} + */ +exports.getBestNapiBuildVersion = function () { + var bestNapiBuildVersion = 0 + var napiBuildVersions = exports.getNapiBuildVersions(pkg) // array of integer strings + if (napiBuildVersions) { + var ourNapiVersion = exports.getNapiVersion() + napiBuildVersions.forEach(function (napiBuildVersionStr) { + var napiBuildVersion = parseInt(napiBuildVersionStr, 10) + if (napiBuildVersion > bestNapiBuildVersion && + napiBuildVersion <= ourNapiVersion) { + bestNapiBuildVersion = napiBuildVersion + } + }) + } + return bestNapiBuildVersion === 0 ? undefined : bestNapiBuildVersion +} + +/** + * Returns an array of N-API versions supported by the package. + * + * @returns {Array<string>|undefined} + */ +exports.getNapiBuildVersions = function () { + var napiBuildVersions = [] + // remove duplicates, convert to text + if (pkg.binary && pkg.binary.napi_versions) { + pkg.binary.napi_versions.forEach(function (napiVersion) { + var duplicated = napiBuildVersions.indexOf('' + napiVersion) !== -1 + if (!duplicated) { + napiBuildVersions.push('' + napiVersion) + } + }) + } + return napiBuildVersions.length ? napiBuildVersions : undefined +} + +/** + * Returns the highest N-API version supported by the current node instance + * or undefined if N-API is not supported. + * + * @returns {string|undefined} + */ +exports.getNapiVersion = function () { + 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+ + } + return version +} diff --git a/node_modules/napi-build-utils/index.md b/node_modules/napi-build-utils/index.md new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/node_modules/napi-build-utils/index.md diff --git a/node_modules/napi-build-utils/package.json b/node_modules/napi-build-utils/package.json new file mode 100644 index 0000000..ad15183 --- /dev/null +++ b/node_modules/napi-build-utils/package.json @@ -0,0 +1,42 @@ +{ + "name": "napi-build-utils", + "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": { + "doc": "jsdoc2md index.js >index.md", + "test": "mocha test/ && npm run lint", + "lint": "standard", + "prepublishOnly": "npm run test" + }, + "keywords": [ + "n-api", + "prebuild", + "prebuild-install" + ], + "author": "Jim Schlight", + "license": "MIT", + "homepage": "https://github.com/inspiredware/napi-build-utils#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/inspiredware/napi-build-utils.git" + }, + "bugs": { + "url": "https://github.com/inspiredware/napi-build-utils/issues" + }, + "devDependencies": { + "chai": "^4.1.2", + "jsdoc-to-markdown": "^4.0.1", + "mocha": "^5.2.0", + "standard": "^12.0.1" + }, + "binary": { + "note": "napi-build-tools is not an N-API module. This entry is for unit testing.", + "napi_versions": [ + 2, + 2, + 3, + 10 + ] + } +} |