@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.2

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 (279) hide show
  1. package/CHANGELOG.md +375 -0
  2. package/dist/js/modern/analyze/generateCode.js +30 -38
  3. package/dist/js/modern/analyze/getBundleEntry.js +5 -13
  4. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
  6. package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
  7. package/dist/js/modern/analyze/getFileSystemEntry.js +5 -18
  8. package/dist/js/modern/analyze/getHtmlTemplate.js +3 -10
  9. package/dist/js/modern/analyze/getServerRoutes.js +25 -38
  10. package/dist/js/modern/analyze/index.js +90 -48
  11. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
  12. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
  13. package/dist/js/modern/analyze/nestedRoutes.js +8 -33
  14. package/dist/js/modern/analyze/templates.js +22 -37
  15. package/dist/js/modern/analyze/utils.js +0 -7
  16. package/dist/js/modern/builder/builderPlugins/compatModern.js +41 -58
  17. package/dist/js/modern/builder/index.js +56 -37
  18. package/dist/js/modern/builder/share.js +1 -5
  19. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
  20. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
  21. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
  22. package/dist/js/modern/commands/build.js +12 -46
  23. package/dist/js/modern/commands/dev.js +20 -23
  24. package/dist/js/modern/commands/inspect.js +4 -19
  25. package/dist/js/modern/commands/start.js +1 -2
  26. package/dist/js/modern/config/default.js +207 -0
  27. package/dist/js/modern/config/index.js +2 -0
  28. package/dist/js/modern/config/initial/createHtmlConfig.js +32 -0
  29. package/dist/js/modern/{builder → config/initial}/createOutputConfig.js +19 -18
  30. package/dist/js/modern/config/initial/createSourceConfig.js +32 -0
  31. package/dist/js/modern/config/initial/createToolsConfig.js +41 -0
  32. package/dist/js/modern/config/initial/index.js +11 -0
  33. package/dist/js/modern/config/initial/inits.js +117 -0
  34. package/dist/js/modern/config/initial/transformNormalizedConfig.js +40 -0
  35. package/dist/js/modern/defineConfig.js +12 -0
  36. package/dist/js/modern/hooks.js +23 -19
  37. package/dist/js/modern/index.js +12 -19
  38. package/dist/js/modern/initialize/index.js +72 -0
  39. package/dist/js/modern/schema/Schema.js +39 -0
  40. package/dist/js/modern/schema/index.js +139 -0
  41. package/dist/js/modern/schema/legacy.js +284 -0
  42. package/dist/js/modern/types/config/deploy.js +0 -0
  43. package/dist/js/modern/types/config/dev.js +0 -0
  44. package/dist/js/modern/types/config/experiments.js +0 -0
  45. package/dist/js/modern/types/config/html.js +0 -0
  46. package/dist/js/modern/types/config/index.js +2 -0
  47. package/dist/js/modern/types/config/output.js +0 -0
  48. package/dist/js/modern/types/config/performance.js +0 -0
  49. package/dist/js/modern/types/config/security.js +0 -0
  50. package/dist/js/modern/types/config/source.js +0 -0
  51. package/dist/js/modern/types/config/tools.js +0 -0
  52. package/dist/js/modern/types/hooks.js +0 -0
  53. package/dist/js/modern/types/index.js +4 -0
  54. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  55. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  56. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  57. package/dist/js/modern/types/legacyConfig/output.js +1 -0
  58. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  59. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  60. package/dist/js/modern/utils/config.js +2 -13
  61. package/dist/js/modern/utils/createFileWatcher.js +82 -0
  62. package/dist/js/modern/utils/createServer.js +0 -5
  63. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
  64. package/dist/js/modern/utils/printInstructions.js +2 -1
  65. package/dist/js/modern/utils/restart.js +17 -0
  66. package/dist/js/modern/utils/routes.js +0 -2
  67. package/dist/js/node/analyze/generateCode.js +30 -61
  68. package/dist/js/node/analyze/getBundleEntry.js +5 -19
  69. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
  70. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
  71. package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
  72. package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
  73. package/dist/js/node/analyze/getFileSystemEntry.js +5 -26
  74. package/dist/js/node/analyze/getHtmlTemplate.js +3 -24
  75. package/dist/js/node/analyze/getServerRoutes.js +24 -46
  76. package/dist/js/node/analyze/index.js +91 -70
  77. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
  78. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
  79. package/dist/js/node/analyze/nestedRoutes.js +8 -41
  80. package/dist/js/node/analyze/templates.js +22 -47
  81. package/dist/js/node/analyze/utils.js +0 -20
  82. package/dist/js/node/builder/builderPlugins/compatModern.js +41 -69
  83. package/dist/js/node/builder/index.js +57 -51
  84. package/dist/js/node/builder/share.js +1 -13
  85. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
  86. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
  87. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
  88. package/dist/js/node/commands/build.js +10 -57
  89. package/dist/js/node/commands/deploy.js +0 -2
  90. package/dist/js/node/commands/dev.js +19 -34
  91. package/dist/js/node/commands/index.js +0 -6
  92. package/dist/js/node/commands/inspect.js +4 -26
  93. package/dist/js/node/commands/start.js +1 -11
  94. package/dist/js/node/config/default.js +214 -0
  95. package/dist/js/node/config/index.js +31 -0
  96. package/dist/js/node/config/initial/createHtmlConfig.js +38 -0
  97. package/dist/js/node/{builder → config/initial}/createOutputConfig.js +19 -20
  98. package/dist/js/node/config/initial/createSourceConfig.js +38 -0
  99. package/dist/js/node/config/initial/createToolsConfig.js +47 -0
  100. package/dist/js/node/config/initial/index.js +24 -0
  101. package/dist/js/node/config/initial/inits.js +127 -0
  102. package/dist/js/node/config/initial/transformNormalizedConfig.js +46 -0
  103. package/dist/js/node/defineConfig.js +20 -0
  104. package/dist/js/node/exports/server.js +0 -1
  105. package/dist/js/node/hooks.js +23 -30
  106. package/dist/js/node/index.js +35 -48
  107. package/dist/js/node/initialize/index.js +79 -0
  108. package/dist/js/node/locale/index.js +0 -4
  109. package/dist/js/node/schema/Schema.js +46 -0
  110. package/dist/js/node/schema/index.js +152 -0
  111. package/dist/js/node/schema/legacy.js +291 -0
  112. package/dist/js/node/types/config/deploy.js +0 -0
  113. package/dist/js/node/types/config/dev.js +0 -0
  114. package/dist/js/node/types/config/experiments.js +0 -0
  115. package/dist/js/node/types/config/html.js +0 -0
  116. package/dist/js/node/types/config/index.js +16 -0
  117. package/dist/js/node/types/config/output.js +0 -0
  118. package/dist/js/node/types/config/performance.js +0 -0
  119. package/dist/js/node/types/config/security.js +0 -0
  120. package/dist/js/node/types/config/source.js +0 -0
  121. package/dist/js/node/types/config/tools.js +0 -0
  122. package/dist/js/node/types/hooks.js +0 -0
  123. package/dist/js/node/types/index.js +38 -0
  124. package/dist/js/node/types/legacyConfig/deploy.js +0 -0
  125. package/dist/js/node/types/legacyConfig/dev.js +0 -0
  126. package/dist/js/node/types/legacyConfig/index.js +0 -0
  127. package/dist/js/node/types/legacyConfig/output.js +5 -0
  128. package/dist/js/node/types/legacyConfig/source.js +0 -0
  129. package/dist/js/node/types/legacyConfig/tools.js +0 -0
  130. package/dist/js/node/utils/commands.js +0 -2
  131. package/dist/js/node/utils/config.js +2 -26
  132. package/dist/js/node/utils/createFileWatcher.js +90 -0
  133. package/dist/js/node/utils/createServer.js +0 -15
  134. package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
  135. package/dist/js/node/utils/language.js +0 -2
  136. package/dist/js/node/utils/printInstructions.js +2 -5
  137. package/dist/js/node/utils/restart.js +23 -0
  138. package/dist/js/node/utils/routes.js +0 -5
  139. package/dist/js/treeshaking/analyze/generateCode.js +58 -101
  140. package/dist/js/treeshaking/analyze/getBundleEntry.js +12 -20
  141. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
  142. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
  143. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
  144. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +5 -18
  145. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +3 -27
  146. package/dist/js/treeshaking/analyze/getServerRoutes.js +29 -41
  147. package/dist/js/treeshaking/analyze/index.js +195 -91
  148. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
  149. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
  150. package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
  151. package/dist/js/treeshaking/analyze/templates.js +31 -50
  152. package/dist/js/treeshaking/analyze/utils.js +7 -14
  153. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +50 -68
  154. package/dist/js/treeshaking/builder/index.js +69 -65
  155. package/dist/js/treeshaking/builder/share.js +1 -5
  156. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
  157. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
  158. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
  159. package/dist/js/treeshaking/commands/build.js +41 -116
  160. package/dist/js/treeshaking/commands/deploy.js +0 -3
  161. package/dist/js/treeshaking/commands/dev.js +38 -46
  162. package/dist/js/treeshaking/commands/inspect.js +9 -27
  163. package/dist/js/treeshaking/commands/start.js +1 -9
  164. package/dist/js/treeshaking/config/default.js +200 -0
  165. package/dist/js/treeshaking/config/index.js +2 -0
  166. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +31 -0
  167. package/dist/js/treeshaking/config/initial/createOutputConfig.js +67 -0
  168. package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -0
  169. package/dist/js/treeshaking/config/initial/createToolsConfig.js +38 -0
  170. package/dist/js/treeshaking/config/initial/index.js +11 -0
  171. package/dist/js/treeshaking/config/initial/inits.js +114 -0
  172. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +38 -0
  173. package/dist/js/treeshaking/defineConfig.js +14 -0
  174. package/dist/js/treeshaking/hooks.js +23 -19
  175. package/dist/js/treeshaking/index.js +8 -43
  176. package/dist/js/treeshaking/initialize/index.js +121 -0
  177. package/dist/js/treeshaking/schema/Schema.js +75 -0
  178. package/dist/js/treeshaking/schema/index.js +138 -0
  179. package/dist/js/treeshaking/schema/legacy.js +273 -0
  180. package/dist/js/treeshaking/types/config/deploy.js +0 -0
  181. package/dist/js/treeshaking/types/config/dev.js +0 -0
  182. package/dist/js/treeshaking/types/config/experiments.js +0 -0
  183. package/dist/js/treeshaking/types/config/html.js +0 -0
  184. package/dist/js/treeshaking/types/config/index.js +2 -0
  185. package/dist/js/treeshaking/types/config/output.js +0 -0
  186. package/dist/js/treeshaking/types/config/performance.js +0 -0
  187. package/dist/js/treeshaking/types/config/security.js +0 -0
  188. package/dist/js/treeshaking/types/config/source.js +0 -0
  189. package/dist/js/treeshaking/types/config/tools.js +0 -0
  190. package/dist/js/treeshaking/types/hooks.js +0 -0
  191. package/dist/js/treeshaking/types/index.js +4 -0
  192. package/dist/js/treeshaking/types/legacyConfig/deploy.js +0 -0
  193. package/dist/js/treeshaking/types/legacyConfig/dev.js +0 -0
  194. package/dist/js/treeshaking/types/legacyConfig/index.js +0 -0
  195. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
  196. package/dist/js/treeshaking/types/legacyConfig/source.js +0 -0
  197. package/dist/js/treeshaking/types/legacyConfig/tools.js +0 -0
  198. package/dist/js/treeshaking/utils/config.js +2 -18
  199. package/dist/js/treeshaking/utils/createFileWatcher.js +123 -0
  200. package/dist/js/treeshaking/utils/createServer.js +0 -10
  201. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
  202. package/dist/js/treeshaking/utils/printInstructions.js +0 -5
  203. package/dist/js/treeshaking/utils/restart.js +45 -0
  204. package/dist/js/treeshaking/utils/routes.js +0 -4
  205. package/dist/types/analyze/generateCode.d.ts +3 -2
  206. package/dist/types/analyze/getBundleEntry.d.ts +2 -2
  207. package/dist/types/analyze/getFileSystemEntry.d.ts +2 -2
  208. package/dist/types/analyze/getHtmlTemplate.d.ts +3 -3
  209. package/dist/types/analyze/getServerRoutes.d.ts +3 -2
  210. package/dist/types/analyze/index.d.ts +3 -42
  211. package/dist/types/analyze/nestedRoutes.d.ts +1 -1
  212. package/dist/types/analyze/templates.d.ts +4 -2
  213. package/dist/types/analyze/utils.d.ts +1 -1
  214. package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -3
  215. package/dist/types/builder/index.d.ts +7 -8
  216. package/dist/types/builder/share.d.ts +2 -2
  217. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
  218. package/dist/types/commands/build.d.ts +2 -2
  219. package/dist/types/commands/deploy.d.ts +2 -2
  220. package/dist/types/commands/dev.d.ts +2 -2
  221. package/dist/types/commands/inspect.d.ts +6 -1
  222. package/dist/types/commands/start.d.ts +2 -2
  223. package/dist/types/config/default.d.ts +3 -0
  224. package/dist/types/config/index.d.ts +2 -0
  225. package/dist/types/config/initial/createHtmlConfig.d.ts +2 -0
  226. package/dist/types/config/initial/createOutputConfig.d.ts +2 -0
  227. package/dist/types/config/initial/createSourceConfig.d.ts +2 -0
  228. package/dist/types/config/initial/createToolsConfig.d.ts +2 -0
  229. package/dist/types/config/initial/index.d.ts +4 -0
  230. package/dist/types/config/initial/inits.d.ts +4 -0
  231. package/dist/types/config/initial/transformNormalizedConfig.d.ts +2 -0
  232. package/dist/types/defineConfig.d.ts +7 -0
  233. package/dist/types/hooks.d.ts +2 -42
  234. package/dist/types/index.d.ts +5 -7
  235. package/dist/types/initialize/index.d.ts +3 -0
  236. package/dist/types/schema/Schema.d.ts +14 -0
  237. package/dist/types/schema/index.d.ts +4 -0
  238. package/dist/types/schema/legacy.d.ts +3 -0
  239. package/dist/types/types/config/deploy.d.ts +9 -0
  240. package/dist/types/types/config/dev.d.ts +13 -0
  241. package/dist/types/types/config/experiments.d.ts +4 -0
  242. package/dist/types/types/config/html.d.ts +4 -0
  243. package/dist/types/types/config/index.d.ts +62 -0
  244. package/dist/types/types/config/output.d.ts +23 -0
  245. package/dist/types/types/config/performance.d.ts +4 -0
  246. package/dist/types/types/config/security.d.ts +4 -0
  247. package/dist/types/types/config/source.d.ts +22 -0
  248. package/dist/types/types/config/tools.d.ts +15 -0
  249. package/dist/types/types/hooks.d.ts +80 -0
  250. package/dist/types/types/index.d.ts +23 -0
  251. package/dist/types/types/legacyConfig/deploy.d.ts +8 -0
  252. package/dist/types/types/legacyConfig/dev.d.ts +12 -0
  253. package/dist/types/types/legacyConfig/index.d.ts +33 -0
  254. package/dist/types/types/legacyConfig/output.d.ts +51 -0
  255. package/dist/types/types/legacyConfig/source.d.ts +25 -0
  256. package/dist/types/types/legacyConfig/tools.d.ts +16 -0
  257. package/dist/types/utils/config.d.ts +2 -3
  258. package/dist/types/utils/createFileWatcher.d.ts +3 -0
  259. package/dist/types/utils/printInstructions.d.ts +3 -3
  260. package/dist/types/utils/restart.d.ts +3 -0
  261. package/package.json +26 -25
  262. package/dist/js/modern/builder/createHtmlConfig.js +0 -58
  263. package/dist/js/modern/builder/createSourceConfig.js +0 -85
  264. package/dist/js/modern/builder/createToolsConfig.js +0 -94
  265. package/dist/js/modern/utils/createCompiler.js +0 -58
  266. package/dist/js/node/builder/createHtmlConfig.js +0 -76
  267. package/dist/js/node/builder/createSourceConfig.js +0 -99
  268. package/dist/js/node/builder/createToolsConfig.js +0 -103
  269. package/dist/js/node/utils/createCompiler.js +0 -75
  270. package/dist/js/treeshaking/builder/createHtmlConfig.js +0 -59
  271. package/dist/js/treeshaking/builder/createOutputConfig.js +0 -67
  272. package/dist/js/treeshaking/builder/createSourceConfig.js +0 -100
  273. package/dist/js/treeshaking/builder/createToolsConfig.js +0 -90
  274. package/dist/js/treeshaking/utils/createCompiler.js +0 -117
  275. package/dist/types/builder/createHtmlConfig.d.ts +0 -6
  276. package/dist/types/builder/createOutputConfig.d.ts +0 -3
  277. package/dist/types/builder/createSourceConfig.d.ts +0 -5
  278. package/dist/types/builder/createToolsConfig.d.ts +0 -13
  279. package/dist/types/utils/createCompiler.d.ts +0 -12
@@ -0,0 +1,121 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
7
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ import path from 'path';
10
+ import { fs, ROUTE_MANIFEST, logger, ROUTE_MINIFEST_FILE } from '@modern-js/utils';
11
+ var PLUGIN_NAME = 'ModernjsRoutePlugin';
12
+ var RouterPlugin = /*#__PURE__*/function () {
13
+ function RouterPlugin(options) {
14
+ _classCallCheck(this, RouterPlugin);
15
+ _defineProperty(this, "existNestedRoutes", void 0);
16
+ this.existNestedRoutes = options.existNestedRoutes;
17
+ }
18
+ _createClass(RouterPlugin, [{
19
+ key: "apply",
20
+ value: function apply(compiler) {
21
+ var existNestedRoutes = this.existNestedRoutes;
22
+ var target = compiler.options.target;
23
+ if (target === 'node' || Array.isArray(target) && target.includes('node')) {
24
+ return;
25
+ }
26
+ if (!existNestedRoutes) {
27
+ return;
28
+ }
29
+ var webpack = compiler.webpack;
30
+ var Compilation = webpack.Compilation,
31
+ sources = webpack.sources;
32
+ var RawSource = sources.RawSource;
33
+ var PROCESS_ASSETS_STAGE_REPORT = Compilation.PROCESS_ASSETS_STAGE_REPORT;
34
+ var outputPath = compiler.options.output.path;
35
+ var newAssetsMap = new Map();
36
+ var normalizePath = function normalizePath(path) {
37
+ if (!path.endsWith('/')) {
38
+ return "".concat(path, "/");
39
+ }
40
+ return path;
41
+ };
42
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function (compilation) {
43
+ compilation.hooks.processAssets.tapPromise({
44
+ name: PLUGIN_NAME,
45
+ stage: PROCESS_ASSETS_STAGE_REPORT
46
+ }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
47
+ var stats, publicPath, routeAssets, namedChunkGroups, assetsByChunkName, _i, _Object$entries, _Object$entries$_i, name, chunkGroup, manifest, injectedContent, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, _iterator, _step, file, asset, newContent, filename;
48
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
49
+ while (1) {
50
+ switch (_context.prev = _context.next) {
51
+ case 0:
52
+ stats = compilation.getStats().toJson({
53
+ chunkGroups: true,
54
+ chunks: true
55
+ });
56
+ publicPath = stats.publicPath;
57
+ routeAssets = {};
58
+ namedChunkGroups = stats.namedChunkGroups, assetsByChunkName = stats.assetsByChunkName;
59
+ if (!(!namedChunkGroups || !assetsByChunkName)) {
60
+ _context.next = 7;
61
+ break;
62
+ }
63
+ logger.warn('Route manifest does not exist, performance will be affected');
64
+ return _context.abrupt("return");
65
+ case 7:
66
+ for (_i = 0, _Object$entries = Object.entries(namedChunkGroups); _i < _Object$entries.length; _i++) {
67
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), name = _Object$entries$_i[0], chunkGroup = _Object$entries$_i[1];
68
+ routeAssets[name] = {
69
+ chunkIds: chunkGroup.chunks,
70
+ assets: assetsByChunkName[name].map(function (item) {
71
+ return publicPath ? normalizePath(publicPath) + item : item;
72
+ })
73
+ };
74
+ }
75
+ manifest = {
76
+ routeAssets: routeAssets
77
+ };
78
+ injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest), ";\n })();\n ");
79
+ entrypointsArray = Array.from(compilation.entrypoints.entries());
80
+ entryChunkIds = entrypointsArray.map(function (entrypoint) {
81
+ return entrypoint[0];
82
+ });
83
+ entryChunks = _toConsumableArray(compilation.chunks).filter(function (chunk) {
84
+ return entryChunkIds.includes(chunk.name);
85
+ });
86
+ entryChunkFiles = entryChunks.map(function (chunk) {
87
+ return _toConsumableArray(chunk.files)[0];
88
+ });
89
+ _iterator = _createForOfIteratorHelper(entryChunkFiles);
90
+ try {
91
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
92
+ file = _step.value;
93
+ asset = compilation.assets[file];
94
+ newContent = "".concat(injectedContent).concat(asset.source().toString());
95
+ newAssetsMap.set(path.join(outputPath, file), newContent);
96
+ compilation.updateAsset(file, new RawSource(newContent));
97
+ }
98
+ } catch (err) {
99
+ _iterator.e(err);
100
+ } finally {
101
+ _iterator.f();
102
+ }
103
+ filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
104
+ _context.next = 19;
105
+ return fs.ensureFile(filename);
106
+ case 19:
107
+ _context.next = 21;
108
+ return fs.writeFile(filename, JSON.stringify(manifest, null, 2));
109
+ case 21:
110
+ case "end":
111
+ return _context.stop();
112
+ }
113
+ }
114
+ }, _callee);
115
+ })));
116
+ });
117
+ }
118
+ }]);
119
+ return RouterPlugin;
120
+ }();
121
+ export { RouterPlugin as default };
@@ -2,166 +2,91 @@ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
4
  import { ResolvedConfigContext } from '@modern-js/core';
5
- import { logger, isUseSSRBundle, printBuildError } from '@modern-js/utils';
5
+ import { logger, printBuildError } from '@modern-js/utils';
6
6
  import { generateRoutes } from "../utils/routes";
7
- import { buildServerConfig, emitResolvedConfig } from "../utils/config";
8
- import createBuilder from "../builder";
7
+ import { buildServerConfig } from "../utils/config";
9
8
  export var build = /*#__PURE__*/function () {
10
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(api, options) {
11
- var resolvedConfig, appContext, hookRunners, apiOnly, _appDirectory, _distDirectory, _serverConfigFile, distDirectory, appDirectory, serverConfigFile, targets, builder;
12
-
13
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
9
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, options) {
10
+ var resolvedConfig, appContext, hookRunners, apiOnly, _appDirectory, _distDirectory, _serverConfigFile, distDirectory, appDirectory, serverConfigFile;
11
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
14
12
  while (1) {
15
- switch (_context3.prev = _context3.next) {
13
+ switch (_context.prev = _context.next) {
16
14
  case 0:
15
+ if (options !== null && options !== void 0 && options.analyze) {
16
+ // Builder will read this env var to enable bundle analyzer
17
+ process.env.BUNDLE_ANALYZE = 'true';
18
+ }
17
19
  resolvedConfig = api.useResolvedConfigContext();
18
20
  appContext = api.useAppContext();
19
21
  hookRunners = api.useHookRunners();
20
22
  apiOnly = appContext.apiOnly;
21
-
22
23
  if (!apiOnly) {
23
- _context3.next = 15;
24
+ _context.next = 16;
24
25
  break;
25
26
  }
26
-
27
27
  _appDirectory = appContext.appDirectory, _distDirectory = appContext.distDirectory, _serverConfigFile = appContext.serverConfigFile;
28
- _context3.next = 8;
28
+ _context.next = 9;
29
29
  return hookRunners.beforeBuild({
30
30
  // "null" bundlerConfigs
31
31
  bundlerConfigs: undefined
32
32
  });
33
-
34
- case 8:
35
- _context3.next = 10;
33
+ case 9:
34
+ _context.next = 11;
36
35
  return buildServerConfig({
37
36
  appDirectory: _appDirectory,
38
37
  distDirectory: _distDirectory,
39
38
  configFile: _serverConfigFile
40
39
  });
41
-
42
- case 10:
43
- _context3.next = 12;
40
+ case 11:
41
+ _context.next = 13;
44
42
  return generateRoutes(appContext);
45
-
46
- case 12:
47
- _context3.next = 14;
43
+ case 13:
44
+ _context.next = 15;
48
45
  return hookRunners.afterBuild({
49
46
  // "null" stats
50
47
  stats: undefined
51
48
  });
52
-
53
- case 14:
54
- return _context3.abrupt("return");
55
-
56
49
  case 15:
50
+ return _context.abrupt("return");
51
+ case 16:
57
52
  resolvedConfig = _objectSpread(_objectSpread({}, resolvedConfig), {}, {
58
53
  cliOptions: options
59
54
  });
60
55
  ResolvedConfigContext.set(resolvedConfig);
61
56
  distDirectory = appContext.distDirectory, appDirectory = appContext.appDirectory, serverConfigFile = appContext.serverConfigFile;
62
- _context3.next = 20;
57
+ _context.next = 21;
63
58
  return buildServerConfig({
64
59
  appDirectory: appDirectory,
65
60
  distDirectory: distDirectory,
66
61
  configFile: serverConfigFile
67
62
  });
68
-
69
- case 20:
70
- targets = ['web'];
71
-
72
- if (resolvedConfig.output.enableModernMode) {
73
- targets.push('modern-web');
74
- }
75
-
76
- if (isUseSSRBundle(resolvedConfig)) {
77
- targets.push('node');
78
- }
79
-
80
- _context3.prev = 23;
81
- _context3.next = 26;
82
- return createBuilder({
83
- target: targets,
84
- appContext: appContext,
85
- normalizedConfig: resolvedConfig,
86
- compatPluginConfig: {
87
- onBeforeBuild: function onBeforeBuild(_ref2) {
88
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
89
- var bundlerConfigs;
90
- return _regeneratorRuntime().wrap(function _callee$(_context) {
91
- while (1) {
92
- switch (_context.prev = _context.next) {
93
- case 0:
94
- bundlerConfigs = _ref2.bundlerConfigs;
95
- _context.next = 3;
96
- return generateRoutes(appContext);
97
-
98
- case 3:
99
- _context.next = 5;
100
- return hookRunners.beforeBuild({
101
- bundlerConfigs: bundlerConfigs
102
- });
103
-
104
- case 5:
105
- case "end":
106
- return _context.stop();
107
- }
108
- }
109
- }, _callee);
110
- }))();
111
- },
112
- onAfterBuild: function onAfterBuild(_ref3) {
113
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
114
- var stats;
115
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
116
- while (1) {
117
- switch (_context2.prev = _context2.next) {
118
- case 0:
119
- stats = _ref3.stats;
120
- _context2.next = 3;
121
- return hookRunners.afterBuild({
122
- stats: stats
123
- });
124
-
125
- case 3:
126
- _context2.next = 5;
127
- return emitResolvedConfig(appDirectory, resolvedConfig);
128
-
129
- case 5:
130
- case "end":
131
- return _context2.stop();
132
- }
133
- }
134
- }, _callee2);
135
- }))();
136
- }
137
- }
138
- });
139
-
140
- case 26:
141
- builder = _context3.sent;
63
+ case 21:
64
+ _context.prev = 21;
142
65
  logger.info('Create a production build...\n');
143
- _context3.next = 30;
144
- return builder.build();
145
-
146
- case 30:
147
- _context3.next = 36;
66
+ if (appContext.builder) {
67
+ _context.next = 25;
68
+ break;
69
+ }
70
+ throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
71
+ case 25:
72
+ _context.next = 27;
73
+ return appContext.builder.build();
74
+ case 27:
75
+ _context.next = 33;
148
76
  break;
149
-
150
- case 32:
151
- _context3.prev = 32;
152
- _context3.t0 = _context3["catch"](23);
153
- printBuildError(_context3.t0); // eslint-disable-next-line no-process-exit
154
-
77
+ case 29:
78
+ _context.prev = 29;
79
+ _context.t0 = _context["catch"](21);
80
+ printBuildError(_context.t0);
81
+ // eslint-disable-next-line no-process-exit
155
82
  process.exit(1);
156
-
157
- case 36:
83
+ case 33:
158
84
  case "end":
159
- return _context3.stop();
85
+ return _context.stop();
160
86
  }
161
87
  }
162
- }, _callee3, null, [[23, 32]]);
88
+ }, _callee, null, [[21, 29]]);
163
89
  }));
164
-
165
90
  return function build(_x, _x2) {
166
91
  return _ref.apply(this, arguments);
167
92
  };
@@ -10,11 +10,9 @@ export var deploy = /*#__PURE__*/function () {
10
10
  hookRunners = api.useHookRunners();
11
11
  _context.next = 3;
12
12
  return hookRunners.beforeDeploy(options);
13
-
14
13
  case 3:
15
14
  _context.next = 5;
16
15
  return hookRunners.afterDeploy(options);
17
-
18
16
  case 5:
19
17
  case "end":
20
18
  return _context.stop();
@@ -22,7 +20,6 @@ export var deploy = /*#__PURE__*/function () {
22
20
  }
23
21
  }, _callee);
24
22
  }));
25
-
26
23
  return function deploy(_x, _x2) {
27
24
  return _ref.apply(this, arguments);
28
25
  };
@@ -1,39 +1,43 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
- import { logger, isSSR } from '@modern-js/utils';
4
+ import { logger } from '@modern-js/utils';
5
5
  import { ResolvedConfigContext } from '@modern-js/core';
6
+ import { createFileWatcher } from "../utils/createFileWatcher";
6
7
  import { printInstructions } from "../utils/printInstructions";
7
- import { createDevCompiler } from "../utils/createCompiler";
8
8
  import { createServer, injectDataLoaderPlugin } from "../utils/createServer";
9
9
  import { generateRoutes } from "../utils/routes";
10
10
  import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
11
11
  import { buildServerConfig } from "../utils/config";
12
12
  export var dev = /*#__PURE__*/function () {
13
13
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(api, options) {
14
- var userConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, entrypoints, serverConfigFile, serverInternalPlugins, checkedEntries, compiler, target, app;
14
+ var _normalizedConfig$too;
15
+ var normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, entrypoints, serverConfigFile, serverInternalPlugins, checkedEntries, compiler, app;
15
16
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
16
17
  while (1) {
17
18
  switch (_context2.prev = _context2.next) {
18
19
  case 0:
19
- userConfig = api.useResolvedConfigContext();
20
+ if (options.analyze) {
21
+ // Builder will read this env var to enable bundle analyzer
22
+ process.env.BUNDLE_ANALYZE = 'true';
23
+ }
24
+ normalizedConfig = api.useResolvedConfigContext();
20
25
  appContext = api.useAppContext();
21
26
  hookRunners = api.useHookRunners();
22
- userConfig = _objectSpread(_objectSpread({}, userConfig), {}, {
27
+ normalizedConfig = _objectSpread(_objectSpread({}, normalizedConfig), {}, {
23
28
  cliOptions: options
24
29
  });
25
- ResolvedConfigContext.set(userConfig);
30
+ ResolvedConfigContext.set(normalizedConfig);
26
31
  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, entrypoints = appContext.entrypoints, serverConfigFile = appContext.serverConfigFile, serverInternalPlugins = appContext.serverInternalPlugins;
27
- _context2.next = 8;
32
+ _context2.next = 9;
28
33
  return getSpecifiedEntries(options.entry || false, entrypoints);
29
-
30
- case 8:
34
+ case 9:
31
35
  checkedEntries = _context2.sent;
32
36
  api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
33
37
  checkedEntries: checkedEntries
34
38
  }));
35
39
  appContext.checkedEntries = checkedEntries;
36
- _context2.next = 13;
40
+ _context2.next = 14;
37
41
  return buildServerConfig({
38
42
  appDirectory: appDirectory,
39
43
  distDirectory: distDirectory,
@@ -44,37 +48,30 @@ export var dev = /*#__PURE__*/function () {
44
48
  }
45
49
  }
46
50
  });
47
-
48
- case 13:
49
- _context2.next = 15;
51
+ case 14:
52
+ _context2.next = 16;
50
53
  return hookRunners.beforeDev();
51
-
52
- case 15:
54
+ case 16:
53
55
  compiler = null;
54
-
55
56
  if (apiOnly) {
56
- _context2.next = 21;
57
+ _context2.next = 23;
57
58
  break;
58
59
  }
59
-
60
- target = isSSR(userConfig) ? ['web', 'node'] : ['web'];
61
- _context2.next = 20;
62
- return createDevCompiler({
63
- target: target,
64
- api: api,
65
- normalizedConfig: userConfig,
66
- appContext: appContext
67
- });
68
-
60
+ if (appContext.builder) {
61
+ _context2.next = 20;
62
+ break;
63
+ }
64
+ throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
69
65
  case 20:
66
+ _context2.next = 22;
67
+ return appContext.builder.createCompiler();
68
+ case 22:
70
69
  compiler = _context2.sent;
71
-
72
- case 21:
73
- _context2.next = 23;
74
- return generateRoutes(appContext);
75
-
76
70
  case 23:
77
71
  _context2.next = 25;
72
+ return generateRoutes(appContext);
73
+ case 25:
74
+ _context2.next = 27;
78
75
  return createServer({
79
76
  dev: _objectSpread(_objectSpread({}, {
80
77
  client: {
@@ -88,16 +85,15 @@ export var dev = /*#__PURE__*/function () {
88
85
  hot: true,
89
86
  liveReload: true,
90
87
  port: port,
91
- https: userConfig.dev.https
92
- }), userConfig.tools.devServer),
88
+ https: normalizedConfig.dev.https
89
+ }), (_normalizedConfig$too = normalizedConfig.tools) === null || _normalizedConfig$too === void 0 ? void 0 : _normalizedConfig$too.devServer),
93
90
  compiler: compiler,
94
91
  pwd: appDirectory,
95
- config: userConfig,
92
+ config: normalizedConfig,
96
93
  serverConfigFile: serverConfigFile,
97
94
  internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
98
95
  });
99
-
100
- case 25:
96
+ case 27:
101
97
  app = _context2.sent;
102
98
  app.listen(port, /*#__PURE__*/function () {
103
99
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(err) {
@@ -109,16 +105,13 @@ export var dev = /*#__PURE__*/function () {
109
105
  _context.next = 2;
110
106
  break;
111
107
  }
112
-
113
108
  throw err;
114
-
115
109
  case 2:
116
110
  if (!apiOnly) {
117
- logger.info("Starting dev server...");
111
+ logger.info("Starting dev server...\n");
118
112
  } else {
119
- printInstructions(hookRunners, appContext, userConfig);
113
+ printInstructions(hookRunners, appContext, normalizedConfig);
120
114
  }
121
-
122
115
  case 3:
123
116
  case "end":
124
117
  return _context.stop();
@@ -126,20 +119,19 @@ export var dev = /*#__PURE__*/function () {
126
119
  }
127
120
  }, _callee);
128
121
  }));
129
-
130
122
  return function (_x3) {
131
123
  return _ref2.apply(this, arguments);
132
124
  };
133
125
  }());
134
-
135
- case 27:
126
+ _context2.next = 31;
127
+ return createFileWatcher(appContext, normalizedConfig.source.configDir, hookRunners);
128
+ case 31:
136
129
  case "end":
137
130
  return _context2.stop();
138
131
  }
139
132
  }
140
133
  }, _callee2);
141
134
  }));
142
-
143
135
  return function dev(_x, _x2) {
144
136
  return _ref.apply(this, arguments);
145
137
  };
@@ -1,51 +1,33 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import { join } from 'path';
4
- import { isUseSSRBundle } from '@modern-js/utils';
5
- import createBuilder from "../builder";
6
4
  export var inspect = /*#__PURE__*/function () {
7
5
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, options) {
8
- var resolvedConfig, appContext, targets, builder;
6
+ var appContext;
9
7
  return _regeneratorRuntime().wrap(function _callee$(_context) {
10
8
  while (1) {
11
9
  switch (_context.prev = _context.next) {
12
10
  case 0:
13
- resolvedConfig = api.useResolvedConfigContext();
14
11
  appContext = api.useAppContext();
15
- targets = ['web'];
16
-
17
- if (resolvedConfig.output.enableModernMode) {
18
- targets.push('modern-web');
12
+ if (appContext.builder) {
13
+ _context.next = 3;
14
+ break;
19
15
  }
20
-
21
- if (isUseSSRBundle(resolvedConfig)) {
22
- targets.push('node');
23
- }
24
-
25
- _context.next = 7;
26
- return createBuilder({
27
- target: targets,
28
- appContext: appContext,
29
- normalizedConfig: resolvedConfig
30
- });
31
-
32
- case 7:
33
- builder = _context.sent;
34
- return _context.abrupt("return", builder.inspectConfig({
16
+ throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
17
+ case 3:
18
+ return _context.abrupt("return", appContext.builder.inspectConfig({
35
19
  env: options.env,
36
20
  verbose: options.verbose,
37
- outputPath: join(builder.context.distPath, options.output),
21
+ outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
38
22
  writeToDisk: true
39
23
  }));
40
-
41
- case 9:
24
+ case 4:
42
25
  case "end":
43
26
  return _context.stop();
44
27
  }
45
28
  }
46
29
  }, _callee);
47
30
  }));
48
-
49
31
  return function inspect(_x, _x2) {
50
32
  return _ref.apply(this, arguments);
51
33
  };
@@ -7,7 +7,6 @@ import { injectDataLoaderPlugin } from "../utils/createServer";
7
7
  export var start = /*#__PURE__*/function () {
8
8
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(api) {
9
9
  var _userConfig$source;
10
-
11
10
  var appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, app;
12
11
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
13
12
  while (1) {
@@ -20,18 +19,17 @@ export var start = /*#__PURE__*/function () {
20
19
  logger.log(chalk.cyan("Starting the modern server..."));
21
20
  _context2.next = 7;
22
21
  return isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
23
-
24
22
  case 7:
25
23
  apiOnly = _context2.sent;
26
24
  _context2.next = 10;
27
25
  return server({
28
26
  pwd: appDirectory,
27
+ // FIXME: remove the `any` type
29
28
  config: userConfig,
30
29
  serverConfigFile: serverConfigFile,
31
30
  internalPlugins: injectDataLoaderPlugin(appContext.serverInternalPlugins),
32
31
  apiOnly: apiOnly
33
32
  });
34
-
35
33
  case 10:
36
34
  app = _context2.sent;
37
35
  app.listen(port, /*#__PURE__*/function () {
@@ -44,13 +42,10 @@ export var start = /*#__PURE__*/function () {
44
42
  _context.next = 2;
45
43
  break;
46
44
  }
47
-
48
45
  throw err;
49
-
50
46
  case 2:
51
47
  _context.next = 4;
52
48
  return printInstructions(hookRunners, appContext, userConfig);
53
-
54
49
  case 4:
55
50
  case "end":
56
51
  return _context.stop();
@@ -58,12 +53,10 @@ export var start = /*#__PURE__*/function () {
58
53
  }
59
54
  }, _callee);
60
55
  }));
61
-
62
56
  return function (_x2) {
63
57
  return _ref2.apply(this, arguments);
64
58
  };
65
59
  }());
66
-
67
60
  case 12:
68
61
  case "end":
69
62
  return _context2.stop();
@@ -71,7 +64,6 @@ export var start = /*#__PURE__*/function () {
71
64
  }
72
65
  }, _callee2);
73
66
  }));
74
-
75
67
  return function start(_x) {
76
68
  return _ref.apply(this, arguments);
77
69
  };