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