@module-federation/node 2.7.32 → 2.7.34

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.
Files changed (122) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +31 -0
  2. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  3. package/dist/plugins/ChunkCorrelationPlugin.js +308 -0
  4. package/dist/plugins/ChunkCorrelationPlugin.js.map +1 -0
  5. package/dist/plugins/ChunkCorrelationPlugin.mjs +305 -0
  6. package/dist/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
  7. package/dist/src/filesystem/stratagies.d.mts +21 -0
  8. package/dist/src/filesystem/stratagies.d.ts +10 -7
  9. package/dist/src/filesystem/stratagies.js +97 -116
  10. package/dist/src/filesystem/stratagies.js.map +1 -1
  11. package/dist/src/filesystem/stratagies.mjs +103 -0
  12. package/dist/src/filesystem/stratagies.mjs.map +1 -0
  13. package/dist/src/index.d.mts +8 -0
  14. package/dist/src/index.d.ts +8 -7
  15. package/dist/src/index.js +16 -22
  16. package/dist/src/index.mjs +9 -0
  17. package/dist/src/plugins/AutomaticPublicPathPlugin.d.mts +12 -0
  18. package/dist/src/plugins/AutomaticPublicPathPlugin.d.ts +9 -7
  19. package/dist/src/plugins/AutomaticPublicPathPlugin.js +26 -35
  20. package/dist/src/plugins/AutomaticPublicPathPlugin.js.map +1 -1
  21. package/dist/src/plugins/AutomaticPublicPathPlugin.mjs +28 -0
  22. package/dist/src/plugins/AutomaticPublicPathPlugin.mjs.map +1 -0
  23. package/dist/src/plugins/ChunkCorrelationPlugin.d.mts +5 -0
  24. package/dist/src/plugins/ChunkCorrelationPlugin.d.ts +4 -61
  25. package/dist/src/plugins/ChunkCorrelationPlugin.js +8 -440
  26. package/dist/src/plugins/ChunkCorrelationPlugin.js.map +1 -1
  27. package/dist/src/plugins/ChunkCorrelationPlugin.mjs +8 -0
  28. package/dist/src/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
  29. package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.mts +21 -0
  30. package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.ts +16 -13
  31. package/dist/src/plugins/CommonJsChunkLoadingPlugin.js +68 -118
  32. package/dist/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -1
  33. package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs +70 -0
  34. package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs.map +1 -0
  35. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.mts +46 -0
  36. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.ts +39 -34
  37. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +110 -126
  38. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -1
  39. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs +111 -0
  40. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs.map +1 -0
  41. package/dist/src/plugins/EntryChunkTrackerPlugin.d.mts +17 -0
  42. package/dist/src/plugins/EntryChunkTrackerPlugin.d.ts +14 -10
  43. package/dist/src/plugins/EntryChunkTrackerPlugin.js +30 -32
  44. package/dist/src/plugins/EntryChunkTrackerPlugin.js.map +1 -1
  45. package/dist/src/plugins/EntryChunkTrackerPlugin.mjs +38 -0
  46. package/dist/src/plugins/EntryChunkTrackerPlugin.mjs.map +1 -0
  47. package/dist/src/plugins/NodeFederationPlugin.d.mts +54 -0
  48. package/dist/src/plugins/NodeFederationPlugin.d.ts +33 -26
  49. package/dist/src/plugins/NodeFederationPlugin.js +72 -84
  50. package/dist/src/plugins/NodeFederationPlugin.js.map +1 -1
  51. package/dist/src/plugins/NodeFederationPlugin.mjs +73 -0
  52. package/dist/src/plugins/NodeFederationPlugin.mjs.map +1 -0
  53. package/dist/src/plugins/RemotePublicPathRuntimeModule.d.mts +15 -0
  54. package/dist/src/plugins/RemotePublicPathRuntimeModule.d.ts +12 -8
  55. package/dist/src/plugins/RemotePublicPathRuntimeModule.js +34 -35
  56. package/dist/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -1
  57. package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs +132 -0
  58. package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs.map +1 -0
  59. package/dist/src/plugins/StreamingTargetPlugin.d.mts +32 -0
  60. package/dist/src/plugins/StreamingTargetPlugin.d.ts +19 -16
  61. package/dist/src/plugins/StreamingTargetPlugin.js +43 -56
  62. package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -1
  63. package/dist/src/plugins/StreamingTargetPlugin.mjs +46 -0
  64. package/dist/src/plugins/StreamingTargetPlugin.mjs.map +1 -0
  65. package/dist/src/plugins/UniversalFederationPlugin.d.mts +49 -0
  66. package/dist/src/plugins/UniversalFederationPlugin.d.ts +26 -23
  67. package/dist/src/plugins/UniversalFederationPlugin.js +62 -81
  68. package/dist/src/plugins/UniversalFederationPlugin.js.map +1 -1
  69. package/dist/src/plugins/UniversalFederationPlugin.mjs +65 -0
  70. package/dist/src/plugins/UniversalFederationPlugin.mjs.map +1 -0
  71. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.mts +9 -0
  72. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.ts +6 -3
  73. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js +17 -17
  74. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js.map +1 -1
  75. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs +25 -0
  76. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs.map +1 -0
  77. package/dist/src/plugins/webpackChunkUtilities.d.mts +55 -0
  78. package/dist/src/plugins/webpackChunkUtilities.d.ts +14 -9
  79. package/dist/src/plugins/webpackChunkUtilities.js +195 -257
  80. package/dist/src/plugins/webpackChunkUtilities.js.map +1 -1
  81. package/dist/src/plugins/webpackChunkUtilities.mjs +234 -0
  82. package/dist/src/plugins/webpackChunkUtilities.mjs.map +1 -0
  83. package/dist/src/recordDynamicRemoteEntryHashPlugin.d.mts +7 -0
  84. package/dist/src/recordDynamicRemoteEntryHashPlugin.d.ts +5 -2
  85. package/dist/src/recordDynamicRemoteEntryHashPlugin.js +24 -61
  86. package/dist/src/recordDynamicRemoteEntryHashPlugin.js.map +1 -1
  87. package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs +26 -0
  88. package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs.map +1 -0
  89. package/dist/src/runtimePlugin.d.mts +27 -0
  90. package/dist/src/runtimePlugin.d.ts +24 -19
  91. package/dist/src/runtimePlugin.js +157 -252
  92. package/dist/src/runtimePlugin.js.map +1 -1
  93. package/dist/src/runtimePlugin.mjs +169 -0
  94. package/dist/src/runtimePlugin.mjs.map +1 -0
  95. package/dist/src/types/index.d.mts +8 -0
  96. package/dist/src/types/index.d.ts +8 -3
  97. package/dist/src/types/index.js +1 -3
  98. package/dist/src/types/index.mjs +1 -0
  99. package/dist/src/utils/flush-chunks.d.mts +15 -0
  100. package/dist/src/utils/flush-chunks.d.ts +7 -3
  101. package/dist/src/utils/flush-chunks.js +90 -161
  102. package/dist/src/utils/flush-chunks.js.map +1 -1
  103. package/dist/src/utils/flush-chunks.mjs +102 -0
  104. package/dist/src/utils/flush-chunks.mjs.map +1 -0
  105. package/dist/src/utils/hot-reload.d.mts +16 -0
  106. package/dist/src/utils/hot-reload.d.ts +14 -10
  107. package/dist/src/utils/hot-reload.js +178 -264
  108. package/dist/src/utils/hot-reload.js.map +1 -1
  109. package/dist/src/utils/hot-reload.mjs +195 -0
  110. package/dist/src/utils/hot-reload.mjs.map +1 -0
  111. package/dist/src/utils/index.d.mts +3 -0
  112. package/dist/src/utils/index.d.ts +3 -2
  113. package/dist/src/utils/index.js +15 -19
  114. package/dist/src/utils/index.mjs +4 -0
  115. package/package.json +65 -15
  116. package/dist/jest.config.d.ts +0 -11
  117. package/dist/jest.config.js +0 -19
  118. package/dist/jest.config.js.map +0 -1
  119. package/dist/package.json +0 -82
  120. package/dist/src/index.js.map +0 -1
  121. package/dist/src/types/index.js.map +0 -1
  122. package/dist/src/utils/index.js.map +0 -1
@@ -0,0 +1,54 @@
1
+ import { ModuleFederationPluginOptions } from "../types/index.mjs";
2
+ import { Compiler, container } from "webpack";
3
+
4
+ //#region src/plugins/NodeFederationPlugin.d.ts
5
+ /**
6
+ * Interface for NodeFederationOptions which extends ModuleFederationPluginOptions
7
+ * @interface
8
+ * @property {boolean} debug - Optional debug flag
9
+ */
10
+ interface NodeFederationOptions extends ModuleFederationPluginOptions {
11
+ debug?: boolean;
12
+ useRuntimePlugin?: boolean;
13
+ }
14
+ /**
15
+ * Interface for Context
16
+ * @interface
17
+ * @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin
18
+ */
19
+ interface Context {
20
+ ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
21
+ }
22
+ /**
23
+ * Class representing a NodeFederationPlugin.
24
+ * @class
25
+ */
26
+ declare class NodeFederationPlugin {
27
+ private _options;
28
+ private context;
29
+ private useRuntimePlugin?;
30
+ private logger;
31
+ /**
32
+ * Create a NodeFederationPlugin.
33
+ * @constructor
34
+ * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
35
+ * @param {Context} context - The context for the NodeFederationPlugin
36
+ */
37
+ constructor({
38
+ debug,
39
+ useRuntimePlugin,
40
+ ...options
41
+ }: NodeFederationOptions, context: Context);
42
+ /**
43
+ * Apply method for the NodeFederationPlugin class.
44
+ * @method
45
+ * @param {Compiler} compiler - The webpack compiler.
46
+ */
47
+ apply(compiler: Compiler): void;
48
+ private preparePluginOptions;
49
+ private updateCompilerOptions;
50
+ private getModuleFederationPlugin;
51
+ }
52
+ //#endregion
53
+ export { NodeFederationPlugin as default };
54
+ //# sourceMappingURL=NodeFederationPlugin.d.mts.map
@@ -1,13 +1,15 @@
1
- import type { Compiler, container } from 'webpack';
2
- import type { ModuleFederationPluginOptions } from '../types';
1
+ import { ModuleFederationPluginOptions } from "../types/index.js";
2
+ import { Compiler, container } from "webpack";
3
+
4
+ //#region src/plugins/NodeFederationPlugin.d.ts
3
5
  /**
4
6
  * Interface for NodeFederationOptions which extends ModuleFederationPluginOptions
5
7
  * @interface
6
8
  * @property {boolean} debug - Optional debug flag
7
9
  */
8
10
  interface NodeFederationOptions extends ModuleFederationPluginOptions {
9
- debug?: boolean;
10
- useRuntimePlugin?: boolean;
11
+ debug?: boolean;
12
+ useRuntimePlugin?: boolean;
11
13
  }
12
14
  /**
13
15
  * Interface for Context
@@ -15,32 +17,37 @@ interface NodeFederationOptions extends ModuleFederationPluginOptions {
15
17
  * @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin
16
18
  */
17
19
  interface Context {
18
- ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
20
+ ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
19
21
  }
20
22
  /**
21
23
  * Class representing a NodeFederationPlugin.
22
24
  * @class
23
25
  */
24
26
  declare class NodeFederationPlugin {
25
- private _options;
26
- private context;
27
- private useRuntimePlugin?;
28
- private logger;
29
- /**
30
- * Create a NodeFederationPlugin.
31
- * @constructor
32
- * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
33
- * @param {Context} context - The context for the NodeFederationPlugin
34
- */
35
- constructor({ debug, useRuntimePlugin, ...options }: NodeFederationOptions, context: Context);
36
- /**
37
- * Apply method for the NodeFederationPlugin class.
38
- * @method
39
- * @param {Compiler} compiler - The webpack compiler.
40
- */
41
- apply(compiler: Compiler): void;
42
- private preparePluginOptions;
43
- private updateCompilerOptions;
44
- private getModuleFederationPlugin;
27
+ private _options;
28
+ private context;
29
+ private useRuntimePlugin?;
30
+ private logger;
31
+ /**
32
+ * Create a NodeFederationPlugin.
33
+ * @constructor
34
+ * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
35
+ * @param {Context} context - The context for the NodeFederationPlugin
36
+ */
37
+ constructor({
38
+ debug,
39
+ useRuntimePlugin,
40
+ ...options
41
+ }: NodeFederationOptions, context: Context);
42
+ /**
43
+ * Apply method for the NodeFederationPlugin class.
44
+ * @method
45
+ * @param {Compiler} compiler - The webpack compiler.
46
+ */
47
+ apply(compiler: Compiler): void;
48
+ private preparePluginOptions;
49
+ private updateCompilerOptions;
50
+ private getModuleFederationPlugin;
45
51
  }
46
- export default NodeFederationPlugin;
52
+ export = NodeFederationPlugin;
53
+ //# sourceMappingURL=NodeFederationPlugin.d.ts.map
@@ -1,88 +1,76 @@
1
1
  'use strict';
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const EntryChunkTrackerPlugin_1 = __importDefault(require("./EntryChunkTrackerPlugin"));
7
- const sdk_1 = require("@module-federation/sdk");
8
- const createBundlerLogger = typeof sdk_1.createInfrastructureLogger === 'function'
9
- ? sdk_1.createInfrastructureLogger
10
- : sdk_1.createLogger;
11
- /**
12
- * Class representing a NodeFederationPlugin.
13
- * @class
14
- */
15
- class NodeFederationPlugin {
16
- /**
17
- * Create a NodeFederationPlugin.
18
- * @constructor
19
- * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
20
- * @param {Context} context - The context for the NodeFederationPlugin
21
- */
22
- constructor({ debug, useRuntimePlugin, ...options }, context) {
23
- this.logger = createBundlerLogger('[ Node Federation Plugin ]');
24
- this._options = options || {};
25
- this.context = context || {};
26
- this.useRuntimePlugin = useRuntimePlugin || false;
27
- }
28
- /**
29
- * Apply method for the NodeFederationPlugin class.
30
- * @method
31
- * @param {Compiler} compiler - The webpack compiler.
32
- */
33
- apply(compiler) {
34
- (0, sdk_1.bindLoggerToCompiler)(this.logger, compiler, 'NodeFederationPlugin');
35
- const { webpack } = compiler;
36
- const pluginOptions = this.preparePluginOptions();
37
- this.updateCompilerOptions(compiler);
38
- const ModuleFederationPlugin = this.getModuleFederationPlugin(compiler, webpack);
39
- new ModuleFederationPlugin(pluginOptions).apply(compiler);
40
- new EntryChunkTrackerPlugin_1.default({}).apply(compiler);
41
- }
42
- preparePluginOptions() {
43
- this._options.runtimePlugins = [
44
- ...(this.useRuntimePlugin ? [require.resolve('../runtimePlugin')] : []),
45
- ...(this._options.runtimePlugins || []),
46
- ];
47
- return {
48
- ...this._options,
49
- remotes: this._options.remotes || {},
50
- runtimePlugins: this._options.runtimePlugins,
51
- // enable dts in browser by default
52
- dts: this._options.dts ?? false,
53
- };
54
- }
55
- updateCompilerOptions(compiler) {
56
- const chunkFileName = compiler.options?.output?.chunkFilename;
57
- const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
58
- if (typeof chunkFileName === 'string' &&
59
- uniqueName &&
60
- !chunkFileName.includes(uniqueName)) {
61
- const suffix = `-[contenthash].js`;
62
- compiler.options.output.chunkFilename = chunkFileName.replace('.js', suffix);
63
- }
64
- }
65
- getModuleFederationPlugin(compiler, webpack) {
66
- let ModuleFederationPlugin;
67
- try {
68
- return require('@module-federation/enhanced').ModuleFederationPlugin;
69
- }
70
- catch (e) {
71
- this.logger.error("Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work");
72
- if (this.context.ModuleFederationPlugin) {
73
- ModuleFederationPlugin = this.context.ModuleFederationPlugin;
74
- }
75
- else if (webpack &&
76
- webpack.container &&
77
- webpack.container.ModuleFederationPlugin) {
78
- ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;
79
- }
80
- else {
81
- ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
82
- }
83
- return ModuleFederationPlugin;
84
- }
85
- }
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+ const require_runtime = require('../../_virtual/_rolldown/runtime.js');
5
+ const require_src_plugins_EntryChunkTrackerPlugin = require('./EntryChunkTrackerPlugin.js');
6
+ let _module_federation_sdk = require("@module-federation/sdk");
7
+
8
+ //#region src/plugins/NodeFederationPlugin.ts
9
+ const createBundlerLogger = typeof _module_federation_sdk.createInfrastructureLogger === "function" ? _module_federation_sdk.createInfrastructureLogger : _module_federation_sdk.createLogger;
10
+ function getRuntimePluginPath() {
11
+ return require.resolve("../runtimePlugin.js");
86
12
  }
13
+ /**
14
+ * Class representing a NodeFederationPlugin.
15
+ * @class
16
+ */
17
+ var NodeFederationPlugin = class {
18
+ /**
19
+ * Create a NodeFederationPlugin.
20
+ * @constructor
21
+ * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
22
+ * @param {Context} context - The context for the NodeFederationPlugin
23
+ */
24
+ constructor({ debug, useRuntimePlugin, ...options }, context) {
25
+ this.logger = createBundlerLogger("[ Node Federation Plugin ]");
26
+ this._options = options || {};
27
+ this.context = context || {};
28
+ this.useRuntimePlugin = useRuntimePlugin || false;
29
+ }
30
+ /**
31
+ * Apply method for the NodeFederationPlugin class.
32
+ * @method
33
+ * @param {Compiler} compiler - The webpack compiler.
34
+ */
35
+ apply(compiler) {
36
+ (0, _module_federation_sdk.bindLoggerToCompiler)(this.logger, compiler, "NodeFederationPlugin");
37
+ const { webpack } = compiler;
38
+ const pluginOptions = this.preparePluginOptions();
39
+ this.updateCompilerOptions(compiler);
40
+ new (this.getModuleFederationPlugin(compiler, webpack))(pluginOptions).apply(compiler);
41
+ new require_src_plugins_EntryChunkTrackerPlugin.default({}).apply(compiler);
42
+ }
43
+ preparePluginOptions() {
44
+ this._options.runtimePlugins = [...this.useRuntimePlugin ? [getRuntimePluginPath()] : [], ...this._options.runtimePlugins || []];
45
+ return {
46
+ ...this._options,
47
+ remotes: this._options.remotes || {},
48
+ runtimePlugins: this._options.runtimePlugins,
49
+ dts: this._options.dts ?? false
50
+ };
51
+ }
52
+ updateCompilerOptions(compiler) {
53
+ const chunkFileName = compiler.options?.output?.chunkFilename;
54
+ const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
55
+ if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
56
+ const suffix = `-[contenthash].js`;
57
+ compiler.options.output.chunkFilename = chunkFileName.replace(".js", suffix);
58
+ }
59
+ }
60
+ getModuleFederationPlugin(compiler, webpack) {
61
+ let ModuleFederationPlugin;
62
+ try {
63
+ return require("@module-federation/enhanced").ModuleFederationPlugin;
64
+ } catch (e) {
65
+ this.logger.error("Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work");
66
+ if (this.context.ModuleFederationPlugin) ModuleFederationPlugin = this.context.ModuleFederationPlugin;
67
+ else if (webpack && webpack.container && webpack.container.ModuleFederationPlugin) ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;
68
+ else ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
69
+ return ModuleFederationPlugin;
70
+ }
71
+ }
72
+ };
73
+
74
+ //#endregion
87
75
  exports.default = NodeFederationPlugin;
88
76
  //# sourceMappingURL=NodeFederationPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeFederationPlugin.js","sourceRoot":"","sources":["../../../src/plugins/NodeFederationPlugin.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"NodeFederationPlugin.js","names":["createInfrastructureLogger","createLogger","EntryChunkTrackerPlugin"],"sources":["../../../src/plugins/NodeFederationPlugin.ts"],"sourcesContent":["'use strict';\n\nimport type { Compiler, container } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\nimport EntryChunkTrackerPlugin from './EntryChunkTrackerPlugin';\nimport {\n bindLoggerToCompiler,\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\n/**\n * Interface for NodeFederationOptions which extends ModuleFederationPluginOptions\n * @interface\n * @property {boolean} debug - Optional debug flag\n */\ninterface NodeFederationOptions extends ModuleFederationPluginOptions {\n debug?: boolean;\n useRuntimePlugin?: boolean;\n}\n\n/**\n * Interface for Context\n * @interface\n * @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin\n */\ninterface Context {\n ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;\n}\n\nconst createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n\nfunction getRuntimePluginPath(): string {\n return require.resolve(\n process.env.IS_ESM_BUILD === 'true'\n ? '../runtimePlugin.mjs'\n : '../runtimePlugin.js',\n );\n}\n\n/**\n * Class representing a NodeFederationPlugin.\n * @class\n */\nclass NodeFederationPlugin {\n private _options: ModuleFederationPluginOptions;\n private context: Context;\n private useRuntimePlugin?: boolean;\n private logger = createBundlerLogger('[ Node Federation Plugin ]');\n\n /**\n * Create a NodeFederationPlugin.\n * @constructor\n * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin\n * @param {Context} context - The context for the NodeFederationPlugin\n */\n constructor(\n { debug, useRuntimePlugin, ...options }: NodeFederationOptions,\n context: Context,\n ) {\n this._options = options || ({} as ModuleFederationPluginOptions);\n this.context = context || ({} as Context);\n this.useRuntimePlugin = useRuntimePlugin || false;\n }\n\n /**\n * Apply method for the NodeFederationPlugin class.\n * @method\n * @param {Compiler} compiler - The webpack compiler.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(this.logger, compiler, 'NodeFederationPlugin');\n const { webpack } = compiler;\n const pluginOptions = this.preparePluginOptions();\n this.updateCompilerOptions(compiler);\n const ModuleFederationPlugin = this.getModuleFederationPlugin(\n compiler,\n webpack,\n );\n new ModuleFederationPlugin(pluginOptions).apply(compiler);\n new EntryChunkTrackerPlugin({}).apply(compiler);\n }\n\n private preparePluginOptions(): ModuleFederationPluginOptions {\n this._options.runtimePlugins = [\n ...(this.useRuntimePlugin ? [getRuntimePluginPath()] : []),\n ...(this._options.runtimePlugins || []),\n ];\n\n return {\n ...this._options,\n remotes: this._options.remotes || {},\n runtimePlugins: this._options.runtimePlugins,\n // enable dts in browser by default\n dts: this._options.dts ?? false,\n };\n }\n\n private updateCompilerOptions(compiler: Compiler): void {\n const chunkFileName = compiler.options?.output?.chunkFilename;\n const uniqueName =\n compiler?.options?.output?.uniqueName || this._options.name;\n if (\n typeof chunkFileName === 'string' &&\n uniqueName &&\n !chunkFileName.includes(uniqueName)\n ) {\n const suffix = `-[contenthash].js`;\n compiler.options.output.chunkFilename = chunkFileName.replace(\n '.js',\n suffix,\n );\n }\n }\n\n private getModuleFederationPlugin(compiler: Compiler, webpack: any): any {\n let ModuleFederationPlugin;\n try {\n return require('@module-federation/enhanced').ModuleFederationPlugin;\n } catch (e) {\n this.logger.error(\n \"Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work\",\n );\n if (this.context.ModuleFederationPlugin) {\n ModuleFederationPlugin = this.context.ModuleFederationPlugin;\n } else if (\n webpack &&\n webpack.container &&\n webpack.container.ModuleFederationPlugin\n ) {\n ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;\n } else {\n ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');\n }\n return ModuleFederationPlugin;\n }\n }\n}\n\nexport default NodeFederationPlugin;\n"],"mappings":";;;;;;;;AA6BA,MAAM,sBACJ,OAAOA,sDAA+B,aACjCA,oDACDC;AAEN,SAAS,uBAA+B;AACtC,QAAO,QAAQ,QAGT,sBACL;;;;;;AAOH,IAAM,uBAAN,MAA2B;;;;;;;CAYzB,YACE,EAAE,OAAO,kBAAkB,GAAG,WAC9B,SACA;gBAXe,oBAAoB,6BAA6B;AAYhE,OAAK,WAAW,WAAY,EAAE;AAC9B,OAAK,UAAU,WAAY,EAAE;AAC7B,OAAK,mBAAmB,oBAAoB;;;;;;;CAQ9C,MAAM,UAAoB;AACxB,mDAAqB,KAAK,QAAQ,UAAU,uBAAuB;EACnE,MAAM,EAAE,YAAY;EACpB,MAAM,gBAAgB,KAAK,sBAAsB;AACjD,OAAK,sBAAsB,SAAS;AAKpC,OAJ+B,KAAK,0BAClC,UACA,QACD,EAC0B,cAAc,CAAC,MAAM,SAAS;AACzD,MAAIC,oDAAwB,EAAE,CAAC,CAAC,MAAM,SAAS;;CAGjD,AAAQ,uBAAsD;AAC5D,OAAK,SAAS,iBAAiB,CAC7B,GAAI,KAAK,mBAAmB,CAAC,sBAAsB,CAAC,GAAG,EAAE,EACzD,GAAI,KAAK,SAAS,kBAAkB,EAAE,CACvC;AAED,SAAO;GACL,GAAG,KAAK;GACR,SAAS,KAAK,SAAS,WAAW,EAAE;GACpC,gBAAgB,KAAK,SAAS;GAE9B,KAAK,KAAK,SAAS,OAAO;GAC3B;;CAGH,AAAQ,sBAAsB,UAA0B;EACtD,MAAM,gBAAgB,SAAS,SAAS,QAAQ;EAChD,MAAM,aACJ,UAAU,SAAS,QAAQ,cAAc,KAAK,SAAS;AACzD,MACE,OAAO,kBAAkB,YACzB,cACA,CAAC,cAAc,SAAS,WAAW,EACnC;GACA,MAAM,SAAS;AACf,YAAS,QAAQ,OAAO,gBAAgB,cAAc,QACpD,OACA,OACD;;;CAIL,AAAQ,0BAA0B,UAAoB,SAAmB;EACvE,IAAI;AACJ,MAAI;AACF,UAAO,QAAQ,8BAA8B,CAAC;WACvC,GAAG;AACV,QAAK,OAAO,MACV,4GACD;AACD,OAAI,KAAK,QAAQ,uBACf,0BAAyB,KAAK,QAAQ;YAEtC,WACA,QAAQ,aACR,QAAQ,UAAU,uBAElB,0BAAyB,QAAQ,UAAU;OAE3C,0BAAyB,QAAQ,+CAA+C;AAElF,UAAO"}
@@ -0,0 +1,73 @@
1
+ import { __require } from "../../_virtual/_rolldown/runtime.mjs";
2
+ import EntryChunkTrackerPlugin from "./EntryChunkTrackerPlugin.mjs";
3
+ import { bindLoggerToCompiler, createInfrastructureLogger, createLogger } from "@module-federation/sdk";
4
+
5
+ //#region src/plugins/NodeFederationPlugin.ts
6
+ const createBundlerLogger = typeof createInfrastructureLogger === "function" ? createInfrastructureLogger : createLogger;
7
+ function getRuntimePluginPath() {
8
+ return __require.resolve("../runtimePlugin.mjs");
9
+ }
10
+ /**
11
+ * Class representing a NodeFederationPlugin.
12
+ * @class
13
+ */
14
+ var NodeFederationPlugin = class {
15
+ /**
16
+ * Create a NodeFederationPlugin.
17
+ * @constructor
18
+ * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
19
+ * @param {Context} context - The context for the NodeFederationPlugin
20
+ */
21
+ constructor({ debug, useRuntimePlugin, ...options }, context) {
22
+ this.logger = createBundlerLogger("[ Node Federation Plugin ]");
23
+ this._options = options || {};
24
+ this.context = context || {};
25
+ this.useRuntimePlugin = useRuntimePlugin || false;
26
+ }
27
+ /**
28
+ * Apply method for the NodeFederationPlugin class.
29
+ * @method
30
+ * @param {Compiler} compiler - The webpack compiler.
31
+ */
32
+ apply(compiler) {
33
+ bindLoggerToCompiler(this.logger, compiler, "NodeFederationPlugin");
34
+ const { webpack } = compiler;
35
+ const pluginOptions = this.preparePluginOptions();
36
+ this.updateCompilerOptions(compiler);
37
+ new (this.getModuleFederationPlugin(compiler, webpack))(pluginOptions).apply(compiler);
38
+ new EntryChunkTrackerPlugin({}).apply(compiler);
39
+ }
40
+ preparePluginOptions() {
41
+ this._options.runtimePlugins = [...this.useRuntimePlugin ? [getRuntimePluginPath()] : [], ...this._options.runtimePlugins || []];
42
+ return {
43
+ ...this._options,
44
+ remotes: this._options.remotes || {},
45
+ runtimePlugins: this._options.runtimePlugins,
46
+ dts: this._options.dts ?? false
47
+ };
48
+ }
49
+ updateCompilerOptions(compiler) {
50
+ const chunkFileName = compiler.options?.output?.chunkFilename;
51
+ const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
52
+ if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
53
+ const suffix = `-[contenthash].js`;
54
+ compiler.options.output.chunkFilename = chunkFileName.replace(".js", suffix);
55
+ }
56
+ }
57
+ getModuleFederationPlugin(compiler, webpack) {
58
+ let ModuleFederationPlugin;
59
+ try {
60
+ return __require("@module-federation/enhanced").ModuleFederationPlugin;
61
+ } catch (e) {
62
+ this.logger.error("Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work");
63
+ if (this.context.ModuleFederationPlugin) ModuleFederationPlugin = this.context.ModuleFederationPlugin;
64
+ else if (webpack && webpack.container && webpack.container.ModuleFederationPlugin) ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;
65
+ else ModuleFederationPlugin = __require("webpack/lib/container/ModuleFederationPlugin");
66
+ return ModuleFederationPlugin;
67
+ }
68
+ }
69
+ };
70
+
71
+ //#endregion
72
+ export { NodeFederationPlugin as default };
73
+ //# sourceMappingURL=NodeFederationPlugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeFederationPlugin.mjs","names":[],"sources":["../../../src/plugins/NodeFederationPlugin.ts"],"sourcesContent":["'use strict';\n\nimport type { Compiler, container } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\nimport EntryChunkTrackerPlugin from './EntryChunkTrackerPlugin';\nimport {\n bindLoggerToCompiler,\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\n/**\n * Interface for NodeFederationOptions which extends ModuleFederationPluginOptions\n * @interface\n * @property {boolean} debug - Optional debug flag\n */\ninterface NodeFederationOptions extends ModuleFederationPluginOptions {\n debug?: boolean;\n useRuntimePlugin?: boolean;\n}\n\n/**\n * Interface for Context\n * @interface\n * @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin\n */\ninterface Context {\n ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;\n}\n\nconst createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n\nfunction getRuntimePluginPath(): string {\n return require.resolve(\n process.env.IS_ESM_BUILD === 'true'\n ? '../runtimePlugin.mjs'\n : '../runtimePlugin.js',\n );\n}\n\n/**\n * Class representing a NodeFederationPlugin.\n * @class\n */\nclass NodeFederationPlugin {\n private _options: ModuleFederationPluginOptions;\n private context: Context;\n private useRuntimePlugin?: boolean;\n private logger = createBundlerLogger('[ Node Federation Plugin ]');\n\n /**\n * Create a NodeFederationPlugin.\n * @constructor\n * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin\n * @param {Context} context - The context for the NodeFederationPlugin\n */\n constructor(\n { debug, useRuntimePlugin, ...options }: NodeFederationOptions,\n context: Context,\n ) {\n this._options = options || ({} as ModuleFederationPluginOptions);\n this.context = context || ({} as Context);\n this.useRuntimePlugin = useRuntimePlugin || false;\n }\n\n /**\n * Apply method for the NodeFederationPlugin class.\n * @method\n * @param {Compiler} compiler - The webpack compiler.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(this.logger, compiler, 'NodeFederationPlugin');\n const { webpack } = compiler;\n const pluginOptions = this.preparePluginOptions();\n this.updateCompilerOptions(compiler);\n const ModuleFederationPlugin = this.getModuleFederationPlugin(\n compiler,\n webpack,\n );\n new ModuleFederationPlugin(pluginOptions).apply(compiler);\n new EntryChunkTrackerPlugin({}).apply(compiler);\n }\n\n private preparePluginOptions(): ModuleFederationPluginOptions {\n this._options.runtimePlugins = [\n ...(this.useRuntimePlugin ? [getRuntimePluginPath()] : []),\n ...(this._options.runtimePlugins || []),\n ];\n\n return {\n ...this._options,\n remotes: this._options.remotes || {},\n runtimePlugins: this._options.runtimePlugins,\n // enable dts in browser by default\n dts: this._options.dts ?? false,\n };\n }\n\n private updateCompilerOptions(compiler: Compiler): void {\n const chunkFileName = compiler.options?.output?.chunkFilename;\n const uniqueName =\n compiler?.options?.output?.uniqueName || this._options.name;\n if (\n typeof chunkFileName === 'string' &&\n uniqueName &&\n !chunkFileName.includes(uniqueName)\n ) {\n const suffix = `-[contenthash].js`;\n compiler.options.output.chunkFilename = chunkFileName.replace(\n '.js',\n suffix,\n );\n }\n }\n\n private getModuleFederationPlugin(compiler: Compiler, webpack: any): any {\n let ModuleFederationPlugin;\n try {\n return require('@module-federation/enhanced').ModuleFederationPlugin;\n } catch (e) {\n this.logger.error(\n \"Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work\",\n );\n if (this.context.ModuleFederationPlugin) {\n ModuleFederationPlugin = this.context.ModuleFederationPlugin;\n } else if (\n webpack &&\n webpack.container &&\n webpack.container.ModuleFederationPlugin\n ) {\n ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;\n } else {\n ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');\n }\n return ModuleFederationPlugin;\n }\n }\n}\n\nexport default NodeFederationPlugin;\n"],"mappings":";;;;;AA6BA,MAAM,sBACJ,OAAO,+BAA+B,aACjC,6BACD;AAEN,SAAS,uBAA+B;AACtC,kBAAe,QAET,uBAEL;;;;;;AAOH,IAAM,uBAAN,MAA2B;;;;;;;CAYzB,YACE,EAAE,OAAO,kBAAkB,GAAG,WAC9B,SACA;gBAXe,oBAAoB,6BAA6B;AAYhE,OAAK,WAAW,WAAY,EAAE;AAC9B,OAAK,UAAU,WAAY,EAAE;AAC7B,OAAK,mBAAmB,oBAAoB;;;;;;;CAQ9C,MAAM,UAAoB;AACxB,uBAAqB,KAAK,QAAQ,UAAU,uBAAuB;EACnE,MAAM,EAAE,YAAY;EACpB,MAAM,gBAAgB,KAAK,sBAAsB;AACjD,OAAK,sBAAsB,SAAS;AAKpC,OAJ+B,KAAK,0BAClC,UACA,QACD,EAC0B,cAAc,CAAC,MAAM,SAAS;AACzD,MAAI,wBAAwB,EAAE,CAAC,CAAC,MAAM,SAAS;;CAGjD,AAAQ,uBAAsD;AAC5D,OAAK,SAAS,iBAAiB,CAC7B,GAAI,KAAK,mBAAmB,CAAC,sBAAsB,CAAC,GAAG,EAAE,EACzD,GAAI,KAAK,SAAS,kBAAkB,EAAE,CACvC;AAED,SAAO;GACL,GAAG,KAAK;GACR,SAAS,KAAK,SAAS,WAAW,EAAE;GACpC,gBAAgB,KAAK,SAAS;GAE9B,KAAK,KAAK,SAAS,OAAO;GAC3B;;CAGH,AAAQ,sBAAsB,UAA0B;EACtD,MAAM,gBAAgB,SAAS,SAAS,QAAQ;EAChD,MAAM,aACJ,UAAU,SAAS,QAAQ,cAAc,KAAK,SAAS;AACzD,MACE,OAAO,kBAAkB,YACzB,cACA,CAAC,cAAc,SAAS,WAAW,EACnC;GACA,MAAM,SAAS;AACf,YAAS,QAAQ,OAAO,gBAAgB,cAAc,QACpD,OACA,OACD;;;CAIL,AAAQ,0BAA0B,UAAoB,SAAmB;EACvE,IAAI;AACJ,MAAI;AACF,oBAAe,8BAA8B,CAAC;WACvC,GAAG;AACV,QAAK,OAAO,MACV,4GACD;AACD,OAAI,KAAK,QAAQ,uBACf,0BAAyB,KAAK,QAAQ;YAEtC,WACA,QAAQ,aACR,QAAQ,UAAU,uBAElB,0BAAyB,QAAQ,UAAU;OAE3C,oCAAiC,+CAA+C;AAElF,UAAO"}
@@ -0,0 +1,15 @@
1
+ import * as webpack from "webpack";
2
+
3
+ //#region src/plugins/RemotePublicPathRuntimeModule.d.ts
4
+ declare const RuntimeModule: typeof webpack.RuntimeModule;
5
+ declare class AutoPublicPathRuntimeModule extends RuntimeModule {
6
+ private options;
7
+ constructor(options: any);
8
+ /**
9
+ * @returns {string} runtime code
10
+ */
11
+ generate(): string;
12
+ }
13
+ //#endregion
14
+ export { AutoPublicPathRuntimeModule as default };
15
+ //# sourceMappingURL=RemotePublicPathRuntimeModule.d.mts.map
@@ -1,10 +1,14 @@
1
- declare const RuntimeModule: typeof import("webpack").RuntimeModule;
1
+ import * as webpack from "webpack";
2
+
3
+ //#region src/plugins/RemotePublicPathRuntimeModule.d.ts
4
+ declare const RuntimeModule: typeof webpack.RuntimeModule;
2
5
  declare class AutoPublicPathRuntimeModule extends RuntimeModule {
3
- private options;
4
- constructor(options: any);
5
- /**
6
- * @returns {string} runtime code
7
- */
8
- generate(): string;
6
+ private options;
7
+ constructor(options: any);
8
+ /**
9
+ * @returns {string} runtime code
10
+ */
11
+ generate(): string;
9
12
  }
10
- export default AutoPublicPathRuntimeModule;
13
+ export = AutoPublicPathRuntimeModule;
14
+ //# sourceMappingURL=RemotePublicPathRuntimeModule.d.ts.map
@@ -1,33 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
4
- const { RuntimeGlobals, RuntimeModule, Template, javascript } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
5
- const { getUndoPath } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/identifier'));
6
- class AutoPublicPathRuntimeModule extends RuntimeModule {
7
- constructor(options) {
8
- super('publicPath', RuntimeModule.STAGE_BASIC + 1);
9
- this.options = options;
10
- }
11
- /**
12
- * @returns {string} runtime code
13
- */
14
- generate() {
15
- const { compilation } = this;
16
- const { scriptType, path, publicPath, importMetaName, uniqueName, chunkLoading,
17
- //@ts-ignore
18
- } = compilation.outputOptions;
19
- const getPath = () => compilation?.getPath(publicPath || '', {
20
- hash: compilation?.hash || 'XXXX',
21
- });
22
- const chunkName = compilation?.getPath(javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(this.chunk, compilation?.outputOptions), {
23
- chunk: this.chunk,
24
- contentHashType: 'javascript',
25
- });
26
- let undoPath = null;
27
- if (chunkName && path) {
28
- undoPath = getUndoPath(chunkName, path, false);
29
- }
30
- const getPathFromFederation = `
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
+ let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
4
+
5
+ //#region src/plugins/RemotePublicPathRuntimeModule.ts
6
+ const { RuntimeGlobals, RuntimeModule, Template, javascript } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
7
+ const { getUndoPath } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/identifier"));
8
+ var AutoPublicPathRuntimeModule = class extends RuntimeModule {
9
+ constructor(options) {
10
+ super("publicPath", RuntimeModule.STAGE_BASIC + 1);
11
+ this.options = options;
12
+ }
13
+ /**
14
+ * @returns {string} runtime code
15
+ */
16
+ generate() {
17
+ const { compilation } = this;
18
+ const { scriptType, path, publicPath, importMetaName, uniqueName, chunkLoading } = compilation.outputOptions;
19
+ const getPath = () => compilation?.getPath(publicPath || "", { hash: compilation?.hash || "XXXX" });
20
+ const currentChunk = this.chunk;
21
+ const chunkName = currentChunk && compilation?.getPath(javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(currentChunk, compilation?.outputOptions), {
22
+ chunk: currentChunk,
23
+ contentHashType: "javascript"
24
+ });
25
+ let undoPath = null;
26
+ if (chunkName && path) undoPath = getUndoPath(chunkName, path, false);
27
+ const getPathFromFederation = `
31
28
  function getPathFromFederation() {
32
29
  // Access the global federation manager or create a fallback object
33
30
  var federationManager = globalThis.__FEDERATION__ || {};
@@ -61,7 +58,7 @@ function getPathFromFederation() {
61
58
  return entryPath;
62
59
  }
63
60
  `;
64
- const definePropertyCode = `
61
+ const definePropertyCode = `
65
62
  Object.defineProperty(__webpack_require__, "p", {
66
63
  get: function() {
67
64
  var scriptUrl;
@@ -83,7 +80,7 @@ Object.defineProperty(__webpack_require__, "p", {
83
80
  } else if (typeof __filename !== "undefined") {
84
81
  scriptUrl = __filename;
85
82
  } else {
86
- scriptUrl = ${publicPath !== 'auto' ? JSON.stringify(getPath()) : 'undefined'};
83
+ scriptUrl = ${publicPath !== "auto" ? JSON.stringify(getPath()) : "undefined"};
87
84
  }
88
85
  }
89
86
  } else {
@@ -127,8 +124,10 @@ Object.defineProperty(__webpack_require__, "p", {
127
124
  }
128
125
  });
129
126
  `;
130
- return Template.asString([getPathFromFederation, definePropertyCode]);
131
- }
132
- }
127
+ return Template.asString([getPathFromFederation, definePropertyCode]);
128
+ }
129
+ };
130
+
131
+ //#endregion
133
132
  exports.default = AutoPublicPathRuntimeModule;
134
133
  //# sourceMappingURL=RemotePublicPathRuntimeModule.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RemotePublicPathRuntimeModule.js","sourceRoot":"","sources":["../../../src/plugins/RemotePublicPathRuntimeModule.ts"],"names":[],"mappings":";;AAAA,0FAAqF;AACrF,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CACrE,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAC9B,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAC7B,IAAA,6CAAoB,EAAC,6BAA6B,CAAC,CACJ,CAAC;AAElD,MAAM,2BAA4B,SAAQ,aAAa;IAGrD,YAAY,OAAY;QACtB,KAAK,CAAC,YAAY,EAAE,aAAa,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACM,QAAQ;QACf,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;QAC7B,MAAM,EACJ,UAAU,EACV,IAAI,EACJ,UAAU,EACV,cAAc,EACd,UAAU,EACV,YAAY;QACZ,YAAY;UACb,GAAG,WAAW,CAAC,aAAa,CAAC;QAE9B,MAAM,OAAO,GAAG,GAAG,EAAE,CACnB,WAAW,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE;YACrC,IAAI,EAAE,WAAW,EAAE,IAAI,IAAI,MAAM;SAClC,CAAC,CAAC;QAEL,MAAM,SAAS,GAAG,WAAW,EAAE,OAAO,CACpC,UAAU,CAAC,uBAAuB,CAAC,wBAAwB,CACzD,IAAI,CAAC,KAAK,EACV,WAAW,EAAE,aAAa,CAC3B,EACD;YACE,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,eAAe,EAAE,YAAY;SAC9B,CACF,CAAC;QAEF,IAAI,QAAQ,GAAkB,IAAI,CAAC;QACnC,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,QAAQ,GAAG,WAAW,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCjC,CAAC;QACE,MAAM,kBAAkB,GAAG;;;;;;uBAMR,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;yBACxB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;;;;;;mDAMF,cAAc,uBAAuB,cAAc;;;;;;;;;wBAU1F,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,WACtD;;;;;YAKE,cAAc,CAAC,MAAM;sBACX,cAAc,CAAC,MAAM;;uBAEpB,cAAc,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;wBAqBpB,IAAI,CAAC,SAAS,CAChC,QAAQ,CACT,kBAAkB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;CAc9C,CAAC;QAEE,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC,CAAC;IACxE,CAAC;CACF;AAED,kBAAe,2BAA2B,CAAC"}
1
+ {"version":3,"file":"RemotePublicPathRuntimeModule.js","names":[],"sources":["../../../src/plugins/RemotePublicPathRuntimeModule.ts"],"sourcesContent":["import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst { RuntimeGlobals, RuntimeModule, Template, javascript } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { getUndoPath } = require(\n normalizeWebpackPath('webpack/lib/util/identifier'),\n) as typeof import('webpack/lib/util/identifier');\n\nclass AutoPublicPathRuntimeModule extends RuntimeModule {\n private options: any;\n\n constructor(options: any) {\n super('publicPath', RuntimeModule.STAGE_BASIC + 1);\n this.options = options;\n }\n\n /**\n * @returns {string} runtime code\n */\n override generate() {\n const { compilation } = this;\n const {\n scriptType,\n path,\n publicPath,\n importMetaName,\n uniqueName,\n chunkLoading,\n //@ts-ignore\n } = compilation.outputOptions;\n\n const getPath = () =>\n compilation?.getPath(publicPath || '', {\n hash: compilation?.hash || 'XXXX',\n });\n\n const currentChunk = this.chunk;\n const chunkName =\n currentChunk &&\n compilation?.getPath(\n javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(\n currentChunk,\n compilation?.outputOptions,\n ),\n {\n chunk: currentChunk,\n contentHashType: 'javascript',\n },\n );\n\n let undoPath: string | null = null;\n if (chunkName && path) {\n undoPath = getUndoPath(chunkName, path, false);\n }\n\n const getPathFromFederation = `\nfunction getPathFromFederation() {\n // Access the global federation manager or create a fallback object\n var federationManager = globalThis.__FEDERATION__ || {};\n // Access the current Webpack instance's federation details or create a fallback object\n var instance = __webpack_require__.federation.instance || {};\n\n // Function to aggregate all known remote module paths\n var getAllKnownRemotes = function() {\n var found = {};\n // Iterate over all federation instances to collect module cache entries\n (federationManager.__INSTANCES__ || []).forEach((instance) => {\n if(instance){\n instance.moduleCache.forEach((value, key) => {\n found[key] = value;\n });\n }\n });\n return found;\n };\n\n // Retrieve the combined remote cache from all federation instances\n const combinedRemoteCache = getAllKnownRemotes();\n // Get the name of the current host from the instance\n const hostName = instance.name;\n // Find the path for the current host in the remote cache\n const foundPath = combinedRemoteCache[hostName];\n // If a path is not found, return undefined to indicate the absence of an entry path\n if (!foundPath) { return undefined; }\n // Return the entry path for the found remote module\n const entryPath = foundPath.remoteInfo.entry;\n return entryPath;\n}\n`;\n const definePropertyCode = `\nObject.defineProperty(__webpack_require__, \"p\", {\n get: function() {\n var scriptUrl;\n\n // Attempt to get the script URL based on the environment\n var scriptType = ${JSON.stringify(scriptType)};\n var chunkLoading = ${JSON.stringify(chunkLoading)};\n var isModuleEnvironment = ['module', 'node', 'async-node', 'require'].includes(scriptType) || chunkLoading;\n\n if (isModuleEnvironment) {\n try {\n // Use Function constructor to avoid direct reference to import.meta in environments that do not support it\n scriptUrl = (new Function('return typeof ${importMetaName}.url === \"string\" ? ${importMetaName}.url : undefined;'))();\n } catch (e) {\n // Handle cases where import.meta is not available or other errors occur\n var scriptPath = getPathFromFederation();\n if (scriptPath) {\n scriptUrl = scriptPath;\n } else if (typeof __filename !== \"undefined\") {\n scriptUrl = __filename;\n } else {\n scriptUrl = ${\n publicPath !== 'auto' ? JSON.stringify(getPath()) : 'undefined'\n };\n }\n }\n } else {\n // Fallback for non-module environments, such as browsers\n if (${RuntimeGlobals.global}.importScripts) {\n scriptUrl = ${RuntimeGlobals.global}.location + \"\";\n }\n var document = ${RuntimeGlobals.global}.document;\n if (!scriptUrl && document) {\n if (document.currentScript) {\n scriptUrl = document.currentScript.src;\n } else {\n var scripts = document.getElementsByTagName(\"script\");\n if (scripts.length) {\n scriptUrl = scripts[scripts.length - 1].src;\n }\n }\n }\n }\n\n if (!scriptUrl) {\n throw new Error(\"Unable to calculate automatic public path\");\n }\n\n // Clean up the script URL by removing any hash or query parameters\n scriptUrl = scriptUrl.replace(/#.*$/, \"\").replace(/\\\\?.*$/, \"\").replace(/\\\\/[^\\\\/]+$/, \"/\");\n\n // Apply any undo path that might be necessary for nested public paths\n var finalScript = ${JSON.stringify(\n undoPath,\n )} ? scriptUrl + ${JSON.stringify(undoPath)} : scriptUrl;\n\n // Helper function to ensure the URL has a protocol if it starts with '//'\n var addProtocol = function(url) {\n return url.startsWith('//') ? 'https:' + url : url;\n };\n\n // Set the global variable for the public path\n globalThis.currentVmokPublicPath = addProtocol(finalScript) || '/';\n\n // Return the final public path\n return finalScript\n }\n});\n`;\n\n return Template.asString([getPathFromFederation, definePropertyCode]);\n }\n}\n\nexport default AutoPublicPathRuntimeModule;\n"],"mappings":";;;;;AACA,MAAM,EAAE,gBAAgB,eAAe,UAAU,eAAe,gFACzC,UAAU,CAChC;AACD,MAAM,EAAE,gBAAgB,gFACD,8BAA8B,CACpD;AAED,IAAM,8BAAN,cAA0C,cAAc;CAGtD,YAAY,SAAc;AACxB,QAAM,cAAc,cAAc,cAAc,EAAE;AAClD,OAAK,UAAU;;;;;CAMjB,AAAS,WAAW;EAClB,MAAM,EAAE,gBAAgB;EACxB,MAAM,EACJ,YACA,MACA,YACA,gBACA,YACA,iBAEE,YAAY;EAEhB,MAAM,gBACJ,aAAa,QAAQ,cAAc,IAAI,EACrC,MAAM,aAAa,QAAQ,QAC5B,CAAC;EAEJ,MAAM,eAAe,KAAK;EAC1B,MAAM,YACJ,gBACA,aAAa,QACX,WAAW,wBAAwB,yBACjC,cACA,aAAa,cACd,EACD;GACE,OAAO;GACP,iBAAiB;GAClB,CACF;EAEH,IAAI,WAA0B;AAC9B,MAAI,aAAa,KACf,YAAW,YAAY,WAAW,MAAM,MAAM;EAGhD,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkC9B,MAAM,qBAAqB;;;;;;uBAMR,KAAK,UAAU,WAAW,CAAC;yBACzB,KAAK,UAAU,aAAa,CAAC;;;;;;mDAMH,eAAe,sBAAsB,eAAe;;;;;;;;;wBAU3F,eAAe,SAAS,KAAK,UAAU,SAAS,CAAC,GAAG,YACrD;;;;;YAKC,eAAe,OAAO;sBACZ,eAAe,OAAO;;uBAErB,eAAe,OAAO;;;;;;;;;;;;;;;;;;;;;wBAqBrB,KAAK,UACvB,SACD,CAAC,iBAAiB,KAAK,UAAU,SAAS,CAAC;;;;;;;;;;;;;;;AAgB5C,SAAO,SAAS,SAAS,CAAC,uBAAuB,mBAAmB,CAAC"}