@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,444 +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 templates_exports = {};
30
- __export(templates_exports, {
31
- fileSystemRoutes: () => fileSystemRoutes,
32
- html: () => html,
33
- index: () => index,
34
- renderFunction: () => renderFunction,
35
- routesForServer: () => routesForServer,
36
- ssrLoaderCombinedModule: () => ssrLoaderCombinedModule
37
- });
38
- module.exports = __toCommonJS(templates_exports);
39
- var import_path = __toESM(require("path"));
40
- var import_utils = require("@modern-js/utils");
41
- var import_constants = require("@modern-js/utils/universal/constants");
42
- var import_constants2 = require("./constants");
43
- var import_utils2 = require("./utils");
44
- const index = ({ mountId, imports, renderFunction: renderFunction2, exportStatement }) => `
45
- const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
46
- const IS_REACT18 = process.env.IS_REACT18 === 'true';
47
- const MOUNT_ID = '${mountId}';
48
-
49
- ${imports}
50
-
51
- let AppWrapper = null;
52
-
53
- let root = null;
54
-
55
- function render() {
56
- ${renderFunction2}
57
- }
58
-
59
- AppWrapper = render();
60
-
61
- ${exportStatement};
62
- `;
63
- const renderFunction = ({ plugins, customBootstrap, fileSystemRoutes: fileSystemRoutes2 }) => {
64
- const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
65
- return `
66
- const finalAppConfig = {
67
- ...App.config,
68
- ...typeof ${import_constants2.APP_CONFIG_NAME} === 'function' ? ${import_constants2.APP_CONFIG_NAME}() : {},
69
- }
70
-
71
- AppWrapper = createApp({
72
- plugins: [
73
- ${plugins.map(({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`).join("\n")}
74
- ]
75
- })(${fileSystemRoutes2 ? "" : `App`})
76
-
77
-
78
- if(!AppWrapper.init && typeof appInit !== 'undefined') {
79
- AppWrapper.init = appInit;
80
- }
81
-
82
-
83
- if (IS_BROWSER) {
84
- ${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
85
- }
86
-
87
- return AppWrapper
88
- `;
89
- };
90
- const html = (partials) => `
91
- <!DOCTYPE html>
92
- <html>
93
- <head>
94
-
95
- ${partials.top.join("\n")}
96
-
97
- ${partials.head.join("\n")}
98
-
99
- </head>
100
-
101
- <body>
102
- <div id="<%= mountId %>"><!--<?- html ?>--></div>
103
- ${partials.body.join("\n")}
104
- <!--<?- chunksMap.js ?>-->
105
- <!--<?- SSRDataScript ?>-->
106
- <!--<?- bottomTemplate ?>-->
107
- </body>
108
-
109
- </html>
110
- `;
111
- const routesForServer = ({ routes }) => {
112
- const loaders = [];
113
- const actions = [];
114
- const loadersMap = {};
115
- const traverseRouteTree = (route) => {
116
- let children;
117
- if ("children" in route && route.children) {
118
- var _route_children;
119
- children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
120
- }
121
- let loader;
122
- let action;
123
- if (route.type === "nested") {
124
- if (route.loader || route.data) {
125
- loaders.push(route.loader);
126
- const loaderId = loaders.length - 1;
127
- loader = `loader_${loaderId}`;
128
- const inline = Boolean(route.data);
129
- loadersMap[loader] = {
130
- loaderId,
131
- routeId: route.id,
132
- filePath: route.data || route.loader,
133
- clientData: Boolean(route.clientData),
134
- route,
135
- inline
136
- };
137
- if (route.action) {
138
- actions.push(route.action);
139
- action = `action_${loaders.length - 1}`;
140
- }
141
- }
142
- }
143
- const finalRoute = {
144
- ...route,
145
- loader,
146
- action,
147
- children
148
- };
149
- return finalRoute;
150
- };
151
- let routesCode = `
152
- export const routes = [
153
- `;
154
- for (const route of routes) {
155
- if ("type" in route) {
156
- const keywords = [
157
- "loader",
158
- "action"
159
- ];
160
- const regs = keywords.map(createMatchReg);
161
- const newRoute = traverseRouteTree(route);
162
- const routeStr = JSON.stringify(newRoute, null, 2);
163
- routesCode += regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/\\"/g, '"');
164
- } else {
165
- routesCode += `${JSON.stringify(route, null, 2)}`;
166
- }
167
- }
168
- routesCode += `
169
- ];`;
170
- let importLoadersCode = "";
171
- for (const [key, loaderInfo] of Object.entries(loadersMap)) {
172
- if (loaderInfo.inline) {
173
- const { route } = loaderInfo;
174
- if (route.action) {
175
- importLoadersCode += `import { loader as ${key}, action as action_${loaderInfo.loaderId} } from "${(0, import_utils.slash)(loaderInfo.filePath)}";
176
- `;
177
- } else {
178
- importLoadersCode += `import { loader as ${key} } from "${(0, import_utils.slash)(loaderInfo.filePath)}";
179
- `;
180
- }
181
- } else {
182
- importLoadersCode += `import ${key} from "${(0, import_utils.slash)(loaderInfo.filePath)}";
183
- `;
184
- }
185
- }
186
- return `
187
- ${importLoadersCode}
188
- ${routesCode}
189
- `;
190
- };
191
- const createMatchReg = (keyword) => new RegExp(`("${keyword}":\\s)"([^
192
- ]+)"`, "g");
193
- const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, splitRouteChunks = true }) => {
194
- const components = [];
195
- const loadings = [];
196
- const errors = [];
197
- const loaders = [];
198
- const loadersMap = {};
199
- const configs = [];
200
- const configsMap = {};
201
- const loadersMapFile = import_path.default.join(internalDirectory, entryName, import_constants2.TEMP_LOADERS_DIR, "map.json");
202
- const importLazyCode = `
203
- import { lazy } from "react";
204
- import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
205
- `;
206
- let rootLayoutCode = ``;
207
- const getDataLoaderPath = ({ loaderId, clientData, action, inline, routeId }) => {
208
- if (!ssrMode) {
209
- return "";
210
- }
211
- const clientDataStr = clientData ? `&clientData=${clientData}` : "";
212
- if (nestedRoutesEntry) {
213
- return `?loaderId=${loaderId}${clientDataStr}&action=${action ? (0, import_utils.slash)(action) : action}&inline=${inline}&routeId=${routeId}`;
214
- }
215
- return "";
216
- };
217
- const traverseRouteTree = (route) => {
218
- let children;
219
- if ("children" in route && route.children) {
220
- var _route_children;
221
- children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
222
- }
223
- let loading;
224
- let error;
225
- let loader;
226
- let action;
227
- let config;
228
- let component = "";
229
- let lazyImport = null;
230
- if (route.type === "nested") {
231
- if (route.loading) {
232
- loadings.push(route.loading);
233
- loading = `loading_${loadings.length - 1}`;
234
- }
235
- if (route.error) {
236
- errors.push(route.error);
237
- error = `error_${errors.length - 1}`;
238
- }
239
- if (route.loader || route.data) {
240
- loaders.push(route.loader);
241
- const loaderId = loaders.length - 1;
242
- loader = `loader_${loaderId}`;
243
- const inline = Boolean(route.data);
244
- loadersMap[loader] = {
245
- loaderId,
246
- routeId: route.id,
247
- filePath: route.data || route.loader,
248
- clientData: Boolean(route.clientData),
249
- route,
250
- inline
251
- };
252
- loader = `loader_${loaderId}`;
253
- if (route.action) {
254
- action = `action_${loaderId}`;
255
- }
256
- }
257
- if (typeof route.config === "string") {
258
- configs.push(route.config);
259
- const configId = configs.length - 1;
260
- config = `config_${configId}`;
261
- configsMap[config] = route.config;
262
- }
263
- if (route._component) {
264
- if (splitRouteChunks) {
265
- if (route.isRoot) {
266
- lazyImport = `() => import('${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
267
- rootLayoutCode = `import RootLayout from '${route._component}'`;
268
- component = `RootLayout`;
269
- } else if (ssrMode === "string") {
270
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
271
- component = `loadable(${lazyImport})`;
272
- } else {
273
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
274
- component = `lazy(${lazyImport})`;
275
- }
276
- } else if (ssrMode === "string") {
277
- components.push(route._component);
278
- component = `component_${components.length - 1}`;
279
- } else {
280
- lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
281
- component = `lazy(${lazyImport})`;
282
- }
283
- }
284
- } else if (route._component) {
285
- if (splitRouteChunks) {
286
- lazyImport = `() => import('${route._component}')`;
287
- component = `loadable(${lazyImport})`;
288
- } else {
289
- components.push(route._component);
290
- component = `component_${components.length - 1}`;
291
- }
292
- }
293
- const finalRoute = {
294
- ...route,
295
- lazyImport,
296
- loading,
297
- loader,
298
- action,
299
- config,
300
- error,
301
- children
302
- };
303
- if (route._component) {
304
- finalRoute.component = component;
305
- }
306
- if (route.type === "nested" && route._component && (route.loader || route.data)) {
307
- finalRoute.shouldRevalidate = `createShouldRevalidate("${route.id}")`;
308
- }
309
- return finalRoute;
310
- };
311
- let routeComponentsCode = `
312
- export const routes = [
313
- `;
314
- for (const route of routes) {
315
- if ("type" in route) {
316
- const newRoute = traverseRouteTree(route);
317
- const routeStr = JSON.stringify(newRoute, null, 2);
318
- const keywords = [
319
- "component",
320
- "lazyImport",
321
- "shouldRevalidate",
322
- "loader",
323
- "action",
324
- "loading",
325
- "error",
326
- "config"
327
- ];
328
- const regs = keywords.map(createMatchReg);
329
- const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/"(RootLayout)"/g, "$1").replace(/\\"/g, '"');
330
- routeComponentsCode += `${newRouteStr},`;
331
- } else {
332
- const component = `loadable(() => import('${route._component}'))`;
333
- const finalRoute = {
334
- ...route,
335
- component
336
- };
337
- const keywords = [
338
- "component",
339
- "lazyImport"
340
- ];
341
- const routeStr = JSON.stringify(finalRoute, null, 2);
342
- const regs = keywords.map(createMatchReg);
343
- const newRouteStr = regs.reduce((acc, reg) => acc.replace(reg, "$1$2"), routeStr).replace(/\\"/g, '"');
344
- routeComponentsCode += `${newRouteStr},`;
345
- }
346
- }
347
- routeComponentsCode += `
348
- ];`;
349
- const importLoadingCode = loadings.map((loading, index2) => {
350
- return `import loading_${index2} from '${loading}';
351
- `;
352
- }).join("");
353
- const importComponentsCode = components.map((component, index2) => {
354
- return `import component_${index2} from '${component}';
355
- `;
356
- }).join("");
357
- const importErrorComponentsCode = errors.map((error, index2) => {
358
- return `import error_${index2} from '${error}';
359
- `;
360
- }).join("");
361
- let importLoadersCode = "";
362
- for (const [key, loaderInfo] of Object.entries(loadersMap)) {
363
- if (loaderInfo.inline) {
364
- const { route } = loaderInfo;
365
- if (route.action) {
366
- importLoadersCode += `import { loader as ${key}, action as action_${loaderInfo.loaderId} } from "${(0, import_utils.slash)(loaderInfo.filePath)}${getDataLoaderPath({
367
- loaderId: key,
368
- clientData: loaderInfo.clientData,
369
- action: route.action,
370
- inline: loaderInfo.inline,
371
- routeId: loaderInfo.routeId
372
- })}";
373
- `;
374
- } else {
375
- importLoadersCode += `import { loader as ${key} } from "${(0, import_utils.slash)(loaderInfo.filePath)}${getDataLoaderPath({
376
- loaderId: key,
377
- clientData: loaderInfo.clientData,
378
- action: false,
379
- inline: loaderInfo.inline,
380
- routeId: route.id
381
- })}";
382
- `;
383
- }
384
- } else {
385
- importLoadersCode += `import ${key} from "${(0, import_utils.slash)(loaderInfo.filePath)}${getDataLoaderPath({
386
- loaderId: key,
387
- clientData: loaderInfo.clientData,
388
- action: false,
389
- inline: loaderInfo.inline,
390
- routeId: loaderInfo.routeId
391
- })}";
392
- `;
393
- }
394
- }
395
- let importConfigsCode = "";
396
- for (const [key, configPath] of Object.entries(configsMap)) {
397
- importConfigsCode += `import * as ${key} from "${(0, import_utils.slash)(configPath)}";
398
- `;
399
- }
400
- await import_utils.fs.ensureFile(loadersMapFile);
401
- await import_utils.fs.writeJSON(loadersMapFile, loadersMap);
402
- const importRuntimeRouterCode = `
403
- import { createShouldRevalidate, handleRouteModule, handleRouteModuleError} from '@modern-js/runtime/router';
404
- `;
405
- const routeModulesCode = `
406
- if(typeof document !== 'undefined'){
407
- window.${import_constants.ROUTE_MODULES} = {}
408
- }
409
- `;
410
- return `
411
- ${importLazyCode}
412
- ${importComponentsCode}
413
- ${importRuntimeRouterCode}
414
- ${rootLayoutCode}
415
- ${importLoadingCode}
416
- ${importErrorComponentsCode}
417
- ${importLoadersCode}
418
- ${importConfigsCode}
419
- ${routeModulesCode}
420
- ${routeComponentsCode}
421
- `;
422
- };
423
- function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
424
- const { entryName, isMainEntry } = entrypoint;
425
- const { packageName, internalDirectory } = appContext;
426
- const ssr = (0, import_utils.getEntryOptions)(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
427
- const ssg = (0, import_utils.isSSGEntry)(config, entryName, entrypoints);
428
- if (entrypoint.nestedRoutesEntry && (ssr || ssg)) {
429
- const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
430
- const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(internalDirectory, entryName);
431
- const combinedModule = `export * from "${(0, import_utils.slash)(serverLoaderRuntime)}"; export * from "${(0, import_utils.slash)(serverLoadersFile)}"`;
432
- return combinedModule;
433
- }
434
- return null;
435
- }
436
- // Annotate the CommonJS export names for ESM import in node:
437
- 0 && (module.exports = {
438
- fileSystemRoutes,
439
- html,
440
- index,
441
- renderFunction,
442
- routesForServer,
443
- ssrLoaderCombinedModule
444
- });
@@ -1,28 +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 exports_exports = {};
20
- __export(exports_exports, {
21
- handleDependencies: () => import_dependencies.handleDependencies
22
- });
23
- module.exports = __toCommonJS(exports_exports);
24
- var import_dependencies = require("./dependencies");
25
- // Annotate the CommonJS export names for ESM import in node:
26
- 0 && (module.exports = {
27
- handleDependencies
28
- });
@@ -1,76 +0,0 @@
1
- var JS_EXTENSIONS = [
2
- ".js",
3
- ".ts",
4
- ".jsx",
5
- ".tsx"
6
- ];
7
- var INDEX_FILE_NAME = "index";
8
- var APP_FILE_NAME = "App";
9
- var PAGES_DIR_NAME = "pages";
10
- var NESTED_ROUTES_DIR = "routes";
11
- var FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
12
- var LOADER_EXPORT_NAME = "loader";
13
- var ACTION_EXPORT_NAME = "action";
14
- var TEMP_LOADERS_DIR = "__loaders__";
15
- var ENTRY_POINT_FILE_NAME = "index.jsx";
16
- var ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
17
- var FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
18
- var FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
19
- var FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
20
- var FILE_SYSTEM_ROUTES_INDEX = "index";
21
- var FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
22
- var HTML_PARTIALS_FOLDER = "html";
23
- var HTML_PARTIALS_EXTENSIONS = [
24
- ".htm",
25
- ".html",
26
- ".ejs"
27
- ];
28
- var FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
29
- var NESTED_ROUTE = {
30
- LAYOUT_FILE: "layout",
31
- LAYOUT_CONFIG_FILE: "layout.config",
32
- LAYOUT_LOADER_FILE: "layout.loader",
33
- LAYOUT_DATA_FILE: "layout.data",
34
- LAYOUT_CLIENT_LOADER: "layout.data.client",
35
- PAGE_FILE: "page",
36
- PAGE_CONFIG_FILE: "page.config",
37
- PAGE_LOADER_FILE: "page.loader",
38
- PAGE_DATA_FILE: "page.data",
39
- PAGE_CLIENT_LOADER: "page.data.client",
40
- SPLATE_FILE: "$",
41
- SPLATE_CONFIG_FILE: "$.config",
42
- SPLATE_LOADER_FILE: "$.loader",
43
- SPLATE_DATA_FILE: "$.data",
44
- SPLATE_CLIENT_DATA: "$.data.client",
45
- LOADING_FILE: "loading",
46
- ERROR_FILE: "error",
47
- LOADER_FILE: "loader"
48
- };
49
- var APP_CONFIG_NAME = "config";
50
- var APP_INIT_EXPORTED = "init";
51
- var APP_INIT_IMPORTED = "appInit";
52
- export {
53
- ACTION_EXPORT_NAME,
54
- APP_CONFIG_NAME,
55
- APP_FILE_NAME,
56
- APP_INIT_EXPORTED,
57
- APP_INIT_IMPORTED,
58
- ENTRY_BOOTSTRAP_FILE_NAME,
59
- ENTRY_POINT_FILE_NAME,
60
- FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
61
- FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
62
- FILE_SYSTEM_ROUTES_FILE_NAME,
63
- FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
64
- FILE_SYSTEM_ROUTES_IGNORED_REGEX,
65
- FILE_SYSTEM_ROUTES_INDEX,
66
- FILE_SYSTEM_ROUTES_LAYOUT,
67
- HTML_PARTIALS_EXTENSIONS,
68
- HTML_PARTIALS_FOLDER,
69
- INDEX_FILE_NAME,
70
- JS_EXTENSIONS,
71
- LOADER_EXPORT_NAME,
72
- NESTED_ROUTE,
73
- NESTED_ROUTES_DIR,
74
- PAGES_DIR_NAME,
75
- TEMP_LOADERS_DIR
76
- };
@@ -1,75 +0,0 @@
1
- import path from "path";
2
- import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME, isRouterV5 } from "@modern-js/utils";
3
- import { getFileSystemEntry } from "./getFileSystemEntry";
4
- import { JS_EXTENSIONS } from "./constants";
5
- import { isSubDirOrEqual } from "./utils";
6
- var ensureExtensions = function(file) {
7
- if (!path.extname(file)) {
8
- return findExists(JS_EXTENSIONS.map(function(ext) {
9
- return "".concat(file).concat(ext);
10
- })) || file;
11
- }
12
- return file;
13
- };
14
- var isDirectory = function(file) {
15
- return !path.extname(file);
16
- };
17
- var ifAlreadyExists = function(entrypoints, checked) {
18
- return entrypoints.some(function(entrypoint) {
19
- if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
20
- checked.entryName = entrypoint.entryName;
21
- return true;
22
- }
23
- if (isSubDirOrEqual(entrypoint.entry, checked.entry) || isSubDirOrEqual(checked.entry, entrypoint.entry)) {
24
- throw new Error("Entry configuration conflicts\n Your configuration: ".concat(checked.entry, ".\n Default entrypoint: ").concat(entrypoint.entry, "\n Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules."));
25
- }
26
- return false;
27
- });
28
- };
29
- var getBundleEntry = function(appContext, config) {
30
- var appDirectory = appContext.appDirectory, packageName = appContext.packageName;
31
- var _config_source = config.source, disableDefaultEntries = _config_source.disableDefaultEntries, entries = _config_source.entries, entriesDir = _config_source.entriesDir, mainEntryName = _config_source.mainEntryName;
32
- var defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config);
33
- if (entries) {
34
- Object.keys(entries).forEach(function(name) {
35
- var value = entries[name];
36
- var entrypoint = typeof value === "string" ? {
37
- entryName: name,
38
- isMainEntry: false,
39
- entry: ensureAbsolutePath(appDirectory, value),
40
- absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, value)) ? ensureAbsolutePath(appDirectory, value) : path.dirname(ensureAbsolutePath(appDirectory, value)),
41
- isAutoMount: true,
42
- fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value)).isDirectory() ? {} : void 0
43
- } : {
44
- entryName: name,
45
- isMainEntry: false,
46
- entry: ensureAbsolutePath(appDirectory, value.entry),
47
- absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, value.entry)) ? ensureAbsolutePath(appDirectory, value.entry) : path.dirname(ensureAbsolutePath(appDirectory, value.entry)),
48
- isAutoMount: !value.disableMount,
49
- customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
50
- fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
51
- };
52
- if (entrypoint.fileSystemRoutes && !isRouterV5(config)) {
53
- entrypoint.nestedRoutesEntry = entrypoint.entry;
54
- }
55
- if (!ifAlreadyExists(defaults, entrypoint)) {
56
- defaults.push(entrypoint);
57
- }
58
- });
59
- }
60
- if (!disableDefaultEntries) {
61
- var entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir || "");
62
- var found = defaults.find(function(param) {
63
- var entryName = param.entryName, entry = param.entry, _param_nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _param_nestedRoutesEntry === void 0 ? "" : _param_nestedRoutesEntry;
64
- return entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs;
65
- });
66
- if (found) {
67
- found.entryName = mainEntryName || MAIN_ENTRY_NAME;
68
- found.isMainEntry = true;
69
- }
70
- }
71
- return defaults;
72
- };
73
- export {
74
- getBundleEntry
75
- };