@module-federation/modern-js 0.0.0-next-20250526035905 → 0.0.0-next-20250526074234

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 (86) hide show
  1. package/dist/cjs/cli/configPlugin.js +8 -6
  2. package/dist/cjs/cli/configPlugin.spec.js +3 -1
  3. package/dist/cjs/cli/index.js +3 -1
  4. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +98 -0
  5. package/dist/cjs/cli/server/data-fetch-server-plugin.js +192 -0
  6. package/dist/cjs/cli/ssrPlugin.js +30 -11
  7. package/dist/cjs/cli/utils.js +5 -0
  8. package/dist/cjs/constant.js +49 -2
  9. package/dist/cjs/{ssr-runtime/index.js → interfaces/global.js} +2 -8
  10. package/dist/cjs/{cli/logger.js → logger.js} +1 -1
  11. package/dist/cjs/runtime/AwaitDataFetch.js +144 -0
  12. package/dist/cjs/runtime/createRemoteComponent.js +327 -0
  13. package/dist/cjs/runtime/index.js +15 -3
  14. package/dist/cjs/{cli/constant.js → runtime/wrapNoSSR.js} +13 -6
  15. package/dist/cjs/ssr-runtime/{plugin.js → devPlugin.js} +9 -6
  16. package/dist/cjs/ssr-runtime/downgrade.js +114 -0
  17. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +136 -0
  18. package/dist/cjs/utils/dataFetch.js +211 -0
  19. package/dist/cjs/utils/index.js +54 -0
  20. package/dist/esm/cli/configPlugin.js +9 -7
  21. package/dist/esm/cli/configPlugin.spec.js +3 -1
  22. package/dist/esm/cli/index.js +3 -1
  23. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +74 -0
  24. package/dist/esm/cli/server/data-fetch-server-plugin.js +240 -0
  25. package/dist/esm/cli/ssrPlugin.js +27 -7
  26. package/dist/esm/cli/utils.js +4 -0
  27. package/dist/esm/constant.js +37 -1
  28. package/dist/esm/interfaces/global.js +0 -0
  29. package/dist/esm/{cli/logger.js → logger.js} +1 -1
  30. package/dist/esm/runtime/AwaitDataFetch.js +131 -0
  31. package/dist/esm/runtime/createRemoteComponent.js +417 -0
  32. package/dist/esm/runtime/index.js +13 -3
  33. package/dist/esm/runtime/wrapNoSSR.js +12 -0
  34. package/dist/esm/ssr-runtime/{plugin.js → devPlugin.js} +5 -2
  35. package/dist/esm/ssr-runtime/downgrade.js +150 -0
  36. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +177 -0
  37. package/dist/esm/utils/dataFetch.js +237 -0
  38. package/dist/esm/utils/index.js +28 -0
  39. package/dist/esm-node/cli/configPlugin.js +9 -7
  40. package/dist/esm-node/cli/configPlugin.spec.js +3 -1
  41. package/dist/esm-node/cli/index.js +3 -1
  42. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +68 -0
  43. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +162 -0
  44. package/dist/esm-node/cli/ssrPlugin.js +26 -7
  45. package/dist/esm-node/cli/utils.js +4 -0
  46. package/dist/esm-node/constant.js +37 -1
  47. package/dist/esm-node/interfaces/global.js +0 -0
  48. package/dist/esm-node/{cli/logger.js → logger.js} +1 -1
  49. package/dist/esm-node/runtime/AwaitDataFetch.js +109 -0
  50. package/dist/esm-node/runtime/createRemoteComponent.js +291 -0
  51. package/dist/esm-node/runtime/index.js +13 -3
  52. package/dist/esm-node/runtime/wrapNoSSR.js +11 -0
  53. package/dist/esm-node/ssr-runtime/{plugin.js → devPlugin.js} +5 -2
  54. package/dist/esm-node/ssr-runtime/downgrade.js +88 -0
  55. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +101 -0
  56. package/dist/esm-node/utils/dataFetch.js +166 -0
  57. package/dist/esm-node/utils/index.js +27 -0
  58. package/dist/types/cli/index.d.ts +1 -0
  59. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +3 -0
  60. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
  61. package/dist/types/cli/utils.d.ts +1 -0
  62. package/dist/types/constant.d.ts +23 -0
  63. package/dist/types/interfaces/global.d.ts +27 -0
  64. package/dist/types/runtime/AwaitDataFetch.d.ts +19 -0
  65. package/dist/types/runtime/createRemoteComponent.d.ts +26 -0
  66. package/dist/types/runtime/index.d.ts +7 -2
  67. package/dist/types/runtime/wrapNoSSR.d.ts +9 -0
  68. package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
  69. package/dist/types/ssr-runtime/downgrade.d.ts +4 -0
  70. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +7 -0
  71. package/dist/types/types/index.d.ts +2 -0
  72. package/dist/types/utils/dataFetch.d.ts +26 -0
  73. package/dist/types/utils/index.d.ts +15 -0
  74. package/package.json +41 -17
  75. package/dist/cjs/runtime/createRemoteSSRComponent.js +0 -210
  76. package/dist/esm/cli/constant.js +0 -4
  77. package/dist/esm/runtime/createRemoteSSRComponent.js +0 -263
  78. package/dist/esm/ssr-runtime/index.js +0 -1
  79. package/dist/esm-node/cli/constant.js +0 -4
  80. package/dist/esm-node/runtime/createRemoteSSRComponent.js +0 -175
  81. package/dist/esm-node/ssr-runtime/index.js +0 -1
  82. package/dist/types/cli/constant.d.ts +0 -1
  83. package/dist/types/runtime/createRemoteSSRComponent.d.ts +0 -19
  84. package/dist/types/ssr-runtime/index.d.ts +0 -1
  85. package/dist/types/ssr-runtime/plugin.d.ts +0 -2
  86. /package/dist/types/{cli/logger.d.ts → logger.d.ts} +0 -0
@@ -1,210 +0,0 @@
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 createRemoteSSRComponent_exports = {};
30
- __export(createRemoteSSRComponent_exports, {
31
- collectSSRAssets: () => collectSSRAssets,
32
- createRemoteSSRComponent: () => createRemoteSSRComponent
33
- });
34
- module.exports = __toCommonJS(createRemoteSSRComponent_exports);
35
- var import_jsx_runtime = require("react/jsx-runtime");
36
- var import_react = __toESM(require("react"));
37
- var import_runtime = require("@module-federation/enhanced/runtime");
38
- var import_react_error_boundary = require("react-error-boundary");
39
- function getLoadedRemoteInfos(instance, id) {
40
- const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
41
- if (!name) {
42
- return;
43
- }
44
- const module2 = instance.moduleCache.get(name);
45
- if (!module2) {
46
- return;
47
- }
48
- const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module2.remoteInfo);
49
- return {
50
- ...module2.remoteInfo,
51
- snapshot: remoteSnapshot,
52
- expose
53
- };
54
- }
55
- function getTargetModuleInfo(id) {
56
- const instance = (0, import_runtime.getInstance)();
57
- if (!instance) {
58
- return;
59
- }
60
- const loadedRemoteInfo = getLoadedRemoteInfos(instance, id);
61
- if (!loadedRemoteInfo) {
62
- return;
63
- }
64
- const snapshot = loadedRemoteInfo.snapshot;
65
- if (!snapshot) {
66
- return;
67
- }
68
- const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
69
- if (!publicPath) {
70
- return;
71
- }
72
- const modules = "modules" in snapshot ? snapshot.modules : [];
73
- const targetModule = modules.find((m) => m.modulePath === loadedRemoteInfo.expose);
74
- if (!targetModule) {
75
- return;
76
- }
77
- const remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
78
- if (!remoteEntry) {
79
- return;
80
- }
81
- return {
82
- module: targetModule,
83
- publicPath,
84
- remoteEntry
85
- };
86
- }
87
- async function collectSSRAssets(options) {
88
- const { id, injectLink = true, injectScript = true, inlineCSS = false } = typeof options === "string" ? {
89
- id: options
90
- } : options;
91
- const links = [];
92
- const scripts = [];
93
- const instance = (0, import_runtime.getInstance)();
94
- if (!instance || !injectLink && !injectScript) {
95
- return [
96
- ...scripts,
97
- ...links
98
- ];
99
- }
100
- const moduleAndPublicPath = getTargetModuleInfo(id);
101
- if (!moduleAndPublicPath) {
102
- return [
103
- ...scripts,
104
- ...links
105
- ];
106
- }
107
- const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
108
- if (injectLink) {
109
- await Promise.all([
110
- ...targetModule.assets.css.sync,
111
- ...targetModule.assets.css.async
112
- ].map(async (file, index) => {
113
- const href = `${publicPath}${file}`;
114
- const key = `${file.split(".")[0]}_${index}`;
115
- if (inlineCSS) {
116
- const content = await fetch(href).then((res) => res.text());
117
- links.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", {
118
- children: content
119
- }, key));
120
- return;
121
- }
122
- links.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("link", {
123
- href: `${publicPath}${file}`,
124
- rel: "stylesheet",
125
- type: "text/css"
126
- }, key));
127
- }));
128
- }
129
- if (injectScript) {
130
- scripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
131
- async: true,
132
- src: `${publicPath}${remoteEntry}`,
133
- crossOrigin: "anonymous"
134
- }, remoteEntry.split(".")[0]));
135
- [
136
- ...targetModule.assets.js.sync
137
- ].forEach((file, index) => {
138
- scripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
139
- async: true,
140
- src: `${publicPath}${file}`,
141
- crossOrigin: "anonymous"
142
- }, `${file.split(".")[0]}_${index}`));
143
- });
144
- }
145
- return [
146
- ...scripts,
147
- ...links
148
- ];
149
- }
150
- function createRemoteSSRComponent(info) {
151
- const exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
152
- const LazyComponent = /* @__PURE__ */ import_react.default.lazy(async () => {
153
- try {
154
- const m = await info.loader();
155
- if (!m) {
156
- throw new Error("load remote failed");
157
- }
158
- const moduleId = m && m[Symbol.for("mf_module_id")];
159
- const assets = await collectSSRAssets({
160
- id: moduleId
161
- });
162
- const Com = m[exportName];
163
- if (exportName in m && typeof Com === "function") {
164
- return {
165
- default: (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
166
- children: [
167
- assets,
168
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Com, {
169
- ...props
170
- })
171
- ]
172
- })
173
- };
174
- } else {
175
- throw Error(`Make sure that ${moduleId} has the correct export when export is ${String(exportName)}`);
176
- }
177
- } catch (err) {
178
- if (!info.fallback) {
179
- throw err;
180
- }
181
- const FallbackFunctionComponent = info.fallback;
182
- const FallbackNode = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FallbackFunctionComponent, {
183
- error: err,
184
- resetErrorBoundary: () => {
185
- console.log('SSR mode not support "resetErrorBoundary" !');
186
- }
187
- });
188
- return {
189
- default: () => FallbackNode
190
- };
191
- }
192
- });
193
- return (props) => {
194
- const { key, ...args } = props;
195
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_error_boundary.ErrorBoundary, {
196
- FallbackComponent: info.fallback,
197
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Suspense, {
198
- fallback: info.loading,
199
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyComponent, {
200
- ...args
201
- })
202
- })
203
- });
204
- };
205
- }
206
- // Annotate the CommonJS export names for ESM import in node:
207
- 0 && (module.exports = {
208
- collectSSRAssets,
209
- createRemoteSSRComponent
210
- });
@@ -1,4 +0,0 @@
1
- var isDev = process.env.NODE_ENV === "development";
2
- export {
3
- isDev
4
- };
@@ -1,263 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
- import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
5
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
7
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
8
- import React from "react";
9
- import { getInstance } from "@module-federation/enhanced/runtime";
10
- import { ErrorBoundary } from "react-error-boundary";
11
- function getLoadedRemoteInfos(instance, id) {
12
- var _ref = instance.remoteHandler.idToRemoteMap[id] || {}, name = _ref.name, expose = _ref.expose;
13
- if (!name) {
14
- return;
15
- }
16
- var module = instance.moduleCache.get(name);
17
- if (!module) {
18
- return;
19
- }
20
- var remoteSnapshot = instance.snapshotHandler.getGlobalRemoteInfo(module.remoteInfo).remoteSnapshot;
21
- return _object_spread_props(_object_spread({}, module.remoteInfo), {
22
- snapshot: remoteSnapshot,
23
- expose
24
- });
25
- }
26
- function getTargetModuleInfo(id) {
27
- var instance = getInstance();
28
- if (!instance) {
29
- return;
30
- }
31
- var loadedRemoteInfo = getLoadedRemoteInfos(instance, id);
32
- if (!loadedRemoteInfo) {
33
- return;
34
- }
35
- var snapshot = loadedRemoteInfo.snapshot;
36
- if (!snapshot) {
37
- return;
38
- }
39
- var publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
40
- if (!publicPath) {
41
- return;
42
- }
43
- var modules = "modules" in snapshot ? snapshot.modules : [];
44
- var targetModule = modules.find(function(m) {
45
- return m.modulePath === loadedRemoteInfo.expose;
46
- });
47
- if (!targetModule) {
48
- return;
49
- }
50
- var remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
51
- if (!remoteEntry) {
52
- return;
53
- }
54
- return {
55
- module: targetModule,
56
- publicPath,
57
- remoteEntry
58
- };
59
- }
60
- function collectSSRAssets(options) {
61
- return _collectSSRAssets.apply(this, arguments);
62
- }
63
- function _collectSSRAssets() {
64
- _collectSSRAssets = _async_to_generator(function(options) {
65
- var _ref, id, _ref_injectLink, injectLink, _ref_injectScript, injectScript, _ref_inlineCSS, inlineCSS, links, scripts, instance, moduleAndPublicPath, targetModule, publicPath, remoteEntry;
66
- return _ts_generator(this, function(_state) {
67
- switch (_state.label) {
68
- case 0:
69
- _ref = typeof options === "string" ? {
70
- id: options
71
- } : options, id = _ref.id, _ref_injectLink = _ref.injectLink, injectLink = _ref_injectLink === void 0 ? true : _ref_injectLink, _ref_injectScript = _ref.injectScript, injectScript = _ref_injectScript === void 0 ? true : _ref_injectScript, _ref_inlineCSS = _ref.inlineCSS, inlineCSS = _ref_inlineCSS === void 0 ? false : _ref_inlineCSS;
72
- links = [];
73
- scripts = [];
74
- instance = getInstance();
75
- if (!instance || !injectLink && !injectScript) {
76
- return [
77
- 2,
78
- _to_consumable_array(scripts).concat(_to_consumable_array(links))
79
- ];
80
- }
81
- moduleAndPublicPath = getTargetModuleInfo(id);
82
- if (!moduleAndPublicPath) {
83
- return [
84
- 2,
85
- _to_consumable_array(scripts).concat(_to_consumable_array(links))
86
- ];
87
- }
88
- targetModule = moduleAndPublicPath.module, publicPath = moduleAndPublicPath.publicPath, remoteEntry = moduleAndPublicPath.remoteEntry;
89
- if (!injectLink)
90
- return [
91
- 3,
92
- 2
93
- ];
94
- return [
95
- 4,
96
- Promise.all(_to_consumable_array(targetModule.assets.css.sync).concat(_to_consumable_array(targetModule.assets.css.async)).map(function() {
97
- var _ref2 = _async_to_generator(function(file, index) {
98
- var href, key, content;
99
- return _ts_generator(this, function(_state2) {
100
- switch (_state2.label) {
101
- case 0:
102
- href = "".concat(publicPath).concat(file);
103
- key = "".concat(file.split(".")[0], "_").concat(index);
104
- if (!inlineCSS)
105
- return [
106
- 3,
107
- 2
108
- ];
109
- return [
110
- 4,
111
- fetch(href).then(function(res) {
112
- return res.text();
113
- })
114
- ];
115
- case 1:
116
- content = _state2.sent();
117
- links.push(/* @__PURE__ */ _jsx("style", {
118
- children: content
119
- }, key));
120
- return [
121
- 2
122
- ];
123
- case 2:
124
- links.push(/* @__PURE__ */ _jsx("link", {
125
- href: "".concat(publicPath).concat(file),
126
- rel: "stylesheet",
127
- type: "text/css"
128
- }, key));
129
- return [
130
- 2
131
- ];
132
- }
133
- });
134
- });
135
- return function(file, index) {
136
- return _ref2.apply(this, arguments);
137
- };
138
- }()))
139
- ];
140
- case 1:
141
- _state.sent();
142
- _state.label = 2;
143
- case 2:
144
- if (injectScript) {
145
- scripts.push(/* @__PURE__ */ _jsx("script", {
146
- async: true,
147
- src: "".concat(publicPath).concat(remoteEntry),
148
- crossOrigin: "anonymous"
149
- }, remoteEntry.split(".")[0]));
150
- _to_consumable_array(targetModule.assets.js.sync).forEach(function(file, index) {
151
- scripts.push(/* @__PURE__ */ _jsx("script", {
152
- async: true,
153
- src: "".concat(publicPath).concat(file),
154
- crossOrigin: "anonymous"
155
- }, "".concat(file.split(".")[0], "_").concat(index)));
156
- });
157
- }
158
- return [
159
- 2,
160
- _to_consumable_array(scripts).concat(_to_consumable_array(links))
161
- ];
162
- }
163
- });
164
- });
165
- return _collectSSRAssets.apply(this, arguments);
166
- }
167
- function createRemoteSSRComponent(info) {
168
- var exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
169
- var LazyComponent = /* @__PURE__ */ React.lazy(/* @__PURE__ */ _async_to_generator(function() {
170
- var m, moduleId, assets, Com, err, FallbackFunctionComponent, FallbackNode;
171
- return _ts_generator(this, function(_state) {
172
- switch (_state.label) {
173
- case 0:
174
- _state.trys.push([
175
- 0,
176
- 3,
177
- ,
178
- 4
179
- ]);
180
- return [
181
- 4,
182
- info.loader()
183
- ];
184
- case 1:
185
- m = _state.sent();
186
- if (!m) {
187
- throw new Error("load remote failed");
188
- }
189
- moduleId = m && m[Symbol.for("mf_module_id")];
190
- return [
191
- 4,
192
- collectSSRAssets({
193
- id: moduleId
194
- })
195
- ];
196
- case 2:
197
- assets = _state.sent();
198
- Com = m[exportName];
199
- if (exportName in m && typeof Com === "function") {
200
- return [
201
- 2,
202
- {
203
- default: function(props) {
204
- return /* @__PURE__ */ _jsxs(_Fragment, {
205
- children: [
206
- assets,
207
- /* @__PURE__ */ _jsx(Com, _object_spread({}, props))
208
- ]
209
- });
210
- }
211
- }
212
- ];
213
- } else {
214
- throw Error("Make sure that ".concat(moduleId, " has the correct export when export is ").concat(String(exportName)));
215
- }
216
- return [
217
- 3,
218
- 4
219
- ];
220
- case 3:
221
- err = _state.sent();
222
- if (!info.fallback) {
223
- throw err;
224
- }
225
- FallbackFunctionComponent = info.fallback;
226
- FallbackNode = /* @__PURE__ */ _jsx(FallbackFunctionComponent, {
227
- error: err,
228
- resetErrorBoundary: function() {
229
- console.log('SSR mode not support "resetErrorBoundary" !');
230
- }
231
- });
232
- return [
233
- 2,
234
- {
235
- default: function() {
236
- return FallbackNode;
237
- }
238
- }
239
- ];
240
- case 4:
241
- return [
242
- 2
243
- ];
244
- }
245
- });
246
- }));
247
- return function(props) {
248
- var key = props.key, args = _object_without_properties(props, [
249
- "key"
250
- ]);
251
- return /* @__PURE__ */ _jsx(ErrorBoundary, {
252
- FallbackComponent: info.fallback,
253
- children: /* @__PURE__ */ _jsx(React.Suspense, {
254
- fallback: info.loading,
255
- children: /* @__PURE__ */ _jsx(LazyComponent, _object_spread({}, args))
256
- })
257
- });
258
- };
259
- }
260
- export {
261
- collectSSRAssets,
262
- createRemoteSSRComponent
263
- };
@@ -1 +0,0 @@
1
- export * from "./plugin";
@@ -1,4 +0,0 @@
1
- const isDev = process.env.NODE_ENV === "development";
2
- export {
3
- isDev
4
- };
@@ -1,175 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import React from "react";
3
- import { getInstance } from "@module-federation/enhanced/runtime";
4
- import { ErrorBoundary } from "react-error-boundary";
5
- function getLoadedRemoteInfos(instance, id) {
6
- const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
7
- if (!name) {
8
- return;
9
- }
10
- const module = instance.moduleCache.get(name);
11
- if (!module) {
12
- return;
13
- }
14
- const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module.remoteInfo);
15
- return {
16
- ...module.remoteInfo,
17
- snapshot: remoteSnapshot,
18
- expose
19
- };
20
- }
21
- function getTargetModuleInfo(id) {
22
- const instance = getInstance();
23
- if (!instance) {
24
- return;
25
- }
26
- const loadedRemoteInfo = getLoadedRemoteInfos(instance, id);
27
- if (!loadedRemoteInfo) {
28
- return;
29
- }
30
- const snapshot = loadedRemoteInfo.snapshot;
31
- if (!snapshot) {
32
- return;
33
- }
34
- const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
35
- if (!publicPath) {
36
- return;
37
- }
38
- const modules = "modules" in snapshot ? snapshot.modules : [];
39
- const targetModule = modules.find((m) => m.modulePath === loadedRemoteInfo.expose);
40
- if (!targetModule) {
41
- return;
42
- }
43
- const remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
44
- if (!remoteEntry) {
45
- return;
46
- }
47
- return {
48
- module: targetModule,
49
- publicPath,
50
- remoteEntry
51
- };
52
- }
53
- async function collectSSRAssets(options) {
54
- const { id, injectLink = true, injectScript = true, inlineCSS = false } = typeof options === "string" ? {
55
- id: options
56
- } : options;
57
- const links = [];
58
- const scripts = [];
59
- const instance = getInstance();
60
- if (!instance || !injectLink && !injectScript) {
61
- return [
62
- ...scripts,
63
- ...links
64
- ];
65
- }
66
- const moduleAndPublicPath = getTargetModuleInfo(id);
67
- if (!moduleAndPublicPath) {
68
- return [
69
- ...scripts,
70
- ...links
71
- ];
72
- }
73
- const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
74
- if (injectLink) {
75
- await Promise.all([
76
- ...targetModule.assets.css.sync,
77
- ...targetModule.assets.css.async
78
- ].map(async (file, index) => {
79
- const href = `${publicPath}${file}`;
80
- const key = `${file.split(".")[0]}_${index}`;
81
- if (inlineCSS) {
82
- const content = await fetch(href).then((res) => res.text());
83
- links.push(/* @__PURE__ */ _jsx("style", {
84
- children: content
85
- }, key));
86
- return;
87
- }
88
- links.push(/* @__PURE__ */ _jsx("link", {
89
- href: `${publicPath}${file}`,
90
- rel: "stylesheet",
91
- type: "text/css"
92
- }, key));
93
- }));
94
- }
95
- if (injectScript) {
96
- scripts.push(/* @__PURE__ */ _jsx("script", {
97
- async: true,
98
- src: `${publicPath}${remoteEntry}`,
99
- crossOrigin: "anonymous"
100
- }, remoteEntry.split(".")[0]));
101
- [
102
- ...targetModule.assets.js.sync
103
- ].forEach((file, index) => {
104
- scripts.push(/* @__PURE__ */ _jsx("script", {
105
- async: true,
106
- src: `${publicPath}${file}`,
107
- crossOrigin: "anonymous"
108
- }, `${file.split(".")[0]}_${index}`));
109
- });
110
- }
111
- return [
112
- ...scripts,
113
- ...links
114
- ];
115
- }
116
- function createRemoteSSRComponent(info) {
117
- const exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
118
- const LazyComponent = /* @__PURE__ */ React.lazy(async () => {
119
- try {
120
- const m = await info.loader();
121
- if (!m) {
122
- throw new Error("load remote failed");
123
- }
124
- const moduleId = m && m[Symbol.for("mf_module_id")];
125
- const assets = await collectSSRAssets({
126
- id: moduleId
127
- });
128
- const Com = m[exportName];
129
- if (exportName in m && typeof Com === "function") {
130
- return {
131
- default: (props) => /* @__PURE__ */ _jsxs(_Fragment, {
132
- children: [
133
- assets,
134
- /* @__PURE__ */ _jsx(Com, {
135
- ...props
136
- })
137
- ]
138
- })
139
- };
140
- } else {
141
- throw Error(`Make sure that ${moduleId} has the correct export when export is ${String(exportName)}`);
142
- }
143
- } catch (err) {
144
- if (!info.fallback) {
145
- throw err;
146
- }
147
- const FallbackFunctionComponent = info.fallback;
148
- const FallbackNode = /* @__PURE__ */ _jsx(FallbackFunctionComponent, {
149
- error: err,
150
- resetErrorBoundary: () => {
151
- console.log('SSR mode not support "resetErrorBoundary" !');
152
- }
153
- });
154
- return {
155
- default: () => FallbackNode
156
- };
157
- }
158
- });
159
- return (props) => {
160
- const { key, ...args } = props;
161
- return /* @__PURE__ */ _jsx(ErrorBoundary, {
162
- FallbackComponent: info.fallback,
163
- children: /* @__PURE__ */ _jsx(React.Suspense, {
164
- fallback: info.loading,
165
- children: /* @__PURE__ */ _jsx(LazyComponent, {
166
- ...args
167
- })
168
- })
169
- });
170
- };
171
- }
172
- export {
173
- collectSSRAssets,
174
- createRemoteSSRComponent
175
- };
@@ -1 +0,0 @@
1
- export * from "./plugin";
@@ -1 +0,0 @@
1
- export declare const isDev: boolean;
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
3
- type IProps = {
4
- id: string;
5
- injectScript?: boolean;
6
- injectLink?: boolean;
7
- inlineCSS?: boolean;
8
- };
9
- type ReactKey = {
10
- key?: React.Key | null;
11
- };
12
- export declare function collectSSRAssets(options: IProps): Promise<React.ReactNode[]>;
13
- export declare function createRemoteSSRComponent<T, E extends keyof T>(info: {
14
- loader: () => Promise<T>;
15
- loading: React.ReactNode;
16
- fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
17
- export?: E;
18
- }): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? ReactKey : Parameters<T[E]>[0] & ReactKey : ReactKey) => React.JSX.Element;
19
- export {};
@@ -1 +0,0 @@
1
- export * from './plugin';
@@ -1,2 +0,0 @@
1
- import type { RuntimePluginFuture } from '@modern-js/runtime';
2
- export declare const mfSSRPlugin: () => RuntimePluginFuture;
File without changes