Merge pull request #904 from napi-rs/swc-fix

Swc fix
This commit is contained in:
LongYinan 2021-12-03 17:02:04 +08:00 committed by GitHub
commit 99863f314d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 8 deletions

View file

@ -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 {}

View file

@ -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))

View file

@ -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"]

View file

@ -3,7 +3,7 @@ use std::hash::Hash;
use crate::bindgen_prelude::{Env, Result, ToNapiValue, *};
impl<K, V> TypeName for HashMap<K, V> {
impl<K, V, S> TypeName for HashMap<K, V, S> {
fn type_name() -> &'static str {
"HashMap"
}
@ -13,7 +13,7 @@ impl<K, V> TypeName for HashMap<K, V> {
}
}
impl<K, V> ToNapiValue for HashMap<K, V>
impl<K, V, S> ToNapiValue for HashMap<K, V, S>
where
K: AsRef<str>,
V: ToNapiValue,

View file

@ -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 {

View file

@ -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 {

View file

@ -183,6 +183,8 @@ pub(crate) unsafe fn log_js_value<V: AsRef<[sys::napi_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;

View file

@ -5,8 +5,8 @@ use napi::{
use napi_derive::js_function;
#[derive(Clone)]
struct A {
cb: ThreadsafeFunction<String>,
pub struct A {
pub cb: ThreadsafeFunction<String>,
}
#[js_function(1)]