@modern-js/app-tools 2.53.1-alpha.3 → 2.54.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. package/bin/modern.js +0 -2
  2. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
  4. package/dist/cjs/commands/build.js +2 -0
  5. package/dist/cjs/commands/deploy.js +2 -2
  6. package/dist/cjs/commands/dev.js +19 -5
  7. package/dist/cjs/commands/index.js +113 -7
  8. package/dist/cjs/commands/serve.js +19 -5
  9. package/dist/cjs/hooks.js +5 -0
  10. package/dist/cjs/index.js +14 -83
  11. package/dist/cjs/plugins/analyze/constants.js +56 -0
  12. package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
  13. package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  14. package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
  15. package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  16. package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
  17. package/dist/cjs/plugins/analyze/templates.js +101 -0
  18. package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
  19. package/dist/cjs/plugins/deploy/dependencies/index.js +16 -25
  20. package/dist/cjs/plugins/deploy/dependencies/utils.js +1 -2
  21. package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -9
  22. package/dist/cjs/plugins/deploy/platforms/node.js +5 -13
  23. package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -9
  24. package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
  25. package/dist/cjs/plugins/serverBuild.js +10 -4
  26. package/dist/cjs/utils/createServer.js +1 -1
  27. package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
  28. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
  29. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  30. package/dist/esm/commands/build.js +16 -9
  31. package/dist/esm/commands/deploy.js +2 -2
  32. package/dist/esm/commands/dev.js +13 -9
  33. package/dist/esm/commands/index.js +411 -3
  34. package/dist/esm/commands/serve.js +12 -8
  35. package/dist/esm/hooks.js +5 -0
  36. package/dist/esm/index.js +12 -394
  37. package/dist/esm/plugins/analyze/constants.js +24 -0
  38. package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
  39. package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
  40. package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
  41. package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  42. package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
  43. package/dist/esm/plugins/analyze/templates.js +22 -0
  44. package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
  45. package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
  46. package/dist/esm/plugins/deploy/dependencies/utils.js +3 -4
  47. package/dist/esm/plugins/deploy/platforms/netlify.js +8 -10
  48. package/dist/esm/plugins/deploy/platforms/node.js +8 -14
  49. package/dist/esm/plugins/deploy/platforms/vercel.js +8 -10
  50. package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
  51. package/dist/esm/plugins/serverBuild.js +13 -6
  52. package/dist/esm/utils/createServer.js +2 -2
  53. package/dist/esm/utils/loadPlugins.js +64 -0
  54. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
  55. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  56. package/dist/esm-node/commands/build.js +2 -0
  57. package/dist/esm-node/commands/deploy.js +2 -2
  58. package/dist/esm-node/commands/dev.js +11 -7
  59. package/dist/esm-node/commands/index.js +92 -3
  60. package/dist/esm-node/commands/serve.js +10 -6
  61. package/dist/esm-node/hooks.js +5 -0
  62. package/dist/esm-node/index.js +12 -79
  63. package/dist/esm-node/plugins/analyze/constants.js +24 -0
  64. package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
  65. package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  66. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
  67. package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  68. package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
  69. package/dist/esm-node/plugins/analyze/templates.js +75 -0
  70. package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
  71. package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
  72. package/dist/esm-node/plugins/deploy/dependencies/utils.js +1 -2
  73. package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -10
  74. package/dist/esm-node/plugins/deploy/platforms/node.js +6 -14
  75. package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -10
  76. package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
  77. package/dist/esm-node/plugins/serverBuild.js +11 -5
  78. package/dist/esm-node/utils/createServer.js +2 -2
  79. package/dist/esm-node/utils/loadPlugins.js +21 -0
  80. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  81. package/dist/types/commands/index.d.ts +10 -3
  82. package/dist/types/config/initialize/inits.d.ts +1 -1
  83. package/dist/types/exports/server.d.ts +4 -0
  84. package/dist/types/index.d.ts +2 -5
  85. package/dist/types/plugins/analyze/constants.d.ts +9 -0
  86. package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
  87. package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
  88. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
  89. package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
  90. package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
  91. package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
  92. package/dist/types/plugins/analyze/templates.d.ts +19 -0
  93. package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
  94. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -9
  95. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
  96. package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
  97. package/dist/types/types/hooks.d.ts +11 -1
  98. package/dist/types/utils/loadPlugins.d.ts +5 -0
  99. package/package.json +22 -30
  100. package/dist/cjs/analyze/constants.js +0 -122
  101. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
  102. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
  103. package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
  104. package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
  105. package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
  106. package/dist/cjs/analyze/nestedRoutes.js +0 -295
  107. package/dist/cjs/analyze/templates.js +0 -444
  108. package/dist/cjs/plugins/deploy/exports.js +0 -28
  109. package/dist/esm/analyze/constants.js +0 -76
  110. package/dist/esm/analyze/getBundleEntry.js +0 -75
  111. package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
  112. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
  113. package/dist/esm/analyze/getClientRoutes/index.js +0 -6
  114. package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
  115. package/dist/esm/analyze/getFileSystemEntry.js +0 -113
  116. package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
  117. package/dist/esm/analyze/nestedRoutes.js +0 -398
  118. package/dist/esm/analyze/templates.js +0 -435
  119. package/dist/esm/plugins/deploy/exports.js +0 -4
  120. package/dist/esm/utils/getServerInternalPlugins.js +0 -40
  121. package/dist/esm-node/analyze/constants.js +0 -76
  122. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
  123. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
  124. package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
  125. package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
  126. package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
  127. package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
  128. package/dist/esm-node/analyze/nestedRoutes.js +0 -259
  129. package/dist/esm-node/analyze/templates.js +0 -405
  130. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  131. package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
  132. package/dist/js/modern/analyze/constants.js +0 -15
  133. package/dist/js/modern/analyze/generateCode.js +0 -179
  134. package/dist/js/modern/analyze/getBundleEntry.js +0 -75
  135. package/dist/js/modern/analyze/getClientRoutes.js +0 -219
  136. package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
  137. package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
  138. package/dist/js/modern/analyze/getServerRoutes.js +0 -192
  139. package/dist/js/modern/analyze/index.js +0 -148
  140. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
  141. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
  142. package/dist/js/modern/analyze/templates.js +0 -88
  143. package/dist/js/modern/analyze/utils.js +0 -92
  144. package/dist/js/modern/commands/build.js +0 -154
  145. package/dist/js/modern/commands/deploy.js +0 -5
  146. package/dist/js/modern/commands/dev.js +0 -95
  147. package/dist/js/modern/commands/index.js +0 -3
  148. package/dist/js/modern/commands/inspect.js +0 -69
  149. package/dist/js/modern/commands/start.js +0 -31
  150. package/dist/js/modern/exports/server.js +0 -1
  151. package/dist/js/modern/hooks.js +0 -21
  152. package/dist/js/modern/index.js +0 -109
  153. package/dist/js/modern/locale/en.js +0 -35
  154. package/dist/js/modern/locale/index.js +0 -9
  155. package/dist/js/modern/locale/zh.js +0 -35
  156. package/dist/js/modern/utils/config.js +0 -78
  157. package/dist/js/modern/utils/createCompiler.js +0 -61
  158. package/dist/js/modern/utils/createServer.js +0 -18
  159. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
  160. package/dist/js/modern/utils/language.js +0 -5
  161. package/dist/js/modern/utils/printInstructions.js +0 -11
  162. package/dist/js/modern/utils/routes.js +0 -15
  163. package/dist/js/modern/utils/types.js +0 -0
  164. package/dist/js/node/analyze/constants.js +0 -36
  165. package/dist/js/node/analyze/generateCode.js +0 -208
  166. package/dist/js/node/analyze/getBundleEntry.js +0 -89
  167. package/dist/js/node/analyze/getClientRoutes.js +0 -241
  168. package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
  169. package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
  170. package/dist/js/node/analyze/getServerRoutes.js +0 -208
  171. package/dist/js/node/analyze/index.js +0 -178
  172. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
  173. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
  174. package/dist/js/node/analyze/templates.js +0 -106
  175. package/dist/js/node/analyze/utils.js +0 -113
  176. package/dist/js/node/commands/build.js +0 -174
  177. package/dist/js/node/commands/deploy.js +0 -14
  178. package/dist/js/node/commands/dev.js +0 -120
  179. package/dist/js/node/commands/index.js +0 -44
  180. package/dist/js/node/commands/inspect.js +0 -98
  181. package/dist/js/node/commands/start.js +0 -47
  182. package/dist/js/node/exports/server.js +0 -13
  183. package/dist/js/node/hooks.js +0 -39
  184. package/dist/js/node/index.js +0 -141
  185. package/dist/js/node/locale/en.js +0 -42
  186. package/dist/js/node/locale/index.js +0 -20
  187. package/dist/js/node/locale/zh.js +0 -42
  188. package/dist/js/node/utils/config.js +0 -103
  189. package/dist/js/node/utils/createCompiler.js +0 -81
  190. package/dist/js/node/utils/createServer.js +0 -35
  191. package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
  192. package/dist/js/node/utils/language.js +0 -13
  193. package/dist/js/node/utils/printInstructions.js +0 -22
  194. package/dist/js/node/utils/routes.js +0 -25
  195. package/dist/js/node/utils/types.js +0 -0
  196. package/dist/types/analyze/constants.d.ts +0 -42
  197. package/dist/types/analyze/getBundleEntry.d.ts +0 -3
  198. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
  199. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
  200. package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
  201. package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
  202. package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
  203. package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
  204. package/dist/types/analyze/nestedRoutes.d.ts +0 -7
  205. package/dist/types/analyze/templates.d.ts +0 -30
  206. package/dist/types/plugins/deploy/exports.d.ts +0 -1
  207. package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
  208. /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  209. /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  210. /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  211. /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  212. /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  213. /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  214. /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -1,195 +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 getRoutesLegacy_exports = {};
30
- __export(getRoutesLegacy_exports, {
31
- getClientRoutes: () => getClientRoutes
32
- });
33
- module.exports = __toCommonJS(getRoutesLegacy_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
36
- var import_makeLegalIdentifier = require("../makeLegalIdentifier");
37
- var import_constants = require("../constants");
38
- var import_utils2 = require("../utils");
39
- var import_utils3 = require("./utils");
40
- const compName = (srcDirectory, filePath) => {
41
- const legalCompName = (0, import_makeLegalIdentifier.makeLegalIdentifier)(import_path.default.relative(srcDirectory, filePath));
42
- return `Comp_${legalCompName}`;
43
- };
44
- const layoutNameAbbr = (filePath) => {
45
- const prefix = "L_";
46
- const dirName = import_path.default.dirname(filePath).split("/").pop() || "";
47
- return `${prefix}${(0, import_makeLegalIdentifier.makeLegalIdentifier)(dirName)}`;
48
- };
49
- const parents = [];
50
- const recursiveReadDirLegacy = ({ dir, routes, basePath = "/", srcDirectory, srcAlias }) => {
51
- let hasDynamicRoute = false;
52
- let resetParent = false;
53
- let parent = parents[parents.length - 1];
54
- const layout = (0, import_utils3.findLayout)(dir);
55
- if (layout) {
56
- if (basePath === "/") {
57
- throw new Error(`should use _app instead of _layout in ${dir}`);
58
- } else {
59
- const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, layout, srcAlias);
60
- const componentName = compName(srcDirectory, layout);
61
- const route = {
62
- path: `${basePath.substring(0, basePath.length - 1)}`,
63
- exact: false,
64
- routes: [],
65
- _component: alias,
66
- component: componentName,
67
- parent
68
- };
69
- parent = route;
70
- resetParent = true;
71
- routes.push(route);
72
- parents.push(route);
73
- routes = route.routes;
74
- }
75
- }
76
- for (const relative of import_utils.fs.readdirSync(dir)) {
77
- const filePath = import_path.default.join(dir, relative);
78
- if (!(0, import_utils3.shouldSkip)(filePath)) {
79
- const filename = import_path.default.basename(filePath, import_path.default.extname(filePath));
80
- const alias = (0, import_utils2.replaceWithAlias)(srcDirectory, filePath, srcAlias);
81
- const componentName = compName(srcDirectory, filePath);
82
- const dynamicRouteMatched = import_constants.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
83
- if (dynamicRouteMatched) {
84
- if (hasDynamicRoute) {
85
- throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
86
- } else {
87
- hasDynamicRoute = true;
88
- }
89
- }
90
- const route = {
91
- path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1].replace(/\$$/, "?")}${dynamicRouteMatched[2]}` : filename}`,
92
- _component: alias,
93
- component: componentName,
94
- exact: true,
95
- parent
96
- };
97
- if (import_utils.fs.statSync(filePath).isDirectory()) {
98
- recursiveReadDirLegacy({
99
- dir: filePath,
100
- routes,
101
- basePath: `${route.path}/`,
102
- srcDirectory,
103
- srcAlias
104
- });
105
- continue;
106
- }
107
- if (filename === import_constants.FILE_SYSTEM_ROUTES_LAYOUT) {
108
- continue;
109
- }
110
- if (filename === import_constants.FILE_SYSTEM_ROUTES_INDEX) {
111
- route.path = basePath === "/" ? basePath : `${basePath.substring(0, basePath.length - 1)}`;
112
- }
113
- if (filename === "404" && basePath === "/") {
114
- route.path = "*";
115
- route.exact = false;
116
- }
117
- routes.push(route);
118
- }
119
- }
120
- if (resetParent) {
121
- parents.pop();
122
- }
123
- };
124
- const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
125
- const flat = (routes) => routes.reduce((memo, route) => memo.concat(Array.isArray(route.routes) ? flat(route.routes) : [
126
- route
127
- ]), []);
128
- const generate = (route) => {
129
- const codes = [];
130
- let lastComponent = route.component;
131
- const imports = [
132
- `import React from 'react';`,
133
- `import ${lastComponent} from '${route._component}'`
134
- ];
135
- while (route = route.parent) {
136
- const layoutComponent = route.component;
137
- const layoutComponentAbbr = layoutNameAbbr(route._component);
138
- imports.push(`import ${layoutComponent} from '${route._component}';`);
139
- const currentComponent = `${layoutComponentAbbr}_${lastComponent}`;
140
- codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
141
- lastComponent = currentComponent;
142
- }
143
- const file = import_path.default.resolve(internalComponentsDir, `${lastComponent}.jsx`);
144
- import_utils.fs.outputFileSync(file, `${imports.join("\n")}
145
- ${codes.join("\n")}
146
- export default ${lastComponent}`);
147
- return {
148
- component: lastComponent,
149
- _component: (0, import_utils2.replaceWithAlias)(internalDirectory, file, internalDirAlias)
150
- };
151
- };
152
- const normalized = flat(nested).map((route) => route.parent ? {
153
- ...route,
154
- ...generate(route),
155
- parent: void 0
156
- } : {
157
- ...route,
158
- parent: void 0
159
- });
160
- return normalized;
161
- };
162
- const getClientRoutes = ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias }) => {
163
- const { entry, entryName } = entrypoint;
164
- if (!import_utils.fs.existsSync(entry)) {
165
- throw new Error(`generate file system routes error, ${entry} directory not found.`);
166
- }
167
- if (!(import_utils.fs.existsSync(entry) && import_utils.fs.statSync(entry).isDirectory())) {
168
- throw new Error(`generate file system routes error, ${entry} should be directory.`);
169
- }
170
- let routes = [];
171
- recursiveReadDirLegacy({
172
- dir: entry,
173
- routes,
174
- basePath: "/",
175
- srcDirectory,
176
- srcAlias
177
- });
178
- const internalComponentsDir = import_path.default.resolve(internalDirectory, `${entryName}/${import_constants.FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
179
- import_utils.fs.emptyDirSync(internalComponentsDir);
180
- routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
181
- parents.length = 0;
182
- routes.sort((a, b) => {
183
- const delta = (0, import_utils3.getRouteWeight)(a.path) - (0, import_utils3.getRouteWeight)(b.path);
184
- if (delta === 0) {
185
- return a.path.length - b.path.length;
186
- }
187
- return delta;
188
- });
189
- (0, import_utils3.debug)(`fileSystem routes: %o`, routes);
190
- return routes;
191
- };
192
- // Annotate the CommonJS export names for ESM import in node:
193
- 0 && (module.exports = {
194
- getClientRoutes
195
- });
@@ -1,31 +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 getClientRoutes_exports = {};
20
- __export(getClientRoutes_exports, {
21
- getClientRoutes: () => import_getRoutes.getClientRoutes,
22
- getClientRoutesLegacy: () => import_getRoutesLegacy.getClientRoutes
23
- });
24
- module.exports = __toCommonJS(getClientRoutes_exports);
25
- var import_getRoutes = require("./getRoutes");
26
- var import_getRoutesLegacy = require("./getRoutesLegacy");
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- getClientRoutes,
30
- getClientRoutesLegacy
31
- });
@@ -1,59 +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 utils_exports = {};
30
- __export(utils_exports, {
31
- debug: () => debug,
32
- findLayout: () => findLayout,
33
- getRouteWeight: () => getRouteWeight,
34
- shouldSkip: () => shouldSkip
35
- });
36
- module.exports = __toCommonJS(utils_exports);
37
- var import_path = __toESM(require("path"));
38
- var import_utils = require("@modern-js/utils");
39
- var import_constants = require("../constants");
40
- const debug = (0, import_utils.createDebugger)("get-client-routes");
41
- const findLayout = (dir) => (0, import_utils.findExists)(import_constants.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.FILE_SYSTEM_ROUTES_LAYOUT}${ext}`)));
42
- const getRouteWeight = (route) => route === "*" ? 999 : route.split(":").length - 1;
43
- const shouldSkip = (file) => {
44
- if (import_utils.fs.statSync(file).isDirectory()) {
45
- return false;
46
- }
47
- const ext = import_path.default.extname(file);
48
- if (import_constants.FILE_SYSTEM_ROUTES_IGNORED_REGEX.test(file) || !import_constants.JS_EXTENSIONS.includes(ext) || import_constants.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT === import_path.default.basename(file, ext)) {
49
- return true;
50
- }
51
- return false;
52
- };
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- debug,
56
- findLayout,
57
- getRouteWeight,
58
- shouldSkip
59
- });
@@ -1,37 +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 makeLegalIdentifier_exports = {};
20
- __export(makeLegalIdentifier_exports, {
21
- makeLegalIdentifier: () => makeLegalIdentifier
22
- });
23
- module.exports = __toCommonJS(makeLegalIdentifier_exports);
24
- const reservedWords = "break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public";
25
- const builtins = "arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl";
26
- const forbidList = new Set(`${reservedWords} ${builtins}`.split(" "));
27
- function makeLegalIdentifier(str) {
28
- const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, "_");
29
- if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
30
- return `_${identifier}`;
31
- }
32
- return identifier || "_";
33
- }
34
- // Annotate the CommonJS export names for ESM import in node:
35
- 0 && (module.exports = {
36
- makeLegalIdentifier
37
- });
@@ -1,295 +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 nestedRoutes_exports = {};
30
- __export(nestedRoutes_exports, {
31
- getRouteId: () => getRouteId,
32
- optimizeRoute: () => optimizeRoute,
33
- walk: () => walk
34
- });
35
- module.exports = __toCommonJS(nestedRoutes_exports);
36
- var path = __toESM(require("path"));
37
- var import_utils = require("@modern-js/utils");
38
- var import_routes = require("../utils/routes");
39
- var import_constants = require("./constants");
40
- var import_utils2 = require("./utils");
41
- const conventionNames = Object.values(import_constants.NESTED_ROUTE);
42
- const replaceDynamicPath = (routePath) => {
43
- return routePath.replace(/\[(.*?)\]/g, ":$1");
44
- };
45
- const getRouteId = (componentPath, routesDir, entryName, isMainEntry) => {
46
- const relativePath = (0, import_utils.normalizeToPosixPath)(path.relative(routesDir, componentPath));
47
- const pathWithoutExt = (0, import_routes.getPathWithoutExt)(relativePath);
48
- let id = ``;
49
- if (isMainEntry) {
50
- id = pathWithoutExt;
51
- } else {
52
- id = `${entryName}_${pathWithoutExt}`;
53
- }
54
- return id.replace(/\[(.*?)\]/g, "($1)");
55
- };
56
- const createIndexRoute = (routeInfo, rootDir, filename, entryName, isMainEntry) => {
57
- return createRoute({
58
- ...routeInfo,
59
- index: true,
60
- children: void 0
61
- }, rootDir, filename, entryName, isMainEntry);
62
- };
63
- const createRoute = (routeInfo, rootDir, filename, entryName, isMainEntry) => {
64
- const id = getRouteId(filename, rootDir, entryName, isMainEntry);
65
- return {
66
- ...routeInfo,
67
- id,
68
- type: "nested"
69
- };
70
- };
71
- const optimizeRoute = (routeTree) => {
72
- if (!routeTree.children || routeTree.children.length === 0) {
73
- return [
74
- routeTree
75
- ];
76
- }
77
- const { children } = routeTree;
78
- if (!routeTree._component && !routeTree.error && !routeTree.loading && !routeTree.config && !routeTree.clientData) {
79
- const newRoutes = children.map((child) => {
80
- const routePath = `${routeTree.path ? routeTree.path : ""}${child.path ? `/${child.path}` : ""}`;
81
- const newRoute = {
82
- ...child,
83
- path: routePath.replace(/\/\//g, "/")
84
- };
85
- if (routePath.length > 0) {
86
- delete newRoute.index;
87
- } else {
88
- delete newRoute.path;
89
- }
90
- return newRoute;
91
- });
92
- return Array.from(new Set(newRoutes)).flatMap(optimizeRoute);
93
- } else {
94
- const optimizedChildren = routeTree.children.flatMap(optimizeRoute);
95
- return [
96
- {
97
- ...routeTree,
98
- children: optimizedChildren
99
- }
100
- ];
101
- }
102
- };
103
- const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion) => {
104
- var _finalRoute_children;
105
- if (!await import_utils.fs.pathExists(dirname)) {
106
- return null;
107
- }
108
- const isDirectory = (await import_utils.fs.stat(dirname)).isDirectory();
109
- if (!isDirectory) {
110
- return null;
111
- }
112
- const relativeDir = path.relative(rootDir, dirname);
113
- const pathSegments = relativeDir.split(path.sep);
114
- const lastSegment = pathSegments[pathSegments.length - 1];
115
- const isRoot = lastSegment === "";
116
- const isPathlessLayout = lastSegment.startsWith("__");
117
- const isWithoutLayoutPath = lastSegment.includes(".");
118
- let routePath = isRoot || isPathlessLayout ? "/" : `${lastSegment}`;
119
- if (isWithoutLayoutPath) {
120
- routePath = lastSegment.split(".").join("/");
121
- }
122
- routePath = replaceDynamicPath(routePath);
123
- const route = {
124
- path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
125
- children: [],
126
- isRoot
127
- };
128
- let pageLoaderFile = "";
129
- let pageRoute = null;
130
- let pageConfigFile = "";
131
- let pageClientData = "";
132
- let pageData = "";
133
- let pageAction = "";
134
- let splatLoaderFile = "";
135
- let splatRoute = null;
136
- let splatConfigFile = "";
137
- let splatClientData = "";
138
- let splatData = "";
139
- let splatAction = "";
140
- const items = await import_utils.fs.readdir(dirname);
141
- for (const item of items) {
142
- const itemPath = path.join(dirname, item);
143
- const itemPathWithAlias = (0, import_routes.getPathWithoutExt)((0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name));
144
- const extname = path.extname(item);
145
- const itemWithoutExt = item.slice(0, -extname.length);
146
- const isDirectory2 = (await import_utils.fs.stat(itemPath)).isDirectory();
147
- if (isDirectory2) {
148
- const childRoute = await walk(itemPath, rootDir, alias, entryName, isMainEntry, oldVersion);
149
- if (childRoute && !Array.isArray(childRoute)) {
150
- var _route_children;
151
- (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.push(childRoute);
152
- }
153
- }
154
- if (extname && (!import_constants.JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
155
- continue;
156
- }
157
- if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_LOADER_FILE) {
158
- if (!route.loader) {
159
- route.loader = itemPathWithAlias;
160
- }
161
- }
162
- if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_CLIENT_LOADER) {
163
- route.clientData = itemPathWithAlias;
164
- }
165
- if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_DATA_FILE) {
166
- route.data = itemPathWithAlias;
167
- if (await (0, import_utils2.hasAction)(itemPath)) {
168
- route.action = itemPathWithAlias;
169
- }
170
- }
171
- if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
172
- if (!route.config) {
173
- route.config = itemPathWithAlias;
174
- }
175
- }
176
- if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_FILE) {
177
- route._component = itemPathWithAlias;
178
- }
179
- if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_LOADER_FILE) {
180
- pageLoaderFile = itemPathWithAlias;
181
- }
182
- if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_CLIENT_LOADER) {
183
- pageClientData = itemPathWithAlias;
184
- }
185
- if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_DATA_FILE) {
186
- pageData = itemPathWithAlias;
187
- if (await (0, import_utils2.hasAction)(itemPath)) {
188
- pageAction = itemPathWithAlias;
189
- }
190
- }
191
- if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_CONFIG_FILE) {
192
- pageConfigFile = itemPathWithAlias;
193
- }
194
- if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_FILE) {
195
- var _route_children1;
196
- pageRoute = createIndexRoute({
197
- _component: itemPathWithAlias
198
- }, rootDir, itemPath, entryName, isMainEntry);
199
- if (pageLoaderFile) {
200
- pageRoute.loader = pageLoaderFile;
201
- }
202
- if (pageConfigFile) {
203
- pageRoute.config = pageConfigFile;
204
- }
205
- if (pageData) {
206
- pageRoute.data = pageData;
207
- }
208
- if (pageClientData) {
209
- pageRoute.clientData = pageClientData;
210
- }
211
- if (pageAction) {
212
- pageRoute.action = pageAction;
213
- }
214
- (_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(pageRoute);
215
- }
216
- if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_LOADER_FILE) {
217
- splatLoaderFile = itemPathWithAlias;
218
- }
219
- if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_CLIENT_DATA) {
220
- splatClientData = itemPathWithAlias;
221
- }
222
- if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_CONFIG_FILE) {
223
- if (!route.config) {
224
- splatConfigFile = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
225
- }
226
- }
227
- if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_DATA_FILE) {
228
- splatData = itemPathWithAlias;
229
- if (await (0, import_utils2.hasAction)(itemPath)) {
230
- splatAction = itemPathWithAlias;
231
- }
232
- }
233
- if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_FILE) {
234
- var _route_children2;
235
- splatRoute = createRoute({
236
- _component: itemPathWithAlias,
237
- path: "*"
238
- }, rootDir, itemPath, entryName, isMainEntry);
239
- if (splatLoaderFile) {
240
- splatRoute.loader = splatLoaderFile;
241
- }
242
- if (splatClientData) {
243
- splatRoute.clientData = splatClientData;
244
- }
245
- if (splatData) {
246
- splatRoute.data = splatData;
247
- }
248
- if (splatConfigFile) {
249
- splatRoute.config = splatConfigFile;
250
- }
251
- if (splatAction) {
252
- splatRoute.action = splatAction;
253
- }
254
- (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(splatRoute);
255
- }
256
- if (itemWithoutExt === import_constants.NESTED_ROUTE.LOADING_FILE) {
257
- route.loading = itemPathWithAlias;
258
- }
259
- if (itemWithoutExt === import_constants.NESTED_ROUTE.ERROR_FILE) {
260
- route.error = itemPathWithAlias;
261
- }
262
- }
263
- let finalRoute = createRoute(route, rootDir, path.join(dirname, `${import_constants.NESTED_ROUTE.LAYOUT_FILE}.ts`), entryName, isMainEntry);
264
- if (isPathlessLayout) {
265
- delete finalRoute.path;
266
- }
267
- const childRoutes = finalRoute.children = (_finalRoute_children = finalRoute.children) === null || _finalRoute_children === void 0 ? void 0 : _finalRoute_children.filter((childRoute) => childRoute);
268
- if (childRoutes && childRoutes.length === 0 && !finalRoute.index && !finalRoute._component) {
269
- return null;
270
- }
271
- if (childRoutes && childRoutes.length === 1 && !finalRoute._component) {
272
- const childRoute = childRoutes[0];
273
- if (childRoute.path === "*") {
274
- const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
275
- finalRoute = {
276
- ...childRoute,
277
- path: path2
278
- };
279
- }
280
- }
281
- if (isRoot && !finalRoute._component) {
282
- throw new Error("The root layout component is required, make sure the routes/layout.tsx file exists.");
283
- }
284
- if (isRoot && !oldVersion) {
285
- const optimizedRoutes = optimizeRoute(finalRoute);
286
- return optimizedRoutes;
287
- }
288
- return finalRoute;
289
- };
290
- // Annotate the CommonJS export names for ESM import in node:
291
- 0 && (module.exports = {
292
- getRouteId,
293
- optimizeRoute,
294
- walk
295
- });