Skip to content

Commit f655c17

Browse files
committed
feat: support preserve_modules
1 parent 02ab3a4 commit f655c17

File tree

31 files changed

+939
-212
lines changed

31 files changed

+939
-212
lines changed

crates/node_binding/napi-binding.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,10 @@ export interface RawEnvironment {
20872087
dynamicImportInWorker?: boolean
20882088
}
20892089

2090+
export interface RawEsmLibraryPlugin {
2091+
preserveModules?: string
2092+
}
2093+
20902094
export interface RawEvalDevToolModulePluginOptions {
20912095
namespace?: string
20922096
moduleFilenameTemplate?: string | ((info: RawModuleFilenameTemplateFnCtx) => string)

crates/rspack_binding_api/src/raw_options/raw_builtins/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod raw_copy;
66
mod raw_css_chunking;
77
mod raw_css_extract;
88
mod raw_dll;
9+
mod raw_esm_lib;
910
mod raw_html;
1011
mod raw_http_uri;
1112
mod raw_ids;
@@ -128,7 +129,7 @@ use crate::{
128129
raw_options::{
129130
RawDynamicEntryPluginOptions, RawEvalDevToolModulePluginOptions, RawExternalItemWrapper,
130131
RawExternalsPluginOptions, RawHttpExternalsRspackPluginOptions, RawSplitChunksOptions,
131-
SourceMapDevToolPluginOptions,
132+
SourceMapDevToolPluginOptions, raw_builtins::raw_esm_lib::RawEsmLibraryPlugin,
132133
},
133134
rslib::RawRslibPluginOptions,
134135
};
@@ -410,7 +411,10 @@ impl<'a> BuiltinPlugin<'a> {
410411
plugins.push(CommonJsChunkFormatPlugin::default().boxed());
411412
}
412413
BuiltinPluginName::EsmLibraryPlugin => {
413-
plugins.push(EsmLibraryPlugin::default().boxed());
414+
let options = downcast_into::<RawEsmLibraryPlugin>(self.options)
415+
.map_err(|report| napi::Error::from_reason(report.to_string()))?;
416+
plugins
417+
.push(EsmLibraryPlugin::new(options.preserve_modules.as_deref().map(Into::into)).boxed());
414418
}
415419
BuiltinPluginName::ArrayPushCallbackChunkFormatPlugin => {
416420
plugins.push(ArrayPushCallbackChunkFormatPlugin::default().boxed());
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[napi(object, object_to_js = false)]
2+
pub struct RawEsmLibraryPlugin {
3+
pub preserve_modules: Option<String>,
4+
}

crates/rspack_plugin_esm_library/src/chunk_link.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub struct ChunkLinkContext {
264264
specifier order doesn't matter, we can sort them based on name
265265
Map<module_id, Map<local_name, export_name>>
266266
*/
267-
exports: FxHashMap<Atom, FxHashSet<Atom>>,
267+
exports: FxHashMap<Atom, FxIndexSet<Atom>>,
268268

269269
/**
270270
symbols that this chunk provides
@@ -396,11 +396,11 @@ impl ChunkLinkContext {
396396
set.get(&export_name).expect("should have inserted")
397397
}
398398

399-
pub fn exports(&self) -> &FxHashMap<Atom, FxHashSet<Atom>> {
399+
pub fn exports(&self) -> &FxHashMap<Atom, FxIndexSet<Atom>> {
400400
&self.exports
401401
}
402402

403-
pub fn exports_mut(&mut self) -> &mut FxHashMap<Atom, FxHashSet<Atom>> {
403+
pub fn exports_mut(&mut self) -> &mut FxHashMap<Atom, FxIndexSet<Atom>> {
404404
&mut self.exports
405405
}
406406

crates/rspack_plugin_esm_library/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod chunk_link;
22
mod dependency;
33
mod link;
44
mod plugin;
5+
mod preserve_modules;
56
mod render;
67
mod runtime;
78
pub use plugin::EsmLibraryPlugin;

0 commit comments

Comments
 (0)