Skip to content

Commit e6430c2

Browse files
NickNasomhdawson
authored andcommitted
doc: Scaffolding for documentation
PR-URL: #168 Reviewed-By: Michael Dawson <[email protected]>
1 parent 8ffea15 commit e6430c2

39 files changed

+200
-83
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Node.js API (N-API) Package Changelog

README.md

Lines changed: 107 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,106 @@
1-
# Node.js API (N-API) Package
2-
3-
This package contains header-only C++ wrapper classes for the ABI-stable
4-
Node.js API (N-API), along with library code that enables
5-
backward-compatibility with use with older versions of Node.js that do
6-
not have N-API built-in.
7-
8-
### API Documentation
9-
10-
- [ABI-Stable C APIs in Node.js](https://nodejs.org/api/n-api.html)
11-
- [C++ APIs in this package](https://nodejs.github.io/node-addon-api/namespace_napi.html)
12-
13-
### Getting Started
14-
15-
To use N-API in a native module:
16-
1. Add a dependency on this package to `package.json`:
17-
```json
18-
"dependencies": {
19-
"node-addon-api": "1.0.0",
20-
}
21-
```
22-
23-
2. Reference this package's include directory and gyp file in `binding.gyp`:
24-
```gyp
25-
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
26-
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
27-
```
28-
29-
3. Decide whether the package will enable C++ exceptions in the N-API wrapper.
30-
The base ABI-stable C APIs do not throw or handle C++ exceptions, but the
31-
N-API C++ wrapper classes may _optionally_
32-
[integrate C++ and JavaScript exception-handling
33-
](https://nodejs.github.io/node-addon-api/class_napi_1_1_error.html).
34-
To enable that capability, C++ exceptions must be enabled in `binding.gyp`:
35-
```gyp
36-
'cflags!': [ '-fno-exceptions' ],
37-
'cflags_cc!': [ '-fno-exceptions' ],
38-
'xcode_settings': {
39-
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
40-
'CLANG_CXX_LIBRARY': 'libc++',
41-
'MACOSX_DEPLOYMENT_TARGET': '10.7',
42-
},
43-
'msvs_settings': {
44-
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
45-
},
46-
```
47-
Alternatively, disable use of C++ exceptions in N-API:
48-
```gyp
49-
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
50-
```
51-
52-
4. Include `napi.h` in the native module code.
53-
To ensure only ABI-stable APIs are used, DO NOT include
54-
`node.h`, `nan.h`, or `v8.h`.
55-
```C++
56-
#include "napi.h"
57-
```
58-
59-
At build time, the N-API back-compat library code will be used only when the
60-
targeted node version *does not* have N-API built-in.
61-
62-
## Conversion Tool
63-
To make the migration to node-addon-api easier, we have provided a script to help
64-
complete the steps listed above. To use the conversion script:
65-
1. Go to your module directory
66-
```
67-
cd [module_path]
68-
```
69-
2. Install node-addon-api module
70-
```
71-
npm install node-addon-api
72-
```
73-
3. Run node-addon-api conversion script
74-
```
75-
node ./node_modules/node-addon-api/tools/conversion.js ./
76-
```
77-
4. While this script makes conversion easier, it still cannot fully convert
78-
the module. The next step is to try to build the module and complete the
79-
remaining conversions necessary to allow it to compile and pass all of the
80-
module's tests.
81-
82-
83-
<a name="collaborators"></a>
1+
# **Node.js API (N-API) Package**
2+
3+
This package contains **header-only C++ wrapper classes** for the **ABI-stable
4+
Node.js API** also known as **N-API**, providing C++ object model and exception
5+
handling semantics with low overhead. It guarantees backward compatibility with
6+
use with older versions of Node.js that do not have N-API built-in.
7+
8+
Node.js API guarentees the **API** and **ABI** compatibility across different
9+
version of Node.js. So if you switch to a
10+
different version of Node.js you must not reinstall and maybe recompile the
11+
Addon.
12+
13+
N-API is an API for building native Addons. It is independent from the underlying
14+
JavaScript runtime (ex V8) and is maintained as part of Node.js itself. This API
15+
will be Application Binary Interface (ABI) stable across versions of Node.js. It
16+
is intended to insulate Addons from changes in the underlying JavaScript engine
17+
and allow modules compiled for one version to run on later versions of Node.js
18+
without recompilation.
19+
20+
APIs exposed by N-API are generally used to create and manipulate JavaScript
21+
values. Concepts and operations generally map to ideas specified in the
22+
**ECMA262 Language Specification**.
23+
24+
- **[Setup](#setup)**
25+
- **[API Documentation](#api)**
26+
- **[Examples](#examples)**
27+
- **[Tests](#tests)**
28+
- **[More resource and info about native Addons](#resources)**
29+
- **[Contributors](#contributors)**
30+
- **[License](#license)**
31+
32+
## **Current version: 1.0.0**
33+
34+
(See [CHANHELOG.md](CHANGELOG.md) for complete Changelog)
35+
36+
[![NPM](https://nodei.co/npm/node-addon-api.png?downloads=true&downloadRank=true)](https://nodei.co/npm/dode-addon-api/) [![NPM](https://nodei.co/npm-dl/node-addon-api.png?months=6&height=1)](https://nodei.co/npm/dode-addon-api/)
37+
38+
<a name="setup"></a>
39+
40+
## Setup
41+
- [Installation and usage](doc/setup.md)
42+
- [node-gyp](doc/node-gyp.md)
43+
- [cmake-js](doc/cmake-js.md)
44+
- [Conversion tool](doc/conversion-tool.md)
45+
- [Generator](doc/generator.md)
46+
47+
<a name="api"></a>
48+
49+
### **API Documentation**
50+
- [Basic Types](doc/basic_types.md)
51+
- [Array](doc/array.md)
52+
- [Symbol](doc/symbol.md)
53+
- [String](doc/string.md)
54+
- [Name](doc/name.md)
55+
- [Number](doc/number.md)
56+
- [Boolean](doc/boolean.md)
57+
- [Env](doc/env.md)
58+
- [Value](doc/value.md)
59+
- [CallbackInfo](doc/callbackinfo.md)
60+
- [Reference](doc/reference.md)
61+
- [External](doc/external.md)
62+
- [Object](doc/object.md)
63+
- [ObjectReference](doc/object_reference.md)
64+
- [PropertyDescriptor](doc/property_descriptor.md)
65+
- [Error Handling](doc/error_handling.md)
66+
- [Error](doc/error.md)
67+
- [Object Lifettime Management](doc/object_lifetime_management.md)
68+
- [HandleScope](doc/handle_scope.md)
69+
- [EscapableHandleScope](doc/escapable_handle_scope.md)
70+
- [Working with JavaScript Values](doc/working_with_javascript_values.md)
71+
- [Function](doc/function.md)
72+
- [FunctionReference](doc/function_reference.md)
73+
- [ObjectWrap](doc/object_wrap.md)
74+
- [ClassPropertyDescriptor](doc/class_property_descriptor.md)
75+
- [Buffer](doc/buffer.md)
76+
- [ArrayBuffer](doc/array_buffer.md)
77+
- [TypedArray](doc/typed_array.md)
78+
- [TypedArrayOf](doc/typed_array_of.md)
79+
- [Async Operations](doc/async_operations.md)
80+
- [AsyncWorker](async_worker.md)
81+
- [Promises](doc/promises.md)
82+
83+
<a name="examples"></a>
84+
85+
### **Examples**
86+
87+
//TODO References to examples
88+
89+
<a name="tests"></a>
90+
91+
### **Tests**
92+
93+
//TODO References to tests
94+
95+
<a name="resources"></a>
96+
97+
### **More resource and info about native Addons**
98+
- **[C++ Addons](https://nodejs.org/dist/latest/docs/api/addons.html)**
99+
- **[N-API](https://nodejs.org/dist/latest/docs/api/n-api.html)**
100+
- **[N-API - Next Generation Node API for Native Modules](https://youtu.be/-Oniup60Afs)**
101+
102+
<a name="contributors"></a>
103+
84104
### WG Members / Collaborators
85105
| Name | GitHub link |
86106
| ------------------- | ----------------------------------------------------- |
@@ -93,3 +113,7 @@ module's tests.
93113
| Michael Dawson | [mhdawson](https://github.com/mhdawson) |
94114
| Sampson Gao | [sampsongao](https://github.com/sampsongao) |
95115
| Taylor Woll | [boingoing](https://github.com/boingoing) |
116+
117+
<a name="license"></a>
118+
119+
Licensed under [MIT](./LICENSE.md)

doc/array.md

Whitespace-only changes.

doc/array_buffer.md

Whitespace-only changes.

doc/async_operations.md

Whitespace-only changes.

doc/async_worker.md

Whitespace-only changes.

doc/basic_types.md

Whitespace-only changes.

doc/boolean.md

Whitespace-only changes.

doc/buffer.md

Whitespace-only changes.

doc/callbackinfo.md

Whitespace-only changes.

0 commit comments

Comments
 (0)