Skip to content

Commit cd402a1

Browse files
2heal1renovate[bot]LingyuCoderhardfistCopilot
authored
feat: support MF share treeshake (#12250)
* feat: treeshake share * fix(module-federation): correct shared module name and optimize tree shaking fix incorrect module name in shared config and test cases change async process_module to sync using block_on for better performance update shared exports optimization to handle side effects properly * feat(module-federation): add treeshakeSharedExcludedPlugins option * chore: add watchRun * fix(shared-modules): handle undefined moduleToHandlerMapping and prevent tree-shaking Add fallback for undefined moduleToHandlerMapping in shared container entry Include additional plugins in filter list and prevent tree-shaking of shared modules by adding console logs when collectShared is true * test(container-1-5): add ui-lib package for treeshake shared infer strategy * fix(shared_used_exports): handle scoped package names in shared exports refactor(node_binding): remove redundant exports in wasi files * chore: update critical file * feat(module-federation): add target and plugins to build info for treeshaking Add target and plugins fields to build info when treeshaking is enabled in module federation. Also rename 'reshake' to 'reShake' for consistency across the codebase. These changes support better treeshaking analysis and configuration. * docs: update field * feat: add treeshakeSharedPlugins * fix: lint * fix: lockfile * fix: lint * chore: rename config * chore(deps): update patch npm dependencies (#12647) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update patch crates (#12646) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore: run ci/eco-ci/eco-benchmark on v2 branch (#12650) * fix: report error when access module_graph in loader (#12639) * fix: report error when access module_graph in loader * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * feat(rstest): add preserveNewUrl option to keep new URL untouched (#12632) * feat(rstest): add preserveNewUrl option to keep new URL untouched * fix: format Rust code with rustfmt * fix(lint): enable @typescript-eslint/await-thenable rule (#12644) * fix(lint): enable await-thenable rule and fix violation - Enable @typescript-eslint/await-thenable rule (off -> error) - Remove unnecessary await on syncTraceEvent() which returns void * Update rslint.json --------- Co-authored-by: neverland <jait.chen@foxmail.com> * refactor: afterCodeGeneration hook use read only compilation ref (#12655) * fix(lint): enable @typescript-eslint/require-await rule (#12664) fix(lint): enable require-await rule and fix violations - Enable @typescript-eslint/require-await rule (off -> error) - FileSystem.ts: Add missing return for Promise, remove async - SubresourceIntegrityPlugin.ts: Use Promise.resolve() instead of async - browser/service.ts: Remove async from function that only throws - loader-runner/worker.ts: Remove async from .then/.catch callbacks * chore(deps): update github-actions (#12645) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(lint): enable @typescript-eslint/return-await rule (#12665) * refactor: make compilation readonly for runtimeModule hook (#12670) * feat: add constructor name for JS runtime modules (#12673) feat: add constructor name for JS runtime module * fix: incremental rebuild no code generation entry panic (#12643) * fix: incremental rebuild bug * add test case * fix: ci * refactor: unify artifact clear logic (#12677) * refactor: use DerfOpt's take/replace assist artifact mutation (#12659) * refactor: remove Default trait of DerefOption * refactor: `replace` is better than `insert` * feat: rspack_cacheable context expose project root (#12685) * feat: rspack_cacheable context expose project root * fix: comment * feat: rspack_cacheable add portable path & portable string (#12688) feat: add portable path & portable string * fix: inlined export invalid syntax comment (#12681) * feat: add `requireAlias` option to control require variable renaming (#12686) * feat: add requireRename option to control require variable renaming * Update packages/rspack/src/config/types.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/rspack-test/configCases/parsing/renaming-disabled/index.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * rename * rename --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(test): flaky test due to calling toJSON while hot updating (#12694) * feat: impl `sync_trace` for `logger` tracing layer (#12687) * Sync node events for logger tracing * Align sync_trace * Remove unless info * Cargo shear * Use one writer * Filter JavaScript * Handle timestamps * Clippy * Clippy * feat: add warning when requireAlias is disabled (#12700) * refactor: rename tree shaking field name * revert: "feat: add warning when requireAlias is disabled" (#12702) Revert "feat: add warning when requireAlias is disabled (#12700)" This reverts commit eb5635c. * feat: use rspack-vue-loader to support Vue hot update (#12698) feat: use rspack-vue-loader to support hotupdate * chore: update artificat * chore: replace async processAssets hooks with sync versions * fix: `environments.importMetaDirnameAndFilename` not work (#12708) fix: `environments.importMetaDirnameAndFilename` should work * fix: dynamic entry panic when disable build cache (#12696) * fix(context-replacement): only apply changes when regex matches (#12657) fix(ContextReplacementPlugin): only apply changes when regex matches The plugin was applying transformations (recursive, regExp, critical) to all require.context() calls regardless of whether the configured regex pattern matched the request. This fix ensures all transformations only apply when the regex successfully matches. Closes #12656 * docs: add missed doc * fix: remove ueless dep * chore: update lock file * fix(mf): handle missing chunk gracefully and improve expose chunk name logic (#12709) * fix(type): runtimeModule.source (#12713) * fix(type): runtimeModule.source * fix: lint * fix: lint * chore: release 1.7.2 (#12710) Release 0.7.2 rspack@0.7.2 rspack_allocator@0.7.2 rspack_binding_api@0.7.2 rspack_binding_build@0.7.2 rspack_binding_builder@0.7.2 rspack_binding_builder_macros@0.7.2 rspack_browser@0.7.2 rspack_browserslist@0.7.2 rspack_cacheable@0.7.2 rspack_cacheable_macros@0.7.2 rspack_collections@0.7.2 rspack_core@0.7.2 rspack_error@0.7.2 rspack_fs@0.7.2 rspack_futures@0.7.2 rspack_hash@0.7.2 rspack_hook@0.7.2 rspack_ids@0.7.2 rspack_javascript_compiler@0.7.2 rspack_loader_lightningcss@0.7.2 rspack_loader_preact_refresh@0.7.2 rspack_loader_react_refresh@0.7.2 rspack_loader_runner@0.7.2 rspack_loader_swc@0.7.2 rspack_loader_testing@0.7.2 rspack_location@0.7.2 rspack_macros@0.7.2 rspack_napi@0.7.2 rspack_napi_macros@0.7.2 rspack_paths@0.7.2 rspack_plugin_asset@0.7.2 rspack_plugin_banner@0.7.2 rspack_plugin_case_sensitive@0.7.2 rspack_plugin_circular_dependencies@0.7.2 rspack_plugin_copy@0.7.2 rspack_plugin_css@0.7.2 rspack_plugin_css_chunking@0.7.2 rspack_plugin_devtool@0.7.2 rspack_plugin_dll@0.7.2 rspack_plugin_dynamic_entry@0.7.2 rspack_plugin_ensure_chunk_conditions@0.7.2 rspack_plugin_entry@0.7.2 rspack_plugin_esm_library@0.7.2 rspack_plugin_externals@0.7.2 rspack_plugin_extract_css@0.7.2 rspack_plugin_hmr@0.7.2 rspack_plugin_html@0.7.2 rspack_plugin_ignore@0.7.2 rspack_plugin_javascript@0.7.2 rspack_plugin_json@0.7.2 rspack_plugin_lazy_compilation@0.7.2 rspack_plugin_library@0.7.2 rspack_plugin_lightning_css_minimizer@0.7.2 rspack_plugin_limit_chunk_count@0.7.2 rspack_plugin_merge_duplicate_chunks@0.7.2 rspack_plugin_mf@0.7.2 rspack_plugin_module_info_header@0.7.2 rspack_plugin_module_replacement@0.7.2 rspack_plugin_no_emit_on_errors@0.7.2 rspack_plugin_progress@0.7.2 rspack_plugin_real_content_hash@0.7.2 rspack_plugin_remove_duplicate_modules@0.7.2 rspack_plugin_remove_empty_chunks@0.7.2 rspack_plugin_rsdoctor@0.7.2 rspack_plugin_rslib@0.7.2 rspack_plugin_rstest@0.7.2 rspack_plugin_runtime@0.7.2 rspack_plugin_runtime_chunk@0.7.2 rspack_plugin_schemes@0.7.2 rspack_plugin_size_limits@0.7.2 rspack_plugin_split_chunks@0.7.2 rspack_plugin_sri@0.7.2 rspack_plugin_swc_js_minimizer@0.7.2 rspack_plugin_wasm@0.7.2 rspack_plugin_web_worker_template@0.7.2 rspack_plugin_worker@0.7.2 rspack_regex@0.7.2 rspack_storage@0.7.2 rspack_swc_plugin_import@0.7.2 rspack_swc_plugin_ts_collector@0.7.2 rspack_tasks@0.7.2 rspack_tracing@0.7.2 rspack_tracing_perfetto@0.7.2 rspack_util@0.7.2 rspack_watcher@0.7.2 rspack_workspace@0.7.2 Generated by cargo-workspaces * chore(deps): update dependency @rspack/plugin-react-refresh to ^1.6.0 (#12718) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @shikijs/transformers to ^3.21.0 (#12719) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update patch crates (#12716) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * test: skip recover-from-error/delete-file in watchCases (#12726) * feat: support portable cache and disable by default (#12680) * feat: support portable cache * feat: disable portable cache by default * fix: rename reShake to secondaryTreeShaking * chore: update artificat * test: use Rstest projects to define tests (#12729) * test: use rstest projects * test: update * test: output.module * test: update * chore(deps): update patch npm dependencies (#12717) * chore(deps): update patch npm dependencies * fix: downgrade MF --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: neverland <chenjiahan.jait@bytedance.com> * refactor: move pass into separate folder and driven by run_passes (#12735) * chore: add rspack_passes.md * refactor: move pass into separate folder and drive by run_passes * chore: use function * refactor: move more into run_passes * chore: fix stats logging * chore: fix stats.logging * refactor(lazy-compilation): use POST request to transfer ids of active modules (#12678) * refactor: use post transfer module ids * test: skip lazy active method * test: add lazy post request help * test: add large module id container * test: add case introduction * refactor: remove about controller * test: we are using post method now * refactor: rename * fix body parser (vibe-kanban 09797829) 1. 如果其他中间件一个解析好了body,并挂载在req.body 上的花就直直接使用 req.body 2. packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts body 解析的时候不能简单的使用 string 的拼接,需要考虑多字节符号的截断的问题。 * refactor read module ids from body (vibe-kanban a7874ac1) packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts 当req.body 非空时,直接假body中时一组 module ids,如果没有 body 自行拼接完,之后也 parse json string,返回 module ids 数组 * refactor: downgrading to lower web api * test: ✅ add lazy compilation active cors cases * chore: update test case doc * fix: we all need cors header no matter is simple request or not * refactor:delete cors header setting * refactor: set cors header should set by user * Update packages/rspack/hot/lazy-compilation-web.js Co-authored-by: neverland <chenjiahan.jait@bytedance.com> * test: fix case name * chore: api-extract update * fix: memory leak of requst listeners * refactor: remove event source handle logic * fix: jsdom XMLHTTPRequets need strict cors header * refactor: node lazy compilation client use post too --------- Co-authored-by: neverland <chenjiahan.jait@bytedance.com> * refactor: move logger into pass and reorg some passes (#12742) * refactor: move logger into pass and reorg some passes * chore: fix bench check * chore(lint): bump @rslint/core to 0.2.0 and enable default-param-last rule (#12746) * chore(deps): bump @rslint/core to 0.2.0 and update rslint.json * fix(lint): enable @typescript-eslint/default-param-last rule * test: support filter test by absolute path (#12749) * test: support filter test by absolute path * Update packages/rspack-test-tools/src/helper/directory.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/rspack-test-tools/src/helper/directory.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/rspack-test/Cache.test.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: lint * docs: update -t --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * refactor: use newtype for alias artifact (#12754) * chore: bump `swc_core` from 54 to 55 (#12758) * chore: bump swc * chore: bump swc exp * chore: cargo codegen * refactor: move all artifacts together (#12755) * chore: limit threads for codspeed benchmark (#12763) Limit threads * chore(deps): update dependency cspell to ^9.6.0 (#12768) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency emnapi to ^1.8.1 (#12769) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency memfs to v4.53.0 (#12770) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * refactor: use compilation readonly ref in codegen optimization hook (#12743) * refactor: use compilation readonly ref in code generation optimization hook * chore: debug bench ci * fix: 🐛 use offical codseed action * Debug ci * Remove debugger * Limit tokio and rayon worker threads * Revert "Limit tokio and rayon worker threads" This reverts commit 10fe6ac. * Update crates/rspack_plugin_progress/src/lib.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: CPunisher <1343316114@qq.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(browser): update worker format and add e2e test (#12747) * fix: remove lazyCompilationMiddleware * chore: change worker entry to iife * chore: add e2e test * chore: fix format * fix: add await for e2e * fix: remove unused imports * chore: fix ci yml * chore: fix ci WASM env injection * fix: update shared global name * perf: reuse container plugin * chore: fix merge conflict * chore: use official version and update docs * chore: fix cargo clippy * chore: bump * workflow: revert ci * ci: add CodSpeed performance analysis action Add GitHub action for continuous benchmarking with CodSpeed. The action supports multiple measurement modes and instruments, including MongoDB instrumentation and caching for faster runs. Includes validation for required inputs and custom runner installation. * chore: revert cacahe implementation * chore: use get_referenced_exports * chore: revert esm depnedency change * chore: revert esm_import_specifier_dependency change * refactor(mf): simplify runtime module implementations --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: harpsealjs <lingyucoder@gmail.com> Co-authored-by: hardfist <yangjianzju@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Max <fi3ework@gmail.com> Co-authored-by: Tu Shaokun <53142663+tt-a1i@users.noreply.github.com> Co-authored-by: neverland <jait.chen@foxmail.com> Co-authored-by: pshu <stormslowly@gmail.com> Co-authored-by: jinrui <jerrykingxyz@gmail.com> Co-authored-by: Gengkun <ahabhgk@gmail.com> Co-authored-by: CPunisher <1343316114@qq.com> Co-authored-by: 9aoy <9aoyuao@gmail.com> Co-authored-by: neverland <chenjiahan.jait@bytedance.com> Co-authored-by: Cong-Cong Pan <dacongsama@live.com> Co-authored-by: Agney Menon <agney.menons@live.com> Co-authored-by: Fy <1114550440@qq.com> Co-authored-by: senze.fan <151665030@qq.com>
1 parent ca0b6a5 commit cd402a1

File tree

118 files changed

+4484
-561
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+4484
-561
lines changed

crates/node_binding/napi-binding.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,13 @@ export declare enum BuiltinPluginName {
548548
SplitChunksPlugin = 'SplitChunksPlugin',
549549
RemoveDuplicateModulesPlugin = 'RemoveDuplicateModulesPlugin',
550550
ShareRuntimePlugin = 'ShareRuntimePlugin',
551+
SharedUsedExportsOptimizerPlugin = 'SharedUsedExportsOptimizerPlugin',
551552
ContainerPlugin = 'ContainerPlugin',
552553
ContainerReferencePlugin = 'ContainerReferencePlugin',
553554
ProvideSharedPlugin = 'ProvideSharedPlugin',
554555
ConsumeSharedPlugin = 'ConsumeSharedPlugin',
556+
CollectSharedEntryPlugin = 'CollectSharedEntryPlugin',
557+
SharedContainerPlugin = 'SharedContainerPlugin',
555558
ModuleFederationRuntimePlugin = 'ModuleFederationRuntimePlugin',
556559
ModuleFederationManifestPlugin = 'ModuleFederationManifestPlugin',
557560
NamedModuleIdsPlugin = 'NamedModuleIdsPlugin',
@@ -1876,6 +1879,11 @@ export interface RawCircularDependencyRspackPluginOptions {
18761879
onEnd?: () => void
18771880
}
18781881

1882+
export interface RawCollectShareEntryPluginOptions {
1883+
consumes: Array<RawConsumeOptions>
1884+
filename?: string
1885+
}
1886+
18791887
export interface RawCompilerPlatform {
18801888
web?: boolean | null
18811889
browser?: boolean | null
@@ -1896,6 +1904,7 @@ export interface RawConsumeOptions {
18961904
strictVersion: boolean
18971905
singleton: boolean
18981906
eager: boolean
1907+
treeShakingMode?: string
18991908
}
19001909

19011910
export interface RawConsumeSharedPluginOptions {
@@ -2613,6 +2622,12 @@ export interface RawOptimizationOptions {
26132622
avoidEntryIife: boolean
26142623
}
26152624

2625+
export interface RawOptimizeSharedConfig {
2626+
shareKey: string
2627+
treeShaking: boolean
2628+
usedExports?: Array<string>
2629+
}
2630+
26162631
export interface RawOptions {
26172632
name?: string
26182633
mode?: undefined | 'production' | 'development' | 'none'
@@ -2712,6 +2727,7 @@ export interface RawProvideOptions {
27122727
singleton?: boolean
27132728
requiredVersion?: string | false | undefined
27142729
strictVersion?: boolean
2730+
treeShakingMode?: string
27152731
}
27162732

27172733
export interface RawRelated {
@@ -2846,6 +2862,21 @@ export interface RawRuntimeChunkOptions {
28462862
name: string | ((entrypoint: { name: string }) => string)
28472863
}
28482864

2865+
export interface RawSharedContainerPluginOptions {
2866+
name: string
2867+
request: string
2868+
version: string
2869+
fileName?: string
2870+
library: JsLibraryOptions
2871+
}
2872+
2873+
export interface RawSharedUsedExportsOptimizerPluginOptions {
2874+
shared: Array<RawOptimizeSharedConfig>
2875+
injectTreeShakingUsedExports?: boolean
2876+
manifestFileName?: string
2877+
statsFileName?: string
2878+
}
2879+
28492880
export interface RawSizeLimitsPluginOptions {
28502881
assetFilter?: (assetFilename: string) => boolean
28512882
hints?: "error" | "warning"
@@ -2889,6 +2920,8 @@ export interface RawSplitChunksOptions {
28892920
export interface RawStatsBuildInfo {
28902921
buildVersion: string
28912922
buildName?: string
2923+
target?: Array<string>
2924+
plugins?: Array<string>
28922925
}
28932926

28942927
export interface RawStatsOptions {

crates/rspack_binding_api/src/plugins/interceptor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ use crate::{
8181
JsContextModuleFactoryAfterResolveDataWrapper, JsContextModuleFactoryAfterResolveResult,
8282
JsContextModuleFactoryBeforeResolveDataWrapper, JsContextModuleFactoryBeforeResolveResult,
8383
},
84+
dependency::DependencyWrapper,
8485
html::{
8586
JsAfterEmitData, JsAfterTemplateExecutionData, JsAlterAssetTagGroupsData, JsAlterAssetTagsData,
8687
JsBeforeAssetTagGenerationData, JsBeforeEmitData,
@@ -97,7 +98,7 @@ use crate::{
9798
runtime::{
9899
JsAdditionalTreeRuntimeRequirementsArg, JsAdditionalTreeRuntimeRequirementsResult,
99100
JsCreateLinkData, JsCreateScriptData, JsLinkPrefetchData, JsLinkPreloadData, JsRuntimeGlobals,
100-
JsRuntimeRequirementInTreeArg, JsRuntimeRequirementInTreeResult,
101+
JsRuntimeRequirementInTreeArg, JsRuntimeRequirementInTreeResult, JsRuntimeSpec,
101102
},
102103
source::JsSourceToJs,
103104
};

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ use napi_derive::napi;
3232
use raw_dll::{RawDllReferenceAgencyPluginOptions, RawFlagAllModulesAsUsedPluginOptions};
3333
use raw_ids::RawOccurrenceChunkIdsPluginOptions;
3434
use raw_lightning_css_minimizer::RawLightningCssMinimizerRspackPluginOptions;
35-
use raw_mf::{RawModuleFederationManifestPluginOptions, RawModuleFederationRuntimePluginOptions};
35+
use raw_mf::{
36+
RawCollectShareEntryPluginOptions, RawModuleFederationManifestPluginOptions,
37+
RawModuleFederationRuntimePluginOptions, RawProvideOptions,
38+
RawSharedUsedExportsOptimizerPluginOptions,
39+
};
3640
use raw_sri::RawSubresourceIntegrityPluginOptions;
3741
use rspack_core::{BoxPlugin, Plugin, PluginExt};
3842
use rspack_error::{Result, ToStringResultToRspackResultExt};
@@ -76,8 +80,9 @@ use rspack_plugin_lightning_css_minimizer::LightningCssMinimizerRspackPlugin;
7680
use rspack_plugin_limit_chunk_count::LimitChunkCountPlugin;
7781
use rspack_plugin_merge_duplicate_chunks::MergeDuplicateChunksPlugin;
7882
use rspack_plugin_mf::{
79-
ConsumeSharedPlugin, ContainerPlugin, ContainerReferencePlugin, ModuleFederationManifestPlugin,
80-
ModuleFederationRuntimePlugin, ProvideSharedPlugin, ShareRuntimePlugin,
83+
CollectSharedEntryPlugin, ConsumeSharedPlugin, ContainerPlugin, ContainerReferencePlugin,
84+
ModuleFederationManifestPlugin, ModuleFederationRuntimePlugin, ProvideSharedPlugin,
85+
ShareRuntimePlugin, SharedContainerPlugin, SharedUsedExportsOptimizerPlugin,
8186
};
8287
use rspack_plugin_module_info_header::ModuleInfoHeaderPlugin;
8388
use rspack_plugin_module_replacement::{ContextReplacementPlugin, NormalModuleReplacementPlugin};
@@ -118,7 +123,7 @@ use self::{
118123
raw_limit_chunk_count::RawLimitChunkCountPluginOptions,
119124
raw_mf::{
120125
RawConsumeSharedPluginOptions, RawContainerPluginOptions, RawContainerReferencePluginOptions,
121-
RawProvideOptions,
126+
RawSharedContainerPluginOptions,
122127
},
123128
raw_normal_replacement::RawNormalModuleReplacementPluginOptions,
124129
raw_runtime_chunk::RawRuntimeChunkOptions,
@@ -171,10 +176,13 @@ pub enum BuiltinPluginName {
171176
SplitChunksPlugin,
172177
RemoveDuplicateModulesPlugin,
173178
ShareRuntimePlugin,
179+
SharedUsedExportsOptimizerPlugin,
174180
ContainerPlugin,
175181
ContainerReferencePlugin,
176182
ProvideSharedPlugin,
177183
ConsumeSharedPlugin,
184+
CollectSharedEntryPlugin,
185+
SharedContainerPlugin,
178186
ModuleFederationRuntimePlugin,
179187
ModuleFederationManifestPlugin,
180188
NamedModuleIdsPlugin,
@@ -471,6 +479,12 @@ impl<'a> BuiltinPlugin<'a> {
471479
)
472480
.boxed(),
473481
),
482+
BuiltinPluginName::SharedUsedExportsOptimizerPlugin => {
483+
let options = downcast_into::<RawSharedUsedExportsOptimizerPluginOptions>(self.options)
484+
.map_err(|report| napi::Error::from_reason(report.to_string()))?
485+
.into();
486+
plugins.push(SharedUsedExportsOptimizerPlugin::new(options).boxed());
487+
}
474488
BuiltinPluginName::ContainerPlugin => {
475489
plugins.push(
476490
ContainerPlugin::new(
@@ -500,6 +514,18 @@ impl<'a> BuiltinPlugin<'a> {
500514
provides.sort_unstable_by_key(|(k, _)| k.to_string());
501515
plugins.push(ProvideSharedPlugin::new(provides).boxed())
502516
}
517+
BuiltinPluginName::CollectSharedEntryPlugin => {
518+
let options = downcast_into::<RawCollectShareEntryPluginOptions>(self.options)
519+
.map_err(|report| napi::Error::from_reason(report.to_string()))?
520+
.into();
521+
plugins.push(CollectSharedEntryPlugin::new(options).boxed())
522+
}
523+
BuiltinPluginName::SharedContainerPlugin => {
524+
let options = downcast_into::<RawSharedContainerPluginOptions>(self.options)
525+
.map_err(|report| napi::Error::from_reason(report.to_string()))?
526+
.into();
527+
plugins.push(SharedContainerPlugin::new(options).boxed())
528+
}
503529
BuiltinPluginName::ConsumeSharedPlugin => plugins.push(
504530
ConsumeSharedPlugin::new(
505531
downcast_into::<RawConsumeSharedPluginOptions>(self.options)

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

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use std::{collections::HashMap, sync::Arc};
33
use napi::Either;
44
use napi_derive::napi;
55
use rspack_plugin_mf::{
6-
ConsumeOptions, ConsumeSharedPluginOptions, ConsumeVersion, ContainerPluginOptions,
7-
ContainerReferencePluginOptions, ExposeOptions, ManifestExposeOption, ManifestSharedOption,
8-
ModuleFederationManifestPluginOptions, ModuleFederationRuntimeExperimentsOptions,
9-
ModuleFederationRuntimePluginOptions, ProvideOptions, ProvideVersion, RemoteAliasTarget,
10-
RemoteOptions, StatsBuildInfo,
6+
CollectSharedEntryPluginOptions, ConsumeOptions, ConsumeSharedPluginOptions, ConsumeVersion,
7+
ContainerPluginOptions, ContainerReferencePluginOptions, ExposeOptions, ManifestExposeOption,
8+
ManifestSharedOption, ModuleFederationManifestPluginOptions,
9+
ModuleFederationRuntimeExperimentsOptions, ModuleFederationRuntimePluginOptions,
10+
OptimizeSharedConfig, ProvideOptions, ProvideVersion, RemoteAliasTarget, RemoteOptions,
11+
SharedContainerPluginOptions, SharedUsedExportsOptimizerPluginOptions, StatsBuildInfo,
1112
};
1213

1314
use crate::options::{
@@ -115,6 +116,7 @@ pub struct RawProvideOptions {
115116
#[napi(ts_type = "string | false | undefined")]
116117
pub required_version: Option<RawVersion>,
117118
pub strict_version: Option<bool>,
119+
pub tree_shaking_mode: Option<String>,
118120
}
119121

120122
impl From<RawProvideOptions> for (String, ProvideOptions) {
@@ -129,11 +131,57 @@ impl From<RawProvideOptions> for (String, ProvideOptions) {
129131
singleton: value.singleton,
130132
required_version: value.required_version.map(|v| RawVersionWrapper(v).into()),
131133
strict_version: value.strict_version,
134+
tree_shaking_mode: value.tree_shaking_mode,
132135
},
133136
)
134137
}
135138
}
136139

140+
#[derive(Debug)]
141+
#[napi(object)]
142+
pub struct RawCollectShareEntryPluginOptions {
143+
pub consumes: Vec<RawConsumeOptions>,
144+
pub filename: Option<String>,
145+
}
146+
147+
impl From<RawCollectShareEntryPluginOptions> for CollectSharedEntryPluginOptions {
148+
fn from(value: RawCollectShareEntryPluginOptions) -> Self {
149+
Self {
150+
consumes: value
151+
.consumes
152+
.into_iter()
153+
.map(|provide| {
154+
let (key, consume_options): (String, ConsumeOptions) = provide.into();
155+
(key, std::sync::Arc::new(consume_options))
156+
})
157+
.collect(),
158+
filename: value.filename,
159+
}
160+
}
161+
}
162+
163+
#[derive(Debug)]
164+
#[napi(object)]
165+
pub struct RawSharedContainerPluginOptions {
166+
pub name: String,
167+
pub request: String,
168+
pub version: String,
169+
pub file_name: Option<String>,
170+
pub library: JsLibraryOptions,
171+
}
172+
173+
impl From<RawSharedContainerPluginOptions> for SharedContainerPluginOptions {
174+
fn from(value: RawSharedContainerPluginOptions) -> Self {
175+
SharedContainerPluginOptions {
176+
name: value.name,
177+
request: value.request,
178+
version: value.version,
179+
library: value.library.into(),
180+
file_name: value.file_name.clone().map(Into::into),
181+
}
182+
}
183+
}
184+
137185
#[derive(Debug)]
138186
#[napi(object)]
139187
pub struct RawConsumeSharedPluginOptions {
@@ -155,6 +203,52 @@ impl From<RawConsumeSharedPluginOptions> for ConsumeSharedPluginOptions {
155203
}
156204
}
157205

206+
#[derive(Debug)]
207+
#[napi(object)]
208+
pub struct RawOptimizeSharedConfig {
209+
pub share_key: String,
210+
pub tree_shaking: bool,
211+
pub used_exports: Option<Vec<String>>,
212+
}
213+
214+
impl From<RawOptimizeSharedConfig> for OptimizeSharedConfig {
215+
fn from(value: RawOptimizeSharedConfig) -> Self {
216+
Self {
217+
share_key: value.share_key,
218+
tree_shaking: value.tree_shaking,
219+
used_exports: value.used_exports.unwrap_or_default(),
220+
}
221+
}
222+
}
223+
224+
#[derive(Debug)]
225+
#[napi(object)]
226+
pub struct RawSharedUsedExportsOptimizerPluginOptions {
227+
pub shared: Vec<RawOptimizeSharedConfig>,
228+
pub inject_tree_shaking_used_exports: Option<bool>,
229+
pub manifest_file_name: Option<String>,
230+
pub stats_file_name: Option<String>,
231+
}
232+
233+
impl From<RawSharedUsedExportsOptimizerPluginOptions> for SharedUsedExportsOptimizerPluginOptions {
234+
fn from(value: RawSharedUsedExportsOptimizerPluginOptions) -> Self {
235+
Self {
236+
shared: value
237+
.shared
238+
.into_iter()
239+
.map(|config| config.into())
240+
.collect(),
241+
inject_tree_shaking_used_exports: value.inject_tree_shaking_used_exports.unwrap_or(true),
242+
manifest_file_name: value
243+
.manifest_file_name
244+
.and_then(|s| if s.trim().is_empty() { None } else { Some(s) }),
245+
stats_file_name: value
246+
.stats_file_name
247+
.and_then(|s| if s.trim().is_empty() { None } else { Some(s) }),
248+
}
249+
}
250+
}
251+
158252
#[derive(Debug)]
159253
#[napi(object)]
160254
pub struct RawConsumeOptions {
@@ -169,6 +263,7 @@ pub struct RawConsumeOptions {
169263
pub strict_version: bool,
170264
pub singleton: bool,
171265
pub eager: bool,
266+
pub tree_shaking_mode: Option<String>,
172267
}
173268

174269
impl From<RawConsumeOptions> for (String, ConsumeOptions) {
@@ -185,6 +280,7 @@ impl From<RawConsumeOptions> for (String, ConsumeOptions) {
185280
strict_version: value.strict_version,
186281
singleton: value.singleton,
187282
eager: value.eager,
283+
tree_shaking_mode: value.tree_shaking_mode,
188284
},
189285
)
190286
}
@@ -274,6 +370,9 @@ pub struct RawManifestSharedOption {
274370
pub struct RawStatsBuildInfo {
275371
pub build_version: String,
276372
pub build_name: Option<String>,
373+
// only appear when enable tree_shaking
374+
pub target: Option<Vec<String>>,
375+
pub plugins: Option<Vec<String>>,
277376
}
278377

279378
#[derive(Debug)]
@@ -337,6 +436,8 @@ impl From<RawModuleFederationManifestPluginOptions> for ModuleFederationManifest
337436
build_info: value.build_info.map(|info| StatsBuildInfo {
338437
build_version: info.build_version,
339438
build_name: info.build_name,
439+
target: info.target,
440+
plugins: info.plugins,
340441
}),
341442
}
342443
}

crates/rspack_core/src/compilation/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ use crate::{
7171
ChunkRenderCacheArtifact, ChunkRenderResult, ChunkUkey, CodeGenerateCacheArtifact,
7272
CodeGenerationJob, CodeGenerationResult, CodeGenerationResults, CompilationLogger,
7373
CompilationLogging, CompilerOptions, CompilerPlatform, ConcatenationScope,
74-
DependenciesDiagnosticsArtifact, DependencyCodeGeneration, DependencyTemplate,
74+
DependenciesDiagnosticsArtifact, DependencyCodeGeneration, DependencyId, DependencyTemplate,
7575
DependencyTemplateType, DependencyType, DerefOption, Entry, EntryData, EntryOptions,
76-
EntryRuntime, Entrypoint, ExecuteModuleId, Filename, ImportPhase, ImportVarMap,
77-
ImportedByDeferModulesArtifact, MemoryGCStorage, ModuleFactory, ModuleGraph,
76+
EntryRuntime, Entrypoint, ExecuteModuleId, ExtendedReferencedExport, Filename, ImportPhase,
77+
ImportVarMap, ImportedByDeferModulesArtifact, MemoryGCStorage, ModuleFactory, ModuleGraph,
7878
ModuleGraphCacheArtifact, ModuleIdentifier, ModuleIdsArtifact, ModuleStaticCache, PathData,
7979
ProcessRuntimeRequirementsCacheArtifact, ResolverFactory, RuntimeGlobals, RuntimeKeyMap,
8080
RuntimeMode, RuntimeModule, RuntimeSpec, RuntimeSpecMap, RuntimeTemplate, SharedPluginDriver,
@@ -97,6 +97,13 @@ define_hook!(CompilationExecuteModule:
9797
Series(module: &ModuleIdentifier, runtime_modules: &IdentifierSet, code_generation_results: &BindingCell<CodeGenerationResults>, execute_module_id: &ExecuteModuleId));
9898
define_hook!(CompilationFinishModules: Series(compilation: &mut Compilation, async_modules_artifact: &mut AsyncModulesArtifact));
9999
define_hook!(CompilationSeal: Series(compilation: &mut Compilation));
100+
define_hook!(CompilationDependencyReferencedExports: Series(
101+
compilation: &Compilation,
102+
dependency: &DependencyId,
103+
referenced_exports: &Option<Vec<ExtendedReferencedExport>>,
104+
runtime: Option<&RuntimeSpec>,
105+
module_graph: Option<&ModuleGraph>
106+
));
100107
define_hook!(CompilationConcatenationScope: SeriesBail(compilation: &Compilation, curr_module: ModuleIdentifier) -> ConcatenationScope);
101108
define_hook!(CompilationOptimizeDependencies: SeriesBail(compilation: &Compilation, side_effects_optimize_artifact: &mut SideEffectsOptimizeArtifact, build_module_graph_artifact: &mut BuildModuleGraphArtifact,
102109
diagnostics: &mut Vec<Diagnostic>) -> bool);
@@ -136,6 +143,7 @@ pub struct CompilationHooks {
136143
pub succeed_module: CompilationSucceedModuleHook,
137144
pub execute_module: CompilationExecuteModuleHook,
138145
pub finish_modules: CompilationFinishModulesHook,
146+
pub dependency_referenced_exports: CompilationDependencyReferencedExportsHook,
139147
pub seal: CompilationSealHook,
140148
pub optimize_dependencies: CompilationOptimizeDependenciesHook,
141149
pub optimize_modules: CompilationOptimizeModulesHook,

0 commit comments

Comments
 (0)