@module-federation/modern-js 0.0.0-next-20240814085621 → 0.0.0-next-20240815093707

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 (66) hide show
  1. package/dist/cjs/cli/configPlugin.js +0 -1
  2. package/dist/cjs/cli/constant.js +0 -6
  3. package/dist/cjs/cli/index.js +1 -6
  4. package/dist/cjs/cli/ssrPlugin.js +4 -4
  5. package/dist/cjs/runtime/index.js +1 -4
  6. package/dist/cjs/ssr-runtime/plugin.js +7 -5
  7. package/dist/esm/cli/configPlugin.js +0 -1
  8. package/dist/esm/cli/constant.js +0 -4
  9. package/dist/esm/cli/index.js +1 -6
  10. package/dist/esm/cli/ssrPlugin.js +2 -2
  11. package/dist/esm/runtime/index.js +1 -3
  12. package/dist/esm/ssr-runtime/plugin.js +10 -5
  13. package/dist/esm-node/cli/configPlugin.js +0 -1
  14. package/dist/esm-node/cli/constant.js +0 -4
  15. package/dist/esm-node/cli/index.js +1 -6
  16. package/dist/esm-node/cli/ssrPlugin.js +2 -2
  17. package/dist/esm-node/runtime/index.js +1 -3
  18. package/dist/esm-node/ssr-runtime/plugin.js +7 -5
  19. package/dist/types/cli/constant.d.ts +0 -2
  20. package/dist/types/runtime/index.d.ts +0 -1
  21. package/dist/types/types/index.d.ts +0 -17
  22. package/package.json +11 -37
  23. package/dist/cjs/cli/ast/constant.js +0 -46
  24. package/dist/cjs/cli/ast/generateRoutes.js +0 -140
  25. package/dist/cjs/cli/ast/generateSlimRoutes.js +0 -106
  26. package/dist/cjs/cli/ast/index.js +0 -31
  27. package/dist/cjs/cli/dataLoaderPlugin.js +0 -221
  28. package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -78
  29. package/dist/cjs/interfaces/route.js +0 -16
  30. package/dist/cjs/runtime/constant.js +0 -34
  31. package/dist/cjs/runtime/dataLoader.js +0 -87
  32. package/dist/cjs/runtime/utils.js +0 -43
  33. package/dist/cjs/runtime/withMFRouteId.js +0 -31
  34. package/dist/esm/cli/ast/constant.js +0 -16
  35. package/dist/esm/cli/ast/generateRoutes.js +0 -107
  36. package/dist/esm/cli/ast/generateSlimRoutes.js +0 -75
  37. package/dist/esm/cli/ast/index.js +0 -6
  38. package/dist/esm/cli/dataLoaderPlugin.js +0 -208
  39. package/dist/esm/cli/server/dataLoaderPlugin.js +0 -122
  40. package/dist/esm/interfaces/route.js +0 -0
  41. package/dist/esm/runtime/constant.js +0 -8
  42. package/dist/esm/runtime/dataLoader.js +0 -125
  43. package/dist/esm/runtime/utils.js +0 -16
  44. package/dist/esm/runtime/withMFRouteId.js +0 -7
  45. package/dist/esm-node/cli/ast/constant.js +0 -16
  46. package/dist/esm-node/cli/ast/generateRoutes.js +0 -106
  47. package/dist/esm-node/cli/ast/generateSlimRoutes.js +0 -72
  48. package/dist/esm-node/cli/ast/index.js +0 -6
  49. package/dist/esm-node/cli/dataLoaderPlugin.js +0 -185
  50. package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -58
  51. package/dist/esm-node/interfaces/route.js +0 -0
  52. package/dist/esm-node/runtime/constant.js +0 -8
  53. package/dist/esm-node/runtime/dataLoader.js +0 -63
  54. package/dist/esm-node/runtime/utils.js +0 -19
  55. package/dist/esm-node/runtime/withMFRouteId.js +0 -7
  56. package/dist/types/cli/ast/constant.d.ts +0 -7
  57. package/dist/types/cli/ast/generateRoutes.d.ts +0 -7
  58. package/dist/types/cli/ast/generateSlimRoutes.d.ts +0 -7
  59. package/dist/types/cli/ast/index.d.ts +0 -2
  60. package/dist/types/cli/dataLoaderPlugin.d.ts +0 -6
  61. package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -5
  62. package/dist/types/interfaces/route.d.ts +0 -13
  63. package/dist/types/runtime/constant.d.ts +0 -3
  64. package/dist/types/runtime/dataLoader.d.ts +0 -7
  65. package/dist/types/runtime/utils.d.ts +0 -1
  66. package/dist/types/runtime/withMFRouteId.d.ts +0 -1
@@ -68,7 +68,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
68
68
  return {
69
69
  config: async () => {
70
70
  var _modernjsConfig_server, _modernjsConfig_dev;
71
- console.log("config plugin config");
72
71
  const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
73
72
  const ipv4 = (0, import_utils.getIPV4)();
74
73
  const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
@@ -18,17 +18,11 @@ 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
- META_NAME: () => META_NAME,
22
- MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME: () => MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
23
21
  isDev: () => isDev
24
22
  });
25
23
  module.exports = __toCommonJS(constant_exports);
26
24
  const isDev = process.env.NODE_ENV === "development";
27
- const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
28
- const META_NAME = "modern-js";
29
25
  // Annotate the CommonJS export names for ESM import in node:
30
26
  0 && (module.exports = {
31
- META_NAME,
32
- MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
33
27
  isDev
34
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_dataLoaderPlugin = require("./dataLoaderPlugin");
31
30
  var import_enhanced2 = require("@module-federation/enhanced");
32
31
  const moduleFederationPlugin = (userConfig = {}) => {
33
32
  const internalModernPluginOptions = {
@@ -80,11 +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_dataLoaderPlugin.moduleFederationDataLoaderPlugin)(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
85
- baseName: "",
86
- ...userConfig.dataLoader
87
- })
82
+ (0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions)
88
83
  ]
89
84
  };
90
85
  };
@@ -35,9 +35,9 @@ __export(ssrPlugin_exports, {
35
35
  module.exports = __toCommonJS(ssrPlugin_exports);
36
36
  var import_path = __toESM(require("path"));
37
37
  var import_utils = require("@modern-js/utils");
38
- var import_enhanced = require("@module-federation/enhanced");
38
+ var import_webpack = require("@module-federation/enhanced/webpack");
39
39
  var import_rspack = require("@module-federation/enhanced/rspack");
40
- var import_node = require("@module-federation/node");
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
42
  var import_constant = require("./constant");
43
43
  function setEnv() {
@@ -101,7 +101,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
101
101
  if (isServer) {
102
102
  if (!userConfig.nodePlugin) {
103
103
  var _config_plugins;
104
- userConfig.nodePlugin = new import_enhanced.ModuleFederationPlugin(userConfig.ssrConfig);
104
+ userConfig.nodePlugin = new import_webpack.ModuleFederationPlugin(userConfig.ssrConfig);
105
105
  (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
106
106
  }
107
107
  } else {
@@ -141,7 +141,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
141
141
  if (isServer) {
142
142
  chain.target("async-node");
143
143
  if (import_constant.isDev) {
144
- chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_node.UniverseEntryChunkTrackerPlugin);
144
+ chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
145
145
  }
146
146
  }
147
147
  if (import_constant.isDev && !isServer) {
@@ -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,15 +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
39
  setup: () => {
41
40
  return {
42
- async beforeRender() {
43
- console.log(111, "beforeRender");
41
+ async init({ context }, next) {
44
42
  if (typeof window !== "undefined") {
45
- return;
43
+ return next({
44
+ context
45
+ });
46
46
  }
47
47
  globalThis.shouldUpdate = false;
48
48
  const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
@@ -52,7 +52,9 @@ const mfSSRPlugin = () => ({
52
52
  await nodeUtils.flushChunks();
53
53
  globalThis.shouldUpdate = true;
54
54
  }
55
- return;
55
+ return next({
56
+ context
57
+ });
56
58
  },
57
59
  wrapRoot(App) {
58
60
  const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
@@ -49,7 +49,6 @@ var moduleFederationConfigPlugin = function(userConfig) {
49
49
  config: /* @__PURE__ */ _async_to_generator(function() {
50
50
  var _modernjsConfig_server, _modernjsConfig_dev, bundlerType, ipv4, enableSSR;
51
51
  return _ts_generator(this, function(_state2) {
52
- console.log("config plugin config");
53
52
  bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
54
53
  ipv4 = getIPV4();
55
54
  enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
@@ -1,8 +1,4 @@
1
1
  var isDev = process.env.NODE_ENV === "development";
2
- var MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
3
- var META_NAME = "modern-js";
4
2
  export {
5
- META_NAME,
6
- MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
7
3
  isDev
8
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 "./dataLoaderPlugin";
9
7
  var moduleFederationPlugin = function() {
10
8
  var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
11
9
  var internalModernPluginOptions = {
@@ -81,10 +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({
86
- baseName: ""
87
- }, userConfig.dataLoader))
82
+ moduleFederationSSRPlugin(internalModernPluginOptions)
88
83
  ]
89
84
  };
90
85
  };
@@ -2,9 +2,9 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "path";
4
4
  import { fs } from "@modern-js/utils";
5
- import { ModuleFederationPlugin } from "@module-federation/enhanced";
5
+ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
6
6
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
7
- import { UniverseEntryChunkTrackerPlugin } from "@module-federation/node";
7
+ import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
8
8
  import { updateStatsAndManifest } from "./manifest";
9
9
  import { isDev } from "./constant";
10
10
  function setEnv() {
@@ -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,22 +4,24 @@ 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
10
  setup: function() {
12
11
  return {
13
- beforeRender: function beforeRender() {
12
+ init: function init(param, next) {
13
+ var context = param.context;
14
14
  return _async_to_generator(function() {
15
15
  var nodeUtils, shouldUpdate;
16
16
  return _ts_generator(this, function(_state) {
17
17
  switch (_state.label) {
18
18
  case 0:
19
- console.log(111, "beforeRender");
20
19
  if (typeof window !== "undefined") {
21
20
  return [
22
- 2
21
+ 2,
22
+ next({
23
+ context
24
+ })
23
25
  ];
24
26
  }
25
27
  globalThis.shouldUpdate = false;
@@ -51,7 +53,10 @@ var mfSSRPlugin = function() {
51
53
  _state.label = 4;
52
54
  case 4:
53
55
  return [
54
- 2
56
+ 2,
57
+ next({
58
+ context
59
+ })
55
60
  ];
56
61
  }
57
62
  });
@@ -32,7 +32,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
32
32
  return {
33
33
  config: async () => {
34
34
  var _modernjsConfig_server, _modernjsConfig_dev;
35
- console.log("config plugin config");
36
35
  const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
37
36
  const ipv4 = getIPV4();
38
37
  const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
@@ -1,8 +1,4 @@
1
1
  const isDev = process.env.NODE_ENV === "development";
2
- const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
3
- const META_NAME = "modern-js";
4
2
  export {
5
- META_NAME,
6
- MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
7
3
  isDev
8
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 "./dataLoaderPlugin";
6
5
  const moduleFederationPlugin = (userConfig = {}) => {
7
6
  const internalModernPluginOptions = {
8
7
  csrConfig: void 0,
@@ -54,11 +53,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
54
53
  },
55
54
  usePlugins: [
56
55
  moduleFederationConfigPlugin(internalModernPluginOptions),
57
- moduleFederationSSRPlugin(internalModernPluginOptions),
58
- moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
59
- baseName: "",
60
- ...userConfig.dataLoader
61
- })
56
+ moduleFederationSSRPlugin(internalModernPluginOptions)
62
57
  ]
63
58
  };
64
59
  };
@@ -1,8 +1,8 @@
1
1
  import path from "path";
2
2
  import { fs } from "@modern-js/utils";
3
- import { ModuleFederationPlugin } from "@module-federation/enhanced";
3
+ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
4
4
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
5
- import { UniverseEntryChunkTrackerPlugin } from "@module-federation/node";
5
+ import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
6
6
  import { updateStatsAndManifest } from "./manifest";
7
7
  import { isDev } from "./constant";
8
8
  function setEnv() {
@@ -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
  };
@@ -1,15 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import hoistNonReactStatics from "hoist-non-react-statics";
3
3
  import { SSRLiveReload } from "./SSRLiveReload";
4
- console.log("mfSSRPlugin trigger");
5
4
  const mfSSRPlugin = () => ({
6
5
  name: "@module-federation/modern-js",
7
6
  setup: () => {
8
7
  return {
9
- async beforeRender() {
10
- console.log(111, "beforeRender");
8
+ async init({ context }, next) {
11
9
  if (typeof window !== "undefined") {
12
- return;
10
+ return next({
11
+ context
12
+ });
13
13
  }
14
14
  globalThis.shouldUpdate = false;
15
15
  const nodeUtils = await import("@module-federation/node/utils");
@@ -19,7 +19,9 @@ const mfSSRPlugin = () => ({
19
19
  await nodeUtils.flushChunks();
20
20
  globalThis.shouldUpdate = true;
21
21
  }
22
- return;
22
+ return next({
23
+ context
24
+ });
23
25
  },
24
26
  wrapRoot(App) {
25
27
  const AppWrapper = (props) => /* @__PURE__ */ _jsxs(_Fragment, {
@@ -1,3 +1 @@
1
1
  export declare const isDev: boolean;
2
- export declare const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
3
- export declare const META_NAME = "modern-js";
@@ -1,3 +1,2 @@
1
1
  export * from '@module-federation/enhanced/runtime';
2
2
  export { createRemoteSSRComponent } from './createRemoteSSRComponent';
3
- export { withMFRouteId } from './withMFRouteId';
@@ -1,12 +1,10 @@
1
1
  import { moduleFederationPlugin } from '@module-federation/sdk';
2
2
  import type { ModuleFederationPlugin as WebpackModuleFederationPlugin } from '@module-federation/enhanced';
3
3
  import type { ModuleFederationPlugin as RspackModuleFederationPlugin } from '@module-federation/enhanced/rspack';
4
- import type { init } from '@module-federation/enhanced/runtime';
5
4
  export interface PluginOptions {
6
5
  config?: moduleFederationPlugin.ModuleFederationPluginOptions;
7
6
  configPath?: string;
8
7
  remoteIpStrategy?: 'ipv4' | 'inherit';
9
- dataLoader?: false | Pick<DataLoaderOptions, 'baseName' | 'partialSSRRemotes'>;
10
8
  }
11
9
  export interface InternalModernPluginOptions {
12
10
  csrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
@@ -18,18 +16,3 @@ export interface InternalModernPluginOptions {
18
16
  remoteIpStrategy?: 'ipv4' | 'inherit';
19
17
  }
20
18
  export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
21
- export type DataLoaderOptions = {
22
- baseName: string;
23
- partialSSRRemotes?: string[];
24
- metaName?: string;
25
- serverPlugin?: string;
26
- transformRuntimeOptions?: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => Parameters<typeof init>[0];
27
- fetchSSRByRouteIds?: (partialSSRRemotes: string[], mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => Promise<string[] | undefined>;
28
- patchMFConfig?: (options: {
29
- mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
30
- baseName: string;
31
- metaName: string;
32
- isServer: boolean;
33
- routesFilePath: string;
34
- }) => void;
35
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20240814085621",
3
+ "version": "0.0.0-next-20240815093707",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -23,19 +23,6 @@
23
23
  "types": "./dist/types/ssr-runtime/index.d.ts",
24
24
  "default": "./dist/esm/ssr-runtime/index.js"
25
25
  },
26
- "./data-loader": {
27
- "types": "./dist/types/runtime/dataLoader.d.ts",
28
- "default": "./dist/esm/runtime/dataLoader.js"
29
- },
30
- "./data-loader-server": {
31
- "types": "./dist/types/cli/server/dataLoaderPlugin.d.ts",
32
- "default": "./dist/cjs/cli/server/dataLoaderPlugin.js"
33
- },
34
- "./data-loader-plugin": {
35
- "import": "./dist/esm/cli/dataLoaderPlugin.js",
36
- "require": "./dist/cjs/cli/dataLoaderPlugin.js",
37
- "types": "./dist/types/cli/dataLoaderPlugin.d.ts"
38
- },
39
26
  "./config-plugin": {
40
27
  "import": "./dist/esm/cli/configPlugin.js",
41
28
  "require": "./dist/cjs/cli/configPlugin.js",
@@ -60,12 +47,6 @@
60
47
  ],
61
48
  "ssr-plugin": [
62
49
  "./dist/types/cli/ssrPlugin.d.ts"
63
- ],
64
- "data-loader-plugin": [
65
- "./dist/types/cli/dataLoaderPlugin.d.ts"
66
- ],
67
- "data-loader": [
68
- "./dist/types/runtime/dataLoader.d.ts"
69
50
  ]
70
51
  }
71
52
  },
@@ -74,31 +55,24 @@
74
55
  "author": "hanric <hanric.zhang@gmail.com>",
75
56
  "license": "MIT",
76
57
  "dependencies": {
77
- "@swc/helpers": "0.5.3",
58
+ "@swc/helpers": "0.5.12",
78
59
  "@modern-js/utils": "2.54.2",
79
60
  "@modern-js/node-bundle-require": "2.54.2",
80
61
  "node-fetch": "~3.3.0",
81
62
  "react-error-boundary": "4.0.13",
82
63
  "hoist-non-react-statics": "3.3.2",
83
- "@babel/generator": "7.25.0",
84
- "@babel/parser": "7.25.3",
85
- "@babel/traverse": "7.25.3",
86
- "@babel/types": "7.25.2",
87
- "@module-federation/sdk": "0.0.0-next-20240814085621",
88
- "@module-federation/enhanced": "0.0.0-next-20240814085621",
89
- "@module-federation/node": "0.0.0-next-20240814085621"
64
+ "@module-federation/sdk": "0.0.0-next-20240815093707",
65
+ "@module-federation/enhanced": "0.0.0-next-20240815093707",
66
+ "@module-federation/node": "0.0.0-next-20240815093707"
90
67
  },
91
68
  "devDependencies": {
92
- "@types/babel__traverse": "7.20.6",
93
- "@types/babel__generator": "7.6.8",
94
69
  "@types/hoist-non-react-statics": "3.3.2",
95
- "@modern-js/server-core": "0.0.0-next-20240814063139",
96
- "@modern-js/app-tools": "0.0.0-next-20240814063139",
97
- "@modern-js/core": "0.0.0-next-20240814063139",
98
- "@modern-js/runtime": "0.0.0-next-20240814063139",
99
- "@modern-js/module-tools": "0.0.0-next-20240814063139",
100
- "@modern-js/tsconfig": "0.0.0-next-20240814063139",
101
- "@module-federation/manifest": "0.0.0-next-20240814085621"
70
+ "@modern-js/app-tools": "2.57.0",
71
+ "@modern-js/core": "2.57.0",
72
+ "@modern-js/runtime": "2.57.0",
73
+ "@modern-js/module-tools": "2.57.0",
74
+ "@modern-js/tsconfig": "2.57.0",
75
+ "@module-federation/manifest": "0.0.0-next-20240815093707"
102
76
  },
103
77
  "peerDependencies": {
104
78
  "react": ">=17",
@@ -1,46 +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 constant_exports = {};
20
- __export(constant_exports, {
21
- COMPONENT: () => COMPONENT,
22
- ELEMENT: () => ELEMENT,
23
- ID: () => ID,
24
- IS_ROOT: () => IS_ROOT,
25
- LAZY_COMPONENT: () => LAZY_COMPONENT,
26
- PRIVATE_COMPONENT: () => PRIVATE_COMPONENT,
27
- SHOULD_REVALIDATE: () => SHOULD_REVALIDATE
28
- });
29
- module.exports = __toCommonJS(constant_exports);
30
- const IS_ROOT = "isRoot";
31
- const ID = "id";
32
- const COMPONENT = "component";
33
- const LAZY_COMPONENT = "lazyImport";
34
- const SHOULD_REVALIDATE = "shouldRevalidate";
35
- const PRIVATE_COMPONENT = "_component";
36
- const ELEMENT = "element";
37
- // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {
39
- COMPONENT,
40
- ELEMENT,
41
- ID,
42
- IS_ROOT,
43
- LAZY_COMPONENT,
44
- PRIVATE_COMPONENT,
45
- SHOULD_REVALIDATE
46
- });
@@ -1,140 +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 generateRoutes_exports = {};
30
- __export(generateRoutes_exports, {
31
- generateRoutes: () => generateRoutes
32
- });
33
- module.exports = __toCommonJS(generateRoutes_exports);
34
- var import_fs = __toESM(require("fs"));
35
- var import_traverse = __toESM(require("@babel/traverse"));
36
- var babelParser = __toESM(require("@babel/parser"));
37
- var import_generator = __toESM(require("@babel/generator"));
38
- var t = __toESM(require("@babel/types"));
39
- function findTargetKeyNode(nodeProperties, key) {
40
- return nodeProperties.find((p) => t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key);
41
- }
42
- function generateRoutes({ sourceCode, filePath, prefix, baseName }) {
43
- const ast = babelParser.parse(sourceCode, {
44
- sourceType: "module"
45
- });
46
- const lazyComponentDeclarations = [];
47
- const componentDeclarations = [];
48
- let componentId = 0;
49
- (0, import_traverse.default)(ast, {
50
- ImportDeclaration(path) {
51
- const source = path.node.source.value;
52
- const routeIdMatch = source.match(/routeId=([^&]+)/);
53
- if (routeIdMatch) {
54
- const originalRouteId = routeIdMatch[1];
55
- const newRouteId = `${prefix}${originalRouteId}`;
56
- const newSource = source.replace(/routeId=[^&]+/, `routeId=${newRouteId}`);
57
- path.node.source = t.stringLiteral(newSource);
58
- }
59
- },
60
- ObjectExpression(path) {
61
- let componentName = "";
62
- let lazyComponentName = "";
63
- if (!Array.isArray(path.node.properties)) {
64
- return;
65
- }
66
- const idNode = findTargetKeyNode(path.node.properties, "id");
67
- if (idNode && t.isObjectProperty(idNode) && t.isStringLiteral(idNode.value)) {
68
- idNode.value = t.stringLiteral(`${prefix}${idNode.value.value}`);
69
- }
70
- const isRootNode = findTargetKeyNode(path.node.properties, "isRoot");
71
- if (isRootNode && t.isObjectProperty(isRootNode) && t.isBooleanLiteral(isRootNode.value)) {
72
- isRootNode.value.value = false;
73
- }
74
- if (!isRootNode) {
75
- const lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
76
- if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
77
- lazyComponentName = `LazyComponent_${componentId}`;
78
- const lazyDeclaration = t.variableDeclaration("const", [
79
- t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
80
- ]);
81
- lazyComponentNode.value = t.identifier(lazyComponentName);
82
- const componentNode2 = findTargetKeyNode(path.node.properties, "component");
83
- if (componentNode2 && t.isObjectProperty(componentNode2) && t.isCallExpression(componentNode2.value) && t.isIdentifier(componentNode2.value.callee)) {
84
- componentNode2.value = t.callExpression(t.identifier("lazy"), [
85
- t.identifier(lazyComponentName)
86
- ]);
87
- }
88
- lazyComponentDeclarations.push(lazyDeclaration);
89
- }
90
- }
91
- const componentNode = findTargetKeyNode(path.node.properties, "component");
92
- if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
93
- componentName = `Component_${componentId}`;
94
- const componentDeclaration = t.variableDeclaration("const", [
95
- t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
96
- t.identifier(lazyComponentName)
97
- ]) : componentNode.value)
98
- ]);
99
- componentDeclarations.push(componentDeclaration);
100
- componentNode.value = t.identifier(componentName);
101
- }
102
- if (lazyComponentName || componentName) {
103
- componentId++;
104
- if (componentName) {
105
- const upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
106
- const jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
107
- path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
108
- }
109
- }
110
- }
111
- });
112
- (0, import_traverse.default)(ast, {
113
- Program(path) {
114
- const lastImportIndex = path.get("body").reduce((lastIndex, p, index) => {
115
- if (t.isImportDeclaration(p.node)) {
116
- lastIndex = index;
117
- }
118
- return lastIndex;
119
- }, -1);
120
- if (lastImportIndex >= 0) {
121
- const lastImport = path.get(`body.${lastImportIndex}`);
122
- [
123
- ...componentDeclarations,
124
- ...lazyComponentDeclarations
125
- ].forEach((declaration) => {
126
- if ("insertAfter" in lastImport) {
127
- lastImport.insertAfter(declaration);
128
- }
129
- });
130
- }
131
- }
132
- });
133
- const { code: newCode } = (0, import_generator.default)(ast);
134
- const finalCode = `${newCode}export const baseName = '${baseName}';`;
135
- import_fs.default.writeFileSync(filePath, finalCode);
136
- }
137
- // Annotate the CommonJS export names for ESM import in node:
138
- 0 && (module.exports = {
139
- generateRoutes
140
- });