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

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 (40) hide show
  1. package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +3 -4
  2. package/dist/cjs/cli/dataLoader/ast/index.js +2 -11
  3. package/dist/cjs/cli/dataLoader/patchMFConfig.js +3 -8
  4. package/dist/cjs/cli/dataLoader/plugin.js +7 -18
  5. package/dist/cjs/cli/index.js +1 -2
  6. package/dist/cjs/cli/server/dataLoaderPlugin.js +1 -1
  7. package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +6 -5
  8. package/dist/esm/cli/dataLoader/ast/generateRoutes.js +3 -4
  9. package/dist/esm/cli/dataLoader/ast/index.js +1 -7
  10. package/dist/esm/cli/dataLoader/patchMFConfig.js +3 -8
  11. package/dist/esm/cli/dataLoader/plugin.js +11 -18
  12. package/dist/esm/cli/index.js +1 -3
  13. package/dist/esm/cli/server/dataLoaderPlugin.js +1 -1
  14. package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +7 -5
  15. package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +3 -4
  16. package/dist/esm-node/cli/dataLoader/ast/index.js +1 -7
  17. package/dist/esm-node/cli/dataLoader/patchMFConfig.js +3 -8
  18. package/dist/esm-node/cli/dataLoader/plugin.js +9 -19
  19. package/dist/esm-node/cli/index.js +1 -2
  20. package/dist/esm-node/cli/server/dataLoaderPlugin.js +1 -1
  21. package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +6 -5
  22. package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +1 -3
  23. package/dist/types/cli/dataLoader/ast/index.d.ts +0 -3
  24. package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -1
  25. package/dist/types/cli/dataLoader/plugin.d.ts +2 -2
  26. package/dist/types/interfaces/route.d.ts +0 -1
  27. package/dist/types/types/index.d.ts +1 -2
  28. package/package.json +11 -11
  29. package/dist/cjs/cli/dataLoader/ast/generateSelfRoutes.js +0 -48
  30. package/dist/cjs/cli/dataLoader/ast/generateSerializableRoutes.js +0 -90
  31. package/dist/cjs/cli/dataLoader/ast/generateSlimRoutes.js +0 -104
  32. package/dist/esm/cli/dataLoader/ast/generateSelfRoutes.js +0 -17
  33. package/dist/esm/cli/dataLoader/ast/generateSerializableRoutes.js +0 -57
  34. package/dist/esm/cli/dataLoader/ast/generateSlimRoutes.js +0 -73
  35. package/dist/esm-node/cli/dataLoader/ast/generateSelfRoutes.js +0 -14
  36. package/dist/esm-node/cli/dataLoader/ast/generateSerializableRoutes.js +0 -56
  37. package/dist/esm-node/cli/dataLoader/ast/generateSlimRoutes.js +0 -70
  38. package/dist/types/cli/dataLoader/ast/generateSelfRoutes.d.ts +0 -7
  39. package/dist/types/cli/dataLoader/ast/generateSerializableRoutes.d.ts +0 -5
  40. package/dist/types/cli/dataLoader/ast/generateSlimRoutes.d.ts +0 -7
@@ -1,7 +1,6 @@
1
1
  import { type moduleFederationPlugin } from '@module-federation/sdk';
2
2
  type PatchMFConfigOptions = {
3
3
  mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
4
- baseName: string;
5
4
  metaName: string;
6
5
  isServer: boolean;
7
6
  internalDirectory: string;
@@ -1,6 +1,6 @@
1
1
  import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
2
  import type { DataLoaderOptions, InternalModernPluginOptions } from '../../types';
3
- import { generateRoutes, generateSlimRoutes } from './ast';
3
+ import { generateRoutes } from './ast';
4
4
  export declare const moduleFederationDataLoaderPlugin: (enable: boolean, internalOptions: InternalModernPluginOptions, userConfig: DataLoaderOptions) => CliPlugin<AppTools>;
5
5
  export default moduleFederationDataLoaderPlugin;
6
- export { generateRoutes, generateSlimRoutes };
6
+ export { generateRoutes };
@@ -7,7 +7,6 @@ export type Route = {
7
7
  children?: Route[];
8
8
  };
9
9
  export type MFModernRouteJson = {
10
- baseName: string;
11
10
  routes: Record<string, Route[]>;
12
11
  prefix: string;
13
12
  };
@@ -6,7 +6,7 @@ export interface PluginOptions {
6
6
  config?: moduleFederationPlugin.ModuleFederationPluginOptions;
7
7
  configPath?: string;
8
8
  remoteIpStrategy?: 'ipv4' | 'inherit';
9
- dataLoader?: false | Pick<DataLoaderOptions, 'baseName' | 'partialSSRRemotes'>;
9
+ dataLoader?: boolean | DataLoaderOptions;
10
10
  }
11
11
  export interface InternalModernPluginOptions {
12
12
  csrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
@@ -20,7 +20,6 @@ export interface InternalModernPluginOptions {
20
20
  export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
21
21
  export type TransformRuntimeOptions = (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => Parameters<typeof init>[0];
22
22
  export type DataLoaderOptions = {
23
- baseName: string;
24
23
  partialSSRRemotes?: string[];
25
24
  metaName?: string;
26
25
  serverPlugin?: string;
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-20240909092952",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -87,21 +87,21 @@
87
87
  "@babel/parser": "7.25.3",
88
88
  "@babel/traverse": "7.25.3",
89
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"
90
+ "@module-federation/sdk": "0.0.0-next-20240909092952",
91
+ "@module-federation/enhanced": "0.0.0-next-20240909092952",
92
+ "@module-federation/node": "0.0.0-next-20240909092952"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@types/babel__traverse": "7.20.6",
96
96
  "@types/babel__generator": "7.6.8",
97
97
  "@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"
98
+ "@modern-js/server-core": "^2.59.0",
99
+ "@modern-js/app-tools": "^2.59.0",
100
+ "@modern-js/core": "^2.59.0",
101
+ "@modern-js/runtime": "^2.59.0",
102
+ "@modern-js/module-tools": "^2.59.0",
103
+ "@modern-js/tsconfig": "^2.59.0",
104
+ "@module-federation/manifest": "0.0.0-next-20240909092952"
105
105
  },
106
106
  "peerDependencies": {
107
107
  "react": ">=17",
@@ -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
- });
@@ -1,104 +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 generateSlimRoutes_exports = {};
30
- __export(generateSlimRoutes_exports, {
31
- generateSlimRoutes: () => generateSlimRoutes
32
- });
33
- module.exports = __toCommonJS(generateSlimRoutes_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
- var import_constant = require("./constant");
40
- function generateSlimRoutes({ sourceCode, filePath, prefix, baseName }) {
41
- const ast = babelParser.parse(sourceCode, {
42
- sourceType: "module"
43
- });
44
- const removedKeys = [
45
- import_constant.COMPONENT,
46
- import_constant.SHOULD_REVALIDATE,
47
- import_constant.LAZY_COMPONENT,
48
- import_constant.PRIVATE_COMPONENT
49
- ];
50
- (0, import_traverse.default)(ast, {
51
- // ImportDeclaration(path) {
52
- // const source = path.node.source.value;
53
- // const routeIdMatch = source.match(/routeId=([^&]+)/);
54
- // if (routeIdMatch) {
55
- // const originalRouteId = routeIdMatch[1];
56
- // const newRouteId = `${prefix}${originalRouteId}`;
57
- // const newSource = source.replace(
58
- // /routeId=[^&]+/,
59
- // `routeId=${newRouteId}`,
60
- // );
61
- // path.node.source = t.stringLiteral(newSource);
62
- // }
63
- // },
64
- ObjectExpression(path) {
65
- if (!Array.isArray(path.node.properties)) {
66
- return;
67
- }
68
- path.node.properties = path.node.properties.filter((p) => {
69
- if (t.isObjectProperty(p) && t.isStringLiteral(p.key)) {
70
- return !removedKeys.includes(p.key.value);
71
- } else {
72
- return true;
73
- }
74
- });
75
- }
76
- });
77
- const tempCode = (0, import_generator.default)(ast).code;
78
- const tempAst = babelParser.parse(tempCode, {
79
- sourceType: "module"
80
- });
81
- const usedIdentifiers = /* @__PURE__ */ new Set();
82
- (0, import_traverse.default)(tempAst, {
83
- Identifier(path) {
84
- if (t.isProperty(path.parent)) {
85
- usedIdentifiers.add(path.node.name);
86
- }
87
- }
88
- });
89
- (0, import_traverse.default)(tempAst, {
90
- ImportDeclaration(path) {
91
- path.node.specifiers = path.node.specifiers.filter((specifier) => usedIdentifiers.has(specifier.local.name));
92
- if (!path.node.specifiers.length) {
93
- path.remove();
94
- }
95
- }
96
- });
97
- const { code: newCode } = (0, import_generator.default)(tempAst);
98
- const finalCode = `${newCode}export const baseName = '${baseName}';`;
99
- import_fs.default.writeFileSync(filePath, finalCode);
100
- }
101
- // Annotate the CommonJS export names for ESM import in node:
102
- 0 && (module.exports = {
103
- generateSlimRoutes
104
- });
@@ -1,17 +0,0 @@
1
- import fs from "fs";
2
- import * as t from "@babel/types";
3
- function findTargetKeyNode(nodeProperties, key) {
4
- return nodeProperties.find(function(p) {
5
- return t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key;
6
- });
7
- }
8
- function generateSelfRoutes(param) {
9
- var sourceCode = param.sourceCode, filePath = param.filePath, prefix = param.prefix, baseName = param.baseName;
10
- var lazyComponentDeclarations = [];
11
- var componentDeclarations = [];
12
- var componentId = 0;
13
- fs.writeFileSync(filePath, sourceCode);
14
- }
15
- export {
16
- generateSelfRoutes
17
- };
@@ -1,57 +0,0 @@
1
- import traverse from "@babel/traverse";
2
- import * as babelParser from "@babel/parser";
3
- import generate from "@babel/generator";
4
- import * as t from "@babel/types";
5
- import { COMPONENT, ID, SHOULD_REVALIDATE, LAZY_COMPONENT, PRIVATE_COMPONENT, LOADER } from "./constant";
6
- function generateSerializableRoutes(param) {
7
- var sourceCode = param.sourceCode, prefix = param.prefix;
8
- var ast = babelParser.parse(sourceCode, {
9
- sourceType: "module"
10
- });
11
- var removedKeys = [
12
- COMPONENT,
13
- SHOULD_REVALIDATE,
14
- LAZY_COMPONENT,
15
- PRIVATE_COMPONENT,
16
- LOADER
17
- ];
18
- traverse(ast, {
19
- ObjectExpression: function ObjectExpression(path1) {
20
- if (!Array.isArray(path1.node.properties)) {
21
- return;
22
- }
23
- path1.node.properties.forEach(function(prop1) {
24
- if (t.isObjectProperty(prop1) && t.isStringLiteral(prop1.key) && t.isStringLiteral(prop1.value) && prop1.key.value === ID) {
25
- }
26
- });
27
- path1.node.properties = path1.node.properties.filter(function(p1) {
28
- if (t.isObjectProperty(p1) && t.isStringLiteral(p1.key)) {
29
- return !removedKeys.includes(p1.key.value);
30
- } else {
31
- return true;
32
- }
33
- });
34
- }
35
- });
36
- var routesValue = "";
37
- traverse(ast, {
38
- VariableDeclarator: function VariableDeclarator(path) {
39
- if (t.isVariableDeclarator(path.node) && t.isIdentifier(path.node.id) && path.node.id.name === "routes") {
40
- var routesAst = path.node.init;
41
- if (!routesAst) {
42
- return;
43
- }
44
- var code = generate(routesAst, {
45
- compact: true,
46
- retainLines: false,
47
- concise: true
48
- }).code;
49
- routesValue = eval("(" + code + ")");
50
- }
51
- }
52
- });
53
- return routesValue;
54
- }
55
- export {
56
- generateSerializableRoutes
57
- };
@@ -1,73 +0,0 @@
1
- import fs from "fs";
2
- import traverse from "@babel/traverse";
3
- import * as babelParser from "@babel/parser";
4
- import generate from "@babel/generator";
5
- import * as t from "@babel/types";
6
- import { COMPONENT, SHOULD_REVALIDATE, LAZY_COMPONENT, PRIVATE_COMPONENT } from "./constant";
7
- function generateSlimRoutes(param) {
8
- var sourceCode = param.sourceCode, filePath = param.filePath, prefix = param.prefix, baseName = param.baseName;
9
- var ast = babelParser.parse(sourceCode, {
10
- sourceType: "module"
11
- });
12
- var removedKeys = [
13
- COMPONENT,
14
- SHOULD_REVALIDATE,
15
- LAZY_COMPONENT,
16
- PRIVATE_COMPONENT
17
- ];
18
- traverse(ast, {
19
- // ImportDeclaration(path) {
20
- // const source = path.node.source.value;
21
- // const routeIdMatch = source.match(/routeId=([^&]+)/);
22
- // if (routeIdMatch) {
23
- // const originalRouteId = routeIdMatch[1];
24
- // const newRouteId = `${prefix}${originalRouteId}`;
25
- // const newSource = source.replace(
26
- // /routeId=[^&]+/,
27
- // `routeId=${newRouteId}`,
28
- // );
29
- // path.node.source = t.stringLiteral(newSource);
30
- // }
31
- // },
32
- ObjectExpression: function ObjectExpression(path) {
33
- if (!Array.isArray(path.node.properties)) {
34
- return;
35
- }
36
- path.node.properties = path.node.properties.filter(function(p) {
37
- if (t.isObjectProperty(p) && t.isStringLiteral(p.key)) {
38
- return !removedKeys.includes(p.key.value);
39
- } else {
40
- return true;
41
- }
42
- });
43
- }
44
- });
45
- var tempCode = generate(ast).code;
46
- var tempAst = babelParser.parse(tempCode, {
47
- sourceType: "module"
48
- });
49
- var usedIdentifiers = /* @__PURE__ */ new Set();
50
- traverse(tempAst, {
51
- Identifier: function Identifier(path) {
52
- if (t.isProperty(path.parent)) {
53
- usedIdentifiers.add(path.node.name);
54
- }
55
- }
56
- });
57
- traverse(tempAst, {
58
- ImportDeclaration: function ImportDeclaration(path) {
59
- path.node.specifiers = path.node.specifiers.filter(function(specifier) {
60
- return usedIdentifiers.has(specifier.local.name);
61
- });
62
- if (!path.node.specifiers.length) {
63
- path.remove();
64
- }
65
- }
66
- });
67
- var _generate = generate(tempAst), newCode = _generate.code;
68
- var finalCode = "".concat(newCode, "export const baseName = '").concat(baseName, "';");
69
- fs.writeFileSync(filePath, finalCode);
70
- }
71
- export {
72
- generateSlimRoutes
73
- };
@@ -1,14 +0,0 @@
1
- import fs from "fs";
2
- import * as t from "@babel/types";
3
- function findTargetKeyNode(nodeProperties, key) {
4
- return nodeProperties.find((p) => t.isObjectProperty(p) && t.isStringLiteral(p.key) && p.key.value === key);
5
- }
6
- function generateSelfRoutes({ sourceCode, filePath, prefix, baseName }) {
7
- const lazyComponentDeclarations = [];
8
- const componentDeclarations = [];
9
- let componentId = 0;
10
- fs.writeFileSync(filePath, sourceCode);
11
- }
12
- export {
13
- generateSelfRoutes
14
- };
@@ -1,56 +0,0 @@
1
- import traverse from "@babel/traverse";
2
- import * as babelParser from "@babel/parser";
3
- import generate from "@babel/generator";
4
- import * as t from "@babel/types";
5
- import { COMPONENT, ID, SHOULD_REVALIDATE, LAZY_COMPONENT, PRIVATE_COMPONENT, LOADER } from "./constant";
6
- function generateSerializableRoutes({ sourceCode, prefix }) {
7
- const ast = babelParser.parse(sourceCode, {
8
- sourceType: "module"
9
- });
10
- const removedKeys = [
11
- COMPONENT,
12
- SHOULD_REVALIDATE,
13
- LAZY_COMPONENT,
14
- PRIVATE_COMPONENT,
15
- LOADER
16
- ];
17
- traverse(ast, {
18
- ObjectExpression(path1) {
19
- if (!Array.isArray(path1.node.properties)) {
20
- return;
21
- }
22
- path1.node.properties.forEach((prop1) => {
23
- if (t.isObjectProperty(prop1) && t.isStringLiteral(prop1.key) && t.isStringLiteral(prop1.value) && prop1.key.value === ID) {
24
- }
25
- });
26
- path1.node.properties = path1.node.properties.filter((p1) => {
27
- if (t.isObjectProperty(p1) && t.isStringLiteral(p1.key)) {
28
- return !removedKeys.includes(p1.key.value);
29
- } else {
30
- return true;
31
- }
32
- });
33
- }
34
- });
35
- let routesValue = "";
36
- traverse(ast, {
37
- VariableDeclarator(path) {
38
- if (t.isVariableDeclarator(path.node) && t.isIdentifier(path.node.id) && path.node.id.name === "routes") {
39
- const routesAst = path.node.init;
40
- if (!routesAst) {
41
- return;
42
- }
43
- const { code } = generate(routesAst, {
44
- compact: true,
45
- retainLines: false,
46
- concise: true
47
- });
48
- routesValue = eval("(" + code + ")");
49
- }
50
- }
51
- });
52
- return routesValue;
53
- }
54
- export {
55
- generateSerializableRoutes
56
- };
@@ -1,70 +0,0 @@
1
- import fs from "fs";
2
- import traverse from "@babel/traverse";
3
- import * as babelParser from "@babel/parser";
4
- import generate from "@babel/generator";
5
- import * as t from "@babel/types";
6
- import { COMPONENT, SHOULD_REVALIDATE, LAZY_COMPONENT, PRIVATE_COMPONENT } from "./constant";
7
- function generateSlimRoutes({ sourceCode, filePath, prefix, baseName }) {
8
- const ast = babelParser.parse(sourceCode, {
9
- sourceType: "module"
10
- });
11
- const removedKeys = [
12
- COMPONENT,
13
- SHOULD_REVALIDATE,
14
- LAZY_COMPONENT,
15
- PRIVATE_COMPONENT
16
- ];
17
- traverse(ast, {
18
- // ImportDeclaration(path) {
19
- // const source = path.node.source.value;
20
- // const routeIdMatch = source.match(/routeId=([^&]+)/);
21
- // if (routeIdMatch) {
22
- // const originalRouteId = routeIdMatch[1];
23
- // const newRouteId = `${prefix}${originalRouteId}`;
24
- // const newSource = source.replace(
25
- // /routeId=[^&]+/,
26
- // `routeId=${newRouteId}`,
27
- // );
28
- // path.node.source = t.stringLiteral(newSource);
29
- // }
30
- // },
31
- ObjectExpression(path) {
32
- if (!Array.isArray(path.node.properties)) {
33
- return;
34
- }
35
- path.node.properties = path.node.properties.filter((p) => {
36
- if (t.isObjectProperty(p) && t.isStringLiteral(p.key)) {
37
- return !removedKeys.includes(p.key.value);
38
- } else {
39
- return true;
40
- }
41
- });
42
- }
43
- });
44
- const tempCode = generate(ast).code;
45
- const tempAst = babelParser.parse(tempCode, {
46
- sourceType: "module"
47
- });
48
- const usedIdentifiers = /* @__PURE__ */ new Set();
49
- traverse(tempAst, {
50
- Identifier(path) {
51
- if (t.isProperty(path.parent)) {
52
- usedIdentifiers.add(path.node.name);
53
- }
54
- }
55
- });
56
- traverse(tempAst, {
57
- ImportDeclaration(path) {
58
- path.node.specifiers = path.node.specifiers.filter((specifier) => usedIdentifiers.has(specifier.local.name));
59
- if (!path.node.specifiers.length) {
60
- path.remove();
61
- }
62
- }
63
- });
64
- const { code: newCode } = generate(tempAst);
65
- const finalCode = `${newCode}export const baseName = '${baseName}';`;
66
- fs.writeFileSync(filePath, finalCode);
67
- }
68
- export {
69
- generateSlimRoutes
70
- };
@@ -1,7 +0,0 @@
1
- declare function generateSelfRoutes({ sourceCode, filePath, prefix, baseName, }: {
2
- sourceCode: string;
3
- filePath: string;
4
- prefix: string;
5
- baseName: string;
6
- }): void;
7
- export { generateSelfRoutes };
@@ -1,5 +0,0 @@
1
- declare function generateSerializableRoutes({ sourceCode, prefix, }: {
2
- sourceCode: string;
3
- prefix: string;
4
- }): string;
5
- export { generateSerializableRoutes };
@@ -1,7 +0,0 @@
1
- declare function generateSlimRoutes({ sourceCode, filePath, prefix, baseName, }: {
2
- sourceCode: string;
3
- filePath: string;
4
- prefix: string;
5
- baseName: string;
6
- }): void;
7
- export { generateSlimRoutes };