|
1 | | -# `@napi-rs/package-template` |
| 1 | +# `nodejs-resolver` |
2 | 2 |
|
3 | | - |
4 | | - |
5 | | -> Template project for writing node package with napi-rs. |
6 | | -
|
7 | | -# Usage |
8 | | - |
9 | | -1. Click **Use this template**. |
10 | | -2. **Clone** your project. |
11 | | -3. Run `yarn install` to install dependencies. |
12 | | -4. Run `npx napi rename [name]` command under the project folder to rename your package. |
13 | | - |
14 | | -## Install this test package |
15 | | - |
16 | | -``` |
17 | | -yarn add @napi-rs/package-template |
18 | | -``` |
19 | | - |
20 | | -## Support matrix |
21 | | - |
22 | | -### Operating Systems |
23 | | - |
24 | | -| | node12 | node14 | node16 | |
25 | | -| ---------------- | ------ | ------ | ------ | |
26 | | -| Windows x64 | ✓ | ✓ | ✓ | |
27 | | -| Windows x32 | ✓ | ✓ | ✓ | |
28 | | -| Windows arm64 | ✓ | ✓ | ✓ | |
29 | | -| macOS x64 | ✓ | ✓ | ✓ | |
30 | | -| macOS arm64 | ✓ | ✓ | ✓ | |
31 | | -| Linux x64 gnu | ✓ | ✓ | ✓ | |
32 | | -| Linux x64 musl | ✓ | ✓ | ✓ | |
33 | | -| Linux arm gnu | ✓ | ✓ | ✓ | |
34 | | -| Linux arm64 gnu | ✓ | ✓ | ✓ | |
35 | | -| Linux arm64 musl | ✓ | ✓ | ✓ | |
36 | | -| Android arm64 | ✓ | ✓ | ✓ | |
37 | | -| Android armv7 | ✓ | ✓ | ✓ | |
38 | | -| FreeBSD x64 | ✓ | ✓ | ✓ | |
39 | | - |
40 | | -## Ability |
41 | | - |
42 | | -### Build |
43 | | - |
44 | | -After `yarn build/npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs). |
45 | | - |
46 | | -### Test |
47 | | - |
48 | | -With [ava](https://github.com/avajs/ava), run `yarn test/npm run test` to testing native addon. You can also switch to another testing framework if you want. |
49 | | - |
50 | | -### CI |
51 | | - |
52 | | -With GitHub actions, every commits and pull request will be built and tested automatically in [`node@12`, `node@14`, `@node16`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms. |
53 | | - |
54 | | -### Release |
55 | | - |
56 | | -Release native package is very difficult in old days. Native packages may ask developers who use its to install `build toolchain` like `gcc/llvm` , `node-gyp` or something more. |
57 | | - |
58 | | -With `GitHub actions`, we can easily prebuild `binary` for major platforms. And with `N-API`, we should never afraid of **ABI Compatible**. |
59 | | - |
60 | | -The other problem is how to deliver prebuild `binary` to users. Download it in `postinstall` script is a common way which most packages do it right now. The problem of this solution is it introduced many other packages to download binary which has not been used by `runtime codes`. The other problem is some user may not easily download the binary from `GitHub/CDN` if they are behind private network (But in most case, they have a private NPM mirror). |
61 | | - |
62 | | -In this package we choose a better way to solve this problem. We release different `npm packages` for different platform. And add it to `optionalDependencies` before release the `Major` package to npm. |
63 | | - |
64 | | -`NPM` will choose which native package should download from `registry` automatically. You can see [npm](./npm) dir for details. And you can also run `yarn add @napi-rs/package-template` to see how it works. |
65 | | - |
66 | | -## Develop requirements |
67 | | - |
68 | | -- Install latest `Rust` |
69 | | -- Install `Node.js@10+` which fully supported `Node-API` |
70 | | -- Install `yarn@1.x` |
71 | | - |
72 | | -## Test in local |
73 | | - |
74 | | -- yarn |
75 | | -- yarn build |
76 | | -- yarn test |
77 | | - |
78 | | -And you will see: |
79 | | - |
80 | | -```bash |
81 | | -$ ava --verbose |
82 | | - |
83 | | - ✔ sync function from native code |
84 | | - ✔ sleep function from native code (201ms) |
85 | | - ─ |
86 | | - |
87 | | - 2 tests passed |
88 | | -✨ Done in 1.12s. |
89 | | -``` |
90 | | - |
91 | | -## Release package |
92 | | - |
93 | | -Ensure you have set you **NPM_TOKEN** in `GitHub` project setting. |
94 | | - |
95 | | -In `Settings -> Secrets`, add **NPM_TOKEN** into it. |
96 | | - |
97 | | -When you want release package: |
98 | | - |
99 | | -``` |
100 | | -npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git] |
101 | | -
|
102 | | -git push |
103 | | -``` |
104 | | - |
105 | | -GitHub actions will do the rest job for you. |
0 commit comments