Skip to content

Commit 4d3257f

Browse files
stormslowlyCopilot
andauthored
refactor: use read only compilation reference in after process assets hook (#12615)
* refactor: use RO compilation ref in after process assets * Update crates/rspack_plugin_progress/src/lib.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 61a248b commit 4d3257f

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

crates/rspack_binding_api/src/plugins/interceptor.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use rspack_core::{
4444
Scheme, build_module_graph::BuildModuleGraphArtifact, parse_resource,
4545
rspack_sources::RawStringSource,
4646
};
47+
use rspack_error::Diagnostic;
4748
use rspack_hash::RspackHash;
4849
use rspack_hook::{Hook, Interceptor};
4950
use rspack_napi::threadsafe_function::ThreadsafeFunction;
@@ -1441,7 +1442,11 @@ impl CompilationProcessAssets for CompilationProcessAssetsTap {
14411442

14421443
#[async_trait]
14431444
impl CompilationAfterProcessAssets for CompilationAfterProcessAssetsTap {
1444-
async fn run(&self, compilation: &mut Compilation) -> rspack_error::Result<()> {
1445+
async fn run(
1446+
&self,
1447+
compilation: &Compilation,
1448+
_diagnostics: &mut Vec<Diagnostic>,
1449+
) -> rspack_error::Result<()> {
14451450
let compilation = JsCompilationWrapper::new(compilation);
14461451
self.function.call_with_sync(compilation).await
14471452
}

crates/rspack_core/src/compilation/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ define_hook!(CompilationDependentFullHash: SeriesBail(compilation: &Compilation,
101101
define_hook!(CompilationRenderManifest: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, manifest: &mut Vec<RenderManifestEntry>, diagnostics: &mut Vec<Diagnostic>),tracing=false);
102102
define_hook!(CompilationChunkAsset: Series(compilation: &Compilation, chunk_ukey: &ChunkUkey, filename: &str));
103103
define_hook!(CompilationProcessAssets: Series(compilation: &mut Compilation));
104-
define_hook!(CompilationAfterProcessAssets: Series(compilation: &mut Compilation));
104+
define_hook!(CompilationAfterProcessAssets: Series(compilation: &Compilation, diagnostics: &mut Vec<Diagnostic>));
105105
define_hook!(CompilationAfterSeal: Series(compilation: &Compilation),tracing=true);
106106

107107
#[derive(Debug, Default)]
@@ -1383,11 +1383,16 @@ impl Compilation {
13831383

13841384
#[instrument("Compilation:after_process_assets", skip_all)]
13851385
async fn after_process_assets(&mut self, plugin_driver: SharedPluginDriver) -> Result<()> {
1386-
plugin_driver
1386+
let mut diagnostics: Vec<Diagnostic> = vec![];
1387+
1388+
let res = plugin_driver
13871389
.compilation_hooks
13881390
.after_process_assets
1389-
.call(self)
1390-
.await
1391+
.call(self, &mut diagnostics)
1392+
.await;
1393+
1394+
self.extend_diagnostics(diagnostics);
1395+
res
13911396
}
13921397

13931398
#[instrument("Compilation:after_seal", target=TRACING_BENCH_TARGET,skip_all)]

crates/rspack_plugin_progress/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,11 @@ async fn process_assets(&self, _compilation: &mut Compilation) -> Result<()> {
519519
}
520520

521521
#[plugin_hook(CompilationAfterProcessAssets for ProgressPlugin)]
522-
async fn after_process_assets(&self, _compilation: &mut Compilation) -> Result<()> {
522+
async fn after_process_assets(
523+
&self,
524+
_compilation: &Compilation,
525+
_diagnostics: &mut Vec<Diagnostic>,
526+
) -> Result<()> {
523527
self
524528
.sealing_hooks_report("after asset optimization", 36)
525529
.await

crates/rspack_plugin_rsdoctor/src/plugin.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,11 @@ async fn after_code_generation(&self, compilation: &mut Compilation) -> Result<(
452452
}
453453

454454
#[plugin_hook(CompilationAfterProcessAssets for RsdoctorPlugin, stage = 9999)]
455-
async fn after_process_assets(&self, compilation: &mut Compilation) -> Result<()> {
455+
async fn after_process_assets(
456+
&self,
457+
compilation: &Compilation,
458+
_diagnostics: &mut Vec<Diagnostic>,
459+
) -> Result<()> {
456460
if !self.has_chunk_graph_feature(RsdoctorPluginChunkGraphFeature::Assets) {
457461
return Ok(());
458462
}

crates/rspack_plugin_sri/src/asset.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ pub async fn handle_assets(&self, compilation: &mut Compilation) -> Result<()> {
293293
}
294294

295295
#[plugin_hook(CompilationAfterProcessAssets for SubresourceIntegrityPlugin)]
296-
pub async fn detect_unresolved_integrity(&self, compilation: &mut Compilation) -> Result<()> {
296+
pub async fn detect_unresolved_integrity(
297+
&self,
298+
compilation: &Compilation,
299+
diagnostics: &mut Vec<Diagnostic>,
300+
) -> Result<()> {
297301
let mut contain_unresolved_files = vec![];
298302
for chunk in compilation.chunk_by_ukey.values() {
299303
for file in chunk.files() {
@@ -309,7 +313,7 @@ pub async fn detect_unresolved_integrity(&self, compilation: &mut Compilation) -
309313
}
310314

311315
for file in contain_unresolved_files {
312-
compilation.push_diagnostic(Diagnostic::error(
316+
diagnostics.push(Diagnostic::error(
313317
"SubresourceIntegrity".to_string(),
314318
format!("Asset {file} contains unresolved integrity placeholders"),
315319
));

0 commit comments

Comments
 (0)