11cb0ef41Sopenharmony_ci# Contributing a new API to Node-API
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciNode-API is the next-generation ABI-stable API for native addons.
41cb0ef41Sopenharmony_ciWhile improving the API surface is encouraged and welcomed, the following are
51cb0ef41Sopenharmony_cia set of principles and guidelines to keep in mind while adding a new
61cb0ef41Sopenharmony_ciNode-API.
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci* A new API **must** adhere to Node-API API shape and spirit.
91cb0ef41Sopenharmony_ci  * **Must** be a C API.
101cb0ef41Sopenharmony_ci  * **Must** not throw exceptions.
111cb0ef41Sopenharmony_ci  * **Must** return `napi_status`.
121cb0ef41Sopenharmony_ci  * **Should** consume `napi_env`.
131cb0ef41Sopenharmony_ci  * **Must** operate only on primitive data types, pointers to primitive
141cb0ef41Sopenharmony_ci    data types or opaque handles.
151cb0ef41Sopenharmony_ci  * **Must** be a necessary API and not a nice to have. Convenience APIs
161cb0ef41Sopenharmony_ci    belong in node-addon-api.
171cb0ef41Sopenharmony_ci  * **Must** not change the signature of an existing Node-API API or break
181cb0ef41Sopenharmony_ci    ABI compatibility with other versions of Node.js.
191cb0ef41Sopenharmony_ci* New API **should** be agnostic towards the underlying JavaScript VM.
201cb0ef41Sopenharmony_ci* New API PRs **must** have a corresponding documentation update.
211cb0ef41Sopenharmony_ci* New API PRs **must** be tagged as **node-api**.
221cb0ef41Sopenharmony_ci* There **must** be at least one test case showing how to use the API.
231cb0ef41Sopenharmony_ci* There **should** be at least one test case per interesting use of the API.
241cb0ef41Sopenharmony_ci* There **should** be a sample provided that operates in a realistic way
251cb0ef41Sopenharmony_ci  (operating how a real addon would be written).
261cb0ef41Sopenharmony_ci* A new API **should** be discussed at the Node-API team meeting.
271cb0ef41Sopenharmony_ci* A new API addition **must** be signed off by at least two members of
281cb0ef41Sopenharmony_ci  the Node-API team.
291cb0ef41Sopenharmony_ci* A new API addition **should** be simultaneously implemented in at least
301cb0ef41Sopenharmony_ci  one other VM implementation of Node.js.
311cb0ef41Sopenharmony_ci* A new API **must** be considered experimental for at least one minor
321cb0ef41Sopenharmony_ci  version release of Node.js before it can be considered for promotion out
331cb0ef41Sopenharmony_ci  of experimental.
341cb0ef41Sopenharmony_ci  * Experimental APIs **must** be documented as such.
351cb0ef41Sopenharmony_ci  * Experimental APIs **must** require an explicit compile-time flag
361cb0ef41Sopenharmony_ci    (`#define`) to be set to opt-in.
371cb0ef41Sopenharmony_ci  * A feature flag of the form `NODE_API_EXPERIMENTAL_HAS_<FEATURE>` **must**
381cb0ef41Sopenharmony_ci    be added with each experimental feature in order to allow code to
391cb0ef41Sopenharmony_ci    distinguish between experimental features as present in one version of
401cb0ef41Sopenharmony_ci    Node.js versus another.
411cb0ef41Sopenharmony_ci  * Experimental APIs **must** be considered for backport.
421cb0ef41Sopenharmony_ci  * Experimental status exit criteria **must** involve at least the
431cb0ef41Sopenharmony_ci    following:
441cb0ef41Sopenharmony_ci    * A new PR **must** be opened in `nodejs/node` to remove experimental
451cb0ef41Sopenharmony_ci      status. This PR **must** be tagged as **node-api** and **semver-minor**.
461cb0ef41Sopenharmony_ci    * Exiting an API from experimental **must** be signed off by the team.
471cb0ef41Sopenharmony_ci    * If a backport is merited, an API **must** have a down-level
481cb0ef41Sopenharmony_ci      implementation.
491cb0ef41Sopenharmony_ci    * The API **should** be used by a published real-world module. Use of
501cb0ef41Sopenharmony_ci      the API by a real-world published module will contribute favorably
511cb0ef41Sopenharmony_ci      to the decision to take an API out of experimental status.
521cb0ef41Sopenharmony_ci    * The API **must** be implemented in a Node.js implementation with an
531cb0ef41Sopenharmony_ci      alternate VM.
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ciSince the adoption of the policy whereby moving to a later version of Node-API
561cb0ef41Sopenharmony_cifrom an earlier version may entail rework of existing code, it is possible to
571cb0ef41Sopenharmony_ciintroduce modifications to already-released Node-APIs, as long as the
581cb0ef41Sopenharmony_cimodifications affect neither the ABI nor the API of earlier versions. Such
591cb0ef41Sopenharmony_cimodifications **must** be accompanied by an opt-out flag. This provides add-on
601cb0ef41Sopenharmony_cimaintainers who take advantage of the initial compile-time flag to track
611cb0ef41Sopenharmony_ciimpending changes to Node-API with
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci* a quick fix to the breakage caused,
641cb0ef41Sopenharmony_ci* a notification that such breakage is impending, and thus
651cb0ef41Sopenharmony_ci* a buffer to adoption above and beyond the one provided by the initial
661cb0ef41Sopenharmony_ci  compile-time flag.
67