From 8de30a9287b3586efe81edf4f2745032c07b298a Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 3 Dec 2021 16:29:03 +0800 Subject: [PATCH 1/6] feat(napi): add -p flag which will be bypassed to cargo --- cli/src/build.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/src/build.ts b/cli/src/build.ts index 51f66f97..a9a95c01 100644 --- a/cli/src/build.ts +++ b/cli/src/build.ts @@ -65,6 +65,10 @@ export class BuildCommand extends Command { )} file, relative to cwd`, }) + project = Option.String('-p', { + description: `Bypass to ${chalk.green('cargo -p')}`, + }) + cargoFlags = Option.String('--cargo-flags', '', { description: `All the others flag passed to ${chalk.yellow('cargo')}`, }) @@ -123,10 +127,12 @@ export class BuildCommand extends Command { }).toString('utf8'), ) debug(`Current triple is: ${chalk.green(triple.raw)}`) + const pFlag = this.project ? `-p ${this.project}` : '' const externalFlags = [ releaseFlag, targetFlag, featuresFlag, + pFlag, this.cargoFlags, ] .filter((flag) => Boolean(flag)) From 49a0139f819badd13bc2869259d65fc878f0c472 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 3 Dec 2021 16:29:57 +0800 Subject: [PATCH 2/6] style: clippy fix --- bench/src/query.rs | 2 +- examples/napi-compat-mode/src/napi4/tsfn_dua_instance.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bench/src/query.rs b/bench/src/query.rs index 0ccf056b..e8e14294 100644 --- a/bench/src/query.rs +++ b/bench/src/query.rs @@ -2,7 +2,7 @@ use napi::{CallContext, JsExternal, JsObject, JsString}; #[derive(Clone)] pub struct QueryEngine { - datamodel: String, + pub datamodel: String, } unsafe impl Sync for QueryEngine {} diff --git a/examples/napi-compat-mode/src/napi4/tsfn_dua_instance.rs b/examples/napi-compat-mode/src/napi4/tsfn_dua_instance.rs index 39e0a236..12ca640d 100644 --- a/examples/napi-compat-mode/src/napi4/tsfn_dua_instance.rs +++ b/examples/napi-compat-mode/src/napi4/tsfn_dua_instance.rs @@ -5,8 +5,8 @@ use napi::{ use napi_derive::js_function; #[derive(Clone)] -struct A { - cb: ThreadsafeFunction, +pub struct A { + pub cb: ThreadsafeFunction, } #[js_function(1)] From 2d5b997b7d634cafb37aacefd7545d5ad328b6e5 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 3 Dec 2021 16:30:31 +0800 Subject: [PATCH 3/6] feat(napi): add experimental flag --- crates/napi/Cargo.toml | 3 ++- crates/napi/src/error.rs | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/napi/Cargo.toml b/crates/napi/Cargo.toml index 93e458c3..21d25610 100644 --- a/crates/napi/Cargo.toml +++ b/crates/napi/Cargo.toml @@ -11,9 +11,10 @@ version = "2.0.0-beta.1" [features] async = ["tokio_rt"] +experimental = ["napi-sys/experimental"] compat-mode = [] default = ["napi3", "compat-mode"] # for most Node.js users -full = ["latin1", "napi8", "async", "serde-json"] +full = ["latin1", "napi8", "async", "serde-json", "experimental"] latin1 = ["encoding_rs"] napi1 = [] napi2 = ["napi1"] diff --git a/crates/napi/src/error.rs b/crates/napi/src/error.rs index 89810716..846dea58 100644 --- a/crates/napi/src/error.rs +++ b/crates/napi/src/error.rs @@ -151,6 +151,9 @@ pub struct JsTypeError(Error); pub struct JsRangeError(Error); +#[cfg(feature = "experimental")] +pub struct JsSyntaxError(Error); + macro_rules! impl_object_methods { ($js_value:ident, $kind:expr) => { impl $js_value { From 77dab3e9f764146d94690b9283ba524c779e89cb Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 3 Dec 2021 16:31:03 +0800 Subject: [PATCH 4/6] docs(napi): prettier --- crates/napi/src/env.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/napi/src/env.rs b/crates/napi/src/env.rs index 50842a6b..13599bc4 100644 --- a/crates/napi/src/env.rs +++ b/crates/napi/src/env.rs @@ -1194,7 +1194,7 @@ impl Env { }) } - /// # Serialize `Rust Struct` into `JavaScript Value` + /// ### Serialize `Rust Struct` into `JavaScript Value` /// /// ``` /// #[derive(Serialize, Debug, Deserialize)] @@ -1220,7 +1220,7 @@ impl Env { node.serialize(s).map(JsUnknown) } - /// # Deserialize data from `JsValue` + /// ### Deserialize data from `JsValue` /// ``` /// #[derive(Serialize, Debug, Deserialize)] /// struct AnObject { From 53fe4d3aa5efdc4f5f3171d8018c280a5cc79dbe Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 3 Dec 2021 16:31:34 +0800 Subject: [PATCH 5/6] feat(napi): re-export ctor as module_init --- crates/napi/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/napi/src/lib.rs b/crates/napi/src/lib.rs index 82ec5609..abe3a012 100644 --- a/crates/napi/src/lib.rs +++ b/crates/napi/src/lib.rs @@ -183,6 +183,8 @@ pub(crate) unsafe fn log_js_value>( ); } +pub use crate::bindgen_runtime::ctor as module_init; + pub mod bindgen_prelude { #[cfg(feature = "compat-mode")] pub use crate::bindgen_runtime::register_module_exports; From 8fc1cfcb386271788479a973f1950ec00bb9e3d7 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 3 Dec 2021 16:31:58 +0800 Subject: [PATCH 6/6] feat(napi): TypeName and ToNapiValue should apply to any HashMap --- crates/napi/src/bindgen_runtime/js_values/map.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/napi/src/bindgen_runtime/js_values/map.rs b/crates/napi/src/bindgen_runtime/js_values/map.rs index f91e7c51..eb313e69 100644 --- a/crates/napi/src/bindgen_runtime/js_values/map.rs +++ b/crates/napi/src/bindgen_runtime/js_values/map.rs @@ -3,7 +3,7 @@ use std::hash::Hash; use crate::bindgen_prelude::{Env, Result, ToNapiValue, *}; -impl TypeName for HashMap { +impl TypeName for HashMap { fn type_name() -> &'static str { "HashMap" } @@ -13,7 +13,7 @@ impl TypeName for HashMap { } } -impl ToNapiValue for HashMap +impl ToNapiValue for HashMap where K: AsRef, V: ToNapiValue,