@modern-js/app-tools 2.0.0-beta.3 → 2.0.0-beta.6

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 (261) hide show
  1. package/CHANGELOG.md +619 -0
  2. package/bin/modern.js +3 -0
  3. package/dist/js/modern/analyze/Builder.js +39 -0
  4. package/dist/js/modern/analyze/constants.js +48 -18
  5. package/dist/js/modern/analyze/generateCode.js +264 -225
  6. package/dist/js/modern/analyze/getBundleEntry.js +34 -32
  7. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +99 -52
  8. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +89 -47
  9. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -2
  10. package/dist/js/modern/analyze/getClientRoutes/utils.js +23 -10
  11. package/dist/js/modern/analyze/getFileSystemEntry.js +52 -23
  12. package/dist/js/modern/analyze/getHtmlTemplate.js +89 -49
  13. package/dist/js/modern/analyze/getServerRoutes.js +122 -126
  14. package/dist/js/modern/analyze/index.js +204 -161
  15. package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -16
  16. package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -11
  17. package/dist/js/modern/analyze/nestedRoutes.js +118 -65
  18. package/dist/js/modern/analyze/templates.js +170 -81
  19. package/dist/js/modern/analyze/utils.js +104 -67
  20. package/dist/js/modern/builder/builderPlugins/compatModern.js +128 -109
  21. package/dist/js/modern/builder/index.js +120 -89
  22. package/dist/js/modern/builder/loaders/routerLoader.js +9 -12
  23. package/dist/js/modern/builder/loaders/serverModuleLoader.js +4 -1
  24. package/dist/js/modern/builder/share.js +23 -21
  25. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +23 -22
  26. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +31 -27
  27. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +100 -84
  28. package/dist/js/modern/commands/build.js +67 -42
  29. package/dist/js/modern/commands/deploy.js +27 -4
  30. package/dist/js/modern/commands/dev.js +81 -34
  31. package/dist/js/modern/commands/index.js +1 -1
  32. package/dist/js/modern/commands/inspect.js +30 -5
  33. package/dist/js/modern/commands/serve.js +54 -0
  34. package/dist/js/modern/config/default.js +112 -145
  35. package/dist/js/modern/config/index.js +8 -2
  36. package/dist/js/modern/config/initial/createHtmlConfig.js +5 -2
  37. package/dist/js/modern/config/initial/createOutputConfig.js +10 -13
  38. package/dist/js/modern/config/initial/createSourceConfig.js +10 -3
  39. package/dist/js/modern/config/initial/createToolsConfig.js +7 -6
  40. package/dist/js/modern/config/initial/index.js +9 -4
  41. package/dist/js/modern/config/initial/inits.js +109 -73
  42. package/dist/js/modern/config/initial/transformNormalizedConfig.js +11 -4
  43. package/dist/js/modern/defineConfig.js +26 -11
  44. package/dist/js/modern/exports/server.js +4 -1
  45. package/dist/js/modern/hooks.js +16 -4
  46. package/dist/js/modern/index.js +178 -90
  47. package/dist/js/modern/initialize/index.js +100 -52
  48. package/dist/js/modern/locale/en.js +20 -21
  49. package/dist/js/modern/locale/index.js +6 -6
  50. package/dist/js/modern/locale/zh.js +21 -22
  51. package/dist/js/modern/schema/Schema.js +6 -5
  52. package/dist/js/modern/schema/index.js +53 -100
  53. package/dist/js/modern/schema/legacy.js +96 -231
  54. package/dist/js/modern/types/config/index.js +0 -1
  55. package/dist/js/modern/types/index.js +0 -1
  56. package/dist/js/modern/types/legacyConfig/output.js +0 -1
  57. package/dist/js/modern/utils/commands.js +10 -2
  58. package/dist/js/modern/utils/config.js +102 -41
  59. package/dist/js/modern/utils/createFileWatcher.js +84 -51
  60. package/dist/js/modern/utils/createServer.js +63 -17
  61. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  62. package/dist/js/modern/utils/getSpecifiedEntries.js +46 -19
  63. package/dist/js/modern/utils/language.js +6 -3
  64. package/dist/js/modern/utils/printInstructions.js +27 -8
  65. package/dist/js/modern/utils/restart.js +43 -16
  66. package/dist/js/modern/utils/routes.js +29 -12
  67. package/dist/js/node/analyze/Builder.js +64 -0
  68. package/dist/js/node/analyze/constants.js +86 -39
  69. package/dist/js/node/analyze/generateCode.js +285 -239
  70. package/dist/js/node/analyze/getBundleEntry.js +62 -44
  71. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +138 -77
  72. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +130 -74
  73. package/dist/js/node/analyze/getClientRoutes/index.js +27 -16
  74. package/dist/js/node/analyze/getClientRoutes/utils.js +51 -21
  75. package/dist/js/node/analyze/getFileSystemEntry.js +82 -39
  76. package/dist/js/node/analyze/getHtmlTemplate.js +120 -61
  77. package/dist/js/node/analyze/getServerRoutes.js +145 -137
  78. package/dist/js/node/analyze/index.js +233 -174
  79. package/dist/js/node/analyze/isDefaultExportFunction.js +59 -26
  80. package/dist/js/node/analyze/makeLegalIdentifier.js +31 -15
  81. package/dist/js/node/analyze/nestedRoutes.js +150 -79
  82. package/dist/js/node/analyze/templates.js +198 -90
  83. package/dist/js/node/analyze/utils.js +136 -81
  84. package/dist/js/node/builder/builderPlugins/compatModern.js +158 -122
  85. package/dist/js/node/builder/index.js +142 -98
  86. package/dist/js/node/builder/loaders/routerLoader.js +29 -18
  87. package/dist/js/node/builder/loaders/serverModuleLoader.js +24 -7
  88. package/dist/js/node/builder/share.js +50 -26
  89. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +43 -26
  90. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +51 -31
  91. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +120 -90
  92. package/dist/js/node/commands/build.js +91 -52
  93. package/dist/js/node/commands/deploy.js +49 -10
  94. package/dist/js/node/commands/dev.js +105 -48
  95. package/dist/js/node/commands/index.js +19 -38
  96. package/dist/js/node/commands/inspect.js +52 -11
  97. package/dist/js/node/commands/serve.js +83 -0
  98. package/dist/js/node/config/default.js +131 -149
  99. package/dist/js/node/config/index.js +31 -28
  100. package/dist/js/node/config/initial/createHtmlConfig.js +26 -6
  101. package/dist/js/node/config/initial/createOutputConfig.js +31 -17
  102. package/dist/js/node/config/initial/createSourceConfig.js +31 -7
  103. package/dist/js/node/config/initial/createToolsConfig.js +28 -10
  104. package/dist/js/node/config/initial/index.js +34 -17
  105. package/dist/js/node/config/initial/inits.js +130 -81
  106. package/dist/js/node/config/initial/transformNormalizedConfig.js +40 -16
  107. package/dist/js/node/defineConfig.js +46 -17
  108. package/dist/js/node/exports/server.js +25 -10
  109. package/dist/js/node/hooks.js +53 -29
  110. package/dist/js/node/index.js +213 -129
  111. package/dist/js/node/initialize/index.js +117 -61
  112. package/dist/js/node/locale/en.js +40 -25
  113. package/dist/js/node/locale/index.js +31 -14
  114. package/dist/js/node/locale/zh.js +41 -26
  115. package/dist/js/node/schema/Schema.js +27 -10
  116. package/dist/js/node/schema/index.js +84 -114
  117. package/dist/js/node/schema/legacy.js +119 -240
  118. package/dist/js/node/types/config/deploy.js +15 -0
  119. package/dist/js/node/types/config/dev.js +15 -0
  120. package/dist/js/node/types/config/experiments.js +15 -0
  121. package/dist/js/node/types/config/html.js +15 -0
  122. package/dist/js/node/types/config/index.js +17 -16
  123. package/dist/js/node/types/config/output.js +15 -0
  124. package/dist/js/node/types/config/performance.js +15 -0
  125. package/dist/js/node/types/config/security.js +15 -0
  126. package/dist/js/node/types/config/source.js +15 -0
  127. package/dist/js/node/types/config/tools.js +15 -0
  128. package/dist/js/node/types/hooks.js +15 -0
  129. package/dist/js/node/types/index.js +19 -38
  130. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  131. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  132. package/dist/js/node/types/legacyConfig/index.js +15 -0
  133. package/dist/js/node/types/legacyConfig/output.js +15 -5
  134. package/dist/js/node/types/legacyConfig/source.js +15 -0
  135. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  136. package/dist/js/node/utils/commands.js +31 -6
  137. package/dist/js/node/utils/config.js +125 -51
  138. package/dist/js/node/utils/createFileWatcher.js +109 -61
  139. package/dist/js/node/utils/createServer.js +92 -25
  140. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  141. package/dist/js/node/utils/getSpecifiedEntries.js +68 -25
  142. package/dist/js/node/utils/language.js +28 -8
  143. package/dist/js/node/utils/printInstructions.js +51 -16
  144. package/dist/js/node/utils/restart.js +65 -21
  145. package/dist/js/node/utils/routes.js +58 -19
  146. package/dist/js/node/utils/types.js +15 -0
  147. package/dist/js/treeshaking/analyze/Builder.js +199 -0
  148. package/dist/js/treeshaking/analyze/constants.js +37 -18
  149. package/dist/js/treeshaking/analyze/generateCode.js +597 -407
  150. package/dist/js/treeshaking/analyze/getBundleEntry.js +55 -63
  151. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +217 -168
  152. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +215 -169
  153. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -2
  154. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +19 -20
  155. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +97 -86
  156. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +298 -125
  157. package/dist/js/treeshaking/analyze/getServerRoutes.js +210 -147
  158. package/dist/js/treeshaking/analyze/index.js +575 -305
  159. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +45 -26
  160. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -16
  161. package/dist/js/treeshaking/analyze/nestedRoutes.js +419 -201
  162. package/dist/js/treeshaking/analyze/templates.js +438 -236
  163. package/dist/js/treeshaking/analyze/utils.js +367 -153
  164. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +285 -199
  165. package/dist/js/treeshaking/builder/index.js +365 -165
  166. package/dist/js/treeshaking/builder/loaders/routerLoader.js +11 -12
  167. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +3 -2
  168. package/dist/js/treeshaking/builder/share.js +38 -44
  169. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +108 -44
  170. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +70 -39
  171. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +334 -112
  172. package/dist/js/treeshaking/commands/build.js +286 -88
  173. package/dist/js/treeshaking/commands/deploy.js +153 -25
  174. package/dist/js/treeshaking/commands/dev.js +313 -131
  175. package/dist/js/treeshaking/commands/index.js +1 -1
  176. package/dist/js/treeshaking/commands/inspect.js +147 -32
  177. package/dist/js/treeshaking/commands/serve.js +199 -0
  178. package/dist/js/treeshaking/config/default.js +207 -198
  179. package/dist/js/treeshaking/config/index.js +3 -2
  180. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -31
  181. package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -70
  182. package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -40
  183. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -38
  184. package/dist/js/treeshaking/config/initial/index.js +10 -9
  185. package/dist/js/treeshaking/config/initial/inits.js +205 -106
  186. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +31 -34
  187. package/dist/js/treeshaking/defineConfig.js +60 -13
  188. package/dist/js/treeshaking/exports/server.js +2 -1
  189. package/dist/js/treeshaking/hooks.js +31 -25
  190. package/dist/js/treeshaking/index.js +681 -256
  191. package/dist/js/treeshaking/initialize/index.js +292 -113
  192. package/dist/js/treeshaking/locale/en.js +34 -33
  193. package/dist/js/treeshaking/locale/index.js +5 -5
  194. package/dist/js/treeshaking/locale/zh.js +34 -33
  195. package/dist/js/treeshaking/schema/Schema.js +267 -69
  196. package/dist/js/treeshaking/schema/index.js +171 -121
  197. package/dist/js/treeshaking/schema/legacy.js +323 -256
  198. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  199. package/dist/js/treeshaking/types/config/dev.js +1 -0
  200. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  201. package/dist/js/treeshaking/types/config/html.js +1 -0
  202. package/dist/js/treeshaking/types/config/index.js +0 -1
  203. package/dist/js/treeshaking/types/config/output.js +1 -0
  204. package/dist/js/treeshaking/types/config/performance.js +1 -0
  205. package/dist/js/treeshaking/types/config/security.js +1 -0
  206. package/dist/js/treeshaking/types/config/source.js +1 -0
  207. package/dist/js/treeshaking/types/config/tools.js +1 -0
  208. package/dist/js/treeshaking/types/hooks.js +1 -0
  209. package/dist/js/treeshaking/types/index.js +0 -1
  210. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  211. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  212. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  213. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -1
  214. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  215. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  216. package/dist/js/treeshaking/utils/commands.js +10 -5
  217. package/dist/js/treeshaking/utils/config.js +295 -117
  218. package/dist/js/treeshaking/utils/createFileWatcher.js +278 -118
  219. package/dist/js/treeshaking/utils/createServer.js +252 -67
  220. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  221. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +182 -55
  222. package/dist/js/treeshaking/utils/language.js +6 -5
  223. package/dist/js/treeshaking/utils/printInstructions.js +151 -29
  224. package/dist/js/treeshaking/utils/restart.js +184 -42
  225. package/dist/js/treeshaking/utils/routes.js +151 -27
  226. package/dist/js/treeshaking/utils/types.js +1 -0
  227. package/dist/types/analyze/Builder.d.ts +8 -0
  228. package/dist/types/analyze/constants.d.ts +10 -1
  229. package/dist/types/analyze/index.d.ts +2 -0
  230. package/dist/types/analyze/templates.d.ts +3 -1
  231. package/dist/types/analyze/utils.d.ts +2 -1
  232. package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -1
  233. package/dist/types/builder/index.d.ts +3 -3
  234. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +1 -7
  235. package/dist/types/commands/index.d.ts +1 -1
  236. package/dist/types/commands/{start.d.ts → serve.d.ts} +0 -0
  237. package/dist/types/defineConfig.d.ts +1 -0
  238. package/dist/types/index.d.ts +7 -1
  239. package/dist/types/initialize/index.d.ts +2 -0
  240. package/dist/types/locale/en.d.ts +1 -1
  241. package/dist/types/locale/index.d.ts +2 -2
  242. package/dist/types/locale/zh.d.ts +1 -1
  243. package/dist/types/types/config/dev.d.ts +2 -2
  244. package/dist/types/types/config/index.d.ts +4 -0
  245. package/dist/types/types/config/output.d.ts +0 -1
  246. package/dist/types/types/config/source.d.ts +2 -0
  247. package/dist/types/types/config/tools.d.ts +2 -0
  248. package/dist/types/types/hooks.d.ts +8 -0
  249. package/dist/types/types/legacyConfig/dev.d.ts +1 -0
  250. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  251. package/dist/types/types/legacyConfig/source.d.ts +1 -0
  252. package/dist/types/types/legacyConfig/tools.d.ts +1 -0
  253. package/dist/types/utils/commands.d.ts +2 -1
  254. package/dist/types/utils/config.d.ts +1 -0
  255. package/dist/types/utils/createServer.d.ts +1 -0
  256. package/dist/types/utils/getServerInternalPlugins.d.ts +2 -0
  257. package/dist/types/utils/restart.d.ts +1 -1
  258. package/package.json +26 -22
  259. package/dist/js/modern/commands/start.js +0 -30
  260. package/dist/js/node/commands/start.js +0 -38
  261. package/dist/js/treeshaking/commands/start.js +0 -69
@@ -1,34 +1,71 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+ var __async = (__this, __arguments, generator) => {
25
+ return new Promise((resolve, reject) => {
26
+ var fulfilled = (value) => {
27
+ try {
28
+ step(generator.next(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var rejected = (value) => {
34
+ try {
35
+ step(generator.throw(value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ };
40
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
+ step((generator = generator.apply(__this, __arguments)).next());
42
+ });
43
+ };
44
+ var generateCode_exports = {};
45
+ __export(generateCode_exports, {
46
+ createImportStatements: () => createImportStatements,
47
+ generateCode: () => generateCode
5
48
  });
6
- exports.generateCode = exports.createImportStatements = void 0;
7
- var _path = _interopRequireDefault(require("path"));
8
- var _utils = require("@modern-js/utils");
9
- var _core = require("@modern-js/core");
10
- var _esbuild = _interopRequireDefault(require("esbuild"));
11
- var _commands = require("../utils/commands");
12
- var templates = _interopRequireWildcard(require("./templates"));
13
- var _getClientRoutes = require("./getClientRoutes");
14
- var _constants = require("./constants");
15
- var _utils2 = require("./utils");
16
- var _nestedRoutes = require("./nestedRoutes");
17
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
49
+ module.exports = __toCommonJS(generateCode_exports);
50
+ var import_path = __toESM(require("path"));
51
+ var import_utils = require("@modern-js/utils");
52
+ var import_core = require("@modern-js/core");
53
+ var import_commands = require("../utils/commands");
54
+ var templates = __toESM(require("./templates"));
55
+ var import_getClientRoutes = require("./getClientRoutes");
56
+ var import_constants = require("./constants");
57
+ var import_utils2 = require("./utils");
58
+ var import_nestedRoutes = require("./nestedRoutes");
59
+ var import_Builder = require("./Builder");
20
60
  const loader = {
21
- '.js': 'jsx',
22
- '.ts': 'tsx'
61
+ ".js": "jsx",
62
+ ".ts": "tsx"
23
63
  };
24
64
  const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
25
- const createImportSpecifier = specifiers => {
26
- let defaults = '';
65
+ const createImportSpecifier = (specifiers) => {
66
+ let defaults = "";
27
67
  const named = [];
28
- for (const {
29
- local,
30
- imported
31
- } of specifiers) {
68
+ for (const { local, imported } of specifiers) {
32
69
  if (local && imported) {
33
70
  named.push(`${imported} as ${local}`);
34
71
  } else if (local) {
@@ -38,22 +75,18 @@ const createImportSpecifier = specifiers => {
38
75
  }
39
76
  }
40
77
  if (defaults && named.length) {
41
- return `${defaults}, { ${named.join(', ')} }`;
78
+ return `${defaults}, { ${named.join(", ")} }`;
42
79
  } else if (defaults) {
43
80
  return defaults;
44
81
  } else {
45
- return `{ ${named.join(', ')} }`;
82
+ return `{ ${named.join(", ")} }`;
46
83
  }
47
84
  };
48
- const createImportStatements = statements => {
49
- // merge import statements with the same value.
85
+ const createImportStatements = (statements) => {
86
+ var _a, _b;
50
87
  const deDuplicated = [];
51
- const seen = new Map();
52
- for (const {
53
- value,
54
- specifiers,
55
- initialize
56
- } of statements) {
88
+ const seen = /* @__PURE__ */ new Map();
89
+ for (const { value, specifiers, initialize } of statements) {
57
90
  if (!seen.has(value)) {
58
91
  deDuplicated.push({
59
92
  value,
@@ -62,243 +95,256 @@ const createImportStatements = statements => {
62
95
  });
63
96
  seen.set(value, specifiers);
64
97
  } else {
65
- var _deDuplicated$modifyI, _deDuplicated$modifyI2;
66
98
  seen.get(value).push(...specifiers);
67
- // make "initialize" param can be connected when multiple plugins were imported from same package
68
- const modifyIndex = deDuplicated.findIndex(v => v.value === value);
69
- const originInitialize = (_deDuplicated$modifyI = (_deDuplicated$modifyI2 = deDuplicated[modifyIndex]) === null || _deDuplicated$modifyI2 === void 0 ? void 0 : _deDuplicated$modifyI2.initialize) !== null && _deDuplicated$modifyI !== void 0 ? _deDuplicated$modifyI : '';
70
- deDuplicated[modifyIndex].initialize = originInitialize.concat(`\n${initialize || ''}`);
99
+ const modifyIndex = deDuplicated.findIndex((v) => v.value === value);
100
+ const originInitialize = (_b = (_a = deDuplicated[modifyIndex]) == null ? void 0 : _a.initialize) != null ? _b : "";
101
+ deDuplicated[modifyIndex].initialize = originInitialize.concat(
102
+ `
103
+ ${initialize || ""}`
104
+ );
71
105
  }
72
106
  }
73
- return deDuplicated.map(({
74
- value,
75
- specifiers,
76
- initialize
77
- }) => `import ${createImportSpecifier(specifiers)} from '${value}';\n${initialize || ''}`).join('\n');
107
+ return deDuplicated.map(
108
+ ({ value, specifiers, initialize }) => `import ${createImportSpecifier(specifiers)} from '${value}';
109
+ ${initialize || ""}`
110
+ ).join("\n");
78
111
  };
79
- exports.createImportStatements = createImportStatements;
80
- const buildLoader = async (entry, outfile) => {
81
- const command = (0, _commands.getCommand)();
82
- await _esbuild.default.build({
83
- format: 'esm',
84
- platform: 'browser',
85
- target: 'esnext',
112
+ const buildLoader = (entry, outfile) => __async(void 0, null, function* () {
113
+ yield import_Builder.loaderBuilder.build({
114
+ format: "esm",
115
+ platform: "browser",
116
+ target: "esnext",
86
117
  loader,
87
- watch: command === 'dev' && {},
118
+ watch: (0, import_commands.isDevCommand)() && {},
88
119
  bundle: true,
89
- logLevel: 'error',
120
+ logLevel: "error",
90
121
  entryPoints: [entry],
91
122
  outfile,
92
- plugins: [{
93
- name: 'make-all-packages-external',
94
- setup(build) {
95
- // https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
96
- build.onResolve({
97
- filter: EXTERNAL_REGEXP
98
- }, args => {
99
- let external = true;
100
- // FIXME: windows external entrypoint
101
- if (args.kind === 'entry-point') {
102
- external = false;
103
- }
104
- return {
105
- path: args.path,
106
- external
107
- };
108
- });
123
+ plugins: [
124
+ {
125
+ name: "make-all-packages-external",
126
+ setup(build) {
127
+ build.onResolve({ filter: EXTERNAL_REGEXP }, (args) => {
128
+ let external = true;
129
+ if (args.kind === "entry-point") {
130
+ external = false;
131
+ }
132
+ return {
133
+ path: args.path,
134
+ external
135
+ };
136
+ });
137
+ }
109
138
  }
110
- }]
139
+ ]
111
140
  });
112
- };
113
- const buildServerLoader = async (entry, outfile) => {
114
- const command = (0, _commands.getCommand)();
115
- await _esbuild.default.build({
116
- format: 'cjs',
117
- platform: 'node',
118
- target: 'esnext',
141
+ });
142
+ const buildServerLoader = (entry, outfile) => __async(void 0, null, function* () {
143
+ yield import_Builder.serverLoaderBuilder.build({
144
+ format: "cjs",
145
+ platform: "node",
146
+ target: "esnext",
119
147
  loader,
120
- watch: command === 'dev' && {},
148
+ watch: (0, import_commands.isDevCommand)() && {},
121
149
  bundle: true,
122
- logLevel: 'error',
150
+ logLevel: "error",
123
151
  entryPoints: [entry],
124
152
  outfile
125
153
  });
126
- };
127
- const generateCode = async (appContext, config, entrypoints, api) => {
128
- var _config$runtime, _config$runtime$route;
154
+ });
155
+ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, null, function* () {
156
+ var _a, _b, _c;
129
157
  const {
130
158
  internalDirectory,
131
159
  distDirectory,
132
160
  srcDirectory,
133
161
  internalDirAlias,
134
- internalSrcAlias
162
+ internalSrcAlias,
163
+ packageName
135
164
  } = appContext;
136
165
  const hookRunners = api.useHookRunners();
137
- const islegacy = Boolean(config === null || config === void 0 ? void 0 : (_config$runtime = config.runtime) === null || _config$runtime === void 0 ? void 0 : (_config$runtime$route = _config$runtime.router) === null || _config$runtime$route === void 0 ? void 0 : _config$runtime$route.legacy);
138
- const {
139
- mountId
140
- } = config.html;
141
- const getRoutes = islegacy ? _getClientRoutes.getClientRoutesLegacy : _getClientRoutes.getClientRoutes;
142
- await Promise.all(entrypoints.map(generateEntryCode));
143
- async function generateEntryCode(entrypoint) {
144
- const {
145
- entryName,
146
- isAutoMount,
147
- customBootstrap,
148
- fileSystemRoutes
149
- } = entrypoint;
150
- if (isAutoMount) {
151
- // generate routes file for file system routes entrypoint.
152
- if (fileSystemRoutes) {
153
- let initialRoutes = [];
154
- let nestedRoute = null;
155
- if (entrypoint.entry) {
156
- initialRoutes = getRoutes({
166
+ const isV5 = typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
167
+ const { mountId } = config.html;
168
+ const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
169
+ yield Promise.all(entrypoints.map(generateEntryCode));
170
+ function generateEntryCode(entrypoint) {
171
+ return __async(this, null, function* () {
172
+ const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
173
+ if (isAutoMount) {
174
+ if (fileSystemRoutes) {
175
+ let initialRoutes = [];
176
+ let nestedRoute = null;
177
+ if (entrypoint.entry) {
178
+ initialRoutes = getRoutes({
179
+ entrypoint,
180
+ srcDirectory,
181
+ srcAlias: internalSrcAlias,
182
+ internalDirectory,
183
+ internalDirAlias
184
+ });
185
+ }
186
+ if (entrypoint.nestedRoutesEntry) {
187
+ if (!isV5) {
188
+ nestedRoute = yield (0, import_nestedRoutes.walk)(
189
+ entrypoint.nestedRoutesEntry,
190
+ entrypoint.nestedRoutesEntry,
191
+ {
192
+ name: internalSrcAlias,
193
+ basename: srcDirectory
194
+ },
195
+ entrypoint.entryName
196
+ );
197
+ if (nestedRoute) {
198
+ initialRoutes.unshift(nestedRoute);
199
+ }
200
+ } else {
201
+ import_utils.logger.error("Nested routes is not supported in legacy mode.");
202
+ process.exit(1);
203
+ }
204
+ }
205
+ const { routes } = yield hookRunners.modifyFileSystemRoutes({
157
206
  entrypoint,
158
- srcDirectory,
159
- srcAlias: internalSrcAlias,
160
- internalDirectory,
161
- internalDirAlias
207
+ routes: initialRoutes
162
208
  });
163
- }
164
- if (entrypoint.nestedRoutesEntry) {
165
- if (!islegacy) {
166
- nestedRoute = await (0, _nestedRoutes.walk)(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
167
- name: internalSrcAlias,
168
- basename: srcDirectory
169
- }, entrypoint.entryName);
170
- if (nestedRoute) {
171
- initialRoutes.unshift(nestedRoute);
172
- }
209
+ const config2 = (0, import_core.useResolvedConfigContext)();
210
+ const ssr = (0, import_utils.getEntryOptions)(
211
+ entryName,
212
+ config2.server.ssr,
213
+ config2.server.ssrByEntries,
214
+ packageName
215
+ );
216
+ let mode;
217
+ if (ssr) {
218
+ mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
173
219
  } else {
174
- _utils.logger.error('Nested routes is not supported in legacy mode.');
175
- // eslint-disable-next-line no-process-exit
176
- process.exit(1);
220
+ mode = false;
177
221
  }
178
- }
179
- const {
180
- routes
181
- } = await hookRunners.modifyFileSystemRoutes({
182
- entrypoint,
183
- routes: initialRoutes
184
- });
185
- const config = (0, _core.useResolvedConfigContext)();
186
- const ssr = config === null || config === void 0 ? void 0 : config.server.ssr;
187
- let mode;
188
- if (ssr) {
189
- mode = typeof ssr === 'object' ? ssr.mode || 'string' : 'string';
190
- } else {
191
- mode = false;
192
- }
193
- if (mode === 'stream') {
194
- const hasPageRoute = routes.some(route => 'type' in route && route.type === 'page');
195
- if (hasPageRoute) {
196
- _utils.logger.error('streaming ssr is not supported when pages dir exists');
197
- // eslint-disable-next-line no-process-exit
198
- process.exit(1);
222
+ if (mode === "stream") {
223
+ const hasPageRoute = routes.some(
224
+ (route) => "type" in route && route.type === "page"
225
+ );
226
+ if (hasPageRoute) {
227
+ import_utils.logger.error(
228
+ "Streaming ssr is not supported when pages dir exists"
229
+ );
230
+ process.exit(1);
231
+ }
232
+ }
233
+ const { code: code2 } = yield hookRunners.beforeGenerateRoutes({
234
+ entrypoint,
235
+ code: yield templates.fileSystemRoutes({
236
+ routes,
237
+ ssrMode: mode,
238
+ nestedRoutesEntry: entrypoint.nestedRoutesEntry,
239
+ entryName: entrypoint.entryName,
240
+ internalDirectory,
241
+ internalDirAlias
242
+ })
243
+ });
244
+ if (entrypoint.nestedRoutesEntry) {
245
+ const routesServerFile = import_path.default.join(
246
+ internalDirectory,
247
+ entryName,
248
+ "route-server-loaders.js"
249
+ );
250
+ const outputRoutesServerFile = import_path.default.join(
251
+ distDirectory,
252
+ import_utils.LOADER_ROUTES_DIR,
253
+ entryName,
254
+ "index.js"
255
+ );
256
+ const code3 = templates.routesForServer({
257
+ routes,
258
+ internalDirectory,
259
+ entryName
260
+ });
261
+ yield import_utils.fs.ensureFile(routesServerFile);
262
+ yield import_utils.fs.writeFile(routesServerFile, code3);
263
+ const loaderEntryFile = import_path.default.join(
264
+ internalDirectory,
265
+ entryName,
266
+ import_constants.TEMP_LOADERS_DIR,
267
+ "entry.js"
268
+ );
269
+ const loaderIndexFile = import_path.default.join(
270
+ internalDirectory,
271
+ entryName,
272
+ import_constants.TEMP_LOADERS_DIR,
273
+ "index.js"
274
+ );
275
+ if (yield import_utils.fs.pathExists(loaderEntryFile)) {
276
+ yield buildLoader(loaderEntryFile, loaderIndexFile);
277
+ }
278
+ if (yield import_utils.fs.pathExists(routesServerFile)) {
279
+ yield buildServerLoader(routesServerFile, outputRoutesServerFile);
280
+ }
199
281
  }
282
+ import_utils.fs.outputFileSync(
283
+ import_path.default.resolve(
284
+ internalDirectory,
285
+ `./${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`
286
+ ),
287
+ code2,
288
+ "utf8"
289
+ );
200
290
  }
201
- const {
202
- code
203
- } = await hookRunners.beforeGenerateRoutes({
291
+ const { imports: importStatements } = yield hookRunners.modifyEntryImports({
204
292
  entrypoint,
205
- code: await templates.fileSystemRoutes({
206
- routes,
207
- ssrMode: mode,
208
- nestedRoutesEntry: entrypoint.nestedRoutesEntry,
209
- entryName: entrypoint.entryName,
293
+ imports: (0, import_utils2.getDefaultImports)({
294
+ entrypoint,
295
+ srcDirectory,
296
+ internalSrcAlias,
297
+ internalDirAlias,
210
298
  internalDirectory
211
299
  })
212
300
  });
213
-
214
- // extract nested router loaders
215
- if (entrypoint.nestedRoutesEntry) {
216
- const routesServerFile = _path.default.join(internalDirectory, entryName, 'route-server-loaders.js');
217
- const outputRoutesServerFile = _path.default.join(distDirectory, _utils.LOADER_ROUTES_DIR, entryName, 'index.js');
218
- const code = templates.routesForServer({
219
- routes: routes,
220
- internalDirectory,
221
- entryName
222
- });
223
- await _utils.fs.ensureFile(routesServerFile);
224
- await _utils.fs.writeFile(routesServerFile, code);
225
- const loaderEntryFile = _path.default.join(internalDirectory, entryName, _constants.TEMP_LOADERS_DIR, 'entry.js');
226
- const loaderIndexFile = _path.default.join(internalDirectory, entryName, _constants.TEMP_LOADERS_DIR, 'index.js');
227
- if (await _utils.fs.pathExists(loaderEntryFile)) {
228
- await buildLoader(loaderEntryFile, loaderIndexFile);
229
- }
230
- if (await _utils.fs.pathExists(routesServerFile)) {
231
- await buildServerLoader(routesServerFile, outputRoutesServerFile);
232
- }
233
- }
234
- _utils.fs.outputFileSync(_path.default.resolve(internalDirectory, `./${entryName}/${_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`), code, 'utf8');
235
- }
236
-
237
- // call modifyEntryImports hook
238
- const {
239
- imports: importStatements
240
- } = await hookRunners.modifyEntryImports({
241
- entrypoint,
242
- imports: (0, _utils2.getDefaultImports)({
301
+ const { plugins } = yield hookRunners.modifyEntryRuntimePlugins({
243
302
  entrypoint,
244
- srcDirectory,
245
- internalSrcAlias,
246
- internalDirAlias,
247
- internalDirectory
248
- })
249
- });
250
-
251
- // call modifyEntryRuntimePlugins hook
252
- const {
253
- plugins
254
- } = await hookRunners.modifyEntryRuntimePlugins({
255
- entrypoint,
256
- plugins: []
257
- });
258
-
259
- // call modifyEntryRenderFunction hook
260
- const {
261
- code: renderFunction
262
- } = await hookRunners.modifyEntryRenderFunction({
263
- entrypoint,
264
- code: templates.renderFunction({
265
- plugins,
266
- customBootstrap,
267
- fileSystemRoutes
268
- })
269
- });
270
-
271
- // call modifyEntryExport hook
272
- const {
273
- exportStatement
274
- } = await hookRunners.modifyEntryExport({
275
- entrypoint,
276
- exportStatement: 'export default AppWrapper;'
277
- });
278
- const code = templates.index({
279
- mountId: mountId,
280
- imports: createImportStatements(importStatements),
281
- renderFunction,
282
- exportStatement
283
- });
284
- const entryFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_POINT_FILE_NAME}`);
285
- entrypoint.entry = entryFile;
286
-
287
- // generate entry file.
288
- if (config.source.enableAsyncEntry) {
289
- const {
290
- code: asyncEntryCode
291
- } = await hookRunners.modifyAsyncEntry({
303
+ plugins: []
304
+ });
305
+ const { code: renderFunction } = yield hookRunners.modifyEntryRenderFunction({
306
+ entrypoint,
307
+ code: templates.renderFunction({
308
+ plugins,
309
+ customBootstrap,
310
+ fileSystemRoutes
311
+ })
312
+ });
313
+ const { exportStatement } = yield hookRunners.modifyEntryExport({
292
314
  entrypoint,
293
- code: `import('./${_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`
315
+ exportStatement: "export default AppWrapper;"
316
+ });
317
+ const code = templates.index({
318
+ mountId,
319
+ imports: createImportStatements(importStatements),
320
+ renderFunction,
321
+ exportStatement
294
322
  });
295
- _utils.fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
296
- const bootstrapFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_BOOTSTRAP_FILE_NAME}`);
297
- _utils.fs.outputFileSync(bootstrapFile, code, 'utf8');
298
- } else {
299
- _utils.fs.outputFileSync(entryFile, code, 'utf8');
323
+ const entryFile = import_path.default.resolve(
324
+ internalDirectory,
325
+ `./${entryName}/${import_constants.ENTRY_POINT_FILE_NAME}`
326
+ );
327
+ entrypoint.entry = entryFile;
328
+ if (config.source.enableAsyncEntry) {
329
+ const { code: asyncEntryCode } = yield hookRunners.modifyAsyncEntry({
330
+ entrypoint,
331
+ code: `import('./${import_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`
332
+ });
333
+ import_utils.fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
334
+ const bootstrapFile = import_path.default.resolve(
335
+ internalDirectory,
336
+ `./${entryName}/${import_constants.ENTRY_BOOTSTRAP_FILE_NAME}`
337
+ );
338
+ import_utils.fs.outputFileSync(bootstrapFile, code, "utf8");
339
+ } else {
340
+ import_utils.fs.outputFileSync(entryFile, code, "utf8");
341
+ }
300
342
  }
301
- }
343
+ });
302
344
  }
303
- };
304
- exports.generateCode = generateCode;
345
+ });
346
+ // Annotate the CommonJS export names for ESM import in node:
347
+ 0 && (module.exports = {
348
+ createImportStatements,
349
+ generateCode
350
+ });