@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
@@ -2,18 +2,18 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
4
  var _excluded = ["path"],
5
- _excluded2 = ["path"];
5
+ _excluded2 = ["path"];
6
6
  import path from 'path';
7
7
  import fs from 'fs';
8
8
  import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash } from '@modern-js/utils';
9
9
  import { walkDirectory } from "./utils";
10
+
10
11
  /**
11
12
  * Add base url for each server route.
12
13
  * @param baseUrl - Base url from server.baseUrl
13
14
  * @param routes - Server routes.
14
15
  * @returns Server routes with baseUrl prefixed.
15
16
  */
16
-
17
17
  var applyBaseUrl = function applyBaseUrl(baseUrl, routes) {
18
18
  if (baseUrl) {
19
19
  if (Array.isArray(baseUrl)) {
@@ -29,33 +29,30 @@ var applyBaseUrl = function applyBaseUrl(baseUrl, routes) {
29
29
  });
30
30
  }
31
31
  }
32
-
33
32
  return routes;
34
33
  };
34
+
35
35
  /**
36
36
  *
37
37
  * @param original - Original entrypoint route info.
38
38
  * @param routeOptions - Custom entrypoint route config from server.routes.
39
39
  * @returns
40
40
  */
41
-
42
-
43
41
  var applyRouteOptions = function applyRouteOptions(original, routeOptions) {
44
42
  var route = routeOptions.route,
45
- disableSpa = routeOptions.disableSpa;
46
- original.isSPA = !disableSpa; // set entryPath as dir
43
+ disableSpa = routeOptions.disableSpa;
44
+ original.isSPA = !disableSpa;
47
45
 
46
+ // set entryPath as dir
48
47
  !original.isSPA && (original.entryPath = path.dirname(original.entryPath));
49
48
  var routes;
50
-
51
49
  if (route) {
52
50
  if (Array.isArray(route)) {
53
51
  routes = route.map(function (url) {
54
52
  if (isPlainObject(url)) {
55
53
  var _ref = url,
56
- urlPath = _ref.path,
57
- other = _objectWithoutProperties(_ref, _excluded);
58
-
54
+ urlPath = _ref.path,
55
+ other = _objectWithoutProperties(_ref, _excluded);
59
56
  return _objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
60
57
  urlPath: urlPath
61
58
  });
@@ -67,9 +64,8 @@ var applyRouteOptions = function applyRouteOptions(original, routeOptions) {
67
64
  });
68
65
  } else if (isPlainObject(route)) {
69
66
  var _ref2 = route,
70
- urlPath = _ref2.path,
71
- other = _objectWithoutProperties(_ref2, _excluded2);
72
-
67
+ urlPath = _ref2.path,
68
+ other = _objectWithoutProperties(_ref2, _excluded2);
73
69
  routes = [_objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
74
70
  urlPath: urlPath
75
71
  })];
@@ -81,36 +77,32 @@ var applyRouteOptions = function applyRouteOptions(original, routeOptions) {
81
77
  } else {
82
78
  routes = [original];
83
79
  }
84
-
85
80
  return routes;
86
81
  };
82
+
87
83
  /**
88
84
  * Collect routes from entrypoints.
89
85
  * @param entrypoints - Bundle entrypoints.
90
86
  * @param config - Normalized user config.
91
87
  * @returns entrypoint Routes
92
88
  */
93
-
94
-
95
89
  var collectHtmlRoutes = function collectHtmlRoutes(entrypoints, appContext, config) {
96
- var _config$output = config.output,
97
- htmlPath = _config$output.htmlPath,
98
- disableHtmlFolder = _config$output.disableHtmlFolder,
99
- enableModernMode = _config$output.enableModernMode,
100
- _config$server = config.server,
101
- baseUrl = _config$server.baseUrl,
102
- routes = _config$server.routes,
103
- ssr = _config$server.ssr,
104
- ssrByEntries = _config$server.ssrByEntries;
90
+ var disableHtmlFolder = config.html.disableHtmlFolder,
91
+ _config$output$distPa = config.output.distPath;
92
+ _config$output$distPa = _config$output$distPa === void 0 ? {} : _config$output$distPa;
93
+ var htmlPath = _config$output$distPa.html,
94
+ _config$server = config.server,
95
+ baseUrl = _config$server.baseUrl,
96
+ routes = _config$server.routes,
97
+ ssr = _config$server.ssr,
98
+ ssrByEntries = _config$server.ssrByEntries;
105
99
  var packageName = appContext.packageName;
106
100
  var htmlRoutes = entrypoints.reduce(function (previous, _ref3) {
107
101
  var entryName = _ref3.entryName;
108
102
  var entryOptions = getEntryOptions(entryName, ssr, ssrByEntries, packageName);
109
103
  var isSSR = Boolean(entryOptions);
110
-
111
104
  var _ref4 = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {},
112
- resHeaders = _ref4.resHeaders;
113
-
105
+ resHeaders = _ref4.resHeaders;
114
106
  var route = {
115
107
  urlPath: "/".concat(entryName === MAIN_ENTRY_NAME ? '' : entryName),
116
108
  entryName: entryName,
@@ -118,53 +110,49 @@ var collectHtmlRoutes = function collectHtmlRoutes(entrypoints, appContext, conf
118
110
  isSPA: true,
119
111
  isSSR: isSSR,
120
112
  responseHeaders: resHeaders,
121
- enableModernMode: Boolean(enableModernMode),
113
+ // FIXME: remove the config.enableModernMode
114
+ // enableModernMode: Boolean(enableModernMode),
122
115
  bundle: isSSR ? "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : undefined
123
116
  };
124
-
125
117
  if (routes !== null && routes !== void 0 && routes.hasOwnProperty(entryName)) {
126
118
  var routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
127
119
  route: routes[entryName]
128
120
  };
129
121
  route = applyRouteOptions(route, routeOptions);
130
122
  }
131
-
132
123
  return Array.isArray(route) ? [].concat(_toConsumableArray(previous), _toConsumableArray(route)) : [].concat(_toConsumableArray(previous), [route]);
133
124
  }, []);
134
125
  htmlRoutes = applyBaseUrl(baseUrl, htmlRoutes);
135
126
  return htmlRoutes;
136
127
  };
128
+
137
129
  /**
138
130
  * Collect static public file routes from config/public folder.
139
131
  * @param appContext - App context info.
140
132
  * @param config - normalized user config.
141
133
  * @returns Static public file routes.
142
134
  */
143
-
144
-
145
135
  var collectStaticRoutes = function collectStaticRoutes(appContext, config) {
146
136
  var appDirectory = appContext.appDirectory;
147
137
  var configDir = config.source.configDir,
148
- _config$server$public = config.server.publicRoutes,
149
- publicRoutes = _config$server$public === void 0 ? {} : _config$server$public;
150
- var publicFolder = path.resolve(appDirectory, configDir, 'public');
138
+ _config$server$public = config.server.publicRoutes,
139
+ publicRoutes = _config$server$public === void 0 ? {} : _config$server$public;
140
+ var publicFolder = path.resolve(appDirectory, configDir || '', 'public');
151
141
  return fs.existsSync(publicFolder) ? walkDirectory(publicFolder).map(function (filePath) {
152
142
  var urlPath = "".concat(urlJoin(toPosix(filePath).slice(toPosix(publicFolder).length)));
153
143
  return {
154
144
  urlPath: publicRoutes[removeLeadingSlash(urlPath)] || urlPath,
155
145
  isSPA: true,
156
146
  isSSR: false,
157
- entryPath: toPosix(path.relative(path.resolve(appDirectory, configDir), filePath))
147
+ entryPath: toPosix(path.relative(path.resolve(appDirectory, configDir || ''), filePath))
158
148
  };
159
149
  }) : [];
160
150
  };
161
-
162
151
  export var getServerRoutes = function getServerRoutes(entrypoints, _ref5) {
163
152
  var appContext = _ref5.appContext,
164
- config = _ref5.config;
153
+ config = _ref5.config;
165
154
  return [].concat(_toConsumableArray(collectHtmlRoutes(entrypoints, appContext, config)), _toConsumableArray(collectStaticRoutes(appContext, config)));
166
155
  };
167
-
168
156
  var toPosix = function toPosix(pathStr) {
169
157
  return pathStr.split(path.sep).join(path.posix.sep);
170
158
  };
@@ -3,96 +3,69 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
5
  import * as path from 'path';
6
- import { createAsyncWaterfall } from '@modern-js/plugin';
7
6
  import { createDebugger, fs, isApiOnly } from '@modern-js/utils';
8
7
  import { cloneDeep } from '@modern-js/utils/lodash';
8
+ import { createBuilderForEdenX } from "../builder";
9
+ import { printInstructions } from "../utils/printInstructions";
10
+ import { generateRoutes } from "../utils/routes";
11
+ import { emitResolvedConfig } from "../utils/config";
12
+ import { getCommand } from "../utils/commands";
13
+ import { initialNormalizedConfig } from "../config";
9
14
  import { isRouteComponentFile } from "./utils";
10
15
  var debug = createDebugger('plugin-analyze');
11
- export var modifyEntryImports = createAsyncWaterfall();
12
- export var modifyEntryExport = createAsyncWaterfall();
13
- export var addRuntimeExports = createAsyncWaterfall();
14
- export var modifyEntryRuntimePlugins = createAsyncWaterfall();
15
- export var modifyEntryRenderFunction = createAsyncWaterfall();
16
- export var modifyAsyncEntry = createAsyncWaterfall();
17
- export var modifyFileSystemRoutes = createAsyncWaterfall();
18
- export var modifyServerRoutes = createAsyncWaterfall();
19
- export var htmlPartials = createAsyncWaterfall();
20
- export var beforeGenerateRoutes = createAsyncWaterfall();
21
- export var addDefineTypes = createAsyncWaterfall();
22
16
  export default (function () {
23
17
  return {
24
18
  name: '@modern-js/plugin-analyze',
25
- registerHook: {
26
- modifyAsyncEntry: modifyAsyncEntry,
27
- modifyEntryImports: modifyEntryImports,
28
- modifyEntryExport: modifyEntryExport,
29
- modifyEntryRuntimePlugins: modifyEntryRuntimePlugins,
30
- modifyEntryRenderFunction: modifyEntryRenderFunction,
31
- modifyFileSystemRoutes: modifyFileSystemRoutes,
32
- modifyServerRoutes: modifyServerRoutes,
33
- htmlPartials: htmlPartials,
34
- addRuntimeExports: addRuntimeExports,
35
- beforeGenerateRoutes: beforeGenerateRoutes,
36
- addDefineTypes: addDefineTypes
37
- },
38
19
  setup: function setup(api) {
39
20
  var pagesDir = [];
40
21
  var originEntrypoints = [];
41
22
  return {
42
23
  prepare: function prepare() {
43
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
24
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
44
25
  var _resolvedConfig$sourc;
45
-
46
- 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;
47
-
48
- return _regeneratorRuntime().wrap(function _callee$(_context) {
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) {
49
28
  while (1) {
50
- switch (_context.prev = _context.next) {
29
+ switch (_context6.prev = _context6.next) {
51
30
  case 0:
52
31
  appContext = api.useAppContext();
53
32
  resolvedConfig = api.useResolvedConfigContext();
54
33
  hookRunners = api.useHookRunners();
55
-
56
34
  try {
57
35
  fs.emptydirSync(appContext.internalDirectory);
58
- } catch (_unused) {// FIXME:
36
+ } catch (_unused) {
37
+ // FIXME:
59
38
  }
60
-
61
- _context.next = 6;
62
- return isApiOnly(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
63
-
39
+ _context6.next = 6;
40
+ return isApiOnly(appContext.appDirectory, (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
64
41
  case 6:
65
- apiOnly = _context.sent;
66
- _context.next = 9;
42
+ apiOnly = _context6.sent;
43
+ _context6.next = 9;
67
44
  return hookRunners.addRuntimeExports();
68
-
69
45
  case 9:
70
46
  if (!apiOnly) {
71
- _context.next = 17;
47
+ _context6.next = 18;
72
48
  break;
73
49
  }
74
-
75
- _context.next = 12;
50
+ _context6.next = 12;
76
51
  return hookRunners.modifyServerRoutes({
77
52
  routes: []
78
53
  });
79
-
80
54
  case 12:
81
- _yield$hookRunners$mo = _context.sent;
55
+ _yield$hookRunners$mo = _context6.sent;
82
56
  _routes = _yield$hookRunners$mo.routes;
83
57
  debug("server routes: %o", _routes);
84
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
58
+ appContext = _objectSpread(_objectSpread({}, appContext), {}, {
85
59
  apiOnly: apiOnly,
86
60
  serverRoutes: _routes
87
- }));
88
- return _context.abrupt("return");
89
-
90
- case 17:
91
- _context.next = 19;
61
+ });
62
+ api.setAppContext(appContext);
63
+ return _context6.abrupt("return");
64
+ case 18:
65
+ _context6.next = 20;
92
66
  return Promise.all([import("./getBundleEntry"), import("./getServerRoutes"), import("./generateCode"), import("./getHtmlTemplate")]);
93
-
94
- case 19:
95
- _yield$Promise$all = _context.sent;
67
+ case 20:
68
+ _yield$Promise$all = _context6.sent;
96
69
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 4);
97
70
  getBundleEntry = _yield$Promise$all2[0].getBundleEntry;
98
71
  getServerRoutes = _yield$Promise$all2[1].getServerRoutes;
@@ -107,19 +80,19 @@ export default (function () {
107
80
  appContext: appContext,
108
81
  config: resolvedConfig
109
82
  });
110
- _context.next = 31;
83
+ _context6.next = 32;
111
84
  return hookRunners.modifyServerRoutes({
112
85
  routes: initialRoutes
113
86
  });
114
-
115
- case 31:
116
- _yield$hookRunners$mo2 = _context.sent;
87
+ case 32:
88
+ _yield$hookRunners$mo2 = _context6.sent;
117
89
  routes = _yield$hookRunners$mo2.routes;
118
90
  debug("server routes: %o", routes);
119
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
91
+ appContext = _objectSpread(_objectSpread({}, appContext), {}, {
120
92
  entrypoints: entrypoints,
121
93
  serverRoutes: routes
122
- }));
94
+ });
95
+ api.setAppContext(appContext);
123
96
  nestedRouteEntries = entrypoints.map(function (point) {
124
97
  return point.nestedRoutesEntry;
125
98
  }).filter(Boolean);
@@ -127,85 +100,216 @@ export default (function () {
127
100
  return point.entry;
128
101
  }).filter(Boolean).concat(nestedRouteEntries);
129
102
  originEntrypoints = cloneDeep(entrypoints);
130
- _context.next = 40;
103
+ _context6.next = 42;
131
104
  return generateCode(appContext, resolvedConfig, entrypoints, api);
132
-
133
- case 40:
134
- _context.next = 42;
105
+ case 42:
106
+ _context6.next = 44;
135
107
  return getHtmlTemplate(entrypoints, api, {
136
108
  appContext: appContext,
137
109
  config: resolvedConfig
138
110
  });
139
-
140
- case 42:
141
- htmlTemplates = _context.sent;
111
+ case 44:
112
+ htmlTemplates = _context6.sent;
142
113
  debug("html templates: %o", htmlTemplates);
143
- _context.next = 46;
114
+ _context6.next = 48;
144
115
  return hookRunners.addDefineTypes();
145
-
146
- case 46:
116
+ case 48:
147
117
  debug("add Define Types");
148
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
118
+ appContext = _objectSpread(_objectSpread({}, appContext), {}, {
149
119
  entrypoints: entrypoints,
150
120
  checkedEntries: defaultChecked,
151
121
  apiOnly: apiOnly,
152
122
  serverRoutes: routes,
153
123
  htmlTemplates: htmlTemplates
154
- }));
155
-
156
- case 48:
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;
146
+ 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
153
+ });
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
174
+ });
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
221
+ });
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
242
+ });
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:
157
260
  case "end":
158
- return _context.stop();
261
+ return _context6.stop();
159
262
  }
160
263
  }
161
- }, _callee);
264
+ }, _callee6);
162
265
  }))();
163
266
  },
164
267
  watchFiles: function watchFiles() {
165
268
  return pagesDir;
166
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
+ },
167
278
  fileChange: function fileChange(e) {
168
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
279
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
169
280
  var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, _yield$import, generateCode, entrypoints;
170
-
171
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
281
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
172
282
  while (1) {
173
- switch (_context2.prev = _context2.next) {
283
+ switch (_context7.prev = _context7.next) {
174
284
  case 0:
175
285
  appContext = api.useAppContext();
176
286
  appDirectory = appContext.appDirectory;
177
287
  filename = e.filename, eventType = e.eventType;
178
-
179
288
  isPageFile = function isPageFile(name) {
180
289
  return pagesDir.some(function (pageDir) {
181
290
  return name.includes(pageDir);
182
291
  });
183
292
  };
184
-
185
293
  absoluteFilePath = path.resolve(appDirectory, filename);
186
294
  isRouteComponent = isPageFile(absoluteFilePath) && isRouteComponentFile(absoluteFilePath);
187
-
188
295
  if (!(isRouteComponent && (eventType === 'add' || eventType === 'unlink'))) {
189
- _context2.next = 14;
296
+ _context7.next = 14;
190
297
  break;
191
298
  }
192
-
193
299
  resolvedConfig = api.useResolvedConfigContext();
194
- _context2.next = 10;
300
+ _context7.next = 10;
195
301
  return import("./generateCode");
196
-
197
302
  case 10:
198
- _yield$import = _context2.sent;
303
+ _yield$import = _context7.sent;
199
304
  generateCode = _yield$import.generateCode;
200
305
  entrypoints = cloneDeep(originEntrypoints);
201
306
  generateCode(appContext, resolvedConfig, entrypoints, api);
202
-
203
307
  case 14:
204
308
  case "end":
205
- return _context2.stop();
309
+ return _context7.stop();
206
310
  }
207
311
  }
208
- }, _callee2);
312
+ }, _callee7);
209
313
  }))();
210
314
  }
211
315
  };
@@ -2,16 +2,13 @@ import fs from 'fs';
2
2
  import { parse } from '@babel/parser';
3
3
  import traverse from '@babel/traverse';
4
4
  import * as t from '@babel/types';
5
-
6
5
  var isFunction = function isFunction(node) {
7
6
  return t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
8
7
  };
9
-
10
8
  export var isDefaultExportFunction = function isDefaultExportFunction(file) {
11
9
  if (!file || !fs.existsSync(file)) {
12
10
  return false;
13
11
  }
14
-
15
12
  var ast = parse(fs.readFileSync(file, 'utf8'), {
16
13
  sourceType: 'unambiguous',
17
14
  plugins: ['jsx', 'typescript', 'classProperties', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'decorators-legacy', 'functionBind', 'classPrivateMethods', ['pipelineOperator', {
@@ -22,7 +19,6 @@ export var isDefaultExportFunction = function isDefaultExportFunction(file) {
22
19
  traverse(ast, {
23
20
  ExportDefaultDeclaration: function ExportDefaultDeclaration(path) {
24
21
  var declaration = path.node.declaration;
25
-
26
22
  if (isFunction(declaration)) {
27
23
  isExportFunction = true;
28
24
  }
@@ -9,10 +9,8 @@ export function makeLegalIdentifier(str) {
9
9
  var identifier = str.replace(/-(\w)/g, function (_, letter) {
10
10
  return letter.toUpperCase();
11
11
  }).replace(/[^$_a-zA-Z0-9]/g, '_');
12
-
13
12
  if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
14
13
  return "_".concat(identifier);
15
14
  }
16
-
17
15
  return identifier || '_';
18
16
  }