Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add guide for updating N-API API surface #21877

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions doc/guides/adding-new-napi-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Contributing a new API to N-API

N-API is Node.js's next generation ABI-stable API for native modules.
While improving the API surface is encouraged and welcomed, the following are
a set of principles and guidelines to keep in mind while adding a new
N-API API.

* A new API **must** adhere to N-API API shape and spirit.
* **Must** be a C API.
* **Must** not throw exceptions.
* **Must** return `napi_status`.
* **Should** consume `napi_env`.
* **Must** operate only on primitive data types, pointers to primitive
datatypes or opaque handles.
* **Must** be a necessary API and not a nice to have. Convenience APIs
belong in node-addon-api.
* **Must** not change the signature of an existing N-API API or break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space before "or"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed- thanks! And yes, whoops- the package-lock changes were accidental 😞

ABI compatibility with other versions of Node.js.
* New API **should** be agnostic towards the underlying JavaScript VM.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a "should" or a "must"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really need to perform the exercise of stretching the bed sheet onto two different mattresses to see if it really is a one-size-fits-all 🙂

I guess, basically, if this is a "must", then so is implementation on top of multiple engines below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, also the thinking here was that there might be legitimate reasons why we might want to expose an API that was VM specific (that other VMs would just return an error/silently fail on), and so the thinking was to leave that up to the reviewers of the relevant PR

* New API PRs **must** have a corresponding documentation update.
* New API PRs **must** be tagged as **n-api**.
* There **must** be at least one test case showing how to use the API.
* There **should** be at least one test case per interesting use of the API.
* There **should** be a sample provided that operates in a realistic way
(operating how a real addon would be written).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit: wrapped lines in this level are not aligned with the first line properly (other levels seem OK).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed- thanks!

* A new API **should** be discussed at the N-API working group meeting.
* A new API addition **must** be signed off by at least two members of
the N-API WG.
* A new API addition **should** be simultaneously implemented in at least
one other VM implementation of Node.js.
* A new API **must** be considered experimental for at least one minor
version release of Node.js before it can be considered for promotion out
of experimental.
* Experimental APIs **must** be documented as such.
* Experimental APIs **must** require an explicit compile-time flag
(`#define`) to be set to opt-in.
* Experimental APIs **must** be considered for backport.
* Experimental status exit criteria **must** involve at least the
following:
* A new PR **must** be opened in `nodejs/node` to remove experimental
status. This PR **must** be tagged as **n-api** and **semver-minor**.
* Exiting an API from experimental **must** be signed off by the
working group.
* If a backport is merited, an API **must** have a down-level
implementation.
* The API **should** be used by a published real-world module. Use of
the API by a real-world published module will contribute favorably
to the decision to take an API out of experimental status.
* The API **must** be implemented in a Node.js implementation with an
alternate VM.
Loading