@module-federation/modern-js 0.0.0-next-20240909092952 → 0.0.0-next-20240909101028

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 (91) hide show
  1. package/dist/cjs/cli/{dataLoader/ast/index.js → constant.js} +6 -6
  2. package/dist/cjs/cli/index.js +1 -5
  3. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
  5. package/dist/cjs/cli/ssrPlugin.js +1 -1
  6. package/dist/cjs/cli/utils.js +4 -8
  7. package/dist/cjs/cli/utils.spec.js +1 -1
  8. package/dist/cjs/constant.js +2 -32
  9. package/dist/cjs/runtime/index.js +1 -4
  10. package/dist/cjs/ssr-runtime/plugin.js +7 -7
  11. package/dist/esm/cli/constant.js +4 -0
  12. package/dist/esm/cli/index.js +1 -4
  13. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
  14. package/dist/esm/cli/ssrPlugin.js +1 -1
  15. package/dist/esm/cli/utils.js +3 -6
  16. package/dist/esm/cli/utils.spec.js +1 -1
  17. package/dist/esm/constant.js +1 -21
  18. package/dist/esm/runtime/index.js +1 -3
  19. package/dist/esm/ssr-runtime/plugin.js +10 -7
  20. package/dist/esm-node/cli/constant.js +4 -0
  21. package/dist/esm-node/cli/index.js +1 -5
  22. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +10 -7
  23. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
  24. package/dist/esm-node/cli/ssrPlugin.js +1 -1
  25. package/dist/esm-node/cli/utils.js +3 -6
  26. package/dist/esm-node/cli/utils.spec.js +1 -1
  27. package/dist/esm-node/constant.js +1 -21
  28. package/dist/esm-node/runtime/index.js +1 -3
  29. package/dist/esm-node/ssr-runtime/plugin.js +7 -7
  30. package/dist/types/cli/constant.d.ts +1 -0
  31. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +2 -2
  32. package/dist/types/cli/utils.d.ts +0 -2
  33. package/dist/types/constant.d.ts +0 -10
  34. package/dist/types/runtime/index.d.ts +0 -1
  35. package/dist/types/types/index.d.ts +0 -9
  36. package/package.json +11 -40
  37. package/dist/cjs/cli/dataLoader/ast/constant.js +0 -49
  38. package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +0 -141
  39. package/dist/cjs/cli/dataLoader/generateRouteFile.js +0 -143
  40. package/dist/cjs/cli/dataLoader/patchMFConfig.js +0 -132
  41. package/dist/cjs/cli/dataLoader/plugin.js +0 -194
  42. package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -44
  43. package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -82
  44. package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -69
  45. package/dist/cjs/interfaces/route.js +0 -16
  46. package/dist/cjs/runtime/dataLoader/plugin.js +0 -73
  47. package/dist/cjs/runtime/dataLoader/utils.js +0 -89
  48. package/dist/cjs/runtime/utils.js +0 -38
  49. package/dist/cjs/runtime/withMFRouteId.js +0 -31
  50. package/dist/esm/cli/dataLoader/ast/constant.js +0 -18
  51. package/dist/esm/cli/dataLoader/ast/generateRoutes.js +0 -108
  52. package/dist/esm/cli/dataLoader/ast/index.js +0 -4
  53. package/dist/esm/cli/dataLoader/generateRouteFile.js +0 -293
  54. package/dist/esm/cli/dataLoader/patchMFConfig.js +0 -98
  55. package/dist/esm/cli/dataLoader/plugin.js +0 -209
  56. package/dist/esm/cli/mfRuntimePlugins/node.js +0 -16
  57. package/dist/esm/cli/server/dataLoaderPlugin.js +0 -105
  58. package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -88
  59. package/dist/esm/interfaces/route.js +0 -0
  60. package/dist/esm/runtime/dataLoader/plugin.js +0 -92
  61. package/dist/esm/runtime/dataLoader/utils.js +0 -63
  62. package/dist/esm/runtime/utils.js +0 -13
  63. package/dist/esm/runtime/withMFRouteId.js +0 -7
  64. package/dist/esm-node/cli/dataLoader/ast/constant.js +0 -18
  65. package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +0 -107
  66. package/dist/esm-node/cli/dataLoader/ast/index.js +0 -4
  67. package/dist/esm-node/cli/dataLoader/generateRouteFile.js +0 -108
  68. package/dist/esm-node/cli/dataLoader/patchMFConfig.js +0 -98
  69. package/dist/esm-node/cli/dataLoader/plugin.js +0 -159
  70. package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -14
  71. package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -62
  72. package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -44
  73. package/dist/esm-node/interfaces/route.js +0 -0
  74. package/dist/esm-node/runtime/dataLoader/plugin.js +0 -49
  75. package/dist/esm-node/runtime/dataLoader/utils.js +0 -63
  76. package/dist/esm-node/runtime/utils.js +0 -13
  77. package/dist/esm-node/runtime/withMFRouteId.js +0 -7
  78. package/dist/types/cli/dataLoader/ast/constant.d.ts +0 -8
  79. package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +0 -5
  80. package/dist/types/cli/dataLoader/ast/index.d.ts +0 -1
  81. package/dist/types/cli/dataLoader/generateRouteFile.d.ts +0 -7
  82. package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -10
  83. package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
  84. package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
  85. package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -10
  86. package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -10
  87. package/dist/types/interfaces/route.d.ts +0 -12
  88. package/dist/types/runtime/dataLoader/plugin.d.ts +0 -2
  89. package/dist/types/runtime/dataLoader/utils.d.ts +0 -19
  90. package/dist/types/runtime/utils.d.ts +0 -2
  91. package/dist/types/runtime/withMFRouteId.d.ts +0 -1
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var ast_exports = {};
20
- __export(ast_exports, {
21
- generateRoutes: () => import_generateRoutes.generateRoutes
19
+ var constant_exports = {};
20
+ __export(constant_exports, {
21
+ isDev: () => isDev
22
22
  });
23
- module.exports = __toCommonJS(ast_exports);
24
- var import_generateRoutes = require("./generateRoutes");
23
+ module.exports = __toCommonJS(constant_exports);
24
+ const isDev = process.env.NODE_ENV === "development";
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
- generateRoutes
27
+ isDev
28
28
  });
@@ -27,7 +27,6 @@ var import_enhanced = require("@module-federation/enhanced");
27
27
  var import_rspack = require("@module-federation/enhanced/rspack");
28
28
  var import_configPlugin = require("./configPlugin");
29
29
  var import_ssrPlugin = require("./ssrPlugin");
30
- var import_plugin = require("./dataLoader/plugin");
31
30
  var import_enhanced2 = require("@module-federation/enhanced");
32
31
  const moduleFederationPlugin = (userConfig = {}) => {
33
32
  const internalModernPluginOptions = {
@@ -80,10 +79,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
80
79
  },
81
80
  usePlugins: [
82
81
  (0, import_configPlugin.moduleFederationConfigPlugin)(internalModernPluginOptions),
83
- (0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions),
84
- (0, import_plugin.moduleFederationDataLoaderPlugin)(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
85
- ...typeof userConfig.dataLoader === "boolean" ? {} : userConfig.dataLoader
86
- })
82
+ (0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions)
87
83
  ]
88
84
  };
89
85
  };
@@ -31,11 +31,14 @@ __export(inject_node_fetch_exports, {
31
31
  default: () => inject_node_fetch_default
32
32
  });
33
33
  module.exports = __toCommonJS(inject_node_fetch_exports);
34
- var import_runtimePlugin = __toESM(require("@module-federation/node/runtimePlugin"));
35
- const isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
36
- const pluginName = `node-plugin-${isContainer}`;
37
- const nodePlugin = () => ({
38
- name: pluginName,
39
- beforeInit: (0, import_runtimePlugin.default)().beforeInit
34
+ var import_node_fetch = __toESM(require("node-fetch"));
35
+ const injectNodeFetchPlugin = () => ({
36
+ name: "inject-node-fetch-plugin",
37
+ beforeInit(args) {
38
+ if (!globalThis.fetch) {
39
+ globalThis.fetch = import_node_fetch.default;
40
+ }
41
+ return args;
42
+ }
40
43
  });
41
- var inject_node_fetch_default = nodePlugin;
44
+ var inject_node_fetch_default = injectNodeFetchPlugin;
@@ -39,46 +39,44 @@ function replaceObjectLocalhost(key, obj) {
39
39
  function replaceLocalhost(url) {
40
40
  return url.replace(import_constant.LOCALHOST, ipv4);
41
41
  }
42
- const resolveEntryIpv4Plugin = () => {
43
- return {
44
- name: "resolve-entry-ipv4",
45
- beforeRegisterRemote(args) {
46
- const { remote } = args;
47
- replaceObjectLocalhost("entry", remote);
48
- return args;
49
- },
50
- async afterResolve(args) {
51
- const { remoteInfo } = args;
52
- replaceObjectLocalhost("entry", remoteInfo);
53
- return args;
54
- },
55
- beforeLoadRemoteSnapshot(args) {
56
- const { moduleInfo } = args;
57
- if ("entry" in moduleInfo) {
58
- replaceObjectLocalhost("entry", moduleInfo);
59
- return args;
60
- }
61
- if ("version" in moduleInfo) {
62
- replaceObjectLocalhost("version", moduleInfo);
63
- }
64
- return args;
65
- },
66
- loadRemoteSnapshot(args) {
67
- const { remoteSnapshot } = args;
68
- if ("publicPath" in remoteSnapshot) {
69
- replaceObjectLocalhost("publicPath", remoteSnapshot);
70
- }
71
- if ("getPublicPath" in remoteSnapshot) {
72
- replaceObjectLocalhost("getPublicPath", remoteSnapshot);
73
- }
74
- if (remoteSnapshot.remotesInfo) {
75
- Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
76
- const remoteInfo = remoteSnapshot.remotesInfo[key];
77
- replaceObjectLocalhost("matchedVersion", remoteInfo);
78
- });
79
- }
42
+ const resolveEntryIpv4Plugin = () => ({
43
+ name: "resolve-entry-ipv4",
44
+ beforeRegisterRemote(args) {
45
+ const { remote } = args;
46
+ replaceObjectLocalhost("entry", remote);
47
+ return args;
48
+ },
49
+ async afterResolve(args) {
50
+ const { remoteInfo } = args;
51
+ replaceObjectLocalhost("entry", remoteInfo);
52
+ return args;
53
+ },
54
+ beforeLoadRemoteSnapshot(args) {
55
+ const { moduleInfo } = args;
56
+ if ("entry" in moduleInfo) {
57
+ replaceObjectLocalhost("entry", moduleInfo);
80
58
  return args;
81
59
  }
82
- };
83
- };
60
+ if ("version" in moduleInfo) {
61
+ replaceObjectLocalhost("version", moduleInfo);
62
+ }
63
+ return args;
64
+ },
65
+ loadRemoteSnapshot(args) {
66
+ const { remoteSnapshot } = args;
67
+ if ("publicPath" in remoteSnapshot) {
68
+ replaceObjectLocalhost("publicPath", remoteSnapshot);
69
+ }
70
+ if ("getPublicPath" in remoteSnapshot) {
71
+ replaceObjectLocalhost("getPublicPath", remoteSnapshot);
72
+ }
73
+ if (remoteSnapshot.remotesInfo) {
74
+ Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
75
+ const remoteInfo = remoteSnapshot.remotesInfo[key];
76
+ replaceObjectLocalhost("matchedVersion", remoteInfo);
77
+ });
78
+ }
79
+ return args;
80
+ }
81
+ });
84
82
  var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
@@ -39,7 +39,7 @@ var import_webpack = require("@module-federation/enhanced/webpack");
39
39
  var import_rspack = require("@module-federation/enhanced/rspack");
40
40
  var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
41
41
  var import_manifest = require("./manifest");
42
- var import_constant = require("../constant");
42
+ var import_constant = require("./constant");
43
43
  function setEnv() {
44
44
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
45
45
  process.env["MF_SSR_PRJ"] = "true";
@@ -32,8 +32,7 @@ __export(utils_exports, {
32
32
  getMFConfig: () => getMFConfig,
33
33
  patchBundlerConfig: () => patchBundlerConfig,
34
34
  patchIgnoreWarning: () => patchIgnoreWarning,
35
- patchMFConfig: () => patchMFConfig,
36
- replaceRemoteUrl: () => replaceRemoteUrl
35
+ patchMFConfig: () => patchMFConfig
37
36
  });
38
37
  module.exports = __toCommonJS(utils_exports);
39
38
  var import_sdk = require("@module-federation/sdk");
@@ -85,9 +84,7 @@ const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
85
84
  if (typeof remoteObject === "string") {
86
85
  return;
87
86
  }
88
- if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
89
- remoteObject.entry = remoteObject.entry.replace(import_constant.LOCALHOST, ipv4);
90
- }
87
+ handleRemoteObject(remoteObject);
91
88
  });
92
89
  } else if (typeof mfConfig.remotes !== "string") {
93
90
  handleRemoteObject(mfConfig.remotes);
@@ -142,7 +139,7 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
142
139
  injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
143
140
  }
144
141
  if (isServer) {
145
- injectRuntimePlugins(require.resolve("./mfRuntimePlugins/node.js"), runtimePlugins);
142
+ injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
146
143
  if (isDev) {
147
144
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
148
145
  }
@@ -332,6 +329,5 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
332
329
  getMFConfig,
333
330
  patchBundlerConfig,
334
331
  patchIgnoreWarning,
335
- patchMFConfig,
336
- replaceRemoteUrl
332
+ patchMFConfig
337
333
  });
@@ -61,7 +61,7 @@ const mfConfig = {
61
61
  remoteType: "script",
62
62
  runtimePlugins: [
63
63
  import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
64
- require.resolve("./mfRuntimePlugins/node.js"),
64
+ require.resolve("@module-federation/node/runtimePlugin"),
65
65
  import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
66
66
  ],
67
67
  shared: {
@@ -18,47 +18,17 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var constant_exports = {};
20
20
  __export(constant_exports, {
21
- DEFAULT_ENTRY: () => DEFAULT_ENTRY,
22
- DEFAULT_LAYOUT: () => DEFAULT_LAYOUT,
23
- FOLD_IDENTIFIER: () => FOLD_IDENTIFIER,
24
21
  LOCALHOST: () => LOCALHOST,
25
- META_NAME: () => META_NAME,
26
- MF_JSON: () => MF_JSON,
27
- MF_ROUTES: () => MF_ROUTES,
28
- MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME: () => MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
29
- MODERN_JS_ROUTE_SERVER_LOADER: () => MODERN_JS_ROUTE_SERVER_LOADER,
30
22
  MODERN_JS_SERVER_DIR: () => MODERN_JS_SERVER_DIR,
31
- PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER,
32
- SEPARATOR: () => SEPARATOR,
33
- isDev: () => isDev
23
+ PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
34
24
  });
35
25
  module.exports = __toCommonJS(constant_exports);
36
26
  const MODERN_JS_SERVER_DIR = "bundles";
37
27
  const LOCALHOST = "localhost";
38
28
  const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
39
- const isDev = process.env.NODE_ENV === "development";
40
- const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
41
- const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
42
- const META_NAME = "modern-js";
43
- const FOLD_IDENTIFIER = "@mf";
44
- const SEPARATOR = "_";
45
- const MF_ROUTES = "mf-routes";
46
- const DEFAULT_ENTRY = "main";
47
- const DEFAULT_LAYOUT = "layout";
48
- const MF_JSON = "mf.json";
49
29
  // Annotate the CommonJS export names for ESM import in node:
50
30
  0 && (module.exports = {
51
- DEFAULT_ENTRY,
52
- DEFAULT_LAYOUT,
53
- FOLD_IDENTIFIER,
54
31
  LOCALHOST,
55
- META_NAME,
56
- MF_JSON,
57
- MF_ROUTES,
58
- MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
59
- MODERN_JS_ROUTE_SERVER_LOADER,
60
32
  MODERN_JS_SERVER_DIR,
61
- PLUGIN_IDENTIFIER,
62
- SEPARATOR,
63
- isDev
33
+ PLUGIN_IDENTIFIER
64
34
  });
@@ -19,16 +19,13 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var runtime_exports = {};
21
21
  __export(runtime_exports, {
22
- createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent,
23
- withMFRouteId: () => import_withMFRouteId.withMFRouteId
22
+ createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
24
23
  });
25
24
  module.exports = __toCommonJS(runtime_exports);
26
25
  __reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
27
26
  var import_createRemoteSSRComponent = require("./createRemoteSSRComponent");
28
- var import_withMFRouteId = require("./withMFRouteId");
29
27
  // Annotate the CommonJS export names for ESM import in node:
30
28
  0 && (module.exports = {
31
29
  createRemoteSSRComponent,
32
- withMFRouteId,
33
30
  ...require("@module-federation/enhanced/runtime")
34
31
  });
@@ -34,17 +34,15 @@ module.exports = __toCommonJS(plugin_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
36
36
  var import_SSRLiveReload = require("./SSRLiveReload");
37
- console.log("mfSSRPlugin trigger");
38
37
  const mfSSRPlugin = () => ({
39
38
  name: "@module-federation/modern-js",
40
- pre: [
41
- "@modern-js/plugin-router"
42
- ],
43
39
  setup: () => {
44
40
  return {
45
- async beforeRender() {
41
+ async init({ context }, next) {
46
42
  if (typeof window !== "undefined") {
47
- return;
43
+ return next({
44
+ context
45
+ });
48
46
  }
49
47
  globalThis.shouldUpdate = false;
50
48
  const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
@@ -54,7 +52,9 @@ const mfSSRPlugin = () => ({
54
52
  await nodeUtils.flushChunks();
55
53
  globalThis.shouldUpdate = true;
56
54
  }
57
- return;
55
+ return next({
56
+ context
57
+ });
58
58
  },
59
59
  wrapRoot(App) {
60
60
  const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
@@ -0,0 +1,4 @@
1
+ var isDev = process.env.NODE_ENV === "development";
2
+ export {
3
+ isDev
4
+ };
@@ -1,11 +1,9 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
3
  import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
5
4
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
6
5
  import { moduleFederationConfigPlugin } from "./configPlugin";
7
6
  import { moduleFederationSSRPlugin } from "./ssrPlugin";
8
- import { moduleFederationDataLoaderPlugin } from "./dataLoader/plugin";
9
7
  var moduleFederationPlugin = function() {
10
8
  var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
11
9
  var internalModernPluginOptions = {
@@ -81,8 +79,7 @@ var moduleFederationPlugin = function() {
81
79
  }(),
82
80
  usePlugins: [
83
81
  moduleFederationConfigPlugin(internalModernPluginOptions),
84
- moduleFederationSSRPlugin(internalModernPluginOptions),
85
- moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, _object_spread({}, typeof userConfig.dataLoader === "boolean" ? {} : userConfig.dataLoader))
82
+ moduleFederationSSRPlugin(internalModernPluginOptions)
86
83
  ]
87
84
  };
88
85
  };
@@ -1,13 +1,16 @@
1
- import nodeRuntimePlugin from "@module-federation/node/runtimePlugin";
2
- var isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
3
- var pluginName = "node-plugin-".concat(isContainer);
4
- var nodePlugin = function() {
1
+ import nodeFetch from "node-fetch";
2
+ var injectNodeFetchPlugin = function() {
5
3
  return {
6
- name: pluginName,
7
- beforeInit: nodeRuntimePlugin().beforeInit
4
+ name: "inject-node-fetch-plugin",
5
+ beforeInit: function beforeInit(args) {
6
+ if (!globalThis.fetch) {
7
+ globalThis.fetch = nodeFetch;
8
+ }
9
+ return args;
10
+ }
8
11
  };
9
12
  };
10
- var inject_node_fetch_default = nodePlugin;
13
+ var inject_node_fetch_default = injectNodeFetchPlugin;
11
14
  export {
12
15
  inject_node_fetch_default as default
13
16
  };
@@ -6,7 +6,7 @@ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
6
6
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
7
7
  import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
8
8
  import { updateStatsAndManifest } from "./manifest";
9
- import { isDev } from "../constant";
9
+ import { isDev } from "./constant";
10
10
  function setEnv() {
11
11
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
12
12
  process.env["MF_SSR_PRJ"] = "true";
@@ -79,9 +79,7 @@ var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
79
79
  if (typeof remoteObject === "string") {
80
80
  return;
81
81
  }
82
- if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
83
- remoteObject.entry = remoteObject.entry.replace(LOCALHOST, ipv4);
84
- }
82
+ handleRemoteObject(remoteObject);
85
83
  });
86
84
  } else if (typeof mfConfig.remotes !== "string") {
87
85
  handleRemoteObject(mfConfig.remotes);
@@ -134,7 +132,7 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
134
132
  injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
135
133
  }
136
134
  if (isServer) {
137
- injectRuntimePlugins(require.resolve("./mfRuntimePlugins/node.js"), runtimePlugins);
135
+ injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
138
136
  if (isDev) {
139
137
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
140
138
  }
@@ -341,6 +339,5 @@ export {
341
339
  getMFConfig,
342
340
  patchBundlerConfig,
343
341
  patchIgnoreWarning,
344
- patchMFConfig,
345
- replaceRemoteUrl
342
+ patchMFConfig
346
343
  };
@@ -43,7 +43,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
43
43
  remoteType: "script",
44
44
  runtimePlugins: [
45
45
  path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
46
- require.resolve("./mfRuntimePlugins/node.js"),
46
+ require.resolve("@module-federation/node/runtimePlugin"),
47
47
  path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
48
48
  ],
49
49
  shared: {
@@ -1,28 +1,8 @@
1
1
  var MODERN_JS_SERVER_DIR = "bundles";
2
2
  var LOCALHOST = "localhost";
3
3
  var PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
4
- var isDev = process.env.NODE_ENV === "development";
5
- var MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
6
- var MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
7
- var META_NAME = "modern-js";
8
- var FOLD_IDENTIFIER = "@mf";
9
- var SEPARATOR = "_";
10
- var MF_ROUTES = "mf-routes";
11
- var DEFAULT_ENTRY = "main";
12
- var DEFAULT_LAYOUT = "layout";
13
- var MF_JSON = "mf.json";
14
4
  export {
15
- DEFAULT_ENTRY,
16
- DEFAULT_LAYOUT,
17
- FOLD_IDENTIFIER,
18
5
  LOCALHOST,
19
- META_NAME,
20
- MF_JSON,
21
- MF_ROUTES,
22
- MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
23
- MODERN_JS_ROUTE_SERVER_LOADER,
24
6
  MODERN_JS_SERVER_DIR,
25
- PLUGIN_IDENTIFIER,
26
- SEPARATOR,
27
- isDev
7
+ PLUGIN_IDENTIFIER
28
8
  };
@@ -1,7 +1,5 @@
1
1
  export * from "@module-federation/enhanced/runtime";
2
2
  import { createRemoteSSRComponent } from "./createRemoteSSRComponent";
3
- import { withMFRouteId } from "./withMFRouteId";
4
3
  export {
5
- createRemoteSSRComponent,
6
- withMFRouteId
4
+ createRemoteSSRComponent
7
5
  };
@@ -4,16 +4,13 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
5
5
  import hoistNonReactStatics from "hoist-non-react-statics";
6
6
  import { SSRLiveReload } from "./SSRLiveReload";
7
- console.log("mfSSRPlugin trigger");
8
7
  var mfSSRPlugin = function() {
9
8
  return {
10
9
  name: "@module-federation/modern-js",
11
- pre: [
12
- "@modern-js/plugin-router"
13
- ],
14
10
  setup: function() {
15
11
  return {
16
- beforeRender: function beforeRender() {
12
+ init: function init(param, next) {
13
+ var context = param.context;
17
14
  return _async_to_generator(function() {
18
15
  var nodeUtils, shouldUpdate;
19
16
  return _ts_generator(this, function(_state) {
@@ -21,7 +18,10 @@ var mfSSRPlugin = function() {
21
18
  case 0:
22
19
  if (typeof window !== "undefined") {
23
20
  return [
24
- 2
21
+ 2,
22
+ next({
23
+ context
24
+ })
25
25
  ];
26
26
  }
27
27
  globalThis.shouldUpdate = false;
@@ -53,7 +53,10 @@ var mfSSRPlugin = function() {
53
53
  _state.label = 4;
54
54
  case 4:
55
55
  return [
56
- 2
56
+ 2,
57
+ next({
58
+ context
59
+ })
57
60
  ];
58
61
  }
59
62
  });
@@ -0,0 +1,4 @@
1
+ const isDev = process.env.NODE_ENV === "development";
2
+ export {
3
+ isDev
4
+ };
@@ -2,7 +2,6 @@ import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryP
2
2
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
3
3
  import { moduleFederationConfigPlugin } from "./configPlugin";
4
4
  import { moduleFederationSSRPlugin } from "./ssrPlugin";
5
- import { moduleFederationDataLoaderPlugin } from "./dataLoader/plugin";
6
5
  const moduleFederationPlugin = (userConfig = {}) => {
7
6
  const internalModernPluginOptions = {
8
7
  csrConfig: void 0,
@@ -54,10 +53,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
54
53
  },
55
54
  usePlugins: [
56
55
  moduleFederationConfigPlugin(internalModernPluginOptions),
57
- moduleFederationSSRPlugin(internalModernPluginOptions),
58
- moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
59
- ...typeof userConfig.dataLoader === "boolean" ? {} : userConfig.dataLoader
60
- })
56
+ moduleFederationSSRPlugin(internalModernPluginOptions)
61
57
  ]
62
58
  };
63
59
  };
@@ -1,11 +1,14 @@
1
- import nodeRuntimePlugin from "@module-federation/node/runtimePlugin";
2
- const isContainer = typeof __filename === "string" ? __filename.includes("remote") ? true : false : false;
3
- const pluginName = `node-plugin-${isContainer}`;
4
- const nodePlugin = () => ({
5
- name: pluginName,
6
- beforeInit: nodeRuntimePlugin().beforeInit
1
+ import nodeFetch from "node-fetch";
2
+ const injectNodeFetchPlugin = () => ({
3
+ name: "inject-node-fetch-plugin",
4
+ beforeInit(args) {
5
+ if (!globalThis.fetch) {
6
+ globalThis.fetch = nodeFetch;
7
+ }
8
+ return args;
9
+ }
7
10
  });
8
- var inject_node_fetch_default = nodePlugin;
11
+ var inject_node_fetch_default = injectNodeFetchPlugin;
9
12
  export {
10
13
  inject_node_fetch_default as default
11
14
  };
@@ -16,48 +16,46 @@ function replaceObjectLocalhost(key, obj) {
16
16
  function replaceLocalhost(url) {
17
17
  return url.replace(LOCALHOST, ipv4);
18
18
  }
19
- const resolveEntryIpv4Plugin = () => {
20
- return {
21
- name: "resolve-entry-ipv4",
22
- beforeRegisterRemote(args) {
23
- const { remote } = args;
24
- replaceObjectLocalhost("entry", remote);
25
- return args;
26
- },
27
- async afterResolve(args) {
28
- const { remoteInfo } = args;
29
- replaceObjectLocalhost("entry", remoteInfo);
30
- return args;
31
- },
32
- beforeLoadRemoteSnapshot(args) {
33
- const { moduleInfo } = args;
34
- if ("entry" in moduleInfo) {
35
- replaceObjectLocalhost("entry", moduleInfo);
36
- return args;
37
- }
38
- if ("version" in moduleInfo) {
39
- replaceObjectLocalhost("version", moduleInfo);
40
- }
41
- return args;
42
- },
43
- loadRemoteSnapshot(args) {
44
- const { remoteSnapshot } = args;
45
- if ("publicPath" in remoteSnapshot) {
46
- replaceObjectLocalhost("publicPath", remoteSnapshot);
47
- }
48
- if ("getPublicPath" in remoteSnapshot) {
49
- replaceObjectLocalhost("getPublicPath", remoteSnapshot);
50
- }
51
- if (remoteSnapshot.remotesInfo) {
52
- Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
53
- const remoteInfo = remoteSnapshot.remotesInfo[key];
54
- replaceObjectLocalhost("matchedVersion", remoteInfo);
55
- });
56
- }
19
+ const resolveEntryIpv4Plugin = () => ({
20
+ name: "resolve-entry-ipv4",
21
+ beforeRegisterRemote(args) {
22
+ const { remote } = args;
23
+ replaceObjectLocalhost("entry", remote);
24
+ return args;
25
+ },
26
+ async afterResolve(args) {
27
+ const { remoteInfo } = args;
28
+ replaceObjectLocalhost("entry", remoteInfo);
29
+ return args;
30
+ },
31
+ beforeLoadRemoteSnapshot(args) {
32
+ const { moduleInfo } = args;
33
+ if ("entry" in moduleInfo) {
34
+ replaceObjectLocalhost("entry", moduleInfo);
57
35
  return args;
58
36
  }
59
- };
60
- };
37
+ if ("version" in moduleInfo) {
38
+ replaceObjectLocalhost("version", moduleInfo);
39
+ }
40
+ return args;
41
+ },
42
+ loadRemoteSnapshot(args) {
43
+ const { remoteSnapshot } = args;
44
+ if ("publicPath" in remoteSnapshot) {
45
+ replaceObjectLocalhost("publicPath", remoteSnapshot);
46
+ }
47
+ if ("getPublicPath" in remoteSnapshot) {
48
+ replaceObjectLocalhost("getPublicPath", remoteSnapshot);
49
+ }
50
+ if (remoteSnapshot.remotesInfo) {
51
+ Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
52
+ const remoteInfo = remoteSnapshot.remotesInfo[key];
53
+ replaceObjectLocalhost("matchedVersion", remoteInfo);
54
+ });
55
+ }
56
+ return args;
57
+ }
58
+ });
61
59
  var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
62
60
  export {
63
61
  resolve_entry_ipv4_default as default
@@ -4,7 +4,7 @@ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
4
4
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
5
5
  import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
6
6
  import { updateStatsAndManifest } from "./manifest";
7
- import { isDev } from "../constant";
7
+ import { isDev } from "./constant";
8
8
  function setEnv() {
9
9
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
10
10
  process.env["MF_SSR_PRJ"] = "true";