Merge pull request #672 from napi-rs/add-next-js

Add next js
This commit is contained in:
LongYinan 2021-07-30 13:47:56 +08:00 committed by GitHub
commit 66e96f0273
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 84 additions and 74 deletions

View file

@ -40,19 +40,19 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-macos-android-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-macos-android-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-macos-android-node@14-${{ hashFiles('yarn.lock') }}

View file

@ -37,19 +37,19 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: bench-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: bench-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: bench-${{ hashFiles('yarn.lock') }}

View file

@ -34,19 +34,19 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: lint-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: lint-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: lint-${{ hashFiles('yarn.lock') }}

View file

@ -42,19 +42,19 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-linux-aarch64-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-linux-aarch64-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-linux-aarch64-gnu-node@14-${{ hashFiles('yarn.lock') }}

View file

@ -42,19 +42,19 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-linux-aarch64-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-linux-aarch64-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-linux-aarch64-gnu-node@14-${{ hashFiles('yarn.lock') }}

View file

@ -42,19 +42,19 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-linux-armv7-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-linux-armv7-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-linux-armv7-gnu-node@14-${{ hashFiles('yarn.lock') }}

View file

@ -18,13 +18,13 @@ jobs:
- uses: actions/checkout@v2
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-alpine-node-alpine-@lts-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-alpine-node-alpine-@lts-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

View file

@ -36,25 +36,25 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-memory-leak-detect-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-memory-leak-detect-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: target
key: stable-memory-leak-detect-cargo-build-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: memory-leak-detect-${{ hashFiles('yarn.lock') }}

View file

@ -35,23 +35,23 @@ jobs:
with:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-napi3-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-napi3-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: target
key: stable-napi3-cargo-build-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: napi3-${{ hashFiles('yarn.lock') }}

View file

@ -42,19 +42,19 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-${{ matrix.os }}-node@${{ matrix.node }}-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-${{ matrix.os }}gnu-node@${{ matrix.node }}-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-${{ matrix.os }}-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}

View file

@ -23,7 +23,7 @@ jobs:
node-version: 14
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-windows-arm64-node@lts-${{ hashFiles('yarn.lock') }}
@ -50,13 +50,13 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-windows-arm64-node@lts-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-windows-arm64-node@lts-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

View file

@ -26,7 +26,7 @@ jobs:
shell: bash
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-windows-i686-node@lts-${{ hashFiles('yarn.lock') }}
@ -53,13 +53,13 @@ jobs:
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-windows-i686-node@lts-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-windows-i686-node@lts-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

View file

@ -16,17 +16,23 @@ A minimal library for building compiled `Node.js` add-ons in `Rust`.
<p align="center">
<a href="https://www.prisma.io/" target="_blank">
<img alt="Prisma" src="./images/prisma.svg">
<img alt="Prisma" src="./images/prisma.svg" height="50px">
</a>
&nbsp;
&nbsp;
<a href="https://swc.rs/" target="_blank">
<img alt="swc" src="https://raw.githubusercontent.com/swc-project/logo/master/swc.png" width="200">
<img alt="swc" src="https://raw.githubusercontent.com/swc-project/logo/master/swc.png" height="50px">
</a>
&nbsp;
&nbsp;
<a href="https://parceljs.org/" target="_blank">
<img alt="Parcel" src="https://user-images.githubusercontent.com/19409/31321658-f6aed0f2-ac3d-11e7-8100-1587e676e0ec.png" width="280">
<img alt="Parcel" src="https://user-images.githubusercontent.com/19409/31321658-f6aed0f2-ac3d-11e7-8100-1587e676e0ec.png" height="50px">
</a>
&nbsp;
<a href="https://nextjs.org/">
<img alt="next.js" src="https://assets.vercel.com/image/upload/v1607554385/repositories/next-js/next-logo.png" height="50px">
&nbsp;
<img alt="nextjs.svg" src="./images/nextjs.svg" height="50px">
</a>
</p>

View file

@ -44,16 +44,16 @@ pub fn register_js(exports: &mut JsObject, env: &Env) -> Result<()> {
"TestClass",
test_class_constructor,
&[
Property::new(&env, "miterNative")?
Property::new(env, "miterNative")?
.with_getter(get_miter_native)
.with_setter(set_miter_native),
Property::new(&env, "miter")?
Property::new(env, "miter")?
.with_getter(get_miter)
.with_setter(set_miter),
Property::new(&env, "lineJoinNative")?
Property::new(env, "lineJoinNative")?
.with_getter(get_line_join_native)
.with_setter(set_line_join_native),
Property::new(&env, "lineJoin")?
Property::new(env, "lineJoin")?
.with_getter(get_line_join)
.with_setter(set_line_join),
],

View file

@ -44,7 +44,7 @@ pub fn setup() {
// If file does not exist, download it.
if metadata(&node_lib_file_path).is_err() {
let node_lib = copy_node_lib(&arch);
let node_lib = copy_node_lib(arch);
write(&node_lib_file_path, &node_lib).expect(&format!(
"Could not save file to {}",

View file

@ -94,19 +94,19 @@ export const createGithubActionsCIYml = (
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-\${{ matrix.os }}-node@${LATEST_LTS_NODE}-cargo-registry-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-\${{ matrix.os }}-node@${LATEST_LTS_NODE}-cargo-index-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-\${{ matrix.os }}-node@${LATEST_LTS_NODE}-\${{ hashFiles('yarn.lock') }}
@ -159,19 +159,19 @@ export const createGithubActionsCIYml = (
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-node-alpine-@${OLDEST_LTS_NODE}-cargo-registry-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-node-alpine-@${OLDEST_LTS_NODE}-cargo-index-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-alpine-node@${OLDEST_LTS_NODE}-\${{ hashFiles('yarn.lock') }}
@ -218,19 +218,19 @@ export const createGithubActionsCIYml = (
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-linux-arm7-gnu-node@${LATEST_LTS_NODE}-cargo-registry-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-linux-arm7-gnu-node@${LATEST_LTS_NODE}-cargo-index-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-linux-arm7-gnu-node@${LATEST_LTS_NODE}-\${{ hashFiles('yarn.lock') }}
@ -288,19 +288,19 @@ export const createGithubActionsCIYml = (
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: stable-linux-aarch64-gnu-node@${LATEST_LTS_NODE}-cargo-registry-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: stable-linux-aarch64-gnu-node@${LATEST_LTS_NODE}-cargo-index-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-linux-aarch64-gnu-node@${LATEST_LTS_NODE}-\${{ hashFiles('yarn.lock') }}
@ -353,19 +353,19 @@ export const createGithubActionsCIYml = (
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: nightly-apple-aarch64-node@${LATEST_LTS_NODE}-cargo-registry-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: nightly-apple-aarch64-node@${LATEST_LTS_NODE}-cargo-index-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-apple-aarch64-node@${LATEST_LTS_NODE}-\${{ hashFiles('yarn.lock') }}
@ -404,19 +404,19 @@ export const createGithubActionsCIYml = (
command: generate-lockfile
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: nightly-apple-aarch64-node@${LATEST_LTS_NODE}-cargo-registry-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: nightly-apple-aarch64-node@${LATEST_LTS_NODE}-cargo-index-trimmed-\${{ hashFiles('**/Cargo.lock') }}
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-apple-aarch64-node@${LATEST_LTS_NODE}-\${{ hashFiles('yarn.lock') }}
@ -459,7 +459,7 @@ export const createGithubActionsCIYml = (
check-latest: true
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-test-\${{ matrix.os }}-node@\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }}
@ -496,7 +496,7 @@ export const createGithubActionsCIYml = (
- uses: actions/checkout@v2
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-alpine-node@\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }}
@ -542,7 +542,7 @@ export const createGithubActionsCIYml = (
check-latest: true
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-test-linux-aarch64-gnu-node@\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }}
@ -627,7 +627,7 @@ ${requiredSteps.map((s) => ` - ${s}`).join('\n')}
check-latest: true
- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-publish-ubuntu-latest-\${{ hashFiles('yarn.lock') }}

4
images/nextjs.svg Normal file
View file

@ -0,0 +1,4 @@
<svg width="148" height="90" viewBox="0 0 148 90" role="img" xmlns="http://www.w3.org/2000/svg">
<path d="M34.992 23.495h27.855v2.219H37.546v16.699h23.792v2.219H37.546v18.334h25.591v2.219H34.992v-41.69zm30.35 0h2.96l13.115 18.334 13.405-18.334L113.055.207 83.1 43.756l15.436 21.429H95.46L81.417 45.683 67.316 65.185h-3.018L79.85 43.756 65.343 23.495zm34.297 2.219v-2.219h31.742v2.219h-14.623v39.47h-2.554v-39.47H99.64zM.145 23.495h3.192l44.011 66.003L29.16 65.185 2.814 26.648l-.116 38.537H.145v-41.69zm130.98 38.801c-.523 0-.914-.405-.914-.928 0-.524.391-.929.913-.929.528 0 .913.405.913.929 0 .523-.385.928-.913.928zm2.508-2.443H135c.019.742.56 1.24 1.354 1.24.888 0 1.391-.535 1.391-1.539v-6.356h1.391v6.362c0 1.808-1.043 2.849-2.77 2.849-1.62 0-2.732-1.01-2.732-2.556zm7.322-.08h1.379c.118.853.95 1.395 2.149 1.395 1.117 0 1.937-.58 1.937-1.377 0-.685-.521-1.097-1.708-1.377l-1.155-.28c-1.62-.38-2.36-1.166-2.36-2.487 0-1.602 1.304-2.668 3.26-2.668 1.82 0 3.15 1.066 3.23 2.58h-1.354c-.13-.828-.85-1.346-1.894-1.346-1.1 0-1.832.53-1.832 1.34 0 .642.472 1.01 1.64 1.284l.987.243c1.838.43 2.596 1.178 2.596 2.53 0 1.72-1.33 2.799-3.453 2.799-1.987 0-3.323-1.029-3.422-2.637z" fill="#000" fill-rule="nonzero">
</path>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -11,7 +11,7 @@ pub(crate) struct Ser<'env>(pub(crate) &'env Env);
impl<'env> Ser<'env> {
fn new(env: &'env Env) -> Self {
Self(&env)
Self(env)
}
}

View file

@ -8,8 +8,8 @@ struct NativeClass {
#[js_function(1)]
fn create_test_class(ctx: CallContext) -> Result<JsFunction> {
let add_count_method = Property::new(&ctx.env, "addCount")?.with_method(add_count);
let add_native_count = Property::new(&ctx.env, "addNativeCount")?.with_method(add_native_count);
let add_count_method = Property::new(ctx.env, "addCount")?.with_method(add_count);
let add_native_count = Property::new(ctx.env, "addNativeCount")?.with_method(add_native_count);
let properties = vec![add_count_method, add_native_count];
ctx
.env
@ -47,8 +47,8 @@ fn add_native_count(ctx: CallContext) -> Result<JsNumber> {
#[js_function(1)]
fn new_test_class(ctx: CallContext) -> Result<JsObject> {
let add_count_method = Property::new(&ctx.env, "addCount")?.with_method(add_count);
let add_native_count = Property::new(&ctx.env, "addNativeCount")?.with_method(add_native_count);
let add_count_method = Property::new(ctx.env, "addCount")?.with_method(add_count);
let add_native_count = Property::new(ctx.env, "addNativeCount")?.with_method(add_native_count);
let properties = vec![add_count_method, add_native_count];
let test_class =
ctx

View file

@ -135,8 +135,8 @@ fn test_delete_element(ctx: CallContext) -> Result<JsBoolean> {
#[js_function(1)]
fn test_define_properties(ctx: CallContext) -> Result<JsUndefined> {
let mut obj = ctx.get::<JsObject>(0)?;
let add_method = Property::new(&ctx.env, "add")?.with_method(add);
let readonly_property = Property::new(&ctx.env, "ro")?.with_getter(readonly_getter);
let add_method = Property::new(ctx.env, "add")?.with_method(add);
let readonly_property = Property::new(ctx.env, "ro")?.with_getter(readonly_getter);
let properties = vec![add_method, readonly_property];
obj.define_properties(&properties)?;
obj.set_named_property("count", ctx.env.create_int32(0)?)?;