@module-federation/modern-js 0.0.0-next-20240909083238 → 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 (103) hide show
  1. package/dist/cjs/{runtime/withMFRouteId.js → cli/constant.js} +6 -9
  2. package/dist/cjs/cli/index.js +1 -6
  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 -6
  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 -6
  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 -10
  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 -142
  39. package/dist/cjs/cli/dataLoader/ast/generateSelfRoutes.js +0 -48
  40. package/dist/cjs/cli/dataLoader/ast/generateSerializableRoutes.js +0 -90
  41. package/dist/cjs/cli/dataLoader/ast/generateSlimRoutes.js +0 -104
  42. package/dist/cjs/cli/dataLoader/ast/index.js +0 -37
  43. package/dist/cjs/cli/dataLoader/generateRouteFile.js +0 -143
  44. package/dist/cjs/cli/dataLoader/patchMFConfig.js +0 -137
  45. package/dist/cjs/cli/dataLoader/plugin.js +0 -205
  46. package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -44
  47. package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -82
  48. package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -68
  49. package/dist/cjs/interfaces/route.js +0 -16
  50. package/dist/cjs/runtime/dataLoader/plugin.js +0 -73
  51. package/dist/cjs/runtime/dataLoader/utils.js +0 -89
  52. package/dist/cjs/runtime/utils.js +0 -38
  53. package/dist/esm/cli/dataLoader/ast/constant.js +0 -18
  54. package/dist/esm/cli/dataLoader/ast/generateRoutes.js +0 -109
  55. package/dist/esm/cli/dataLoader/ast/generateSelfRoutes.js +0 -17
  56. package/dist/esm/cli/dataLoader/ast/generateSerializableRoutes.js +0 -57
  57. package/dist/esm/cli/dataLoader/ast/generateSlimRoutes.js +0 -73
  58. package/dist/esm/cli/dataLoader/ast/index.js +0 -10
  59. package/dist/esm/cli/dataLoader/generateRouteFile.js +0 -293
  60. package/dist/esm/cli/dataLoader/patchMFConfig.js +0 -103
  61. package/dist/esm/cli/dataLoader/plugin.js +0 -216
  62. package/dist/esm/cli/mfRuntimePlugins/node.js +0 -16
  63. package/dist/esm/cli/server/dataLoaderPlugin.js +0 -105
  64. package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -86
  65. package/dist/esm/interfaces/route.js +0 -0
  66. package/dist/esm/runtime/dataLoader/plugin.js +0 -92
  67. package/dist/esm/runtime/dataLoader/utils.js +0 -63
  68. package/dist/esm/runtime/utils.js +0 -13
  69. package/dist/esm/runtime/withMFRouteId.js +0 -7
  70. package/dist/esm-node/cli/dataLoader/ast/constant.js +0 -18
  71. package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +0 -108
  72. package/dist/esm-node/cli/dataLoader/ast/generateSelfRoutes.js +0 -14
  73. package/dist/esm-node/cli/dataLoader/ast/generateSerializableRoutes.js +0 -56
  74. package/dist/esm-node/cli/dataLoader/ast/generateSlimRoutes.js +0 -70
  75. package/dist/esm-node/cli/dataLoader/ast/index.js +0 -10
  76. package/dist/esm-node/cli/dataLoader/generateRouteFile.js +0 -108
  77. package/dist/esm-node/cli/dataLoader/patchMFConfig.js +0 -103
  78. package/dist/esm-node/cli/dataLoader/plugin.js +0 -169
  79. package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -14
  80. package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -62
  81. package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -43
  82. package/dist/esm-node/interfaces/route.js +0 -0
  83. package/dist/esm-node/runtime/dataLoader/plugin.js +0 -49
  84. package/dist/esm-node/runtime/dataLoader/utils.js +0 -63
  85. package/dist/esm-node/runtime/utils.js +0 -13
  86. package/dist/esm-node/runtime/withMFRouteId.js +0 -7
  87. package/dist/types/cli/dataLoader/ast/constant.d.ts +0 -8
  88. package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +0 -7
  89. package/dist/types/cli/dataLoader/ast/generateSelfRoutes.d.ts +0 -7
  90. package/dist/types/cli/dataLoader/ast/generateSerializableRoutes.d.ts +0 -5
  91. package/dist/types/cli/dataLoader/ast/generateSlimRoutes.d.ts +0 -7
  92. package/dist/types/cli/dataLoader/ast/index.d.ts +0 -4
  93. package/dist/types/cli/dataLoader/generateRouteFile.d.ts +0 -7
  94. package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -11
  95. package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
  96. package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
  97. package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -10
  98. package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -10
  99. package/dist/types/interfaces/route.d.ts +0 -13
  100. package/dist/types/runtime/dataLoader/plugin.d.ts +0 -2
  101. package/dist/types/runtime/dataLoader/utils.d.ts +0 -19
  102. package/dist/types/runtime/utils.d.ts +0 -2
  103. package/dist/types/runtime/withMFRouteId.d.ts +0 -1
@@ -47,9 +47,7 @@ const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
47
47
  if (typeof remoteObject === "string") {
48
48
  return;
49
49
  }
50
- if ("entry" in remoteObject && typeof remoteObject.entry === "string") {
51
- remoteObject.entry = remoteObject.entry.replace(LOCALHOST, ipv4);
52
- }
50
+ handleRemoteObject(remoteObject);
53
51
  });
54
52
  } else if (typeof mfConfig.remotes !== "string") {
55
53
  handleRemoteObject(mfConfig.remotes);
@@ -104,7 +102,7 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
104
102
  injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
105
103
  }
106
104
  if (isServer) {
107
- injectRuntimePlugins(require.resolve("./mfRuntimePlugins/node.js"), runtimePlugins);
105
+ injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
108
106
  if (isDev) {
109
107
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
110
108
  }
@@ -293,6 +291,5 @@ export {
293
291
  getMFConfig,
294
292
  patchBundlerConfig,
295
293
  patchIgnoreWarning,
296
- patchMFConfig,
297
- replaceRemoteUrl
294
+ patchMFConfig
298
295
  };
@@ -38,7 +38,7 @@ describe("patchMFConfig", async () => {
38
38
  remoteType: "script",
39
39
  runtimePlugins: [
40
40
  path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
41
- require.resolve("./mfRuntimePlugins/node.js"),
41
+ require.resolve("@module-federation/node/runtimePlugin"),
42
42
  path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
43
43
  ],
44
44
  shared: {
@@ -1,28 +1,8 @@
1
1
  const MODERN_JS_SERVER_DIR = "bundles";
2
2
  const LOCALHOST = "localhost";
3
3
  const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
4
- const isDev = process.env.NODE_ENV === "development";
5
- const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
6
- const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
7
- const META_NAME = "modern-js";
8
- const FOLD_IDENTIFIER = "@mf";
9
- const SEPARATOR = "_";
10
- const MF_ROUTES = "mf-routes";
11
- const DEFAULT_ENTRY = "main";
12
- const DEFAULT_LAYOUT = "layout";
13
- const 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
  };
@@ -1,17 +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
- pre: [
8
- "@modern-js/plugin-router"
9
- ],
10
6
  setup: () => {
11
7
  return {
12
- async beforeRender() {
8
+ async init({ context }, next) {
13
9
  if (typeof window !== "undefined") {
14
- return;
10
+ return next({
11
+ context
12
+ });
15
13
  }
16
14
  globalThis.shouldUpdate = false;
17
15
  const nodeUtils = await import("@module-federation/node/utils");
@@ -21,7 +19,9 @@ const mfSSRPlugin = () => ({
21
19
  await nodeUtils.flushChunks();
22
20
  globalThis.shouldUpdate = true;
23
21
  }
24
- return;
22
+ return next({
23
+ context
24
+ });
25
25
  },
26
26
  wrapRoot(App) {
27
27
  const AppWrapper = (props) => /* @__PURE__ */ _jsxs(_Fragment, {
@@ -0,0 +1 @@
1
+ export declare const isDev: boolean;
@@ -1,3 +1,3 @@
1
1
  import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
- declare const nodePlugin: () => FederationRuntimePlugin;
3
- export default nodePlugin;
2
+ declare const injectNodeFetchPlugin: () => FederationRuntimePlugin;
3
+ export default injectNodeFetchPlugin;
@@ -2,10 +2,8 @@ import type { webpack, UserConfig, AppTools, Rspack, Bundler } from '@modern-js/
2
2
  import { moduleFederationPlugin } from '@module-federation/sdk';
3
3
  import { PluginOptions } from '../types';
4
4
  import { BundlerConfig } from '../interfaces/bundler';
5
- import type { init } from '@module-federation/enhanced/runtime';
6
5
  export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
7
6
  export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
8
- export declare const replaceRemoteUrl: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions | Parameters<typeof init>[0], remoteIpStrategy?: "ipv4" | "inherit") => void;
9
7
  export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
10
8
  export declare function patchIgnoreWarning<T extends Bundler>(bundlerConfig: BundlerConfig<T>): void;
11
9
  export declare function patchBundlerConfig<T extends Bundler>(options: {
@@ -1,13 +1,3 @@
1
1
  export declare const MODERN_JS_SERVER_DIR = "bundles";
2
2
  export declare const LOCALHOST = "localhost";
3
3
  export declare const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
4
- export declare const isDev: boolean;
5
- export declare const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
6
- export declare const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
7
- export declare const META_NAME = "modern-js";
8
- export declare const FOLD_IDENTIFIER = "@mf";
9
- export declare const SEPARATOR = "_";
10
- export declare const MF_ROUTES = "mf-routes";
11
- export declare const DEFAULT_ENTRY = "main";
12
- export declare const DEFAULT_LAYOUT = "layout";
13
- export declare const MF_JSON = "mf.json";
@@ -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,11 +16,3 @@ export interface InternalModernPluginOptions {
18
16
  remoteIpStrategy?: 'ipv4' | 'inherit';
19
17
  }
20
18
  export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
21
- export type TransformRuntimeOptions = (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => Parameters<typeof init>[0];
22
- export type DataLoaderOptions = {
23
- baseName: string;
24
- partialSSRRemotes?: string[];
25
- metaName?: string;
26
- serverPlugin?: string;
27
- transformRuntimeOptions?: TransformRuntimeOptions;
28
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20240909083238",
3
+ "version": "0.0.0-next-20240909101028",
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/plugin.d.ts",
28
- "default": "./dist/esm/runtime/dataLoader/plugin.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/dataLoader/plugin.js",
36
- "require": "./dist/cjs/cli/dataLoader/plugin.js",
37
- "types": "./dist/types/cli/dataLoader/plugin.d.ts"
38
- },
39
26
  "./config-plugin": {
40
27
  "import": "./dist/esm/cli/configPlugin.js",
41
28
  "require": "./dist/cjs/cli/configPlugin.js",
@@ -60,15 +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/dataLoader/plugin.d.ts"
66
- ],
67
- "data-loader": [
68
- "./dist/types/runtime/dataLoader/plugin.d.ts"
69
- ],
70
- "data-loader-server": [
71
- "./dist/types/cli/server/dataLoaderPlugin.d.ts"
72
50
  ]
73
51
  }
74
52
  },
@@ -78,30 +56,23 @@
78
56
  "license": "MIT",
79
57
  "dependencies": {
80
58
  "@swc/helpers": "0.5.12",
81
- "@modern-js/utils": "2.58.4-alpha.2",
59
+ "@modern-js/utils": "2.54.2",
82
60
  "@modern-js/node-bundle-require": "2.54.2",
83
61
  "node-fetch": "~3.3.0",
84
62
  "react-error-boundary": "4.0.13",
85
63
  "hoist-non-react-statics": "3.3.2",
86
- "@babel/generator": "7.25.0",
87
- "@babel/parser": "7.25.3",
88
- "@babel/traverse": "7.25.3",
89
- "@babel/types": "7.25.2",
90
- "@module-federation/sdk": "0.0.0-next-20240909083238",
91
- "@module-federation/enhanced": "0.0.0-next-20240909083238",
92
- "@module-federation/node": "0.0.0-next-20240909083238"
64
+ "@module-federation/sdk": "0.0.0-next-20240909101028",
65
+ "@module-federation/enhanced": "0.0.0-next-20240909101028",
66
+ "@module-federation/node": "0.0.0-next-20240909101028"
93
67
  },
94
68
  "devDependencies": {
95
- "@types/babel__traverse": "7.20.6",
96
- "@types/babel__generator": "7.6.8",
97
69
  "@types/hoist-non-react-statics": "3.3.2",
98
- "@modern-js/server-core": "0.0.0-next-20240828024207",
99
- "@modern-js/app-tools": "0.0.0-next-20240828024207",
100
- "@modern-js/core": "0.0.0-next-20240828024207",
101
- "@modern-js/runtime": "0.0.0-next-20240828024207",
102
- "@modern-js/module-tools": "0.0.0-next-20240828024207",
103
- "@modern-js/tsconfig": "0.0.0-next-20240828024207",
104
- "@module-federation/manifest": "0.0.0-next-20240909083238"
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-20240909101028"
105
76
  },
106
77
  "peerDependencies": {
107
78
  "react": ">=17",
@@ -1,49 +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
- LOADER: () => LOADER,
27
- PRIVATE_COMPONENT: () => PRIVATE_COMPONENT,
28
- SHOULD_REVALIDATE: () => SHOULD_REVALIDATE
29
- });
30
- module.exports = __toCommonJS(constant_exports);
31
- const IS_ROOT = "isRoot";
32
- const ID = "id";
33
- const COMPONENT = "component";
34
- const LAZY_COMPONENT = "lazyImport";
35
- const SHOULD_REVALIDATE = "shouldRevalidate";
36
- const PRIVATE_COMPONENT = "_component";
37
- const ELEMENT = "element";
38
- const LOADER = "loader";
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- COMPONENT,
42
- ELEMENT,
43
- ID,
44
- IS_ROOT,
45
- LAZY_COMPONENT,
46
- LOADER,
47
- PRIVATE_COMPONENT,
48
- SHOULD_REVALIDATE
49
- });
@@ -1,142 +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(
57
- // /routeId=[^&]+/,
58
- // `routeId=${newRouteId}`,
59
- // );
60
- // path.node.source = t.stringLiteral(newSource);
61
- // }
62
- // },
63
- ObjectExpression(path) {
64
- let componentName = "";
65
- let lazyComponentName = "";
66
- if (!Array.isArray(path.node.properties)) {
67
- return;
68
- }
69
- const idNode = findTargetKeyNode(path.node.properties, "id");
70
- if (idNode && t.isObjectProperty(idNode) && t.isStringLiteral(idNode.value)) {
71
- }
72
- const isRootNode = findTargetKeyNode(path.node.properties, "isRoot");
73
- if (isRootNode && t.isObjectProperty(isRootNode) && t.isBooleanLiteral(isRootNode.value)) {
74
- isRootNode.value.value = false;
75
- }
76
- if (!isRootNode) {
77
- const lazyComponentNode = findTargetKeyNode(path.node.properties, "lazyImport");
78
- if (lazyComponentNode && t.isObjectProperty(lazyComponentNode) && t.isArrowFunctionExpression(lazyComponentNode.value)) {
79
- lazyComponentName = `LazyComponent_${componentId}`;
80
- const lazyDeclaration = t.variableDeclaration("const", [
81
- t.variableDeclarator(t.identifier(lazyComponentName), lazyComponentNode.value)
82
- ]);
83
- lazyComponentNode.value = t.identifier(lazyComponentName);
84
- const componentNode2 = findTargetKeyNode(path.node.properties, "component");
85
- if (componentNode2 && t.isObjectProperty(componentNode2) && t.isCallExpression(componentNode2.value) && t.isIdentifier(componentNode2.value.callee)) {
86
- componentNode2.value = t.callExpression(t.identifier("lazy"), [
87
- t.identifier(lazyComponentName)
88
- ]);
89
- }
90
- lazyComponentDeclarations.push(lazyDeclaration);
91
- }
92
- }
93
- const componentNode = findTargetKeyNode(path.node.properties, "component");
94
- if (componentNode && t.isObjectProperty(componentNode) && t.isCallExpression(componentNode.value) && t.isIdentifier(componentNode.value.callee)) {
95
- componentName = `Component_${componentId}`;
96
- const componentDeclaration = t.variableDeclaration("const", [
97
- t.variableDeclarator(t.identifier(componentName), lazyComponentName ? t.callExpression(t.identifier("lazy"), [
98
- t.identifier(lazyComponentName)
99
- ]) : componentNode.value)
100
- ]);
101
- componentDeclarations.push(componentDeclaration);
102
- componentNode.value = t.identifier(componentName);
103
- }
104
- if (lazyComponentName || componentName) {
105
- componentId++;
106
- if (componentName) {
107
- const upperFirstName = componentName.slice(0, 1).toUpperCase() + componentName.slice(1);
108
- const jsxElement = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(upperFirstName), [], true), null, [], true);
109
- path.node.properties.push(t.objectProperty(t.identifier("element"), jsxElement));
110
- }
111
- }
112
- }
113
- });
114
- (0, import_traverse.default)(ast, {
115
- Program(path) {
116
- const lastImportIndex = path.get("body").reduce((lastIndex, p, index) => {
117
- if (t.isImportDeclaration(p.node)) {
118
- lastIndex = index;
119
- }
120
- return lastIndex;
121
- }, -1);
122
- if (lastImportIndex >= 0) {
123
- const lastImport = path.get(`body.${lastImportIndex}`);
124
- [
125
- ...componentDeclarations,
126
- ...lazyComponentDeclarations
127
- ].forEach((declaration) => {
128
- if ("insertAfter" in lastImport) {
129
- lastImport.insertAfter(declaration);
130
- }
131
- });
132
- }
133
- }
134
- });
135
- const { code: newCode } = (0, import_generator.default)(ast);
136
- const finalCode = `${newCode}export const baseName = '${baseName}';`;
137
- import_fs.default.writeFileSync(filePath, finalCode);
138
- }
139
- // Annotate the CommonJS export names for ESM import in node:
140
- 0 && (module.exports = {
141
- generateRoutes
142
- });
@@ -1,48 +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 generateSelfRoutes_exports = {};
30
- __export(generateSelfRoutes_exports, {
31
- generateSelfRoutes: () => generateSelfRoutes
32
- });
33
- module.exports = __toCommonJS(generateSelfRoutes_exports);
34
- var import_fs = __toESM(require("fs"));
35
- var t = __toESM(require("@babel/types"));
36
- function findTargetKeyNode(nodeProperties, key) {
37
- return nodeProperties.find((p) => t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key);
38
- }
39
- function generateSelfRoutes({ sourceCode, filePath, prefix, baseName }) {
40
- const lazyComponentDeclarations = [];
41
- const componentDeclarations = [];
42
- let componentId = 0;
43
- import_fs.default.writeFileSync(filePath, sourceCode);
44
- }
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- generateSelfRoutes
48
- });
@@ -1,90 +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 generateSerializableRoutes_exports = {};
30
- __export(generateSerializableRoutes_exports, {
31
- generateSerializableRoutes: () => generateSerializableRoutes
32
- });
33
- module.exports = __toCommonJS(generateSerializableRoutes_exports);
34
- var import_traverse = __toESM(require("@babel/traverse"));
35
- var babelParser = __toESM(require("@babel/parser"));
36
- var import_generator = __toESM(require("@babel/generator"));
37
- var t = __toESM(require("@babel/types"));
38
- var import_constant = require("./constant");
39
- function generateSerializableRoutes({ sourceCode, prefix }) {
40
- const ast = babelParser.parse(sourceCode, {
41
- sourceType: "module"
42
- });
43
- const removedKeys = [
44
- import_constant.COMPONENT,
45
- import_constant.SHOULD_REVALIDATE,
46
- import_constant.LAZY_COMPONENT,
47
- import_constant.PRIVATE_COMPONENT,
48
- import_constant.LOADER
49
- ];
50
- (0, import_traverse.default)(ast, {
51
- ObjectExpression(path1) {
52
- if (!Array.isArray(path1.node.properties)) {
53
- return;
54
- }
55
- path1.node.properties.forEach((prop1) => {
56
- if (t.isObjectProperty(prop1) && t.isStringLiteral(prop1.key) && t.isStringLiteral(prop1.value) && prop1.key.value === import_constant.ID) {
57
- }
58
- });
59
- path1.node.properties = path1.node.properties.filter((p1) => {
60
- if (t.isObjectProperty(p1) && t.isStringLiteral(p1.key)) {
61
- return !removedKeys.includes(p1.key.value);
62
- } else {
63
- return true;
64
- }
65
- });
66
- }
67
- });
68
- let routesValue = "";
69
- (0, import_traverse.default)(ast, {
70
- VariableDeclarator(path) {
71
- if (t.isVariableDeclarator(path.node) && t.isIdentifier(path.node.id) && path.node.id.name === "routes") {
72
- const routesAst = path.node.init;
73
- if (!routesAst) {
74
- return;
75
- }
76
- const { code } = (0, import_generator.default)(routesAst, {
77
- compact: true,
78
- retainLines: false,
79
- concise: true
80
- });
81
- routesValue = eval("(" + code + ")");
82
- }
83
- }
84
- });
85
- return routesValue;
86
- }
87
- // Annotate the CommonJS export names for ESM import in node:
88
- 0 && (module.exports = {
89
- generateSerializableRoutes
90
- });