Skip to content

Commit

Permalink
Merge branch 'main' into changeset-release/main
Browse files Browse the repository at this point in the history
  • Loading branch information
GiveMe-A-Name authored Oct 10, 2024
2 parents 1372329 + 5416306 commit adcabc6
Show file tree
Hide file tree
Showing 66 changed files with 1,978 additions and 2,104 deletions.
28 changes: 23 additions & 5 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"timezone": "Asia/Shanghai",
"extends": [":dependencyDashboard"],
"extends": [
":dependencyDashboard"
],
"schedule": [
"before 8am on wednesday"
],
Expand Down Expand Up @@ -120,10 +122,14 @@
],
"excludePackageNames": [
"typescript",
"pnpm"
"pnpm",
"@playwright/test"
],
// bump major in a separate PR
"matchUpdateTypes": ["patch", "minor"]
"matchUpdateTypes": [
"patch",
"minor"
]
},
{
"groupName": "npm dependencies",
Expand All @@ -134,7 +140,10 @@
"dependencies"
],
// bump major in a separate PR
"matchUpdateTypes": ["patch", "minor"]
"matchUpdateTypes": [
"patch",
"minor"
]
},
{
"groupName": "webpack",
Expand All @@ -145,6 +154,15 @@
"webpack"
],
"enabled": false
},
{
"groupName": "playwright",
"matchManagers": [
"npm"
],
"matchPackagePrefixes": [
"@playwright/test"
]
}
]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: crate-ci/typos@v1.25.0
- uses: crate-ci/typos@v1.26.0
with:
files: .

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ jobs:
- name: Run e2e
uses: ./.github/actions/docker-run
with:
image: mcr.microsoft.com/playwright:v1.35.0-jammy
image: mcr.microsoft.com/playwright:v1.47.0-jammy
# .cache is required by download artifact, and mount in ./.github/actions/docker-run
# .tool_cache is required by pnpm
options: -v ${{ runner.tool_cache }}:$HOME/.tool_cache
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

20 changes: 20 additions & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,26 @@ export interface RawJavascriptParserOptions {
worker?: Array<string>
overrideStrict?: string
importMeta?: boolean
/**
* This option is experimental in Rspack only and subject to change or be removed anytime.
* @experimental
*/
requireAsExpression?: boolean
/**
* This option is experimental in Rspack only and subject to change or be removed anytime.
* @experimental
*/
requireDynamic?: boolean
/**
* This option is experimental in Rspack only and subject to change or be removed anytime.
* @experimental
*/
requireResolve?: boolean
/**
* This option is experimental in Rspack only and subject to change or be removed anytime.
* @experimental
*/
importDynamic?: boolean
}

export interface RawLazyCompilationOption {
Expand Down
16 changes: 16 additions & 0 deletions crates/rspack_binding_options/src/options/raw_module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ pub struct RawJavascriptParserOptions {
pub worker: Option<Vec<String>>,
pub override_strict: Option<String>,
pub import_meta: Option<bool>,
/// This option is experimental in Rspack only and subject to change or be removed anytime.
/// @experimental
pub require_as_expression: Option<bool>,
/// This option is experimental in Rspack only and subject to change or be removed anytime.
/// @experimental
pub require_dynamic: Option<bool>,
/// This option is experimental in Rspack only and subject to change or be removed anytime.
/// @experimental
pub require_resolve: Option<bool>,
/// This option is experimental in Rspack only and subject to change or be removed anytime.
/// @experimental
pub import_dynamic: Option<bool>,
}

impl From<RawJavascriptParserOptions> for JavascriptParserOptions {
Expand Down Expand Up @@ -307,6 +319,10 @@ impl From<RawJavascriptParserOptions> for JavascriptParserOptions {
.override_strict
.map(|e| OverrideStrict::from(e.as_str())),
import_meta: value.import_meta,
require_as_expression: value.require_as_expression,
require_dynamic: value.require_dynamic,
require_resolve: value.require_resolve,
import_dynamic: value.import_dynamic,
}
}
}
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 @@ -14,6 +14,7 @@ napi-derive = { workspace = true }
rspack_collections = { version = "0.1.0", path = "../rspack_collections" }
rspack_core = { version = "0.1.0", path = "../rspack_core" }
rspack_error = { version = "0.1.0", path = "../rspack_error" }
rspack_hash = { version = "0.1.0", path = "../rspack_hash" }
rspack_napi = { version = "0.1.0", path = "../rspack_napi" }
rspack_plugin_html = { version = "0.1.0", path = "../rspack_plugin_html" }
rspack_plugin_runtime = { version = "0.1.0", path = "../rspack_plugin_runtime" }
Expand Down
14 changes: 10 additions & 4 deletions crates/rspack_binding_values/src/compilation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ impl JsCompilation {
filename: LocalJsFilename,
data: JsPathData,
) -> napi::Result<String> {
let chunk = data.chunk.as_ref().map(|c| c.to_chunk(self.0));
self
.0
.get_asset_path(&filename.into(), data.as_core_path_data())
.get_asset_path(&filename.into(), data.as_core_path_data(chunk.as_ref()))
}

#[napi]
Expand All @@ -398,15 +399,19 @@ impl JsCompilation {
filename: LocalJsFilename,
data: JsPathData,
) -> napi::Result<PathWithInfo> {
let chunk = data.chunk.as_ref().map(|c| c.to_chunk(self.0));
let path_and_asset_info = self
.0
.get_asset_path_with_info(&filename.into(), data.as_core_path_data())?;
.get_asset_path_with_info(&filename.into(), data.as_core_path_data(chunk.as_ref()))?;
Ok(path_and_asset_info.into())
}

#[napi]
pub fn get_path(&self, filename: LocalJsFilename, data: JsPathData) -> napi::Result<String> {
self.0.get_path(&filename.into(), data.as_core_path_data())
let chunk = data.chunk.as_ref().map(|c| c.to_chunk(self.0));
self
.0
.get_path(&filename.into(), data.as_core_path_data(chunk.as_ref()))
}

#[napi]
Expand All @@ -415,9 +420,10 @@ impl JsCompilation {
filename: LocalJsFilename,
data: JsPathData,
) -> napi::Result<PathWithInfo> {
let chunk = data.chunk.as_ref().map(|c| c.to_chunk(self.0));
let path_and_asset_info = self
.0
.get_path_with_info(&filename.into(), data.as_core_path_data())?;
.get_path_with_info(&filename.into(), data.as_core_path_data(chunk.as_ref()))?;
Ok(path_and_asset_info.into())
}

Expand Down
49 changes: 47 additions & 2 deletions crates/rspack_binding_values/src/path_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::collections::HashMap;

use napi::Either;
use napi_derive::napi;
use rspack_core::{Chunk, Compilation, SourceType};
use rspack_hash::RspackHashDigest;

use super::JsAssetInfo;

Expand Down Expand Up @@ -35,9 +37,48 @@ pub struct JsChunkPathData {
pub id: Option<String>,
pub name: Option<String>,
pub hash: Option<String>,
// TODO: support custom content hash type
pub content_hash: Option<Either<String, HashMap<String, String>>>,
}

impl JsChunkPathData {
pub fn to_chunk(&self, compilation: &Compilation) -> Chunk {
let mut chunk = rspack_core::Chunk::new(self.name.clone(), rspack_core::ChunkKind::Normal);
chunk.id = self.id.clone();
chunk.hash = self
.hash
.clone()
.map(|s| RspackHashDigest::new(s.into(), &compilation.options.output.hash_digest));

chunk.rendered_hash = self.hash.as_ref().map(|d| {
if d.len() < compilation.options.output.hash_digest_length {
d.as_str().into()
} else {
d[..compilation.options.output.hash_digest_length].into()
}
});
if let Some(hash) = self.content_hash.as_ref() {
match hash {
Either::A(hash) => {
chunk.content_hash.insert(
SourceType::Unknown,
RspackHashDigest::new(hash.clone().into(), &compilation.options.output.hash_digest),
);
}
Either::B(map) => {
for (key, hash) in map {
chunk.content_hash.insert(
SourceType::from(key.as_str()),
RspackHashDigest::new(hash.clone().into(), &compilation.options.output.hash_digest),
);
}
}
}
}
chunk
}
}

impl<'a> From<&'a rspack_core::Chunk> for JsChunkPathData {
fn from(chunk: &'a rspack_core::Chunk) -> Self {
Self {
Expand All @@ -56,10 +97,14 @@ impl<'a> From<&'a rspack_core::Chunk> for JsChunkPathData {
}

impl JsPathData {
pub fn as_core_path_data(&self) -> rspack_core::PathData {
pub fn as_core_path_data<'a>(
&'a self,
chunk: Option<&'a rspack_core::Chunk>,
) -> rspack_core::PathData<'a> {
rspack_core::PathData {
filename: self.filename.as_deref(),
chunk: None,
chunk,
// TODO: support custom module
module: None,
hash: self.hash.as_deref(),
content_hash: self.content_hash.as_deref(),
Expand Down
5 changes: 5 additions & 0 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,11 @@ impl Module for ConcatenatedModule {
exports_final_names_map,
));
}
code_generation_result.set_hash(
&compilation.options.output.hash_function,
&compilation.options.output.hash_digest,
&compilation.options.output.hash_salt,
);
Ok(code_generation_result)
}

Expand Down
8 changes: 4 additions & 4 deletions crates/rspack_core/src/dependency/runtime_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ pub fn block_promise(
message: Some(message),
},
);
return format!("Promise.resolve({comment})");
return format!("Promise.resolve({})", comment.trim());
};
let chunk_group = compilation
.chunk_graph
Expand All @@ -551,7 +551,7 @@ pub fn block_promise(
message: Some(message),
},
);
return format!("Promise.resolve({comment})");
return format!("Promise.resolve({})", comment.trim());
};
if chunk_group.chunks.is_empty() {
let comment = comment(
Expand All @@ -562,7 +562,7 @@ pub fn block_promise(
message: Some(message),
},
);
return format!("Promise.resolve({comment})");
return format!("Promise.resolve({})", comment.trim());
}
let mg = compilation.get_module_graph();
let block = mg.block_by_id_expect(block);
Expand Down Expand Up @@ -631,7 +631,7 @@ pub fn block_promise(
.join(", ")
)
} else {
format!("Promise.resolve({comment})")
format!("Promise.resolve({})", comment.trim())
}
}

Expand Down
Loading

0 comments on commit adcabc6

Please sign in to comment.