Skip to content

Commit

Permalink
chore: revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 20, 2024
1 parent e60b636 commit 68bdad8
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 133 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ serde = "1.0.211"
serde_json = "1.0.132"
swc_core = { version = "0.101.4", default-features = false }
tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls"] }
parking_lot = "0.12.3"

[profile.release]
debug = false
Expand Down
1 change: 0 additions & 1 deletion crates/binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ napi-derive = "2.16.12"
oneshot = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
parking_lot = { workspace = true }

[target.'cfg(not(target_os = "linux"))'.dependencies]
mimalloc-rust = { workspace = true }
Expand Down
65 changes: 0 additions & 65 deletions crates/binding/src/context.rs

This file was deleted.

24 changes: 0 additions & 24 deletions crates/binding/src/js_hook.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use napi::bindgen_prelude::*;
use napi::JsObject;
use napi::NapiRaw;
use napi_derive::napi;
use serde_json::Value;
Expand Down Expand Up @@ -82,29 +81,6 @@ pub struct JsHooks {
pub transform_include: Option<JsFunction>,
}

// #[napi(object)]
// pub struct JsPluginContext {
// pub root: String,
// pub error: Option<JsFunction>,
// }

// impl JsPluginContext {
// pub fn new() -> Self {
// Self {
// root: "root".to_string(),
// // error: None,
// }
// }

// #[napi]
// pub async fn testtest(&self, err: Error) {
// println!(">>> error: {}", err.to_string());
// }
// }

// pub unsafe fn create_js_plugin_context(env: Env) -> Result<JsPluginContext> {
// }

pub struct TsFnHooks {
pub build_start: Option<ThreadsafeFunction<(), ()>>,
pub build_end: Option<ThreadsafeFunction<(), ()>>,
Expand Down
1 change: 0 additions & 1 deletion crates/binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use napi_derive::napi;
mod js_hook;
mod js_plugin;
mod threadsafe_function;
mod context;

#[cfg(not(target_os = "linux"))]
#[global_allocator]
Expand Down
28 changes: 4 additions & 24 deletions crates/binding/src/threadsafe_function.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
use std::marker::PhantomData;

use anyhow::{anyhow, Result};
use napi::bindgen_prelude::{spawn, FromNapiValue, JsValuesTupleIntoVec, Promise, ToNapiValue};
use napi::bindgen_prelude::{spawn, FromNapiValue, JsValuesTupleIntoVec, Promise};
use napi::sys::{napi_env, napi_value};
use napi::threadsafe_function::{
ErrorStrategy, ThreadsafeFunction as Tsfn, ThreadsafeFunctionCallMode,
};
use napi::{JsObject, JsUnknown};
use napi::JsUnknown;
use oneshot::channel;

use crate::context::create_js_context;

pub struct ThreadsafeFunction<P: 'static, R> {
tsfn: Tsfn<Args<P>, ErrorStrategy::Fatal>,
tsfn: Tsfn<P, ErrorStrategy::Fatal>,
env: napi_env,
_phantom: PhantomData<R>,
}

struct Args<P>(JsObject, P);

impl<P> JsValuesTupleIntoVec for Args<P>
where
P: JsValuesTupleIntoVec,
{
fn into_vec(self, env: napi::sys::napi_env) -> napi::Result<Vec<napi::sys::napi_value>> {
Ok([
vec![unsafe { ToNapiValue::to_napi_value(env, self.0)? }],
JsValuesTupleIntoVec::into_vec(self.1, env)?,
]
.concat())
}
}

impl<P: 'static, R> Clone for ThreadsafeFunction<P, R> {
fn clone(&self) -> Self {
Self {
Expand All @@ -56,11 +39,8 @@ impl<P: 'static + JsValuesTupleIntoVec, R> FromNapiValue for ThreadsafeFunction<
impl<P: 'static, R: FromNapiValue + Send + 'static> ThreadsafeFunction<P, R> {
pub fn call(&self, value: P) -> Result<R> {
let (sender, receiver) = channel();
let ctx = unsafe { create_js_context(self.env) };
// load(path)
// load(ctx, path)
self.tsfn.call_with_return_value(
Args(ctx, value),
value,
ThreadsafeFunctionCallMode::NonBlocking,
move |r: JsUnknown| {
if r.is_promise().unwrap() {
Expand Down
13 changes: 0 additions & 13 deletions crates/mako/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ use crate::stats::StatsInfo;
use crate::utils::id_helper::{assign_numeric_ids, compare_modules_by_incoming_edges};
use crate::utils::{thread_pool, ParseRegex};

#[derive(Default)]
pub struct PluginContext {
}

impl PluginContext {
pub fn error(&self, err: Error) {
println!("{}", err.to_string().red());
}
}

pub struct Context {
pub module_graph: RwLock<ModuleGraph>,
pub chunk_graph: RwLock<ChunkGraph>,
Expand All @@ -48,7 +38,6 @@ pub struct Context {
pub root: PathBuf,
pub meta: Meta,
pub plugin_driver: PluginDriver,
pub plugin_context: Arc<PluginContext>,
pub stats_info: StatsInfo,
pub resolvers: Resolvers,
pub static_cache: RwLock<MemoryChunkFileCache>,
Expand Down Expand Up @@ -139,7 +128,6 @@ impl Default for Context {
modules_with_missing_deps: RwLock::new(Vec::new()),
meta: Meta::new(),
plugin_driver: Default::default(),
plugin_context: Arc::new(Default::default()),
stats_info: StatsInfo::new(),
resolvers,
optimize_infos: Mutex::new(None),
Expand Down Expand Up @@ -383,7 +371,6 @@ impl Compiler {
modules_with_missing_deps: RwLock::new(Vec::new()),
meta: Meta::new(),
plugin_driver,
plugin_context: Default::default(),
numeric_ids_map: RwLock::new(numeric_ids_map),
stats_info: StatsInfo::new(),
resolvers,
Expand Down
3 changes: 0 additions & 3 deletions packages/mako/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ export interface JsHooks {
) => Promise<{ content: string; type: 'css' | 'js' } | void> | void;
transformInclude?: (filePath: string) => Promise<bool> | bool;
}
export interface JsPluginContext {
root: string;
}
export interface WriteFile {
path: string;
content: Buffer;
Expand Down

0 comments on commit 68bdad8

Please sign in to comment.