@modern-js/app-tools 1.22.1 → 2.0.0-alpha.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 (325) hide show
  1. package/CHANGELOG.md +1383 -87
  2. package/bin/modern.js +13 -1
  3. package/dist/js/modern/analyze/Builder.js +39 -0
  4. package/dist/js/modern/analyze/constants.js +48 -15
  5. package/dist/js/modern/analyze/generateCode.js +286 -133
  6. package/dist/js/modern/analyze/getBundleEntry.js +39 -41
  7. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +220 -0
  8. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +216 -0
  9. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -0
  10. package/dist/js/modern/analyze/getClientRoutes/utils.js +31 -0
  11. package/dist/js/modern/analyze/getFileSystemEntry.js +74 -39
  12. package/dist/js/modern/analyze/getHtmlTemplate.js +90 -57
  13. package/dist/js/modern/analyze/getServerRoutes.js +123 -140
  14. package/dist/js/modern/analyze/index.js +220 -133
  15. package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -20
  16. package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -13
  17. package/dist/js/modern/analyze/nestedRoutes.js +166 -0
  18. package/dist/js/modern/analyze/templates.js +289 -29
  19. package/dist/js/modern/analyze/utils.js +128 -58
  20. package/dist/js/modern/builder/builderPlugins/compatModern.js +233 -0
  21. package/dist/js/modern/builder/index.js +154 -0
  22. package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
  23. package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
  24. package/dist/js/modern/builder/share.js +46 -0
  25. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
  26. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
  27. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +113 -0
  28. package/dist/js/modern/commands/build.js +75 -138
  29. package/dist/js/modern/commands/deploy.js +27 -4
  30. package/dist/js/modern/commands/dev.js +102 -66
  31. package/dist/js/modern/commands/index.js +1 -1
  32. package/dist/js/modern/commands/inspect.js +33 -64
  33. package/dist/js/modern/commands/serve.js +54 -0
  34. package/dist/js/modern/config/default.js +173 -0
  35. package/dist/js/modern/config/index.js +8 -0
  36. package/dist/js/modern/config/initial/createHtmlConfig.js +35 -0
  37. package/dist/js/modern/config/initial/createOutputConfig.js +68 -0
  38. package/dist/js/modern/config/initial/createSourceConfig.js +39 -0
  39. package/dist/js/modern/config/initial/createToolsConfig.js +42 -0
  40. package/dist/js/modern/config/initial/index.js +16 -0
  41. package/dist/js/modern/config/initial/inits.js +153 -0
  42. package/dist/js/modern/config/initial/transformNormalizedConfig.js +47 -0
  43. package/dist/js/modern/defineConfig.js +27 -0
  44. package/dist/js/modern/exports/server.js +4 -1
  45. package/dist/js/modern/hooks.js +37 -21
  46. package/dist/js/modern/index.js +185 -94
  47. package/dist/js/modern/initialize/index.js +120 -0
  48. package/dist/js/modern/locale/en.js +20 -22
  49. package/dist/js/modern/locale/index.js +6 -6
  50. package/dist/js/modern/locale/zh.js +21 -23
  51. package/dist/js/modern/schema/Schema.js +40 -0
  52. package/dist/js/modern/schema/index.js +88 -0
  53. package/dist/js/modern/schema/legacy.js +148 -0
  54. package/dist/js/modern/types/config/deploy.js +0 -0
  55. package/dist/js/modern/types/config/dev.js +0 -0
  56. package/dist/js/modern/types/config/experiments.js +0 -0
  57. package/dist/js/modern/types/config/html.js +0 -0
  58. package/dist/js/modern/types/config/index.js +1 -0
  59. package/dist/js/modern/types/config/output.js +0 -0
  60. package/dist/js/modern/types/config/performance.js +0 -0
  61. package/dist/js/modern/types/config/security.js +0 -0
  62. package/dist/js/modern/types/config/source.js +0 -0
  63. package/dist/js/modern/types/config/tools.js +0 -0
  64. package/dist/js/modern/types/hooks.js +0 -0
  65. package/dist/js/modern/types/index.js +3 -0
  66. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  67. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  68. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  69. package/dist/js/modern/types/legacyConfig/output.js +0 -0
  70. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  71. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  72. package/dist/js/modern/utils/commands.js +13 -0
  73. package/dist/js/modern/utils/config.js +102 -52
  74. package/dist/js/modern/utils/createFileWatcher.js +115 -0
  75. package/dist/js/modern/utils/createServer.js +67 -10
  76. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  77. package/dist/js/modern/utils/getSpecifiedEntries.js +46 -25
  78. package/dist/js/modern/utils/language.js +6 -3
  79. package/dist/js/modern/utils/printInstructions.js +29 -9
  80. package/dist/js/modern/utils/restart.js +44 -0
  81. package/dist/js/modern/utils/routes.js +29 -14
  82. package/dist/js/node/analyze/Builder.js +64 -0
  83. package/dist/js/node/analyze/constants.js +86 -33
  84. package/dist/js/node/analyze/generateCode.js +305 -163
  85. package/dist/js/node/analyze/getBundleEntry.js +66 -58
  86. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +242 -0
  87. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +238 -0
  88. package/dist/js/node/analyze/getClientRoutes/index.js +30 -0
  89. package/dist/js/node/analyze/getClientRoutes/utils.js +58 -0
  90. package/dist/js/node/analyze/getFileSystemEntry.js +99 -58
  91. package/dist/js/node/analyze/getHtmlTemplate.js +121 -83
  92. package/dist/js/node/analyze/getServerRoutes.js +146 -160
  93. package/dist/js/node/analyze/index.js +243 -161
  94. package/dist/js/node/analyze/isDefaultExportFunction.js +59 -38
  95. package/dist/js/node/analyze/makeLegalIdentifier.js +31 -19
  96. package/dist/js/node/analyze/nestedRoutes.js +193 -0
  97. package/dist/js/node/analyze/templates.js +316 -43
  98. package/dist/js/node/analyze/utils.js +158 -78
  99. package/dist/js/node/builder/builderPlugins/compatModern.js +258 -0
  100. package/dist/js/node/builder/index.js +177 -0
  101. package/dist/js/node/builder/loaders/routerLoader.js +38 -0
  102. package/dist/js/node/builder/loaders/serverModuleLoader.js +28 -0
  103. package/dist/js/node/builder/share.js +75 -0
  104. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +53 -0
  105. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +60 -0
  106. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +135 -0
  107. package/dist/js/node/commands/build.js +97 -159
  108. package/dist/js/node/commands/deploy.js +49 -12
  109. package/dist/js/node/commands/dev.js +121 -93
  110. package/dist/js/node/commands/index.js +19 -44
  111. package/dist/js/node/commands/inspect.js +56 -93
  112. package/dist/js/node/commands/serve.js +83 -0
  113. package/dist/js/node/config/default.js +195 -0
  114. package/dist/js/node/config/index.js +34 -0
  115. package/dist/js/node/config/initial/createHtmlConfig.js +58 -0
  116. package/dist/js/node/config/initial/createOutputConfig.js +91 -0
  117. package/dist/js/node/config/initial/createSourceConfig.js +62 -0
  118. package/dist/js/node/config/initial/createToolsConfig.js +65 -0
  119. package/dist/js/node/config/initial/index.js +41 -0
  120. package/dist/js/node/config/initial/inits.js +176 -0
  121. package/dist/js/node/config/initial/transformNormalizedConfig.js +70 -0
  122. package/dist/js/node/defineConfig.js +49 -0
  123. package/dist/js/node/exports/server.js +25 -11
  124. package/dist/js/node/hooks.js +53 -36
  125. package/dist/js/node/index.js +216 -128
  126. package/dist/js/node/initialize/index.js +135 -0
  127. package/dist/js/node/locale/en.js +40 -26
  128. package/dist/js/node/locale/index.js +31 -18
  129. package/dist/js/node/locale/zh.js +41 -27
  130. package/dist/js/node/schema/Schema.js +63 -0
  131. package/dist/js/node/schema/index.js +118 -0
  132. package/dist/js/node/schema/legacy.js +169 -0
  133. package/dist/js/node/types/config/deploy.js +15 -0
  134. package/dist/js/node/types/config/dev.js +15 -0
  135. package/dist/js/node/types/config/experiments.js +15 -0
  136. package/dist/js/node/types/config/html.js +15 -0
  137. package/dist/js/node/types/config/index.js +17 -0
  138. package/dist/js/node/types/config/output.js +15 -0
  139. package/dist/js/node/types/config/performance.js +15 -0
  140. package/dist/js/node/types/config/security.js +15 -0
  141. package/dist/js/node/types/config/source.js +15 -0
  142. package/dist/js/node/types/config/tools.js +15 -0
  143. package/dist/js/node/types/hooks.js +15 -0
  144. package/dist/js/node/types/index.js +19 -0
  145. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  146. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  147. package/dist/js/node/types/legacyConfig/index.js +15 -0
  148. package/dist/js/node/types/legacyConfig/output.js +15 -0
  149. package/dist/js/node/types/legacyConfig/source.js +15 -0
  150. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  151. package/dist/js/node/utils/commands.js +37 -0
  152. package/dist/js/node/utils/config.js +125 -75
  153. package/dist/js/node/utils/createFileWatcher.js +139 -0
  154. package/dist/js/node/utils/createServer.js +96 -25
  155. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  156. package/dist/js/node/utils/getSpecifiedEntries.js +68 -34
  157. package/dist/js/node/utils/language.js +28 -10
  158. package/dist/js/node/utils/printInstructions.js +51 -19
  159. package/dist/js/node/utils/restart.js +67 -0
  160. package/dist/js/node/utils/routes.js +58 -24
  161. package/dist/js/node/utils/types.js +15 -0
  162. package/dist/js/treeshaking/analyze/Builder.js +199 -0
  163. package/dist/js/treeshaking/analyze/constants.js +37 -0
  164. package/dist/js/treeshaking/analyze/generateCode.js +615 -0
  165. package/dist/js/treeshaking/analyze/getBundleEntry.js +64 -0
  166. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +233 -0
  167. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
  168. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -0
  169. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +23 -0
  170. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +107 -0
  171. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +302 -0
  172. package/dist/js/treeshaking/analyze/getServerRoutes.js +222 -0
  173. package/dist/js/treeshaking/analyze/index.js +589 -0
  174. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +47 -0
  175. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -0
  176. package/dist/js/treeshaking/analyze/nestedRoutes.js +426 -0
  177. package/dist/js/treeshaking/analyze/templates.js +446 -0
  178. package/dist/js/treeshaking/analyze/utils.js +390 -0
  179. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +304 -0
  180. package/dist/js/treeshaking/builder/index.js +374 -0
  181. package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
  182. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
  183. package/dist/js/treeshaking/builder/share.js +40 -0
  184. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +110 -0
  185. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +72 -0
  186. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +343 -0
  187. package/dist/js/treeshaking/commands/build.js +291 -0
  188. package/dist/js/treeshaking/commands/deploy.js +154 -0
  189. package/dist/js/treeshaking/commands/dev.js +319 -0
  190. package/dist/js/treeshaking/commands/index.js +3 -0
  191. package/dist/js/treeshaking/commands/inspect.js +149 -0
  192. package/dist/js/treeshaking/commands/serve.js +199 -0
  193. package/dist/js/treeshaking/config/default.js +208 -0
  194. package/dist/js/treeshaking/config/index.js +3 -0
  195. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -0
  196. package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -0
  197. package/dist/js/treeshaking/config/initial/createSourceConfig.js +42 -0
  198. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -0
  199. package/dist/js/treeshaking/config/initial/index.js +12 -0
  200. package/dist/js/treeshaking/config/initial/inits.js +213 -0
  201. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +35 -0
  202. package/dist/js/treeshaking/defineConfig.js +61 -0
  203. package/dist/js/treeshaking/exports/server.js +2 -0
  204. package/dist/js/treeshaking/hooks.js +31 -0
  205. package/dist/js/treeshaking/index.js +694 -0
  206. package/dist/js/treeshaking/initialize/index.js +300 -0
  207. package/dist/js/treeshaking/locale/en.js +35 -0
  208. package/dist/js/treeshaking/locale/index.js +9 -0
  209. package/dist/js/treeshaking/locale/zh.js +35 -0
  210. package/dist/js/treeshaking/schema/Schema.js +273 -0
  211. package/dist/js/treeshaking/schema/index.js +181 -0
  212. package/dist/js/treeshaking/schema/legacy.js +337 -0
  213. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  214. package/dist/js/treeshaking/types/config/dev.js +1 -0
  215. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  216. package/dist/js/treeshaking/types/config/html.js +1 -0
  217. package/dist/js/treeshaking/types/config/index.js +1 -0
  218. package/dist/js/treeshaking/types/config/output.js +1 -0
  219. package/dist/js/treeshaking/types/config/performance.js +1 -0
  220. package/dist/js/treeshaking/types/config/security.js +1 -0
  221. package/dist/js/treeshaking/types/config/source.js +1 -0
  222. package/dist/js/treeshaking/types/config/tools.js +1 -0
  223. package/dist/js/treeshaking/types/hooks.js +1 -0
  224. package/dist/js/treeshaking/types/index.js +3 -0
  225. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  226. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  227. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  228. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
  229. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  230. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  231. package/dist/js/treeshaking/utils/commands.js +10 -0
  232. package/dist/js/treeshaking/utils/config.js +302 -0
  233. package/dist/js/treeshaking/utils/createFileWatcher.js +283 -0
  234. package/dist/js/treeshaking/utils/createServer.js +258 -0
  235. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  236. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +185 -0
  237. package/dist/js/treeshaking/utils/language.js +6 -0
  238. package/dist/js/treeshaking/utils/printInstructions.js +152 -0
  239. package/dist/js/treeshaking/utils/restart.js +187 -0
  240. package/dist/js/treeshaking/utils/routes.js +153 -0
  241. package/dist/js/treeshaking/utils/types.js +1 -0
  242. package/dist/types/analyze/Builder.d.ts +8 -0
  243. package/dist/types/analyze/constants.d.ts +13 -1
  244. package/dist/types/analyze/generateCode.d.ts +3 -2
  245. package/dist/types/analyze/getBundleEntry.d.ts +2 -2
  246. package/dist/types/analyze/{getClientRoutes.d.ts → getClientRoutes/getRoutes.d.ts} +2 -7
  247. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +15 -0
  248. package/dist/types/analyze/getClientRoutes/index.d.ts +2 -0
  249. package/dist/types/analyze/getClientRoutes/utils.d.ts +5 -0
  250. package/dist/types/analyze/getFileSystemEntry.d.ts +2 -2
  251. package/dist/types/analyze/getHtmlTemplate.d.ts +3 -3
  252. package/dist/types/analyze/getServerRoutes.d.ts +3 -2
  253. package/dist/types/analyze/index.d.ts +3 -40
  254. package/dist/types/analyze/nestedRoutes.d.ts +5 -0
  255. package/dist/types/analyze/templates.d.ts +24 -5
  256. package/dist/types/analyze/utils.d.ts +12 -2
  257. package/dist/types/builder/builderPlugins/compatModern.d.ts +14 -0
  258. package/dist/types/builder/index.d.ts +18 -0
  259. package/dist/types/builder/loaders/routerLoader.d.ts +3 -0
  260. package/dist/types/builder/loaders/serverModuleLoader.d.ts +3 -0
  261. package/dist/types/builder/share.d.ts +26 -0
  262. package/dist/types/builder/webpackPlugins/htmlAsyncChunkPlugin.d.ts +8 -0
  263. package/dist/types/builder/webpackPlugins/htmlBottomTemplate.d.ts +10 -0
  264. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +4 -0
  265. package/dist/types/commands/build.d.ts +2 -1
  266. package/dist/types/commands/deploy.d.ts +2 -1
  267. package/dist/types/commands/dev.d.ts +2 -1
  268. package/dist/types/commands/index.d.ts +1 -1
  269. package/dist/types/commands/inspect.d.ts +10 -6
  270. package/dist/types/commands/serve.d.ts +3 -0
  271. package/dist/types/config/default.d.ts +3 -0
  272. package/dist/types/config/index.d.ts +2 -0
  273. package/dist/types/config/initial/createHtmlConfig.d.ts +2 -0
  274. package/dist/types/config/initial/createOutputConfig.d.ts +2 -0
  275. package/dist/types/config/initial/createSourceConfig.d.ts +2 -0
  276. package/dist/types/config/initial/createToolsConfig.d.ts +2 -0
  277. package/dist/types/config/initial/index.d.ts +4 -0
  278. package/dist/types/config/initial/inits.d.ts +4 -0
  279. package/dist/types/config/initial/transformNormalizedConfig.d.ts +2 -0
  280. package/dist/types/defineConfig.d.ts +8 -0
  281. package/dist/types/hooks.d.ts +2 -37
  282. package/dist/types/index.d.ts +9 -3
  283. package/dist/types/initialize/index.d.ts +5 -0
  284. package/dist/types/locale/en.d.ts +1 -2
  285. package/dist/types/locale/index.d.ts +2 -4
  286. package/dist/types/locale/zh.d.ts +1 -2
  287. package/dist/types/schema/Schema.d.ts +14 -0
  288. package/dist/types/schema/index.d.ts +4 -0
  289. package/dist/types/schema/legacy.d.ts +3 -0
  290. package/dist/types/types/config/deploy.d.ts +9 -0
  291. package/dist/types/types/config/dev.d.ts +13 -0
  292. package/dist/types/types/config/experiments.d.ts +4 -0
  293. package/dist/types/types/config/html.d.ts +4 -0
  294. package/dist/types/types/config/index.d.ts +66 -0
  295. package/dist/types/types/config/output.d.ts +22 -0
  296. package/dist/types/types/config/performance.d.ts +4 -0
  297. package/dist/types/types/config/security.d.ts +4 -0
  298. package/dist/types/types/config/source.d.ts +24 -0
  299. package/dist/types/types/config/tools.d.ts +24 -0
  300. package/dist/types/types/hooks.d.ts +89 -0
  301. package/dist/types/types/index.d.ts +23 -0
  302. package/dist/types/types/legacyConfig/deploy.d.ts +8 -0
  303. package/dist/types/types/legacyConfig/dev.d.ts +13 -0
  304. package/dist/types/types/legacyConfig/index.d.ts +33 -0
  305. package/dist/types/types/legacyConfig/output.d.ts +51 -0
  306. package/dist/types/types/legacyConfig/source.d.ts +25 -0
  307. package/dist/types/types/legacyConfig/tools.d.ts +17 -0
  308. package/dist/types/utils/commands.d.ts +2 -0
  309. package/dist/types/utils/config.d.ts +2 -2
  310. package/dist/types/utils/createFileWatcher.d.ts +4 -0
  311. package/dist/types/utils/createServer.d.ts +9 -1
  312. package/dist/types/utils/getServerInternalPlugins.d.ts +2 -0
  313. package/dist/types/utils/printInstructions.d.ts +3 -2
  314. package/dist/types/utils/restart.d.ts +3 -0
  315. package/dist/types/utils/types.d.ts +2 -3
  316. package/lib/types.d.ts +1 -1
  317. package/package.json +37 -46
  318. package/dist/js/modern/analyze/getClientRoutes.js +0 -219
  319. package/dist/js/modern/commands/start.js +0 -31
  320. package/dist/js/modern/utils/createCompiler.js +0 -61
  321. package/dist/js/node/analyze/getClientRoutes.js +0 -241
  322. package/dist/js/node/commands/start.js +0 -47
  323. package/dist/js/node/utils/createCompiler.js +0 -81
  324. package/dist/types/commands/start.d.ts +0 -2
  325. package/dist/types/utils/createCompiler.d.ts +0 -13
package/bin/modern.js CHANGED
@@ -1,3 +1,15 @@
1
1
  #!/usr/bin/env node
2
+ const {
3
+ INTERNAL_APP_TOOLS_PLUGINS,
4
+ INTERNAL_SERVER_PLUGINS,
5
+ INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
6
+ } = require('@modern-js/utils');
2
7
 
3
- require('@modern-js/core/bin');
8
+ require('@modern-js/core/runBin').run({
9
+ internalPlugins: {
10
+ cli: INTERNAL_APP_TOOLS_PLUGINS,
11
+ server: INTERNAL_SERVER_PLUGINS,
12
+ autoLoad: INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
13
+ },
14
+ toolsType: 'app-tools',
15
+ });
@@ -0,0 +1,39 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { build } from "esbuild";
22
+ class Builder {
23
+ build(options) {
24
+ return __async(this, null, function* () {
25
+ this.buildRes = yield build(options);
26
+ });
27
+ }
28
+ stop() {
29
+ var _a, _b;
30
+ ((_a = this.buildRes) == null ? void 0 : _a.stop) && ((_b = this.buildRes) == null ? void 0 : _b.stop());
31
+ }
32
+ }
33
+ const loaderBuilder = new Builder();
34
+ const serverLoaderBuilder = new Builder();
35
+ export {
36
+ Builder,
37
+ loaderBuilder,
38
+ serverLoaderBuilder
39
+ };
@@ -1,15 +1,48 @@
1
- export const JS_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
2
- export const INDEX_FILE_NAME = 'index';
3
- export const APP_FILE_NAME = 'App';
4
- export const PAGES_DIR_NAME = 'pages';
5
- export const FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
6
- export const ENTRY_POINT_FILE_NAME = 'index.js';
7
- export const ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
8
- export const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
9
- export const FILE_SYSTEM_ROUTES_LAYOUT = '_layout';
10
- export const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = '_app';
11
- export const FILE_SYSTEM_ROUTES_INDEX = 'index';
12
- export const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
13
- export const HTML_PARTIALS_FOLDER = 'html';
14
- export const HTML_PARTIALS_EXTENSIONS = ['.htm', '.html', '.ejs'];
15
- export const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = 'internal_components';
1
+ const JS_EXTENSIONS = [".js", ".ts", ".jsx", ".tsx"];
2
+ const INDEX_FILE_NAME = "index";
3
+ const APP_FILE_NAME = "App";
4
+ const PAGES_DIR_NAME = "pages";
5
+ const NESTED_ROUTES_DIR = "routes";
6
+ const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
7
+ const LOADER_EXPORT_NAME = "loader";
8
+ const TEMP_LOADERS_DIR = "__loaders__";
9
+ const ENTRY_POINT_FILE_NAME = "index.js";
10
+ const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.js";
11
+ const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
12
+ const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
13
+ const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
14
+ const FILE_SYSTEM_ROUTES_INDEX = "index";
15
+ const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
16
+ const HTML_PARTIALS_FOLDER = "html";
17
+ const HTML_PARTIALS_EXTENSIONS = [".htm", ".html", ".ejs"];
18
+ const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
19
+ const NESTED_ROUTE = {
20
+ LAYOUT_FILE: "layout",
21
+ LAYOUT_LOADER_FILE: "layout.loader",
22
+ PAGE_FILE: "page",
23
+ PAGE_LOADER_FILE: "page.loader",
24
+ LOADING_FILE: "loading",
25
+ ERROR_FILE: "error",
26
+ LOADER_FILE: "loader"
27
+ };
28
+ export {
29
+ APP_FILE_NAME,
30
+ ENTRY_BOOTSTRAP_FILE_NAME,
31
+ ENTRY_POINT_FILE_NAME,
32
+ FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
33
+ FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
34
+ FILE_SYSTEM_ROUTES_FILE_NAME,
35
+ FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
36
+ FILE_SYSTEM_ROUTES_IGNORED_REGEX,
37
+ FILE_SYSTEM_ROUTES_INDEX,
38
+ FILE_SYSTEM_ROUTES_LAYOUT,
39
+ HTML_PARTIALS_EXTENSIONS,
40
+ HTML_PARTIALS_FOLDER,
41
+ INDEX_FILE_NAME,
42
+ JS_EXTENSIONS,
43
+ LOADER_EXPORT_NAME,
44
+ NESTED_ROUTE,
45
+ NESTED_ROUTES_DIR,
46
+ PAGES_DIR_NAME,
47
+ TEMP_LOADERS_DIR
48
+ };
@@ -1,18 +1,54 @@
1
- import path from 'path';
2
- import { fs } from '@modern-js/utils';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import path from "path";
22
+ import {
23
+ fs,
24
+ getEntryOptions,
25
+ LOADER_ROUTES_DIR,
26
+ logger
27
+ } from "@modern-js/utils";
28
+ import {
29
+ useResolvedConfigContext
30
+ } from "@modern-js/core";
31
+ import { isDevCommand } from "../utils/commands";
3
32
  import * as templates from "./templates";
4
- import { getClientRoutes } from "./getClientRoutes";
5
- import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
33
+ import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
34
+ import {
35
+ FILE_SYSTEM_ROUTES_FILE_NAME,
36
+ ENTRY_POINT_FILE_NAME,
37
+ ENTRY_BOOTSTRAP_FILE_NAME,
38
+ TEMP_LOADERS_DIR
39
+ } from "./constants";
6
40
  import { getDefaultImports } from "./utils";
7
-
8
- const createImportSpecifier = specifiers => {
9
- let defaults = '';
41
+ import { walk } from "./nestedRoutes";
42
+ import { loaderBuilder, serverLoaderBuilder } from "./Builder";
43
+ const loader = {
44
+ ".js": "jsx",
45
+ ".ts": "tsx"
46
+ };
47
+ const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
48
+ const createImportSpecifier = (specifiers) => {
49
+ let defaults = "";
10
50
  const named = [];
11
-
12
- for (const {
13
- local,
14
- imported
15
- } of specifiers) {
51
+ for (const { local, imported } of specifiers) {
16
52
  if (local && imported) {
17
53
  named.push(`${imported} as ${local}`);
18
54
  } else if (local) {
@@ -21,26 +57,19 @@ const createImportSpecifier = specifiers => {
21
57
  named.push(imported);
22
58
  }
23
59
  }
24
-
25
60
  if (defaults && named.length) {
26
- return `${defaults}, { ${named.join(', ')} }`;
61
+ return `${defaults}, { ${named.join(", ")} }`;
27
62
  } else if (defaults) {
28
63
  return defaults;
29
64
  } else {
30
- return `{ ${named.join(', ')} }`;
65
+ return `{ ${named.join(", ")} }`;
31
66
  }
32
67
  };
33
-
34
- export const createImportStatements = statements => {
35
- // merge import statements with the same value.
68
+ const createImportStatements = (statements) => {
69
+ var _a, _b;
36
70
  const deDuplicated = [];
37
- const seen = new Map();
38
-
39
- for (const {
40
- value,
41
- specifiers,
42
- initialize
43
- } of statements) {
71
+ const seen = /* @__PURE__ */ new Map();
72
+ for (const { value, specifiers, initialize } of statements) {
44
73
  if (!seen.has(value)) {
45
74
  deDuplicated.push({
46
75
  value,
@@ -49,131 +78,255 @@ export const createImportStatements = statements => {
49
78
  });
50
79
  seen.set(value, specifiers);
51
80
  } else {
52
- var _deDuplicated$modifyI, _deDuplicated$modifyI2;
53
-
54
- seen.get(value).push(...specifiers); // make "initialize" param can be connected when multiple plugins were imported from same package
55
-
56
- const modifyIndex = deDuplicated.findIndex(v => v.value === value);
57
- const originInitialize = (_deDuplicated$modifyI = (_deDuplicated$modifyI2 = deDuplicated[modifyIndex]) === null || _deDuplicated$modifyI2 === void 0 ? void 0 : _deDuplicated$modifyI2.initialize) !== null && _deDuplicated$modifyI !== void 0 ? _deDuplicated$modifyI : '';
58
- deDuplicated[modifyIndex].initialize = originInitialize.concat(`\n${initialize || ''}`);
81
+ seen.get(value).push(...specifiers);
82
+ const modifyIndex = deDuplicated.findIndex((v) => v.value === value);
83
+ const originInitialize = (_b = (_a = deDuplicated[modifyIndex]) == null ? void 0 : _a.initialize) != null ? _b : "";
84
+ deDuplicated[modifyIndex].initialize = originInitialize.concat(
85
+ `
86
+ ${initialize || ""}`
87
+ );
59
88
  }
60
89
  }
61
-
62
- return deDuplicated.map(({
63
- value,
64
- specifiers,
65
- initialize
66
- }) => `import ${createImportSpecifier(specifiers)} from '${value}';\n${initialize || ''}`).join('\n');
90
+ return deDuplicated.map(
91
+ ({ value, specifiers, initialize }) => `import ${createImportSpecifier(specifiers)} from '${value}';
92
+ ${initialize || ""}`
93
+ ).join("\n");
67
94
  };
68
- export const generateCode = async (appContext, config, entrypoints, api) => {
95
+ const buildLoader = (entry, outfile) => __async(void 0, null, function* () {
96
+ yield loaderBuilder.build({
97
+ format: "esm",
98
+ platform: "browser",
99
+ target: "esnext",
100
+ loader,
101
+ watch: isDevCommand() && {},
102
+ bundle: true,
103
+ logLevel: "error",
104
+ entryPoints: [entry],
105
+ outfile,
106
+ plugins: [
107
+ {
108
+ name: "make-all-packages-external",
109
+ setup(build) {
110
+ build.onResolve({ filter: EXTERNAL_REGEXP }, (args) => {
111
+ let external = true;
112
+ if (args.kind === "entry-point") {
113
+ external = false;
114
+ }
115
+ return {
116
+ path: args.path,
117
+ external
118
+ };
119
+ });
120
+ }
121
+ }
122
+ ]
123
+ });
124
+ });
125
+ const buildServerLoader = (entry, outfile) => __async(void 0, null, function* () {
126
+ yield serverLoaderBuilder.build({
127
+ format: "cjs",
128
+ platform: "node",
129
+ target: "esnext",
130
+ loader,
131
+ watch: isDevCommand() && {},
132
+ bundle: true,
133
+ logLevel: "error",
134
+ entryPoints: [entry],
135
+ outfile
136
+ });
137
+ });
138
+ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, null, function* () {
139
+ var _a, _b, _c;
69
140
  const {
70
141
  internalDirectory,
142
+ distDirectory,
71
143
  srcDirectory,
72
144
  internalDirAlias,
73
- internalSrcAlias
145
+ internalSrcAlias,
146
+ packageName
74
147
  } = appContext;
75
148
  const hookRunners = api.useHookRunners();
76
- const {
77
- output: {
78
- mountId
79
- }
80
- } = config;
81
-
82
- for (const entrypoint of entrypoints) {
83
- const {
84
- entryName,
85
- isAutoMount,
86
- customBootstrap,
87
- fileSystemRoutes
88
- } = entrypoint;
89
-
90
- if (isAutoMount) {
91
- // generate routes file for file system routes entrypoint.
92
- if (fileSystemRoutes) {
93
- const initialRoutes = getClientRoutes({
149
+ const isV5 = typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
150
+ const { mountId } = config.html;
151
+ const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
152
+ yield Promise.all(entrypoints.map(generateEntryCode));
153
+ function generateEntryCode(entrypoint) {
154
+ return __async(this, null, function* () {
155
+ const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
156
+ if (isAutoMount) {
157
+ if (fileSystemRoutes) {
158
+ let initialRoutes = [];
159
+ let nestedRoute = null;
160
+ if (entrypoint.entry) {
161
+ initialRoutes = getRoutes({
162
+ entrypoint,
163
+ srcDirectory,
164
+ srcAlias: internalSrcAlias,
165
+ internalDirectory,
166
+ internalDirAlias
167
+ });
168
+ }
169
+ if (entrypoint.nestedRoutesEntry) {
170
+ if (!isV5) {
171
+ nestedRoute = yield walk(
172
+ entrypoint.nestedRoutesEntry,
173
+ entrypoint.nestedRoutesEntry,
174
+ {
175
+ name: internalSrcAlias,
176
+ basename: srcDirectory
177
+ },
178
+ entrypoint.entryName
179
+ );
180
+ if (nestedRoute) {
181
+ initialRoutes.unshift(nestedRoute);
182
+ }
183
+ } else {
184
+ logger.error("Nested routes is not supported in legacy mode.");
185
+ process.exit(1);
186
+ }
187
+ }
188
+ const { routes } = yield hookRunners.modifyFileSystemRoutes({
189
+ entrypoint,
190
+ routes: initialRoutes
191
+ });
192
+ const config2 = useResolvedConfigContext();
193
+ const ssr = getEntryOptions(
194
+ entryName,
195
+ config2.server.ssr,
196
+ config2.server.ssrByEntries,
197
+ packageName
198
+ );
199
+ let mode;
200
+ if (ssr) {
201
+ mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
202
+ } else {
203
+ mode = false;
204
+ }
205
+ if (mode === "stream") {
206
+ const hasPageRoute = routes.some(
207
+ (route) => "type" in route && route.type === "page"
208
+ );
209
+ if (hasPageRoute) {
210
+ logger.error(
211
+ "Streaming ssr is not supported when pages dir exists"
212
+ );
213
+ process.exit(1);
214
+ }
215
+ }
216
+ const { code: code2 } = yield hookRunners.beforeGenerateRoutes({
217
+ entrypoint,
218
+ code: yield templates.fileSystemRoutes({
219
+ routes,
220
+ ssrMode: mode,
221
+ nestedRoutesEntry: entrypoint.nestedRoutesEntry,
222
+ entryName: entrypoint.entryName,
223
+ internalDirectory,
224
+ internalDirAlias
225
+ })
226
+ });
227
+ if (entrypoint.nestedRoutesEntry) {
228
+ const routesServerFile = path.join(
229
+ internalDirectory,
230
+ entryName,
231
+ "route-server-loaders.js"
232
+ );
233
+ const outputRoutesServerFile = path.join(
234
+ distDirectory,
235
+ LOADER_ROUTES_DIR,
236
+ entryName,
237
+ "index.js"
238
+ );
239
+ const code3 = templates.routesForServer({
240
+ routes,
241
+ internalDirectory,
242
+ entryName
243
+ });
244
+ yield fs.ensureFile(routesServerFile);
245
+ yield fs.writeFile(routesServerFile, code3);
246
+ const loaderEntryFile = path.join(
247
+ internalDirectory,
248
+ entryName,
249
+ TEMP_LOADERS_DIR,
250
+ "entry.js"
251
+ );
252
+ const loaderIndexFile = path.join(
253
+ internalDirectory,
254
+ entryName,
255
+ TEMP_LOADERS_DIR,
256
+ "index.js"
257
+ );
258
+ if (yield fs.pathExists(loaderEntryFile)) {
259
+ yield buildLoader(loaderEntryFile, loaderIndexFile);
260
+ }
261
+ if (yield fs.pathExists(routesServerFile)) {
262
+ yield buildServerLoader(routesServerFile, outputRoutesServerFile);
263
+ }
264
+ }
265
+ fs.outputFileSync(
266
+ path.resolve(
267
+ internalDirectory,
268
+ `./${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`
269
+ ),
270
+ code2,
271
+ "utf8"
272
+ );
273
+ }
274
+ const { imports: importStatements } = yield hookRunners.modifyEntryImports({
94
275
  entrypoint,
95
- srcDirectory,
96
- srcAlias: internalSrcAlias,
97
- internalDirectory,
98
- internalDirAlias
276
+ imports: getDefaultImports({
277
+ entrypoint,
278
+ srcDirectory,
279
+ internalSrcAlias,
280
+ internalDirAlias,
281
+ internalDirectory
282
+ })
99
283
  });
100
- const {
101
- routes
102
- } = await hookRunners.modifyFileSystemRoutes({
284
+ const { plugins } = yield hookRunners.modifyEntryRuntimePlugins({
103
285
  entrypoint,
104
- routes: initialRoutes
286
+ plugins: []
105
287
  });
106
- const {
107
- code
108
- } = await hookRunners.beforeGenerateRoutes({
288
+ const { code: renderFunction } = yield hookRunners.modifyEntryRenderFunction({
109
289
  entrypoint,
110
- code: templates.fileSystemRoutes({
111
- routes
290
+ code: templates.renderFunction({
291
+ plugins,
292
+ customBootstrap,
293
+ fileSystemRoutes
112
294
  })
113
295
  });
114
- fs.outputFileSync(path.resolve(internalDirectory, `./${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`), code, 'utf8');
115
- } // call modifyEntryImports hook
116
-
117
-
118
- const {
119
- imports: importStatements
120
- } = await hookRunners.modifyEntryImports({
121
- entrypoint,
122
- imports: getDefaultImports({
123
- entrypoint,
124
- srcDirectory,
125
- internalSrcAlias,
126
- internalDirAlias,
127
- internalDirectory
128
- })
129
- }); // call modifyEntryRuntimePlugins hook
130
-
131
- const {
132
- plugins
133
- } = await hookRunners.modifyEntryRuntimePlugins({
134
- entrypoint,
135
- plugins: []
136
- }); // call modifyEntryRenderFunction hook
137
-
138
- const {
139
- code: renderFunction
140
- } = await hookRunners.modifyEntryRenderFunction({
141
- entrypoint,
142
- code: templates.renderFunction({
143
- plugins,
144
- customBootstrap,
145
- fileSystemRoutes
146
- })
147
- }); // call modifyEntryExport hook
148
-
149
- const {
150
- exportStatement
151
- } = await hookRunners.modifyEntryExport({
152
- entrypoint,
153
- exportStatement: 'export default AppWrapper;'
154
- });
155
- const code = templates.index({
156
- mountId: mountId,
157
- imports: createImportStatements(importStatements),
158
- renderFunction,
159
- exportStatement
160
- });
161
- const entryFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
162
- entrypoint.entry = entryFile; // generate entry file.
163
-
164
- if (config.source.enableAsyncEntry) {
165
- const {
166
- code: asyncEntryCode
167
- } = await hookRunners.modifyAsyncEntry({
296
+ const { exportStatement } = yield hookRunners.modifyEntryExport({
168
297
  entrypoint,
169
- code: `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`
298
+ exportStatement: "export default AppWrapper;"
170
299
  });
171
- fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
172
- const bootstrapFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
173
- fs.outputFileSync(bootstrapFile, code, 'utf8');
174
- } else {
175
- fs.outputFileSync(entryFile, code, 'utf8');
300
+ const code = templates.index({
301
+ mountId,
302
+ imports: createImportStatements(importStatements),
303
+ renderFunction,
304
+ exportStatement
305
+ });
306
+ const entryFile = path.resolve(
307
+ internalDirectory,
308
+ `./${entryName}/${ENTRY_POINT_FILE_NAME}`
309
+ );
310
+ entrypoint.entry = entryFile;
311
+ if (config.source.enableAsyncEntry) {
312
+ const { code: asyncEntryCode } = yield hookRunners.modifyAsyncEntry({
313
+ entrypoint,
314
+ code: `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`
315
+ });
316
+ fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
317
+ const bootstrapFile = path.resolve(
318
+ internalDirectory,
319
+ `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`
320
+ );
321
+ fs.outputFileSync(bootstrapFile, code, "utf8");
322
+ } else {
323
+ fs.outputFileSync(entryFile, code, "utf8");
324
+ }
176
325
  }
177
- }
326
+ });
178
327
  }
179
- };
328
+ });
329
+ export {
330
+ createImportStatements,
331
+ generateCode
332
+ };