node-addon-api
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -119,2 +119,6 @@ { | ||
{ | ||
"name": "Jack Xia", | ||
"url": "https://github.com/JckXia" | ||
}, | ||
{ | ||
"name": "Jake Barnes", | ||
@@ -144,2 +148,6 @@ "url": "https://github.com/DuBistKomisch" | ||
{ | ||
"name": "José Expósito", | ||
"url": "https://github.com/JoseExposito" | ||
}, | ||
{ | ||
"name": "joshgarde", | ||
@@ -161,2 +169,6 @@ "url": "https://github.com/joshgarde" | ||
{ | ||
"name": "Kévin VOYER", | ||
"url": "https://github.com/kecsou" | ||
}, | ||
{ | ||
"name": "kidneysolo", | ||
@@ -182,2 +194,6 @@ "url": "https://github.com/kidneysolo" | ||
{ | ||
"name": "LongYinan", | ||
"url": "https://github.com/Brooooooklyn" | ||
}, | ||
{ | ||
"name": "Lovell Fuller", | ||
@@ -303,4 +319,3 @@ "url": "https://github.com/lovell" | ||
], | ||
"dependencies": {}, | ||
"description": "Node.js API (N-API)", | ||
"description": "Node.js API (Node-API)", | ||
"devDependencies": { | ||
@@ -337,2 +352,7 @@ "benchmark": "^2.1.4", | ||
}, | ||
"files": [ | ||
"*.{c,h,gyp,gypi}", | ||
"package-support.json", | ||
"tools/" | ||
], | ||
"scripts": { | ||
@@ -348,8 +368,8 @@ "prebenchmark": "node-gyp rebuild -C benchmark", | ||
"doc": "doxygen doc/Doxyfile", | ||
"lint": "node tools/clang-format.js", | ||
"lint:fix": "git-clang-format '*.h', '*.cc'" | ||
"lint": "node tools/clang-format", | ||
"lint:fix": "node tools/clang-format --fix" | ||
}, | ||
"pre-commit": "lint", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"support": true | ||
} |
114
README.md
@@ -0,16 +1,27 @@ | ||
NOTE: The default branch has been renamed! | ||
master is now named main | ||
If you have a local clone, you can update it by running: | ||
```shell | ||
git branch -m master main | ||
git fetch origin | ||
git branch -u origin/main main | ||
``` | ||
# **node-addon-api module** | ||
This module contains **header-only C++ wrapper classes** which simplify | ||
the use of the C based [N-API](https://nodejs.org/dist/latest/docs/api/n-api.html) | ||
the use of the C based [Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html) | ||
provided by Node.js when using C++. It provides a C++ object model | ||
and exception handling semantics with low overhead. | ||
There are three options for implementing addons: N-API, nan, or direct | ||
There are three options for implementing addons: Node-API, nan, or direct | ||
use of internal V8, libuv and Node.js libraries. Unless there is a need for | ||
direct access to functionality which is not exposed by N-API as outlined | ||
direct access to functionality which is not exposed by Node-API as outlined | ||
in [C/C++ addons](https://nodejs.org/dist/latest/docs/api/addons.html) | ||
in Node.js core, use N-API. Refer to | ||
[C/C++ addons with N-API](https://nodejs.org/dist/latest/docs/api/n-api.html) | ||
for more information on N-API. | ||
in Node.js core, use Node-API. Refer to | ||
[C/C++ addons with Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html) | ||
for more information on Node-API. | ||
N-API is an ABI stable C interface provided by Node.js for building native | ||
Node-API is an ABI stable C interface provided by Node.js for building native | ||
addons. It is independent from the underlying JavaScript runtime (e.g. V8 or ChakraCore) | ||
@@ -23,4 +34,4 @@ and is maintained as part of Node.js itself. It is intended to insulate | ||
The `node-addon-api` module, which is not part of Node.js, preserves the benefits | ||
of the N-API as it consists only of inline code that depends only on the stable API | ||
provided by N-API. As such, modules built against one version of Node.js | ||
of the Node-API as it consists only of inline code that depends only on the stable API | ||
provided by Node-API. As such, modules built against one version of Node.js | ||
using node-addon-api should run without having to be rebuilt with newer versions | ||
@@ -31,13 +42,13 @@ of Node.js. | ||
`libuv` (included in a project via `#include <uv.h>`) are not ABI-stable across | ||
Node.js major versions. Thus, an addon must use N-API and/or `node-addon-api` | ||
Node.js major versions. Thus, an addon must use Node-API and/or `node-addon-api` | ||
exclusively and build against a version of Node.js that includes an | ||
implementation of N-API (meaning an active LTS version of Node.js) in | ||
implementation of Node-API (meaning an active LTS version of Node.js) in | ||
order to benefit from ABI stability across Node.js major versions. Node.js | ||
provides an [ABI stability guide][] containing a detailed explanation of ABI | ||
stability in general, and the N-API ABI stability guarantee in particular. | ||
stability in general, and the Node-API ABI stability guarantee in particular. | ||
As new APIs are added to N-API, node-addon-api must be updated to provide | ||
As new APIs are added to Node-API, node-addon-api must be updated to provide | ||
wrappers for those new APIs. For this reason node-addon-api provides | ||
methods that allow callers to obtain the underlying N-API handles so | ||
direct calls to N-API and the use of the objects/methods provided by | ||
methods that allow callers to obtain the underlying Node-API handles so | ||
direct calls to Node-API and the use of the objects/methods provided by | ||
node-addon-api can be used together. For example, in order to be able | ||
@@ -50,4 +61,4 @@ to use an API for which the node-addon-api does not yet provide a wrapper. | ||
The [N-API Resource](https://nodejs.github.io/node-addon-examples/) offers an | ||
excellent orientation and tips for developers just getting started with N-API | ||
The [Node-API Resource](https://nodejs.github.io/node-addon-examples/) offers an | ||
excellent orientation and tips for developers just getting started with Node-API | ||
and node-addon-api. | ||
@@ -65,3 +76,3 @@ | ||
## **Current version: 3.1.0** | ||
## **Current version: 3.2.0** | ||
@@ -74,8 +85,8 @@ (See [CHANGELOG.md](CHANGELOG.md) for complete Changelog) | ||
node-addon-api is based on [N-API](https://nodejs.org/api/n-api.html) and supports using different N-API versions. | ||
This allows addons built with it to run with Node.js versions which support the targeted N-API version. | ||
node-addon-api is based on [Node-API](https://nodejs.org/api/n-api.html) and supports using different Node-API versions. | ||
This allows addons built with it to run with Node.js versions which support the targeted Node-API version. | ||
**However** the node-addon-api support model is to support only the active LTS Node.js versions. This means that | ||
every year there will be a new major which drops support for the Node.js LTS version which has gone out of service. | ||
The oldest Node.js version supported by the current version of node-addon-api is Node.js 10.x. | ||
The oldest Node.js version supported by the current version of node-addon-api is Node.js 12.x. | ||
@@ -149,10 +160,10 @@ ## Setup | ||
- **[Hello World](https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world/node-addon-api)** | ||
- **[Pass arguments to a function](https://github.com/nodejs/node-addon-examples/tree/master/2_function_arguments/node-addon-api)** | ||
- **[Callbacks](https://github.com/nodejs/node-addon-examples/tree/master/3_callbacks/node-addon-api)** | ||
- **[Object factory](https://github.com/nodejs/node-addon-examples/tree/master/4_object_factory/node-addon-api)** | ||
- **[Function factory](https://github.com/nodejs/node-addon-examples/tree/master/5_function_factory/node-addon-api)** | ||
- **[Wrapping C++ Object](https://github.com/nodejs/node-addon-examples/tree/master/6_object_wrap/node-addon-api)** | ||
- **[Factory of wrapped object](https://github.com/nodejs/node-addon-examples/tree/master/7_factory_wrap/node-addon-api)** | ||
- **[Passing wrapped object around](https://github.com/nodejs/node-addon-examples/tree/master/8_passing_wrapped/node-addon-api)** | ||
- **[Hello World](https://github.com/nodejs/node-addon-examples/tree/HEAD/1_hello_world/node-addon-api)** | ||
- **[Pass arguments to a function](https://github.com/nodejs/node-addon-examples/tree/HEAD/2_function_arguments/node-addon-api)** | ||
- **[Callbacks](https://github.com/nodejs/node-addon-examples/tree/HEAD/3_callbacks/node-addon-api)** | ||
- **[Object factory](https://github.com/nodejs/node-addon-examples/tree/HEAD/4_object_factory/node-addon-api)** | ||
- **[Function factory](https://github.com/nodejs/node-addon-examples/tree/HEAD/5_function_factory/node-addon-api)** | ||
- **[Wrapping C++ Object](https://github.com/nodejs/node-addon-examples/tree/HEAD/6_object_wrap/node-addon-api)** | ||
- **[Factory of wrapped object](https://github.com/nodejs/node-addon-examples/tree/HEAD/7_factory_wrap/node-addon-api)** | ||
- **[Passing wrapped object around](https://github.com/nodejs/node-addon-examples/tree/HEAD/8_passing_wrapped/node-addon-api)** | ||
@@ -176,3 +187,3 @@ <a name="tests"></a> | ||
To run the tests targetting a specific version of N-API run | ||
To run the tests targeting a specific version of Node-API run | ||
``` | ||
@@ -184,3 +195,3 @@ npm install | ||
where X is the version of N-API you want to target. | ||
where X is the version of Node-API you want to target. | ||
@@ -201,3 +212,3 @@ ### **Debug** | ||
Take a look and get inspired by our **[test suite](https://github.com/nodejs/node-addon-api/tree/master/test)** | ||
Take a look and get inspired by our **[test suite](https://github.com/nodejs/node-addon-api/tree/HEAD/test)** | ||
@@ -218,6 +229,7 @@ ### **Benchmarks** | ||
- **[C++ Addons](https://nodejs.org/dist/latest/docs/api/addons.html)** | ||
- **[N-API](https://nodejs.org/dist/latest/docs/api/n-api.html)** | ||
- **[N-API - Next Generation Node API for Native Modules](https://youtu.be/-Oniup60Afs)** | ||
- **[Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html)** | ||
- **[Node-API - Next Generation Node API for Native Modules](https://youtu.be/-Oniup60Afs)** | ||
- **[How We Migrated Realm JavaScript From NAN to Node-API](https://developer.mongodb.com/article/realm-javascript-nan-to-n-api)** | ||
As node-addon-api's core mission is to expose the plain C N-API as C++ | ||
As node-addon-api's core mission is to expose the plain C Node-API as C++ | ||
wrappers, tools that facilitate n-api/node-addon-api providing more | ||
@@ -230,2 +242,8 @@ convenient patterns on developing a Node.js add-ons with n-api/node-addon-api | ||
<a name="other-bindings"></a> | ||
### **Other bindings** | ||
- **[napi-rs](https://napi.rs)** - (`Rust`) | ||
<a name="badges"></a> | ||
@@ -235,15 +253,17 @@ | ||
The use of badges is recommended to indicate the minimum version of N-API | ||
The use of badges is recommended to indicate the minimum version of Node-API | ||
required for the module. This helps to determine which Node.js major versions are | ||
supported. Addon maintainers can consult the [N-API support matrix][] to determine | ||
which Node.js versions provide a given N-API version. The following badges are | ||
supported. Addon maintainers can consult the [Node-API support matrix][] to determine | ||
which Node.js versions provide a given Node-API version. The following badges are | ||
available: | ||
![N-API v1 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v1%20Badge.svg) | ||
![N-API v2 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v2%20Badge.svg) | ||
![N-API v3 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v3%20Badge.svg) | ||
![N-API v4 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v4%20Badge.svg) | ||
![N-API v5 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v5%20Badge.svg) | ||
![N-API v6 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20v6%20Badge.svg) | ||
![N-API Experimental Version Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/N-API%20Experimental%20Version%20Badge.svg) | ||
![Node-API v1 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v1%20Badge.svg) | ||
![Node-API v2 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v2%20Badge.svg) | ||
![Node-API v3 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v3%20Badge.svg) | ||
![Node-API v4 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v4%20Badge.svg) | ||
![Node-API v5 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v5%20Badge.svg) | ||
![Node-API v6 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v6%20Badge.svg) | ||
![Node-API v7 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v7%20Badge.svg) | ||
![Node-API v8 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v8%20Badge.svg) | ||
![Node-API Experimental Version Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20Experimental%20Version%20Badge.svg) | ||
@@ -265,3 +285,2 @@ ## **Contributing** | ||
| Gabriel Schulhof | [gabrielschulhof](https://github.com/gabrielschulhof) | | ||
| Hitesh Kanwathirtha | [digitalinfinity](https://github.com/digitalinfinity) | | ||
| Jim Schlight | [jschlight](https://github.com/jschlight) | | ||
@@ -278,2 +297,3 @@ | Michael Dawson | [mhdawson](https://github.com/mhdawson) | | ||
| Jason Ginchereau | [jasongin](https://github.com/jasongin) | | ||
| Hitesh Kanwathirtha | [digitalinfinity](https://github.com/digitalinfinity) | | ||
| Sampson Gao | [sampsongao](https://github.com/sampsongao) | | ||
@@ -287,2 +307,2 @@ | Taylor Woll | [boingoing](https://github.com/boingoing) | | ||
[ABI stability guide]: https://nodejs.org/en/docs/guides/abi-stability/ | ||
[N-API support matrix]: https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api_version_matrix | ||
[Node-API support matrix]: https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api_version_matrix |
@@ -7,7 +7,23 @@ #!/usr/bin/env node | ||
const filesToCheck = ['*.h', '*.cc']; | ||
const CLANG_FORMAT_START = process.env.CLANG_FORMAT_START || 'master'; | ||
const CLANG_FORMAT_START = process.env.CLANG_FORMAT_START || 'main'; | ||
function main(args) { | ||
let fix = false; | ||
while (args.length > 0) { | ||
switch (args[0]) { | ||
case '-f': | ||
case '--fix': | ||
fix = true; | ||
default: | ||
} | ||
args.shift(); | ||
} | ||
let clangFormatPath = path.dirname(require.resolve('clang-format')); | ||
const options = ['--binary=node_modules/.bin/clang-format', '--style=file']; | ||
if (fix) { | ||
options.push(CLANG_FORMAT_START); | ||
} else { | ||
options.push('--diff', CLANG_FORMAT_START); | ||
} | ||
@@ -19,10 +35,8 @@ const gitClangFormatPath = path.join(clangFormatPath, | ||
...options, | ||
'--diff', | ||
CLANG_FORMAT_START, | ||
'HEAD', | ||
'--', | ||
...filesToCheck | ||
], { encoding: 'utf-8' }); | ||
if (result.error) { | ||
console.error('Error running git-clang-format:', result.error); | ||
if (result.stderr) { | ||
console.error('Error running git-clang-format:', result.stderr); | ||
return 2; | ||
@@ -32,2 +46,8 @@ } | ||
const clangFormatOutput = result.stdout.trim(); | ||
// Bail fast if in fix mode. | ||
if (fix) { | ||
console.log(clangFormatOutput); | ||
return 0; | ||
} | ||
// Detect if there is any complains from clang-format | ||
if (clangFormatOutput !== '' && | ||
@@ -37,9 +57,9 @@ clangFormatOutput !== ('no modified files to format') && | ||
console.error(clangFormatOutput); | ||
const fixCmd = '"npm run lint:fix"'; | ||
const fixCmd = 'npm run lint:fix'; | ||
console.error(` | ||
ERROR: please run ${fixCmd} to format changes in your commit | ||
ERROR: please run "${fixCmd}" to format changes in your commit | ||
Note that when running the command locally, please keep your local | ||
master branch and working branch up to date with nodejs/node-addon-api | ||
main branch and working branch up to date with nodejs/node-addon-api | ||
to exclude un-related complains. | ||
Or you can run "env CLANG_FORMAT_START=upstream/master ${fixCmd}".`); | ||
Or you can run "env CLANG_FORMAT_START=upstream/main ${fixCmd}".`); | ||
return 1; | ||
@@ -46,0 +66,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
294
3
2
419809
18
431