Skip to content

Commit

Permalink
chore: merge origin main
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Sep 19, 2024
2 parents b790814 + 2164f12 commit f3125fa
Show file tree
Hide file tree
Showing 106 changed files with 785 additions and 542 deletions.
26 changes: 26 additions & 0 deletions 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 @@ -22,6 +22,7 @@ async-trait = { version = "0.1.79" }
bitflags = { version = "2.5.0" }
camino = { version = "1.1.8" }
concat-string = { version = "1.0.1" }
cow-utils = { version = "0.1.3" }
css-module-lexer = { version = "0.0.14" }
dashmap = { version = "5.5.3" }
derivative = { version = "2.2.0" }
Expand Down
9 changes: 9 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
allow-dbg-in-tests = true
allow-unwrap-in-tests = true

disallowed-methods = [
{ path = "str::to_ascii_lowercase", reason = "To avoid memory allocation, use `cow_utils::CowUtils::cow_to_ascii_lowercase` instead." },
{ path = "str::to_ascii_uppercase", reason = "To avoid memory allocation, use `cow_utils::CowUtils::cow_to_ascii_uppercase` instead." },
{ path = "str::to_lowercase", reason = "To avoid memory allocation, use `cow_utils::CowUtils::cow_to_lowercase` instead." },
{ path = "str::to_uppercase", reason = "To avoid memory allocation, use `cow_utils::CowUtils::cow_to_uppercase` instead." },
{ path = "str::replace", reason = "To avoid memory allocation, use `cow_utils::CowUtils::replace` instead." },
{ path = "str::replacen", reason = "To avoid memory allocation, use `cow_utils::CowUtils::replacen` instead." },
]
1 change: 1 addition & 0 deletions crates/node_binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rspack_tracing = { version = "0.1.0", path = "../rspack_tracing" }
tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }

async-trait = { workspace = true }
cow-utils = { workspace = true }
once_cell = { workspace = true }
tracing = { workspace = true }

Expand Down
8 changes: 2 additions & 6 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,8 @@ export interface JsCodegenerationResults {
}

export interface JsCompatSource {
/** Whether the underlying data structure is a `RawSource` */
isRaw: boolean
/** Whether the underlying value is a buffer or string */
isBuffer: boolean
source: Buffer
map?: Buffer
source: string | Buffer
map?: string
}

export interface JsContextModuleFactoryAfterResolveData {
Expand Down
26 changes: 15 additions & 11 deletions crates/node_binding/src/plugins/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use std::{
};

use async_trait::async_trait;
use cow_utils::CowUtils;
use napi::{
bindgen_prelude::{Buffer, FromNapiValue, Promise, ToNapiValue},
Env, JsFunction, NapiRaw,
};
use rspack_binding_values::{
CompatSource, JsAdditionalTreeRuntimeRequirementsArg, JsAdditionalTreeRuntimeRequirementsResult,
JsAdditionalTreeRuntimeRequirementsArg, JsAdditionalTreeRuntimeRequirementsResult,
JsAfterEmitData, JsAfterResolveData, JsAfterResolveOutput, JsAfterTemplateExecutionData,
JsAlterAssetTagGroupsData, JsAlterAssetTagsData, JsAssetEmittedArgs,
JsBeforeAssetTagGenerationData, JsBeforeEmitData, JsBeforeResolveArgs, JsBeforeResolveOutput,
Expand All @@ -23,14 +24,13 @@ use rspack_binding_values::{
};
use rspack_collections::IdentifierSet;
use rspack_core::{
parse_resource, rspack_sources::SourceExt, AfterResolveData, AfterResolveResult,
AssetEmittedInfo, BeforeResolveData, BeforeResolveResult, BoxModule, Chunk, ChunkUkey,
CodeGenerationResults, Compilation, CompilationAdditionalTreeRuntimeRequirements,
CompilationAdditionalTreeRuntimeRequirementsHook, CompilationAfterOptimizeModules,
CompilationAfterOptimizeModulesHook, CompilationAfterProcessAssets,
CompilationAfterProcessAssetsHook, CompilationAfterSeal, CompilationAfterSealHook,
CompilationBuildModule, CompilationBuildModuleHook, CompilationChunkAsset,
CompilationChunkAssetHook, CompilationChunkHash, CompilationChunkHashHook,
parse_resource, AfterResolveData, AfterResolveResult, AssetEmittedInfo, BeforeResolveData,
BeforeResolveResult, BoxModule, Chunk, ChunkUkey, CodeGenerationResults, Compilation,
CompilationAdditionalTreeRuntimeRequirements, CompilationAdditionalTreeRuntimeRequirementsHook,
CompilationAfterOptimizeModules, CompilationAfterOptimizeModulesHook,
CompilationAfterProcessAssets, CompilationAfterProcessAssetsHook, CompilationAfterSeal,
CompilationAfterSealHook, CompilationBuildModule, CompilationBuildModuleHook,
CompilationChunkAsset, CompilationChunkAssetHook, CompilationChunkHash, CompilationChunkHashHook,
CompilationExecuteModule, CompilationExecuteModuleHook, CompilationFinishModules,
CompilationFinishModulesHook, CompilationOptimizeChunkModules,
CompilationOptimizeChunkModulesHook, CompilationOptimizeModules, CompilationOptimizeModulesHook,
Expand Down Expand Up @@ -1161,7 +1161,11 @@ impl CompilationRuntimeModule for CompilationRuntimeModuleTap {
),
module_identifier: module.identifier().to_string(),
constructor_name: module.get_constructor_name(),
name: module.name().to_string().replace("webpack/runtime/", ""),
name: module
.name()
.as_str()
.cow_replace("webpack/runtime/", "")
.into_owned(),
},
chunk: JsChunk::from(chunk),
};
Expand All @@ -1172,7 +1176,7 @@ impl CompilationRuntimeModule for CompilationRuntimeModuleTap {
.runtime_modules
.get_mut(m)
.expect("should have module");
module.set_custom_source(CompatSource::from(source).boxed())
module.set_custom_source(source.into())
}
Ok(())
}
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 @@ -14,6 +14,7 @@ ignored = ["tracing"]

[dependencies]
async-trait = { workspace = true }
cow-utils = { workspace = true }
derivative = { workspace = true }
futures = { workspace = true }
glob = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cow_utils::CowUtils;
use derivative::Derivative;
use napi::{bindgen_prelude::Buffer, Either};
use napi_derive::napi;
Expand Down Expand Up @@ -110,7 +111,7 @@ impl From<RawCopyPattern> for CopyPattern {
}),
context: context.map(Into::into),
to_type: if let Some(to_type) = to_type {
match to_type.to_lowercase().as_str() {
match to_type.cow_to_lowercase().as_ref() {
"dir" => Some(ToType::Dir),
"file" => Some(ToType::File),
"template" => Some(ToType::Template),
Expand Down Expand Up @@ -143,7 +144,7 @@ impl From<RawCopyPattern> for CopyPattern {
fn convert_to_enum(input: Either<String, Buffer>) -> RawSource {
match input {
Either::A(s) => RawSource::from(s),
Either::B(b) => RawSource::from(b.to_vec()),
Either::B(b) => RawSource::from(Vec::<u8>::from(b)),
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/rspack_binding_values/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "rspack_binding_values"
repository = "https://github.com/web-infra-dev/rspack"
version = "0.1.0"
[dependencies]
cow-utils = { workspace = true }
futures = { workspace = true }
heck = { workspace = true }
napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow"] }
Expand Down
17 changes: 7 additions & 10 deletions crates/rspack_binding_values/src/compilation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use rspack_collections::IdentifierSet;
use rspack_core::get_chunk_from_ukey;
use rspack_core::get_chunk_group_from_ukey;
use rspack_core::rspack_sources::BoxSource;
use rspack_core::rspack_sources::SourceExt;
use rspack_core::AssetInfo;
use rspack_core::CompilationId;
use rspack_core::ModuleIdentifier;
Expand All @@ -30,8 +29,8 @@ use crate::JsStatsOptimizationBailout;
use crate::LocalJsFilename;
use crate::ModuleDTOWrapper;
use crate::{
chunk::JsChunk, CompatSource, JsAsset, JsAssetInfo, JsChunkGroup, JsCompatSource, JsPathData,
JsStats, ToJsCompatSource,
chunk::JsChunk, JsAsset, JsAssetInfo, JsChunkGroup, JsCompatSource, JsPathData, JsStats,
ToJsCompatSource,
};
use crate::{JsDiagnostic, JsRspackError};

Expand Down Expand Up @@ -68,11 +67,11 @@ impl JsCompilation {
.update_asset(&filename, |original_source, mut original_info| {
let new_source: napi::Result<BoxSource> = try {
let new_source = match new_source_or_function {
Either::A(new_source) => Into::<CompatSource>::into(new_source).boxed(),
Either::A(new_source) => new_source.into(),
Either::B(new_source_fn) => {
let compat_source: CompatSource =
let js_compat_source: JsCompatSource =
new_source_fn.call1(original_source.to_js_compat_source())?;
compat_source.boxed()
js_compat_source.into()
}
};
new_source
Expand Down Expand Up @@ -202,7 +201,7 @@ impl JsCompilation {

#[napi]
pub fn set_asset_source(&mut self, name: String, source: JsCompatSource) {
let source = CompatSource::from(source).boxed();
let source: BoxSource = source.into();
match self.0.assets_mut().entry(name) {
std::collections::hash_map::Entry::Occupied(mut e) => e.get_mut().set_source(Some(source)),
std::collections::hash_map::Entry::Vacant(e) => {
Expand Down Expand Up @@ -256,11 +255,9 @@ impl JsCompilation {

#[napi]
pub fn emit_asset(&mut self, filename: String, source: JsCompatSource, asset_info: JsAssetInfo) {
let compat_source: CompatSource = source.into();

self.0.emit_asset(
filename,
rspack_core::CompilationAsset::new(Some(compat_source.boxed()), asset_info.into()),
rspack_core::CompilationAsset::new(Some(source.into()), asset_info.into()),
);
}

Expand Down
7 changes: 4 additions & 3 deletions crates/rspack_binding_values/src/html.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use cow_utils::CowUtils;
use napi::Either;
use napi_derive::napi;
use rspack_plugin_html::{
Expand Down Expand Up @@ -54,13 +55,13 @@ impl From<JsHtmlPluginTag> for HtmlPluginTag {
.filter_map(|(key, value)| {
value.as_ref().and_then(|v| match v {
Either::A(x) => Some(HtmlPluginAttribute {
attr_name: key.to_ascii_lowercase(),
attr_value: Some(x.to_ascii_lowercase()),
attr_name: key.cow_to_ascii_lowercase().into_owned(),
attr_value: Some(x.cow_to_ascii_lowercase().into_owned()),
}),
Either::B(x) => {
if *x {
Some(HtmlPluginAttribute {
attr_name: key.to_ascii_lowercase(),
attr_name: key.cow_to_ascii_lowercase().into_owned(),
attr_value: None,
})
} else {
Expand Down
Loading

0 comments on commit f3125fa

Please sign in to comment.