Skip to content

Commit 0c3f666

Browse files
committed
feat: remove napi in core crate
1 parent 8befd7c commit 0c3f666

File tree

6 files changed

+36
-35
lines changed

6 files changed

+36
-35
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/binding/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ crate-type = ["cdylib"]
1515
napi = { version = "2.12.0", default-features = false, features = ["napi4", "async"] }
1616
napi-derive = { version = "2.12.2" }
1717
swc_core = { version = "0.100.1", features = ["base_node"] }
18-
svgr-rs = { path = "../core", features = ["node"] }
18+
svgr-rs = { path = "../core" }
1919

2020
[build-dependencies]
2121
napi-build = "2.0.1"

crates/binding/src/lib.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,49 @@
44
#[macro_use]
55
extern crate napi_derive;
66

7-
use svgr_rs::{transform, Config, State};
7+
use svgr_rs::{transform, Caller, Config, State};
88
use swc_core::node::get_deserialized;
99

10+
#[napi(object, object_to_js = false)]
11+
pub struct JsCaller {
12+
pub name: Option<String>,
13+
pub previous_export: Option<String>,
14+
}
15+
16+
impl From<JsCaller> for Caller {
17+
fn from(val: JsCaller) -> Self {
18+
Self {
19+
name: val.name,
20+
previous_export: val.previous_export,
21+
}
22+
}
23+
}
24+
25+
#[napi(object, object_to_js = false)]
26+
pub struct JsState {
27+
pub file_path: Option<String>,
28+
pub component_name: Option<String>,
29+
pub caller: Option<JsCaller>,
30+
}
31+
32+
impl From<JsState> for State {
33+
fn from(val: JsState) -> Self {
34+
Self {
35+
file_path: val.file_path,
36+
component_name: val.component_name,
37+
caller: val.caller.map(|c| c.into()),
38+
}
39+
}
40+
}
41+
1042
#[napi(js_name = "transform")]
1143
pub async fn transform_node(
1244
code: String,
1345
config: napi::bindgen_prelude::Buffer,
14-
state: Option<State>,
46+
js_state: Option<JsState>,
1547
) -> napi::bindgen_prelude::Result<String> {
1648
let config: Config = get_deserialized(&config)?;
17-
let state = state.unwrap_or_default();
49+
let state = js_state.map(|s| s.into()).unwrap_or_default();
1850
match transform(code, config, state) {
1951
Ok(result) => napi::bindgen_prelude::Result::Ok(result),
2052
Err(reason) => napi::bindgen_prelude::Result::Err(napi::bindgen_prelude::Error::from_reason(

crates/core/Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ license = "MIT"
77
repository = "https://github.com/svg-rust/svgr-rs.git"
88
version = "0.1.3"
99

10-
[features]
11-
node = ["dep:napi", "dep:napi-derive"]
12-
1310
[dependencies]
14-
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
15-
napi = { version = "2.12.0", default-features = false, features = ["napi4", "async"], optional = true }
16-
napi-derive = { version = "2.12.2", optional = true }
17-
1811
clap = { version = "4.2.0", features = ["derive"] }
1912
regex = "1.7.3"
2013
serde = { version = "1", features = ["derive"] }

crates/core/src/core/state.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,13 @@ use std::path::Path;
33
use lazy_static::lazy_static;
44
use regex::Regex;
55

6-
#[cfg(feature = "node")]
7-
#[napi(object)]
8-
#[derive(Debug, Clone, Default)]
9-
pub struct Caller {
10-
pub name: Option<String>,
11-
pub previous_export: Option<String>,
12-
}
13-
14-
#[cfg(not(feature = "node"))]
156
#[derive(Debug, Clone, Default)]
167
pub struct Caller {
178
pub name: Option<String>,
189
pub previous_export: Option<String>,
1910
}
2011

2112
/// The state linked to the transformation.
22-
#[cfg(feature = "node")]
23-
#[napi(object, js_name = "State")]
2413
pub struct Config {
2514
/// The name of the file that is generated, mainly used to find runtime config file to apply.
2615
pub file_path: Option<String>,
@@ -44,13 +33,6 @@ impl Default for Config {
4433
}
4534
}
4635

47-
#[cfg(not(feature = "node"))]
48-
pub struct Config {
49-
pub file_path: Option<String>,
50-
pub component_name: Option<String>,
51-
pub caller: Option<Caller>,
52-
}
53-
5436
#[derive(Debug)]
5537
pub struct InternalConfig {
5638
#[allow(dead_code)]

crates/core/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#![feature(path_file_prefix)]
22
#![deny(clippy::all)]
33

4-
#[cfg(feature = "node")]
5-
#[macro_use]
6-
extern crate napi_derive;
7-
84
use std::{borrow::Borrow, sync::Arc};
95

106
use swc_core::{

0 commit comments

Comments
 (0)