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

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 (75) hide show
  1. package/dist/cjs/cli/ast/constant.js +49 -0
  2. package/dist/cjs/cli/ast/generateRoutes.js +140 -0
  3. package/dist/cjs/cli/ast/generateSerializableRoutes.js +91 -0
  4. package/dist/cjs/cli/ast/generateSlimRoutes.js +106 -0
  5. package/dist/cjs/cli/ast/index.js +34 -0
  6. package/dist/cjs/cli/bundler-plugins/SerializableRoutesPlugin.js +65 -0
  7. package/dist/cjs/cli/constant.js +6 -0
  8. package/dist/cjs/cli/dataLoaderPlugin.js +281 -0
  9. package/dist/cjs/cli/index.js +6 -1
  10. package/dist/cjs/cli/server/dataLoaderPlugin.js +83 -0
  11. package/dist/cjs/cli/ssrPlugin.js +4 -4
  12. package/dist/cjs/cli/utils.js +4 -2
  13. package/dist/cjs/interfaces/route.js +16 -0
  14. package/dist/cjs/runtime/constant.js +34 -0
  15. package/dist/cjs/runtime/dataLoader.js +87 -0
  16. package/dist/cjs/runtime/index.js +4 -1
  17. package/dist/cjs/runtime/utils.js +43 -0
  18. package/dist/cjs/runtime/withMFRouteId.js +31 -0
  19. package/dist/cjs/ssr-runtime/plugin.js +5 -7
  20. package/dist/esm/cli/ast/constant.js +18 -0
  21. package/dist/esm/cli/ast/generateRoutes.js +107 -0
  22. package/dist/esm/cli/ast/generateSerializableRoutes.js +58 -0
  23. package/dist/esm/cli/ast/generateSlimRoutes.js +75 -0
  24. package/dist/esm/cli/ast/index.js +8 -0
  25. package/dist/esm/cli/bundler-plugins/SerializableRoutesPlugin.js +45 -0
  26. package/dist/esm/cli/constant.js +4 -0
  27. package/dist/esm/cli/dataLoaderPlugin.js +326 -0
  28. package/dist/esm/cli/index.js +6 -1
  29. package/dist/esm/cli/server/dataLoaderPlugin.js +146 -0
  30. package/dist/esm/cli/ssrPlugin.js +2 -2
  31. package/dist/esm/cli/utils.js +2 -1
  32. package/dist/esm/interfaces/route.js +0 -0
  33. package/dist/esm/runtime/constant.js +8 -0
  34. package/dist/esm/runtime/dataLoader.js +125 -0
  35. package/dist/esm/runtime/index.js +3 -1
  36. package/dist/esm/runtime/utils.js +16 -0
  37. package/dist/esm/runtime/withMFRouteId.js +7 -0
  38. package/dist/esm/ssr-runtime/plugin.js +5 -10
  39. package/dist/esm-node/cli/ast/constant.js +18 -0
  40. package/dist/esm-node/cli/ast/generateRoutes.js +106 -0
  41. package/dist/esm-node/cli/ast/generateSerializableRoutes.js +57 -0
  42. package/dist/esm-node/cli/ast/generateSlimRoutes.js +72 -0
  43. package/dist/esm-node/cli/ast/index.js +8 -0
  44. package/dist/esm-node/cli/bundler-plugins/SerializableRoutesPlugin.js +30 -0
  45. package/dist/esm-node/cli/constant.js +4 -0
  46. package/dist/esm-node/cli/dataLoaderPlugin.js +245 -0
  47. package/dist/esm-node/cli/index.js +6 -1
  48. package/dist/esm-node/cli/server/dataLoaderPlugin.js +63 -0
  49. package/dist/esm-node/cli/ssrPlugin.js +2 -2
  50. package/dist/esm-node/cli/utils.js +2 -1
  51. package/dist/esm-node/interfaces/route.js +0 -0
  52. package/dist/esm-node/runtime/constant.js +8 -0
  53. package/dist/esm-node/runtime/dataLoader.js +63 -0
  54. package/dist/esm-node/runtime/index.js +3 -1
  55. package/dist/esm-node/runtime/utils.js +19 -0
  56. package/dist/esm-node/runtime/withMFRouteId.js +7 -0
  57. package/dist/esm-node/ssr-runtime/plugin.js +5 -7
  58. package/dist/types/cli/ast/constant.d.ts +8 -0
  59. package/dist/types/cli/ast/generateRoutes.d.ts +7 -0
  60. package/dist/types/cli/ast/generateSerializableRoutes.d.ts +5 -0
  61. package/dist/types/cli/ast/generateSlimRoutes.d.ts +7 -0
  62. package/dist/types/cli/ast/index.d.ts +3 -0
  63. package/dist/types/cli/bundler-plugins/SerializableRoutesPlugin.d.ts +12 -0
  64. package/dist/types/cli/constant.d.ts +2 -0
  65. package/dist/types/cli/dataLoaderPlugin.d.ts +6 -0
  66. package/dist/types/cli/server/dataLoaderPlugin.d.ts +5 -0
  67. package/dist/types/cli/utils.d.ts +1 -0
  68. package/dist/types/interfaces/route.d.ts +13 -0
  69. package/dist/types/runtime/constant.d.ts +3 -0
  70. package/dist/types/runtime/dataLoader.d.ts +7 -0
  71. package/dist/types/runtime/index.d.ts +1 -0
  72. package/dist/types/runtime/utils.d.ts +1 -0
  73. package/dist/types/runtime/withMFRouteId.d.ts +1 -0
  74. package/dist/types/types/index.d.ts +18 -0
  75. package/package.json +37 -11
@@ -0,0 +1,49 @@
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
+ });
@@ -0,0 +1,140 @@
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
+ });
@@ -0,0 +1,91 @@
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
+ prop1.value = t.stringLiteral(`${prefix}${prop1.value.value}`);
58
+ }
59
+ });
60
+ path1.node.properties = path1.node.properties.filter((p1) => {
61
+ if (t.isObjectProperty(p1) && t.isStringLiteral(p1.key)) {
62
+ return !removedKeys.includes(p1.key.value);
63
+ } else {
64
+ return true;
65
+ }
66
+ });
67
+ }
68
+ });
69
+ let routesValue = "";
70
+ (0, import_traverse.default)(ast, {
71
+ VariableDeclarator(path) {
72
+ if (t.isVariableDeclarator(path.node) && t.isIdentifier(path.node.id) && path.node.id.name === "routes") {
73
+ const routesAst = path.node.init;
74
+ if (!routesAst) {
75
+ return;
76
+ }
77
+ const { code } = (0, import_generator.default)(routesAst, {
78
+ compact: true,
79
+ retainLines: false,
80
+ concise: true
81
+ });
82
+ routesValue = eval("(" + code + ")");
83
+ }
84
+ }
85
+ });
86
+ return routesValue;
87
+ }
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ generateSerializableRoutes
91
+ });
@@ -0,0 +1,106 @@
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(/routeId=[^&]+/, `routeId=${newRouteId}`);
58
+ path.node.source = t.stringLiteral(newSource);
59
+ }
60
+ },
61
+ ObjectExpression(path) {
62
+ if (!Array.isArray(path.node.properties)) {
63
+ return;
64
+ }
65
+ path.node.properties.forEach((prop) => {
66
+ if (t.isObjectProperty(prop) && t.isStringLiteral(prop.key) && t.isStringLiteral(prop.value) && prop.key.value === import_constant.ID) {
67
+ prop.value = t.stringLiteral(`${prefix}${prop.value.value}`);
68
+ }
69
+ });
70
+ path.node.properties = path.node.properties.filter((p) => {
71
+ if (t.isObjectProperty(p) && t.isStringLiteral(p.key)) {
72
+ return !removedKeys.includes(p.key.value);
73
+ } else {
74
+ return true;
75
+ }
76
+ });
77
+ }
78
+ });
79
+ const tempCode = (0, import_generator.default)(ast).code;
80
+ const tempAst = babelParser.parse(tempCode, {
81
+ sourceType: "module"
82
+ });
83
+ const usedIdentifiers = /* @__PURE__ */ new Set();
84
+ (0, import_traverse.default)(tempAst, {
85
+ Identifier(path) {
86
+ if (t.isProperty(path.parent)) {
87
+ usedIdentifiers.add(path.node.name);
88
+ }
89
+ }
90
+ });
91
+ (0, import_traverse.default)(tempAst, {
92
+ ImportDeclaration(path) {
93
+ path.node.specifiers = path.node.specifiers.filter((specifier) => usedIdentifiers.has(specifier.local.name));
94
+ if (!path.node.specifiers.length) {
95
+ path.remove();
96
+ }
97
+ }
98
+ });
99
+ const { code: newCode } = (0, import_generator.default)(tempAst);
100
+ const finalCode = `${newCode}export const baseName = '${baseName}';`;
101
+ import_fs.default.writeFileSync(filePath, finalCode);
102
+ }
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ generateSlimRoutes
106
+ });
@@ -0,0 +1,34 @@
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 ast_exports = {};
20
+ __export(ast_exports, {
21
+ generateRoutes: () => import_generateRoutes.generateRoutes,
22
+ generateSerializableRoutes: () => import_generateSerializableRoutes.generateSerializableRoutes,
23
+ generateSlimRoutes: () => import_generateSlimRoutes.generateSlimRoutes
24
+ });
25
+ module.exports = __toCommonJS(ast_exports);
26
+ var import_generateRoutes = require("./generateRoutes");
27
+ var import_generateSlimRoutes = require("./generateSlimRoutes");
28
+ var import_generateSerializableRoutes = require("./generateSerializableRoutes");
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ generateRoutes,
32
+ generateSerializableRoutes,
33
+ generateSlimRoutes
34
+ });
@@ -0,0 +1,65 @@
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 SerializableRoutesPlugin_exports = {};
30
+ __export(SerializableRoutesPlugin_exports, {
31
+ SERIALIZABLE_ROUTES: () => SERIALIZABLE_ROUTES,
32
+ SerializableRoutesPlugin: () => SerializableRoutesPlugin
33
+ });
34
+ module.exports = __toCommonJS(SerializableRoutesPlugin_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_ast = require("../ast");
37
+ const SERIALIZABLE_ROUTES = "serializable-routes.json";
38
+ class SerializableRoutesPlugin {
39
+ apply(compiler) {
40
+ compiler.hooks.thisCompilation.tap("generateStats", (compilation) => {
41
+ compilation.hooks.processAssets.tapPromise({
42
+ name: "generateSerializableRoutes",
43
+ // @ts-ignore use runtime variable in case peer dep not installed
44
+ stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
45
+ }, async () => {
46
+ const sourceCode = import_fs.default.readFileSync(this.routesFilePath, "utf-8");
47
+ const routesCode = (0, import_ast.generateSerializableRoutes)({
48
+ sourceCode,
49
+ prefix: this.prefix
50
+ });
51
+ compilation.emitAsset(SERIALIZABLE_ROUTES, new compiler.webpack.sources.RawSource(JSON.stringify(routesCode, null, 2)));
52
+ });
53
+ });
54
+ }
55
+ constructor(options) {
56
+ const { routesFilePath, prefix } = options;
57
+ this.routesFilePath = routesFilePath;
58
+ this.prefix = prefix;
59
+ }
60
+ }
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ SERIALIZABLE_ROUTES,
64
+ SerializableRoutesPlugin
65
+ });
@@ -18,11 +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
+ META_NAME: () => META_NAME,
22
+ MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME: () => MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
21
23
  isDev: () => isDev
22
24
  });
23
25
  module.exports = __toCommonJS(constant_exports);
24
26
  const isDev = process.env.NODE_ENV === "development";
27
+ const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
28
+ const META_NAME = "modern-js";
25
29
  // Annotate the CommonJS export names for ESM import in node:
26
30
  0 && (module.exports = {
31
+ META_NAME,
32
+ MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
27
33
  isDev
28
34
  });