Skip to content

Commit

Permalink
feat: make occasion
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrykingxyz committed Dec 5, 2024
1 parent 29b77a1 commit a898ce4
Show file tree
Hide file tree
Showing 205 changed files with 1,749 additions and 139 deletions.
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ rustflags = [
"-Wclippy::empty_structs_with_brackets",
"-Wclippy::rc_buffer",
"-Wclippy::rc_mutex",
"-Wclippy::same_name_method",
# https://github.com/bitflags/bitflags/issues/424
# "-Wclippy::same_name_method",

"-Aclippy::default_constructed_unit_structs",
"--cfg", "tokio_unstable"
Expand Down
29 changes: 28 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ rustc-hash = { version = "2.1.0" }
serde = { version = "1.0.215" }
serde_json = { version = "1.0.133" }
simd-json = { version = "0.14.0-rc.2" }
smol_str = { version = "0.3.0" }
stacker = { version = "0.1.17" }
sugar_path = { version = "1.2.0", features = ["cached_current_dir"] }
syn = { version = "2.0.90" }
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_binding_options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ napi = { workspace = true, features = ["async"
napi-derive = { workspace = true }
pollster = { workspace = true }
rspack_binding_values = { workspace = true }
rspack_cacheable = { workspace = true }
rspack_collections = { workspace = true }
rspack_core = { workspace = true }
rspack_error = { workspace = true }
Expand Down
20 changes: 12 additions & 8 deletions crates/rspack_binding_options/src/plugins/js_loader/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
sync::{Arc, LazyLock},
};

use rspack_cacheable::{cacheable, cacheable_dyn};
use rspack_collections::{Identifiable, Identifier};
use rspack_core::{
BoxLoader, Context, Loader, ModuleRuleUseLoader, NormalModuleFactoryResolveLoader, ResolveResult,
Expand All @@ -24,9 +25,11 @@ use tokio::sync::RwLock;

use super::{JsLoaderRspackPlugin, JsLoaderRspackPluginInner};

#[cacheable]
#[derive(Debug)]
pub struct JsLoader(pub Identifier);

#[cacheable_dyn]
impl Loader<RunnerContext> for JsLoader {}

impl Identifiable for JsLoader {
Expand Down Expand Up @@ -60,14 +63,15 @@ pub async fn get_builtin_loader(builtin: &str, options: Option<&str>) -> Result<
}

let loader = Arc::new(
rspack_loader_swc::SwcLoader::new(serde_json::from_str(options.as_ref()).map_err(|e| {
serde_error_to_miette(
e,
options.clone(),
"failed to parse builtin:swc-loader options",
)
})?)
.with_identifier(builtin.into()),
rspack_loader_swc::SwcLoader::new(options.as_ref())
.map_err(|e| {
serde_error_to_miette(
e,
options.clone(),
"failed to parse builtin:swc-loader options",
)
})?
.with_identifier(builtin.into()),
);

SWC_LOADER_CACHE.write().await.insert(
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_cacheable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ rspack_macros = { workspace = true }
rspack_resolver = { workspace = true }
rspack_sources = { workspace = true }
serde_json = { workspace = true }
smol_str = { workspace = true }
swc_core = { workspace = true, features = ["ecma_ast"] }
ustr = { workspace = true }
1 change: 1 addition & 0 deletions crates/rspack_cacheable/src/with/as_preset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod lightningcss;
mod rspack_resolver;
mod rspack_sources;
mod serde_json;
mod smol_str;
mod swc;
mod ustr;

Expand Down
41 changes: 41 additions & 0 deletions crates/rspack_cacheable/src/with/as_preset/smol_str.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use rkyv::{
rancor::{Fallible, Source},
ser::Writer,
string::{ArchivedString, StringResolver},
with::{ArchiveWith, DeserializeWith, SerializeWith},
Place,
};
use smol_str::SmolStr;

use super::AsPreset;

impl ArchiveWith<SmolStr> for AsPreset {
type Archived = ArchivedString;
type Resolver = StringResolver;

#[inline]
fn resolve_with(field: &SmolStr, resolver: Self::Resolver, out: Place<Self::Archived>) {
ArchivedString::resolve_from_str(field.as_str(), resolver, out);
}
}

impl<S> SerializeWith<SmolStr, S> for AsPreset
where
S: ?Sized + Fallible + Writer,
S::Error: Source,
{
#[inline]
fn serialize_with(field: &SmolStr, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
ArchivedString::serialize_from_str(field.as_str(), serializer)
}
}

impl<D> DeserializeWith<ArchivedString, SmolStr, D> for AsPreset
where
D: ?Sized + Fallible,
{
#[inline]
fn deserialize_with(field: &ArchivedString, _: &mut D) -> Result<SmolStr, D::Error> {
Ok(SmolStr::from(field.as_str()))
}
}
13 changes: 13 additions & 0 deletions crates/rspack_cacheable/src/with/as_ref_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,16 @@ impl AsRefStrConverter for Arc<str> {
}
}
}

// for Box<str>
impl AsRefStrConverter for Box<str> {
fn as_str(&self) -> &str {
self
}
fn from_str(s: &str) -> Self
where
Self: Sized,
{
s.into()
}
}
13 changes: 0 additions & 13 deletions crates/rspack_cacheable/src/with/as_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,3 @@ impl AsStringConverter for PathBuf {
Ok(PathBuf::from(s))
}
}

// for Box<str>
impl AsStringConverter for Box<str> {
fn to_string(&self) -> Result<String, SerializeError> {
Ok(str::to_string(self))
}
fn from_str(s: &str) -> Result<Self, DeserializeError>
where
Self: Sized,
{
Ok(s.into())
}
}
Loading

0 comments on commit a898ce4

Please sign in to comment.