@modern-js/app-tools 2.8.1-alpha.3 → 2.10.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 (290) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/dist/cjs/analyze/generateCode.js +3 -1
  3. package/dist/cjs/analyze/index.js +8 -0
  4. package/dist/cjs/analyze/templates.js +45 -14
  5. package/dist/cjs/builder/builder-rspack/index.js +22 -1
  6. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +6 -3
  7. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
  8. package/dist/esm/analyze/generateCode.js +3 -2
  9. package/dist/esm/analyze/index.js +8 -0
  10. package/dist/esm/analyze/templates.js +54 -16
  11. package/dist/esm/builder/builder-rspack/index.js +169 -1
  12. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +10 -3
  13. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
  14. package/dist/esm-node/analyze/generateCode.js +3 -1
  15. package/dist/esm-node/analyze/index.js +8 -0
  16. package/dist/esm-node/analyze/templates.js +45 -14
  17. package/dist/esm-node/builder/builder-rspack/index.js +12 -1
  18. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +7 -4
  19. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +3 -0
  20. package/dist/types/analyze/templates.d.ts +3 -1
  21. package/dist/types/builder/builder-rspack/index.d.ts +2 -1
  22. package/dist/types/types/config/output.d.ts +1 -0
  23. package/package.json +31 -27
  24. package/dist/js/modern/analyze/constants.js +0 -56
  25. package/dist/js/modern/analyze/generateCode.js +0 -247
  26. package/dist/js/modern/analyze/getBundleEntry.js +0 -71
  27. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +0 -220
  28. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +0 -216
  29. package/dist/js/modern/analyze/getClientRoutes/index.js +0 -6
  30. package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -31
  31. package/dist/js/modern/analyze/getFileSystemEntry.js +0 -109
  32. package/dist/js/modern/analyze/getHtmlTemplate.js +0 -115
  33. package/dist/js/modern/analyze/getServerRoutes.js +0 -178
  34. package/dist/js/modern/analyze/index.js +0 -333
  35. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -42
  36. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -13
  37. package/dist/js/modern/analyze/nestedRoutes.js +0 -186
  38. package/dist/js/modern/analyze/templates.js +0 -328
  39. package/dist/js/modern/analyze/utils.js +0 -141
  40. package/dist/js/modern/builder/builder-rspack/index.js +0 -8
  41. package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +0 -41
  42. package/dist/js/modern/builder/builder-webpack/index.js +0 -93
  43. package/dist/js/modern/builder/builder-webpack/webpackPlugins/RouterPlugin.js +0 -116
  44. package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +0 -1
  45. package/dist/js/modern/builder/generator/createBuilderOptions.js +0 -24
  46. package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +0 -39
  47. package/dist/js/modern/builder/generator/getBuilderTargets.js +0 -21
  48. package/dist/js/modern/builder/generator/index.js +0 -53
  49. package/dist/js/modern/builder/index.js +0 -39
  50. package/dist/js/modern/builder/shared/builderPlugins/adapterModern.js +0 -219
  51. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -27
  52. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -34
  53. package/dist/js/modern/builder/shared/createCopyPattern.js +0 -46
  54. package/dist/js/modern/builder/shared/index.js +0 -3
  55. package/dist/js/modern/builder/shared/loaders/serverModuleLoader.js +0 -7
  56. package/dist/js/modern/builder/shared/types.js +0 -0
  57. package/dist/js/modern/commands/build.js +0 -91
  58. package/dist/js/modern/commands/deploy.js +0 -28
  59. package/dist/js/modern/commands/dev.js +0 -109
  60. package/dist/js/modern/commands/index.js +0 -3
  61. package/dist/js/modern/commands/inspect.js +0 -38
  62. package/dist/js/modern/commands/serve.js +0 -54
  63. package/dist/js/modern/config/default.js +0 -175
  64. package/dist/js/modern/config/index.js +0 -3
  65. package/dist/js/modern/config/initialize/index.js +0 -12
  66. package/dist/js/modern/config/initialize/inits.js +0 -154
  67. package/dist/js/modern/config/legacy/createHtmlConfig.js +0 -35
  68. package/dist/js/modern/config/legacy/createOutputConfig.js +0 -68
  69. package/dist/js/modern/config/legacy/createSourceConfig.js +0 -39
  70. package/dist/js/modern/config/legacy/createToolsConfig.js +0 -42
  71. package/dist/js/modern/config/legacy/index.js +0 -51
  72. package/dist/js/modern/defineConfig.js +0 -27
  73. package/dist/js/modern/exports/server.js +0 -4
  74. package/dist/js/modern/hooks.js +0 -35
  75. package/dist/js/modern/index.js +0 -221
  76. package/dist/js/modern/initialize/index.js +0 -132
  77. package/dist/js/modern/locale/en.js +0 -36
  78. package/dist/js/modern/locale/index.js +0 -9
  79. package/dist/js/modern/locale/zh.js +0 -36
  80. package/dist/js/modern/schema/Schema.js +0 -40
  81. package/dist/js/modern/schema/index.js +0 -88
  82. package/dist/js/modern/schema/legacy.js +0 -148
  83. package/dist/js/modern/types/config/deploy.js +0 -0
  84. package/dist/js/modern/types/config/dev.js +0 -0
  85. package/dist/js/modern/types/config/experiments.js +0 -0
  86. package/dist/js/modern/types/config/html.js +0 -0
  87. package/dist/js/modern/types/config/index.js +0 -1
  88. package/dist/js/modern/types/config/output.js +0 -0
  89. package/dist/js/modern/types/config/performance.js +0 -0
  90. package/dist/js/modern/types/config/security.js +0 -0
  91. package/dist/js/modern/types/config/source.js +0 -0
  92. package/dist/js/modern/types/config/tools.js +0 -0
  93. package/dist/js/modern/types/hooks.js +0 -0
  94. package/dist/js/modern/types/index.js +0 -3
  95. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  96. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  97. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  98. package/dist/js/modern/types/legacyConfig/output.js +0 -0
  99. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  100. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  101. package/dist/js/modern/types/utils.js +0 -0
  102. package/dist/js/modern/utils/config.js +0 -128
  103. package/dist/js/modern/utils/createServer.js +0 -75
  104. package/dist/js/modern/utils/env.js +0 -15
  105. package/dist/js/modern/utils/generateWatchFiles.js +0 -55
  106. package/dist/js/modern/utils/getSelectedEntries.js +0 -58
  107. package/dist/js/modern/utils/getServerInternalPlugins.js +0 -58
  108. package/dist/js/modern/utils/language.js +0 -8
  109. package/dist/js/modern/utils/printInstructions.js +0 -31
  110. package/dist/js/modern/utils/restart.js +0 -44
  111. package/dist/js/modern/utils/routes.js +0 -30
  112. package/dist/js/modern/utils/types.js +0 -0
  113. package/dist/js/node/analyze/constants.js +0 -100
  114. package/dist/js/node/analyze/generateCode.js +0 -271
  115. package/dist/js/node/analyze/getBundleEntry.js +0 -95
  116. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +0 -242
  117. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +0 -238
  118. package/dist/js/node/analyze/getClientRoutes/index.js +0 -30
  119. package/dist/js/node/analyze/getClientRoutes/utils.js +0 -58
  120. package/dist/js/node/analyze/getFileSystemEntry.js +0 -131
  121. package/dist/js/node/analyze/getHtmlTemplate.js +0 -144
  122. package/dist/js/node/analyze/getServerRoutes.js +0 -196
  123. package/dist/js/node/analyze/index.js +0 -340
  124. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -71
  125. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -36
  126. package/dist/js/node/analyze/nestedRoutes.js +0 -213
  127. package/dist/js/node/analyze/templates.js +0 -359
  128. package/dist/js/node/analyze/utils.js +0 -172
  129. package/dist/js/node/builder/builder-rspack/index.js +0 -31
  130. package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +0 -64
  131. package/dist/js/node/builder/builder-webpack/index.js +0 -118
  132. package/dist/js/node/builder/builder-webpack/webpackPlugins/RouterPlugin.js +0 -140
  133. package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +0 -17
  134. package/dist/js/node/builder/generator/createBuilderOptions.js +0 -47
  135. package/dist/js/node/builder/generator/createBuilderProviderConfig.js +0 -60
  136. package/dist/js/node/builder/generator/getBuilderTargets.js +0 -39
  137. package/dist/js/node/builder/generator/index.js +0 -82
  138. package/dist/js/node/builder/index.js +0 -68
  139. package/dist/js/node/builder/shared/builderPlugins/adapterModern.js +0 -245
  140. package/dist/js/node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -50
  141. package/dist/js/node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -57
  142. package/dist/js/node/builder/shared/createCopyPattern.js +0 -75
  143. package/dist/js/node/builder/shared/index.js +0 -19
  144. package/dist/js/node/builder/shared/loaders/serverModuleLoader.js +0 -28
  145. package/dist/js/node/builder/shared/types.js +0 -15
  146. package/dist/js/node/commands/build.js +0 -112
  147. package/dist/js/node/commands/deploy.js +0 -51
  148. package/dist/js/node/commands/dev.js +0 -126
  149. package/dist/js/node/commands/index.js +0 -19
  150. package/dist/js/node/commands/inspect.js +0 -61
  151. package/dist/js/node/commands/serve.js +0 -83
  152. package/dist/js/node/config/default.js +0 -197
  153. package/dist/js/node/config/index.js +0 -19
  154. package/dist/js/node/config/initialize/index.js +0 -35
  155. package/dist/js/node/config/initialize/inits.js +0 -177
  156. package/dist/js/node/config/legacy/createHtmlConfig.js +0 -58
  157. package/dist/js/node/config/legacy/createOutputConfig.js +0 -91
  158. package/dist/js/node/config/legacy/createSourceConfig.js +0 -62
  159. package/dist/js/node/config/legacy/createToolsConfig.js +0 -65
  160. package/dist/js/node/config/legacy/index.js +0 -75
  161. package/dist/js/node/defineConfig.js +0 -49
  162. package/dist/js/node/exports/server.js +0 -27
  163. package/dist/js/node/hooks.js +0 -54
  164. package/dist/js/node/index.js +0 -245
  165. package/dist/js/node/initialize/index.js +0 -141
  166. package/dist/js/node/locale/en.js +0 -59
  167. package/dist/js/node/locale/index.js +0 -33
  168. package/dist/js/node/locale/zh.js +0 -59
  169. package/dist/js/node/schema/Schema.js +0 -63
  170. package/dist/js/node/schema/index.js +0 -118
  171. package/dist/js/node/schema/legacy.js +0 -169
  172. package/dist/js/node/types/config/deploy.js +0 -15
  173. package/dist/js/node/types/config/dev.js +0 -15
  174. package/dist/js/node/types/config/experiments.js +0 -15
  175. package/dist/js/node/types/config/html.js +0 -15
  176. package/dist/js/node/types/config/index.js +0 -17
  177. package/dist/js/node/types/config/output.js +0 -15
  178. package/dist/js/node/types/config/performance.js +0 -15
  179. package/dist/js/node/types/config/security.js +0 -15
  180. package/dist/js/node/types/config/source.js +0 -15
  181. package/dist/js/node/types/config/tools.js +0 -15
  182. package/dist/js/node/types/hooks.js +0 -15
  183. package/dist/js/node/types/index.js +0 -19
  184. package/dist/js/node/types/legacyConfig/deploy.js +0 -15
  185. package/dist/js/node/types/legacyConfig/dev.js +0 -15
  186. package/dist/js/node/types/legacyConfig/index.js +0 -15
  187. package/dist/js/node/types/legacyConfig/output.js +0 -15
  188. package/dist/js/node/types/legacyConfig/source.js +0 -15
  189. package/dist/js/node/types/legacyConfig/tools.js +0 -15
  190. package/dist/js/node/types/utils.js +0 -15
  191. package/dist/js/node/utils/config.js +0 -153
  192. package/dist/js/node/utils/createServer.js +0 -106
  193. package/dist/js/node/utils/env.js +0 -38
  194. package/dist/js/node/utils/generateWatchFiles.js +0 -85
  195. package/dist/js/node/utils/getSelectedEntries.js +0 -81
  196. package/dist/js/node/utils/getServerInternalPlugins.js +0 -79
  197. package/dist/js/node/utils/language.js +0 -31
  198. package/dist/js/node/utils/printInstructions.js +0 -54
  199. package/dist/js/node/utils/restart.js +0 -67
  200. package/dist/js/node/utils/routes.js +0 -59
  201. package/dist/js/node/utils/types.js +0 -15
  202. package/dist/js/treeshaking/analyze/constants.js +0 -42
  203. package/dist/js/treeshaking/analyze/generateCode.js +0 -485
  204. package/dist/js/treeshaking/analyze/getBundleEntry.js +0 -62
  205. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +0 -233
  206. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +0 -231
  207. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +0 -3
  208. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -23
  209. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +0 -107
  210. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +0 -302
  211. package/dist/js/treeshaking/analyze/getServerRoutes.js +0 -224
  212. package/dist/js/treeshaking/analyze/index.js +0 -702
  213. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -47
  214. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -13
  215. package/dist/js/treeshaking/analyze/nestedRoutes.js +0 -409
  216. package/dist/js/treeshaking/analyze/templates.js +0 -465
  217. package/dist/js/treeshaking/analyze/utils.js +0 -374
  218. package/dist/js/treeshaking/builder/builder-rspack/index.js +0 -6
  219. package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +0 -64
  220. package/dist/js/treeshaking/builder/builder-webpack/index.js +0 -301
  221. package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/RouterPlugin.js +0 -346
  222. package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +0 -1
  223. package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +0 -41
  224. package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +0 -70
  225. package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +0 -16
  226. package/dist/js/treeshaking/builder/generator/index.js +0 -199
  227. package/dist/js/treeshaking/builder/index.js +0 -175
  228. package/dist/js/treeshaking/builder/shared/builderPlugins/adapterModern.js +0 -300
  229. package/dist/js/treeshaking/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -110
  230. package/dist/js/treeshaking/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -72
  231. package/dist/js/treeshaking/builder/shared/createCopyPattern.js +0 -40
  232. package/dist/js/treeshaking/builder/shared/index.js +0 -3
  233. package/dist/js/treeshaking/builder/shared/loaders/serverModuleLoader.js +0 -5
  234. package/dist/js/treeshaking/builder/shared/types.js +0 -1
  235. package/dist/js/treeshaking/commands/build.js +0 -291
  236. package/dist/js/treeshaking/commands/deploy.js +0 -154
  237. package/dist/js/treeshaking/commands/dev.js +0 -301
  238. package/dist/js/treeshaking/commands/index.js +0 -3
  239. package/dist/js/treeshaking/commands/inspect.js +0 -149
  240. package/dist/js/treeshaking/commands/serve.js +0 -199
  241. package/dist/js/treeshaking/config/default.js +0 -210
  242. package/dist/js/treeshaking/config/index.js +0 -3
  243. package/dist/js/treeshaking/config/initialize/index.js +0 -10
  244. package/dist/js/treeshaking/config/initialize/inits.js +0 -211
  245. package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +0 -19
  246. package/dist/js/treeshaking/config/legacy/createOutputConfig.js +0 -41
  247. package/dist/js/treeshaking/config/legacy/createSourceConfig.js +0 -42
  248. package/dist/js/treeshaking/config/legacy/createToolsConfig.js +0 -23
  249. package/dist/js/treeshaking/config/legacy/index.js +0 -38
  250. package/dist/js/treeshaking/defineConfig.js +0 -61
  251. package/dist/js/treeshaking/exports/server.js +0 -2
  252. package/dist/js/treeshaking/hooks.js +0 -29
  253. package/dist/js/treeshaking/index.js +0 -713
  254. package/dist/js/treeshaking/initialize/index.js +0 -284
  255. package/dist/js/treeshaking/locale/en.js +0 -38
  256. package/dist/js/treeshaking/locale/index.js +0 -9
  257. package/dist/js/treeshaking/locale/zh.js +0 -38
  258. package/dist/js/treeshaking/schema/Schema.js +0 -273
  259. package/dist/js/treeshaking/schema/index.js +0 -181
  260. package/dist/js/treeshaking/schema/legacy.js +0 -337
  261. package/dist/js/treeshaking/types/config/deploy.js +0 -1
  262. package/dist/js/treeshaking/types/config/dev.js +0 -1
  263. package/dist/js/treeshaking/types/config/experiments.js +0 -1
  264. package/dist/js/treeshaking/types/config/html.js +0 -1
  265. package/dist/js/treeshaking/types/config/index.js +0 -1
  266. package/dist/js/treeshaking/types/config/output.js +0 -1
  267. package/dist/js/treeshaking/types/config/performance.js +0 -1
  268. package/dist/js/treeshaking/types/config/security.js +0 -1
  269. package/dist/js/treeshaking/types/config/source.js +0 -1
  270. package/dist/js/treeshaking/types/config/tools.js +0 -1
  271. package/dist/js/treeshaking/types/hooks.js +0 -1
  272. package/dist/js/treeshaking/types/index.js +0 -3
  273. package/dist/js/treeshaking/types/legacyConfig/deploy.js +0 -1
  274. package/dist/js/treeshaking/types/legacyConfig/dev.js +0 -1
  275. package/dist/js/treeshaking/types/legacyConfig/index.js +0 -1
  276. package/dist/js/treeshaking/types/legacyConfig/output.js +0 -1
  277. package/dist/js/treeshaking/types/legacyConfig/source.js +0 -1
  278. package/dist/js/treeshaking/types/legacyConfig/tools.js +0 -1
  279. package/dist/js/treeshaking/types/utils.js +0 -1
  280. package/dist/js/treeshaking/utils/config.js +0 -302
  281. package/dist/js/treeshaking/utils/createServer.js +0 -258
  282. package/dist/js/treeshaking/utils/env.js +0 -13
  283. package/dist/js/treeshaking/utils/generateWatchFiles.js +0 -214
  284. package/dist/js/treeshaking/utils/getSelectedEntries.js +0 -186
  285. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +0 -210
  286. package/dist/js/treeshaking/utils/language.js +0 -6
  287. package/dist/js/treeshaking/utils/printInstructions.js +0 -152
  288. package/dist/js/treeshaking/utils/restart.js +0 -187
  289. package/dist/js/treeshaking/utils/routes.js +0 -153
  290. package/dist/js/treeshaking/utils/types.js +0 -1
@@ -1,702 +0,0 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
- try {
11
- var info = gen[key](arg);
12
- var value = info.value;
13
- } catch (error) {
14
- reject(error);
15
- return;
16
- }
17
- if (info.done) {
18
- resolve(value);
19
- } else {
20
- Promise.resolve(value).then(_next, _throw);
21
- }
22
- }
23
- function _asyncToGenerator(fn) {
24
- return function() {
25
- var self = this, args = arguments;
26
- return new Promise(function(resolve, reject) {
27
- var gen = fn.apply(self, args);
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
- function _throw(err) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
- }
34
- _next(undefined);
35
- });
36
- };
37
- }
38
- function _defineProperty(obj, key, value) {
39
- if (key in obj) {
40
- Object.defineProperty(obj, key, {
41
- value: value,
42
- enumerable: true,
43
- configurable: true,
44
- writable: true
45
- });
46
- } else {
47
- obj[key] = value;
48
- }
49
- return obj;
50
- }
51
- function _iterableToArrayLimit(arr, i) {
52
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
53
- if (_i == null) return;
54
- var _arr = [];
55
- var _n = true;
56
- var _d = false;
57
- var _s, _e;
58
- try {
59
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
60
- _arr.push(_s.value);
61
- if (i && _arr.length === i) break;
62
- }
63
- } catch (err) {
64
- _d = true;
65
- _e = err;
66
- } finally{
67
- try {
68
- if (!_n && _i["return"] != null) _i["return"]();
69
- } finally{
70
- if (_d) throw _e;
71
- }
72
- }
73
- return _arr;
74
- }
75
- function _nonIterableRest() {
76
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
- }
78
- function _objectSpread(target) {
79
- for(var i = 1; i < arguments.length; i++){
80
- var source = arguments[i] != null ? arguments[i] : {};
81
- var ownKeys = Object.keys(source);
82
- if (typeof Object.getOwnPropertySymbols === "function") {
83
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
84
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
85
- }));
86
- }
87
- ownKeys.forEach(function(key) {
88
- _defineProperty(target, key, source[key]);
89
- });
90
- }
91
- return target;
92
- }
93
- function ownKeys(object, enumerableOnly) {
94
- var keys = Object.keys(object);
95
- if (Object.getOwnPropertySymbols) {
96
- var symbols = Object.getOwnPropertySymbols(object);
97
- if (enumerableOnly) {
98
- symbols = symbols.filter(function(sym) {
99
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
100
- });
101
- }
102
- keys.push.apply(keys, symbols);
103
- }
104
- return keys;
105
- }
106
- function _objectSpreadProps(target, source) {
107
- source = source != null ? source : {};
108
- if (Object.getOwnPropertyDescriptors) {
109
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
110
- } else {
111
- ownKeys(Object(source)).forEach(function(key) {
112
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
113
- });
114
- }
115
- return target;
116
- }
117
- function _slicedToArray(arr, i) {
118
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
119
- }
120
- function _unsupportedIterableToArray(o, minLen) {
121
- if (!o) return;
122
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
123
- var n = Object.prototype.toString.call(o).slice(8, -1);
124
- if (n === "Object" && o.constructor) n = o.constructor.name;
125
- if (n === "Map" || n === "Set") return Array.from(n);
126
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
127
- }
128
- var __generator = this && this.__generator || function(thisArg, body) {
129
- var f, y, t, g, _ = {
130
- label: 0,
131
- sent: function() {
132
- if (t[0] & 1) throw t[1];
133
- return t[1];
134
- },
135
- trys: [],
136
- ops: []
137
- };
138
- return g = {
139
- next: verb(0),
140
- "throw": verb(1),
141
- "return": verb(2)
142
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
143
- return this;
144
- }), g;
145
- function verb(n) {
146
- return function(v) {
147
- return step([
148
- n,
149
- v
150
- ]);
151
- };
152
- }
153
- function step(op) {
154
- if (f) throw new TypeError("Generator is already executing.");
155
- while(_)try {
156
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
157
- if (y = 0, t) op = [
158
- op[0] & 2,
159
- t.value
160
- ];
161
- switch(op[0]){
162
- case 0:
163
- case 1:
164
- t = op;
165
- break;
166
- case 4:
167
- _.label++;
168
- return {
169
- value: op[1],
170
- done: false
171
- };
172
- case 5:
173
- _.label++;
174
- y = op[1];
175
- op = [
176
- 0
177
- ];
178
- continue;
179
- case 7:
180
- op = _.ops.pop();
181
- _.trys.pop();
182
- continue;
183
- default:
184
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
185
- _ = 0;
186
- continue;
187
- }
188
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
189
- _.label = op[1];
190
- break;
191
- }
192
- if (op[0] === 6 && _.label < t[1]) {
193
- _.label = t[1];
194
- t = op;
195
- break;
196
- }
197
- if (t && _.label < t[2]) {
198
- _.label = t[2];
199
- _.ops.push(op);
200
- break;
201
- }
202
- if (t[2]) _.ops.pop();
203
- _.trys.pop();
204
- continue;
205
- }
206
- op = body.call(thisArg, _);
207
- } catch (e) {
208
- op = [
209
- 6,
210
- e
211
- ];
212
- y = 0;
213
- } finally{
214
- f = t = 0;
215
- }
216
- if (op[0] & 5) throw op[1];
217
- return {
218
- value: op[0] ? op[1] : void 0,
219
- done: true
220
- };
221
- }
222
- };
223
- import * as path from "path";
224
- import { createDebugger, findExists, fs, getEntryOptions, isApiOnly, minimist, getCommand, isDevCommand } from "@modern-js/utils";
225
- import { cloneDeep } from "@modern-js/utils/lodash";
226
- import { printInstructions } from "../utils/printInstructions";
227
- import { generateRoutes } from "../utils/routes";
228
- import { emitResolvedConfig } from "../utils/config";
229
- import { getSelectedEntries } from "../utils/getSelectedEntries";
230
- import { initialNormalizedConfig } from "../config";
231
- import { createBuilderGenerator } from "../builder";
232
- import { getServerLoadersFile, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
233
- import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
234
- var debug = createDebugger("plugin-analyze");
235
- var analyze_default = function(param) {
236
- var bundler = param.bundler;
237
- return {
238
- name: "@modern-js/plugin-analyze",
239
- setup: function(api) {
240
- var pagesDir = [];
241
- var nestedRouteEntries = [];
242
- var originEntrypoints = [];
243
- return {
244
- prepare: function prepare() {
245
- return _asyncToGenerator(function() {
246
- var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, _ref, routes2, _ref1, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes, htmlTemplates, checkedEntries, entry, command, buildCommands, normalizedConfig, createBuilderForModern, builder;
247
- return __generator(this, function(_state) {
248
- switch(_state.label){
249
- case 0:
250
- appContext = api.useAppContext();
251
- resolvedConfig = api.useResolvedConfigContext();
252
- hookRunners = api.useHookRunners();
253
- try {
254
- fs.emptydirSync(appContext.internalDirectory);
255
- } catch (e) {}
256
- return [
257
- 4,
258
- isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir)
259
- ];
260
- case 1:
261
- apiOnly = _state.sent();
262
- return [
263
- 4,
264
- hookRunners.addRuntimeExports()
265
- ];
266
- case 2:
267
- _state.sent();
268
- if (!apiOnly) return [
269
- 3,
270
- 4
271
- ];
272
- return [
273
- 4,
274
- hookRunners.modifyServerRoutes({
275
- routes: []
276
- })
277
- ];
278
- case 3:
279
- _ref = _state.sent(), routes2 = _ref.routes;
280
- debug("server routes: %o", routes2);
281
- appContext = _objectSpreadProps(_objectSpread({}, appContext), {
282
- apiOnly: apiOnly,
283
- serverRoutes: routes2
284
- });
285
- api.setAppContext(appContext);
286
- return [
287
- 2
288
- ];
289
- case 4:
290
- return [
291
- 4,
292
- Promise.all([
293
- import("./getBundleEntry"),
294
- import("./getServerRoutes"),
295
- import("./generateCode"),
296
- import("./getHtmlTemplate")
297
- ])
298
- ];
299
- case 5:
300
- _ref1 = _slicedToArray.apply(void 0, [
301
- _state.sent(),
302
- 4
303
- ]), getBundleEntry = _ref1[0].getBundleEntry, getServerRoutes = _ref1[1].getServerRoutes, generateCode = _ref1[2].generateCode, getHtmlTemplate = _ref1[3].getHtmlTemplate;
304
- entrypoints = getBundleEntry(appContext, resolvedConfig);
305
- debug("entrypoints: %o", entrypoints);
306
- initialRoutes = getServerRoutes(entrypoints, {
307
- appContext: appContext,
308
- config: resolvedConfig
309
- });
310
- return [
311
- 4,
312
- hookRunners.modifyServerRoutes({
313
- routes: initialRoutes
314
- })
315
- ];
316
- case 6:
317
- routes = _state.sent().routes;
318
- debug("server routes: %o", routes);
319
- appContext = _objectSpreadProps(_objectSpread({}, appContext), {
320
- entrypoints: entrypoints,
321
- serverRoutes: routes
322
- });
323
- api.setAppContext(appContext);
324
- nestedRouteEntries = entrypoints.map(function(point) {
325
- return point.nestedRoutesEntry;
326
- }).filter(Boolean);
327
- pagesDir = entrypoints.map(function(point) {
328
- return point.entry;
329
- }).filter(Boolean).concat(nestedRouteEntries);
330
- originEntrypoints = cloneDeep(entrypoints);
331
- return [
332
- 4,
333
- generateCode(appContext, resolvedConfig, entrypoints, api)
334
- ];
335
- case 7:
336
- _state.sent();
337
- return [
338
- 4,
339
- getHtmlTemplate(entrypoints, api, {
340
- appContext: appContext,
341
- config: resolvedConfig
342
- })
343
- ];
344
- case 8:
345
- htmlTemplates = _state.sent();
346
- debug("html templates: %o", htmlTemplates);
347
- return [
348
- 4,
349
- hookRunners.addDefineTypes()
350
- ];
351
- case 9:
352
- _state.sent();
353
- debug("add Define Types");
354
- checkedEntries = entrypoints.map(function(point) {
355
- return point.entryName;
356
- });
357
- if (!isDevCommand()) return [
358
- 3,
359
- 11
360
- ];
361
- entry = minimist(process.argv.slice(2)).entry;
362
- return [
363
- 4,
364
- getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
365
- ];
366
- case 10:
367
- checkedEntries = _state.sent();
368
- _state.label = 11;
369
- case 11:
370
- appContext = _objectSpreadProps(_objectSpread({}, appContext), {
371
- entrypoints: entrypoints,
372
- checkedEntries: checkedEntries,
373
- apiOnly: apiOnly,
374
- serverRoutes: routes,
375
- htmlTemplates: htmlTemplates
376
- });
377
- api.setAppContext(appContext);
378
- command = getCommand();
379
- buildCommands = [
380
- "dev",
381
- "start",
382
- "build",
383
- "inspect",
384
- "deploy"
385
- ];
386
- if (!buildCommands.includes(command)) return [
387
- 3,
388
- 14
389
- ];
390
- normalizedConfig = api.useResolvedConfigContext();
391
- return [
392
- 4,
393
- createBuilderGenerator(bundler)
394
- ];
395
- case 12:
396
- createBuilderForModern = _state.sent();
397
- return [
398
- 4,
399
- createBuilderForModern({
400
- normalizedConfig: normalizedConfig,
401
- appContext: appContext,
402
- onBeforeBuild: function onBeforeBuild(param) {
403
- var bundlerConfigs = param.bundlerConfigs;
404
- return _asyncToGenerator(function() {
405
- var hookRunners2;
406
- return __generator(this, function(_state) {
407
- switch(_state.label){
408
- case 0:
409
- hookRunners2 = api.useHookRunners();
410
- return [
411
- 4,
412
- generateRoutes(appContext)
413
- ];
414
- case 1:
415
- _state.sent();
416
- return [
417
- 4,
418
- hookRunners2.beforeBuild({
419
- bundlerConfigs: bundlerConfigs
420
- })
421
- ];
422
- case 2:
423
- _state.sent();
424
- return [
425
- 2
426
- ];
427
- }
428
- });
429
- })();
430
- },
431
- onAfterBuild: function onAfterBuild(param) {
432
- var stats = param.stats;
433
- return _asyncToGenerator(function() {
434
- var hookRunners2;
435
- return __generator(this, function(_state) {
436
- switch(_state.label){
437
- case 0:
438
- hookRunners2 = api.useHookRunners();
439
- return [
440
- 4,
441
- hookRunners2.afterBuild({
442
- stats: stats
443
- })
444
- ];
445
- case 1:
446
- _state.sent();
447
- return [
448
- 4,
449
- emitResolvedConfig(appContext.appDirectory, normalizedConfig)
450
- ];
451
- case 2:
452
- _state.sent();
453
- return [
454
- 2
455
- ];
456
- }
457
- });
458
- })();
459
- },
460
- onDevCompileDone: function onDevCompileDone(param) {
461
- var isFirstCompile = param.isFirstCompile;
462
- return _asyncToGenerator(function() {
463
- var hookRunners2;
464
- return __generator(this, function(_state) {
465
- hookRunners2 = api.useHookRunners();
466
- if (process.stdout.isTTY || isFirstCompile) {
467
- hookRunners2.afterDev();
468
- if (isFirstCompile) {
469
- printInstructions(hookRunners2, appContext, normalizedConfig);
470
- }
471
- }
472
- return [
473
- 2
474
- ];
475
- });
476
- })();
477
- },
478
- onBeforeCreateCompiler: function onBeforeCreateCompiler(param) {
479
- var bundlerConfigs = param.bundlerConfigs;
480
- return _asyncToGenerator(function() {
481
- var hookRunners2;
482
- return __generator(this, function(_state) {
483
- switch(_state.label){
484
- case 0:
485
- hookRunners2 = api.useHookRunners();
486
- return [
487
- 4,
488
- hookRunners2.beforeCreateCompiler({
489
- bundlerConfigs: bundlerConfigs
490
- })
491
- ];
492
- case 1:
493
- _state.sent();
494
- return [
495
- 2
496
- ];
497
- }
498
- });
499
- })();
500
- },
501
- onAfterCreateCompiler: function onAfterCreateCompiler(param) {
502
- var compiler = param.compiler;
503
- return _asyncToGenerator(function() {
504
- var hookRunners2;
505
- return __generator(this, function(_state) {
506
- switch(_state.label){
507
- case 0:
508
- hookRunners2 = api.useHookRunners();
509
- return [
510
- 4,
511
- hookRunners2.afterCreateCompiler({
512
- compiler: compiler
513
- })
514
- ];
515
- case 1:
516
- _state.sent();
517
- return [
518
- 2
519
- ];
520
- }
521
- });
522
- })();
523
- }
524
- })
525
- ];
526
- case 13:
527
- builder = _state.sent();
528
- builder.addPlugins(resolvedConfig.builderPlugins);
529
- appContext = _objectSpreadProps(_objectSpread({}, appContext), {
530
- builder: builder
531
- });
532
- api.setAppContext(appContext);
533
- _state.label = 14;
534
- case 14:
535
- return [
536
- 2
537
- ];
538
- }
539
- });
540
- })();
541
- },
542
- watchFiles: function watchFiles() {
543
- return pagesDir;
544
- },
545
- config: function config() {
546
- return {
547
- tools: {
548
- webpackChain: function(chain, param) {
549
- var name = param.name;
550
- var appContext = api.useAppContext();
551
- var resolvedConfig = api.useResolvedConfigContext();
552
- var entrypoints = appContext.entrypoints, internalDirectory = appContext.internalDirectory, packageName = appContext.packageName;
553
- entrypoints.forEach(function(entrypoint) {
554
- var entryName = entrypoint.entryName;
555
- var ssr = getEntryOptions(entryName, resolvedConfig.server.ssr, resolvedConfig.server.ssrByEntries, packageName);
556
- if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
557
- var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
558
- chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
559
- }
560
- });
561
- }
562
- }
563
- };
564
- },
565
- resolvedConfig: function resolvedConfig(param) {
566
- var resolved = param.resolved;
567
- var appContext = api.useAppContext();
568
- var config = initialNormalizedConfig(resolved, appContext, bundler);
569
- return {
570
- resolved: config
571
- };
572
- },
573
- modifyEntryImports: function modifyEntryImports(param) {
574
- var entrypoint = param.entrypoint, imports = param.imports;
575
- return _asyncToGenerator(function() {
576
- var appContext, srcDirectory, internalSrcAlias, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout, _ref, moduleExports, hasAppConfig, generateLayoutPath, hasAppInit;
577
- return __generator(this, function(_state) {
578
- switch(_state.label){
579
- case 0:
580
- appContext = api.useAppContext();
581
- srcDirectory = appContext.srcDirectory, internalSrcAlias = appContext.internalSrcAlias;
582
- fileSystemRoutes = entrypoint.fileSystemRoutes, nestedRoutesEntry = entrypoint.nestedRoutesEntry;
583
- if (!(fileSystemRoutes && nestedRoutesEntry)) return [
584
- 3,
585
- 3
586
- ];
587
- rootLayoutPath = path.join(nestedRoutesEntry, "layout");
588
- rootLayoutFile = findExists([
589
- ".js",
590
- ".ts",
591
- ".jsx",
592
- ".tsx"
593
- ].map(function(ext) {
594
- return "".concat(rootLayoutPath).concat(ext);
595
- }));
596
- if (!rootLayoutFile) return [
597
- 3,
598
- 3
599
- ];
600
- return [
601
- 4,
602
- fs.readFile(rootLayoutFile)
603
- ];
604
- case 1:
605
- rootLayoutBuffer = _state.sent();
606
- rootLayout = rootLayoutBuffer.toString();
607
- return [
608
- 4,
609
- parseModule({
610
- source: rootLayout.toString(),
611
- filename: rootLayoutFile
612
- })
613
- ];
614
- case 2:
615
- _ref = _slicedToArray.apply(void 0, [
616
- _state.sent(),
617
- 2
618
- ]), moduleExports = _ref[1];
619
- hasAppConfig = moduleExports.some(function(e) {
620
- return e.n === APP_CONFIG_NAME;
621
- });
622
- generateLayoutPath = replaceWithAlias(srcDirectory, rootLayoutFile, internalSrcAlias);
623
- if (hasAppConfig) {
624
- imports.push({
625
- value: generateLayoutPath,
626
- specifiers: [
627
- {
628
- imported: APP_CONFIG_NAME
629
- }
630
- ]
631
- });
632
- }
633
- hasAppInit = moduleExports.some(function(e) {
634
- return e.n === APP_INIT_EXPORTED;
635
- });
636
- if (hasAppInit) {
637
- imports.push({
638
- value: generateLayoutPath,
639
- specifiers: [
640
- {
641
- imported: APP_INIT_EXPORTED,
642
- local: APP_INIT_IMPORTED
643
- }
644
- ]
645
- });
646
- }
647
- _state.label = 3;
648
- case 3:
649
- return [
650
- 2,
651
- {
652
- entrypoint: entrypoint,
653
- imports: imports
654
- }
655
- ];
656
- }
657
- });
658
- })();
659
- },
660
- fileChange: function fileChange(e) {
661
- return _asyncToGenerator(function() {
662
- var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, generateCode, entrypoints;
663
- return __generator(this, function(_state) {
664
- switch(_state.label){
665
- case 0:
666
- appContext = api.useAppContext();
667
- appDirectory = appContext.appDirectory;
668
- filename = e.filename, eventType = e.eventType;
669
- isPageFile = function(name) {
670
- return pagesDir.some(function(pageDir) {
671
- return name.includes(pageDir);
672
- });
673
- };
674
- absoluteFilePath = path.resolve(appDirectory, filename);
675
- isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
676
- if (!(isRouteComponent && (eventType === "add" || eventType === "unlink"))) return [
677
- 3,
678
- 2
679
- ];
680
- resolvedConfig = api.useResolvedConfigContext();
681
- return [
682
- 4,
683
- import("./generateCode")
684
- ];
685
- case 1:
686
- generateCode = _state.sent().generateCode;
687
- entrypoints = cloneDeep(originEntrypoints);
688
- generateCode(appContext, resolvedConfig, entrypoints, api);
689
- _state.label = 2;
690
- case 2:
691
- return [
692
- 2
693
- ];
694
- }
695
- });
696
- })();
697
- }
698
- };
699
- }
700
- };
701
- };
702
- export { analyze_default as default };