@modern-js/app-tools 2.0.0-beta.2 → 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 (231) hide show
  1. package/CHANGELOG.md +251 -0
  2. package/bin/modern.js +10 -1
  3. package/dist/js/modern/analyze/constants.js +38 -16
  4. package/dist/js/modern/analyze/generateCode.js +271 -211
  5. package/dist/js/modern/analyze/getBundleEntry.js +31 -32
  6. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +93 -49
  7. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +89 -47
  8. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -2
  9. package/dist/js/modern/analyze/getClientRoutes/utils.js +23 -10
  10. package/dist/js/modern/analyze/getFileSystemEntry.js +43 -22
  11. package/dist/js/modern/analyze/getHtmlTemplate.js +89 -49
  12. package/dist/js/modern/analyze/getServerRoutes.js +122 -126
  13. package/dist/js/modern/analyze/index.js +193 -159
  14. package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -16
  15. package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -11
  16. package/dist/js/modern/analyze/nestedRoutes.js +110 -53
  17. package/dist/js/modern/analyze/templates.js +190 -77
  18. package/dist/js/modern/analyze/utils.js +98 -51
  19. package/dist/js/modern/builder/builderPlugins/compatModern.js +124 -107
  20. package/dist/js/modern/builder/index.js +123 -86
  21. package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
  22. package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
  23. package/dist/js/modern/builder/share.js +22 -20
  24. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +23 -22
  25. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +31 -27
  26. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +98 -84
  27. package/dist/js/modern/commands/build.js +67 -42
  28. package/dist/js/modern/commands/deploy.js +27 -4
  29. package/dist/js/modern/commands/dev.js +93 -47
  30. package/dist/js/modern/commands/index.js +1 -1
  31. package/dist/js/modern/commands/inspect.js +30 -5
  32. package/dist/js/modern/commands/start.js +37 -16
  33. package/dist/js/modern/config/default.js +103 -114
  34. package/dist/js/modern/config/index.js +8 -2
  35. package/dist/js/modern/config/initial/createHtmlConfig.js +5 -2
  36. package/dist/js/modern/config/initial/createOutputConfig.js +11 -9
  37. package/dist/js/modern/config/initial/createSourceConfig.js +5 -2
  38. package/dist/js/modern/config/initial/createToolsConfig.js +7 -6
  39. package/dist/js/modern/config/initial/index.js +9 -4
  40. package/dist/js/modern/config/initial/inits.js +109 -73
  41. package/dist/js/modern/config/initial/transformNormalizedConfig.js +6 -3
  42. package/dist/js/modern/defineConfig.js +26 -11
  43. package/dist/js/modern/exports/server.js +4 -1
  44. package/dist/js/modern/hooks.js +10 -3
  45. package/dist/js/modern/index.js +140 -89
  46. package/dist/js/modern/initialize/index.js +98 -51
  47. package/dist/js/modern/locale/en.js +20 -21
  48. package/dist/js/modern/locale/index.js +6 -6
  49. package/dist/js/modern/locale/zh.js +21 -22
  50. package/dist/js/modern/schema/Schema.js +6 -5
  51. package/dist/js/modern/schema/index.js +51 -100
  52. package/dist/js/modern/schema/legacy.js +96 -231
  53. package/dist/js/modern/types/config/index.js +0 -1
  54. package/dist/js/modern/types/index.js +0 -1
  55. package/dist/js/modern/types/legacyConfig/output.js +0 -1
  56. package/dist/js/modern/utils/commands.js +5 -2
  57. package/dist/js/modern/utils/config.js +102 -41
  58. package/dist/js/modern/utils/createFileWatcher.js +84 -51
  59. package/dist/js/modern/utils/createServer.js +63 -17
  60. package/dist/js/modern/utils/getSpecifiedEntries.js +46 -19
  61. package/dist/js/modern/utils/language.js +6 -3
  62. package/dist/js/modern/utils/printInstructions.js +27 -8
  63. package/dist/js/modern/utils/restart.js +43 -16
  64. package/dist/js/modern/utils/routes.js +29 -12
  65. package/dist/js/node/analyze/constants.js +54 -35
  66. package/dist/js/node/analyze/generateCode.js +290 -228
  67. package/dist/js/node/analyze/getBundleEntry.js +55 -44
  68. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +132 -76
  69. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +128 -74
  70. package/dist/js/node/analyze/getClientRoutes/index.js +23 -17
  71. package/dist/js/node/analyze/getClientRoutes/utils.js +44 -21
  72. package/dist/js/node/analyze/getFileSystemEntry.js +70 -39
  73. package/dist/js/node/analyze/getHtmlTemplate.js +116 -61
  74. package/dist/js/node/analyze/getServerRoutes.js +143 -137
  75. package/dist/js/node/analyze/index.js +240 -174
  76. package/dist/js/node/analyze/isDefaultExportFunction.js +55 -26
  77. package/dist/js/node/analyze/makeLegalIdentifier.js +27 -15
  78. package/dist/js/node/analyze/nestedRoutes.js +140 -67
  79. package/dist/js/node/analyze/templates.js +211 -84
  80. package/dist/js/node/analyze/utils.js +123 -62
  81. package/dist/js/node/builder/builderPlugins/compatModern.js +152 -120
  82. package/dist/js/node/builder/index.js +151 -95
  83. package/dist/js/node/builder/loaders/routerLoader.js +36 -0
  84. package/dist/js/node/builder/loaders/serverModuleLoader.js +26 -0
  85. package/dist/js/node/builder/share.js +45 -25
  86. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +39 -26
  87. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +47 -31
  88. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +116 -90
  89. package/dist/js/node/commands/build.js +89 -52
  90. package/dist/js/node/commands/deploy.js +45 -10
  91. package/dist/js/node/commands/dev.js +115 -61
  92. package/dist/js/node/commands/index.js +19 -38
  93. package/dist/js/node/commands/inspect.js +48 -11
  94. package/dist/js/node/commands/start.js +65 -27
  95. package/dist/js/node/config/default.js +119 -118
  96. package/dist/js/node/config/index.js +25 -29
  97. package/dist/js/node/config/initial/createHtmlConfig.js +22 -6
  98. package/dist/js/node/config/initial/createOutputConfig.js +28 -13
  99. package/dist/js/node/config/initial/createSourceConfig.js +22 -6
  100. package/dist/js/node/config/initial/createToolsConfig.js +24 -10
  101. package/dist/js/node/config/initial/index.js +28 -17
  102. package/dist/js/node/config/initial/inits.js +126 -81
  103. package/dist/js/node/config/initial/transformNormalizedConfig.js +31 -15
  104. package/dist/js/node/defineConfig.js +43 -17
  105. package/dist/js/node/exports/server.js +21 -10
  106. package/dist/js/node/hooks.js +44 -29
  107. package/dist/js/node/index.js +190 -130
  108. package/dist/js/node/initialize/index.js +116 -61
  109. package/dist/js/node/locale/en.js +36 -25
  110. package/dist/js/node/locale/index.js +27 -15
  111. package/dist/js/node/locale/zh.js +37 -26
  112. package/dist/js/node/schema/Schema.js +23 -10
  113. package/dist/js/node/schema/index.js +77 -114
  114. package/dist/js/node/schema/legacy.js +117 -240
  115. package/dist/js/node/types/config/index.js +17 -16
  116. package/dist/js/node/types/index.js +19 -38
  117. package/dist/js/node/types/legacyConfig/output.js +0 -5
  118. package/dist/js/node/utils/commands.js +21 -6
  119. package/dist/js/node/utils/config.js +120 -51
  120. package/dist/js/node/utils/createFileWatcher.js +104 -60
  121. package/dist/js/node/utils/createServer.js +86 -25
  122. package/dist/js/node/utils/getSpecifiedEntries.js +64 -25
  123. package/dist/js/node/utils/language.js +24 -8
  124. package/dist/js/node/utils/printInstructions.js +47 -16
  125. package/dist/js/node/utils/restart.js +61 -21
  126. package/dist/js/node/utils/routes.js +53 -18
  127. package/dist/js/treeshaking/analyze/constants.js +28 -16
  128. package/dist/js/treeshaking/analyze/generateCode.js +604 -355
  129. package/dist/js/treeshaking/analyze/getBundleEntry.js +52 -63
  130. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +214 -168
  131. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +215 -169
  132. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -2
  133. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +19 -20
  134. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +89 -86
  135. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +298 -125
  136. package/dist/js/treeshaking/analyze/getServerRoutes.js +210 -146
  137. package/dist/js/treeshaking/analyze/index.js +558 -303
  138. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +45 -26
  139. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -16
  140. package/dist/js/treeshaking/analyze/nestedRoutes.js +414 -160
  141. package/dist/js/treeshaking/analyze/templates.js +432 -161
  142. package/dist/js/treeshaking/analyze/utils.js +361 -80
  143. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +281 -195
  144. package/dist/js/treeshaking/builder/index.js +371 -165
  145. package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
  146. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
  147. package/dist/js/treeshaking/builder/share.js +41 -44
  148. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +108 -44
  149. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +70 -39
  150. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +332 -112
  151. package/dist/js/treeshaking/commands/build.js +286 -88
  152. package/dist/js/treeshaking/commands/deploy.js +153 -25
  153. package/dist/js/treeshaking/commands/dev.js +318 -132
  154. package/dist/js/treeshaking/commands/index.js +1 -1
  155. package/dist/js/treeshaking/commands/inspect.js +147 -32
  156. package/dist/js/treeshaking/commands/start.js +190 -68
  157. package/dist/js/treeshaking/config/default.js +210 -199
  158. package/dist/js/treeshaking/config/index.js +3 -2
  159. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -31
  160. package/dist/js/treeshaking/config/initial/createOutputConfig.js +43 -67
  161. package/dist/js/treeshaking/config/initial/createSourceConfig.js +37 -40
  162. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -38
  163. package/dist/js/treeshaking/config/initial/index.js +10 -9
  164. package/dist/js/treeshaking/config/initial/inits.js +205 -106
  165. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +27 -34
  166. package/dist/js/treeshaking/defineConfig.js +60 -13
  167. package/dist/js/treeshaking/exports/server.js +2 -1
  168. package/dist/js/treeshaking/hooks.js +26 -25
  169. package/dist/js/treeshaking/index.js +465 -257
  170. package/dist/js/treeshaking/initialize/index.js +290 -112
  171. package/dist/js/treeshaking/locale/en.js +34 -33
  172. package/dist/js/treeshaking/locale/index.js +5 -5
  173. package/dist/js/treeshaking/locale/zh.js +34 -33
  174. package/dist/js/treeshaking/schema/Schema.js +267 -69
  175. package/dist/js/treeshaking/schema/index.js +165 -121
  176. package/dist/js/treeshaking/schema/legacy.js +323 -256
  177. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  178. package/dist/js/treeshaking/types/config/dev.js +1 -0
  179. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  180. package/dist/js/treeshaking/types/config/html.js +1 -0
  181. package/dist/js/treeshaking/types/config/index.js +0 -1
  182. package/dist/js/treeshaking/types/config/output.js +1 -0
  183. package/dist/js/treeshaking/types/config/performance.js +1 -0
  184. package/dist/js/treeshaking/types/config/security.js +1 -0
  185. package/dist/js/treeshaking/types/config/source.js +1 -0
  186. package/dist/js/treeshaking/types/config/tools.js +1 -0
  187. package/dist/js/treeshaking/types/hooks.js +1 -0
  188. package/dist/js/treeshaking/types/index.js +0 -1
  189. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  190. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  191. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  192. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -1
  193. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  194. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  195. package/dist/js/treeshaking/utils/commands.js +6 -5
  196. package/dist/js/treeshaking/utils/config.js +295 -117
  197. package/dist/js/treeshaking/utils/createFileWatcher.js +278 -118
  198. package/dist/js/treeshaking/utils/createServer.js +252 -67
  199. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +182 -55
  200. package/dist/js/treeshaking/utils/language.js +6 -5
  201. package/dist/js/treeshaking/utils/printInstructions.js +151 -29
  202. package/dist/js/treeshaking/utils/restart.js +184 -42
  203. package/dist/js/treeshaking/utils/routes.js +151 -27
  204. package/dist/js/treeshaking/utils/types.js +1 -0
  205. package/dist/types/analyze/constants.d.ts +2 -0
  206. package/dist/types/analyze/index.d.ts +2 -0
  207. package/dist/types/analyze/templates.d.ts +8 -7
  208. package/dist/types/analyze/utils.d.ts +9 -1
  209. package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -1
  210. package/dist/types/builder/index.d.ts +2 -2
  211. package/dist/types/builder/loaders/routerLoader.d.ts +3 -0
  212. package/dist/types/builder/loaders/serverModuleLoader.d.ts +3 -0
  213. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +1 -7
  214. package/dist/types/defineConfig.d.ts +1 -0
  215. package/dist/types/index.d.ts +2 -0
  216. package/dist/types/initialize/index.d.ts +2 -0
  217. package/dist/types/types/config/index.d.ts +1 -0
  218. package/dist/types/types/config/output.d.ts +0 -1
  219. package/dist/types/types/config/source.d.ts +1 -0
  220. package/dist/types/types/config/tools.d.ts +10 -1
  221. package/dist/types/types/hooks.d.ts +2 -1
  222. package/dist/types/types/legacyConfig/dev.d.ts +1 -0
  223. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  224. package/dist/types/types/legacyConfig/source.d.ts +1 -0
  225. package/dist/types/types/legacyConfig/tools.d.ts +1 -0
  226. package/dist/types/utils/config.d.ts +1 -0
  227. package/dist/types/utils/createFileWatcher.d.ts +2 -1
  228. package/dist/types/utils/createServer.d.ts +1 -0
  229. package/dist/types/utils/restart.d.ts +1 -1
  230. package/lib/types.d.ts +1 -1
  231. package/package.json +27 -23
@@ -1,30 +1,152 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import { prettyInstructions, logger } from '@modern-js/utils';
4
- export var printInstructions = /*#__PURE__*/function () {
5
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(hookRunners, appContext, config) {
6
- var message, _yield$hookRunners$be, instructions;
7
- return _regeneratorRuntime().wrap(function _callee$(_context) {
8
- while (1) {
9
- switch (_context.prev = _context.next) {
10
- case 0:
11
- message = prettyInstructions(appContext, config); // call beforePrintInstructions hook.
12
- _context.next = 3;
13
- return hookRunners.beforePrintInstructions({
14
- instructions: message
15
- });
16
- case 3:
17
- _yield$hookRunners$be = _context.sent;
18
- instructions = _yield$hookRunners$be.instructions;
19
- logger.info(instructions);
20
- case 6:
21
- case "end":
22
- return _context.stop();
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return(g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g);
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ 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;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
23
117
  }
24
- }
25
- }, _callee);
26
- }));
27
- return function printInstructions(_x, _x2, _x3) {
28
- return _ref.apply(this, arguments);
29
- };
30
- }();
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ import { prettyInstructions, logger } from "@modern-js/utils";
126
+ var printInstructions = function() {
127
+ var _ref = _asyncToGenerator(function(hookRunners, appContext, config) {
128
+ var message, instructions;
129
+ return __generator(this, function(_state) {
130
+ switch(_state.label){
131
+ case 0:
132
+ message = prettyInstructions(appContext, config);
133
+ return [
134
+ 4,
135
+ hookRunners.beforePrintInstructions({
136
+ instructions: message
137
+ })
138
+ ];
139
+ case 1:
140
+ instructions = _state.sent().instructions;
141
+ logger.info(instructions);
142
+ return [
143
+ 2
144
+ ];
145
+ }
146
+ });
147
+ });
148
+ return function printInstructions(hookRunners, appContext, config) {
149
+ return _ref.apply(this, arguments);
150
+ };
151
+ }();
152
+ export { printInstructions };
@@ -1,45 +1,187 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import { cli } from '@modern-js/core';
4
- import { logger, program } from '@modern-js/utils';
5
- export function restart(_x) {
6
- return _restart.apply(this, arguments);
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
7
14
  }
8
- function _restart() {
9
- _restart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(hooksRunner) {
10
- var hasGetError;
11
- return _regeneratorRuntime().wrap(function _callee$(_context) {
12
- while (1) {
13
- switch (_context.prev = _context.next) {
14
- case 0:
15
- logger.info('Restart...\n');
16
- hasGetError = false;
17
- _context.next = 4;
18
- return hooksRunner.beforeRestart();
19
- case 4:
20
- _context.prev = 4;
21
- _context.next = 7;
22
- return cli.init(cli.initOptions);
23
- case 7:
24
- _context.next = 13;
25
- break;
26
- case 9:
27
- _context.prev = 9;
28
- _context.t0 = _context["catch"](4);
29
- console.error(_context.t0);
30
- hasGetError = true;
31
- case 13:
32
- _context.prev = 13;
33
- if (!hasGetError) {
34
- program.parse(process.argv);
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ 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;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
35
107
  }
36
- return _context.finish(13);
37
- case 16:
38
- case "end":
39
- return _context.stop();
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
40
117
  }
41
- }
42
- }, _callee, null, [[4, 9, 13, 16]]);
43
- }));
44
- return _restart.apply(this, arguments);
45
- }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ import { cli } from "@modern-js/core";
126
+ import { chalk, clearConsole, logger, program } from "@modern-js/utils";
127
+ function restart(hooksRunner, filename) {
128
+ return _restart.apply(this, arguments);
129
+ }
130
+ function _restart() {
131
+ _restart = _asyncToGenerator(function(hooksRunner, filename) {
132
+ var hasGetError, err;
133
+ return __generator(this, function(_state) {
134
+ switch(_state.label){
135
+ case 0:
136
+ clearConsole();
137
+ logger.info("Restart because ".concat(chalk.yellow(filename), " is changed...\n"));
138
+ hasGetError = false;
139
+ return [
140
+ 4,
141
+ hooksRunner.beforeRestart()
142
+ ];
143
+ case 1:
144
+ _state.sent();
145
+ _state.label = 2;
146
+ case 2:
147
+ _state.trys.push([
148
+ 2,
149
+ 4,
150
+ 5,
151
+ 6
152
+ ]);
153
+ return [
154
+ 4,
155
+ cli.init(cli.getPrevInitOptions())
156
+ ];
157
+ case 3:
158
+ _state.sent();
159
+ return [
160
+ 3,
161
+ 6
162
+ ];
163
+ case 4:
164
+ err = _state.sent();
165
+ console.error(err);
166
+ hasGetError = true;
167
+ return [
168
+ 3,
169
+ 6
170
+ ];
171
+ case 5:
172
+ if (!hasGetError) {
173
+ program.parse(process.argv);
174
+ }
175
+ return [
176
+ 7
177
+ ];
178
+ case 6:
179
+ return [
180
+ 2
181
+ ];
182
+ }
183
+ });
184
+ });
185
+ return _restart.apply(this, arguments);
186
+ }
187
+ export { restart };
@@ -1,29 +1,153 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import path from 'path';
4
- import { fs, ROUTE_SPEC_FILE } from '@modern-js/utils';
5
- var generateRoutes = /*#__PURE__*/function () {
6
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(appContext) {
7
- var serverRoutes, distDirectory, output;
8
- return _regeneratorRuntime().wrap(function _callee$(_context) {
9
- while (1) {
10
- switch (_context.prev = _context.next) {
11
- case 0:
12
- serverRoutes = appContext.serverRoutes, distDirectory = appContext.distDirectory;
13
- output = JSON.stringify({
14
- routes: serverRoutes
15
- }, null, 2);
16
- _context.next = 4;
17
- return fs.outputFile(path.join(distDirectory, ROUTE_SPEC_FILE), output);
18
- case 4:
19
- case "end":
20
- return _context.stop();
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return(g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g);
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ 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;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
21
117
  }
22
- }
23
- }, _callee);
24
- }));
25
- return function generateRoutes(_x) {
26
- return _ref.apply(this, arguments);
27
- };
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ import path from "path";
126
+ import { fs, ROUTE_SPEC_FILE } from "@modern-js/utils";
127
+ var generateRoutes = function() {
128
+ var _ref = _asyncToGenerator(function(appContext) {
129
+ var serverRoutes, distDirectory, output;
130
+ return __generator(this, function(_state) {
131
+ switch(_state.label){
132
+ case 0:
133
+ serverRoutes = appContext.serverRoutes, distDirectory = appContext.distDirectory;
134
+ output = JSON.stringify({
135
+ routes: serverRoutes
136
+ }, null, 2);
137
+ return [
138
+ 4,
139
+ fs.outputFile(path.join(distDirectory, ROUTE_SPEC_FILE), output)
140
+ ];
141
+ case 1:
142
+ _state.sent();
143
+ return [
144
+ 2
145
+ ];
146
+ }
147
+ });
148
+ });
149
+ return function generateRoutes(appContext) {
150
+ return _ref.apply(this, arguments);
151
+ };
28
152
  }();
29
- export { generateRoutes };
153
+ export { generateRoutes };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -4,6 +4,8 @@ export declare const APP_FILE_NAME = "App";
4
4
  export declare const PAGES_DIR_NAME = "pages";
5
5
  export declare const NESTED_ROUTES_DIR = "routes";
6
6
  export declare const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
7
+ export declare const LOADER_EXPORT_NAME = "loader";
8
+ export declare const TEMP_LOADERS_DIR = "__loaders__";
7
9
  export declare const ENTRY_POINT_FILE_NAME = "index.js";
8
10
  export declare const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.js";
9
11
  export declare const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP: RegExp;
@@ -1,4 +1,6 @@
1
1
  import type { CliPlugin } from '@modern-js/core';
2
2
  import { AppTools } from '../types';
3
+
3
4
  declare const _default: () => CliPlugin<AppTools>;
5
+
4
6
  export default _default;
@@ -27,22 +27,23 @@ export declare const html: (partials: {
27
27
  }) => string;
28
28
  export declare const routesForServer: ({
29
29
  routes,
30
- alias
30
+ internalDirectory,
31
+ entryName
31
32
  }: {
32
33
  routes: (NestedRoute | PageRoute)[];
33
- alias: {
34
- name: string;
35
- basename: string;
36
- };
34
+ internalDirectory: string;
35
+ entryName: string;
37
36
  }) => string;
38
37
  export declare const fileSystemRoutes: ({
39
38
  routes,
40
39
  ssrMode,
41
40
  nestedRoutesEntry,
42
- entryName
41
+ entryName,
42
+ internalDirectory
43
43
  }: {
44
44
  routes: RouteLegacy[] | (NestedRoute | PageRoute)[];
45
45
  ssrMode: 'string' | 'stream' | false;
46
46
  nestedRoutesEntry?: string | undefined;
47
47
  entryName: string;
48
- }) => string;
48
+ internalDirectory: string;
49
+ }) => Promise<string>;
@@ -15,4 +15,12 @@ export declare const getDefaultImports: ({
15
15
  internalDirectory: string;
16
16
  }) => ImportStatement[];
17
17
  export declare const isRouteComponentFile: (filePath: string) => boolean;
18
- export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
18
+ export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
19
+ export declare const parseModule: ({
20
+ source,
21
+ filename
22
+ }: {
23
+ source: string;
24
+ filename: string;
25
+ }) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean]>;
26
+ export declare const hasLoader: (filename: string) => Promise<boolean>;
@@ -7,7 +7,8 @@ declare type FnParameter<T extends {
7
7
  }> = { [P in keyof T]: Parameter<T[P]> };
8
8
  export declare type PluginCompatModernOptions = FnParameter<Partial<Pick<BuilderPluginAPI, 'onAfterBuild' | 'onAfterCreateCompiler' | 'onAfterStartDevServer' | 'onBeforeBuild' | 'onBeforeCreateCompiler' | 'onBeforeStartDevServer' | 'onDevCompileDone' | 'onExit'>>>;
9
9
  /**
10
- * Provides default configuration consistent with `@modern-js/webpack`
10
+ * Provides default configuration consistent with modern.js v1
11
11
  */
12
+
12
13
  export declare const PluginCompatModern: (appContext: IAppContext, modernConfig: AppNormalizedConfig, options?: PluginCompatModernOptions) => BuilderPlugin<BuilderPluginAPI>;
13
14
  export {};