@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,369 +1,619 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
2
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
5
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
6
- import path from 'path';
7
- import { fs, logger } from '@modern-js/utils';
8
- import { useResolvedConfigContext } from '@modern-js/core';
9
- import esbuild from 'esbuild';
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithoutHoles(arr) {
7
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _asyncToGenerator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _iterableToArray(iter) {
39
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
40
+ }
41
+ function _nonIterableSpread() {
42
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
43
+ }
44
+ function _toConsumableArray(arr) {
45
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
46
+ }
47
+ function _unsupportedIterableToArray(o, minLen) {
48
+ if (!o) return;
49
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
50
+ var n = Object.prototype.toString.call(o).slice(8, -1);
51
+ if (n === "Object" && o.constructor) n = o.constructor.name;
52
+ if (n === "Map" || n === "Set") return Array.from(n);
53
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
54
+ }
55
+ var __generator = this && this.__generator || function(thisArg, body) {
56
+ var f, y, t, g, _ = {
57
+ label: 0,
58
+ sent: function() {
59
+ if (t[0] & 1) throw t[1];
60
+ return t[1];
61
+ },
62
+ trys: [],
63
+ ops: []
64
+ };
65
+ return(g = {
66
+ next: verb(0),
67
+ "throw": verb(1),
68
+ "return": verb(2)
69
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
70
+ return this;
71
+ }), g);
72
+ function verb(n) {
73
+ return function(v) {
74
+ return step([
75
+ n,
76
+ v
77
+ ]);
78
+ };
79
+ }
80
+ function step(op) {
81
+ if (f) throw new TypeError("Generator is already executing.");
82
+ while(_)try {
83
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
84
+ if (y = 0, t) op = [
85
+ op[0] & 2,
86
+ t.value
87
+ ];
88
+ switch(op[0]){
89
+ case 0:
90
+ case 1:
91
+ t = op;
92
+ break;
93
+ case 4:
94
+ _.label++;
95
+ return {
96
+ value: op[1],
97
+ done: false
98
+ };
99
+ case 5:
100
+ _.label++;
101
+ y = op[1];
102
+ op = [
103
+ 0
104
+ ];
105
+ continue;
106
+ case 7:
107
+ op = _.ops.pop();
108
+ _.trys.pop();
109
+ continue;
110
+ default:
111
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
112
+ _ = 0;
113
+ continue;
114
+ }
115
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
116
+ _.label = op[1];
117
+ break;
118
+ }
119
+ if (op[0] === 6 && _.label < t[1]) {
120
+ _.label = t[1];
121
+ t = op;
122
+ break;
123
+ }
124
+ if (t && _.label < t[2]) {
125
+ _.label = t[2];
126
+ _.ops.push(op);
127
+ break;
128
+ }
129
+ if (t[2]) _.ops.pop();
130
+ _.trys.pop();
131
+ continue;
132
+ }
133
+ op = body.call(thisArg, _);
134
+ } catch (e) {
135
+ op = [
136
+ 6,
137
+ e
138
+ ];
139
+ y = 0;
140
+ } finally{
141
+ f = t = 0;
142
+ }
143
+ if (op[0] & 5) throw op[1];
144
+ return {
145
+ value: op[0] ? op[1] : void 0,
146
+ done: true
147
+ };
148
+ }
149
+ };
150
+ import path from "path";
151
+ import { fs, getEntryOptions, LOADER_ROUTES_DIR, logger } from "@modern-js/utils";
152
+ import { useResolvedConfigContext } from "@modern-js/core";
10
153
  import { getCommand } from "../utils/commands";
11
154
  import * as templates from "./templates";
12
155
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
13
- import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
156
+ import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, TEMP_LOADERS_DIR } from "./constants";
14
157
  import { getDefaultImports } from "./utils";
15
158
  import { walk } from "./nestedRoutes";
16
- var createImportSpecifier = function createImportSpecifier(specifiers) {
17
- var defaults = '';
18
- var named = [];
19
- var _iterator = _createForOfIteratorHelper(specifiers),
20
- _step;
21
- try {
22
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
23
- var _step$value = _step.value,
24
- local = _step$value.local,
25
- imported = _step$value.imported;
26
- if (local && imported) {
27
- named.push("".concat(imported, " as ").concat(local));
28
- } else if (local) {
29
- defaults = local;
30
- } else {
31
- named.push(imported);
32
- }
159
+ import { loaderBuilder, serverLoaderBuilder } from "./Builder";
160
+ var loader = {
161
+ ".js": "jsx",
162
+ ".ts": "tsx"
163
+ };
164
+ var EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
165
+ var createImportSpecifier = function(specifiers) {
166
+ var defaults = "";
167
+ var named = [];
168
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
169
+ try {
170
+ for(var _iterator = specifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
171
+ var _value = _step.value, local = _value.local, imported = _value.imported;
172
+ if (local && imported) {
173
+ named.push("".concat(imported, " as ").concat(local));
174
+ } else if (local) {
175
+ defaults = local;
176
+ } else {
177
+ named.push(imported);
178
+ }
179
+ }
180
+ } catch (err) {
181
+ _didIteratorError = true;
182
+ _iteratorError = err;
183
+ } finally{
184
+ try {
185
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
186
+ _iterator.return();
187
+ }
188
+ } finally{
189
+ if (_didIteratorError) {
190
+ throw _iteratorError;
191
+ }
192
+ }
193
+ }
194
+ if (defaults && named.length) {
195
+ return "".concat(defaults, ", { ").concat(named.join(", "), " }");
196
+ } else if (defaults) {
197
+ return defaults;
198
+ } else {
199
+ return "{ ".concat(named.join(", "), " }");
33
200
  }
34
- } catch (err) {
35
- _iterator.e(err);
36
- } finally {
37
- _iterator.f();
38
- }
39
- if (defaults && named.length) {
40
- return "".concat(defaults, ", { ").concat(named.join(', '), " }");
41
- } else if (defaults) {
42
- return defaults;
43
- } else {
44
- return "{ ".concat(named.join(', '), " }");
45
- }
46
201
  };
47
- export var createImportStatements = function createImportStatements(statements) {
48
- // merge import statements with the same value.
49
- var deDuplicated = [];
50
- var seen = new Map();
51
- var _iterator2 = _createForOfIteratorHelper(statements),
52
- _step2;
53
- try {
54
- var _loop = function _loop() {
55
- var _step2$value = _step2.value,
56
- value = _step2$value.value,
57
- specifiers = _step2$value.specifiers,
58
- initialize = _step2$value.initialize;
59
- if (!seen.has(value)) {
60
- deDuplicated.push({
61
- value: value,
62
- specifiers: specifiers,
63
- initialize: initialize
202
+ var createImportStatements = function(statements) {
203
+ var deDuplicated = [];
204
+ var seen = /* @__PURE__ */ new Map();
205
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
206
+ try {
207
+ var _loop = function() {
208
+ var _value = _step.value, value = _value.value, specifiers = _value.specifiers, initialize = _value.initialize;
209
+ if (!seen.has(value)) {
210
+ deDuplicated.push({
211
+ value: value,
212
+ specifiers: specifiers,
213
+ initialize: initialize
214
+ });
215
+ seen.set(value, specifiers);
216
+ } else {
217
+ var _instance;
218
+ var ref;
219
+ (_instance = seen.get(value)).push.apply(_instance, _toConsumableArray(specifiers));
220
+ var modifyIndex = deDuplicated.findIndex(function(v) {
221
+ return v.value === value;
222
+ });
223
+ var ref1;
224
+ var originInitialize = (ref1 = (ref = deDuplicated[modifyIndex]) === null || ref === void 0 ? void 0 : ref.initialize) !== null && ref1 !== void 0 ? ref1 : "";
225
+ deDuplicated[modifyIndex].initialize = originInitialize.concat("\n".concat(initialize || ""));
226
+ }
227
+ };
228
+ for(var _iterator = statements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
229
+ } catch (err) {
230
+ _didIteratorError = true;
231
+ _iteratorError = err;
232
+ } finally{
233
+ try {
234
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
235
+ _iterator.return();
236
+ }
237
+ } finally{
238
+ if (_didIteratorError) {
239
+ throw _iteratorError;
240
+ }
241
+ }
242
+ }
243
+ return deDuplicated.map(function(param) {
244
+ var value = param.value, specifiers = param.specifiers, initialize = param.initialize;
245
+ return "import ".concat(createImportSpecifier(specifiers), " from '").concat(value, "';\n").concat(initialize || "");
246
+ }).join("\n");
247
+ };
248
+ var buildLoader = function() {
249
+ var _ref = _asyncToGenerator(function(entry, outfile) {
250
+ var command;
251
+ return __generator(this, function(_state) {
252
+ switch(_state.label){
253
+ case 0:
254
+ command = getCommand();
255
+ return [
256
+ 4,
257
+ loaderBuilder.build({
258
+ format: "esm",
259
+ platform: "browser",
260
+ target: "esnext",
261
+ loader: loader,
262
+ watch: command === "dev" && {},
263
+ bundle: true,
264
+ logLevel: "error",
265
+ entryPoints: [
266
+ entry
267
+ ],
268
+ outfile: outfile,
269
+ plugins: [
270
+ {
271
+ name: "make-all-packages-external",
272
+ setup: function setup(build) {
273
+ build.onResolve({
274
+ filter: EXTERNAL_REGEXP
275
+ }, function(args) {
276
+ var external = true;
277
+ if (args.kind === "entry-point") {
278
+ external = false;
279
+ }
280
+ return {
281
+ path: args.path,
282
+ external: external
283
+ };
284
+ });
285
+ }
286
+ }
287
+ ]
288
+ })
289
+ ];
290
+ case 1:
291
+ _state.sent();
292
+ return [
293
+ 2
294
+ ];
295
+ }
64
296
  });
65
- seen.set(value, specifiers);
66
- } else {
67
- var _seen$get, _deDuplicated$modifyI, _deDuplicated$modifyI2;
68
- (_seen$get = seen.get(value)).push.apply(_seen$get, _toConsumableArray(specifiers));
69
- // make "initialize" param can be connected when multiple plugins were imported from same package
70
- var modifyIndex = deDuplicated.findIndex(function (v) {
71
- return v.value === value;
297
+ });
298
+ return function buildLoader(entry, outfile) {
299
+ return _ref.apply(this, arguments);
300
+ };
301
+ }();
302
+ var buildServerLoader = function() {
303
+ var _ref = _asyncToGenerator(function(entry, outfile) {
304
+ var command;
305
+ return __generator(this, function(_state) {
306
+ switch(_state.label){
307
+ case 0:
308
+ command = getCommand();
309
+ return [
310
+ 4,
311
+ serverLoaderBuilder.build({
312
+ format: "cjs",
313
+ platform: "node",
314
+ target: "esnext",
315
+ loader: loader,
316
+ watch: command === "dev" && {},
317
+ bundle: true,
318
+ logLevel: "error",
319
+ entryPoints: [
320
+ entry
321
+ ],
322
+ outfile: outfile
323
+ })
324
+ ];
325
+ case 1:
326
+ _state.sent();
327
+ return [
328
+ 2
329
+ ];
330
+ }
72
331
  });
73
- var originInitialize = (_deDuplicated$modifyI = (_deDuplicated$modifyI2 = deDuplicated[modifyIndex]) === null || _deDuplicated$modifyI2 === void 0 ? void 0 : _deDuplicated$modifyI2.initialize) !== null && _deDuplicated$modifyI !== void 0 ? _deDuplicated$modifyI : '';
74
- deDuplicated[modifyIndex].initialize = originInitialize.concat("\n".concat(initialize || ''));
75
- }
332
+ });
333
+ return function buildServerLoader(entry, outfile) {
334
+ return _ref.apply(this, arguments);
76
335
  };
77
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
78
- _loop();
79
- }
80
- } catch (err) {
81
- _iterator2.e(err);
82
- } finally {
83
- _iterator2.f();
84
- }
85
- return deDuplicated.map(function (_ref) {
86
- var value = _ref.value,
87
- specifiers = _ref.specifiers,
88
- initialize = _ref.initialize;
89
- return "import ".concat(createImportSpecifier(specifiers), " from '").concat(value, "';\n").concat(initialize || '');
90
- }).join('\n');
91
- };
92
- var buildLoader = /*#__PURE__*/function () {
93
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(entry, outfile) {
94
- var loader, EXTERNAL_REGEXP, command;
95
- return _regeneratorRuntime().wrap(function _callee$(_context) {
96
- while (1) {
97
- switch (_context.prev = _context.next) {
98
- case 0:
99
- loader = {
100
- '.js': 'jsx',
101
- '.ts': 'tsx'
102
- };
103
- EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
104
- command = getCommand();
105
- _context.next = 5;
106
- return esbuild.build({
107
- format: 'cjs',
108
- platform: 'node',
109
- target: 'esnext',
110
- loader: loader,
111
- watch: command === 'dev' && {},
112
- bundle: true,
113
- logLevel: 'error',
114
- entryPoints: [entry],
115
- outfile: outfile,
116
- plugins: [{
117
- name: 'make-all-packages-external',
118
- setup: function setup(build) {
119
- // https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
120
- build.onResolve({
121
- filter: EXTERNAL_REGEXP
122
- }, function (args) {
123
- var external = true;
124
- // FIXME: windows external entrypoint
125
- if (args.kind === 'entry-point') {
126
- external = false;
127
- }
128
- return {
129
- path: args.path,
130
- external: external
131
- };
132
- });
133
- }
134
- }]
135
- });
136
- case 5:
137
- case "end":
138
- return _context.stop();
139
- }
140
- }
141
- }, _callee);
142
- }));
143
- return function buildLoader(_x, _x2) {
144
- return _ref2.apply(this, arguments);
145
- };
146
336
  }();
147
- export var generateCode = /*#__PURE__*/function () {
148
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(appContext, config, entrypoints, api) {
149
- var _config$runtime, _config$runtime$route;
150
- var internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, hookRunners, islegacy, mountId, getRoutes, generateEntryCode, _generateEntryCode;
151
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
152
- while (1) {
153
- switch (_context3.prev = _context3.next) {
154
- case 0:
155
- _generateEntryCode = function _generateEntryCode3() {
156
- _generateEntryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(entrypoint) {
157
- var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, _yield$hookRunners$mo, routes, _config, ssr, mode, hasPageRoute, _yield$hookRunners$be, _code, routesServerFile, outputRoutesServerFile, _code2, _yield$hookRunners$mo2, importStatements, _yield$hookRunners$mo3, plugins, _yield$hookRunners$mo4, renderFunction, _yield$hookRunners$mo5, exportStatement, code, entryFile, _yield$hookRunners$mo6, asyncEntryCode, bootstrapFile;
158
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
159
- while (1) {
160
- switch (_context2.prev = _context2.next) {
161
- case 0:
162
- entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
163
- if (!isAutoMount) {
164
- _context2.next = 69;
165
- break;
166
- }
167
- if (!fileSystemRoutes) {
168
- _context2.next = 39;
169
- break;
170
- }
171
- initialRoutes = [];
172
- nestedRoute = null;
173
- if (entrypoint.entry) {
174
- initialRoutes = getRoutes({
175
- entrypoint: entrypoint,
176
- srcDirectory: srcDirectory,
177
- srcAlias: internalSrcAlias,
178
- internalDirectory: internalDirectory,
179
- internalDirAlias: internalDirAlias
180
- });
181
- }
182
- if (!entrypoint.nestedRoutesEntry) {
183
- _context2.next = 16;
184
- break;
185
- }
186
- if (islegacy) {
187
- _context2.next = 14;
188
- break;
189
- }
190
- _context2.next = 10;
191
- return walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
192
- name: internalSrcAlias,
193
- basename: srcDirectory
194
- }, entrypoint.entryName);
195
- case 10:
196
- nestedRoute = _context2.sent;
197
- if (nestedRoute) {
198
- initialRoutes.unshift(nestedRoute);
199
- }
200
- _context2.next = 16;
201
- break;
202
- case 14:
203
- logger.error('Nested routes is not supported in legacy mode.');
204
- // eslint-disable-next-line no-process-exit
205
- process.exit(1);
206
- case 16:
207
- _context2.next = 18;
208
- return hookRunners.modifyFileSystemRoutes({
209
- entrypoint: entrypoint,
210
- routes: initialRoutes
211
- });
212
- case 18:
213
- _yield$hookRunners$mo = _context2.sent;
214
- routes = _yield$hookRunners$mo.routes;
215
- _config = useResolvedConfigContext();
216
- ssr = _config === null || _config === void 0 ? void 0 : _config.server.ssr;
217
- if (ssr) {
218
- mode = _typeof(ssr) === 'object' ? ssr.mode || 'string' : 'string';
219
- } else {
220
- mode = false;
221
- }
222
- if (mode === 'stream') {
223
- hasPageRoute = routes.some(function (route) {
224
- return 'type' in route && route.type === 'page';
225
- });
226
- if (hasPageRoute) {
227
- logger.error('streaming ssr is not supported when pages dir exists');
228
- // eslint-disable-next-line no-process-exit
337
+ var generateCode = function() {
338
+ var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
339
+ var ref, ref1, internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, islegacy, mountId, getRoutes;
340
+ function generateEntryCode(entrypoint) {
341
+ return _generateEntryCode.apply(this, arguments);
342
+ }
343
+ function _generateEntryCode() {
344
+ _generateEntryCode = _asyncToGenerator(function(entrypoint) {
345
+ var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, ref, code2, _, _tmp, routesServerFile, outputRoutesServerFile, code3, loaderEntryFile, loaderIndexFile, ref1, importStatements, plugins, ref2, renderFunction, exportStatement, code, entryFile, ref3, asyncEntryCode, bootstrapFile;
346
+ return __generator(this, function(_state) {
347
+ switch(_state.label){
348
+ case 0:
349
+ entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
350
+ if (!isAutoMount) return [
351
+ 3,
352
+ 22
353
+ ];
354
+ if (!fileSystemRoutes) return [
355
+ 3,
356
+ 15
357
+ ];
358
+ initialRoutes = [];
359
+ nestedRoute = null;
360
+ if (entrypoint.entry) {
361
+ initialRoutes = getRoutes({
362
+ entrypoint: entrypoint,
363
+ srcDirectory: srcDirectory,
364
+ srcAlias: internalSrcAlias,
365
+ internalDirectory: internalDirectory,
366
+ internalDirAlias: internalDirAlias
367
+ });
368
+ }
369
+ if (!entrypoint.nestedRoutesEntry) return [
370
+ 3,
371
+ 3
372
+ ];
373
+ if (!!islegacy) return [
374
+ 3,
375
+ 2
376
+ ];
377
+ return [
378
+ 4,
379
+ walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
380
+ name: internalSrcAlias,
381
+ basename: srcDirectory
382
+ }, entrypoint.entryName)
383
+ ];
384
+ case 1:
385
+ nestedRoute = _state.sent();
386
+ if (nestedRoute) {
387
+ initialRoutes.unshift(nestedRoute);
388
+ }
389
+ return [
390
+ 3,
391
+ 3
392
+ ];
393
+ case 2:
394
+ logger.error("Nested routes is not supported in legacy mode.");
229
395
  process.exit(1);
230
- }
231
- }
232
- _context2.next = 26;
233
- return hookRunners.beforeGenerateRoutes({
234
- entrypoint: entrypoint,
235
- code: templates.fileSystemRoutes({
236
- routes: routes,
237
- ssrMode: mode,
238
- nestedRoutesEntry: entrypoint.nestedRoutesEntry,
239
- entryName: entrypoint.entryName
240
- })
241
- });
242
- case 26:
243
- _yield$hookRunners$be = _context2.sent;
244
- _code = _yield$hookRunners$be.code;
245
- if (!entrypoint.nestedRoutesEntry) {
246
- _context2.next = 38;
247
- break;
248
- }
249
- routesServerFile = path.join(internalDirectory, entryName, 'routes.server.js');
250
- outputRoutesServerFile = path.join(distDirectory, 'loader-routes', entryName, 'index.js');
251
- _code2 = templates.routesForServer({
252
- routes: routes,
253
- alias: {
254
- name: internalSrcAlias,
255
- basename: srcDirectory
256
- }
257
- });
258
- _context2.next = 34;
259
- return fs.ensureFile(routesServerFile);
260
- case 34:
261
- _context2.next = 36;
262
- return fs.writeFile(routesServerFile, _code2);
263
- case 36:
264
- _context2.next = 38;
265
- return buildLoader(routesServerFile, outputRoutesServerFile);
266
- case 38:
267
- fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), _code, 'utf8');
268
- case 39:
269
- _context2.next = 41;
270
- return hookRunners.modifyEntryImports({
271
- entrypoint: entrypoint,
272
- imports: getDefaultImports({
273
- entrypoint: entrypoint,
274
- srcDirectory: srcDirectory,
275
- internalSrcAlias: internalSrcAlias,
276
- internalDirAlias: internalDirAlias,
277
- internalDirectory: internalDirectory
278
- })
279
- });
280
- case 41:
281
- _yield$hookRunners$mo2 = _context2.sent;
282
- importStatements = _yield$hookRunners$mo2.imports;
283
- _context2.next = 45;
284
- return hookRunners.modifyEntryRuntimePlugins({
285
- entrypoint: entrypoint,
286
- plugins: []
287
- });
288
- case 45:
289
- _yield$hookRunners$mo3 = _context2.sent;
290
- plugins = _yield$hookRunners$mo3.plugins;
291
- _context2.next = 49;
292
- return hookRunners.modifyEntryRenderFunction({
293
- entrypoint: entrypoint,
294
- code: templates.renderFunction({
295
- plugins: plugins,
296
- customBootstrap: customBootstrap,
297
- fileSystemRoutes: fileSystemRoutes
298
- })
299
- });
300
- case 49:
301
- _yield$hookRunners$mo4 = _context2.sent;
302
- renderFunction = _yield$hookRunners$mo4.code;
303
- _context2.next = 53;
304
- return hookRunners.modifyEntryExport({
305
- entrypoint: entrypoint,
306
- exportStatement: 'export default AppWrapper;'
307
- });
308
- case 53:
309
- _yield$hookRunners$mo5 = _context2.sent;
310
- exportStatement = _yield$hookRunners$mo5.exportStatement;
311
- code = templates.index({
312
- mountId: mountId,
313
- imports: createImportStatements(importStatements),
314
- renderFunction: renderFunction,
315
- exportStatement: exportStatement
316
- });
317
- entryFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
318
- entrypoint.entry = entryFile;
319
-
320
- // generate entry file.
321
- if (!config.source.enableAsyncEntry) {
322
- _context2.next = 68;
323
- break;
324
- }
325
- _context2.next = 61;
326
- return hookRunners.modifyAsyncEntry({
327
- entrypoint: entrypoint,
328
- code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
329
- });
330
- case 61:
331
- _yield$hookRunners$mo6 = _context2.sent;
332
- asyncEntryCode = _yield$hookRunners$mo6.code;
333
- fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
334
- bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
335
- fs.outputFileSync(bootstrapFile, code, 'utf8');
336
- _context2.next = 69;
337
- break;
338
- case 68:
339
- fs.outputFileSync(entryFile, code, 'utf8');
340
- case 69:
341
- case "end":
342
- return _context2.stop();
396
+ _state.label = 3;
397
+ case 3:
398
+ return [
399
+ 4,
400
+ hookRunners.modifyFileSystemRoutes({
401
+ entrypoint: entrypoint,
402
+ routes: initialRoutes
403
+ })
404
+ ];
405
+ case 4:
406
+ routes = _state.sent().routes;
407
+ config2 = useResolvedConfigContext();
408
+ ssr = getEntryOptions(entryName, config2.server.ssr, config2.server.ssrByEntries, packageName);
409
+ if (ssr) {
410
+ mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
411
+ } else {
412
+ mode = false;
413
+ }
414
+ if (mode === "stream") {
415
+ hasPageRoute = routes.some(function(route) {
416
+ return "type" in route && route.type === "page";
417
+ });
418
+ if (hasPageRoute) {
419
+ logger.error("Streaming ssr is not supported when pages dir exists");
420
+ process.exit(1);
421
+ }
422
+ }
423
+ _ = hookRunners.beforeGenerateRoutes;
424
+ _tmp = {
425
+ entrypoint: entrypoint
426
+ };
427
+ return [
428
+ 4,
429
+ templates.fileSystemRoutes({
430
+ routes: routes,
431
+ ssrMode: mode,
432
+ nestedRoutesEntry: entrypoint.nestedRoutesEntry,
433
+ entryName: entrypoint.entryName,
434
+ internalDirectory: internalDirectory,
435
+ internalDirAlias: internalDirAlias
436
+ })
437
+ ];
438
+ case 5:
439
+ return [
440
+ 4,
441
+ _.apply(hookRunners, [
442
+ (_tmp.code = _state.sent(), _tmp)
443
+ ])
444
+ ];
445
+ case 6:
446
+ ref = _state.sent(), code2 = ref.code;
447
+ if (!entrypoint.nestedRoutesEntry) return [
448
+ 3,
449
+ 14
450
+ ];
451
+ routesServerFile = path.join(internalDirectory, entryName, "route-server-loaders.js");
452
+ outputRoutesServerFile = path.join(distDirectory, LOADER_ROUTES_DIR, entryName, "index.js");
453
+ code3 = templates.routesForServer({
454
+ routes: routes,
455
+ internalDirectory: internalDirectory,
456
+ entryName: entryName
457
+ });
458
+ return [
459
+ 4,
460
+ fs.ensureFile(routesServerFile)
461
+ ];
462
+ case 7:
463
+ _state.sent();
464
+ return [
465
+ 4,
466
+ fs.writeFile(routesServerFile, code3)
467
+ ];
468
+ case 8:
469
+ _state.sent();
470
+ loaderEntryFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "entry.js");
471
+ loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "index.js");
472
+ return [
473
+ 4,
474
+ fs.pathExists(loaderEntryFile)
475
+ ];
476
+ case 9:
477
+ if (!_state.sent()) return [
478
+ 3,
479
+ 11
480
+ ];
481
+ return [
482
+ 4,
483
+ buildLoader(loaderEntryFile, loaderIndexFile)
484
+ ];
485
+ case 10:
486
+ _state.sent();
487
+ _state.label = 11;
488
+ case 11:
489
+ return [
490
+ 4,
491
+ fs.pathExists(routesServerFile)
492
+ ];
493
+ case 12:
494
+ if (!_state.sent()) return [
495
+ 3,
496
+ 14
497
+ ];
498
+ return [
499
+ 4,
500
+ buildServerLoader(routesServerFile, outputRoutesServerFile)
501
+ ];
502
+ case 13:
503
+ _state.sent();
504
+ _state.label = 14;
505
+ case 14:
506
+ fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
507
+ _state.label = 15;
508
+ case 15:
509
+ return [
510
+ 4,
511
+ hookRunners.modifyEntryImports({
512
+ entrypoint: entrypoint,
513
+ imports: getDefaultImports({
514
+ entrypoint: entrypoint,
515
+ srcDirectory: srcDirectory,
516
+ internalSrcAlias: internalSrcAlias,
517
+ internalDirAlias: internalDirAlias,
518
+ internalDirectory: internalDirectory
519
+ })
520
+ })
521
+ ];
522
+ case 16:
523
+ ref1 = _state.sent(), importStatements = ref1.imports;
524
+ return [
525
+ 4,
526
+ hookRunners.modifyEntryRuntimePlugins({
527
+ entrypoint: entrypoint,
528
+ plugins: []
529
+ })
530
+ ];
531
+ case 17:
532
+ plugins = _state.sent().plugins;
533
+ return [
534
+ 4,
535
+ hookRunners.modifyEntryRenderFunction({
536
+ entrypoint: entrypoint,
537
+ code: templates.renderFunction({
538
+ plugins: plugins,
539
+ customBootstrap: customBootstrap,
540
+ fileSystemRoutes: fileSystemRoutes
541
+ })
542
+ })
543
+ ];
544
+ case 18:
545
+ ref2 = _state.sent(), renderFunction = ref2.code;
546
+ return [
547
+ 4,
548
+ hookRunners.modifyEntryExport({
549
+ entrypoint: entrypoint,
550
+ exportStatement: "export default AppWrapper;"
551
+ })
552
+ ];
553
+ case 19:
554
+ exportStatement = _state.sent().exportStatement;
555
+ code = templates.index({
556
+ mountId: mountId,
557
+ imports: createImportStatements(importStatements),
558
+ renderFunction: renderFunction,
559
+ exportStatement: exportStatement
560
+ });
561
+ entryFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
562
+ entrypoint.entry = entryFile;
563
+ if (!config.source.enableAsyncEntry) return [
564
+ 3,
565
+ 21
566
+ ];
567
+ return [
568
+ 4,
569
+ hookRunners.modifyAsyncEntry({
570
+ entrypoint: entrypoint,
571
+ code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
572
+ })
573
+ ];
574
+ case 20:
575
+ ref3 = _state.sent(), asyncEntryCode = ref3.code;
576
+ fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
577
+ bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
578
+ fs.outputFileSync(bootstrapFile, code, "utf8");
579
+ return [
580
+ 3,
581
+ 22
582
+ ];
583
+ case 21:
584
+ fs.outputFileSync(entryFile, code, "utf8");
585
+ _state.label = 22;
586
+ case 22:
587
+ return [
588
+ 2
589
+ ];
343
590
  }
344
- }
345
- }, _callee2);
346
- }));
347
- return _generateEntryCode.apply(this, arguments);
348
- };
349
- generateEntryCode = function _generateEntryCode2(_x7) {
350
- return _generateEntryCode.apply(this, arguments);
351
- };
352
- internalDirectory = appContext.internalDirectory, distDirectory = appContext.distDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias;
353
- hookRunners = api.useHookRunners();
354
- 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);
355
- mountId = config.html.mountId;
356
- getRoutes = islegacy ? getClientRoutesLegacy : getClientRoutes;
357
- _context3.next = 9;
358
- return Promise.all(entrypoints.map(generateEntryCode));
359
- case 9:
360
- case "end":
361
- return _context3.stop();
591
+ });
592
+ });
593
+ return _generateEntryCode.apply(this, arguments);
362
594
  }
363
- }
364
- }, _callee3);
365
- }));
366
- return function generateCode(_x3, _x4, _x5, _x6) {
367
- return _ref3.apply(this, arguments);
368
- };
369
- }();
595
+ return __generator(this, function(_state) {
596
+ switch(_state.label){
597
+ case 0:
598
+ internalDirectory = appContext.internalDirectory, distDirectory = appContext.distDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
599
+ hookRunners = api.useHookRunners();
600
+ islegacy = Boolean(config === null || config === void 0 ? void 0 : (ref = config.runtime) === null || ref === void 0 ? void 0 : (ref1 = ref.router) === null || ref1 === void 0 ? void 0 : ref1.legacy);
601
+ mountId = config.html.mountId;
602
+ getRoutes = islegacy ? getClientRoutesLegacy : getClientRoutes;
603
+ return [
604
+ 4,
605
+ Promise.all(entrypoints.map(generateEntryCode))
606
+ ];
607
+ case 1:
608
+ _state.sent();
609
+ return [
610
+ 2
611
+ ];
612
+ }
613
+ });
614
+ });
615
+ return function generateCode(appContext, config, entrypoints, api) {
616
+ return _ref.apply(this, arguments);
617
+ };
618
+ }();
619
+ export { createImportStatements, generateCode };