@module-federation/modern-js 0.14.2 → 0.15.0

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/LICENSE +21 -0
  2. package/dist/cjs/cli/configPlugin.js +381 -0
  3. package/dist/cjs/cli/configPlugin.spec.js +114 -0
  4. package/dist/cjs/cli/index.js +95 -0
  5. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +98 -0
  6. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +44 -0
  7. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +82 -0
  8. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +43 -0
  9. package/dist/cjs/cli/server/data-fetch-server-plugin.js +189 -0
  10. package/dist/cjs/cli/ssrPlugin.js +236 -0
  11. package/dist/cjs/cli/utils.js +90 -0
  12. package/dist/cjs/constant.js +78 -0
  13. package/dist/cjs/interfaces/bundler.js +16 -0
  14. package/dist/cjs/interfaces/global.js +16 -0
  15. package/dist/cjs/logger.js +27 -0
  16. package/dist/cjs/runtime/AwaitDataFetch.js +144 -0
  17. package/dist/cjs/runtime/createRemoteComponent.js +327 -0
  18. package/dist/cjs/runtime/index.js +50 -0
  19. package/dist/cjs/runtime/wrapNoSSR.js +35 -0
  20. package/dist/cjs/server/fileCache.js +84 -0
  21. package/dist/cjs/server/fileCache.spec.js +28 -0
  22. package/dist/cjs/server/index.js +58 -0
  23. package/dist/cjs/server/staticMiddleware.js +77 -0
  24. package/dist/cjs/server/staticMiddleware.spec.js +185 -0
  25. package/dist/cjs/ssr-runtime/SSRLiveReload.js +43 -0
  26. package/dist/cjs/ssr-runtime/devPlugin.js +71 -0
  27. package/dist/cjs/ssr-runtime/downgrade.js +114 -0
  28. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +136 -0
  29. package/dist/cjs/types/index.js +16 -0
  30. package/dist/cjs/utils/dataFetch.js +211 -0
  31. package/dist/cjs/utils/index.js +54 -0
  32. package/dist/esm/cli/configPlugin.js +388 -0
  33. package/dist/esm/cli/configPlugin.spec.js +110 -0
  34. package/dist/esm/cli/index.js +90 -0
  35. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +74 -0
  36. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +16 -0
  37. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +74 -0
  38. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
  39. package/dist/esm/cli/server/data-fetch-server-plugin.js +237 -0
  40. package/dist/esm/cli/ssrPlugin.js +219 -0
  41. package/dist/esm/cli/utils.js +53 -0
  42. package/dist/esm/constant.js +42 -0
  43. package/dist/esm/interfaces/bundler.js +0 -0
  44. package/dist/esm/interfaces/global.js +0 -0
  45. package/dist/esm/logger.js +7 -0
  46. package/dist/esm/runtime/AwaitDataFetch.js +131 -0
  47. package/dist/esm/runtime/createRemoteComponent.js +417 -0
  48. package/dist/esm/runtime/index.js +22 -0
  49. package/dist/esm/runtime/wrapNoSSR.js +12 -0
  50. package/dist/esm/server/fileCache.js +98 -0
  51. package/dist/esm/server/fileCache.spec.js +50 -0
  52. package/dist/esm/server/index.js +36 -0
  53. package/dist/esm/server/staticMiddleware.js +81 -0
  54. package/dist/esm/server/staticMiddleware.spec.js +328 -0
  55. package/dist/esm/ssr-runtime/SSRLiveReload.js +26 -0
  56. package/dist/esm/ssr-runtime/devPlugin.js +73 -0
  57. package/dist/esm/ssr-runtime/downgrade.js +150 -0
  58. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +177 -0
  59. package/dist/esm/types/index.js +0 -0
  60. package/dist/esm/utils/dataFetch.js +237 -0
  61. package/dist/esm/utils/index.js +28 -0
  62. package/dist/esm-node/cli/configPlugin.js +340 -0
  63. package/dist/esm-node/cli/configPlugin.spec.js +91 -0
  64. package/dist/esm-node/cli/index.js +70 -0
  65. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +68 -0
  66. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +14 -0
  67. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +62 -0
  68. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
  69. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +159 -0
  70. package/dist/esm-node/cli/ssrPlugin.js +200 -0
  71. package/dist/esm-node/cli/utils.js +53 -0
  72. package/dist/esm-node/constant.js +42 -0
  73. package/dist/esm-node/interfaces/bundler.js +0 -0
  74. package/dist/esm-node/interfaces/global.js +0 -0
  75. package/dist/esm-node/logger.js +7 -0
  76. package/dist/esm-node/runtime/AwaitDataFetch.js +109 -0
  77. package/dist/esm-node/runtime/createRemoteComponent.js +291 -0
  78. package/dist/esm-node/runtime/index.js +22 -0
  79. package/dist/esm-node/runtime/wrapNoSSR.js +11 -0
  80. package/dist/esm-node/server/fileCache.js +49 -0
  81. package/dist/esm-node/server/fileCache.spec.js +27 -0
  82. package/dist/esm-node/server/index.js +34 -0
  83. package/dist/esm-node/server/staticMiddleware.js +43 -0
  84. package/dist/esm-node/server/staticMiddleware.spec.js +162 -0
  85. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +19 -0
  86. package/dist/esm-node/ssr-runtime/devPlugin.js +37 -0
  87. package/dist/esm-node/ssr-runtime/downgrade.js +88 -0
  88. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +101 -0
  89. package/dist/esm-node/types/index.js +0 -0
  90. package/dist/esm-node/utils/dataFetch.js +166 -0
  91. package/dist/esm-node/utils/index.js +27 -0
  92. package/dist/types/cli/configPlugin.d.ts +21 -0
  93. package/dist/types/cli/configPlugin.spec.d.ts +1 -0
  94. package/dist/types/cli/index.d.ts +6 -0
  95. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +3 -0
  96. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
  97. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +3 -0
  98. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
  99. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
  100. package/dist/types/cli/ssrPlugin.d.ts +6 -0
  101. package/dist/types/cli/utils.d.ts +6 -0
  102. package/dist/types/constant.d.ts +25 -0
  103. package/dist/types/interfaces/bundler.d.ts +18 -0
  104. package/dist/types/interfaces/global.d.ts +27 -0
  105. package/dist/types/logger.d.ts +2 -0
  106. package/dist/types/runtime/AwaitDataFetch.d.ts +19 -0
  107. package/dist/types/runtime/createRemoteComponent.d.ts +26 -0
  108. package/dist/types/runtime/index.d.ts +10 -0
  109. package/dist/types/runtime/wrapNoSSR.d.ts +9 -0
  110. package/dist/types/server/fileCache.d.ts +14 -0
  111. package/dist/types/server/fileCache.spec.d.ts +1 -0
  112. package/dist/types/server/index.d.ts +4 -0
  113. package/dist/types/server/staticMiddleware.d.ts +6 -0
  114. package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
  115. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +1 -0
  116. package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
  117. package/dist/types/ssr-runtime/downgrade.d.ts +4 -0
  118. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +7 -0
  119. package/dist/types/types/index.d.ts +24 -0
  120. package/dist/types/utils/dataFetch.d.ts +26 -0
  121. package/dist/types/utils/index.d.ts +15 -0
  122. package/package.json +37 -12
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ssrPlugin_exports = {};
30
+ __export(ssrPlugin_exports, {
31
+ CHAIN_MF_PLUGIN_ID: () => CHAIN_MF_PLUGIN_ID,
32
+ default: () => ssrPlugin_default,
33
+ moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
34
+ setEnv: () => setEnv
35
+ });
36
+ module.exports = __toCommonJS(ssrPlugin_exports);
37
+ var import_path = __toESM(require("path"));
38
+ var import_fs_extra = __toESM(require("fs-extra"));
39
+ var import_webpack = require("@module-federation/enhanced/webpack");
40
+ var import_rspack = require("@module-federation/enhanced/rspack");
41
+ var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
42
+ var import_logger = __toESM(require("../logger"));
43
+ var import_utils = require("./utils");
44
+ var import_manifest = require("@module-federation/rsbuild-plugin/manifest");
45
+ var import_utils2 = require("./utils");
46
+ function setEnv() {
47
+ process.env["MF_DISABLE_EMIT_STATS"] = "true";
48
+ process.env["MF_SSR_PRJ"] = "true";
49
+ }
50
+ const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
51
+ const mfSSRRsbuildPlugin = (pluginOptions) => {
52
+ return {
53
+ name: "@modern-js/plugin-mf-post-config",
54
+ pre: [
55
+ "@modern-js/builder-plugin-ssr"
56
+ ],
57
+ setup(api) {
58
+ if (pluginOptions.csrConfig.getPublicPath) {
59
+ return;
60
+ }
61
+ let csrOutputPath = "";
62
+ let ssrOutputPath = "";
63
+ let ssrEnv = "";
64
+ api.modifyEnvironmentConfig((config, { name }) => {
65
+ const target = config.output.target;
66
+ if ((0, import_utils2.skipByTarget)(target)) {
67
+ return config;
68
+ }
69
+ if ((0, import_utils2.isWebTarget)(target)) {
70
+ csrOutputPath = config.output.distPath.root;
71
+ } else {
72
+ ssrOutputPath = config.output.distPath.root;
73
+ ssrEnv = name;
74
+ }
75
+ return config;
76
+ });
77
+ const modifySSRPublicPath = (config, utils) => {
78
+ if (ssrEnv !== utils.environment.name) {
79
+ return config;
80
+ }
81
+ const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
82
+ if (userSSRConfig.distOutputDir) {
83
+ return;
84
+ }
85
+ config.output.publicPath = `${config.output.publicPath}${import_path.default.relative(csrOutputPath, ssrOutputPath)}/`;
86
+ return config;
87
+ };
88
+ api.modifyWebpackConfig((config, utils) => {
89
+ modifySSRPublicPath(config, utils);
90
+ return config;
91
+ });
92
+ api.modifyRspackConfig((config, utils) => {
93
+ modifySSRPublicPath(config, utils);
94
+ return config;
95
+ });
96
+ }
97
+ };
98
+ };
99
+ const moduleFederationSSRPlugin = (pluginOptions) => ({
100
+ name: "@modern-js/plugin-module-federation-ssr",
101
+ pre: [
102
+ "@modern-js/plugin-module-federation-config",
103
+ "@modern-js/plugin-module-federation"
104
+ ],
105
+ setup: async (api) => {
106
+ var _pluginOptions_userConfig, _modernjsConfig_server;
107
+ const modernjsConfig = api.getConfig();
108
+ var _pluginOptions_userConfig_ssr;
109
+ const enableSSR = (_pluginOptions_userConfig_ssr = (_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) !== null && _pluginOptions_userConfig_ssr !== void 0 ? _pluginOptions_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
110
+ if (!enableSSR) {
111
+ return;
112
+ }
113
+ setEnv();
114
+ api._internalRuntimePlugins(({ entrypoint, plugins }) => {
115
+ const { fetchServerQuery } = pluginOptions;
116
+ plugins.push({
117
+ name: "injectDataFetchFunction",
118
+ path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
119
+ config: {
120
+ fetchServerQuery
121
+ }
122
+ });
123
+ if (!(0, import_utils.isDev)()) {
124
+ return {
125
+ entrypoint,
126
+ plugins
127
+ };
128
+ }
129
+ plugins.push({
130
+ name: "mfSSRDev",
131
+ path: "@module-federation/modern-js/ssr-dev-plugin",
132
+ config: {}
133
+ });
134
+ return {
135
+ entrypoint,
136
+ plugins
137
+ };
138
+ });
139
+ if (pluginOptions.ssrConfig.remotes) {
140
+ api._internalServerPlugins(({ plugins }) => {
141
+ plugins.push({
142
+ name: "@module-federation/modern-js/data-fetch-server-plugin",
143
+ options: {}
144
+ });
145
+ return {
146
+ plugins
147
+ };
148
+ });
149
+ }
150
+ api.modifyBundlerChain((chain) => {
151
+ const target = chain.get("target");
152
+ if ((0, import_utils2.skipByTarget)(target)) {
153
+ return;
154
+ }
155
+ const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
156
+ const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
157
+ const isWeb = (0, import_utils2.isWebTarget)(target);
158
+ if (!isWeb) {
159
+ if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
160
+ chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
161
+ pluginOptions.ssrConfig
162
+ ]).init((Plugin, args) => {
163
+ pluginOptions.nodePlugin = new Plugin(args[0]);
164
+ return pluginOptions.nodePlugin;
165
+ });
166
+ }
167
+ }
168
+ if (!isWeb) {
169
+ chain.target("async-node");
170
+ if ((0, import_utils.isDev)()) {
171
+ chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
172
+ }
173
+ const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
174
+ const publicPath = chain.output.get("publicPath");
175
+ if (userSSRConfig.distOutputDir && publicPath) {
176
+ chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
177
+ }
178
+ }
179
+ if ((0, import_utils.isDev)() && isWeb) {
180
+ chain.externals({
181
+ "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
182
+ });
183
+ }
184
+ });
185
+ api.config(() => {
186
+ return {
187
+ builderPlugins: [
188
+ mfSSRRsbuildPlugin(pluginOptions)
189
+ ],
190
+ tools: {
191
+ devServer: {
192
+ before: [
193
+ (req, res, next) => {
194
+ if (!enableSSR) {
195
+ next();
196
+ return;
197
+ }
198
+ try {
199
+ var _req_url, _req_url1;
200
+ if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
201
+ const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
202
+ import_fs_extra.default.statSync(filepath);
203
+ res.setHeader("Access-Control-Allow-Origin", "*");
204
+ res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
205
+ res.setHeader("Access-Control-Allow-Headers", "*");
206
+ import_fs_extra.default.createReadStream(filepath).pipe(res);
207
+ } else {
208
+ next();
209
+ }
210
+ } catch (err) {
211
+ import_logger.default.debug(err);
212
+ next();
213
+ }
214
+ }
215
+ ]
216
+ }
217
+ }
218
+ };
219
+ });
220
+ api.onAfterBuild(() => {
221
+ const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
222
+ (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
223
+ });
224
+ api.onDevCompileDone(() => {
225
+ const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
226
+ (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
227
+ });
228
+ }
229
+ });
230
+ var ssrPlugin_default = moduleFederationSSRPlugin;
231
+ // Annotate the CommonJS export names for ESM import in node:
232
+ 0 && (module.exports = {
233
+ CHAIN_MF_PLUGIN_ID,
234
+ moduleFederationSSRPlugin,
235
+ setEnv
236
+ });
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var utils_exports = {};
30
+ __export(utils_exports, {
31
+ getIPV4: () => getIPV4,
32
+ isDev: () => isDev,
33
+ isWebTarget: () => isWebTarget,
34
+ skipByTarget: () => skipByTarget
35
+ });
36
+ module.exports = __toCommonJS(utils_exports);
37
+ var import_os = __toESM(require("os"));
38
+ const localIpv4 = "127.0.0.1";
39
+ const getIpv4Interfaces = () => {
40
+ try {
41
+ const interfaces = import_os.default.networkInterfaces();
42
+ const ipv4Interfaces = [];
43
+ Object.values(interfaces).forEach((detail) => {
44
+ detail === null || detail === void 0 ? void 0 : detail.forEach((detail2) => {
45
+ const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
46
+ if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
47
+ ipv4Interfaces.push(detail2);
48
+ }
49
+ });
50
+ });
51
+ return ipv4Interfaces;
52
+ } catch (_err) {
53
+ return [];
54
+ }
55
+ };
56
+ const getIPV4 = () => {
57
+ const ipv4Interfaces = getIpv4Interfaces();
58
+ const ipv4Interface = ipv4Interfaces[0] || {
59
+ address: localIpv4
60
+ };
61
+ return ipv4Interface.address;
62
+ };
63
+ const isWebTarget = (target) => {
64
+ const WEB_TARGET = "web";
65
+ if (Array.isArray(target)) {
66
+ return target.includes(WEB_TARGET);
67
+ } else if (typeof target === "string") {
68
+ return target === WEB_TARGET;
69
+ }
70
+ return false;
71
+ };
72
+ const skipByTarget = (target) => {
73
+ const IGNORE_TARGET = "webworker";
74
+ if (Array.isArray(target)) {
75
+ return target.includes(IGNORE_TARGET);
76
+ } else if (typeof target === "string") {
77
+ return target === IGNORE_TARGET;
78
+ }
79
+ return false;
80
+ };
81
+ function isDev() {
82
+ return process.env.NODE_ENV === "development";
83
+ }
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ getIPV4,
87
+ isDev,
88
+ isWebTarget,
89
+ skipByTarget
90
+ });
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var constant_exports = {};
20
+ __export(constant_exports, {
21
+ DATA_FETCH_ERROR_PREFIX: () => DATA_FETCH_ERROR_PREFIX,
22
+ DATA_FETCH_FUNCTION: () => DATA_FETCH_FUNCTION,
23
+ DATA_FETCH_MAP_KEY: () => DATA_FETCH_MAP_KEY,
24
+ DATA_FETCH_QUERY: () => DATA_FETCH_QUERY,
25
+ DOWNGRADE_KEY: () => DOWNGRADE_KEY,
26
+ ERROR_TYPE: () => ERROR_TYPE,
27
+ FS_HREF: () => FS_HREF,
28
+ LOAD_REMOTE_ERROR_PREFIX: () => LOAD_REMOTE_ERROR_PREFIX,
29
+ LOCALHOST: () => LOCALHOST,
30
+ MF_DATA_FETCH_STATUS: () => MF_DATA_FETCH_STATUS,
31
+ MF_DATA_FETCH_TYPE: () => MF_DATA_FETCH_TYPE,
32
+ PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER,
33
+ WRAP_DATA_FETCH_ID_IDENTIFIER: () => WRAP_DATA_FETCH_ID_IDENTIFIER
34
+ });
35
+ module.exports = __toCommonJS(constant_exports);
36
+ const LOCALHOST = "localhost";
37
+ const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
38
+ const DATA_FETCH_QUERY = "x-mf-data-fetch";
39
+ const DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
40
+ const LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
41
+ const DOWNGRADE_KEY = "_mfSSRDowngrade";
42
+ const DATA_FETCH_MAP_KEY = "__MF_DATA_FETCH_MAP__";
43
+ const DATA_FETCH_FUNCTION = "_mfDataFetch";
44
+ const FS_HREF = "_mfFSHref";
45
+ const ERROR_TYPE = {
46
+ DATA_FETCH: 1,
47
+ LOAD_REMOTE: 2,
48
+ UNKNOWN: 3
49
+ };
50
+ const WRAP_DATA_FETCH_ID_IDENTIFIER = "wrap_dfip_identifier";
51
+ var MF_DATA_FETCH_TYPE;
52
+ (function(MF_DATA_FETCH_TYPE2) {
53
+ MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_SERVER"] = 1] = "FETCH_SERVER";
54
+ MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_CLIENT"] = 2] = "FETCH_CLIENT";
55
+ })(MF_DATA_FETCH_TYPE || (MF_DATA_FETCH_TYPE = {}));
56
+ var MF_DATA_FETCH_STATUS;
57
+ (function(MF_DATA_FETCH_STATUS2) {
58
+ MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADED"] = 1] = "LOADED";
59
+ MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADING"] = 2] = "LOADING";
60
+ MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["AWAIT"] = 0] = "AWAIT";
61
+ MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["ERROR"] = 3] = "ERROR";
62
+ })(MF_DATA_FETCH_STATUS || (MF_DATA_FETCH_STATUS = {}));
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ DATA_FETCH_ERROR_PREFIX,
66
+ DATA_FETCH_FUNCTION,
67
+ DATA_FETCH_MAP_KEY,
68
+ DATA_FETCH_QUERY,
69
+ DOWNGRADE_KEY,
70
+ ERROR_TYPE,
71
+ FS_HREF,
72
+ LOAD_REMOTE_ERROR_PREFIX,
73
+ LOCALHOST,
74
+ MF_DATA_FETCH_STATUS,
75
+ MF_DATA_FETCH_TYPE,
76
+ PLUGIN_IDENTIFIER,
77
+ WRAP_DATA_FETCH_ID_IDENTIFIER
78
+ });
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var bundler_exports = {};
16
+ module.exports = __toCommonJS(bundler_exports);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var global_exports = {};
16
+ module.exports = __toCommonJS(global_exports);
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var logger_exports = {};
20
+ __export(logger_exports, {
21
+ default: () => logger_default
22
+ });
23
+ module.exports = __toCommonJS(logger_exports);
24
+ var import_sdk = require("@module-federation/sdk");
25
+ var import_constant = require("./constant");
26
+ const logger = (0, import_sdk.createLogger)(import_constant.PLUGIN_IDENTIFIER);
27
+ var logger_default = logger;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var AwaitDataFetch_exports = {};
30
+ __export(AwaitDataFetch_exports, {
31
+ AwaitDataFetch: () => AwaitDataFetch,
32
+ transformError: () => transformError
33
+ });
34
+ module.exports = __toCommonJS(AwaitDataFetch_exports);
35
+ var import_jsx_runtime = require("react/jsx-runtime");
36
+ var import_react = require("react");
37
+ var import_logger = __toESM(require("../logger"));
38
+ var import_constant = require("../constant");
39
+ var import_utils = require("../utils");
40
+ function isPromise(obj) {
41
+ return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
42
+ }
43
+ const AWAIT_ERROR_PREFIX = "<Await /> caught the following error during render: ";
44
+ const transformError = (err) => {
45
+ const errMsg = err instanceof Error ? err.message : err;
46
+ const originalMsg = errMsg.replace(AWAIT_ERROR_PREFIX, "");
47
+ const dataFetchMapKey = (0, import_utils.getDataFetchIdWithErrorMsgs)(originalMsg);
48
+ if (originalMsg.indexOf(import_constant.DATA_FETCH_ERROR_PREFIX) === 0) {
49
+ return {
50
+ error: new Error(originalMsg.replace(import_constant.DATA_FETCH_ERROR_PREFIX, "").replace((0, import_utils.wrapDataFetchId)(dataFetchMapKey), "")),
51
+ errorType: import_constant.ERROR_TYPE.DATA_FETCH,
52
+ dataFetchMapKey
53
+ };
54
+ }
55
+ if (originalMsg.indexOf(import_constant.LOAD_REMOTE_ERROR_PREFIX) === 0) {
56
+ return {
57
+ error: new Error(originalMsg.replace(import_constant.LOAD_REMOTE_ERROR_PREFIX, "").replace((0, import_utils.wrapDataFetchId)(dataFetchMapKey), "")),
58
+ errorType: import_constant.ERROR_TYPE.LOAD_REMOTE,
59
+ dataFetchMapKey
60
+ };
61
+ }
62
+ return {
63
+ error: new Error(originalMsg.replace((0, import_utils.wrapDataFetchId)(dataFetchMapKey), "")),
64
+ errorType: import_constant.ERROR_TYPE.UNKNOWN,
65
+ dataFetchMapKey
66
+ };
67
+ };
68
+ const DefaultLoading = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
69
+ const DefaultErrorElement = (_data) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
70
+ children: "Error"
71
+ });
72
+ function AwaitDataFetch({ resolve, loading = DefaultLoading, errorElement = DefaultErrorElement, children, params }) {
73
+ const dataRef = (0, import_react.useRef)();
74
+ const data = dataRef.current || resolve;
75
+ const getData = isPromise(data) ? fetchData(data, dataRef) : () => data;
76
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AwaitSuspense, {
77
+ params,
78
+ loading,
79
+ errorElement,
80
+ // @ts-ignore
81
+ resolve: getData,
82
+ children
83
+ });
84
+ }
85
+ function AwaitSuspense({ resolve, children, loading = DefaultLoading, errorElement = DefaultErrorElement }) {
86
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
87
+ fallback: loading,
88
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ResolveAwait, {
89
+ resolve,
90
+ errorElement,
91
+ children
92
+ })
93
+ });
94
+ }
95
+ function ResolveAwait({ children, resolve, errorElement, params }) {
96
+ const data = resolve();
97
+ import_logger.default.debug("resolve data: ", data);
98
+ if (typeof data === "string" && data.indexOf(AWAIT_ERROR_PREFIX) === 0) {
99
+ const transformedError = transformError(data);
100
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
101
+ children: typeof errorElement === "function" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
102
+ children: [
103
+ globalThis.FEDERATION_SSR && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
104
+ suppressHydrationWarning: true,
105
+ dangerouslySetInnerHTML: {
106
+ __html: String.raw`
107
+ globalThis['${import_constant.DATA_FETCH_FUNCTION}'] = globalThis['${import_constant.DATA_FETCH_FUNCTION}'] || []
108
+ globalThis['${import_constant.DATA_FETCH_FUNCTION}'].push([${transformedError.dataFetchMapKey ? `'${transformedError.dataFetchMapKey}'` : ""},${params ? JSON.stringify(params) : null},true]);`
109
+ }
110
+ }),
111
+ errorElement(transformedError)
112
+ ]
113
+ }) : errorElement
114
+ });
115
+ }
116
+ const toRender = typeof children === "function" ? children(data) : children;
117
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
118
+ children: toRender
119
+ });
120
+ }
121
+ const fetchData = (promise, ref) => {
122
+ let data;
123
+ let status = "pending";
124
+ const suspender = promise.then((res) => {
125
+ status = "success";
126
+ data = res;
127
+ ref.current = res;
128
+ }).catch((e) => {
129
+ status = "success";
130
+ console.warn(e);
131
+ data = AWAIT_ERROR_PREFIX + e;
132
+ });
133
+ return () => {
134
+ if (status === "pending") {
135
+ throw suspender;
136
+ }
137
+ return data;
138
+ };
139
+ };
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ AwaitDataFetch,
143
+ transformError
144
+ });