@module-federation/rspack 0.0.0-chore-bump-node-22-20260710161714

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present hanric(2heal1)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # `@module-federation/rspack` Documentation
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present hanric(2heal1)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ import type { Compiler, RspackPluginInstance } from '@rspack/core';
2
+ import { moduleFederationPlugin } from '@module-federation/sdk';
3
+ import { RemoteEntryPlugin } from './RemoteEntryPlugin';
4
+ export declare const PLUGIN_NAME = "RspackModuleFederationPlugin";
5
+ type ResolveFn = typeof require.resolve;
6
+ export declare function resolveRspackRuntimeImplementation(implementation?: string, resolve?: ResolveFn): string;
7
+ export declare function resolveRspackRuntimeAlias(implementation: string, resolve?: ResolveFn): string;
8
+ export declare class ModuleFederationPlugin implements RspackPluginInstance {
9
+ readonly name = "RspackModuleFederationPlugin";
10
+ private _options;
11
+ private _statsPlugin?;
12
+ constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions);
13
+ private _patchBundlerConfig;
14
+ private _checkSingleton;
15
+ apply(compiler: Compiler): void;
16
+ private _patchChunkSplit;
17
+ }
18
+ export declare const GetPublicPathPlugin: typeof RemoteEntryPlugin;
19
+ export { TreeShakingSharedPlugin, type TreeShakingSharedPluginOptions, } from './TreeShakingSharedPlugin';
@@ -0,0 +1,389 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ // webpack/runtime/compat_get_default_export
13
+ (() => {
14
+ // getDefaultExport function for compatibility with non-ESM modules
15
+ __webpack_require__.n = (module) => {
16
+ var getter = module && module.__esModule ?
17
+ () => (module['default']) :
18
+ () => (module);
19
+ __webpack_require__.d(getter, { a: getter });
20
+ return getter;
21
+ };
22
+
23
+ })();
24
+ // webpack/runtime/define_property_getters
25
+ (() => {
26
+ __webpack_require__.d = (exports, getters, values) => {
27
+ var define = (defs, kind) => {
28
+ for(var key in defs) {
29
+ if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
31
+ }
32
+ }
33
+ };
34
+ define(getters, "get");
35
+ define(values, "value");
36
+ };
37
+ })();
38
+ // webpack/runtime/has_own_property
39
+ (() => {
40
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
41
+ })();
42
+ // webpack/runtime/make_namespace_object
43
+ (() => {
44
+ // define __esModule on exports
45
+ __webpack_require__.r = (exports) => {
46
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
+ }
49
+ Object.defineProperty(exports, '__esModule', { value: true });
50
+ };
51
+ })();
52
+ var __webpack_exports__ = {};
53
+ // ESM COMPAT FLAG
54
+ __webpack_require__.r(__webpack_exports__);
55
+
56
+ // EXPORTS
57
+ __webpack_require__.d(__webpack_exports__, {
58
+ GetPublicPathPlugin: () => (/* binding */ GetPublicPathPlugin),
59
+ ModuleFederationPlugin: () => (/* binding */ ModuleFederationPlugin),
60
+ PLUGIN_NAME: () => (/* binding */ PLUGIN_NAME),
61
+ TreeShakingSharedPlugin: () => (/* reexport */ external_TreeShakingSharedPlugin_js_namespaceObject.TreeShakingSharedPlugin),
62
+ resolveRspackRuntimeAlias: () => (/* binding */ resolveRspackRuntimeAlias),
63
+ resolveRspackRuntimeImplementation: () => (/* binding */ resolveRspackRuntimeImplementation)
64
+ });
65
+
66
+ ;// CONCATENATED MODULE: external "@module-federation/sdk"
67
+ const sdk_namespaceObject = require("@module-federation/sdk");
68
+ ;// CONCATENATED MODULE: external "@module-federation/manifest"
69
+ const manifest_namespaceObject = require("@module-federation/manifest");
70
+ ;// CONCATENATED MODULE: external "@module-federation/managers"
71
+ const managers_namespaceObject = require("@module-federation/managers");
72
+ ;// CONCATENATED MODULE: external "@module-federation/dts-plugin"
73
+ const dts_plugin_namespaceObject = require("@module-federation/dts-plugin");
74
+ ;// CONCATENATED MODULE: external "@module-federation/bridge-react-webpack-plugin"
75
+ const bridge_react_webpack_plugin_namespaceObject = require("@module-federation/bridge-react-webpack-plugin");
76
+ var bridge_react_webpack_plugin_default = /*#__PURE__*/__webpack_require__.n(bridge_react_webpack_plugin_namespaceObject);
77
+ ;// CONCATENATED MODULE: external "node:path"
78
+ const external_node_path_namespaceObject = require("node:path");
79
+ var external_node_path_default = /*#__PURE__*/__webpack_require__.n(external_node_path_namespaceObject);
80
+ ;// CONCATENATED MODULE: external "node:fs"
81
+ const external_node_fs_namespaceObject = require("node:fs");
82
+ var external_node_fs_default = /*#__PURE__*/__webpack_require__.n(external_node_fs_namespaceObject);
83
+ ;// CONCATENATED MODULE: external "./RemoteEntryPlugin.js"
84
+ const external_RemoteEntryPlugin_js_namespaceObject = require("./RemoteEntryPlugin.js");
85
+ ;// CONCATENATED MODULE: external "./logger.js"
86
+ const external_logger_js_namespaceObject = require("./logger.js");
87
+ var external_logger_js_default = /*#__PURE__*/__webpack_require__.n(external_logger_js_namespaceObject);
88
+ ;// CONCATENATED MODULE: external "./TreeShakingSharedPlugin.js"
89
+ const external_TreeShakingSharedPlugin_js_namespaceObject = require("./TreeShakingSharedPlugin.js");
90
+ ;// CONCATENATED MODULE: ./src/ModuleFederationPlugin.ts
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ const PLUGIN_NAME = 'RspackModuleFederationPlugin';
101
+ function resolveRuntimeEntry(spec, implementation, resolve = require.resolve) {
102
+ const candidates = [
103
+ spec.bundler,
104
+ spec.esm,
105
+ spec.cjs
106
+ ];
107
+ const modulePaths = implementation ? [
108
+ implementation
109
+ ] : undefined;
110
+ let lastError;
111
+ for (const candidate of candidates){
112
+ try {
113
+ return modulePaths ? resolve(candidate, {
114
+ paths: modulePaths
115
+ }) : resolve(candidate);
116
+ } catch (error) {
117
+ lastError = error;
118
+ }
119
+ }
120
+ throw lastError;
121
+ }
122
+ function resolveRspackRuntimeImplementation(implementation, resolve = require.resolve) {
123
+ return resolveRuntimeEntry({
124
+ bundler: '@module-federation/runtime-tools/bundler',
125
+ esm: '@module-federation/runtime-tools/dist/index.js',
126
+ cjs: '@module-federation/runtime-tools/dist/index.cjs'
127
+ }, implementation, resolve);
128
+ }
129
+ function resolveRspackRuntimeAlias(implementation, resolve = require.resolve) {
130
+ return resolveRuntimeEntry({
131
+ bundler: '@module-federation/runtime/bundler',
132
+ esm: '@module-federation/runtime/dist/index.js',
133
+ cjs: '@module-federation/runtime/dist/index.cjs'
134
+ }, implementation, resolve);
135
+ }
136
+ class ModuleFederationPlugin {
137
+ _patchBundlerConfig(compiler) {
138
+ const { name, experiments } = this._options;
139
+ const definePluginOptions = {};
140
+ if (name) {
141
+ definePluginOptions['FEDERATION_BUILD_IDENTIFIER'] = JSON.stringify((0,sdk_namespaceObject.composeKeyWithSeparator)(name, managers_namespaceObject.utils.getBuildVersion()));
142
+ }
143
+ // Add FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN
144
+ const disableSnapshot = experiments?.optimization?.disableSnapshot ?? false;
145
+ definePluginOptions['FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN'] = disableSnapshot;
146
+ // Determine ENV_TARGET: only if manually specified in experiments.optimization.target
147
+ if (experiments?.optimization && typeof experiments.optimization === 'object' && experiments.optimization !== null && 'target' in experiments.optimization) {
148
+ const manualTarget = experiments.optimization.target;
149
+ // Ensure the target is one of the expected values before setting
150
+ if (manualTarget === 'web' || manualTarget === 'node') {
151
+ definePluginOptions['ENV_TARGET'] = JSON.stringify(manualTarget);
152
+ }
153
+ }
154
+ // No inference for ENV_TARGET. If not manually set and valid, it's not defined.
155
+ new compiler.webpack.DefinePlugin(definePluginOptions).apply(compiler);
156
+ }
157
+ _checkSingleton(compiler) {
158
+ let count = 0;
159
+ compiler.options.plugins.forEach((p)=>{
160
+ if (typeof p !== 'object' || !p) {
161
+ return;
162
+ }
163
+ if (p['name'] === this.name) {
164
+ count++;
165
+ if (count > 1) {
166
+ throw new Error(`Detect duplicate register ${this.name},please ensure ${this.name} is singleton!`);
167
+ }
168
+ }
169
+ });
170
+ }
171
+ apply(compiler) {
172
+ (0,sdk_namespaceObject.bindLoggerToCompiler)((external_logger_js_default()), compiler, PLUGIN_NAME);
173
+ const { _options: options } = this;
174
+ if (!options.name) {
175
+ throw new Error('[ ModuleFederationPlugin ]: name is required');
176
+ }
177
+ this._checkSingleton(compiler);
178
+ this._patchBundlerConfig(compiler);
179
+ const containerManager = new managers_namespaceObject.ContainerManager();
180
+ containerManager.init(options);
181
+ if (containerManager.enable) {
182
+ this._patchChunkSplit(compiler, options.name);
183
+ }
184
+ // must before ModuleFederationPlugin
185
+ new external_RemoteEntryPlugin_js_namespaceObject.RemoteEntryPlugin(options).apply(compiler);
186
+ if (options.experiments?.provideExternalRuntime) {
187
+ if (containerManager.enable) {
188
+ throw new Error('You can only set provideExternalRuntime: true in pure consumer which not expose modules.');
189
+ }
190
+ const runtimePlugins = options.runtimePlugins || [];
191
+ options.runtimePlugins = runtimePlugins.concat(require.resolve('@module-federation/inject-external-runtime-core-plugin'));
192
+ }
193
+ if (options.experiments?.externalRuntime === true) {
194
+ const Externals = compiler.webpack.ExternalsPlugin;
195
+ new Externals(compiler.options.externalsType || 'global', {
196
+ '@module-federation/runtime-core': '_FEDERATION_RUNTIME_CORE'
197
+ }).apply(compiler);
198
+ }
199
+ const implementationPath = options.implementation ? options.implementation : resolveRspackRuntimeImplementation();
200
+ options.implementation = implementationPath;
201
+ let disableManifest = options.manifest === false;
202
+ let disableDts = options.dts === false;
203
+ if (!disableDts) {
204
+ const dtsPlugin = new dts_plugin_namespaceObject.DtsPlugin(options);
205
+ // @ts-ignore
206
+ dtsPlugin.apply(compiler);
207
+ dtsPlugin.addRuntimePlugins();
208
+ }
209
+ if (!disableManifest && options.exposes) {
210
+ try {
211
+ options.exposes = containerManager.containerPluginExposesOptions;
212
+ } catch (err) {
213
+ if (err instanceof Error) {
214
+ err.message = `[ ModuleFederationPlugin ]: Manifest will not generate, because: ${err.message}`;
215
+ }
216
+ external_logger_js_default().warn(err);
217
+ disableManifest = true;
218
+ }
219
+ }
220
+ new compiler.webpack.container.ModuleFederationPlugin(options).apply(compiler);
221
+ let runtimePath;
222
+ try {
223
+ runtimePath = resolveRspackRuntimeAlias(implementationPath);
224
+ } catch (err) {
225
+ const detail = err instanceof Error ? err.message : String(err);
226
+ throw new Error(`[ ModuleFederationPlugin ]: Unable to resolve runtime entry (paths: [${implementationPath}]): ${detail}`);
227
+ }
228
+ compiler.hooks.afterPlugins.tap('PatchAliasWebpackPlugin', ()=>{
229
+ compiler.options.resolve.alias = {
230
+ ...compiler.options.resolve.alias,
231
+ '@module-federation/runtime$': runtimePath
232
+ };
233
+ });
234
+ if (!disableManifest) {
235
+ this._statsPlugin = new manifest_namespaceObject.StatsPlugin(options, {
236
+ pluginVersion: "0.0.0-chore-bump-node-22-20260710161714",
237
+ bundler: 'rspack'
238
+ });
239
+ // @ts-ignore
240
+ this._statsPlugin.apply(compiler);
241
+ }
242
+ const checkBridgeReactInstalled = ()=>{
243
+ try {
244
+ const userPackageJsonPath = external_node_path_default().resolve(compiler.context, 'package.json');
245
+ if (external_node_fs_default().existsSync(userPackageJsonPath)) {
246
+ const userPackageJson = JSON.parse(external_node_fs_default().readFileSync(userPackageJsonPath, 'utf-8'));
247
+ const userDependencies = {
248
+ ...userPackageJson.dependencies,
249
+ ...userPackageJson.devDependencies
250
+ };
251
+ return !!userDependencies['@module-federation/bridge-react'];
252
+ }
253
+ return false;
254
+ } catch (error) {
255
+ return false;
256
+ }
257
+ };
258
+ const hasBridgeReact = checkBridgeReactInstalled();
259
+ // react bridge plugin
260
+ const shouldEnableBridgePlugin = ()=>{
261
+ // Priority 1: Explicit enableBridgeRouter configuration
262
+ if (options?.bridge?.enableBridgeRouter === true) {
263
+ return true;
264
+ }
265
+ // Priority 2: Explicit disable via enableBridgeRouter:false or disableAlias:true
266
+ if (options?.bridge?.enableBridgeRouter === false || options?.bridge?.disableAlias === true) {
267
+ if (options?.bridge?.disableAlias === true) {
268
+ external_logger_js_default().warn('⚠️ [ModuleFederationPlugin] The `disableAlias` option is deprecated and will be removed in a future version.\n' + ' Please use `enableBridgeRouter: false` instead:\n' + ' {\n' + ' bridge: {\n' + ' enableBridgeRouter: false // Use this instead of disableAlias: true\n' + ' }\n' + ' }');
269
+ }
270
+ return false;
271
+ }
272
+ // Priority 3: Automatic detection based on bridge-react installation
273
+ if (hasBridgeReact) {
274
+ external_logger_js_default().info('💡 [ModuleFederationPlugin] Detected @module-federation/bridge-react in your dependencies.\n' + ' For better control and to avoid future breaking changes, please explicitly set:\n' + ' {\n' + ' bridge: {\n' + ' enableBridgeRouter: true // Explicitly enable bridge router\n' + ' }\n' + ' }');
275
+ return true;
276
+ }
277
+ return false;
278
+ };
279
+ const enableBridgePlugin = shouldEnableBridgePlugin();
280
+ // When bridge plugin is disabled (router disabled), alias to /base entry
281
+ if (!enableBridgePlugin && hasBridgeReact) {
282
+ compiler.hooks.afterPlugins.tap('BridgeReactBaseAliasPlugin', ()=>{
283
+ try {
284
+ const bridgeReactBasePath = external_node_path_default().resolve(compiler.context, 'node_modules/@module-federation/bridge-react/dist/base.es.js');
285
+ if (!external_node_fs_default().existsSync(bridgeReactBasePath)) {
286
+ external_logger_js_default().warn('⚠️ [ModuleFederationPlugin] bridge-react /base entry not found, falling back to default entry');
287
+ return;
288
+ }
289
+ compiler.options.resolve.alias = {
290
+ ...compiler.options.resolve.alias,
291
+ '@module-federation/bridge-react$': bridgeReactBasePath
292
+ };
293
+ external_logger_js_default().info('✅ [ModuleFederationPlugin] Router disabled - using /base entry (no react-router-dom)');
294
+ } catch (error) {
295
+ external_logger_js_default().warn('⚠️ [ModuleFederationPlugin] Failed to set /base alias, using default entry');
296
+ }
297
+ });
298
+ }
299
+ if (enableBridgePlugin) {
300
+ new (bridge_react_webpack_plugin_default())({
301
+ moduleFederationOptions: this._options
302
+ }).apply(compiler);
303
+ }
304
+ }
305
+ _patchChunkSplit(compiler, name) {
306
+ const { splitChunks } = compiler.options.optimization;
307
+ const patchChunkSplit = (cacheGroup)=>{
308
+ switch(typeof cacheGroup){
309
+ case 'boolean':
310
+ case 'string':
311
+ case 'function':
312
+ break;
313
+ // cacheGroup.chunks will inherit splitChunks.chunks, so you only need to modify the chunks that are set separately
314
+ case 'object':
315
+ {
316
+ if (cacheGroup instanceof RegExp) {
317
+ break;
318
+ }
319
+ if (!cacheGroup.chunks) {
320
+ break;
321
+ }
322
+ if (typeof cacheGroup.chunks === 'function') {
323
+ const prevChunks = cacheGroup.chunks;
324
+ cacheGroup.chunks = (chunk)=>{
325
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
326
+ return false;
327
+ }
328
+ return prevChunks(chunk);
329
+ };
330
+ break;
331
+ }
332
+ if (cacheGroup.chunks === 'all') {
333
+ cacheGroup.chunks = (chunk)=>{
334
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
335
+ return false;
336
+ }
337
+ return true;
338
+ };
339
+ break;
340
+ }
341
+ if (cacheGroup.chunks === 'initial') {
342
+ cacheGroup.chunks = (chunk)=>{
343
+ if (chunk.name && (chunk.name === name || chunk.name === name + '_partial')) {
344
+ return false;
345
+ }
346
+ return chunk.isOnlyInitial();
347
+ };
348
+ break;
349
+ }
350
+ break;
351
+ }
352
+ default:
353
+ break;
354
+ }
355
+ };
356
+ if (!splitChunks) {
357
+ return;
358
+ }
359
+ // 修改 splitChunk.chunks
360
+ patchChunkSplit(splitChunks);
361
+ const { cacheGroups } = splitChunks;
362
+ if (!cacheGroups) {
363
+ return;
364
+ }
365
+ // 修改 splitChunk.cacheGroups[key].chunks
366
+ Object.keys(cacheGroups).forEach((cacheGroupKey)=>{
367
+ patchChunkSplit(cacheGroups[cacheGroupKey]);
368
+ });
369
+ }
370
+ constructor(options){
371
+ this.name = PLUGIN_NAME;
372
+ this._options = options;
373
+ }
374
+ }
375
+ const GetPublicPathPlugin = external_RemoteEntryPlugin_js_namespaceObject.RemoteEntryPlugin;
376
+
377
+
378
+ exports.GetPublicPathPlugin = __webpack_exports__.GetPublicPathPlugin;
379
+ exports.ModuleFederationPlugin = __webpack_exports__.ModuleFederationPlugin;
380
+ exports.PLUGIN_NAME = __webpack_exports__.PLUGIN_NAME;
381
+ exports.TreeShakingSharedPlugin = __webpack_exports__.TreeShakingSharedPlugin;
382
+ exports.resolveRspackRuntimeAlias = __webpack_exports__.resolveRspackRuntimeAlias;
383
+ exports.resolveRspackRuntimeImplementation = __webpack_exports__.resolveRspackRuntimeImplementation;
384
+ for(var __rspack_i in __webpack_exports__) {
385
+ if(["GetPublicPathPlugin","ModuleFederationPlugin","PLUGIN_NAME","TreeShakingSharedPlugin","resolveRspackRuntimeAlias","resolveRspackRuntimeImplementation"].indexOf(__rspack_i) === -1) {
386
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
387
+ }
388
+ }
389
+ Object.defineProperty(exports, '__esModule', { value: true });