Skip to content

Commit e87810f

Browse files
authored
Merge pull request #1 from bvanjoi/next
feat: init
2 parents b58ce50 + 6f67465 commit e87810f

File tree

36 files changed

+758
-301
lines changed

36 files changed

+758
-301
lines changed

.github/workflows/Publish.yml

Lines changed: 484 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
name: CI
1+
name: Test
22
env:
33
DEBUG: napi:*
4-
APP_NAME: package-template
4+
APP_NAME: nodejs-resolver
55
MACOSX_DEPLOYMENT_TARGET: '10.13'
66
'on':
77
push:
@@ -16,6 +16,7 @@ env:
1616
- .editorconfig
1717
- docs/**
1818
pull_request: null
19+
1920
jobs:
2021
build:
2122
if: "!contains(github.event.head_commit.message, 'skip ci')"
@@ -442,8 +443,8 @@ jobs:
442443
set -e
443444
yarn test
444445
ls -la
445-
publish:
446-
name: Publish
446+
Test:
447+
name: Test
447448
runs-on: ubuntu-latest
448449
needs:
449450
- build-freebsd
@@ -479,19 +480,6 @@ jobs:
479480
- name: List packages
480481
run: ls -R ./npm
481482
shell: bash
482-
- name: Publish
483+
- name: Test
483484
run: |
484-
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
485-
then
486-
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
487-
npm publish --access public
488-
elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
489-
then
490-
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
491-
npm publish --tag next --access public
492-
else
493-
echo "Not a release, skipping publish"
494-
fi
495-
env:
496-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
497-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
485+
npm run test

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["LongYinan <lynweklm@gmail.com>"]
33
edition = "2021"
4-
name = "napi-package-template"
4+
name = "napi-nodejs-resolver"
55
version = "0.1.0"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -12,6 +12,9 @@ crate-type = ["cdylib"]
1212
[dependencies]
1313
napi = "2"
1414
napi-derive = "2"
15+
nodejs-resolver = "0.0.14"
16+
serde = { version = "1.0.137", features = ["derive"] }
17+
serde_json = "1.0.81"
1518

1619
[build-dependencies]
1720
napi-build = "1"

README.md

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,2 @@
1-
# `@napi-rs/package-template`
1+
# `nodejs-resolver`
22

3-
![https://github.com/napi-rs/package-template/actions](https://github.com/napi-rs/package-template/workflows/CI/badge.svg)
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.

__test__/index.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import path from 'path'
2+
13
import test from 'ava'
24

3-
import { plus100 } from '../index'
5+
import factory from '../index'
46

57
test('sync function from native code', (t) => {
6-
const fixture = 42
7-
t.is(plus100(fixture), fixture + 100)
8+
const resolver = factory.create(JSON.stringify({}))
9+
const result = factory.resolve(resolver, __dirname, './lib.js')
10+
t.is(result.path, path.resolve(__dirname, './lib.js'))
11+
t.is(result.status, true)
812
})

__test__/lib.js

Whitespace-only changes.

index.d.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,18 @@
33

44
/* auto-generated by NAPI-RS */
55

6-
export function plus100(input: number): number
6+
export class ExternalObject<T> {
7+
readonly '': {
8+
readonly '': unique symbol
9+
[K: symbol]: T
10+
}
11+
}
12+
export interface ResolverInternal {
13+
14+
}
15+
export function create(options: string): ExternalObject<ResolverInternal>
16+
export interface ResolveResult {
17+
status: boolean
18+
path?: string
19+
}
20+
export function resolve(resolver: ExternalObject<ResolverInternal>,): ResolveResult

0 commit comments

Comments
 (0)