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

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 (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
@@ -2,12 +2,10 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  import path from "path";
5
- import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
5
+ import { findExists, fs, getEntryOptions, JS_EXTENSIONS, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
6
6
  import * as templates from "./templates";
7
- import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
8
- import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
9
- import { getDefaultImports, getServerLoadersFile, getServerCombinedModueFile } from "./utils";
10
- import { walk } from "./nestedRoutes";
7
+ import { ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
8
+ import { getDefaultImports } from "./utils";
11
9
  var createImportSpecifier = function(specifiers) {
12
10
  var defaults = "";
13
11
  var named = [];
@@ -94,170 +92,22 @@ var createImportStatements = function(statements) {
94
92
  };
95
93
  var generateCode = function() {
96
94
  var _ref = _async_to_generator(function(appContext, config, entrypoints, api) {
97
- var internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, getRoutes, importsStatemets, oldVersion;
98
- function generateEntryCode(entrypoint) {
95
+ var internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, runtimeConfigFile, hookRunners, customRuntimeConfig, importsStatemets;
96
+ function generateEntryCode(entrypoint, customRuntimeConfig2) {
99
97
  return _generateEntryCode.apply(this, arguments);
100
98
  }
101
99
  function _generateEntryCode() {
102
- _generateEntryCode = _async_to_generator(function(entrypoint) {
103
- var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, initialRoutes, nestedRoutes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile, imports, entryFile;
100
+ _generateEntryCode = _async_to_generator(function(entrypoint, customRuntimeConfig2) {
101
+ var entryName, isAutoMount, imports, entryFile;
104
102
  return _ts_generator(this, function(_state) {
105
103
  switch (_state.label) {
106
104
  case 0:
107
- entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, isAutoMount = entrypoint.isAutoMount, fileSystemRoutes = entrypoint.fileSystemRoutes;
105
+ entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount;
108
106
  if (!isAutoMount)
109
- return [
110
- 3,
111
- 13
112
- ];
113
- if (!fileSystemRoutes)
114
- return [
115
- 3,
116
- 11
117
- ];
118
- initialRoutes = [];
119
- nestedRoutes = null;
120
- if (entrypoint.entry) {
121
- initialRoutes = getRoutes({
122
- entrypoint,
123
- srcDirectory,
124
- srcAlias: internalSrcAlias,
125
- internalDirectory,
126
- internalDirAlias
127
- });
128
- }
129
- if (!(!isV5 && entrypoint.nestedRoutesEntry))
130
107
  return [
131
108
  3,
132
109
  2
133
110
  ];
134
- return [
135
- 4,
136
- walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
137
- name: internalSrcAlias,
138
- basename: srcDirectory
139
- }, entrypoint.entryName, entrypoint.isMainEntry, oldVersion)
140
- ];
141
- case 1:
142
- nestedRoutes = _state.sent();
143
- if (nestedRoutes) {
144
- if (!Array.isArray(nestedRoutes)) {
145
- nestedRoutes = [
146
- nestedRoutes
147
- ];
148
- }
149
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
150
- try {
151
- for (_iterator = nestedRoutes[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
152
- route = _step.value;
153
- initialRoutes.unshift(route);
154
- }
155
- } catch (err) {
156
- _didIteratorError = true;
157
- _iteratorError = err;
158
- } finally {
159
- try {
160
- if (!_iteratorNormalCompletion && _iterator.return != null) {
161
- _iterator.return();
162
- }
163
- } finally {
164
- if (_didIteratorError) {
165
- throw _iteratorError;
166
- }
167
- }
168
- }
169
- }
170
- _state.label = 2;
171
- case 2:
172
- return [
173
- 4,
174
- hookRunners.modifyFileSystemRoutes({
175
- entrypoint,
176
- routes: initialRoutes
177
- })
178
- ];
179
- case 3:
180
- routes = _state.sent().routes;
181
- _$config = api.useResolvedConfigContext();
182
- ssr = getEntryOptions(entryName, isMainEntry, _$config.server.ssr, _$config.server.ssrByEntries, packageName);
183
- useSSG = isSSGEntry(_$config, entryName, entrypoints);
184
- if (ssr) {
185
- mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
186
- }
187
- if (mode === "stream") {
188
- hasPageRoute = routes.some(function(route2) {
189
- return "type" in route2 && route2.type === "page";
190
- });
191
- if (hasPageRoute) {
192
- logger.error("Streaming ssr is not supported when pages dir exists");
193
- process.exit(1);
194
- }
195
- }
196
- _ = hookRunners.beforeGenerateRoutes;
197
- _tmp = {
198
- entrypoint
199
- };
200
- return [
201
- 4,
202
- templates.fileSystemRoutes({
203
- routes,
204
- ssrMode: useSSG ? "string" : mode,
205
- nestedRoutesEntry: entrypoint.nestedRoutesEntry,
206
- entryName: entrypoint.entryName,
207
- internalDirectory,
208
- splitRouteChunks: _$config === null || _$config === void 0 ? void 0 : (_config_output = _$config.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
209
- })
210
- ];
211
- case 4:
212
- return [
213
- 4,
214
- _.apply(hookRunners, [
215
- (_tmp.code = _state.sent(), _tmp)
216
- ])
217
- ];
218
- case 5:
219
- code = _state.sent().code;
220
- if (!(entrypoint.nestedRoutesEntry && isUseSSRBundle(_$config)))
221
- return [
222
- 3,
223
- 8
224
- ];
225
- routesServerFile = getServerLoadersFile(internalDirectory, entryName);
226
- code1 = templates.routesForServer({
227
- routes
228
- });
229
- return [
230
- 4,
231
- fs.ensureFile(routesServerFile)
232
- ];
233
- case 6:
234
- _state.sent();
235
- return [
236
- 4,
237
- fs.writeFile(routesServerFile, code1)
238
- ];
239
- case 7:
240
- _state.sent();
241
- _state.label = 8;
242
- case 8:
243
- serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, _$config, appContext);
244
- if (!serverLoaderCombined)
245
- return [
246
- 3,
247
- 10
248
- ];
249
- serverLoaderFile = getServerCombinedModueFile(internalDirectory, entryName);
250
- return [
251
- 4,
252
- fs.outputFile(serverLoaderFile, serverLoaderCombined)
253
- ];
254
- case 9:
255
- _state.sent();
256
- _state.label = 10;
257
- case 10:
258
- fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code, "utf8");
259
- _state.label = 11;
260
- case 11:
261
111
  return [
262
112
  4,
263
113
  hookRunners.modifyEntryImports({
@@ -267,17 +117,19 @@ var generateCode = function() {
267
117
  srcDirectory,
268
118
  appDirectory,
269
119
  internalSrcAlias,
270
- internalDirAlias
120
+ internalDirAlias,
121
+ runtimeConfigFile,
122
+ customRuntimeConfig: customRuntimeConfig2
271
123
  })
272
124
  })
273
125
  ];
274
- case 12:
126
+ case 1:
275
127
  imports = _state.sent().imports;
276
128
  importsStatemets.set(entryName, imports);
277
129
  entryFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
278
130
  entrypoint.internalEntry = entryFile;
279
- _state.label = 13;
280
- case 13:
131
+ _state.label = 2;
132
+ case 2:
281
133
  return [
282
134
  2
283
135
  ];
@@ -289,15 +141,17 @@ var generateCode = function() {
289
141
  return _ts_generator(this, function(_state) {
290
142
  switch (_state.label) {
291
143
  case 0:
292
- internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, appDirectory = appContext.appDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
144
+ internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, appDirectory = appContext.appDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, runtimeConfigFile = appContext.runtimeConfigFile;
293
145
  hookRunners = api.useHookRunners();
294
- isV5 = isRouterV5(config);
295
- getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
146
+ customRuntimeConfig = findExists(JS_EXTENSIONS.map(function(ext) {
147
+ return path.resolve(srcDirectory, "".concat(runtimeConfigFile).concat(ext));
148
+ }));
296
149
  importsStatemets = /* @__PURE__ */ new Map();
297
- oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
298
150
  return [
299
151
  4,
300
- Promise.all(entrypoints.map(generateEntryCode))
152
+ Promise.all(entrypoints.map(function(entrypoint) {
153
+ return generateEntryCode(entrypoint, customRuntimeConfig);
154
+ }))
301
155
  ];
302
156
  case 1:
303
157
  _state.sent();
@@ -316,14 +170,17 @@ var generateCode = function() {
316
170
  }();
317
171
  var generateIndexCode = function() {
318
172
  var _ref = _async_to_generator(function(param) {
319
- var appContext, api, entrypoints, config, importsStatemets, bundlerConfigs, hookRunners, mountId, internalDirectory, packageName;
173
+ var appContext, api, entrypoints, config, importsStatemets, bundlerConfigs, hookRunners, mountId, internalDirectory, packageName, srcDirectory, runtimeConfigFile, customRuntimeConfig;
320
174
  return _ts_generator(this, function(_state) {
321
175
  switch (_state.label) {
322
176
  case 0:
323
177
  appContext = param.appContext, api = param.api, entrypoints = param.entrypoints, config = param.config, importsStatemets = param.importsStatemets, bundlerConfigs = param.bundlerConfigs;
324
178
  hookRunners = api.useHookRunners();
325
179
  mountId = config.html.mountId;
326
- internalDirectory = appContext.internalDirectory, packageName = appContext.packageName;
180
+ internalDirectory = appContext.internalDirectory, packageName = appContext.packageName, srcDirectory = appContext.srcDirectory, runtimeConfigFile = appContext.runtimeConfigFile;
181
+ customRuntimeConfig = findExists(JS_EXTENSIONS.map(function(ext) {
182
+ return path.resolve(srcDirectory, "".concat(runtimeConfigFile).concat(ext));
183
+ }));
327
184
  return [
328
185
  4,
329
186
  Promise.all(entrypoints.map(function() {
@@ -355,6 +212,7 @@ var generateIndexCode = function() {
355
212
  code: templates.renderFunction({
356
213
  plugins,
357
214
  customBootstrap,
215
+ customRuntimeConfig,
358
216
  fileSystemRoutes
359
217
  })
360
218
  })
@@ -0,0 +1,101 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import path from "path";
4
+ import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME, JS_EXTENSIONS } from "@modern-js/utils";
5
+ import { getFileSystemEntry } from "./getFileSystemEntry";
6
+ import { isSubDirOrEqual } from "./utils";
7
+ var ensureExtensions = function(file) {
8
+ if (!path.extname(file)) {
9
+ return findExists(JS_EXTENSIONS.map(function(ext) {
10
+ return "".concat(file).concat(ext);
11
+ })) || file;
12
+ }
13
+ return file;
14
+ };
15
+ var isDirectory = function(file) {
16
+ return !path.extname(file);
17
+ };
18
+ var ifAlreadyExists = function(entrypoints, checked) {
19
+ return entrypoints.some(function(entrypoint) {
20
+ if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
21
+ checked.entryName = entrypoint.entryName;
22
+ return true;
23
+ }
24
+ if (isSubDirOrEqual(entrypoint.entry, checked.entry) || isSubDirOrEqual(checked.entry, entrypoint.entry)) {
25
+ 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."));
26
+ }
27
+ return false;
28
+ });
29
+ };
30
+ var getBundleEntry = function() {
31
+ var _ref = _async_to_generator(function(hookRunners, appContext, config) {
32
+ var appDirectory, packageName, _config_source, disableDefaultEntries, entries, entriesDir, mainEntryName, defaults, _tmp, entriesDirAbs, found;
33
+ return _ts_generator(this, function(_state) {
34
+ switch (_state.label) {
35
+ case 0:
36
+ appDirectory = appContext.appDirectory, packageName = appContext.packageName;
37
+ _config_source = config.source, disableDefaultEntries = _config_source.disableDefaultEntries, entries = _config_source.entries, entriesDir = _config_source.entriesDir, mainEntryName = _config_source.mainEntryName;
38
+ if (!disableDefaultEntries)
39
+ return [
40
+ 3,
41
+ 1
42
+ ];
43
+ _tmp = [];
44
+ return [
45
+ 3,
46
+ 3
47
+ ];
48
+ case 1:
49
+ return [
50
+ 4,
51
+ getFileSystemEntry(hookRunners, appContext, config)
52
+ ];
53
+ case 2:
54
+ _tmp = _state.sent();
55
+ _state.label = 3;
56
+ case 3:
57
+ defaults = _tmp;
58
+ if (entries) {
59
+ Object.keys(entries).forEach(function(name) {
60
+ var value = entries[name];
61
+ var entryName = typeof value === "string" ? value : value.entry;
62
+ var isAutoMount = typeof value === "string" ? true : !value.disableMount;
63
+ var entrypoint = {
64
+ entryName: name,
65
+ isMainEntry: false,
66
+ entry: ensureAbsolutePath(appDirectory, entryName),
67
+ absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, entryName)) ? ensureAbsolutePath(appDirectory, entryName) : path.dirname(ensureAbsolutePath(appDirectory, entryName)),
68
+ isAutoMount,
69
+ customBootstrap: typeof value === "string" ? false : value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
70
+ fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, entryName)).isDirectory() ? {} : void 0
71
+ };
72
+ if (!ifAlreadyExists(defaults, entrypoint)) {
73
+ defaults.push(entrypoint);
74
+ }
75
+ });
76
+ }
77
+ if (!disableDefaultEntries) {
78
+ entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir || "");
79
+ found = defaults.find(function(param) {
80
+ var entryName = param.entryName, entry = param.entry, _param_nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _param_nestedRoutesEntry === void 0 ? "" : _param_nestedRoutesEntry;
81
+ return entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs;
82
+ });
83
+ if (found) {
84
+ found.entryName = mainEntryName || MAIN_ENTRY_NAME;
85
+ found.isMainEntry = true;
86
+ }
87
+ }
88
+ return [
89
+ 2,
90
+ defaults
91
+ ];
92
+ }
93
+ });
94
+ });
95
+ return function getBundleEntry2(hookRunners, appContext, config) {
96
+ return _ref.apply(this, arguments);
97
+ };
98
+ }();
99
+ export {
100
+ getBundleEntry
101
+ };
@@ -0,0 +1,195 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import { findExists, ensureAbsolutePath, JS_EXTENSIONS } from "@modern-js/utils";
6
+ import { INDEX_FILE_NAME } from "./constants";
7
+ import { isDefaultExportFunction } from "./isDefaultExportFunction";
8
+ var hasIndex = function(dir) {
9
+ return findExists(JS_EXTENSIONS.map(function(ext) {
10
+ return path.resolve(dir, "".concat(INDEX_FILE_NAME).concat(ext));
11
+ }));
12
+ };
13
+ var isBundleEntry = function() {
14
+ var _ref = _async_to_generator(function(hookRunners, dir) {
15
+ return _ts_generator(this, function(_state) {
16
+ switch (_state.label) {
17
+ case 0:
18
+ return [
19
+ 4,
20
+ hookRunners.checkEntryPoint({
21
+ path: dir,
22
+ entry: false
23
+ })
24
+ ];
25
+ case 1:
26
+ return [
27
+ 2,
28
+ _state.sent().entry || hasIndex(dir)
29
+ ];
30
+ }
31
+ });
32
+ });
33
+ return function isBundleEntry2(hookRunners, dir) {
34
+ return _ref.apply(this, arguments);
35
+ };
36
+ }();
37
+ var scanDir = function(hookRunners, dirs) {
38
+ return Promise.all(dirs.map(function() {
39
+ var _ref = _async_to_generator(function(dir) {
40
+ var indexFile, customBootstrap, entryName, entryFile;
41
+ return _ts_generator(this, function(_state) {
42
+ switch (_state.label) {
43
+ case 0:
44
+ indexFile = hasIndex(dir);
45
+ customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
46
+ entryName = path.basename(dir);
47
+ if (indexFile && !customBootstrap) {
48
+ return [
49
+ 2,
50
+ {
51
+ entryName,
52
+ isMainEntry: false,
53
+ entry: indexFile,
54
+ absoluteEntryDir: path.resolve(dir),
55
+ isAutoMount: false,
56
+ customBootstrap
57
+ }
58
+ ];
59
+ }
60
+ return [
61
+ 4,
62
+ hookRunners.checkEntryPoint({
63
+ path: dir,
64
+ entry: false
65
+ })
66
+ ];
67
+ case 1:
68
+ entryFile = _state.sent().entry;
69
+ if (entryFile) {
70
+ return [
71
+ 2,
72
+ {
73
+ entryName,
74
+ isMainEntry: false,
75
+ entry: entryFile,
76
+ absoluteEntryDir: path.resolve(dir),
77
+ isAutoMount: true,
78
+ customBootstrap
79
+ }
80
+ ];
81
+ }
82
+ throw Error("There is no valid entry point in the current project!");
83
+ }
84
+ });
85
+ });
86
+ return function(dir) {
87
+ return _ref.apply(this, arguments);
88
+ };
89
+ }()));
90
+ };
91
+ var getFileSystemEntry = function() {
92
+ var _ref = _async_to_generator(function(hookRunners, appContext, config) {
93
+ var appDirectory, _config_source, entriesDir, disableEntryDirs, disabledDirs, src, dirs;
94
+ return _ts_generator(this, function(_state) {
95
+ switch (_state.label) {
96
+ case 0:
97
+ appDirectory = appContext.appDirectory;
98
+ _config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs;
99
+ disabledDirs = [];
100
+ if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
101
+ disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map(function(dir) {
102
+ return ensureAbsolutePath(appDirectory, dir);
103
+ });
104
+ }
105
+ src = ensureAbsolutePath(appDirectory, entriesDir || "");
106
+ if (!fs.existsSync(src))
107
+ return [
108
+ 3,
109
+ 5
110
+ ];
111
+ if (!fs.statSync(src).isDirectory())
112
+ return [
113
+ 3,
114
+ 3
115
+ ];
116
+ return [
117
+ 4,
118
+ isBundleEntry(hookRunners, src)
119
+ ];
120
+ case 1:
121
+ if (_state.sent()) {
122
+ return [
123
+ 2,
124
+ scanDir(hookRunners, [
125
+ src
126
+ ])
127
+ ];
128
+ }
129
+ dirs = [];
130
+ return [
131
+ 4,
132
+ Promise.all(fs.readdirSync(src).map(function() {
133
+ var _ref2 = _async_to_generator(function(filename) {
134
+ var file, _tmp;
135
+ return _ts_generator(this, function(_state2) {
136
+ switch (_state2.label) {
137
+ case 0:
138
+ file = path.join(src, filename);
139
+ _tmp = fs.statSync(file).isDirectory();
140
+ if (!_tmp)
141
+ return [
142
+ 3,
143
+ 2
144
+ ];
145
+ return [
146
+ 4,
147
+ isBundleEntry(hookRunners, file)
148
+ ];
149
+ case 1:
150
+ _tmp = _state2.sent();
151
+ _state2.label = 2;
152
+ case 2:
153
+ if (_tmp && !disabledDirs.includes(file)) {
154
+ dirs.push(file);
155
+ }
156
+ return [
157
+ 2
158
+ ];
159
+ }
160
+ });
161
+ });
162
+ return function(filename) {
163
+ return _ref2.apply(this, arguments);
164
+ };
165
+ }()))
166
+ ];
167
+ case 2:
168
+ _state.sent();
169
+ return [
170
+ 2,
171
+ scanDir(hookRunners, dirs)
172
+ ];
173
+ case 3:
174
+ throw Error("source.entriesDir accept a directory.");
175
+ case 4:
176
+ return [
177
+ 3,
178
+ 6
179
+ ];
180
+ case 5:
181
+ throw Error("src dir ".concat(entriesDir, " not found."));
182
+ case 6:
183
+ return [
184
+ 2
185
+ ];
186
+ }
187
+ });
188
+ });
189
+ return function getFileSystemEntry2(hookRunners, appContext, config) {
190
+ return _ref.apply(this, arguments);
191
+ };
192
+ }();
193
+ export {
194
+ getFileSystemEntry
195
+ };
@@ -5,7 +5,7 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
5
  import path from "path";
6
6
  import fs from "fs";
7
7
  import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
8
- import { isMainEntry } from "../utils/routes";
8
+ import { isMainEntry } from "../../utils/routes";
9
9
  import { walkDirectory } from "./utils";
10
10
  var applyBaseUrl = function(baseUrl, routes) {
11
11
  if (baseUrl) {