@modern-js/app-tools 2.0.0-beta.3 → 2.0.0-canary.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 (221) hide show
  1. package/dist/js/modern/analyze/constants.js +38 -18
  2. package/dist/js/modern/analyze/generateCode.js +261 -221
  3. package/dist/js/modern/analyze/getBundleEntry.js +31 -32
  4. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +93 -49
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +89 -47
  6. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -2
  7. package/dist/js/modern/analyze/getClientRoutes/utils.js +23 -10
  8. package/dist/js/modern/analyze/getFileSystemEntry.js +43 -22
  9. package/dist/js/modern/analyze/getHtmlTemplate.js +89 -49
  10. package/dist/js/modern/analyze/getServerRoutes.js +122 -126
  11. package/dist/js/modern/analyze/index.js +193 -159
  12. package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -16
  13. package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -11
  14. package/dist/js/modern/analyze/nestedRoutes.js +106 -60
  15. package/dist/js/modern/analyze/templates.js +161 -80
  16. package/dist/js/modern/analyze/utils.js +87 -66
  17. package/dist/js/modern/builder/builderPlugins/compatModern.js +121 -109
  18. package/dist/js/modern/builder/index.js +122 -83
  19. package/dist/js/modern/builder/loaders/routerLoader.js +9 -12
  20. package/dist/js/modern/builder/loaders/serverModuleLoader.js +4 -1
  21. package/dist/js/modern/builder/share.js +22 -20
  22. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +23 -22
  23. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +31 -27
  24. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +98 -84
  25. package/dist/js/modern/commands/build.js +67 -42
  26. package/dist/js/modern/commands/deploy.js +27 -4
  27. package/dist/js/modern/commands/dev.js +77 -27
  28. package/dist/js/modern/commands/index.js +1 -1
  29. package/dist/js/modern/commands/inspect.js +30 -5
  30. package/dist/js/modern/commands/start.js +37 -15
  31. package/dist/js/modern/config/default.js +103 -113
  32. package/dist/js/modern/config/index.js +8 -2
  33. package/dist/js/modern/config/initial/createHtmlConfig.js +5 -2
  34. package/dist/js/modern/config/initial/createOutputConfig.js +9 -10
  35. package/dist/js/modern/config/initial/createSourceConfig.js +5 -2
  36. package/dist/js/modern/config/initial/createToolsConfig.js +7 -6
  37. package/dist/js/modern/config/initial/index.js +9 -4
  38. package/dist/js/modern/config/initial/inits.js +109 -73
  39. package/dist/js/modern/config/initial/transformNormalizedConfig.js +6 -3
  40. package/dist/js/modern/defineConfig.js +26 -11
  41. package/dist/js/modern/exports/server.js +4 -1
  42. package/dist/js/modern/hooks.js +10 -3
  43. package/dist/js/modern/index.js +140 -89
  44. package/dist/js/modern/initialize/index.js +98 -51
  45. package/dist/js/modern/locale/en.js +20 -21
  46. package/dist/js/modern/locale/index.js +6 -6
  47. package/dist/js/modern/locale/zh.js +21 -22
  48. package/dist/js/modern/schema/Schema.js +6 -5
  49. package/dist/js/modern/schema/index.js +51 -100
  50. package/dist/js/modern/schema/legacy.js +96 -231
  51. package/dist/js/modern/types/config/index.js +0 -1
  52. package/dist/js/modern/types/index.js +0 -1
  53. package/dist/js/modern/types/legacyConfig/output.js +0 -1
  54. package/dist/js/modern/utils/commands.js +5 -2
  55. package/dist/js/modern/utils/config.js +102 -41
  56. package/dist/js/modern/utils/createFileWatcher.js +84 -51
  57. package/dist/js/modern/utils/createServer.js +63 -17
  58. package/dist/js/modern/utils/getSpecifiedEntries.js +46 -19
  59. package/dist/js/modern/utils/language.js +6 -3
  60. package/dist/js/modern/utils/printInstructions.js +27 -8
  61. package/dist/js/modern/utils/restart.js +43 -16
  62. package/dist/js/modern/utils/routes.js +29 -12
  63. package/dist/js/node/analyze/constants.js +54 -39
  64. package/dist/js/node/analyze/generateCode.js +281 -239
  65. package/dist/js/node/analyze/getBundleEntry.js +55 -44
  66. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +132 -76
  67. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +128 -74
  68. package/dist/js/node/analyze/getClientRoutes/index.js +23 -17
  69. package/dist/js/node/analyze/getClientRoutes/utils.js +44 -21
  70. package/dist/js/node/analyze/getFileSystemEntry.js +70 -39
  71. package/dist/js/node/analyze/getHtmlTemplate.js +116 -61
  72. package/dist/js/node/analyze/getServerRoutes.js +143 -137
  73. package/dist/js/node/analyze/index.js +240 -174
  74. package/dist/js/node/analyze/isDefaultExportFunction.js +55 -26
  75. package/dist/js/node/analyze/makeLegalIdentifier.js +27 -15
  76. package/dist/js/node/analyze/nestedRoutes.js +137 -75
  77. package/dist/js/node/analyze/templates.js +183 -89
  78. package/dist/js/node/analyze/utils.js +114 -81
  79. package/dist/js/node/builder/builderPlugins/compatModern.js +149 -122
  80. package/dist/js/node/builder/index.js +150 -92
  81. package/dist/js/node/builder/loaders/routerLoader.js +27 -18
  82. package/dist/js/node/builder/loaders/serverModuleLoader.js +22 -7
  83. package/dist/js/node/builder/share.js +45 -25
  84. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +39 -26
  85. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +47 -31
  86. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +116 -90
  87. package/dist/js/node/commands/build.js +89 -52
  88. package/dist/js/node/commands/deploy.js +45 -10
  89. package/dist/js/node/commands/dev.js +99 -41
  90. package/dist/js/node/commands/index.js +19 -38
  91. package/dist/js/node/commands/inspect.js +48 -11
  92. package/dist/js/node/commands/start.js +65 -26
  93. package/dist/js/node/config/default.js +119 -117
  94. package/dist/js/node/config/index.js +25 -29
  95. package/dist/js/node/config/initial/createHtmlConfig.js +22 -6
  96. package/dist/js/node/config/initial/createOutputConfig.js +26 -14
  97. package/dist/js/node/config/initial/createSourceConfig.js +22 -6
  98. package/dist/js/node/config/initial/createToolsConfig.js +24 -10
  99. package/dist/js/node/config/initial/index.js +28 -17
  100. package/dist/js/node/config/initial/inits.js +126 -81
  101. package/dist/js/node/config/initial/transformNormalizedConfig.js +31 -15
  102. package/dist/js/node/defineConfig.js +43 -17
  103. package/dist/js/node/exports/server.js +21 -10
  104. package/dist/js/node/hooks.js +44 -29
  105. package/dist/js/node/index.js +190 -130
  106. package/dist/js/node/initialize/index.js +116 -61
  107. package/dist/js/node/locale/en.js +36 -25
  108. package/dist/js/node/locale/index.js +27 -15
  109. package/dist/js/node/locale/zh.js +37 -26
  110. package/dist/js/node/schema/Schema.js +23 -10
  111. package/dist/js/node/schema/index.js +77 -114
  112. package/dist/js/node/schema/legacy.js +117 -240
  113. package/dist/js/node/types/config/index.js +17 -16
  114. package/dist/js/node/types/index.js +19 -38
  115. package/dist/js/node/types/legacyConfig/output.js +0 -5
  116. package/dist/js/node/utils/commands.js +21 -6
  117. package/dist/js/node/utils/config.js +120 -51
  118. package/dist/js/node/utils/createFileWatcher.js +104 -61
  119. package/dist/js/node/utils/createServer.js +86 -25
  120. package/dist/js/node/utils/getSpecifiedEntries.js +64 -25
  121. package/dist/js/node/utils/language.js +24 -8
  122. package/dist/js/node/utils/printInstructions.js +47 -16
  123. package/dist/js/node/utils/restart.js +61 -21
  124. package/dist/js/node/utils/routes.js +53 -18
  125. package/dist/js/treeshaking/analyze/constants.js +28 -18
  126. package/dist/js/treeshaking/analyze/generateCode.js +599 -406
  127. package/dist/js/treeshaking/analyze/getBundleEntry.js +52 -63
  128. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +214 -168
  129. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +215 -169
  130. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -2
  131. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +19 -20
  132. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +89 -86
  133. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +298 -125
  134. package/dist/js/treeshaking/analyze/getServerRoutes.js +210 -147
  135. package/dist/js/treeshaking/analyze/index.js +558 -303
  136. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +45 -26
  137. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -16
  138. package/dist/js/treeshaking/analyze/nestedRoutes.js +411 -200
  139. package/dist/js/treeshaking/analyze/templates.js +433 -236
  140. package/dist/js/treeshaking/analyze/utils.js +358 -153
  141. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +281 -200
  142. package/dist/js/treeshaking/builder/index.js +371 -163
  143. package/dist/js/treeshaking/builder/loaders/routerLoader.js +11 -12
  144. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +3 -2
  145. package/dist/js/treeshaking/builder/share.js +41 -44
  146. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +108 -44
  147. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +70 -39
  148. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +332 -112
  149. package/dist/js/treeshaking/commands/build.js +286 -88
  150. package/dist/js/treeshaking/commands/deploy.js +153 -25
  151. package/dist/js/treeshaking/commands/dev.js +318 -131
  152. package/dist/js/treeshaking/commands/index.js +1 -1
  153. package/dist/js/treeshaking/commands/inspect.js +147 -32
  154. package/dist/js/treeshaking/commands/start.js +190 -67
  155. package/dist/js/treeshaking/config/default.js +210 -198
  156. package/dist/js/treeshaking/config/index.js +3 -2
  157. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -31
  158. package/dist/js/treeshaking/config/initial/createOutputConfig.js +43 -70
  159. package/dist/js/treeshaking/config/initial/createSourceConfig.js +37 -40
  160. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -38
  161. package/dist/js/treeshaking/config/initial/index.js +10 -9
  162. package/dist/js/treeshaking/config/initial/inits.js +205 -106
  163. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +27 -34
  164. package/dist/js/treeshaking/defineConfig.js +60 -13
  165. package/dist/js/treeshaking/exports/server.js +2 -1
  166. package/dist/js/treeshaking/hooks.js +26 -25
  167. package/dist/js/treeshaking/index.js +465 -257
  168. package/dist/js/treeshaking/initialize/index.js +290 -112
  169. package/dist/js/treeshaking/locale/en.js +34 -33
  170. package/dist/js/treeshaking/locale/index.js +5 -5
  171. package/dist/js/treeshaking/locale/zh.js +34 -33
  172. package/dist/js/treeshaking/schema/Schema.js +267 -69
  173. package/dist/js/treeshaking/schema/index.js +165 -121
  174. package/dist/js/treeshaking/schema/legacy.js +323 -256
  175. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  176. package/dist/js/treeshaking/types/config/dev.js +1 -0
  177. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  178. package/dist/js/treeshaking/types/config/html.js +1 -0
  179. package/dist/js/treeshaking/types/config/index.js +0 -1
  180. package/dist/js/treeshaking/types/config/output.js +1 -0
  181. package/dist/js/treeshaking/types/config/performance.js +1 -0
  182. package/dist/js/treeshaking/types/config/security.js +1 -0
  183. package/dist/js/treeshaking/types/config/source.js +1 -0
  184. package/dist/js/treeshaking/types/config/tools.js +1 -0
  185. package/dist/js/treeshaking/types/hooks.js +1 -0
  186. package/dist/js/treeshaking/types/index.js +0 -1
  187. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  188. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  189. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  190. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -1
  191. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  192. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  193. package/dist/js/treeshaking/utils/commands.js +6 -5
  194. package/dist/js/treeshaking/utils/config.js +295 -117
  195. package/dist/js/treeshaking/utils/createFileWatcher.js +278 -118
  196. package/dist/js/treeshaking/utils/createServer.js +252 -67
  197. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +182 -55
  198. package/dist/js/treeshaking/utils/language.js +6 -5
  199. package/dist/js/treeshaking/utils/printInstructions.js +151 -29
  200. package/dist/js/treeshaking/utils/restart.js +184 -42
  201. package/dist/js/treeshaking/utils/routes.js +151 -27
  202. package/dist/js/treeshaking/utils/types.js +1 -0
  203. package/dist/types/analyze/index.d.ts +2 -0
  204. package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -1
  205. package/dist/types/builder/index.d.ts +2 -2
  206. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +1 -7
  207. package/dist/types/defineConfig.d.ts +1 -0
  208. package/dist/types/index.d.ts +2 -0
  209. package/dist/types/initialize/index.d.ts +2 -0
  210. package/dist/types/types/config/index.d.ts +1 -0
  211. package/dist/types/types/config/output.d.ts +0 -1
  212. package/dist/types/types/config/source.d.ts +1 -0
  213. package/dist/types/types/config/tools.d.ts +2 -0
  214. package/dist/types/types/legacyConfig/dev.d.ts +1 -0
  215. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  216. package/dist/types/types/legacyConfig/source.d.ts +1 -0
  217. package/dist/types/types/legacyConfig/tools.d.ts +1 -0
  218. package/dist/types/utils/config.d.ts +1 -0
  219. package/dist/types/utils/createServer.d.ts +1 -0
  220. package/dist/types/utils/restart.d.ts +1 -1
  221. package/package.json +9 -8
@@ -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 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 }; }
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_esbuild = require("esbuild");
34
+ var import_commands = require("../utils/commands");
35
+ var templates = __toESM(require("./templates"));
36
+ var import_getClientRoutes = require("./getClientRoutes");
37
+ var import_constants = require("./constants");
38
+ var import_utils2 = require("./utils");
39
+ var import_nestedRoutes = require("./nestedRoutes");
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
+ };
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,252 @@ 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
+ const command = (0, import_commands.getCommand)();
114
+ yield (0, import_esbuild.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(build2) {
128
+ build2.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 buildServerLoader = async (entry, outfile) => {
114
- const command = (0, _commands.getCommand)();
115
- await _esbuild.default.build({
116
- format: 'cjs',
117
- platform: 'node',
118
- target: 'esnext',
142
+ });
143
+ const buildServerLoader = (entry, outfile) => __async(void 0, null, function* () {
144
+ const command = (0, import_commands.getCommand)();
145
+ yield (0, import_esbuild.build)({
146
+ format: "cjs",
147
+ platform: "node",
148
+ target: "esnext",
119
149
  loader,
120
- watch: command === 'dev' && {},
150
+ watch: command === "dev" && {},
121
151
  bundle: true,
122
- logLevel: 'error',
152
+ logLevel: "error",
123
153
  entryPoints: [entry],
124
154
  outfile
125
155
  });
126
- };
127
- const generateCode = async (appContext, config, entrypoints, api) => {
128
- var _config$runtime, _config$runtime$route;
156
+ });
157
+ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, null, function* () {
158
+ var _a, _b;
129
159
  const {
130
160
  internalDirectory,
131
161
  distDirectory,
132
162
  srcDirectory,
133
163
  internalDirAlias,
134
- internalSrcAlias
164
+ internalSrcAlias,
165
+ packageName
135
166
  } = appContext;
136
167
  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({
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({
157
208
  entrypoint,
158
- srcDirectory,
159
- srcAlias: internalSrcAlias,
160
- internalDirectory,
161
- internalDirAlias
209
+ routes: initialRoutes
162
210
  });
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
- }
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";
173
221
  } 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);
222
+ mode = false;
177
223
  }
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);
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
+ }
199
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
+ })
244
+ });
245
+ if (entrypoint.nestedRoutesEntry) {
246
+ const routesServerFile = import_path.default.join(
247
+ internalDirectory,
248
+ entryName,
249
+ "route-server-loaders.js"
250
+ );
251
+ const outputRoutesServerFile = import_path.default.join(
252
+ distDirectory,
253
+ import_utils.LOADER_ROUTES_DIR,
254
+ entryName,
255
+ "index.js"
256
+ );
257
+ const code3 = templates.routesForServer({
258
+ routes,
259
+ internalDirectory,
260
+ entryName
261
+ });
262
+ yield import_utils.fs.ensureFile(routesServerFile);
263
+ yield import_utils.fs.writeFile(routesServerFile, code3);
264
+ const loaderEntryFile = import_path.default.join(
265
+ internalDirectory,
266
+ entryName,
267
+ import_constants.TEMP_LOADERS_DIR,
268
+ "entry.js"
269
+ );
270
+ const loaderIndexFile = import_path.default.join(
271
+ internalDirectory,
272
+ entryName,
273
+ import_constants.TEMP_LOADERS_DIR,
274
+ "index.js"
275
+ );
276
+ if (yield import_utils.fs.pathExists(loaderEntryFile)) {
277
+ yield buildLoader(loaderEntryFile, loaderIndexFile);
278
+ }
279
+ if (yield import_utils.fs.pathExists(routesServerFile)) {
280
+ yield buildServerLoader(routesServerFile, outputRoutesServerFile);
281
+ }
282
+ }
283
+ import_utils.fs.outputFileSync(
284
+ import_path.default.resolve(
285
+ internalDirectory,
286
+ `./${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`
287
+ ),
288
+ code2,
289
+ "utf8"
290
+ );
200
291
  }
201
- const {
202
- code
203
- } = await hookRunners.beforeGenerateRoutes({
292
+ const { imports: importStatements } = yield hookRunners.modifyEntryImports({
204
293
  entrypoint,
205
- code: await templates.fileSystemRoutes({
206
- routes,
207
- ssrMode: mode,
208
- nestedRoutesEntry: entrypoint.nestedRoutesEntry,
209
- entryName: entrypoint.entryName,
294
+ imports: (0, import_utils2.getDefaultImports)({
295
+ entrypoint,
296
+ srcDirectory,
297
+ internalSrcAlias,
298
+ internalDirAlias,
210
299
  internalDirectory
211
300
  })
212
301
  });
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)({
302
+ const { plugins } = yield hookRunners.modifyEntryRuntimePlugins({
243
303
  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({
304
+ plugins: []
305
+ });
306
+ const { code: renderFunction } = yield hookRunners.modifyEntryRenderFunction({
307
+ entrypoint,
308
+ code: templates.renderFunction({
309
+ plugins,
310
+ customBootstrap,
311
+ fileSystemRoutes
312
+ })
313
+ });
314
+ const { exportStatement } = yield hookRunners.modifyEntryExport({
292
315
  entrypoint,
293
- code: `import('./${_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`
316
+ exportStatement: "export default AppWrapper;"
294
317
  });
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');
318
+ const code = templates.index({
319
+ mountId,
320
+ imports: createImportStatements(importStatements),
321
+ renderFunction,
322
+ exportStatement
323
+ });
324
+ const entryFile = import_path.default.resolve(
325
+ internalDirectory,
326
+ `./${entryName}/${import_constants.ENTRY_POINT_FILE_NAME}`
327
+ );
328
+ entrypoint.entry = entryFile;
329
+ if (config.source.enableAsyncEntry) {
330
+ const { code: asyncEntryCode } = yield hookRunners.modifyAsyncEntry({
331
+ entrypoint,
332
+ code: `import('./${import_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`
333
+ });
334
+ import_utils.fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
335
+ const bootstrapFile = import_path.default.resolve(
336
+ internalDirectory,
337
+ `./${entryName}/${import_constants.ENTRY_BOOTSTRAP_FILE_NAME}`
338
+ );
339
+ import_utils.fs.outputFileSync(bootstrapFile, code, "utf8");
340
+ } else {
341
+ import_utils.fs.outputFileSync(entryFile, code, "utf8");
342
+ }
300
343
  }
301
- }
344
+ });
302
345
  }
303
- };
304
- exports.generateCode = generateCode;
346
+ });