@module-federation/node 0.0.0-perf-devtools-20260107043700 → 0.0.0-perf-website-code-usage-20260914033703

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 (128) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +31 -0
  2. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  3. package/dist/node_modules/.pnpm/webpack@5.104.1_@swc_core@1.7.26_@swc_helpers@0.5.13__esbuild@0.28.1_webpack-cli@5.1.4/node_modules/webpack/types.d.mts +1 -0
  4. package/dist/node_modules/.pnpm/webpack@5.104.1_@swc_core@1.7.26_@swc_helpers@0.5.13__esbuild@0.28.1_webpack-cli@5.1.4/node_modules/webpack/types.d.ts +1 -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/plugins/createBundlerLogger.js +9 -0
  10. package/dist/plugins/createBundlerLogger.js.map +1 -0
  11. package/dist/plugins/createBundlerLogger.mjs +8 -0
  12. package/dist/plugins/createBundlerLogger.mjs.map +1 -0
  13. package/dist/src/filesystem/stratagies.d.mts +21 -0
  14. package/dist/src/filesystem/stratagies.d.ts +10 -7
  15. package/dist/src/filesystem/stratagies.js +97 -116
  16. package/dist/src/filesystem/stratagies.js.map +1 -1
  17. package/dist/src/filesystem/stratagies.mjs +103 -0
  18. package/dist/src/filesystem/stratagies.mjs.map +1 -0
  19. package/dist/src/index.d.mts +8 -0
  20. package/dist/src/index.d.ts +8 -7
  21. package/dist/src/index.js +16 -22
  22. package/dist/src/index.mjs +9 -0
  23. package/dist/src/plugins/AutomaticPublicPathPlugin.d.mts +12 -0
  24. package/dist/src/plugins/AutomaticPublicPathPlugin.d.ts +9 -7
  25. package/dist/src/plugins/AutomaticPublicPathPlugin.js +26 -35
  26. package/dist/src/plugins/AutomaticPublicPathPlugin.js.map +1 -1
  27. package/dist/src/plugins/AutomaticPublicPathPlugin.mjs +28 -0
  28. package/dist/src/plugins/AutomaticPublicPathPlugin.mjs.map +1 -0
  29. package/dist/src/plugins/ChunkCorrelationPlugin.d.mts +5 -0
  30. package/dist/src/plugins/ChunkCorrelationPlugin.d.ts +4 -61
  31. package/dist/src/plugins/ChunkCorrelationPlugin.js +8 -440
  32. package/dist/src/plugins/ChunkCorrelationPlugin.js.map +1 -1
  33. package/dist/src/plugins/ChunkCorrelationPlugin.mjs +8 -0
  34. package/dist/src/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
  35. package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.mts +21 -0
  36. package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.ts +16 -13
  37. package/dist/src/plugins/CommonJsChunkLoadingPlugin.js +68 -118
  38. package/dist/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -1
  39. package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs +70 -0
  40. package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs.map +1 -0
  41. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.mts +44 -0
  42. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.ts +37 -34
  43. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +109 -126
  44. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -1
  45. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs +110 -0
  46. package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs.map +1 -0
  47. package/dist/src/plugins/EntryChunkTrackerPlugin.d.mts +17 -0
  48. package/dist/src/plugins/EntryChunkTrackerPlugin.d.ts +14 -10
  49. package/dist/src/plugins/EntryChunkTrackerPlugin.js +30 -32
  50. package/dist/src/plugins/EntryChunkTrackerPlugin.js.map +1 -1
  51. package/dist/src/plugins/EntryChunkTrackerPlugin.mjs +38 -0
  52. package/dist/src/plugins/EntryChunkTrackerPlugin.mjs.map +1 -0
  53. package/dist/src/plugins/NodeFederationPlugin.d.mts +54 -0
  54. package/dist/src/plugins/NodeFederationPlugin.d.ts +33 -26
  55. package/dist/src/plugins/NodeFederationPlugin.js +72 -84
  56. package/dist/src/plugins/NodeFederationPlugin.js.map +1 -1
  57. package/dist/src/plugins/NodeFederationPlugin.mjs +73 -0
  58. package/dist/src/plugins/NodeFederationPlugin.mjs.map +1 -0
  59. package/dist/src/plugins/RemotePublicPathRuntimeModule.d.mts +13 -0
  60. package/dist/src/plugins/RemotePublicPathRuntimeModule.d.ts +10 -8
  61. package/dist/src/plugins/RemotePublicPathRuntimeModule.js +34 -35
  62. package/dist/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -1
  63. package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs +132 -0
  64. package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs.map +1 -0
  65. package/dist/src/plugins/StreamingTargetPlugin.d.mts +32 -0
  66. package/dist/src/plugins/StreamingTargetPlugin.d.ts +19 -16
  67. package/dist/src/plugins/StreamingTargetPlugin.js +43 -56
  68. package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -1
  69. package/dist/src/plugins/StreamingTargetPlugin.mjs +46 -0
  70. package/dist/src/plugins/StreamingTargetPlugin.mjs.map +1 -0
  71. package/dist/src/plugins/UniversalFederationPlugin.d.mts +49 -0
  72. package/dist/src/plugins/UniversalFederationPlugin.d.ts +26 -23
  73. package/dist/src/plugins/UniversalFederationPlugin.js +62 -81
  74. package/dist/src/plugins/UniversalFederationPlugin.js.map +1 -1
  75. package/dist/src/plugins/UniversalFederationPlugin.mjs +65 -0
  76. package/dist/src/plugins/UniversalFederationPlugin.mjs.map +1 -0
  77. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.mts +9 -0
  78. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.ts +6 -3
  79. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js +14 -17
  80. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js.map +1 -1
  81. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs +23 -0
  82. package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs.map +1 -0
  83. package/dist/src/plugins/webpackChunkUtilities.d.mts +55 -0
  84. package/dist/src/plugins/webpackChunkUtilities.d.ts +14 -9
  85. package/dist/src/plugins/webpackChunkUtilities.js +195 -257
  86. package/dist/src/plugins/webpackChunkUtilities.js.map +1 -1
  87. package/dist/src/plugins/webpackChunkUtilities.mjs +234 -0
  88. package/dist/src/plugins/webpackChunkUtilities.mjs.map +1 -0
  89. package/dist/src/recordDynamicRemoteEntryHashPlugin.d.mts +7 -0
  90. package/dist/src/recordDynamicRemoteEntryHashPlugin.d.ts +5 -2
  91. package/dist/src/recordDynamicRemoteEntryHashPlugin.js +24 -61
  92. package/dist/src/recordDynamicRemoteEntryHashPlugin.js.map +1 -1
  93. package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs +26 -0
  94. package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs.map +1 -0
  95. package/dist/src/runtimePlugin.d.mts +27 -0
  96. package/dist/src/runtimePlugin.d.ts +24 -19
  97. package/dist/src/runtimePlugin.js +214 -252
  98. package/dist/src/runtimePlugin.js.map +1 -1
  99. package/dist/src/runtimePlugin.mjs +226 -0
  100. package/dist/src/runtimePlugin.mjs.map +1 -0
  101. package/dist/src/types/index.d.mts +8 -0
  102. package/dist/src/types/index.d.ts +8 -3
  103. package/dist/src/types/index.js +1 -3
  104. package/dist/src/types/index.mjs +1 -0
  105. package/dist/src/utils/flush-chunks.d.mts +17 -0
  106. package/dist/src/utils/flush-chunks.d.ts +9 -3
  107. package/dist/src/utils/flush-chunks.js +138 -167
  108. package/dist/src/utils/flush-chunks.js.map +1 -1
  109. package/dist/src/utils/flush-chunks.mjs +144 -0
  110. package/dist/src/utils/flush-chunks.mjs.map +1 -0
  111. package/dist/src/utils/hot-reload.d.mts +16 -0
  112. package/dist/src/utils/hot-reload.d.ts +14 -10
  113. package/dist/src/utils/hot-reload.js +178 -264
  114. package/dist/src/utils/hot-reload.js.map +1 -1
  115. package/dist/src/utils/hot-reload.mjs +195 -0
  116. package/dist/src/utils/hot-reload.mjs.map +1 -0
  117. package/dist/src/utils/index.d.mts +3 -0
  118. package/dist/src/utils/index.d.ts +3 -2
  119. package/dist/src/utils/index.js +15 -19
  120. package/dist/src/utils/index.mjs +4 -0
  121. package/package.json +71 -26
  122. package/dist/jest.config.d.ts +0 -11
  123. package/dist/jest.config.js +0 -19
  124. package/dist/jest.config.js.map +0 -1
  125. package/dist/package.json +0 -90
  126. package/dist/src/index.js.map +0 -1
  127. package/dist/src/types/index.js.map +0 -1
  128. package/dist/src/utils/index.js.map +0 -1
@@ -1,292 +1,206 @@
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
- exports.revalidate = exports.fetchRemote = exports.createFetcher = exports.checkFakeRemote = exports.checkMedusaConfigChange = exports.checkUnreachableRemote = exports.performReload = void 0;
7
- exports.getFetchModule = getFetchModule;
8
- const flush_chunks_1 = require("./flush-chunks");
9
- const crypto_1 = __importDefault(require("crypto"));
10
- const helpers_1 = __importDefault(require("@module-federation/runtime/helpers"));
11
- const path_1 = __importDefault(require("path"));
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
+ const require_src_utils_flush_chunks = require('./flush-chunks.js');
4
+ let path = require("path");
5
+ path = require_runtime.__toESM(path);
6
+ let crypto = require("crypto");
7
+ crypto = require_runtime.__toESM(crypto);
8
+ let _module_federation_runtime_helpers = require("@module-federation/runtime/helpers");
9
+ _module_federation_runtime_helpers = require_runtime.__toESM(_module_federation_runtime_helpers);
10
+
11
+ //#region src/utils/hot-reload.ts
12
12
  const getRequire = () => {
13
- //@ts-ignore
14
- return typeof __non_webpack_require__ !== 'undefined'
15
- ? __non_webpack_require__
16
- : eval('require');
13
+ return typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : eval("require");
17
14
  };
18
15
  function callsites() {
19
- const _prepareStackTrace = Error.prepareStackTrace;
20
- try {
21
- let result = [];
22
- Error.prepareStackTrace = (_, callSites) => {
23
- const callSitesWithoutCurrent = callSites.slice(1);
24
- result = callSitesWithoutCurrent;
25
- return callSitesWithoutCurrent;
26
- };
27
- new Error().stack;
28
- return result;
29
- }
30
- finally {
31
- Error.prepareStackTrace = _prepareStackTrace;
32
- }
16
+ const _prepareStackTrace = Error.prepareStackTrace;
17
+ try {
18
+ let result = [];
19
+ Error.prepareStackTrace = (_, callSites) => {
20
+ const callSitesWithoutCurrent = callSites.slice(1);
21
+ result = callSitesWithoutCurrent;
22
+ return callSitesWithoutCurrent;
23
+ };
24
+ (/* @__PURE__ */ new Error()).stack;
25
+ return result;
26
+ } finally {
27
+ Error.prepareStackTrace = _prepareStackTrace;
28
+ }
33
29
  }
34
- const find = function (moduleName) {
35
- if (moduleName[0] === '.') {
36
- // Use custom callsites function
37
- const stack = callsites();
38
- for (const frame of stack) {
39
- const filename = frame.getFileName();
40
- if (filename && filename !== module.filename) {
41
- moduleName = path_1.default.resolve(path_1.default.dirname(filename), moduleName);
42
- break;
43
- }
44
- }
45
- }
46
- try {
47
- return getRequire().resolve(moduleName);
48
- }
49
- catch (e) {
50
- return;
51
- }
30
+ const find = function(moduleName) {
31
+ if (moduleName[0] === ".") {
32
+ const stack = callsites();
33
+ for (const frame of stack) {
34
+ const filename = frame.getFileName();
35
+ if (filename && filename !== module.filename) {
36
+ moduleName = path.default.resolve(path.default.dirname(filename), moduleName);
37
+ break;
38
+ }
39
+ }
40
+ }
41
+ try {
42
+ return getRequire().resolve(moduleName);
43
+ } catch (e) {
44
+ return;
45
+ }
52
46
  };
53
47
  /**
54
- * Removes a module from the cache. We need this to re-load our http_request !
55
- * see: https://stackoverflow.com/a/14801711/1148249
56
- */
57
- const decache = async function (moduleName) {
58
- //@ts-ignore
59
- moduleName = find(moduleName);
60
- if (!moduleName) {
61
- return;
62
- }
63
- const currentChunk = getRequire().cache[__filename];
64
- // Run over the cache looking for the files
65
- // loaded by the specified module name
66
- searchCache(moduleName, function (mod) {
67
- delete getRequire().cache[mod.id];
68
- });
69
- try {
70
- // Remove cached paths to the module.
71
- // Thanks to @bentael for pointing this out.
72
- //@ts-ignore
73
- Object.keys(currentChunk.constructor._pathCache).forEach(function (cacheKey) {
74
- if (cacheKey.indexOf(moduleName) > -1) {
75
- //@ts-ignore
76
- delete currentChunk.constructor._pathCache[cacheKey];
77
- }
78
- });
79
- }
80
- catch (error) {
81
- //null
82
- }
48
+ * Removes a module from the cache. We need this to re-load our http_request !
49
+ * see: https://stackoverflow.com/a/14801711/1148249
50
+ */
51
+ const decache = async function(moduleName) {
52
+ moduleName = find(moduleName);
53
+ if (!moduleName) return;
54
+ const currentChunk = getRequire().cache[__filename];
55
+ searchCache(moduleName, function(mod) {
56
+ delete getRequire().cache[mod.id];
57
+ });
58
+ try {
59
+ Object.keys(currentChunk.constructor._pathCache).forEach(function(cacheKey) {
60
+ if (cacheKey.indexOf(moduleName) > -1) delete currentChunk.constructor._pathCache[cacheKey];
61
+ });
62
+ } catch (error) {}
83
63
  };
84
64
  /**
85
- * Runs over the cache to search for all the cached
86
- * files
87
- */
88
- const searchCache = function (moduleName, callback) {
89
- // Resolve the module identified by the specified name
90
- let mod = getRequire().resolve(moduleName);
91
- const visited = {};
92
- // Check if the module has been resolved and found within
93
- // the cache no else so #ignore else https://git.io/vtgMI
94
- /* istanbul ignore else */
95
- //@ts-ignore
96
- if (mod && (mod = getRequire().cache[mod]) !== undefined) {
97
- // Recursively go over the results
98
- (function run(current) {
99
- visited[current.id] = true;
100
- // Go over each of the module's children and
101
- // run over it
102
- current.children.forEach(function (child) {
103
- // ignore .node files, decaching native modules throws a
104
- // "module did not self-register" error on second require
105
- if (path_1.default.extname(child.filename) !== '.node' && !visited[child.id]) {
106
- run(child);
107
- }
108
- });
109
- // Call the specified callback providing the
110
- // found module
111
- callback(current);
112
- //@ts-ignore
113
- })(mod);
114
- }
65
+ * Runs over the cache to search for all the cached
66
+ * files
67
+ */
68
+ const searchCache = function(moduleName, callback) {
69
+ let mod = getRequire().resolve(moduleName);
70
+ const visited = {};
71
+ /* istanbul ignore else */
72
+ if (mod && (mod = getRequire().cache[mod]) !== void 0) (function run(current) {
73
+ visited[current.id] = true;
74
+ current.children.forEach(function(child) {
75
+ if (path.default.extname(child.filename) !== ".node" && !visited[child.id]) run(child);
76
+ });
77
+ callback(current);
78
+ })(mod);
115
79
  };
80
+ globalThis.moduleGraphDirty = false;
116
81
  const hashmap = globalThis.mfHashMap || {};
117
82
  globalThis.moduleGraphDirty = false;
118
83
  const requireCacheRegex = /(remote|server|hot-reload|react-loadable-manifest|runtime|styled-jsx)/;
119
84
  const performReload = async (shouldReload) => {
120
- if (!shouldReload) {
121
- return false;
122
- }
123
- const req = getRequire();
124
- const gs = new Function('return globalThis')();
125
- const entries = gs.entryChunkCache || new Set();
126
- //@ts-ignore
127
- gs.__FEDERATION__.__INSTANCES__.map((i) => {
128
- //@ts-ignore
129
- i.moduleCache.forEach((mc) => {
130
- if (mc.remoteInfo && mc.remoteInfo.entryGlobalName) {
131
- delete gs[mc.remoteInfo.entryGlobalName];
132
- }
133
- });
134
- i.moduleCache.clear();
135
- if (gs[i.name]) {
136
- delete gs[i.name];
137
- }
138
- });
139
- //@ts-ignore
140
- __webpack_require__?.federation?.instance?.moduleCache?.clear();
141
- helpers_1.default.global.resetFederationGlobalInfo();
142
- globalThis.moduleGraphDirty = false;
143
- globalThis.mfHashMap = {};
144
- if (!entries) {
145
- Object.keys(req.cache).forEach((key) => {
146
- if (requireCacheRegex.test(key)) {
147
- decache(key); // Use decache here
148
- }
149
- });
150
- }
151
- else {
152
- for (const entry of entries) {
153
- decache(entry);
154
- //reload entries again
155
- await getRequire()(entry);
156
- }
157
- }
158
- return true;
85
+ if (!shouldReload) return false;
86
+ const req = getRequire();
87
+ const gs = new Function("return globalThis")();
88
+ const entries = gs.entryChunkCache || /* @__PURE__ */ new Set();
89
+ gs.__FEDERATION__.__INSTANCES__.map((i) => {
90
+ i.moduleCache.forEach((mc) => {
91
+ if (mc.remoteInfo && mc.remoteInfo.entryGlobalName) delete gs[mc.remoteInfo.entryGlobalName];
92
+ });
93
+ i.moduleCache.clear();
94
+ if (gs[i.name]) delete gs[i.name];
95
+ });
96
+ __webpack_require__?.federation?.instance?.moduleCache?.clear();
97
+ _module_federation_runtime_helpers.default.global.resetFederationGlobalInfo();
98
+ globalThis.moduleGraphDirty = false;
99
+ globalThis.mfHashMap = {};
100
+ if (!entries) Object.keys(req.cache).forEach((key) => {
101
+ if (requireCacheRegex.test(key)) decache(key);
102
+ });
103
+ else for (const entry of entries) {
104
+ decache(entry);
105
+ await getRequire()(entry);
106
+ }
107
+ return true;
159
108
  };
160
- exports.performReload = performReload;
161
109
  const checkUnreachableRemote = (remoteScope) => {
162
- for (const property in remoteScope.remotes) {
163
- if (!remoteScope[property]) {
164
- console.error('unreachable remote found', property, 'hot reloading to refetch');
165
- return true;
166
- }
167
- }
168
- return false;
110
+ for (const property in remoteScope.remotes) if (!remoteScope[property]) {
111
+ console.error("unreachable remote found", property, "hot reloading to refetch");
112
+ return true;
113
+ }
114
+ return false;
169
115
  };
170
- exports.checkUnreachableRemote = checkUnreachableRemote;
171
116
  const checkMedusaConfigChange = (remoteScope, fetchModule) => {
172
- //@ts-ignore
173
- if (remoteScope._medusa) {
174
- //@ts-ignore
175
- for (const property in remoteScope._medusa) {
176
- fetchModule(property)
177
- .then((res) => res.json())
178
- .then((medusaResponse) => {
179
- if (medusaResponse.version !==
180
- //@ts-ignore
181
- remoteScope?._medusa[property].version) {
182
- console.log('medusa config changed', property, 'hot reloading to refetch');
183
- (0, exports.performReload)(true);
184
- return true;
185
- }
186
- });
187
- }
188
- }
189
- return false;
117
+ if (remoteScope._medusa) for (const property in remoteScope._medusa) fetchModule(property).then((res) => res.json()).then((medusaResponse) => {
118
+ if (medusaResponse.version !== remoteScope?._medusa[property].version) {
119
+ console.log("medusa config changed", property, "hot reloading to refetch");
120
+ performReload(true);
121
+ return true;
122
+ }
123
+ });
124
+ return false;
190
125
  };
191
- exports.checkMedusaConfigChange = checkMedusaConfigChange;
192
126
  const checkFakeRemote = (remoteScope) => {
193
- for (const property in remoteScope._config) {
194
- let remote = remoteScope._config[property];
195
- const resolveRemote = async () => {
196
- remote = await remote();
197
- };
198
- if (typeof remote === 'function') {
199
- resolveRemote();
200
- }
201
- if (remote.fake) {
202
- console.log('fake remote found', property, 'hot reloading to refetch');
203
- return true;
204
- }
205
- }
206
- return false;
127
+ for (const property in remoteScope._config) {
128
+ let remote = remoteScope._config[property];
129
+ const resolveRemote = async () => {
130
+ remote = await remote();
131
+ };
132
+ if (typeof remote === "function") resolveRemote();
133
+ if (remote.fake) {
134
+ console.log("fake remote found", property, "hot reloading to refetch");
135
+ return true;
136
+ }
137
+ }
138
+ return false;
207
139
  };
208
- exports.checkFakeRemote = checkFakeRemote;
209
140
  const createFetcher = (url, fetchModule, name, cb) => {
210
- return fetchModule(url)
211
- .then((re) => {
212
- if (!re.ok) {
213
- throw new Error(`Error loading remote: status: ${re.status}, content-type: ${re.headers.get('content-type')}`);
214
- }
215
- return re.text();
216
- })
217
- .then((contents) => {
218
- const hash = crypto_1.default.createHash('md5').update(contents).digest('hex');
219
- cb(hash);
220
- })
221
- .catch((e) => {
222
- console.error('Remote', name, url, 'Failed to load or is not online', e);
223
- });
141
+ return fetchModule(url).then((re) => {
142
+ if (!re.ok) throw new Error(`Error loading remote: status: ${re.status}, content-type: ${re.headers.get("content-type")}`);
143
+ return re.text();
144
+ }).then((contents) => {
145
+ cb(crypto.default.createHash("md5").update(contents).digest("hex"));
146
+ }).catch((e) => {
147
+ console.error("Remote", name, url, "Failed to load or is not online", e);
148
+ });
224
149
  };
225
- exports.createFetcher = createFetcher;
226
150
  const fetchRemote = (remoteScope, fetchModule) => {
227
- const fetches = [];
228
- let needReload = false;
229
- for (const property in remoteScope) {
230
- const name = property;
231
- const container = remoteScope[property];
232
- const url = container.entry;
233
- const fetcher = (0, exports.createFetcher)(url, fetchModule, name, (hash) => {
234
- if (hashmap[name]) {
235
- if (hashmap[name] !== hash) {
236
- hashmap[name] = hash;
237
- needReload = true;
238
- console.log(name, 'hash is different - must hot reload server');
239
- }
240
- }
241
- else {
242
- hashmap[name] = hash;
243
- }
244
- });
245
- fetches.push(fetcher);
246
- }
247
- return Promise.all(fetches).then(() => {
248
- return needReload;
249
- });
151
+ const fetches = [];
152
+ let needReload = false;
153
+ for (const property in remoteScope) {
154
+ const name = property;
155
+ const url = remoteScope[property].entry;
156
+ const fetcher = createFetcher(url, fetchModule, name, (hash) => {
157
+ if (hashmap[name]) {
158
+ if (hashmap[name] !== hash) {
159
+ hashmap[name] = hash;
160
+ needReload = true;
161
+ console.log(name, "hash is different - must hot reload server");
162
+ }
163
+ } else hashmap[name] = hash;
164
+ });
165
+ fetches.push(fetcher);
166
+ }
167
+ return Promise.all(fetches).then(() => {
168
+ return needReload;
169
+ });
250
170
  };
251
- exports.fetchRemote = fetchRemote;
252
- //@ts-ignore
253
- const revalidate = async (fetchModule = getFetchModule() || (() => { }), force = false) => {
254
- if (globalThis.moduleGraphDirty) {
255
- force = true;
256
- }
257
- const remotesFromAPI = (0, flush_chunks_1.getAllKnownRemotes)();
258
- //@ts-ignore
259
- return new Promise((res) => {
260
- if (force) {
261
- if (Object.keys(hashmap).length !== 0) {
262
- res(true);
263
- return;
264
- }
265
- }
266
- if ((0, exports.checkMedusaConfigChange)(remotesFromAPI, fetchModule)) {
267
- res(true);
268
- }
269
- if ((0, exports.checkFakeRemote)(remotesFromAPI)) {
270
- res(true);
271
- }
272
- (0, exports.fetchRemote)(remotesFromAPI, fetchModule).then((val) => {
273
- res(val);
274
- });
275
- }).then((shouldReload) => {
276
- return (0, exports.performReload)(shouldReload);
277
- });
171
+ const revalidate = async (fetchModule = getFetchModule() || (() => {}), force = false) => {
172
+ if (globalThis.moduleGraphDirty) force = true;
173
+ const remotesFromAPI = require_src_utils_flush_chunks.getAllKnownRemotes();
174
+ return new Promise((res) => {
175
+ if (force) {
176
+ if (Object.keys(hashmap).length !== 0) {
177
+ res(true);
178
+ return;
179
+ }
180
+ }
181
+ if (checkMedusaConfigChange(remotesFromAPI, fetchModule)) res(true);
182
+ if (checkFakeRemote(remotesFromAPI)) res(true);
183
+ fetchRemote(remotesFromAPI, fetchModule).then((val) => {
184
+ res(val);
185
+ });
186
+ }).then((shouldReload) => {
187
+ return performReload(shouldReload);
188
+ });
278
189
  };
279
- exports.revalidate = revalidate;
280
190
  function getFetchModule() {
281
- //@ts-ignore
282
- const loadedModule =
283
- //@ts-ignore
284
- globalThis.webpackChunkLoad || global.webpackChunkLoad || global.fetch;
285
- if (loadedModule) {
286
- return loadedModule;
287
- }
288
- // eslint-disable-next-line @typescript-eslint/no-var-requires
289
- const nodeFetch = require('node-fetch');
290
- return nodeFetch.default || nodeFetch;
191
+ const loadedModule = globalThis.webpackChunkLoad || global.webpackChunkLoad || global.fetch;
192
+ if (loadedModule) return loadedModule;
193
+ const nodeFetch = require("node-fetch");
194
+ return nodeFetch.default || nodeFetch;
291
195
  }
196
+
197
+ //#endregion
198
+ exports.checkFakeRemote = checkFakeRemote;
199
+ exports.checkMedusaConfigChange = checkMedusaConfigChange;
200
+ exports.checkUnreachableRemote = checkUnreachableRemote;
201
+ exports.createFetcher = createFetcher;
202
+ exports.fetchRemote = fetchRemote;
203
+ exports.getFetchModule = getFetchModule;
204
+ exports.performReload = performReload;
205
+ exports.revalidate = revalidate;
292
206
  //# sourceMappingURL=hot-reload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hot-reload.js","sourceRoot":"","sources":["../../../src/utils/hot-reload.ts"],"names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D,8DAA8D;IAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACxC,OAAO,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC;AACxC,CAAC"}
1
+ {"version":3,"file":"hot-reload.js","names":["getAllKnownRemotes"],"sources":["../../../src/utils/hot-reload.ts"],"sourcesContent":["import { getAllKnownRemotes } from './flush-chunks';\nimport crypto from 'crypto';\nimport helpers from '@module-federation/runtime/helpers';\nimport path from 'path';\n\ndeclare global {\n var mfHashMap: Record<string, string> | undefined;\n var moduleGraphDirty: boolean;\n}\n\nconst getRequire = (): NodeRequire => {\n //@ts-ignore\n return typeof __non_webpack_require__ !== 'undefined'\n ? (__non_webpack_require__ as NodeRequire)\n : eval('require');\n};\n\nfunction callsites(): any[] {\n const _prepareStackTrace = Error.prepareStackTrace;\n try {\n let result: any[] = [];\n Error.prepareStackTrace = (_, callSites) => {\n const callSitesWithoutCurrent = callSites.slice(1);\n result = callSitesWithoutCurrent;\n return callSitesWithoutCurrent;\n };\n\n new Error().stack;\n return result;\n } finally {\n Error.prepareStackTrace = _prepareStackTrace;\n }\n}\n\nconst find = function (moduleName: string): string | undefined {\n if (moduleName[0] === '.') {\n // Use custom callsites function\n const stack = callsites();\n for (const frame of stack) {\n const filename = frame.getFileName();\n if (filename && filename !== module.filename) {\n moduleName = path.resolve(path.dirname(filename), moduleName);\n break;\n }\n }\n }\n try {\n return getRequire().resolve(moduleName);\n } catch (e) {\n return;\n }\n};\n\n/**\n * Removes a module from the cache. We need this to re-load our http_request !\n * see: https://stackoverflow.com/a/14801711/1148249\n */\nconst decache = async function (moduleName: string) {\n //@ts-ignore\n moduleName = find(moduleName);\n\n if (!moduleName) {\n return;\n }\n\n const currentChunk = getRequire().cache[__filename];\n\n // Run over the cache looking for the files\n // loaded by the specified module name\n searchCache(moduleName, function (mod: NodeModule) {\n delete getRequire().cache[mod.id];\n });\n try {\n // Remove cached paths to the module.\n // Thanks to @bentael for pointing this out.\n //@ts-ignore\n Object.keys((currentChunk.constructor as any)._pathCache).forEach(\n function (cacheKey) {\n if (cacheKey.indexOf(moduleName) > -1) {\n //@ts-ignore\n delete (currentChunk.constructor as any)._pathCache[cacheKey];\n }\n },\n );\n } catch (error) {\n //null\n }\n};\n\n/**\n * Runs over the cache to search for all the cached\n * files\n */\nconst searchCache = function (\n moduleName: string,\n callback: (mod: NodeModule) => void,\n) {\n // Resolve the module identified by the specified name\n let mod = getRequire().resolve(moduleName);\n const visited: Record<string, boolean> = {};\n\n // Check if the module has been resolved and found within\n // the cache no else so #ignore else https://git.io/vtgMI\n /* istanbul ignore else */\n //@ts-ignore\n if (mod && (mod = getRequire().cache[mod]) !== undefined) {\n // Recursively go over the results\n (function run(current: NodeModule) {\n visited[current.id] = true;\n // Go over each of the module's children and\n // run over it\n current.children.forEach(function (child: NodeModule) {\n // ignore .node files, decaching native modules throws a\n // \"module did not self-register\" error on second require\n if (path.extname(child.filename) !== '.node' && !visited[child.id]) {\n run(child);\n }\n });\n\n // Call the specified callback providing the\n // found module\n callback(current);\n //@ts-ignore\n })(mod);\n }\n};\n\nglobalThis.moduleGraphDirty = false;\n\nconst hashmap = globalThis.mfHashMap || ({} as Record<string, string>);\nglobalThis.moduleGraphDirty = false;\n\nconst requireCacheRegex =\n /(remote|server|hot-reload|react-loadable-manifest|runtime|styled-jsx)/;\n\nexport const performReload = async (\n shouldReload: boolean,\n): Promise<boolean> => {\n if (!shouldReload) {\n return false;\n }\n\n const req = getRequire();\n\n const gs = new Function('return globalThis')();\n const entries: Set<string> = gs.entryChunkCache || new Set();\n\n //@ts-ignore\n gs.__FEDERATION__.__INSTANCES__.map((i: any) => {\n //@ts-ignore\n i.moduleCache.forEach((mc: any) => {\n if (mc.remoteInfo && mc.remoteInfo.entryGlobalName) {\n delete gs[mc.remoteInfo.entryGlobalName];\n }\n });\n i.moduleCache.clear();\n if (gs[i.name]) {\n delete gs[i.name];\n }\n });\n //@ts-ignore\n __webpack_require__?.federation?.instance?.moduleCache?.clear();\n helpers.global.resetFederationGlobalInfo();\n globalThis.moduleGraphDirty = false;\n globalThis.mfHashMap = {};\n\n if (!entries) {\n Object.keys(req.cache).forEach((key) => {\n if (requireCacheRegex.test(key)) {\n decache(key); // Use decache here\n }\n });\n } else {\n for (const entry of entries) {\n decache(entry);\n //reload entries again\n await getRequire()(entry);\n }\n }\n\n return true;\n};\n\nexport const checkUnreachableRemote = (remoteScope: any): boolean => {\n for (const property in remoteScope.remotes) {\n if (!remoteScope[property]) {\n console.error(\n 'unreachable remote found',\n property,\n 'hot reloading to refetch',\n );\n return true;\n }\n }\n return false;\n};\n\nexport const checkMedusaConfigChange = (\n remoteScope: any,\n fetchModule: any,\n): boolean => {\n //@ts-ignore\n if (remoteScope._medusa) {\n //@ts-ignore\n for (const property in remoteScope._medusa) {\n fetchModule(property)\n .then((res: Response) => res.json())\n .then((medusaResponse: any): void | boolean => {\n if (\n medusaResponse.version !==\n //@ts-ignore\n remoteScope?._medusa[property].version\n ) {\n console.log(\n 'medusa config changed',\n property,\n 'hot reloading to refetch',\n );\n performReload(true);\n return true;\n }\n });\n }\n }\n return false;\n};\n\nexport const checkFakeRemote = (remoteScope: any): boolean => {\n for (const property in remoteScope._config) {\n let remote = remoteScope._config[property];\n\n const resolveRemote = async () => {\n remote = await remote();\n };\n\n if (typeof remote === 'function') {\n resolveRemote();\n }\n\n if (remote.fake) {\n console.log('fake remote found', property, 'hot reloading to refetch');\n return true;\n }\n }\n return false;\n};\n\nexport const createFetcher = (\n url: string,\n fetchModule: any,\n name: string,\n cb: (hash: string) => void,\n): Promise<void | boolean> => {\n return fetchModule(url)\n .then((re: Response) => {\n if (!re.ok) {\n throw new Error(\n `Error loading remote: status: ${\n re.status\n }, content-type: ${re.headers.get('content-type')}`,\n );\n }\n return re.text();\n })\n .then((contents: string): void | boolean => {\n const hash = crypto.createHash('md5').update(contents).digest('hex');\n cb(hash);\n })\n .catch((e: Error) => {\n console.error('Remote', name, url, 'Failed to load or is not online', e);\n });\n};\n\nexport const fetchRemote = (\n remoteScope: any,\n fetchModule: any,\n): Promise<boolean> => {\n const fetches: Promise<void | boolean>[] = [];\n let needReload = false;\n for (const property in remoteScope) {\n const name = property;\n const container = remoteScope[property];\n const url = container.entry;\n const fetcher = createFetcher(url, fetchModule, name, (hash) => {\n if (hashmap[name]) {\n if (hashmap[name] !== hash) {\n hashmap[name] = hash;\n needReload = true;\n console.log(name, 'hash is different - must hot reload server');\n }\n } else {\n hashmap[name] = hash;\n }\n });\n\n fetches.push(fetcher);\n }\n return Promise.all(fetches).then(() => {\n return needReload;\n });\n};\n//@ts-ignore\nexport const revalidate = async (\n fetchModule: any = getFetchModule() || (() => {}),\n force: boolean = false,\n): Promise<boolean> => {\n if (globalThis.moduleGraphDirty) {\n force = true;\n }\n const remotesFromAPI = getAllKnownRemotes();\n //@ts-ignore\n return new Promise((res) => {\n if (force) {\n if (Object.keys(hashmap).length !== 0) {\n res(true);\n return;\n }\n }\n if (checkMedusaConfigChange(remotesFromAPI, fetchModule)) {\n res(true);\n }\n\n if (checkFakeRemote(remotesFromAPI)) {\n res(true);\n }\n\n fetchRemote(remotesFromAPI, fetchModule).then((val) => {\n res(val);\n });\n }).then((shouldReload: unknown) => {\n return performReload(shouldReload as boolean);\n });\n};\n\nexport function getFetchModule(): any {\n //@ts-ignore\n const loadedModule =\n //@ts-ignore\n globalThis.webpackChunkLoad || global.webpackChunkLoad || global.fetch;\n if (loadedModule) {\n return loadedModule;\n }\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const nodeFetch = require('node-fetch');\n return nodeFetch.default || nodeFetch;\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,mBAAgC;AAEpC,QAAO,OAAO,4BAA4B,cACrC,0BACD,KAAK,UAAU;;AAGrB,SAAS,YAAmB;CAC1B,MAAM,qBAAqB,MAAM;AACjC,KAAI;EACF,IAAI,SAAgB,EAAE;AACtB,QAAM,qBAAqB,GAAG,cAAc;GAC1C,MAAM,0BAA0B,UAAU,M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