Skip to content

Commit b74ad3c

Browse files
committed
refactor(rust): pass NormalizedOutputOptions in generateBundle hook
1 parent 788d7fc commit b74ad3c

File tree

10 files changed

+32
-20
lines changed

10 files changed

+32
-20
lines changed

crates/rolldown/src/bundler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Bundler {
166166
// Add additional files from build plugins.
167167
self.file_emitter.add_additional_files(&mut output.assets);
168168

169-
self.plugin_driver.generate_bundle(&mut output.assets, is_write).await?;
169+
self.plugin_driver.generate_bundle(&mut output.assets, is_write, &self.options).await?;
170170

171171
output.watch_files = self.plugin_driver.watch_files.iter().map(|f| f.clone()).collect();
172172

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,14 @@ pub struct BindingPluginOptions {
138138

139139
#[serde(skip_deserializing)]
140140
#[napi(
141-
ts_type = "(ctx: BindingPluginContext, bundle: BindingOutputs, isWrite: boolean) => MaybePromise<VoidNullable<JsChangedOutputs>>"
141+
ts_type = "(ctx: BindingPluginContext, bundle: BindingOutputs, isWrite: boolean, opts: BindingNormalizedOptions) => MaybePromise<VoidNullable<JsChangedOutputs>>"
142142
)]
143-
pub generate_bundle:
144-
Option<MaybeAsyncJsCallback<(BindingPluginContext, BindingOutputs, bool), JsChangedOutputs>>,
143+
pub generate_bundle: Option<
144+
MaybeAsyncJsCallback<
145+
(BindingPluginContext, BindingOutputs, bool, BindingNormalizedOptions),
146+
JsChangedOutputs,
147+
>,
148+
>,
145149
pub generate_bundle_meta: Option<BindingPluginHookMeta>,
146150

147151
#[serde(skip_deserializing)]

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,14 @@ impl Plugin for JsPlugin {
365365
args: &mut rolldown_plugin::HookGenerateBundleArgs<'_>,
366366
) -> rolldown_plugin::HookNoopReturn {
367367
if let Some(cb) = &self.generate_bundle {
368-
let changed =
369-
cb.await_call((ctx.clone().into(), args.bundle.clone().into(), args.is_write)).await?;
368+
let changed = cb
369+
.await_call((
370+
ctx.clone().into(),
371+
args.bundle.clone().into(),
372+
args.is_write,
373+
BindingNormalizedOptions::new(Arc::clone(args.options)),
374+
))
375+
.await?;
370376
update_outputs(args.bundle, changed)?;
371377
}
372378
Ok(())

crates/rolldown_plugin/src/plugin_driver/output_hooks.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,16 @@ impl PluginDriver {
114114
Ok(())
115115
}
116116

117-
pub async fn generate_bundle(&self, bundle: &mut Vec<Output>, is_write: bool) -> HookNoopReturn {
117+
pub async fn generate_bundle(
118+
&self,
119+
bundle: &mut Vec<Output>,
120+
is_write: bool,
121+
opts: &SharedNormalizedBundlerOptions,
122+
) -> HookNoopReturn {
118123
for (_, plugin, ctx) in
119124
self.iter_plugin_with_context_by_order(&self.order_by_generate_bundle_meta)
120125
{
121-
let mut args = crate::HookGenerateBundleArgs { is_write, bundle };
126+
let mut args = crate::HookGenerateBundleArgs { is_write, bundle, options: opts };
122127
plugin.call_generate_bundle(ctx, &mut args).await?;
123128
ctx.file_emitter.add_additional_files(bundle);
124129
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use rolldown_common::Output;
1+
use rolldown_common::{Output, SharedNormalizedBundlerOptions};
22

33
#[derive(Debug)]
44
pub struct HookGenerateBundleArgs<'a> {
5+
pub options: &'a SharedNormalizedBundlerOptions,
56
pub bundle: &'a mut Vec<Output>,
67
pub is_write: bool,
78
}

packages/rolldown/src/binding.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ export interface BindingPluginOptions {
429429
renderStartMeta?: BindingPluginHookMeta
430430
renderError?: (ctx: BindingPluginContext, error: string) => void
431431
renderErrorMeta?: BindingPluginHookMeta
432-
generateBundle?: (ctx: BindingPluginContext, bundle: BindingOutputs, isWrite: boolean) => MaybePromise<VoidNullable<JsChangedOutputs>>
432+
generateBundle?: (ctx: BindingPluginContext, bundle: BindingOutputs, isWrite: boolean, opts: BindingNormalizedOptions) => MaybePromise<VoidNullable<JsChangedOutputs>>
433433
generateBundleMeta?: BindingPluginHookMeta
434434
writeBundle?: (ctx: BindingPluginContext, bundle: BindingOutputs) => MaybePromise<VoidNullable<JsChangedOutputs>>
435435
writeBundleMeta?: BindingPluginHookMeta

packages/rolldown/src/plugin/bindingify-output-hooks.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function bindingifyGenerateBundle(
161161
const { handler, meta } = normalizeHook(hook)
162162

163163
return {
164-
plugin: async (ctx, bundle, isWrite) => {
164+
plugin: async (ctx, bundle, isWrite, opts) => {
165165
const changed = {
166166
updated: new Set(),
167167
deleted: new Set(),
@@ -175,8 +175,7 @@ export function bindingifyGenerateBundle(
175175
args.onLog,
176176
args.logLevel,
177177
),
178-
// TODO(hyf0): pass `BindingNormalizedOptions` in `renderChunk` hook
179-
{} as NormalizedOutputOptions,
178+
new NormalizedOutputOptionsImpl(opts),
180179
output,
181180
isWrite,
182181
)

packages/rollup-tests/src/ignored-tests.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,6 @@ const ignoreTests = [
256256
"rollup@function@respect-default-export-reexporter-side-effects: respect side-effects in reexporting modules even if moduleSideEffects are off",
257257
"rollup@function@respect-reexporter-side-effects: respect side-effects in reexporting modules even if moduleSideEffects are off",
258258
"rollup@function@namespace-member-side-effects@assignment: checks side effects when reassigning namespace members",
259-
260-
// TODO(hyf0): will be fixed in the next PR
261-
"rollup@form@shebang-1: preserve shebang in entry module for CJS and ESM outputs@generates es",
262259
]
263260

264261
// Generated by packages/rollup-tests/test/form/found-tree-shaking-not-align.js
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"failed": 0,
33
"skipFailed": 0,
4-
"ignored": 446,
4+
"ignored": 445,
55
"ignoredByUnsupportedFeatures": 396,
6-
"passed": 674
6+
"passed": 675
77
}

packages/rollup-tests/src/status.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
|----| ---- |
33
| failed | 0|
44
| skipFailed | 0|
5-
| ignored | 446|
5+
| ignored | 445|
66
| ignoredByUnsupportedFeatures | 396|
7-
| passed | 674|
7+
| passed | 675|

0 commit comments

Comments
 (0)