@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,102 @@
1
+ //#region src/utils/flush-chunks.ts
2
+ if (!globalThis.usedChunks) globalThis.usedChunks = /* @__PURE__ */ new Set();
3
+ /**
4
+ * Initialize usedChunks and share it globally.
5
+ * @type {Set}
6
+ */
7
+ const { usedChunks } = globalThis;
8
+ /**
9
+ * Load hostStats from the JSON file.
10
+ * @returns {object} hostStats - An object containing host stats data.
11
+ */
12
+ const loadHostStats = () => {
13
+ try {
14
+ return __non_webpack_require__("../federated-stats.json");
15
+ } catch (e) {
16
+ return {};
17
+ }
18
+ };
19
+ const getAllKnownRemotes = function() {
20
+ const federationController = new Function("return globalThis")().__FEDERATION__;
21
+ if (!federationController || !federationController.__INSTANCES__) return {};
22
+ var collected = {};
23
+ for (const instance of federationController.__INSTANCES__) for (const [key, cacheModule] of instance.moduleCache) if (cacheModule.remoteInfo) collected[cacheModule.remoteInfo.name] = cacheModule.remoteInfo;
24
+ return collected;
25
+ };
26
+ /**
27
+ * Create a shareMap based on the loaded modules.
28
+ * @returns {object} shareMap - An object containing the shareMap data.
29
+ */
30
+ const createShareMap = () => {
31
+ if (__webpack_share_scopes__?.default) return Object.keys(__webpack_share_scopes__.default).reduce((acc, key) => {
32
+ const shareMap = __webpack_share_scopes__.default[key];
33
+ if (!shareMap || typeof shareMap !== "object") return acc;
34
+ const loadedModules = Object.values(shareMap).filter((sharedModule) => sharedModule.loaded).map((sharedModule) => sharedModule.from);
35
+ if (loadedModules.length > 0) acc[key] = loadedModules;
36
+ return acc;
37
+ }, {});
38
+ return {};
39
+ };
40
+ /**
41
+ * Process a single chunk and return an array of updated chunks.
42
+ * @param {string} chunk - A chunk string containing remote and request data.
43
+ * @param {object} shareMap - An object containing the shareMap data.
44
+ * @param {object} hostStats - An object containing host stats data.
45
+ * @returns {Promise<Array>} A promise that resolves to an array of updated chunks.
46
+ */
47
+ const processChunk = async (chunk, shareMap, hostStats) => {
48
+ const chunks = /* @__PURE__ */ new Set();
49
+ const normalizedChunk = chunk.includes("->") ? chunk.replace("->", "/") : chunk;
50
+ const remoteSeparatorIndex = normalizedChunk.indexOf("/");
51
+ const remote = remoteSeparatorIndex === -1 ? normalizedChunk : normalizedChunk.slice(0, remoteSeparatorIndex);
52
+ const req = remoteSeparatorIndex === -1 ? "" : normalizedChunk.slice(remoteSeparatorIndex + 1);
53
+ const request = req?.startsWith("./") ? req : "./" + req;
54
+ const knownRemotes = getAllKnownRemotes();
55
+ if (!knownRemotes[remote]) {
56
+ console.error(`flush chunks: Remote ${remote} is not defined in the global config`);
57
+ return;
58
+ }
59
+ try {
60
+ const remoteName = new URL(knownRemotes[remote].entry).pathname.split("/").pop();
61
+ const statsFile = knownRemotes[remote].entry.replace(remoteName, "federated-stats.json").replace("ssr", "chunks");
62
+ let stats = {};
63
+ try {
64
+ stats = await fetch(statsFile).then((res) => res.json());
65
+ } catch (e) {
66
+ console.error("flush error", e);
67
+ }
68
+ const [prefix] = knownRemotes[remote].entry.split("static/");
69
+ if (stats.federatedModules) stats.federatedModules.forEach((modules) => {
70
+ if (modules.exposes?.[request]) modules.exposes[request].forEach((chunk) => {
71
+ chunks.add([prefix, chunk].join(""));
72
+ Object.values(chunk).forEach((chunk) => {
73
+ if (chunk.files) chunk.files.forEach((file) => {
74
+ chunks.add(prefix + file);
75
+ });
76
+ if (chunk.requiredModules) chunk.requiredModules.forEach((module) => {
77
+ if (shareMap[module]) {}
78
+ });
79
+ });
80
+ });
81
+ });
82
+ return Array.from(chunks);
83
+ } catch (e) {
84
+ console.error("flush error:", e);
85
+ }
86
+ };
87
+ /**
88
+ * Flush the chunks and return a deduplicated array of chunks.
89
+ * @returns {Promise<Array>} A promise that resolves to an array of deduplicated chunks.
90
+ */
91
+ const flushChunks = async () => {
92
+ const hostStats = loadHostStats();
93
+ const shareMap = createShareMap();
94
+ const allFlushed = await Promise.all(Array.from(usedChunks).map(async (chunk) => processChunk(chunk, shareMap, hostStats)));
95
+ const dedupe = Array.from(new Set([...allFlushed.flat()]));
96
+ usedChunks.clear();
97
+ return dedupe.filter(Boolean);
98
+ };
99
+
100
+ //#endregion
101
+ export { flushChunks, getAllKnownRemotes, usedChunks };
102
+ //# sourceMappingURL=flush-chunks.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flush-chunks.mjs","names":[],"sources":["../../../src/utils/flush-chunks.ts"],"sourcesContent":["/* eslint-disable no-undef */\n\n// @ts-ignore\nif (!globalThis.usedChunks) {\n // @ts-ignore\n globalThis.usedChunks = new Set();\n}\n/**\n * Initialize usedChunks and share it globally.\n * @type {Set}\n */\n// @ts-ignore\nexport const { usedChunks } = globalThis;\n/**\n * Load hostStats from the JSON file.\n * @returns {object} hostStats - An object containing host stats data.\n */\nconst loadHostStats = () => {\n try {\n //@ts-ignore\n return __non_webpack_require__('../federated-stats.json');\n } catch (e) {\n return {};\n }\n};\n\nexport const getAllKnownRemotes = function () {\n // Attempt to access the global federation controller safely\n const federationController = new Function('return globalThis')()\n .__FEDERATION__;\n if (!federationController || !federationController.__INSTANCES__) {\n // If the federation controller or instances are not defined, return an empty object\n return {};\n }\n\n var collected = {};\n // Use a for...of loop to iterate over all federation instances\n for (const instance of federationController.__INSTANCES__) {\n // Use another for...of loop to iterate over the module cache Map entries\n for (const [key, cacheModule] of instance.moduleCache) {\n // Check if the cacheModule has remoteInfo and use it to collect remote names\n if (cacheModule.remoteInfo) {\n //@ts-ignore\n collected[cacheModule.remoteInfo.name] = cacheModule.remoteInfo;\n }\n }\n }\n return collected;\n};\n\n/**\n * Create a shareMap based on the loaded modules.\n * @returns {object} shareMap - An object containing the shareMap data.\n */\nconst createShareMap = () => {\n // Check if __webpack_share_scopes__ is defined and has a default property\n // @ts-ignore\n if (__webpack_share_scopes__?.default) {\n // Reduce the keys of the default property to create the share map\n // @ts-ignore\n return Object.keys(__webpack_share_scopes__.default).reduce((acc, key) => {\n // @ts-ignore\n const shareMap = __webpack_share_scopes__.default[key];\n // shareScope may equal undefined or null if it has unexpected value\n if (!shareMap || typeof shareMap !== 'object') {\n return acc;\n }\n // Get the loaded modules for the current key\n const loadedModules = Object.values(shareMap)\n // Filter out the modules that are not loaded\n // @ts-ignore\n .filter((sharedModule) => sharedModule.loaded)\n // Map the filtered modules to their 'from' properties\n // @ts-ignore\n .map((sharedModule) => sharedModule.from);\n\n // If there are any loaded modules, add them to the accumulator object\n if (loadedModules.length > 0) {\n // @ts-ignore\n acc[key] = loadedModules;\n }\n // Return the accumulator object for the next iteration\n return acc;\n }, {});\n }\n // If __webpack_share_scopes__ is not defined or doesn't have a default property, return an empty object\n return {};\n};\n\n/**\n * Process a single chunk and return an array of updated chunks.\n * @param {string} chunk - A chunk string containing remote and request data.\n * @param {object} shareMap - An object containing the shareMap data.\n * @param {object} hostStats - An object containing host stats data.\n * @returns {Promise<Array>} A promise that resolves to an array of updated chunks.\n */\n// @ts-ignore\nconst processChunk = async (chunk, shareMap, hostStats) => {\n const chunks = new Set();\n const normalizedChunk = chunk.includes('->')\n ? chunk.replace('->', '/')\n : chunk;\n const remoteSeparatorIndex = normalizedChunk.indexOf('/');\n const remote =\n remoteSeparatorIndex === -1\n ? normalizedChunk\n : normalizedChunk.slice(0, remoteSeparatorIndex);\n const req =\n remoteSeparatorIndex === -1\n ? ''\n : normalizedChunk.slice(remoteSeparatorIndex + 1);\n const request = req?.startsWith('./') ? req : './' + req;\n const knownRemotes = getAllKnownRemotes();\n //@ts-ignore\n if (!knownRemotes[remote]) {\n console.error(\n `flush chunks: Remote ${remote} is not defined in the global config`,\n );\n return;\n }\n\n try {\n //@ts-ignore\n const remoteName = new URL(knownRemotes[remote].entry).pathname\n .split('/')\n .pop();\n //@ts-ignore\n\n const statsFile = knownRemotes[remote].entry\n .replace(remoteName, 'federated-stats.json')\n .replace('ssr', 'chunks');\n let stats = {};\n\n try {\n stats = await fetch(statsFile).then((res) => res.json());\n } catch (e) {\n console.error('flush error', e);\n }\n //@ts-ignore\n\n const [prefix] = knownRemotes[remote].entry.split('static/');\n //@ts-ignore\n\n if (stats.federatedModules) {\n //@ts-ignore\n\n stats.federatedModules.forEach((modules) => {\n if (modules.exposes?.[request]) {\n //@ts-ignore\n\n modules.exposes[request].forEach((chunk) => {\n chunks.add([prefix, chunk].join(''));\n\n Object.values(chunk).forEach((chunk) => {\n //@ts-ignore\n\n if (chunk.files) {\n //@ts-ignore\n\n chunk.files.forEach((file) => {\n chunks.add(prefix + file);\n });\n }\n //@ts-ignore\n\n if (chunk.requiredModules) {\n //@ts-ignore\n\n chunk.requiredModules.forEach((module) => {\n if (shareMap[module]) {\n // If the module is from the host, log the host stats\n }\n });\n }\n });\n });\n }\n });\n }\n\n return Array.from(chunks);\n } catch (e) {\n console.error('flush error:', e);\n }\n};\n\n/**\n * Flush the chunks and return a deduplicated array of chunks.\n * @returns {Promise<Array>} A promise that resolves to an array of deduplicated chunks.\n */\nexport const flushChunks = async () => {\n const hostStats = loadHostStats();\n const shareMap = createShareMap();\n\n const allFlushed = await Promise.all(\n Array.from(usedChunks).map(async (chunk) =>\n processChunk(chunk, shareMap, hostStats),\n ),\n );\n\n // Deduplicate the chunks array\n const dedupe = Array.from(new Set([...allFlushed.flat()]));\n\n // Clear usedChunks\n usedChunks.clear();\n // Filter out any undefined or null values\n return dedupe.filter(Boolean);\n};\n"],"mappings":"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"}
@@ -0,0 +1,16 @@
1
+ //#region src/utils/hot-reload.d.ts
2
+ declare global {
3
+ var mfHashMap: Record<string, string> | undefined;
4
+ var moduleGraphDirty: boolean;
5
+ }
6
+ declare const performReload: (shouldReload: boolean) => Promise<boolean>;
7
+ declare const checkUnreachableRemote: (remoteScope: any) => boolean;
8
+ declare const checkMedusaConfigChange: (remoteScope: any, fetchModule: any) => boolean;
9
+ declare const checkFakeRemote: (remoteScope: any) => boolean;
10
+ declare const createFetcher: (url: string, fetchModule: any, name: string, cb: (hash: string) => void) => Promise<void | boolean>;
11
+ declare const fetchRemote: (remoteScope: any, fetchModule: any) => Promise<boolean>;
12
+ declare const revalidate: (fetchModule?: any, force?: boolean) => Promise<boolean>;
13
+ declare function getFetchModule(): any;
14
+ //#endregion
15
+ export { checkFakeRemote, checkMedusaConfigChange, checkUnreachableRemote, createFetcher, fetchRemote, getFetchModule, performReload, revalidate };
16
+ //# sourceMappingURL=hot-reload.d.mts.map
@@ -1,12 +1,16 @@
1
+ //#region src/utils/hot-reload.d.ts
1
2
  declare global {
2
- var mfHashMap: Record<string, string> | undefined;
3
- var moduleGraphDirty: boolean;
3
+ var mfHashMap: Record<string, string> | undefined;
4
+ var moduleGraphDirty: boolean;
4
5
  }
5
- export declare const performReload: (shouldReload: boolean) => Promise<boolean>;
6
- export declare const checkUnreachableRemote: (remoteScope: any) => boolean;
7
- export declare const checkMedusaConfigChange: (remoteScope: any, fetchModule: any) => boolean;
8
- export declare const checkFakeRemote: (remoteScope: any) => boolean;
9
- export declare const createFetcher: (url: string, fetchModule: any, name: string, cb: (hash: string) => void) => Promise<void | boolean>;
10
- export declare const fetchRemote: (remoteScope: any, fetchModule: any) => Promise<boolean>;
11
- export declare const revalidate: (fetchModule?: any, force?: boolean) => Promise<boolean>;
12
- export declare function getFetchModule(): any;
6
+ declare const performReload: (shouldReload: boolean) => Promise<boolean>;
7
+ declare const checkUnreachableRemote: (remoteScope: any) => boolean;
8
+ declare const checkMedusaConfigChange: (remoteScope: any, fetchModule: any) => boolean;
9
+ declare const checkFakeRemote: (remoteScope: any) => boolean;
10
+ declare const createFetcher: (url: string, fetchModule: any, name: string, cb: (hash: string) => void) => Promise<void | boolean>;
11
+ declare const fetchRemote: (remoteScope: any, fetchModule: any) => Promise<boolean>;
12
+ declare const revalidate: (fetchModule?: any, force?: boolean) => Promise<boolean>;
13
+ declare function getFetchModule(): any;
14
+ //#endregion
15
+ export { checkFakeRemote, checkMedusaConfigChange, checkUnreachableRemote, createFetcher, fetchRemote, getFetchModule, performReload, revalidate };
16
+ //# sourceMappingURL=hot-reload.d.ts.map
@@ -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