@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
@@ -5,14 +5,13 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
5
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
6
6
  import * as path from "path";
7
7
  import { createDebugger, findExists, fs, isApiOnly, minimist, isDevCommand, getArgv } from "@modern-js/utils";
8
- import { cloneDeep } from "@modern-js/utils/lodash";
9
- import { printInstructions } from "../utils/printInstructions";
10
- import { generateRoutes, getPathWithoutExt } from "../utils/routes";
11
- import { emitResolvedConfig } from "../utils/config";
12
- import { getSelectedEntries } from "../utils/getSelectedEntries";
13
- import { initialNormalizedConfig } from "../config";
14
- import { createBuilderGenerator } from "../builder";
15
- import { checkIsBuildCommands, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
8
+ import { printInstructions } from "../../utils/printInstructions";
9
+ import { generateRoutes, getPathWithoutExt } from "../../utils/routes";
10
+ import { emitResolvedConfig } from "../../utils/config";
11
+ import { getSelectedEntries } from "../../utils/getSelectedEntries";
12
+ import { initialNormalizedConfig } from "../../config";
13
+ import { createBuilderGenerator } from "../../builder";
14
+ import { checkIsBuildCommands, parseModule, replaceWithAlias } from "./utils";
16
15
  import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
17
16
  import { generateIndexCode } from "./generateCode";
18
17
  var debug = createDebugger("plugin-analyze");
@@ -23,11 +22,10 @@ function analyze_default(param) {
23
22
  setup: function(api) {
24
23
  var pagesDir = [];
25
24
  var nestedRouteEntries = [];
26
- var originEntrypoints = [];
27
25
  return {
28
26
  prepare: function prepare() {
29
27
  return _async_to_generator(function() {
30
- var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, routes, _ref, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes1, importsStatemets, htmlTemplates, checkedEntries, entry, normalizedConfig, createBuilderForModern, builder;
28
+ var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, routes, _ref, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, _, _tmp, initialRoutes, routes1, importsStatemets, htmlTemplates, checkedEntries, entry, normalizedConfig, createBuilderForModern, builder;
31
29
  return _ts_generator(this, function(_state) {
32
30
  switch (_state.label) {
33
31
  case 0:
@@ -89,7 +87,21 @@ function analyze_default(param) {
89
87
  _state.sent(),
90
88
  4
91
89
  ]), getBundleEntry = _ref[0].getBundleEntry, getServerRoutes = _ref[1].getServerRoutes, generateCode = _ref[2].generateCode, getHtmlTemplate = _ref[3].getHtmlTemplate;
92
- entrypoints = getBundleEntry(appContext, resolvedConfig);
90
+ _ = hookRunners.modifyEntrypoints;
91
+ _tmp = {};
92
+ return [
93
+ 4,
94
+ getBundleEntry(hookRunners, appContext, resolvedConfig)
95
+ ];
96
+ case 6:
97
+ return [
98
+ 4,
99
+ _.apply(hookRunners, [
100
+ (_tmp.entrypoints = _state.sent(), _tmp)
101
+ ])
102
+ ];
103
+ case 7:
104
+ entrypoints = _state.sent().entrypoints;
93
105
  debug("entrypoints: %o", entrypoints);
94
106
  initialRoutes = getServerRoutes(entrypoints, {
95
107
  appContext,
@@ -101,7 +113,7 @@ function analyze_default(param) {
101
113
  routes: initialRoutes
102
114
  })
103
115
  ];
104
- case 6:
116
+ case 8:
105
117
  routes1 = _state.sent().routes;
106
118
  debug("server routes: %o", routes1);
107
119
  appContext = _object_spread_props(_object_spread({}, api.useAppContext()), {
@@ -117,12 +129,11 @@ function analyze_default(param) {
117
129
  }).filter(function(entry2) {
118
130
  return entry2 && !path.extname(entry2);
119
131
  }).concat(nestedRouteEntries);
120
- originEntrypoints = cloneDeep(entrypoints);
121
132
  return [
122
133
  4,
123
134
  generateCode(appContext, resolvedConfig, entrypoints, api)
124
135
  ];
125
- case 7:
136
+ case 9:
126
137
  importsStatemets = _state.sent().importsStatemets;
127
138
  return [
128
139
  4,
@@ -131,14 +142,14 @@ function analyze_default(param) {
131
142
  config: resolvedConfig
132
143
  })
133
144
  ];
134
- case 8:
145
+ case 10:
135
146
  htmlTemplates = _state.sent();
136
147
  debug("html templates: %o", htmlTemplates);
137
148
  return [
138
149
  4,
139
150
  hookRunners.addDefineTypes()
140
151
  ];
141
- case 9:
152
+ case 11:
142
153
  _state.sent();
143
154
  debug("add Define Types");
144
155
  checkedEntries = entrypoints.map(function(point) {
@@ -147,17 +158,17 @@ function analyze_default(param) {
147
158
  if (!isDevCommand())
148
159
  return [
149
160
  3,
150
- 11
161
+ 13
151
162
  ];
152
163
  entry = minimist(getArgv()).entry;
153
164
  return [
154
165
  4,
155
166
  getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
156
167
  ];
157
- case 10:
168
+ case 12:
158
169
  checkedEntries = _state.sent();
159
- _state.label = 11;
160
- case 11:
170
+ _state.label = 13;
171
+ case 13:
161
172
  appContext = _object_spread_props(_object_spread({}, api.useAppContext()), {
162
173
  entrypoints,
163
174
  checkedEntries,
@@ -169,14 +180,14 @@ function analyze_default(param) {
169
180
  if (!checkIsBuildCommands())
170
181
  return [
171
182
  3,
172
- 14
183
+ 16
173
184
  ];
174
185
  normalizedConfig = api.useResolvedConfigContext();
175
186
  return [
176
187
  4,
177
188
  createBuilderGenerator(bundler)
178
189
  ];
179
- case 12:
190
+ case 14:
180
191
  createBuilderForModern = _state.sent();
181
192
  return [
182
193
  4,
@@ -185,7 +196,7 @@ function analyze_default(param) {
185
196
  appContext
186
197
  })
187
198
  ];
188
- case 13:
199
+ case 15:
189
200
  builder = _state.sent();
190
201
  builder.onBeforeBuild(function() {
191
202
  var _ref2 = _async_to_generator(function(param2) {
@@ -215,7 +226,7 @@ function analyze_default(param) {
215
226
  }
216
227
  });
217
228
  });
218
- return function(_) {
229
+ return function(_2) {
219
230
  return _ref2.apply(this, arguments);
220
231
  };
221
232
  }());
@@ -247,7 +258,7 @@ function analyze_default(param) {
247
258
  }
248
259
  });
249
260
  });
250
- return function(_) {
261
+ return function(_2) {
251
262
  return _ref2.apply(this, arguments);
252
263
  };
253
264
  }());
@@ -268,7 +279,7 @@ function analyze_default(param) {
268
279
  ];
269
280
  });
270
281
  });
271
- return function(_) {
282
+ return function(_2) {
272
283
  return _ref2.apply(this, arguments);
273
284
  };
274
285
  }());
@@ -307,7 +318,7 @@ function analyze_default(param) {
307
318
  }
308
319
  });
309
320
  });
310
- return function(_) {
321
+ return function(_2) {
311
322
  return _ref2.apply(this, arguments);
312
323
  };
313
324
  }());
@@ -333,7 +344,7 @@ function analyze_default(param) {
333
344
  }
334
345
  });
335
346
  });
336
- return function(_) {
347
+ return function(_2) {
337
348
  return _ref2.apply(this, arguments);
338
349
  };
339
350
  }());
@@ -342,8 +353,8 @@ function analyze_default(param) {
342
353
  builder
343
354
  });
344
355
  api.setAppContext(appContext);
345
- _state.label = 14;
346
- case 14:
356
+ _state.label = 16;
357
+ case 16:
347
358
  return [
348
359
  2
349
360
  ];
@@ -456,46 +467,7 @@ function analyze_default(param) {
456
467
  });
457
468
  })();
458
469
  }
459
- ),
460
- fileChange: function fileChange(e) {
461
- return _async_to_generator(function() {
462
- var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
463
- return _ts_generator(this, function(_state) {
464
- switch (_state.label) {
465
- case 0:
466
- appContext = api.useAppContext();
467
- appDirectory = appContext.appDirectory;
468
- filename = e.filename, eventType = e.eventType;
469
- isPageFile = function(name) {
470
- return pagesDir.some(function(pageDir) {
471
- return name.includes(pageDir);
472
- });
473
- };
474
- absoluteFilePath = path.resolve(appDirectory, filename);
475
- isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
476
- if (!(isRouteComponent && (eventType === "add" || eventType === "unlink")))
477
- return [
478
- 3,
479
- 2
480
- ];
481
- resolvedConfig = api.useResolvedConfigContext();
482
- return [
483
- 4,
484
- import("./generateCode")
485
- ];
486
- case 1:
487
- generateCode = _state.sent().generateCode;
488
- entrypoints = cloneDeep(originEntrypoints);
489
- generateCode(appContext, resolvedConfig, entrypoints, api);
490
- _state.label = 2;
491
- case 2:
492
- return [
493
- 2
494
- ];
495
- }
496
- });
497
- })();
498
- }
470
+ )
499
471
  };
500
472
  }
501
473
  };
@@ -0,0 +1,22 @@
1
+ import { APP_CONFIG_NAME } from "./constants";
2
+ var index = function(param) {
3
+ var mountId = param.mountId, imports = param.imports, renderFunction2 = param.renderFunction, exportStatement = param.exportStatement;
4
+ return "\nconst IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';\nconst IS_REACT18 = process.env.IS_REACT18 === 'true';\nconst MOUNT_ID = '".concat(mountId, "';\n\n").concat(imports, "\n\nlet AppWrapper = null;\n\nlet root = null;\n\nfunction render() {\n ").concat(renderFunction2, "\n}\n\nAppWrapper = render();\n\n").concat(exportStatement, ";\n");
5
+ };
6
+ var renderFunction = function(param) {
7
+ var plugins = param.plugins, customBootstrap = param.customBootstrap, fileSystemRoutes = param.fileSystemRoutes, customRuntimeConfig = param.customRuntimeConfig;
8
+ var bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
9
+ var runtimePlugins = "...(runtimeConfig?.plugins || []),";
10
+ return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === 'function' ? ").concat(APP_CONFIG_NAME, "() : {},\n }\n\n AppWrapper = createApp({\n plugins: [\n ").concat(plugins.map(function(param2) {
11
+ var name = param2.name, options = param2.options, args = param2.args;
12
+ return "".concat(name, "({...").concat(options, ", ...finalAppConfig?.").concat(args || name, "}),");
13
+ }).join("\n"), "\n ").concat(customRuntimeConfig ? runtimePlugins : "", "\n ]\n })(").concat(fileSystemRoutes ? "" : "App", ")\n\n\n if(!AppWrapper.init && typeof appInit !== 'undefined') {\n AppWrapper.init = appInit;\n }\n\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper, () => ".concat(bootstrap, ");") : "".concat(bootstrap, ";"), "\n }\n\n return AppWrapper\n");
14
+ };
15
+ var html = function(partials) {
16
+ return "\n<!DOCTYPE html>\n<html>\n<head>\n\n ".concat(partials.top.join("\n"), "\n\n ").concat(partials.head.join("\n"), '\n\n</head>\n\n<body>\n <div id="<%= mountId %>"><!--<?- html ?>--></div>\n ').concat(partials.body.join("\n"), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
17
+ };
18
+ export {
19
+ html,
20
+ index,
21
+ renderFunction
22
+ };
@@ -1,13 +1,12 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
3
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
4
  import fs from "fs";
6
5
  import path from "path";
7
- import { isReact18, normalizeToPosixPath, fs as fse, getCommand } from "@modern-js/utils";
6
+ import { isReact18, normalizeToPosixPath, getCommand, JS_EXTENSIONS } from "@modern-js/utils";
8
7
  import { transform } from "esbuild";
9
8
  import { parse } from "es-module-lexer";
10
- import { ACTION_EXPORT_NAME, FILE_SYSTEM_ROUTES_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME } from "./constants";
9
+ import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
11
10
  var walkDirectory = function(dir) {
12
11
  return fs.readdirSync(dir).reduce(function(previous, filename) {
13
12
  var filePath = path.join(dir, filename);
@@ -21,7 +20,7 @@ var walkDirectory = function(dir) {
21
20
  }, []);
22
21
  };
23
22
  var getDefaultImports = function(param) {
24
- var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, appDirectory = param.appDirectory, internalSrcAlias = param.internalSrcAlias, internalDirAlias = param.internalDirAlias;
23
+ var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, appDirectory = param.appDirectory, internalSrcAlias = param.internalSrcAlias, internalDirAlias = param.internalDirAlias, runtimeConfigFile = param.runtimeConfigFile, customRuntimeConfig = param.customRuntimeConfig;
25
24
  var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes, customBootstrap = entrypoint.customBootstrap, entry = entrypoint.entry;
26
25
  var imports = [
27
26
  {
@@ -92,21 +91,17 @@ var getDefaultImports = function(param) {
92
91
  value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
93
92
  });
94
93
  }
95
- return imports;
96
- };
97
- var isPageComponentFile = function(filePath) {
98
- if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
99
- return false;
100
- }
101
- if ([
102
- ".js",
103
- ".jsx",
104
- ".ts",
105
- ".tsx"
106
- ].includes(path.extname(filePath))) {
107
- return true;
94
+ if (customRuntimeConfig) {
95
+ imports.push({
96
+ specifiers: [
97
+ {
98
+ local: "runtimeConfig"
99
+ }
100
+ ],
101
+ value: path.join(internalSrcAlias, runtimeConfigFile || "")
102
+ });
108
103
  }
109
- return false;
104
+ return imports;
110
105
  };
111
106
  var replaceWithAlias = function(base, filePath, alias) {
112
107
  if (filePath.includes(base)) {
@@ -158,119 +153,6 @@ var parseModule = function() {
158
153
  return _ref.apply(this, arguments);
159
154
  };
160
155
  }();
161
- var hasLoader = function() {
162
- var _ref = _async_to_generator(function(filename, source) {
163
- var content, _ref2, moduleExports;
164
- return _ts_generator(this, function(_state) {
165
- switch (_state.label) {
166
- case 0:
167
- content = source;
168
- if (!!source)
169
- return [
170
- 3,
171
- 2
172
- ];
173
- return [
174
- 4,
175
- fse.readFile(filename, "utf-8")
176
- ];
177
- case 1:
178
- content = _state.sent().toString();
179
- _state.label = 2;
180
- case 2:
181
- if (!content)
182
- return [
183
- 3,
184
- 4
185
- ];
186
- return [
187
- 4,
188
- parseModule({
189
- source: content.toString(),
190
- filename
191
- })
192
- ];
193
- case 3:
194
- _ref2 = _sliced_to_array.apply(void 0, [
195
- _state.sent(),
196
- 2
197
- ]), moduleExports = _ref2[1];
198
- return [
199
- 2,
200
- moduleExports.some(function(e) {
201
- return e.n === LOADER_EXPORT_NAME;
202
- })
203
- ];
204
- case 4:
205
- return [
206
- 2,
207
- false
208
- ];
209
- }
210
- });
211
- });
212
- return function hasLoader2(filename, source) {
213
- return _ref.apply(this, arguments);
214
- };
215
- }();
216
- var hasAction = function() {
217
- var _ref = _async_to_generator(function(filename, source) {
218
- var content, _ref2, moduleExports;
219
- return _ts_generator(this, function(_state) {
220
- switch (_state.label) {
221
- case 0:
222
- content = source;
223
- if (!!source)
224
- return [
225
- 3,
226
- 2
227
- ];
228
- return [
229
- 4,
230
- fse.readFile(filename, "utf-8")
231
- ];
232
- case 1:
233
- content = _state.sent().toString();
234
- _state.label = 2;
235
- case 2:
236
- if (!content)
237
- return [
238
- 3,
239
- 4
240
- ];
241
- return [
242
- 4,
243
- parseModule({
244
- source: content.toString(),
245
- filename
246
- })
247
- ];
248
- case 3:
249
- _ref2 = _sliced_to_array.apply(void 0, [
250
- _state.sent(),
251
- 2
252
- ]), moduleExports = _ref2[1];
253
- return [
254
- 2,
255
- moduleExports.some(function(e) {
256
- return e.n === ACTION_EXPORT_NAME;
257
- })
258
- ];
259
- case 4:
260
- return [
261
- 2,
262
- false
263
- ];
264
- }
265
- });
266
- });
267
- return function hasAction2(filename, source) {
268
- return _ref.apply(this, arguments);
269
- };
270
- }();
271
- var getServerLoadersFile = function(internalDirectory, entryName) {
272
- return path.join(internalDirectory, entryName, "route-server-loaders.js");
273
- };
274
156
  var getServerCombinedModueFile = function(internalDirectory, entryName) {
275
157
  return path.join(internalDirectory, entryName, "server-loader-combined.js");
276
158
  };
@@ -298,10 +180,6 @@ export {
298
180
  checkIsBuildCommands,
299
181
  getDefaultImports,
300
182
  getServerCombinedModueFile,
301
- getServerLoadersFile,
302
- hasAction,
303
- hasLoader,
304
- isPageComponentFile,
305
183
  isSubDirOrEqual,
306
184
  parseModule,
307
185
  replaceWithAlias,