@module-federation/modern-js 0.13.1 → 0.14.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 (78) hide show
  1. package/package.json +7 -7
  2. package/dist/LICENSE +0 -21
  3. package/dist/cjs/cli/configPlugin.js +0 -377
  4. package/dist/cjs/cli/configPlugin.spec.js +0 -112
  5. package/dist/cjs/cli/constant.js +0 -28
  6. package/dist/cjs/cli/index.js +0 -85
  7. package/dist/cjs/cli/logger.js +0 -27
  8. package/dist/cjs/cli/manifest.js +0 -75
  9. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +0 -44
  10. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -82
  11. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +0 -43
  12. package/dist/cjs/cli/ssrPlugin.js +0 -217
  13. package/dist/cjs/cli/utils.js +0 -85
  14. package/dist/cjs/constant.js +0 -31
  15. package/dist/cjs/interfaces/bundler.js +0 -16
  16. package/dist/cjs/runtime/createRemoteSSRComponent.js +0 -201
  17. package/dist/cjs/runtime/index.js +0 -38
  18. package/dist/cjs/ssr-runtime/SSRLiveReload.js +0 -43
  19. package/dist/cjs/ssr-runtime/index.js +0 -22
  20. package/dist/cjs/ssr-runtime/plugin.js +0 -68
  21. package/dist/cjs/types/index.js +0 -16
  22. package/dist/esm/cli/configPlugin.js +0 -384
  23. package/dist/esm/cli/configPlugin.spec.js +0 -108
  24. package/dist/esm/cli/constant.js +0 -4
  25. package/dist/esm/cli/index.js +0 -79
  26. package/dist/esm/cli/logger.js +0 -7
  27. package/dist/esm/cli/manifest.js +0 -41
  28. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  29. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  30. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  31. package/dist/esm/cli/ssrPlugin.js +0 -199
  32. package/dist/esm/cli/utils.js +0 -49
  33. package/dist/esm/constant.js +0 -6
  34. package/dist/esm/interfaces/bundler.js +0 -0
  35. package/dist/esm/runtime/createRemoteSSRComponent.js +0 -191
  36. package/dist/esm/runtime/index.js +0 -12
  37. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  38. package/dist/esm/ssr-runtime/index.js +0 -1
  39. package/dist/esm/ssr-runtime/plugin.js +0 -70
  40. package/dist/esm/types/index.js +0 -0
  41. package/dist/esm-node/cli/configPlugin.js +0 -336
  42. package/dist/esm-node/cli/configPlugin.spec.js +0 -89
  43. package/dist/esm-node/cli/constant.js +0 -4
  44. package/dist/esm-node/cli/index.js +0 -60
  45. package/dist/esm-node/cli/logger.js +0 -7
  46. package/dist/esm-node/cli/manifest.js +0 -41
  47. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  48. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  49. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  50. package/dist/esm-node/cli/ssrPlugin.js +0 -181
  51. package/dist/esm-node/cli/utils.js +0 -49
  52. package/dist/esm-node/constant.js +0 -6
  53. package/dist/esm-node/interfaces/bundler.js +0 -0
  54. package/dist/esm-node/runtime/createRemoteSSRComponent.js +0 -166
  55. package/dist/esm-node/runtime/index.js +0 -12
  56. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  57. package/dist/esm-node/ssr-runtime/index.js +0 -1
  58. package/dist/esm-node/ssr-runtime/plugin.js +0 -34
  59. package/dist/esm-node/types/index.js +0 -0
  60. package/dist/types/cli/configPlugin.d.ts +0 -21
  61. package/dist/types/cli/configPlugin.spec.d.ts +0 -1
  62. package/dist/types/cli/constant.d.ts +0 -1
  63. package/dist/types/cli/index.d.ts +0 -5
  64. package/dist/types/cli/logger.d.ts +0 -2
  65. package/dist/types/cli/manifest.d.ts +0 -2
  66. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +0 -3
  67. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +0 -3
  68. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
  69. package/dist/types/cli/ssrPlugin.d.ts +0 -6
  70. package/dist/types/cli/utils.d.ts +0 -5
  71. package/dist/types/constant.d.ts +0 -2
  72. package/dist/types/interfaces/bundler.d.ts +0 -18
  73. package/dist/types/runtime/createRemoteSSRComponent.d.ts +0 -18
  74. package/dist/types/runtime/index.d.ts +0 -5
  75. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +0 -1
  76. package/dist/types/ssr-runtime/index.d.ts +0 -1
  77. package/dist/types/ssr-runtime/plugin.d.ts +0 -2
  78. package/dist/types/types/index.d.ts +0 -22
@@ -1,201 +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
- function collectSSRAssets(options) {
88
- const { id, injectLink = true, injectScript = true } = 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
- [
110
- ...targetModule.assets.css.sync,
111
- ...targetModule.assets.css.async
112
- ].forEach((file, index) => {
113
- links.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("link", {
114
- href: `${publicPath}${file}`,
115
- rel: "stylesheet",
116
- type: "text/css"
117
- }, `${file.split(".")[0]}_${index}`));
118
- });
119
- }
120
- if (injectScript) {
121
- scripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
122
- async: true,
123
- src: `${publicPath}${remoteEntry}`,
124
- crossOrigin: "anonymous"
125
- }, remoteEntry.split(".")[0]));
126
- [
127
- ...targetModule.assets.js.sync
128
- ].forEach((file, index) => {
129
- scripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
130
- async: true,
131
- src: `${publicPath}${file}`,
132
- crossOrigin: "anonymous"
133
- }, `${file.split(".")[0]}_${index}`));
134
- });
135
- }
136
- return [
137
- ...scripts,
138
- ...links
139
- ];
140
- }
141
- function createRemoteSSRComponent(info) {
142
- const exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
143
- const LazyComponent = /* @__PURE__ */ import_react.default.lazy(async () => {
144
- try {
145
- const m = await info.loader();
146
- if (!m) {
147
- throw new Error("load remote failed");
148
- }
149
- const moduleId = m && m[Symbol.for("mf_module_id")];
150
- const assets = collectSSRAssets({
151
- id: moduleId
152
- });
153
- const Com = m[exportName];
154
- if (exportName in m && typeof Com === "function") {
155
- return {
156
- default: (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
157
- children: [
158
- assets,
159
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Com, {
160
- ...props
161
- })
162
- ]
163
- })
164
- };
165
- } else {
166
- throw Error(`Make sure that ${moduleId} has the correct export when export is ${String(exportName)}`);
167
- }
168
- } catch (err) {
169
- if (!info.fallback) {
170
- throw err;
171
- }
172
- const FallbackFunctionComponent = info.fallback;
173
- const FallbackNode = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FallbackFunctionComponent, {
174
- error: err,
175
- resetErrorBoundary: () => {
176
- console.log('SSR mode not support "resetErrorBoundary" !');
177
- }
178
- });
179
- return {
180
- default: () => FallbackNode
181
- };
182
- }
183
- });
184
- return (props) => {
185
- const { key, ...args } = props;
186
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_error_boundary.ErrorBoundary, {
187
- FallbackComponent: info.fallback,
188
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Suspense, {
189
- fallback: info.loading,
190
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyComponent, {
191
- ...args
192
- })
193
- })
194
- });
195
- };
196
- }
197
- // Annotate the CommonJS export names for ESM import in node:
198
- 0 && (module.exports = {
199
- collectSSRAssets,
200
- createRemoteSSRComponent
201
- });
@@ -1,38 +0,0 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var runtime_exports = {};
21
- __export(runtime_exports, {
22
- kit: () => kit
23
- });
24
- module.exports = __toCommonJS(runtime_exports);
25
- __reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
26
- const kit = {
27
- get createRemoteSSRComponent() {
28
- return require("./createRemoteSSRComponent").createRemoteSSRComponent;
29
- },
30
- get collectSSRAssets() {
31
- return require("./createRemoteSSRComponent").collectSSRAssets;
32
- }
33
- };
34
- // Annotate the CommonJS export names for ESM import in node:
35
- 0 && (module.exports = {
36
- kit,
37
- ...require("@module-federation/enhanced/runtime")
38
- });
@@ -1,43 +0,0 @@
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 SSRLiveReload_exports = {};
20
- __export(SSRLiveReload_exports, {
21
- SSRLiveReload: () => SSRLiveReload
22
- });
23
- module.exports = __toCommonJS(SSRLiveReload_exports);
24
- var import_jsx_runtime = require("react/jsx-runtime");
25
- function SSRLiveReload() {
26
- if (process.env.NODE_ENV !== "development") {
27
- return null;
28
- }
29
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
30
- suppressHydrationWarning: true,
31
- dangerouslySetInnerHTML: {
32
- __html: String.raw`
33
- if(${globalThis.shouldUpdate}){
34
- location.reload();
35
- }
36
- `
37
- }
38
- });
39
- }
40
- // Annotate the CommonJS export names for ESM import in node:
41
- 0 && (module.exports = {
42
- SSRLiveReload
43
- });
@@ -1,22 +0,0 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var ssr_runtime_exports = {};
17
- module.exports = __toCommonJS(ssr_runtime_exports);
18
- __reExport(ssr_runtime_exports, require("./plugin"), module.exports);
19
- // Annotate the CommonJS export names for ESM import in node:
20
- 0 && (module.exports = {
21
- ...require("./plugin")
22
- });
@@ -1,68 +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 plugin_exports = {};
30
- __export(plugin_exports, {
31
- mfSSRPlugin: () => mfSSRPlugin
32
- });
33
- module.exports = __toCommonJS(plugin_exports);
34
- var import_jsx_runtime = require("react/jsx-runtime");
35
- var import_SSRLiveReload = require("./SSRLiveReload");
36
- const mfSSRPlugin = () => ({
37
- name: "@module-federation/modern-js",
38
- setup: (api) => {
39
- api.onBeforeRender(async () => {
40
- if (typeof window !== "undefined") {
41
- return;
42
- }
43
- globalThis.shouldUpdate = false;
44
- const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
45
- const shouldUpdate = await nodeUtils.revalidate();
46
- if (shouldUpdate) {
47
- console.log("should RELOAD", shouldUpdate);
48
- await nodeUtils.flushChunks();
49
- globalThis.shouldUpdate = true;
50
- }
51
- });
52
- api.wrapRoot((App) => {
53
- const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
54
- children: [
55
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SSRLiveReload.SSRLiveReload, {}),
56
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
57
- ...props
58
- })
59
- ]
60
- });
61
- return AppWrapper;
62
- });
63
- }
64
- });
65
- // Annotate the CommonJS export names for ESM import in node:
66
- 0 && (module.exports = {
67
- mfSSRPlugin
68
- });
@@ -1,16 +0,0 @@
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 types_exports = {};
16
- module.exports = __toCommonJS(types_exports);