File: adding-new-napi-api.md

package info (click to toggle)
nodejs 22.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 246,928 kB
  • sloc: cpp: 1,582,349; javascript: 582,017; ansic: 82,400; python: 60,561; sh: 4,009; makefile: 2,263; asm: 1,732; pascal: 1,565; perl: 248; lisp: 222; xml: 42
file content (52 lines) | stat: -rw-r--r-- 2,368 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Contributing a new API to Node-API

Node-API is the ABI-stable API for native addons. We encourage contributions to enhance the API,
while also ensuring compatibility and adherence to guidelines. When adding a new API to Node-API,
please follow these principles and guidelines:

## Core principles

1. **Adherence to Node-API standards**
   * **Must** be a C API.
   * **Must** not throw exceptions.
   * **Must** return `napi_status`.
   * **Should** consume `napi_env`.
   * **Must** operate on primitive data types, pointers to primitive data types, or opaque handles.
   * **Must** be a necessary API, not a convenience API (which belongs in node-addon-api).
   * **Must** not break ABI compatibility with other Node.js versions.

2. **Maintaining VM agnosticism**
   * New APIs **should** be compatible with various JavaScript VMs.

## Documentation and testing

1. **Documentation**
   * PRs introducing new APIs **must** include corresponding documentation updates.
   * Experimental APIs **must** be clearly documented as experimental and require an explicit compile-time flag
     to opt-in (`#define`).

2. **Testing**
   * PRs **must** include at least one test case demonstrating API usage.
   * **Should** include test cases for various interesting uses of the API.
   * **Should** provide a sample demonstrating realistic usage, similar to a real-world addon.

## Process and approval

1. **Team discussion**
   * New APIs **should** be discussed in a Node-API team meeting.

2. **Review and approval**
   * A new API addition **must** be signed off by at least two Node-API team members.
   * **Should** be implemented in at least one other VM implementation of Node.js.

3. **Experimental phase**
   * New APIs **must** be marked as experimental for at least one minor Node.js release before promotion.
   * **Must** have a feature flag (`NODE_API_EXPERIMENTAL_HAS_<FEATURE>`) for distinguishing experimental
     feature existence.
   * **Must** be considered for backporting.
   * Exit criteria from experimental status include:
     * Opening a PR in `nodejs/node` to remove experimental status, tagged as **node-api** and **semver-minor**.
     * Approval by the Node-API team.
     * Availability of a down-level implementation if backporting is needed.
     * Usage by a published real-world module.
     * Implementation in an alternative VM.