@module-federation/node 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.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -0
  3. package/dist/_virtual/_rolldown/runtime.js +31 -0
  4. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  5. package/dist/plugins/ChunkCorrelationPlugin.js +308 -0
  6. package/dist/plugins/ChunkCorrelationPlugin.js.map +1 -0
  7. package/dist/plugins/ChunkCorrelationPlugin.mjs +305 -0
  8. package/dist/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
  9. package/dist/src/filesystem/stratagies.d.mts +21 -0
  10. package/dist/src/filesystem/stratagies.d.ts +21 -0
  11. package/dist/src/filesystem/stratagies.js +105 -0
  12. package/dist/src/filesystem/stratagies.js.map +1 -0
  13. package/dist/src/filesystem/stratagies.mjs +103 -0
  14. package/dist/src/filesystem/stratagies.mjs.map +1 -0
  15. package/dist/src/index.d.mts +8 -0
  16. package/dist/src/index.d.ts +8 -0
  17. package/dist/src/index.js +16 -0
  18. package/dist/src/index.mjs +9 -0
  19. package/dist/src/plugins/AutomaticPublicPathPlugin.d.mts +12 -0
  20. package/dist/src/plugins/AutomaticPublicPathPlugin.d.ts +11 -0
  21. package/dist/src/plugins/AutomaticPublicPathPlugin.js +29 -0
  22. package/dist/src/plugins/AutomaticPublicPathPlugin.js.map +1 -0
  23. package/dist/src/plugins/AutomaticPublicPathPlugin.mjs +28 -0
  24. package/dist/src/plugins/AutomaticPublicPathPlugin.mjs.map +1 -0
  25. package/dist/src/plugins/ChunkCorrelationPlugin.d.mts +5 -0
  26. package/dist/src/plugins/ChunkCorrelationPlugin.d.ts +4 -0
  27. package/dist/src/plugins/ChunkCorrelationPlugin.js +9 -0
  28. package/dist/src/plugins/ChunkCorrelationPlugin.js.map +1 -0
  29. package/dist/src/plugins/ChunkCorrelationPlugin.mjs +8 -0
  30. package/dist/src/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
  31. package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.mts +21 -0
  32. package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.ts +20 -0
  33. package/dist/src/plugins/CommonJsChunkLoadingPlugin.js +71 -0
  34. package/dist/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -0
  35. package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs +70 -0
  36. package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs.map +1 -0
  37. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.mts +46 -0
  38. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.ts +45 -0
  39. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +112 -0
  40. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -0
  41. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs +111 -0
  42. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs.map +1 -0
  43. package/dist/src/plugins/EntryChunkTrackerPlugin.d.mts +17 -0
  44. package/dist/src/plugins/EntryChunkTrackerPlugin.d.ts +17 -0
  45. package/dist/src/plugins/EntryChunkTrackerPlugin.js +39 -0
  46. package/dist/src/plugins/EntryChunkTrackerPlugin.js.map +1 -0
  47. package/dist/src/plugins/EntryChunkTrackerPlugin.mjs +38 -0
  48. package/dist/src/plugins/EntryChunkTrackerPlugin.mjs.map +1 -0
  49. package/dist/src/plugins/NodeFederationPlugin.d.mts +54 -0
  50. package/dist/src/plugins/NodeFederationPlugin.d.ts +53 -0
  51. package/dist/src/plugins/NodeFederationPlugin.js +76 -0
  52. package/dist/src/plugins/NodeFederationPlugin.js.map +1 -0
  53. package/dist/src/plugins/NodeFederationPlugin.mjs +73 -0
  54. package/dist/src/plugins/NodeFederationPlugin.mjs.map +1 -0
  55. package/dist/src/plugins/RemotePublicPathRuntimeModule.d.mts +15 -0
  56. package/dist/src/plugins/RemotePublicPathRuntimeModule.d.ts +14 -0
  57. package/dist/src/plugins/RemotePublicPathRuntimeModule.js +133 -0
  58. package/dist/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -0
  59. package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs +132 -0
  60. package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs.map +1 -0
  61. package/dist/src/plugins/StreamingTargetPlugin.d.mts +32 -0
  62. package/dist/src/plugins/StreamingTargetPlugin.d.ts +31 -0
  63. package/dist/src/plugins/StreamingTargetPlugin.js +46 -0
  64. package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -0
  65. package/dist/src/plugins/StreamingTargetPlugin.mjs +46 -0
  66. package/dist/src/plugins/StreamingTargetPlugin.mjs.map +1 -0
  67. package/dist/src/plugins/UniversalFederationPlugin.d.mts +49 -0
  68. package/dist/src/plugins/UniversalFederationPlugin.d.ts +48 -0
  69. package/dist/src/plugins/UniversalFederationPlugin.js +66 -0
  70. package/dist/src/plugins/UniversalFederationPlugin.js.map +1 -0
  71. package/dist/src/plugins/UniversalFederationPlugin.mjs +65 -0
  72. package/dist/src/plugins/UniversalFederationPlugin.mjs.map +1 -0
  73. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.mts +9 -0
  74. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.ts +8 -0
  75. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js +25 -0
  76. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js.map +1 -0
  77. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs +23 -0
  78. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs.map +1 -0
  79. package/dist/src/plugins/webpackChunkUtilities.d.mts +55 -0
  80. package/dist/src/plugins/webpackChunkUtilities.d.ts +55 -0
  81. package/dist/src/plugins/webpackChunkUtilities.js +242 -0
  82. package/dist/src/plugins/webpackChunkUtilities.js.map +1 -0
  83. package/dist/src/plugins/webpackChunkUtilities.mjs +234 -0
  84. package/dist/src/plugins/webpackChunkUtilities.mjs.map +1 -0
  85. package/dist/src/recordDynamicRemoteEntryHashPlugin.d.mts +7 -0
  86. package/dist/src/recordDynamicRemoteEntryHashPlugin.d.ts +6 -0
  87. package/dist/src/recordDynamicRemoteEntryHashPlugin.js +28 -0
  88. package/dist/src/recordDynamicRemoteEntryHashPlugin.js.map +1 -0
  89. package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs +26 -0
  90. package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs.map +1 -0
  91. package/dist/src/runtimePlugin.d.mts +27 -0
  92. package/dist/src/runtimePlugin.d.ts +27 -0
  93. package/dist/src/runtimePlugin.js +242 -0
  94. package/dist/src/runtimePlugin.js.map +1 -0
  95. package/dist/src/runtimePlugin.mjs +226 -0
  96. package/dist/src/runtimePlugin.mjs.map +1 -0
  97. package/dist/src/types/index.d.mts +8 -0
  98. package/dist/src/types/index.d.ts +8 -0
  99. package/dist/src/types/index.js +1 -0
  100. package/dist/src/types/index.mjs +1 -0
  101. package/dist/src/utils/flush-chunks.d.mts +15 -0
  102. package/dist/src/utils/flush-chunks.d.ts +15 -0
  103. package/dist/src/utils/flush-chunks.js +106 -0
  104. package/dist/src/utils/flush-chunks.js.map +1 -0
  105. package/dist/src/utils/flush-chunks.mjs +102 -0
  106. package/dist/src/utils/flush-chunks.mjs.map +1 -0
  107. package/dist/src/utils/hot-reload.d.mts +16 -0
  108. package/dist/src/utils/hot-reload.d.ts +16 -0
  109. package/dist/src/utils/hot-reload.js +206 -0
  110. package/dist/src/utils/hot-reload.js.map +1 -0
  111. package/dist/src/utils/hot-reload.mjs +195 -0
  112. package/dist/src/utils/hot-reload.mjs.map +1 -0
  113. package/dist/src/utils/index.d.mts +3 -0
  114. package/dist/src/utils/index.d.ts +3 -0
  115. package/dist/src/utils/index.js +15 -0
  116. package/dist/src/utils/index.mjs +4 -0
  117. package/package.json +135 -0
@@ -0,0 +1,133 @@
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 = `
28
+ function getPathFromFederation() {
29
+ // Access the global federation manager or create a fallback object
30
+ var federationManager = globalThis.__FEDERATION__ || {};
31
+ // Access the current Webpack instance's federation details or create a fallback object
32
+ var instance = __webpack_require__.federation.instance || {};
33
+
34
+ // Function to aggregate all known remote module paths
35
+ var getAllKnownRemotes = function() {
36
+ var found = {};
37
+ // Iterate over all federation instances to collect module cache entries
38
+ (federationManager.__INSTANCES__ || []).forEach((instance) => {
39
+ if(instance){
40
+ instance.moduleCache.forEach((value, key) => {
41
+ found[key] = value;
42
+ });
43
+ }
44
+ });
45
+ return found;
46
+ };
47
+
48
+ // Retrieve the combined remote cache from all federation instances
49
+ const combinedRemoteCache = getAllKnownRemotes();
50
+ // Get the name of the current host from the instance
51
+ const hostName = instance.name;
52
+ // Find the path for the current host in the remote cache
53
+ const foundPath = combinedRemoteCache[hostName];
54
+ // If a path is not found, return undefined to indicate the absence of an entry path
55
+ if (!foundPath) { return undefined; }
56
+ // Return the entry path for the found remote module
57
+ const entryPath = foundPath.remoteInfo.entry;
58
+ return entryPath;
59
+ }
60
+ `;
61
+ const definePropertyCode = `
62
+ Object.defineProperty(__webpack_require__, "p", {
63
+ get: function() {
64
+ var scriptUrl;
65
+
66
+ // Attempt to get the script URL based on the environment
67
+ var scriptType = ${JSON.stringify(scriptType)};
68
+ var chunkLoading = ${JSON.stringify(chunkLoading)};
69
+ var isModuleEnvironment = ['module', 'node', 'async-node', 'require'].includes(scriptType) || chunkLoading;
70
+
71
+ if (isModuleEnvironment) {
72
+ try {
73
+ // Use Function constructor to avoid direct reference to import.meta in environments that do not support it
74
+ scriptUrl = (new Function('return typeof ${importMetaName}.url === "string" ? ${importMetaName}.url : undefined;'))();
75
+ } catch (e) {
76
+ // Handle cases where import.meta is not available or other errors occur
77
+ var scriptPath = getPathFromFederation();
78
+ if (scriptPath) {
79
+ scriptUrl = scriptPath;
80
+ } else if (typeof __filename !== "undefined") {
81
+ scriptUrl = __filename;
82
+ } else {
83
+ scriptUrl = ${publicPath !== "auto" ? JSON.stringify(getPath()) : "undefined"};
84
+ }
85
+ }
86
+ } else {
87
+ // Fallback for non-module environments, such as browsers
88
+ if (${RuntimeGlobals.global}.importScripts) {
89
+ scriptUrl = ${RuntimeGlobals.global}.location + "";
90
+ }
91
+ var document = ${RuntimeGlobals.global}.document;
92
+ if (!scriptUrl && document) {
93
+ if (document.currentScript) {
94
+ scriptUrl = document.currentScript.src;
95
+ } else {
96
+ var scripts = document.getElementsByTagName("script");
97
+ if (scripts.length) {
98
+ scriptUrl = scripts[scripts.length - 1].src;
99
+ }
100
+ }
101
+ }
102
+ }
103
+
104
+ if (!scriptUrl) {
105
+ throw new Error("Unable to calculate automatic public path");
106
+ }
107
+
108
+ // Clean up the script URL by removing any hash or query parameters
109
+ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\\?.*$/, "").replace(/\\/[^\\/]+$/, "/");
110
+
111
+ // Apply any undo path that might be necessary for nested public paths
112
+ var finalScript = ${JSON.stringify(undoPath)} ? scriptUrl + ${JSON.stringify(undoPath)} : scriptUrl;
113
+
114
+ // Helper function to ensure the URL has a protocol if it starts with '//'
115
+ var addProtocol = function(url) {
116
+ return url.startsWith('//') ? 'https:' + url : url;
117
+ };
118
+
119
+ // Set the global variable for the public path
120
+ globalThis.currentVmokPublicPath = addProtocol(finalScript) || '/';
121
+
122
+ // Return the final public path
123
+ return finalScript
124
+ }
125
+ });
126
+ `;
127
+ return Template.asString([getPathFromFederation, definePropertyCode]);
128
+ }
129
+ };
130
+
131
+ //#endregion
132
+ exports.default = AutoPublicPathRuntimeModule;
133
+ //# sourceMappingURL=RemotePublicPathRuntimeModule.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,132 @@
1
+ import { __require } from "../../_virtual/_rolldown/runtime.mjs";
2
+ import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
3
+
4
+ //#region src/plugins/RemotePublicPathRuntimeModule.ts
5
+ const { RuntimeGlobals, RuntimeModule, Template, javascript } = __require(normalizeWebpackPath("webpack"));
6
+ const { getUndoPath } = __require(normalizeWebpackPath("webpack/lib/util/identifier"));
7
+ var AutoPublicPathRuntimeModule = class extends RuntimeModule {
8
+ constructor(options) {
9
+ super("publicPath", RuntimeModule.STAGE_BASIC + 1);
10
+ this.options = options;
11
+ }
12
+ /**
13
+ * @returns {string} runtime code
14
+ */
15
+ generate() {
16
+ const { compilation } = this;
17
+ const { scriptType, path, publicPath, importMetaName, uniqueName, chunkLoading } = compilation.outputOptions;
18
+ const getPath = () => compilation?.getPath(publicPath || "", { hash: compilation?.hash || "XXXX" });
19
+ const currentChunk = this.chunk;
20
+ const chunkName = currentChunk && compilation?.getPath(javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(currentChunk, compilation?.outputOptions), {
21
+ chunk: currentChunk,
22
+ contentHashType: "javascript"
23
+ });
24
+ let undoPath = null;
25
+ if (chunkName && path) undoPath = getUndoPath(chunkName, path, false);
26
+ const getPathFromFederation = `
27
+ function getPathFromFederation() {
28
+ // Access the global federation manager or create a fallback object
29
+ var federationManager = globalThis.__FEDERATION__ || {};
30
+ // Access the current Webpack instance's federation details or create a fallback object
31
+ var instance = __webpack_require__.federation.instance || {};
32
+
33
+ // Function to aggregate all known remote module paths
34
+ var getAllKnownRemotes = function() {
35
+ var found = {};
36
+ // Iterate over all federation instances to collect module cache entries
37
+ (federationManager.__INSTANCES__ || []).forEach((instance) => {
38
+ if(instance){
39
+ instance.moduleCache.forEach((value, key) => {
40
+ found[key] = value;
41
+ });
42
+ }
43
+ });
44
+ return found;
45
+ };
46
+
47
+ // Retrieve the combined remote cache from all federation instances
48
+ const combinedRemoteCache = getAllKnownRemotes();
49
+ // Get the name of the current host from the instance
50
+ const hostName = instance.name;
51
+ // Find the path for the current host in the remote cache
52
+ const foundPath = combinedRemoteCache[hostName];
53
+ // If a path is not found, return undefined to indicate the absence of an entry path
54
+ if (!foundPath) { return undefined; }
55
+ // Return the entry path for the found remote module
56
+ const entryPath = foundPath.remoteInfo.entry;
57
+ return entryPath;
58
+ }
59
+ `;
60
+ const definePropertyCode = `
61
+ Object.defineProperty(__webpack_require__, "p", {
62
+ get: function() {
63
+ var scriptUrl;
64
+
65
+ // Attempt to get the script URL based on the environment
66
+ var scriptType = ${JSON.stringify(scriptType)};
67
+ var chunkLoading = ${JSON.stringify(chunkLoading)};
68
+ var isModuleEnvironment = ['module', 'node', 'async-node', 'require'].includes(scriptType) || chunkLoading;
69
+
70
+ if (isModuleEnvironment) {
71
+ try {
72
+ // Use Function constructor to avoid direct reference to import.meta in environments that do not support it
73
+ scriptUrl = (new Function('return typeof ${importMetaName}.url === "string" ? ${importMetaName}.url : undefined;'))();
74
+ } catch (e) {
75
+ // Handle cases where import.meta is not available or other errors occur
76
+ var scriptPath = getPathFromFederation();
77
+ if (scriptPath) {
78
+ scriptUrl = scriptPath;
79
+ } else if (typeof __filename !== "undefined") {
80
+ scriptUrl = __filename;
81
+ } else {
82
+ scriptUrl = ${publicPath !== "auto" ? JSON.stringify(getPath()) : "undefined"};
83
+ }
84
+ }
85
+ } else {
86
+ // Fallback for non-module environments, such as browsers
87
+ if (${RuntimeGlobals.global}.importScripts) {
88
+ scriptUrl = ${RuntimeGlobals.global}.location + "";
89
+ }
90
+ var document = ${RuntimeGlobals.global}.document;
91
+ if (!scriptUrl && document) {
92
+ if (document.currentScript) {
93
+ scriptUrl = document.currentScript.src;
94
+ } else {
95
+ var scripts = document.getElementsByTagName("script");
96
+ if (scripts.length) {
97
+ scriptUrl = scripts[scripts.length - 1].src;
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ if (!scriptUrl) {
104
+ throw new Error("Unable to calculate automatic public path");
105
+ }
106
+
107
+ // Clean up the script URL by removing any hash or query parameters
108
+ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\\?.*$/, "").replace(/\\/[^\\/]+$/, "/");
109
+
110
+ // Apply any undo path that might be necessary for nested public paths
111
+ var finalScript = ${JSON.stringify(undoPath)} ? scriptUrl + ${JSON.stringify(undoPath)} : scriptUrl;
112
+
113
+ // Helper function to ensure the URL has a protocol if it starts with '//'
114
+ var addProtocol = function(url) {
115
+ return url.startsWith('//') ? 'https:' + url : url;
116
+ };
117
+
118
+ // Set the global variable for the public path
119
+ globalThis.currentVmokPublicPath = addProtocol(finalScript) || '/';
120
+
121
+ // Return the final public path
122
+ return finalScript
123
+ }
124
+ });
125
+ `;
126
+ return Template.asString([getPathFromFederation, definePropertyCode]);
127
+ }
128
+ };
129
+
130
+ //#endregion
131
+ export { AutoPublicPathRuntimeModule as default };
132
+ //# sourceMappingURL=RemotePublicPathRuntimeModule.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemotePublicPathRuntimeModule.mjs","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,yBAC/C,qBAAqB,UAAU,CAChC;AACD,MAAM,EAAE,0BACN,qBAAqB,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"}
@@ -0,0 +1,32 @@
1
+ import { ModuleFederationPluginOptions } from "../types/index.mjs";
2
+ import { Compiler, WebpackPluginInstance } from "webpack";
3
+
4
+ //#region src/plugins/StreamingTargetPlugin.d.ts
5
+ /**
6
+ * Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions
7
+ * @property {string} promiseBaseURI - The base URI for the promise
8
+ * @property {boolean} debug - Flag to enable/disable debug mode
9
+ */
10
+ interface StreamingTargetOptions extends ModuleFederationPluginOptions {
11
+ promiseBaseURI?: string;
12
+ debug?: boolean;
13
+ }
14
+ /**
15
+ * Class representing a StreamingTargetPlugin
16
+ */
17
+ declare class StreamingTargetPlugin implements WebpackPluginInstance {
18
+ private options;
19
+ /**
20
+ * Create a StreamingTargetPlugin
21
+ * @param {StreamingTargetOptions} options - The options for the plugin
22
+ */
23
+ constructor(options: StreamingTargetOptions);
24
+ /**
25
+ * Apply the plugin to the compiler
26
+ * @param {Compiler} compiler - The webpack compiler
27
+ */
28
+ apply(compiler: Compiler): void;
29
+ }
30
+ //#endregion
31
+ export { StreamingTargetPlugin as default };
32
+ //# sourceMappingURL=StreamingTargetPlugin.d.mts.map
@@ -0,0 +1,31 @@
1
+ import { ModuleFederationPluginOptions } from "../types/index.js";
2
+ import { Compiler, WebpackPluginInstance } from "webpack";
3
+
4
+ //#region src/plugins/StreamingTargetPlugin.d.ts
5
+ /**
6
+ * Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions
7
+ * @property {string} promiseBaseURI - The base URI for the promise
8
+ * @property {boolean} debug - Flag to enable/disable debug mode
9
+ */
10
+ interface StreamingTargetOptions extends ModuleFederationPluginOptions {
11
+ promiseBaseURI?: string;
12
+ debug?: boolean;
13
+ }
14
+ /**
15
+ * Class representing a StreamingTargetPlugin
16
+ */
17
+ declare class StreamingTargetPlugin implements WebpackPluginInstance {
18
+ private options;
19
+ /**
20
+ * Create a StreamingTargetPlugin
21
+ * @param {StreamingTargetOptions} options - The options for the plugin
22
+ */
23
+ constructor(options: StreamingTargetOptions);
24
+ /**
25
+ * Apply the plugin to the compiler
26
+ * @param {Compiler} compiler - The webpack compiler
27
+ */
28
+ apply(compiler: Compiler): void;
29
+ }
30
+ export = StreamingTargetPlugin;
31
+ //# sourceMappingURL=StreamingTargetPlugin.d.ts.map
@@ -0,0 +1,46 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_src_plugins_CommonJsChunkLoadingPlugin = require('./CommonJsChunkLoadingPlugin.js');
3
+
4
+ //#region src/plugins/StreamingTargetPlugin.ts
5
+ /**
6
+ * Class representing a StreamingTargetPlugin
7
+ */
8
+ var StreamingTargetPlugin = class {
9
+ /**
10
+ * Create a StreamingTargetPlugin
11
+ * @param {StreamingTargetOptions} options - The options for the plugin
12
+ */
13
+ constructor(options) {
14
+ this.options = options || {};
15
+ }
16
+ /**
17
+ * Apply the plugin to the compiler
18
+ * @param {Compiler} compiler - The webpack compiler
19
+ */
20
+ apply(compiler) {
21
+ const { webpack } = compiler;
22
+ compiler.options.output.chunkFormat = "commonjs";
23
+ if (compiler.options.output.enabledLibraryTypes === void 0) compiler.options.output.enabledLibraryTypes = ["commonjs-module"];
24
+ else compiler.options.output.enabledLibraryTypes.push("commonjs-module");
25
+ compiler.options.output.chunkLoading = "async-node";
26
+ compiler.options.output.enabledChunkLoadingTypes = [];
27
+ compiler.options.output.environment = {
28
+ ...compiler.options.output.environment,
29
+ dynamicImport: true
30
+ };
31
+ new (webpack?.node?.NodeEnvironmentPlugin || (require("webpack/lib/node/NodeEnvironmentPlugin")))({ infrastructureLogging: compiler.options.infrastructureLogging }).apply(compiler);
32
+ new (webpack?.node?.NodeTargetPlugin || (require("webpack/lib/node/NodeTargetPlugin")))().apply(compiler);
33
+ new require_src_plugins_CommonJsChunkLoadingPlugin.default({
34
+ asyncChunkLoading: true,
35
+ name: this.options.name,
36
+ remotes: this.options.remotes,
37
+ baseURI: compiler.options.output.publicPath,
38
+ promiseBaseURI: this.options.promiseBaseURI,
39
+ debug: this.options.debug
40
+ }).apply(compiler);
41
+ }
42
+ };
43
+
44
+ //#endregion
45
+ exports.default = StreamingTargetPlugin;
46
+ //# sourceMappingURL=StreamingTargetPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamingTargetPlugin.js","names":["CommonJsChunkLoadingPlugin"],"sources":["../../../src/plugins/StreamingTargetPlugin.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\n\nimport CommonJsChunkLoadingPlugin from './CommonJsChunkLoadingPlugin';\n\n/**\n * Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions\n * @property {string} promiseBaseURI - The base URI for the promise\n * @property {boolean} debug - Flag to enable/disable debug mode\n */\ninterface StreamingTargetOptions extends ModuleFederationPluginOptions {\n promiseBaseURI?: string;\n debug?: boolean;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\n/**\n * Interface for StreamingTargetContext\n */\ninterface StreamingTargetContext {}\n\n/**\n * Class representing a StreamingTargetPlugin\n */\nclass StreamingTargetPlugin implements WebpackPluginInstance {\n private options: StreamingTargetOptions;\n\n /**\n * Create a StreamingTargetPlugin\n * @param {StreamingTargetOptions} options - The options for the plugin\n */\n constructor(options: StreamingTargetOptions) {\n this.options = options || {};\n }\n\n /**\n * Apply the plugin to the compiler\n * @param {Compiler} compiler - The webpack compiler\n */\n apply(compiler: Compiler) {\n // When used with Next.js, context is needed to use Next.js webpack\n const { webpack } = compiler;\n\n compiler.options.output.chunkFormat = 'commonjs';\n if (compiler.options.output.enabledLibraryTypes === undefined) {\n compiler.options.output.enabledLibraryTypes = ['commonjs-module'];\n } else {\n compiler.options.output.enabledLibraryTypes.push('commonjs-module');\n }\n\n compiler.options.output.chunkLoading = 'async-node';\n\n // Disable default config\n // FIXME: enabledChunkLoadingTypes is of type 'string[] | undefined'\n // Can't use the 'false' value as it isn't the right format,\n // Emptying it out ensures theres no other readFileVm added to webpack runtime\n compiler.options.output.enabledChunkLoadingTypes = [];\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n dynamicImport: true,\n };\n\n new (\n webpack?.node?.NodeEnvironmentPlugin ||\n require('webpack/lib/node/NodeEnvironmentPlugin')\n )({\n infrastructureLogging: compiler.options.infrastructureLogging,\n }).apply(compiler);\n\n new (\n webpack?.node?.NodeTargetPlugin ||\n require('webpack/lib/node/NodeTargetPlugin')\n )().apply(compiler);\n new CommonJsChunkLoadingPlugin({\n asyncChunkLoading: true,\n name: this.options.name,\n remotes: this.options.remotes as Record<string, string>,\n baseURI: compiler.options.output.publicPath,\n promiseBaseURI: this.options.promiseBaseURI,\n debug: this.options.debug,\n }).apply(compiler);\n }\n}\n\nexport default StreamingTargetPlugin;\n"],"mappings":";;;;;;;AAwBA,IAAM,wBAAN,MAA6D;;;;;CAO3D,YAAY,SAAiC;AAC3C,OAAK,UAAU,WAAW,EAAE;;;;;;CAO9B,MAAM,UAAoB;EAExB,MAAM,EAAE,YAAY;AAEpB,WAAS,QAAQ,OAAO,cAAc;AACtC,MAAI,SAAS,QAAQ,OAAO,wBAAwB,OAClD,UAAS,QAAQ,OAAO,sBAAsB,CAAC,kBAAkB;MAEjE,UAAS,QAAQ,OAAO,oBAAoB,KAAK,kBAAkB;AAGrE,WAAS,QAAQ,OAAO,eAAe;AAMvC,WAAS,QAAQ,OAAO,2BAA2B,EAAE;AACrD,WAAS,QAAQ,OAAO,cAAc;GACpC,GAAG,SAAS,QAAQ,OAAO;GAC3B,eAAe;GAChB;AAED,OACE,SAAS,MAAM,0BACf,QAAQ,yCAAyC,GACjD,EACA,uBAAuB,SAAS,QAAQ,uBACzC,CAAC,CAAC,MAAM,SAAS;AAElB,OACE,SAAS,MAAM,qBACf,QAAQ,oCAAoC,IAC3C,CAAC,MAAM,SAAS;AACnB,MAAIA,uDAA2B;GAC7B,mBAAmB;GACnB,MAAM,KAAK,QAAQ;GACnB,SAAS,KAAK,QAAQ;GACtB,SAAS,SAAS,QAAQ,OAAO;GACjC,gBAAgB,KAAK,QAAQ;GAC7B,OAAO,KAAK,QAAQ;GACrB,CAAC,CAAC,MAAM,SAAS"}
@@ -0,0 +1,46 @@
1
+ import { __require } from "../../_virtual/_rolldown/runtime.mjs";
2
+ import DynamicFilesystemChunkLoadingPlugin from "./CommonJsChunkLoadingPlugin.mjs";
3
+
4
+ //#region src/plugins/StreamingTargetPlugin.ts
5
+ /**
6
+ * Class representing a StreamingTargetPlugin
7
+ */
8
+ var StreamingTargetPlugin = class {
9
+ /**
10
+ * Create a StreamingTargetPlugin
11
+ * @param {StreamingTargetOptions} options - The options for the plugin
12
+ */
13
+ constructor(options) {
14
+ this.options = options || {};
15
+ }
16
+ /**
17
+ * Apply the plugin to the compiler
18
+ * @param {Compiler} compiler - The webpack compiler
19
+ */
20
+ apply(compiler) {
21
+ const { webpack } = compiler;
22
+ compiler.options.output.chunkFormat = "commonjs";
23
+ if (compiler.options.output.enabledLibraryTypes === void 0) compiler.options.output.enabledLibraryTypes = ["commonjs-module"];
24
+ else compiler.options.output.enabledLibraryTypes.push("commonjs-module");
25
+ compiler.options.output.chunkLoading = "async-node";
26
+ compiler.options.output.enabledChunkLoadingTypes = [];
27
+ compiler.options.output.environment = {
28
+ ...compiler.options.output.environment,
29
+ dynamicImport: true
30
+ };
31
+ new (webpack?.node?.NodeEnvironmentPlugin || (__require("webpack/lib/node/NodeEnvironmentPlugin")))({ infrastructureLogging: compiler.options.infrastructureLogging }).apply(compiler);
32
+ new (webpack?.node?.NodeTargetPlugin || (__require("webpack/lib/node/NodeTargetPlugin")))().apply(compiler);
33
+ new DynamicFilesystemChunkLoadingPlugin({
34
+ asyncChunkLoading: true,
35
+ name: this.options.name,
36
+ remotes: this.options.remotes,
37
+ baseURI: compiler.options.output.publicPath,
38
+ promiseBaseURI: this.options.promiseBaseURI,
39
+ debug: this.options.debug
40
+ }).apply(compiler);
41
+ }
42
+ };
43
+
44
+ //#endregion
45
+ export { StreamingTargetPlugin as default };
46
+ //# sourceMappingURL=StreamingTargetPlugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamingTargetPlugin.mjs","names":["CommonJsChunkLoadingPlugin"],"sources":["../../../src/plugins/StreamingTargetPlugin.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\n\nimport CommonJsChunkLoadingPlugin from './CommonJsChunkLoadingPlugin';\n\n/**\n * Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions\n * @property {string} promiseBaseURI - The base URI for the promise\n * @property {boolean} debug - Flag to enable/disable debug mode\n */\ninterface StreamingTargetOptions extends ModuleFederationPluginOptions {\n promiseBaseURI?: string;\n debug?: boolean;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\n/**\n * Interface for StreamingTargetContext\n */\ninterface StreamingTargetContext {}\n\n/**\n * Class representing a StreamingTargetPlugin\n */\nclass StreamingTargetPlugin implements WebpackPluginInstance {\n private options: StreamingTargetOptions;\n\n /**\n * Create a StreamingTargetPlugin\n * @param {StreamingTargetOptions} options - The options for the plugin\n */\n constructor(options: StreamingTargetOptions) {\n this.options = options || {};\n }\n\n /**\n * Apply the plugin to the compiler\n * @param {Compiler} compiler - The webpack compiler\n */\n apply(compiler: Compiler) {\n // When used with Next.js, context is needed to use Next.js webpack\n const { webpack } = compiler;\n\n compiler.options.output.chunkFormat = 'commonjs';\n if (compiler.options.output.enabledLibraryTypes === undefined) {\n compiler.options.output.enabledLibraryTypes = ['commonjs-module'];\n } else {\n compiler.options.output.enabledLibraryTypes.push('commonjs-module');\n }\n\n compiler.options.output.chunkLoading = 'async-node';\n\n // Disable default config\n // FIXME: enabledChunkLoadingTypes is of type 'string[] | undefined'\n // Can't use the 'false' value as it isn't the right format,\n // Emptying it out ensures theres no other readFileVm added to webpack runtime\n compiler.options.output.enabledChunkLoadingTypes = [];\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n dynamicImport: true,\n };\n\n new (\n webpack?.node?.NodeEnvironmentPlugin ||\n require('webpack/lib/node/NodeEnvironmentPlugin')\n )({\n infrastructureLogging: compiler.options.infrastructureLogging,\n }).apply(compiler);\n\n new (\n webpack?.node?.NodeTargetPlugin ||\n require('webpack/lib/node/NodeTargetPlugin')\n )().apply(compiler);\n new CommonJsChunkLoadingPlugin({\n asyncChunkLoading: true,\n name: this.options.name,\n remotes: this.options.remotes as Record<string, string>,\n baseURI: compiler.options.output.publicPath,\n promiseBaseURI: this.options.promiseBaseURI,\n debug: this.options.debug,\n }).apply(compiler);\n }\n}\n\nexport default StreamingTargetPlugin;\n"],"mappings":";;;;;;;AAwBA,IAAM,wBAAN,MAA6D;;;;;CAO3D,YAAY,SAAiC;AAC3C,OAAK,UAAU,WAAW,EAAE;;;;;;CAO9B,MAAM,UAAoB;EAExB,MAAM,EAAE,YAAY;AAEpB,WAAS,QAAQ,OAAO,cAAc;AACtC,MAAI,SAAS,QAAQ,OAAO,wBAAwB,OAClD,UAAS,QAAQ,OAAO,sBAAsB,CAAC,kBAAkB;MAEjE,UAAS,QAAQ,OAAO,oBAAoB,KAAK,kBAAkB;AAGrE,WAAS,QAAQ,OAAO,eAAe;AAMvC,WAAS,QAAQ,OAAO,2BAA2B,EAAE;AACrD,WAAS,QAAQ,OAAO,cAAc;GACpC,GAAG,SAAS,QAAQ,OAAO;GAC3B,eAAe;GAChB;AAED,OACE,SAAS,MAAM,oCACP,yCAAyC,GACjD,EACA,uBAAuB,SAAS,QAAQ,uBACzC,CAAC,CAAC,MAAM,SAAS;AAElB,OACE,SAAS,MAAM,+BACP,oCAAoC,IAC3C,CAAC,MAAM,SAAS;AACnB,MAAIA,oCAA2B;GAC7B,mBAAmB;GACnB,MAAM,KAAK,QAAQ;GACnB,SAAS,KAAK,QAAQ;GACtB,SAAS,SAAS,QAAQ,OAAO;GACjC,gBAAgB,KAAK,QAAQ;GAC7B,OAAO,KAAK,QAAQ;GACrB,CAAC,CAAC,MAAM,SAAS"}
@@ -0,0 +1,49 @@
1
+ import { ModuleFederationPluginOptions } from "../types/index.mjs";
2
+ import { Compiler, container } from "webpack";
3
+
4
+ //#region src/plugins/UniversalFederationPlugin.d.ts
5
+ /**
6
+ * Interface for NodeFederationOptions
7
+ * @property {boolean} isServer - Indicates if the server is running
8
+ * @property {string} [promiseBaseURI] - The base URI for the promise
9
+ * @property {boolean} [debug] - Indicates if debug mode is enabled
10
+ */
11
+ interface NodeFederationOptions extends ModuleFederationPluginOptions {
12
+ isServer: boolean;
13
+ promiseBaseURI?: string;
14
+ debug?: boolean;
15
+ useRuntimePlugin?: boolean;
16
+ }
17
+ /**
18
+ * Interface for NodeFederationContext
19
+ * @property {typeof container.ModuleFederationPlugin} [ModuleFederationPlugin] - The ModuleFederationPlugin from webpack container
20
+ */
21
+ interface NodeFederationContext {
22
+ ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
23
+ }
24
+ /**
25
+ * Class representing a UniversalFederationPlugin
26
+ */
27
+ declare class UniversalFederationPlugin {
28
+ private _options;
29
+ private context;
30
+ private name;
31
+ /**
32
+ * Create a UniversalFederationPlugin
33
+ * @param {NodeFederationOptions} options - The options for the plugin
34
+ * @param {NodeFederationContext} context - The context for the plugin
35
+ */
36
+ constructor(options: NodeFederationOptions, context: NodeFederationContext);
37
+ private updateCompilerOptions;
38
+ /**
39
+ * Apply the plugin to the compiler
40
+ * @param {Compiler} compiler - The webpack compiler
41
+ */
42
+ apply(compiler: Compiler): void;
43
+ }
44
+ /**
45
+ * Exporting UniversalFederationPlugin as default
46
+ */
47
+ //#endregion
48
+ export { UniversalFederationPlugin as default };
49
+ //# sourceMappingURL=UniversalFederationPlugin.d.mts.map
@@ -0,0 +1,48 @@
1
+ import { ModuleFederationPluginOptions } from "../types/index.js";
2
+ import { Compiler, container } from "webpack";
3
+
4
+ //#region src/plugins/UniversalFederationPlugin.d.ts
5
+ /**
6
+ * Interface for NodeFederationOptions
7
+ * @property {boolean} isServer - Indicates if the server is running
8
+ * @property {string} [promiseBaseURI] - The base URI for the promise
9
+ * @property {boolean} [debug] - Indicates if debug mode is enabled
10
+ */
11
+ interface NodeFederationOptions extends ModuleFederationPluginOptions {
12
+ isServer: boolean;
13
+ promiseBaseURI?: string;
14
+ debug?: boolean;
15
+ useRuntimePlugin?: boolean;
16
+ }
17
+ /**
18
+ * Interface for NodeFederationContext
19
+ * @property {typeof container.ModuleFederationPlugin} [ModuleFederationPlugin] - The ModuleFederationPlugin from webpack container
20
+ */
21
+ interface NodeFederationContext {
22
+ ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
23
+ }
24
+ /**
25
+ * Class representing a UniversalFederationPlugin
26
+ */
27
+ declare class UniversalFederationPlugin {
28
+ private _options;
29
+ private context;
30
+ private name;
31
+ /**
32
+ * Create a UniversalFederationPlugin
33
+ * @param {NodeFederationOptions} options - The options for the plugin
34
+ * @param {NodeFederationContext} context - The context for the plugin
35
+ */
36
+ constructor(options: NodeFederationOptions, context: NodeFederationContext);
37
+ private updateCompilerOptions;
38
+ /**
39
+ * Apply the plugin to the compiler
40
+ * @param {Compiler} compiler - The webpack compiler
41
+ */
42
+ apply(compiler: Compiler): void;
43
+ }
44
+ /**
45
+ * Exporting UniversalFederationPlugin as default
46
+ */
47
+ export = UniversalFederationPlugin;
48
+ //# sourceMappingURL=UniversalFederationPlugin.d.ts.map
@@ -0,0 +1,66 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
+ const require_src_plugins_StreamingTargetPlugin = require('./StreamingTargetPlugin.js');
4
+ const require_src_plugins_NodeFederationPlugin = require('./NodeFederationPlugin.js');
5
+ let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
6
+ let _module_federation_enhanced_webpack = require("@module-federation/enhanced/webpack");
7
+
8
+ //#region src/plugins/UniversalFederationPlugin.ts
9
+ /**
10
+ * Importing necessary plugins and types
11
+ */
12
+ const resolveRuntimePluginPath = () => require.resolve("../runtimePlugin.js");
13
+ /**
14
+ * Class representing a UniversalFederationPlugin
15
+ */
16
+ var UniversalFederationPlugin = class {
17
+ /**
18
+ * Create a UniversalFederationPlugin
19
+ * @param {NodeFederationOptions} options - The options for the plugin
20
+ * @param {NodeFederationContext} context - The context for the plugin
21
+ */
22
+ constructor(options, context) {
23
+ this._options = options || {};
24
+ this.context = context || {};
25
+ this.name = "ModuleFederationPlugin";
26
+ if (this._options.useRuntimePlugin && this._options.isServer) {
27
+ const runtimePluginPath = resolveRuntimePluginPath();
28
+ this._options.runtimePlugins = this._options.runtimePlugins ? this._options.runtimePlugins.concat([runtimePluginPath]) : [runtimePluginPath];
29
+ }
30
+ }
31
+ updateCompilerOptions(compiler) {
32
+ compiler.options.output.chunkFormat = "commonjs";
33
+ if (compiler.options.output.enabledLibraryTypes === void 0) compiler.options.output.enabledLibraryTypes = ["commonjs-module"];
34
+ else compiler.options.output.enabledLibraryTypes.push("commonjs-module");
35
+ const chunkFileName = compiler.options?.output?.chunkFilename;
36
+ const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
37
+ if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
38
+ const suffix = `-[contenthash].js`;
39
+ compiler.options.output.chunkFilename = chunkFileName.replace(".js", suffix);
40
+ }
41
+ }
42
+ /**
43
+ * Apply the plugin to the compiler
44
+ * @param {Compiler} compiler - The webpack compiler
45
+ */
46
+ apply(compiler) {
47
+ const { isServer, debug, useRuntimePlugin, ...options } = this._options;
48
+ const { webpack } = compiler;
49
+ if (!process.env["FEDERATION_WEBPACK_PATH"]) process.env["FEDERATION_WEBPACK_PATH"] = (0, _module_federation_sdk_normalize_webpack_path.getWebpackPath)(compiler);
50
+ if (isServer || compiler.options.name === "server" || compiler.options.target === "node" || compiler.options.target === "async-node") if (useRuntimePlugin) {
51
+ this.updateCompilerOptions(compiler);
52
+ new _module_federation_enhanced_webpack.ModuleFederationPlugin({ ...options }).apply(compiler);
53
+ } else {
54
+ new require_src_plugins_NodeFederationPlugin.default(options, this.context).apply(compiler);
55
+ new require_src_plugins_StreamingTargetPlugin.default({
56
+ ...options,
57
+ debug
58
+ }).apply(compiler);
59
+ }
60
+ else new _module_federation_enhanced_webpack.ModuleFederationPlugin(options).apply(compiler);
61
+ }
62
+ };
63
+
64
+ //#endregion
65
+ exports.default = UniversalFederationPlugin;
66
+ //# sourceMappingURL=UniversalFederationPlugin.js.map