-
-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
2,160 additions
and
207 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
crates/rspack_binding_options/src/options/raw_builtins/raw_lazy_compilation.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use napi_derive::napi; | ||
use rspack_core::ModuleIdentifier; | ||
use rspack_napi::threadsafe_function::ThreadsafeFunction; | ||
use rspack_plugin_lazy_compilation::backend::{Backend, ModuleInfo}; | ||
|
||
use crate::RawRegexMatcher; | ||
|
||
#[napi(object)] | ||
pub struct RawModuleInfo { | ||
pub active: bool, | ||
pub client: String, | ||
pub data: String, | ||
} | ||
|
||
#[napi(object, object_to_js = false)] | ||
pub struct RawLazyCompilationOption { | ||
pub module: ThreadsafeFunction<RawModuleArg, RawModuleInfo>, | ||
pub test: Option<RawRegexMatcher>, | ||
pub entries: bool, | ||
pub imports: bool, | ||
pub cacheable: bool, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct RawModuleArg { | ||
pub module: String, | ||
pub path: String, | ||
} | ||
|
||
pub(crate) struct JsBackend { | ||
module: ThreadsafeFunction<RawModuleArg, RawModuleInfo>, | ||
} | ||
|
||
impl std::fmt::Debug for JsBackend { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("JsBackend").finish() | ||
} | ||
} | ||
|
||
impl From<&RawLazyCompilationOption> for JsBackend { | ||
fn from(value: &RawLazyCompilationOption) -> Self { | ||
Self { | ||
module: value.module.clone(), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Backend for JsBackend { | ||
async fn module( | ||
&mut self, | ||
identifier: ModuleIdentifier, | ||
path: String, | ||
) -> rspack_error::Result<ModuleInfo> { | ||
let module_info = self | ||
.module | ||
.call(RawModuleArg { | ||
module: identifier.to_string(), | ||
path, | ||
}) | ||
.await | ||
.expect("channel should have result"); | ||
|
||
Ok(ModuleInfo { | ||
active: module_info.active, | ||
client: module_info.client, | ||
data: module_info.data, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.