Skip to content

Commit 7396534

Browse files
committed
refactor(rust): add HookGenerateBundleArgs
1 parent 5ebdca9 commit 7396534

File tree

9 files changed

+30
-25
lines changed

9 files changed

+30
-25
lines changed

crates/rolldown_binding/src/options/plugin/js_plugin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ impl Plugin for JsPlugin {
362362
async fn generate_bundle(
363363
&self,
364364
ctx: &rolldown_plugin::PluginContext,
365-
bundle: &mut Vec<rolldown_common::Output>,
366-
is_write: bool,
365+
args: &mut rolldown_plugin::HookGenerateBundleArgs<'_>,
367366
) -> rolldown_plugin::HookNoopReturn {
368367
if let Some(cb) = &self.generate_bundle {
369-
let changed = cb.await_call((ctx.clone().into(), bundle.clone().into(), is_write)).await?;
370-
update_outputs(bundle, changed)?;
368+
let changed =
369+
cb.await_call((ctx.clone().into(), args.bundle.clone().into(), args.is_write)).await?;
370+
update_outputs(args.bundle, changed)?;
371371
}
372372
Ok(())
373373
}

crates/rolldown_binding/src/options/plugin/parallel_js_plugin.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,10 @@ impl Plugin for ParallelJsPlugin {
151151
async fn generate_bundle(
152152
&self,
153153
ctx: &rolldown_plugin::PluginContext,
154-
bundle: &mut Vec<rolldown_common::Output>,
155-
is_write: bool,
154+
args: &mut rolldown_plugin::HookGenerateBundleArgs<'_>,
156155
) -> rolldown_plugin::HookNoopReturn {
157156
if self.first_plugin().generate_bundle.is_some() {
158-
self.run_single(|plugin| plugin.call_generate_bundle(ctx, bundle, is_write)).await
157+
self.run_single(|plugin| plugin.call_generate_bundle(ctx, args)).await
159158
} else {
160159
Ok(())
161160
}

crates/rolldown_plugin/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub use crate::{
3333
types::hook_filter::{
3434
GeneralHookFilter, LoadHookFilter, ResolvedIdHookFilter, TransformHookFilter,
3535
},
36+
types::hook_generate_bundle_args::HookGenerateBundleArgs,
3637
types::hook_load_args::HookLoadArgs,
3738
types::hook_load_output::HookLoadOutput,
3839
types::hook_render_chunk_args::HookRenderChunkArgs,

crates/rolldown_plugin/src/plugin.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use crate::{
1111
hook_transform_ast_args::HookTransformAstArgs,
1212
hook_transform_output::HookTransformOutput,
1313
},
14-
HookAddonArgs, HookBuildEndArgs, HookLoadArgs, HookLoadOutput, HookRenderChunkArgs,
15-
HookRenderChunkOutput, HookResolveIdArgs, HookResolveIdOutput, HookTransformArgs,
16-
SharedTransformPluginContext,
14+
HookAddonArgs, HookBuildEndArgs, HookGenerateBundleArgs, HookLoadArgs, HookLoadOutput,
15+
HookRenderChunkArgs, HookRenderChunkOutput, HookResolveIdArgs, HookResolveIdOutput,
16+
HookTransformArgs, SharedTransformPluginContext,
1717
};
1818
use anyhow::Result;
1919
use rolldown_common::{ModuleInfo, Output, RollupRenderedChunk, WatcherChangeKind};
@@ -223,8 +223,7 @@ pub trait Plugin: Any + Debug + Send + Sync + 'static {
223223
fn generate_bundle(
224224
&self,
225225
_ctx: &PluginContext,
226-
_bundle: &mut Vec<Output>,
227-
_is_write: bool,
226+
_args: &mut HookGenerateBundleArgs,
228227
) -> impl std::future::Future<Output = HookNoopReturn> + Send {
229228
async { Ok(()) }
230229
}

crates/rolldown_plugin/src/plugin_driver/output_hooks.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ impl PluginDriver {
118118
for (_, plugin, ctx) in
119119
self.iter_plugin_with_context_by_order(&self.order_by_generate_bundle_meta)
120120
{
121-
plugin.call_generate_bundle(ctx, bundle, is_write).await?;
121+
let mut args = crate::HookGenerateBundleArgs { is_write, bundle };
122+
plugin.call_generate_bundle(ctx, &mut args).await?;
122123
ctx.file_emitter.add_additional_files(bundle);
123124
}
124125
Ok(())

crates/rolldown_plugin/src/pluginable.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::{
88
hook_render_error::HookRenderErrorArgs,
99
hook_transform_ast_args::HookTransformAstArgs,
1010
},
11-
HookAddonArgs, HookBuildEndArgs, HookBuildStartArgs, HookInjectionOutputReturn, HookLoadArgs,
12-
HookRenderChunkArgs, HookRenderStartArgs, HookResolveIdArgs, HookTransformArgs, Plugin,
13-
SharedTransformPluginContext,
11+
HookAddonArgs, HookBuildEndArgs, HookBuildStartArgs, HookGenerateBundleArgs,
12+
HookInjectionOutputReturn, HookLoadArgs, HookRenderChunkArgs, HookRenderStartArgs,
13+
HookResolveIdArgs, HookTransformArgs, Plugin, SharedTransformPluginContext,
1414
};
1515
use anyhow::Ok;
1616
use rolldown_common::{ModuleInfo, Output, RollupRenderedChunk, WatcherChangeKind};
@@ -171,8 +171,7 @@ pub trait Pluginable: Any + Debug + Send + Sync + 'static {
171171
async fn call_generate_bundle(
172172
&self,
173173
_ctx: &PluginContext,
174-
_bundle: &mut Vec<Output>,
175-
_is_write: bool,
174+
_args: &mut HookGenerateBundleArgs,
176175
) -> HookNoopReturn;
177176

178177
fn call_generate_bundle_meta(&self) -> Option<PluginHookMeta>;
@@ -409,10 +408,9 @@ impl<T: Plugin> Pluginable for T {
409408
async fn call_generate_bundle(
410409
&self,
411410
ctx: &PluginContext,
412-
bundle: &mut Vec<Output>,
413-
is_write: bool,
411+
args: &mut HookGenerateBundleArgs,
414412
) -> HookNoopReturn {
415-
Plugin::generate_bundle(self, ctx, bundle, is_write).await
413+
Plugin::generate_bundle(self, ctx, args).await
416414
}
417415

418416
fn call_generate_bundle_meta(&self) -> Option<PluginHookMeta> {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use rolldown_common::Output;
2+
3+
#[derive(Debug)]
4+
pub struct HookGenerateBundleArgs<'a> {
5+
pub bundle: &'a mut Vec<Output>,
6+
pub is_write: bool,
7+
}

crates/rolldown_plugin/src/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod hook_addon_args;
22
pub mod hook_build_end_args;
33
pub mod hook_build_start_args;
44
pub mod hook_filter;
5+
pub mod hook_generate_bundle_args;
56
pub mod hook_load_args;
67
pub mod hook_load_output;
78
pub mod hook_render_chunk_args;

crates/rolldown_plugin_manifest/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ impl Plugin for ManifestPlugin {
3434
async fn generate_bundle(
3535
&self,
3636
ctx: &PluginContext,
37-
bundle: &mut Vec<Output>,
38-
_is_write: bool,
37+
args: &mut rolldown_plugin::HookGenerateBundleArgs<'_>,
3938
) -> HookNoopReturn {
4039
// Use BTreeMap to make the result sorted
4140
let mut manifest = BTreeMap::default();
@@ -53,11 +52,11 @@ impl Plugin for ManifestPlugin {
5352
}
5453
}
5554

56-
for file in bundle.iter() {
55+
for file in args.bundle.iter() {
5756
match file {
5857
Output::Chunk(chunk) => {
5958
let name = self.get_chunk_name(chunk);
60-
let chunk_manifest = Rc::new(self.create_chunk(bundle, chunk, name.clone()));
59+
let chunk_manifest = Rc::new(self.create_chunk(args.bundle, chunk, name.clone()));
6160
manifest.insert(name.clone(), chunk_manifest);
6261
}
6362
Output::Asset(asset) => {

0 commit comments

Comments
 (0)