Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 crates/rspack_plugin_sri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ rspack_hash = { workspace = true }
rspack_hook = { workspace = true }
rspack_paths = { workspace = true }
rspack_plugin_html = { workspace = true }
rspack_plugin_mf = { workspace = true }
rspack_plugin_real_content_hash = { workspace = true }
rspack_plugin_runtime = { workspace = true }
rspack_util = { workspace = true }
Expand Down
21 changes: 15 additions & 6 deletions crates/rspack_plugin_sri/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,15 @@ fn process_chunk_source(
}
}

fn digest_chunks(compilation: &Compilation) -> Vec<HashSet<ChunkUkey>> {
fn digest_chunks(compilation: &Compilation) -> Vec<Vec<ChunkUkey>> {
let mut batches = vec![];
let mut visited_chunk_groups = HashSet::default();
let mut visited_chunks = HashSet::default();
let mut batch_chunk_groups = compilation.entrypoints().values().collect::<Vec<_>>();

while !batch_chunk_groups.is_empty() {
let mut chunk_batch = HashSet::default();
let mut chunk_batch = vec![];
let mut chunk_runtime_batch = vec![];
for chunk_group in std::mem::take(&mut batch_chunk_groups) {
if visited_chunk_groups.contains(chunk_group) {
continue;
Expand All @@ -208,15 +209,23 @@ fn digest_chunks(compilation: &Compilation) -> Vec<HashSet<ChunkUkey>> {
if let Some(chunk_group) = compilation.chunk_group_by_ukey.get(chunk_group) {
batch_chunk_groups.extend(chunk_group.children.iter());
batch_chunk_groups.extend(chunk_group.async_entrypoints_iterable());
for chunk in chunk_group.chunks.iter() {
if visited_chunks.contains(chunk) {
for chunk_ukey in chunk_group.chunks.iter() {
if visited_chunks.contains(chunk_ukey) {
continue;
}
visited_chunks.insert(*chunk);
chunk_batch.insert(*chunk);
let Some(chunk) = compilation.chunk_by_ukey.get(chunk_ukey) else {
continue;
};
visited_chunks.insert(*chunk_ukey);
if chunk.has_runtime(&compilation.chunk_group_by_ukey) {
chunk_runtime_batch.push(*chunk_ukey);
} else {
chunk_batch.push(*chunk_ukey);
}
}
}
}
batches.push(chunk_runtime_batch);
batches.push(chunk_batch);
}
batches.reverse();
Expand Down
6 changes: 1 addition & 5 deletions crates/rspack_plugin_sri/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rspack_core::{
};
use rspack_error::{Result, error};
use rspack_hook::plugin_hook;
use rspack_plugin_mf::{ConsumeSharedModule, ProvideSharedModule};
use rspack_plugin_runtime::{
CreateScriptData, LinkPreloadData, RuntimePluginCreateScript, RuntimePluginLinkPreload,
};
Expand Down Expand Up @@ -83,10 +82,7 @@ impl RuntimeModule for SRIHashVariableRuntimeModule {
.chunk_graph
.get_chunk_modules(&c, &module_graph)
.iter()
.any(|m| {
m.downcast_ref::<ConsumeSharedModule>().is_none()
&& m.downcast_ref::<ProvideSharedModule>().is_none()
});
.any(|m| m.source().is_some());

if has_modules && include_chunks.contains_key(id) {
Some(id)
Expand Down
Loading