@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,10 +1,228 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
- import * as path from 'path';
6
- import { createDebugger, fs, isApiOnly } from '@modern-js/utils';
7
- import { cloneDeep } from '@modern-js/utils/lodash';
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 _arrayWithHoles(arr) {
7
+ if (Array.isArray(arr)) return 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 _defineProperty(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
51
+ function _iterableToArrayLimit(arr, i) {
52
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
53
+ if (_i == null) return;
54
+ var _arr = [];
55
+ var _n = true;
56
+ var _d = false;
57
+ var _s, _e;
58
+ try {
59
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
60
+ _arr.push(_s.value);
61
+ if (i && _arr.length === i) break;
62
+ }
63
+ } catch (err) {
64
+ _d = true;
65
+ _e = err;
66
+ } finally{
67
+ try {
68
+ if (!_n && _i["return"] != null) _i["return"]();
69
+ } finally{
70
+ if (_d) throw _e;
71
+ }
72
+ }
73
+ return _arr;
74
+ }
75
+ function _nonIterableRest() {
76
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
+ }
78
+ function _objectSpread(target) {
79
+ for(var i = 1; i < arguments.length; i++){
80
+ var source = arguments[i] != null ? arguments[i] : {};
81
+ var ownKeys = Object.keys(source);
82
+ if (typeof Object.getOwnPropertySymbols === "function") {
83
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
84
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
85
+ }));
86
+ }
87
+ ownKeys.forEach(function(key) {
88
+ _defineProperty(target, key, source[key]);
89
+ });
90
+ }
91
+ return target;
92
+ }
93
+ function ownKeys(object, enumerableOnly) {
94
+ var keys = Object.keys(object);
95
+ if (Object.getOwnPropertySymbols) {
96
+ var symbols = Object.getOwnPropertySymbols(object);
97
+ if (enumerableOnly) {
98
+ symbols = symbols.filter(function(sym) {
99
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
100
+ });
101
+ }
102
+ keys.push.apply(keys, symbols);
103
+ }
104
+ return keys;
105
+ }
106
+ function _objectSpreadProps(target, source) {
107
+ source = source != null ? source : {};
108
+ if (Object.getOwnPropertyDescriptors) {
109
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
110
+ } else {
111
+ ownKeys(Object(source)).forEach(function(key) {
112
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
113
+ });
114
+ }
115
+ return target;
116
+ }
117
+ function _slicedToArray(arr, i) {
118
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
119
+ }
120
+ function _unsupportedIterableToArray(o, minLen) {
121
+ if (!o) return;
122
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
123
+ var n = Object.prototype.toString.call(o).slice(8, -1);
124
+ if (n === "Object" && o.constructor) n = o.constructor.name;
125
+ if (n === "Map" || n === "Set") return Array.from(n);
126
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
127
+ }
128
+ var __generator = this && this.__generator || function(thisArg, body) {
129
+ var f, y, t, g, _ = {
130
+ label: 0,
131
+ sent: function() {
132
+ if (t[0] & 1) throw t[1];
133
+ return t[1];
134
+ },
135
+ trys: [],
136
+ ops: []
137
+ };
138
+ return g = {
139
+ next: verb(0),
140
+ "throw": verb(1),
141
+ "return": verb(2)
142
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
143
+ return this;
144
+ }), g;
145
+ function verb(n) {
146
+ return function(v) {
147
+ return step([
148
+ n,
149
+ v
150
+ ]);
151
+ };
152
+ }
153
+ function step(op) {
154
+ if (f) throw new TypeError("Generator is already executing.");
155
+ while(_)try {
156
+ 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;
157
+ if (y = 0, t) op = [
158
+ op[0] & 2,
159
+ t.value
160
+ ];
161
+ switch(op[0]){
162
+ case 0:
163
+ case 1:
164
+ t = op;
165
+ break;
166
+ case 4:
167
+ _.label++;
168
+ return {
169
+ value: op[1],
170
+ done: false
171
+ };
172
+ case 5:
173
+ _.label++;
174
+ y = op[1];
175
+ op = [
176
+ 0
177
+ ];
178
+ continue;
179
+ case 7:
180
+ op = _.ops.pop();
181
+ _.trys.pop();
182
+ continue;
183
+ default:
184
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
185
+ _ = 0;
186
+ continue;
187
+ }
188
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
189
+ _.label = op[1];
190
+ break;
191
+ }
192
+ if (op[0] === 6 && _.label < t[1]) {
193
+ _.label = t[1];
194
+ t = op;
195
+ break;
196
+ }
197
+ if (t && _.label < t[2]) {
198
+ _.label = t[2];
199
+ _.ops.push(op);
200
+ break;
201
+ }
202
+ if (t[2]) _.ops.pop();
203
+ _.trys.pop();
204
+ continue;
205
+ }
206
+ op = body.call(thisArg, _);
207
+ } catch (e) {
208
+ op = [
209
+ 6,
210
+ e
211
+ ];
212
+ y = 0;
213
+ } finally{
214
+ f = t = 0;
215
+ }
216
+ if (op[0] & 5) throw op[1];
217
+ return {
218
+ value: op[0] ? op[1] : void 0,
219
+ done: true
220
+ };
221
+ }
222
+ };
223
+ import * as path from "path";
224
+ import { createDebugger, fs, isApiOnly } from "@modern-js/utils";
225
+ import { cloneDeep } from "@modern-js/utils/lodash";
8
226
  import { createBuilderForEdenX } from "../builder";
9
227
  import { printInstructions } from "../utils/printInstructions";
10
228
  import { generateRoutes } from "../utils/routes";
@@ -12,307 +230,344 @@ import { emitResolvedConfig } from "../utils/config";
12
230
  import { getCommand } from "../utils/commands";
13
231
  import { initialNormalizedConfig } from "../config";
14
232
  import { isRouteComponentFile } from "./utils";
15
- var debug = createDebugger('plugin-analyze');
16
- export default (function () {
17
- return {
18
- name: '@modern-js/plugin-analyze',
19
- setup: function setup(api) {
20
- var pagesDir = [];
21
- var originEntrypoints = [];
22
- return {
23
- prepare: function prepare() {
24
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
25
- var _resolvedConfig$sourc;
26
- var appContext, resolvedConfig, hookRunners, apiOnly, _yield$hookRunners$mo, _routes, _yield$Promise$all, _yield$Promise$all2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, defaultChecked, initialRoutes, _yield$hookRunners$mo2, routes, nestedRouteEntries, htmlTemplates, command, buildCommands, normalizedConfig, builder;
27
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
28
- while (1) {
29
- switch (_context6.prev = _context6.next) {
30
- case 0:
31
- appContext = api.useAppContext();
32
- resolvedConfig = api.useResolvedConfigContext();
33
- hookRunners = api.useHookRunners();
34
- try {
35
- fs.emptydirSync(appContext.internalDirectory);
36
- } catch (_unused) {
37
- // FIXME:
38
- }
39
- _context6.next = 6;
40
- return isApiOnly(appContext.appDirectory, (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
41
- case 6:
42
- apiOnly = _context6.sent;
43
- _context6.next = 9;
44
- return hookRunners.addRuntimeExports();
45
- case 9:
46
- if (!apiOnly) {
47
- _context6.next = 18;
48
- break;
49
- }
50
- _context6.next = 12;
51
- return hookRunners.modifyServerRoutes({
52
- routes: []
53
- });
54
- case 12:
55
- _yield$hookRunners$mo = _context6.sent;
56
- _routes = _yield$hookRunners$mo.routes;
57
- debug("server routes: %o", _routes);
58
- appContext = _objectSpread(_objectSpread({}, appContext), {}, {
59
- apiOnly: apiOnly,
60
- serverRoutes: _routes
61
- });
62
- api.setAppContext(appContext);
63
- return _context6.abrupt("return");
64
- case 18:
65
- _context6.next = 20;
66
- return Promise.all([import("./getBundleEntry"), import("./getServerRoutes"), import("./generateCode"), import("./getHtmlTemplate")]);
67
- case 20:
68
- _yield$Promise$all = _context6.sent;
69
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 4);
70
- getBundleEntry = _yield$Promise$all2[0].getBundleEntry;
71
- getServerRoutes = _yield$Promise$all2[1].getServerRoutes;
72
- generateCode = _yield$Promise$all2[2].generateCode;
73
- getHtmlTemplate = _yield$Promise$all2[3].getHtmlTemplate;
74
- entrypoints = getBundleEntry(appContext, resolvedConfig);
75
- defaultChecked = entrypoints.map(function (point) {
76
- return point.entryName;
77
- });
78
- debug("entrypoints: %o", entrypoints);
79
- initialRoutes = getServerRoutes(entrypoints, {
80
- appContext: appContext,
81
- config: resolvedConfig
82
- });
83
- _context6.next = 32;
84
- return hookRunners.modifyServerRoutes({
85
- routes: initialRoutes
86
- });
87
- case 32:
88
- _yield$hookRunners$mo2 = _context6.sent;
89
- routes = _yield$hookRunners$mo2.routes;
90
- debug("server routes: %o", routes);
91
- appContext = _objectSpread(_objectSpread({}, appContext), {}, {
92
- entrypoints: entrypoints,
93
- serverRoutes: routes
94
- });
95
- api.setAppContext(appContext);
96
- nestedRouteEntries = entrypoints.map(function (point) {
97
- return point.nestedRoutesEntry;
98
- }).filter(Boolean);
99
- pagesDir = entrypoints.map(function (point) {
100
- return point.entry;
101
- }).filter(Boolean).concat(nestedRouteEntries);
102
- originEntrypoints = cloneDeep(entrypoints);
103
- _context6.next = 42;
104
- return generateCode(appContext, resolvedConfig, entrypoints, api);
105
- case 42:
106
- _context6.next = 44;
107
- return getHtmlTemplate(entrypoints, api, {
108
- appContext: appContext,
109
- config: resolvedConfig
110
- });
111
- case 44:
112
- htmlTemplates = _context6.sent;
113
- debug("html templates: %o", htmlTemplates);
114
- _context6.next = 48;
115
- return hookRunners.addDefineTypes();
116
- case 48:
117
- debug("add Define Types");
118
- appContext = _objectSpread(_objectSpread({}, appContext), {}, {
119
- entrypoints: entrypoints,
120
- checkedEntries: defaultChecked,
121
- apiOnly: apiOnly,
122
- serverRoutes: routes,
123
- htmlTemplates: htmlTemplates
124
- });
125
- api.setAppContext(appContext);
126
- command = getCommand();
127
- buildCommands = ['dev', 'build', 'inspect', 'deploy'];
128
- if (!buildCommands.includes(command)) {
129
- _context6.next = 60;
130
- break;
131
- }
132
- normalizedConfig = api.useResolvedConfigContext();
133
- _context6.next = 57;
134
- return createBuilderForEdenX({
135
- normalizedConfig: normalizedConfig,
136
- appContext: appContext,
137
- compatPluginConfig: {
138
- onBeforeBuild: function onBeforeBuild(_ref) {
139
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
140
- var bundlerConfigs, hookRunners;
141
- return _regeneratorRuntime().wrap(function _callee$(_context) {
142
- while (1) {
143
- switch (_context.prev = _context.next) {
144
- case 0:
145
- bundlerConfigs = _ref.bundlerConfigs;
233
+ var debug = createDebugger("plugin-analyze");
234
+ var analyze_default = function() {
235
+ return {
236
+ name: "@modern-js/plugin-analyze",
237
+ setup: function(api) {
238
+ var pagesDir = [];
239
+ var originEntrypoints = [];
240
+ return {
241
+ prepare: function prepare() {
242
+ return _asyncToGenerator(function() {
243
+ var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, defaultChecked, initialRoutes, routes, nestedRouteEntries, htmlTemplates, command, buildCommands, normalizedConfig, builder;
244
+ return __generator(this, function(_state) {
245
+ switch(_state.label){
246
+ case 0:
247
+ appContext = api.useAppContext();
248
+ resolvedConfig = api.useResolvedConfigContext();
146
249
  hookRunners = api.useHookRunners();
147
- _context.next = 4;
148
- return generateRoutes(appContext);
149
- case 4:
150
- _context.next = 6;
151
- return hookRunners.beforeBuild({
152
- bundlerConfigs: bundlerConfigs
250
+ try {
251
+ fs.emptydirSync(appContext.internalDirectory);
252
+ } catch (e) {}
253
+ return [
254
+ 4,
255
+ isApiOnly(appContext.appDirectory, (ref = resolvedConfig.source) === null || ref === void 0 ? void 0 : ref.entriesDir)
256
+ ];
257
+ case 1:
258
+ apiOnly = _state.sent();
259
+ return [
260
+ 4,
261
+ hookRunners.addRuntimeExports()
262
+ ];
263
+ case 2:
264
+ _state.sent();
265
+ if (!apiOnly) return [
266
+ 3,
267
+ 4
268
+ ];
269
+ return [
270
+ 4,
271
+ hookRunners.modifyServerRoutes({
272
+ routes: []
273
+ })
274
+ ];
275
+ case 3:
276
+ ref1 = _state.sent(), routes2 = ref1.routes;
277
+ debug("server routes: %o", routes2);
278
+ appContext = _objectSpreadProps(_objectSpread({}, appContext), {
279
+ apiOnly: apiOnly,
280
+ serverRoutes: routes2
153
281
  });
154
- case 6:
155
- case "end":
156
- return _context.stop();
157
- }
158
- }
159
- }, _callee);
160
- }))();
161
- },
162
- onAfterBuild: function onAfterBuild(_ref2) {
163
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
164
- var stats, hookRunners;
165
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
166
- while (1) {
167
- switch (_context2.prev = _context2.next) {
168
- case 0:
169
- stats = _ref2.stats;
170
- hookRunners = api.useHookRunners();
171
- _context2.next = 4;
172
- return hookRunners.afterBuild({
173
- stats: stats
282
+ api.setAppContext(appContext);
283
+ return [
284
+ 2
285
+ ];
286
+ case 4:
287
+ return [
288
+ 4,
289
+ Promise.all([
290
+ import("./getBundleEntry"),
291
+ import("./getServerRoutes"),
292
+ import("./generateCode"),
293
+ import("./getHtmlTemplate")
294
+ ])
295
+ ];
296
+ case 5:
297
+ ref2 = _slicedToArray.apply(void 0, [
298
+ _state.sent(),
299
+ 4
300
+ ]), getBundleEntry = ref2[0].getBundleEntry, getServerRoutes = ref2[1].getServerRoutes, generateCode = ref2[2].generateCode, getHtmlTemplate = ref2[3].getHtmlTemplate;
301
+ entrypoints = getBundleEntry(appContext, resolvedConfig);
302
+ defaultChecked = entrypoints.map(function(point) {
303
+ return point.entryName;
174
304
  });
175
- case 4:
176
- _context2.next = 6;
177
- return emitResolvedConfig(appContext.appDirectory, normalizedConfig);
178
- case 6:
179
- case "end":
180
- return _context2.stop();
181
- }
182
- }
183
- }, _callee2);
184
- }))();
185
- },
186
- onDevCompileDone: function onDevCompileDone(_ref3) {
187
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
188
- var isFirstCompile, hookRunners;
189
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
190
- while (1) {
191
- switch (_context3.prev = _context3.next) {
192
- case 0:
193
- isFirstCompile = _ref3.isFirstCompile;
194
- hookRunners = api.useHookRunners();
195
- if (process.stdout.isTTY || isFirstCompile) {
196
- hookRunners.afterDev();
197
- if (isFirstCompile) {
198
- printInstructions(hookRunners, appContext, normalizedConfig);
199
- }
200
- }
201
- case 3:
202
- case "end":
203
- return _context3.stop();
204
- }
205
- }
206
- }, _callee3);
207
- }))();
208
- },
209
- onBeforeCreateCompiler: function onBeforeCreateCompiler(_ref4) {
210
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
211
- var bundlerConfigs, hookRunners;
212
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
213
- while (1) {
214
- switch (_context4.prev = _context4.next) {
215
- case 0:
216
- bundlerConfigs = _ref4.bundlerConfigs;
217
- hookRunners = api.useHookRunners(); // run modernjs framework `beforeCreateCompiler` hook
218
- _context4.next = 4;
219
- return hookRunners.beforeCreateCompiler({
220
- bundlerConfigs: bundlerConfigs
305
+ debug("entrypoints: %o", entrypoints);
306
+ initialRoutes = getServerRoutes(entrypoints, {
307
+ appContext: appContext,
308
+ config: resolvedConfig
221
309
  });
222
- case 4:
223
- case "end":
224
- return _context4.stop();
225
- }
226
- }
227
- }, _callee4);
228
- }))();
229
- },
230
- onAfterCreateCompiler: function onAfterCreateCompiler(_ref5) {
231
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
232
- var compiler, hookRunners;
233
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
234
- while (1) {
235
- switch (_context5.prev = _context5.next) {
236
- case 0:
237
- compiler = _ref5.compiler;
238
- hookRunners = api.useHookRunners(); // run modernjs framework afterCreateCompiler hooks
239
- _context5.next = 4;
240
- return hookRunners.afterCreateCompiler({
241
- compiler: compiler
310
+ return [
311
+ 4,
312
+ hookRunners.modifyServerRoutes({
313
+ routes: initialRoutes
314
+ })
315
+ ];
316
+ case 6:
317
+ routes = _state.sent().routes;
318
+ debug("server routes: %o", routes);
319
+ appContext = _objectSpreadProps(_objectSpread({}, appContext), {
320
+ entrypoints: entrypoints,
321
+ serverRoutes: routes
242
322
  });
243
- case 4:
244
- case "end":
245
- return _context5.stop();
246
- }
247
- }
248
- }, _callee5);
249
- }))();
250
- }
251
- }
252
- });
253
- case 57:
254
- builder = _context6.sent;
255
- appContext = _objectSpread(_objectSpread({}, appContext), {}, {
256
- builder: builder
257
- });
258
- api.setAppContext(appContext);
259
- case 60:
260
- case "end":
261
- return _context6.stop();
262
- }
263
- }
264
- }, _callee6);
265
- }))();
266
- },
267
- watchFiles: function watchFiles() {
268
- return pagesDir;
269
- },
270
- resolvedConfig: function resolvedConfig(_ref6) {
271
- var resolved = _ref6.resolved;
272
- var appContext = api.useAppContext();
273
- var config = initialNormalizedConfig(resolved, appContext);
274
- return {
275
- resolved: config
276
- };
277
- },
278
- fileChange: function fileChange(e) {
279
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
280
- var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, _yield$import, generateCode, entrypoints;
281
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
282
- while (1) {
283
- switch (_context7.prev = _context7.next) {
284
- case 0:
285
- appContext = api.useAppContext();
286
- appDirectory = appContext.appDirectory;
287
- filename = e.filename, eventType = e.eventType;
288
- isPageFile = function isPageFile(name) {
289
- return pagesDir.some(function (pageDir) {
290
- return name.includes(pageDir);
291
- });
323
+ api.setAppContext(appContext);
324
+ nestedRouteEntries = entrypoints.map(function(point) {
325
+ return point.nestedRoutesEntry;
326
+ }).filter(Boolean);
327
+ pagesDir = entrypoints.map(function(point) {
328
+ return point.entry;
329
+ }).filter(Boolean).concat(nestedRouteEntries);
330
+ originEntrypoints = cloneDeep(entrypoints);
331
+ return [
332
+ 4,
333
+ generateCode(appContext, resolvedConfig, entrypoints, api)
334
+ ];
335
+ case 7:
336
+ _state.sent();
337
+ return [
338
+ 4,
339
+ getHtmlTemplate(entrypoints, api, {
340
+ appContext: appContext,
341
+ config: resolvedConfig
342
+ })
343
+ ];
344
+ case 8:
345
+ htmlTemplates = _state.sent();
346
+ debug("html templates: %o", htmlTemplates);
347
+ return [
348
+ 4,
349
+ hookRunners.addDefineTypes()
350
+ ];
351
+ case 9:
352
+ _state.sent();
353
+ debug("add Define Types");
354
+ appContext = _objectSpreadProps(_objectSpread({}, appContext), {
355
+ entrypoints: entrypoints,
356
+ checkedEntries: defaultChecked,
357
+ apiOnly: apiOnly,
358
+ serverRoutes: routes,
359
+ htmlTemplates: htmlTemplates
360
+ });
361
+ api.setAppContext(appContext);
362
+ command = getCommand();
363
+ buildCommands = [
364
+ "dev",
365
+ "build",
366
+ "inspect",
367
+ "deploy"
368
+ ];
369
+ if (!buildCommands.includes(command)) return [
370
+ 3,
371
+ 11
372
+ ];
373
+ normalizedConfig = api.useResolvedConfigContext();
374
+ return [
375
+ 4,
376
+ createBuilderForEdenX({
377
+ normalizedConfig: normalizedConfig,
378
+ appContext: appContext,
379
+ compatPluginConfig: {
380
+ onBeforeBuild: function onBeforeBuild(param) {
381
+ var bundlerConfigs = param.bundlerConfigs;
382
+ return _asyncToGenerator(function() {
383
+ var hookRunners2;
384
+ return __generator(this, function(_state) {
385
+ switch(_state.label){
386
+ case 0:
387
+ hookRunners2 = api.useHookRunners();
388
+ return [
389
+ 4,
390
+ generateRoutes(appContext)
391
+ ];
392
+ case 1:
393
+ _state.sent();
394
+ return [
395
+ 4,
396
+ hookRunners2.beforeBuild({
397
+ bundlerConfigs: bundlerConfigs
398
+ })
399
+ ];
400
+ case 2:
401
+ _state.sent();
402
+ return [
403
+ 2
404
+ ];
405
+ }
406
+ });
407
+ })();
408
+ },
409
+ onAfterBuild: function onAfterBuild(param) {
410
+ var stats = param.stats;
411
+ return _asyncToGenerator(function() {
412
+ var hookRunners2;
413
+ return __generator(this, function(_state) {
414
+ switch(_state.label){
415
+ case 0:
416
+ hookRunners2 = api.useHookRunners();
417
+ return [
418
+ 4,
419
+ hookRunners2.afterBuild({
420
+ stats: stats
421
+ })
422
+ ];
423
+ case 1:
424
+ _state.sent();
425
+ return [
426
+ 4,
427
+ emitResolvedConfig(appContext.appDirectory, normalizedConfig)
428
+ ];
429
+ case 2:
430
+ _state.sent();
431
+ return [
432
+ 2
433
+ ];
434
+ }
435
+ });
436
+ })();
437
+ },
438
+ onDevCompileDone: function onDevCompileDone(param) {
439
+ var isFirstCompile = param.isFirstCompile;
440
+ return _asyncToGenerator(function() {
441
+ var hookRunners2;
442
+ return __generator(this, function(_state) {
443
+ hookRunners2 = api.useHookRunners();
444
+ if (process.stdout.isTTY || isFirstCompile) {
445
+ hookRunners2.afterDev();
446
+ if (isFirstCompile) {
447
+ printInstructions(hookRunners2, appContext, normalizedConfig);
448
+ }
449
+ }
450
+ return [
451
+ 2
452
+ ];
453
+ });
454
+ })();
455
+ },
456
+ onBeforeCreateCompiler: function onBeforeCreateCompiler(param) {
457
+ var bundlerConfigs = param.bundlerConfigs;
458
+ return _asyncToGenerator(function() {
459
+ var hookRunners2;
460
+ return __generator(this, function(_state) {
461
+ switch(_state.label){
462
+ case 0:
463
+ hookRunners2 = api.useHookRunners();
464
+ return [
465
+ 4,
466
+ hookRunners2.beforeCreateCompiler({
467
+ bundlerConfigs: bundlerConfigs
468
+ })
469
+ ];
470
+ case 1:
471
+ _state.sent();
472
+ return [
473
+ 2
474
+ ];
475
+ }
476
+ });
477
+ })();
478
+ },
479
+ onAfterCreateCompiler: function onAfterCreateCompiler(param) {
480
+ var compiler = param.compiler;
481
+ return _asyncToGenerator(function() {
482
+ var hookRunners2;
483
+ return __generator(this, function(_state) {
484
+ switch(_state.label){
485
+ case 0:
486
+ hookRunners2 = api.useHookRunners();
487
+ return [
488
+ 4,
489
+ hookRunners2.afterCreateCompiler({
490
+ compiler: compiler
491
+ })
492
+ ];
493
+ case 1:
494
+ _state.sent();
495
+ return [
496
+ 2
497
+ ];
498
+ }
499
+ });
500
+ })();
501
+ }
502
+ }
503
+ })
504
+ ];
505
+ case 10:
506
+ builder = _state.sent();
507
+ appContext = _objectSpreadProps(_objectSpread({}, appContext), {
508
+ builder: builder
509
+ });
510
+ api.setAppContext(appContext);
511
+ _state.label = 11;
512
+ case 11:
513
+ return [
514
+ 2
515
+ ];
516
+ }
517
+ });
518
+ })();
519
+ },
520
+ watchFiles: function watchFiles() {
521
+ return pagesDir;
522
+ },
523
+ resolvedConfig: function resolvedConfig(param) {
524
+ var resolved = param.resolved;
525
+ var appContext = api.useAppContext();
526
+ var config = initialNormalizedConfig(resolved, appContext);
527
+ return {
528
+ resolved: config
292
529
  };
293
- absoluteFilePath = path.resolve(appDirectory, filename);
294
- isRouteComponent = isPageFile(absoluteFilePath) && isRouteComponentFile(absoluteFilePath);
295
- if (!(isRouteComponent && (eventType === 'add' || eventType === 'unlink'))) {
296
- _context7.next = 14;
297
- break;
298
- }
299
- resolvedConfig = api.useResolvedConfigContext();
300
- _context7.next = 10;
301
- return import("./generateCode");
302
- case 10:
303
- _yield$import = _context7.sent;
304
- generateCode = _yield$import.generateCode;
305
- entrypoints = cloneDeep(originEntrypoints);
306
- generateCode(appContext, resolvedConfig, entrypoints, api);
307
- case 14:
308
- case "end":
309
- return _context7.stop();
530
+ },
531
+ fileChange: function fileChange(e) {
532
+ return _asyncToGenerator(function() {
533
+ var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
534
+ return __generator(this, function(_state) {
535
+ switch(_state.label){
536
+ case 0:
537
+ appContext = api.useAppContext();
538
+ appDirectory = appContext.appDirectory;
539
+ filename = e.filename, eventType = e.eventType;
540
+ isPageFile = function(name) {
541
+ return pagesDir.some(function(pageDir) {
542
+ return name.includes(pageDir);
543
+ });
544
+ };
545
+ absoluteFilePath = path.resolve(appDirectory, filename);
546
+ isRouteComponent = isPageFile(absoluteFilePath) && isRouteComponentFile(absoluteFilePath);
547
+ if (!(isRouteComponent && (eventType === "add" || eventType === "unlink"))) return [
548
+ 3,
549
+ 2
550
+ ];
551
+ resolvedConfig = api.useResolvedConfigContext();
552
+ return [
553
+ 4,
554
+ import("./generateCode")
555
+ ];
556
+ case 1:
557
+ generateCode = _state.sent().generateCode;
558
+ entrypoints = cloneDeep(originEntrypoints);
559
+ generateCode(appContext, resolvedConfig, entrypoints, api);
560
+ _state.label = 2;
561
+ case 2:
562
+ return [
563
+ 2
564
+ ];
565
+ }
566
+ });
567
+ })();
310
568
  }
311
- }
312
- }, _callee7);
313
- }))();
569
+ };
314
570
  }
315
- };
316
- }
317
- };
318
- });
571
+ };
572
+ };
573
+ export { analyze_default as default };