@modern-js/app-tools 2.0.0-beta.2 → 2.0.0-beta.4

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