@modern-js/app-tools 2.6.0 → 2.7.1-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 (322) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/analyze/generateCode.js +7 -7
  4. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +1 -1
  5. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  6. package/dist/cjs/analyze/index.js +20 -2
  7. package/dist/cjs/analyze/nestedRoutes.js +1 -1
  8. package/dist/cjs/analyze/templates.js +6 -4
  9. package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
  10. package/dist/cjs/builder/generator/index.js +10 -2
  11. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +101 -0
  12. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +91 -0
  13. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +140 -0
  14. package/dist/cjs/builder/shared/builderPlugins/index.js +19 -0
  15. package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
  16. package/dist/cjs/builder/shared/bundlerPlugins/index.js +19 -0
  17. package/dist/cjs/builder/shared/index.js +1 -1
  18. package/dist/cjs/commands/dev.js +6 -0
  19. package/dist/cjs/commands/serve.js +17 -0
  20. package/dist/cjs/index.js +1 -1
  21. package/dist/cjs/locale/en.js +1 -0
  22. package/dist/cjs/locale/zh.js +1 -0
  23. package/dist/cjs/schema/index.js +4 -0
  24. package/dist/esm/analyze/generateCode.js +8 -9
  25. package/dist/esm/analyze/getClientRoutes/getRoutes.js +1 -1
  26. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  27. package/dist/esm/analyze/index.js +15 -3
  28. package/dist/esm/analyze/nestedRoutes.js +1 -1
  29. package/dist/esm/analyze/templates.js +6 -5
  30. package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +0 -11
  31. package/dist/esm/builder/generator/index.js +6 -4
  32. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +101 -0
  33. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +120 -0
  34. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +131 -0
  35. package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
  36. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +350 -0
  37. package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
  38. package/dist/esm/builder/shared/index.js +1 -1
  39. package/dist/esm/commands/dev.js +6 -0
  40. package/dist/esm/commands/serve.js +6 -1
  41. package/dist/esm/index.js +1 -1
  42. package/dist/esm/locale/en.js +1 -0
  43. package/dist/esm/locale/zh.js +1 -0
  44. package/dist/esm/schema/index.js +7 -0
  45. package/dist/esm-node/analyze/generateCode.js +14 -9
  46. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +1 -1
  47. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  48. package/dist/esm-node/analyze/index.js +22 -3
  49. package/dist/esm-node/analyze/nestedRoutes.js +1 -1
  50. package/dist/esm-node/analyze/templates.js +6 -4
  51. package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
  52. package/dist/esm-node/builder/generator/index.js +10 -2
  53. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +67 -0
  54. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +67 -0
  55. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +119 -0
  56. package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
  57. package/dist/esm-node/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
  58. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
  59. package/dist/esm-node/builder/shared/index.js +1 -1
  60. package/dist/esm-node/commands/dev.js +6 -0
  61. package/dist/esm-node/commands/serve.js +18 -1
  62. package/dist/esm-node/index.js +1 -1
  63. package/dist/esm-node/locale/en.js +1 -0
  64. package/dist/esm-node/locale/zh.js +1 -0
  65. package/dist/esm-node/schema/index.js +4 -0
  66. package/dist/js/modern/analyze/constants.js +54 -0
  67. package/dist/js/modern/analyze/generateCode.js +247 -0
  68. package/dist/js/modern/analyze/getBundleEntry.js +71 -0
  69. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +220 -0
  70. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +216 -0
  71. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -0
  72. package/dist/js/modern/analyze/getClientRoutes/utils.js +31 -0
  73. package/dist/js/modern/analyze/getFileSystemEntry.js +109 -0
  74. package/dist/js/modern/analyze/getHtmlTemplate.js +115 -0
  75. package/dist/js/modern/analyze/getServerRoutes.js +175 -0
  76. package/dist/js/modern/analyze/index.js +332 -0
  77. package/dist/js/modern/analyze/isDefaultExportFunction.js +42 -0
  78. package/dist/js/modern/analyze/makeLegalIdentifier.js +13 -0
  79. package/dist/js/modern/analyze/nestedRoutes.js +157 -0
  80. package/dist/js/modern/analyze/templates.js +334 -0
  81. package/dist/js/modern/analyze/utils.js +141 -0
  82. package/dist/{esm-node/builder/shared/builderPlugins/adapterModern.js → js/modern/builder/builderPlugins/compatModern.js} +135 -104
  83. package/dist/js/modern/builder/index.js +159 -0
  84. package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
  85. package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
  86. package/dist/js/modern/builder/share.js +46 -0
  87. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +30 -0
  88. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +37 -0
  89. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +113 -0
  90. package/dist/js/modern/commands/build.js +91 -0
  91. package/dist/js/modern/commands/deploy.js +28 -0
  92. package/dist/js/modern/commands/dev.js +109 -0
  93. package/dist/js/modern/commands/index.js +3 -0
  94. package/dist/js/modern/commands/inspect.js +38 -0
  95. package/dist/js/modern/commands/serve.js +54 -0
  96. package/dist/js/modern/config/default.js +175 -0
  97. package/dist/js/modern/config/index.js +8 -0
  98. package/dist/js/modern/config/initial/createHtmlConfig.js +35 -0
  99. package/dist/js/modern/config/initial/createOutputConfig.js +68 -0
  100. package/dist/js/modern/config/initial/createSourceConfig.js +39 -0
  101. package/dist/js/modern/config/initial/createToolsConfig.js +42 -0
  102. package/dist/js/modern/config/initial/index.js +16 -0
  103. package/dist/js/modern/config/initial/inits.js +152 -0
  104. package/dist/js/modern/config/initial/transformNormalizedConfig.js +47 -0
  105. package/dist/js/modern/defineConfig.js +27 -0
  106. package/dist/js/modern/exports/server.js +4 -0
  107. package/dist/js/modern/hooks.js +35 -0
  108. package/dist/js/modern/index.js +211 -0
  109. package/dist/js/modern/initialize/index.js +124 -0
  110. package/dist/js/modern/locale/en.js +36 -0
  111. package/dist/js/modern/locale/index.js +9 -0
  112. package/dist/js/modern/locale/zh.js +36 -0
  113. package/dist/js/modern/schema/Schema.js +40 -0
  114. package/dist/js/modern/schema/index.js +88 -0
  115. package/dist/js/modern/schema/legacy.js +148 -0
  116. package/dist/js/modern/types/config/deploy.js +0 -0
  117. package/dist/js/modern/types/config/dev.js +0 -0
  118. package/dist/js/modern/types/config/experiments.js +0 -0
  119. package/dist/js/modern/types/config/html.js +0 -0
  120. package/dist/js/modern/types/config/index.js +1 -0
  121. package/dist/js/modern/types/config/output.js +0 -0
  122. package/dist/js/modern/types/config/performance.js +0 -0
  123. package/dist/js/modern/types/config/security.js +0 -0
  124. package/dist/js/modern/types/config/source.js +0 -0
  125. package/dist/js/modern/types/config/tools.js +0 -0
  126. package/dist/js/modern/types/hooks.js +0 -0
  127. package/dist/js/modern/types/index.js +3 -0
  128. package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
  129. package/dist/js/modern/types/legacyConfig/dev.js +0 -0
  130. package/dist/js/modern/types/legacyConfig/index.js +0 -0
  131. package/dist/js/modern/types/legacyConfig/output.js +0 -0
  132. package/dist/js/modern/types/legacyConfig/source.js +0 -0
  133. package/dist/js/modern/types/legacyConfig/tools.js +0 -0
  134. package/dist/js/modern/utils/config.js +128 -0
  135. package/dist/js/modern/utils/createServer.js +75 -0
  136. package/dist/js/modern/utils/env.js +15 -0
  137. package/dist/js/modern/utils/generateWatchFiles.js +55 -0
  138. package/dist/js/modern/utils/getSelectedEntries.js +58 -0
  139. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  140. package/dist/js/modern/utils/language.js +8 -0
  141. package/dist/js/modern/utils/printInstructions.js +31 -0
  142. package/dist/js/modern/utils/restart.js +44 -0
  143. package/dist/js/modern/utils/routes.js +30 -0
  144. package/dist/js/modern/utils/types.js +0 -0
  145. package/dist/js/node/analyze/constants.js +98 -0
  146. package/dist/js/node/analyze/generateCode.js +271 -0
  147. package/dist/js/node/analyze/getBundleEntry.js +95 -0
  148. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +242 -0
  149. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +238 -0
  150. package/dist/js/node/analyze/getClientRoutes/index.js +30 -0
  151. package/dist/js/node/analyze/getClientRoutes/utils.js +58 -0
  152. package/dist/js/node/analyze/getFileSystemEntry.js +131 -0
  153. package/dist/js/node/analyze/getHtmlTemplate.js +144 -0
  154. package/dist/js/node/analyze/getServerRoutes.js +194 -0
  155. package/dist/js/node/analyze/index.js +339 -0
  156. package/dist/js/node/analyze/isDefaultExportFunction.js +71 -0
  157. package/dist/js/node/analyze/makeLegalIdentifier.js +36 -0
  158. package/dist/js/node/analyze/nestedRoutes.js +184 -0
  159. package/dist/js/node/analyze/templates.js +365 -0
  160. package/dist/js/node/analyze/utils.js +172 -0
  161. package/dist/{cjs/builder/shared/builderPlugins/adapterModern.js → js/node/builder/builderPlugins/compatModern.js} +137 -113
  162. package/dist/js/node/builder/index.js +177 -0
  163. package/dist/js/node/builder/loaders/routerLoader.js +38 -0
  164. package/dist/js/node/builder/loaders/serverModuleLoader.js +28 -0
  165. package/dist/js/node/builder/share.js +75 -0
  166. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +53 -0
  167. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +60 -0
  168. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +135 -0
  169. package/dist/js/node/commands/build.js +112 -0
  170. package/dist/js/node/commands/deploy.js +51 -0
  171. package/dist/js/node/commands/dev.js +126 -0
  172. package/dist/js/node/commands/index.js +19 -0
  173. package/dist/js/node/commands/inspect.js +61 -0
  174. package/dist/js/node/commands/serve.js +83 -0
  175. package/dist/js/node/config/default.js +197 -0
  176. package/dist/js/node/config/index.js +34 -0
  177. package/dist/js/node/config/initial/createHtmlConfig.js +58 -0
  178. package/dist/js/node/config/initial/createOutputConfig.js +91 -0
  179. package/dist/js/node/config/initial/createSourceConfig.js +62 -0
  180. package/dist/js/node/config/initial/createToolsConfig.js +65 -0
  181. package/dist/js/node/config/initial/index.js +41 -0
  182. package/dist/js/node/config/initial/inits.js +175 -0
  183. package/dist/js/node/config/initial/transformNormalizedConfig.js +70 -0
  184. package/dist/js/node/defineConfig.js +49 -0
  185. package/dist/js/node/exports/server.js +27 -0
  186. package/dist/js/node/hooks.js +54 -0
  187. package/dist/js/node/index.js +235 -0
  188. package/dist/js/node/initialize/index.js +134 -0
  189. package/dist/js/node/locale/en.js +59 -0
  190. package/dist/js/node/locale/index.js +33 -0
  191. package/dist/js/node/locale/zh.js +59 -0
  192. package/dist/js/node/schema/Schema.js +63 -0
  193. package/dist/js/node/schema/index.js +118 -0
  194. package/dist/js/node/schema/legacy.js +169 -0
  195. package/dist/js/node/types/config/deploy.js +15 -0
  196. package/dist/js/node/types/config/dev.js +15 -0
  197. package/dist/js/node/types/config/experiments.js +15 -0
  198. package/dist/js/node/types/config/html.js +15 -0
  199. package/dist/{cjs/builder/builder-webpack/webpackPlugins → js/node/types/config}/index.js +3 -3
  200. package/dist/js/node/types/config/output.js +15 -0
  201. package/dist/js/node/types/config/performance.js +15 -0
  202. package/dist/js/node/types/config/security.js +15 -0
  203. package/dist/js/node/types/config/source.js +15 -0
  204. package/dist/js/node/types/config/tools.js +15 -0
  205. package/dist/js/node/types/hooks.js +15 -0
  206. package/dist/js/node/types/index.js +19 -0
  207. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  208. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  209. package/dist/js/node/types/legacyConfig/index.js +15 -0
  210. package/dist/js/node/types/legacyConfig/output.js +15 -0
  211. package/dist/js/node/types/legacyConfig/source.js +15 -0
  212. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  213. package/dist/js/node/utils/config.js +153 -0
  214. package/dist/js/node/utils/createServer.js +106 -0
  215. package/dist/js/node/utils/env.js +38 -0
  216. package/dist/js/node/utils/generateWatchFiles.js +85 -0
  217. package/dist/js/node/utils/getSelectedEntries.js +81 -0
  218. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  219. package/dist/js/node/utils/language.js +31 -0
  220. package/dist/js/node/utils/printInstructions.js +54 -0
  221. package/dist/js/node/utils/restart.js +67 -0
  222. package/dist/js/node/utils/routes.js +59 -0
  223. package/dist/js/node/utils/types.js +15 -0
  224. package/dist/js/treeshaking/analyze/constants.js +40 -0
  225. package/dist/js/treeshaking/analyze/generateCode.js +485 -0
  226. package/dist/js/treeshaking/analyze/getBundleEntry.js +62 -0
  227. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +233 -0
  228. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
  229. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -0
  230. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +23 -0
  231. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +107 -0
  232. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +302 -0
  233. package/dist/js/treeshaking/analyze/getServerRoutes.js +222 -0
  234. package/dist/js/treeshaking/analyze/index.js +697 -0
  235. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +47 -0
  236. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -0
  237. package/dist/js/treeshaking/analyze/nestedRoutes.js +384 -0
  238. package/dist/js/treeshaking/analyze/templates.js +468 -0
  239. package/dist/js/treeshaking/analyze/utils.js +374 -0
  240. package/dist/{esm/builder/shared/builderPlugins/adapterModern.js → js/treeshaking/builder/builderPlugins/compatModern.js} +142 -138
  241. package/dist/js/treeshaking/builder/index.js +374 -0
  242. package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
  243. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
  244. package/dist/js/treeshaking/builder/share.js +40 -0
  245. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +110 -0
  246. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +72 -0
  247. package/dist/{esm/builder/builder-webpack/webpackPlugins/RouterPlugin.js → js/treeshaking/builder/webpackPlugins/routerPlugin.js} +3 -6
  248. package/dist/js/treeshaking/commands/build.js +291 -0
  249. package/dist/js/treeshaking/commands/deploy.js +154 -0
  250. package/dist/js/treeshaking/commands/dev.js +301 -0
  251. package/dist/js/treeshaking/commands/index.js +3 -0
  252. package/dist/js/treeshaking/commands/inspect.js +149 -0
  253. package/dist/js/treeshaking/commands/serve.js +199 -0
  254. package/dist/js/treeshaking/config/default.js +210 -0
  255. package/dist/js/treeshaking/config/index.js +3 -0
  256. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -0
  257. package/dist/js/treeshaking/config/initial/createOutputConfig.js +41 -0
  258. package/dist/js/treeshaking/config/initial/createSourceConfig.js +42 -0
  259. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -0
  260. package/dist/js/treeshaking/config/initial/index.js +12 -0
  261. package/dist/js/treeshaking/config/initial/inits.js +209 -0
  262. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +35 -0
  263. package/dist/js/treeshaking/defineConfig.js +61 -0
  264. package/dist/js/treeshaking/exports/server.js +2 -0
  265. package/dist/js/treeshaking/hooks.js +29 -0
  266. package/dist/js/treeshaking/index.js +706 -0
  267. package/dist/js/treeshaking/initialize/index.js +276 -0
  268. package/dist/js/treeshaking/locale/en.js +38 -0
  269. package/dist/js/treeshaking/locale/index.js +9 -0
  270. package/dist/js/treeshaking/locale/zh.js +38 -0
  271. package/dist/js/treeshaking/schema/Schema.js +273 -0
  272. package/dist/js/treeshaking/schema/index.js +181 -0
  273. package/dist/js/treeshaking/schema/legacy.js +337 -0
  274. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  275. package/dist/js/treeshaking/types/config/dev.js +1 -0
  276. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  277. package/dist/js/treeshaking/types/config/html.js +1 -0
  278. package/dist/js/treeshaking/types/config/index.js +1 -0
  279. package/dist/js/treeshaking/types/config/output.js +1 -0
  280. package/dist/js/treeshaking/types/config/performance.js +1 -0
  281. package/dist/js/treeshaking/types/config/security.js +1 -0
  282. package/dist/js/treeshaking/types/config/source.js +1 -0
  283. package/dist/js/treeshaking/types/config/tools.js +1 -0
  284. package/dist/js/treeshaking/types/hooks.js +1 -0
  285. package/dist/js/treeshaking/types/index.js +3 -0
  286. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  287. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  288. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  289. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
  290. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  291. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  292. package/dist/js/treeshaking/utils/config.js +302 -0
  293. package/dist/js/treeshaking/utils/createServer.js +258 -0
  294. package/dist/js/treeshaking/utils/env.js +13 -0
  295. package/dist/js/treeshaking/utils/generateWatchFiles.js +214 -0
  296. package/dist/js/treeshaking/utils/getSelectedEntries.js +186 -0
  297. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  298. package/dist/js/treeshaking/utils/language.js +6 -0
  299. package/dist/js/treeshaking/utils/printInstructions.js +152 -0
  300. package/dist/js/treeshaking/utils/restart.js +187 -0
  301. package/dist/js/treeshaking/utils/routes.js +153 -0
  302. package/dist/js/treeshaking/utils/types.js +1 -0
  303. package/dist/types/analyze/templates.d.ts +5 -3
  304. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +7 -0
  305. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +5 -0
  306. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +4 -0
  307. package/dist/types/builder/shared/builderPlugins/index.d.ts +3 -0
  308. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +5 -0
  309. package/dist/types/builder/shared/bundlerPlugins/index.d.ts +3 -0
  310. package/dist/types/builder/shared/index.d.ts +1 -1
  311. package/dist/types/builder/shared/types.d.ts +7 -4
  312. package/dist/types/locale/en.d.ts +1 -0
  313. package/dist/types/locale/index.d.ts +2 -0
  314. package/dist/types/locale/zh.d.ts +1 -0
  315. package/dist/types/types/config/output.d.ts +3 -15
  316. package/lib/types.d.ts +1 -1
  317. package/package.json +28 -28
  318. package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +0 -1
  319. package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +0 -1
  320. package/dist/types/builder/builder-webpack/webpackPlugins/RouterPlugin.d.ts +0 -4
  321. package/dist/types/builder/builder-webpack/webpackPlugins/index.d.ts +0 -1
  322. package/dist/types/builder/shared/builderPlugins/adapterModern.d.ts +0 -13
package/CHANGELOG.md CHANGED
@@ -1,5 +1,57 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 2.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - dcad887024: feat: support deferred data for streaming ssr
8
+ feat: 流式渲染支持 deferred data
9
+ - 84bfb439b8: feat: support custom apiDir, lambdaDir and style of writing for bff
10
+ feat: 支持定制 api 目录,lambda 目录,bff 的写法
11
+
12
+ ### Patch Changes
13
+
14
+ - 0644f90567: feat: support optional params in file-based route
15
+ feat: 约定式路由支持可选参数
16
+ - 6547de8dd4: fix: use api.useResolvedConfigContext instead useResolvedConfigContext from @modern-js/core
17
+ fix: 使用 api.useResolvedConfigContext 代替从 @modern-js/core 中导出的 useResolvedConfigContext
18
+ - 1eea234fdd: chore: make test files naming consistent
19
+
20
+ chore: 统一测试文件命名为小驼峰格式
21
+
22
+ - Updated dependencies [206c806efa]
23
+ - Updated dependencies [a729b0d366]
24
+ - Updated dependencies [dfece9dc1c]
25
+ - Updated dependencies [6378e26bf9]
26
+ - Updated dependencies [0f15fc597c]
27
+ - Updated dependencies [3a942a2472]
28
+ - Updated dependencies [5f899af53a]
29
+ - Updated dependencies [dcad887024]
30
+ - Updated dependencies [a4672f7c16]
31
+ - Updated dependencies [1b913372b4]
32
+ - Updated dependencies [ebe0d2dd6e]
33
+ - Updated dependencies [7fff9020e1]
34
+ - Updated dependencies [1eea234fdd]
35
+ - Updated dependencies [84bfb439b8]
36
+ - @modern-js/builder-rspack-provider@2.7.0
37
+ - @modern-js/builder-shared@2.7.0
38
+ - @modern-js/builder-webpack-provider@2.7.0
39
+ - @modern-js/core@2.7.0
40
+ - @modern-js/builder@2.7.0
41
+ - @modern-js/server@2.7.0
42
+ - @modern-js/utils@2.7.0
43
+ - @modern-js/plugin-data-loader@2.7.0
44
+ - @modern-js/types@2.7.0
45
+ - @modern-js/plugin-i18n@2.7.0
46
+ - @modern-js/plugin-lint@2.7.0
47
+ - @modern-js/prod-server@2.7.0
48
+ - @modern-js/node-bundle-require@2.7.0
49
+ - @modern-js/builder-plugin-esbuild@2.7.0
50
+ - @modern-js/builder-plugin-node-polyfill@2.7.0
51
+ - @modern-js/new-action@2.7.0
52
+ - @modern-js/upgrade@2.7.0
53
+ - @modern-js/plugin@2.7.0
54
+
3
55
  ## 2.6.0
4
56
 
5
57
  ### Patch Changes
package/README.md CHANGED
@@ -19,8 +19,8 @@ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-sta
19
19
 
20
20
  ## Contributing
21
21
 
22
- Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
23
 
24
24
  ## License
25
25
 
26
- Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -33,7 +33,6 @@ __export(generateCode_exports, {
33
33
  module.exports = __toCommonJS(generateCode_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
- var import_core = require("@modern-js/core");
37
36
  var templates = __toESM(require("./templates"));
38
37
  var import_getClientRoutes = require("./getClientRoutes");
39
38
  var import_constants = require("./constants");
@@ -100,6 +99,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
100
99
  const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
101
100
  await Promise.all(entrypoints.map(generateEntryCode));
102
101
  async function generateEntryCode(entrypoint) {
102
+ var _a;
103
103
  const { entryName, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
104
104
  if (isAutoMount) {
105
105
  if (fileSystemRoutes) {
@@ -132,18 +132,17 @@ const generateCode = async (appContext, config, entrypoints, api) => {
132
132
  entrypoint,
133
133
  routes: initialRoutes
134
134
  });
135
- const config2 = (0, import_core.useResolvedConfigContext)();
135
+ const config2 = api.useResolvedConfigContext();
136
136
  const ssr = (0, import_utils.getEntryOptions)(
137
137
  entryName,
138
138
  config2.server.ssr,
139
139
  config2.server.ssrByEntries,
140
140
  packageName
141
141
  );
142
+ const useSSG = (0, import_utils.isSSGEntry)(config2, entryName, entrypoints);
142
143
  let mode;
143
144
  if (ssr) {
144
145
  mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
145
- } else {
146
- mode = false;
147
146
  }
148
147
  if (mode === "stream") {
149
148
  const hasPageRoute = routes.some(
@@ -160,13 +159,14 @@ const generateCode = async (appContext, config, entrypoints, api) => {
160
159
  entrypoint,
161
160
  code: await templates.fileSystemRoutes({
162
161
  routes,
163
- ssrMode: mode,
162
+ ssrMode: useSSG ? "string" : mode,
164
163
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
165
164
  entryName: entrypoint.entryName,
166
- internalDirectory
165
+ internalDirectory,
166
+ splitRoutesChunks: (_a = config2 == null ? void 0 : config2.output) == null ? void 0 : _a.splitRoutesChunks
167
167
  })
168
168
  });
169
- if (entrypoint.nestedRoutesEntry && mode) {
169
+ if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
170
170
  const routesServerFile = (0, import_utils2.getServerLoadersFile)(
171
171
  internalDirectory,
172
172
  entryName
@@ -97,7 +97,7 @@ const recursiveReadDir = ({
97
97
  }
98
98
  }
99
99
  const route = {
100
- path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
100
+ path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1].replace(/\$$/, "?")}${dynamicRouteMatched[2]}` : filename}`,
101
101
  _component: alias,
102
102
  component: componentName,
103
103
  parent,
@@ -97,7 +97,7 @@ const recursiveReadDirLegacy = ({
97
97
  }
98
98
  }
99
99
  const route = {
100
- path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
100
+ path: `${basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1].replace(/\$$/, "?")}${dynamicRouteMatched[2]}` : filename}`,
101
101
  _component: alias,
102
102
  component: componentName,
103
103
  exact: true,
@@ -33,6 +33,7 @@ module.exports = __toCommonJS(analyze_exports);
33
33
  var path = __toESM(require("path"));
34
34
  var import_utils = require("@modern-js/utils");
35
35
  var import_lodash = require("@modern-js/utils/lodash");
36
+ var import_builder_shared = require("@modern-js/builder-shared");
36
37
  var import_printInstructions = require("../utils/printInstructions");
37
38
  var import_routes = require("../utils/routes");
38
39
  var import_config = require("../utils/config");
@@ -204,12 +205,21 @@ var analyze_default = ({
204
205
  resolvedConfig.server.ssrByEntries,
205
206
  packageName
206
207
  );
207
- if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
208
+ const useSSG = (0, import_utils.isSSGEntry)(
209
+ resolvedConfig,
210
+ entryName,
211
+ entrypoints
212
+ );
213
+ if (entrypoint.nestedRoutesEntry && (ssr || useSSG) && name === "server") {
214
+ const serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
208
215
  const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
209
216
  internalDirectory,
210
217
  entryName
211
218
  );
212
- chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
219
+ const combinedModule = (0, import_builder_shared.createVirtualModule)(
220
+ `export * from "${serverLoaderRuntime}"; export * from "${serverLoadersFile}"`
221
+ );
222
+ chain.entry(`${entryName}-server-loaders`).add(combinedModule);
213
223
  }
214
224
  });
215
225
  }
@@ -274,6 +284,14 @@ var analyze_default = ({
274
284
  imports
275
285
  };
276
286
  },
287
+ validateSchema() {
288
+ return {
289
+ target: "output.splitRoutesChunks",
290
+ schema: {
291
+ type: "boolean"
292
+ }
293
+ };
294
+ },
277
295
  async fileChange(e) {
278
296
  const appContext = api.useAppContext();
279
297
  const { appDirectory } = appContext;
@@ -79,7 +79,7 @@ const walk = async (dirname, rootDir, alias, entryName) => {
79
79
  }
80
80
  routePath = replaceDynamicPath(routePath);
81
81
  const route = {
82
- path: routePath,
82
+ path: routePath == null ? void 0 : routePath.replace(/\$$/, "?"),
83
83
  children: [],
84
84
  isRoot
85
85
  };
@@ -180,12 +180,14 @@ const fileSystemRoutes = async ({
180
180
  ssrMode,
181
181
  nestedRoutesEntry,
182
182
  entryName,
183
- internalDirectory
183
+ internalDirectory,
184
+ splitRoutesChunks = true
184
185
  }) => {
185
186
  const loadings = [];
186
187
  const errors = [];
187
188
  const loaders = [];
188
189
  const loadersMap = {};
190
+ const webpackMode = splitRoutesChunks ? "lazy" : "eager";
189
191
  const loadersMapFile = import_path.default.join(
190
192
  internalDirectory,
191
193
  entryName,
@@ -244,15 +246,15 @@ const fileSystemRoutes = async ({
244
246
  rootLayoutCode = `import RootLayout from '${route._component}'`;
245
247
  component = `RootLayout`;
246
248
  } else if (ssrMode === "string") {
247
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
249
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ /* webpackMode: "${webpackMode}" */ '${route._component}')`;
248
250
  component = `loadable(${lazyImport})`;
249
251
  } else {
250
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
252
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ /* webpackMode: "${webpackMode}" */ '${route._component}')`;
251
253
  component = `lazy(${lazyImport})`;
252
254
  }
253
255
  }
254
256
  } else if (route._component) {
255
- lazyImport = `() => import('${route._component}')`;
257
+ lazyImport = `() => import( /* webpackMode: "${webpackMode}" */ '${route._component}')`;
256
258
  component = `loadable(${lazyImport})`;
257
259
  }
258
260
  const finalRoute = {
@@ -22,13 +22,11 @@ __export(compatModern_exports, {
22
22
  module.exports = __toCommonJS(compatModern_exports);
23
23
  var import_path = require("path");
24
24
  var import_shared = require("../../shared");
25
- var import_webpackPlugins = require("../webpackPlugins");
26
25
  const builderPluginCompatModern = (options) => ({
27
26
  name: "builder-plugin-compat-modern",
28
27
  setup(api) {
29
28
  const { normalizedConfig: modernConfig, appContext } = options;
30
29
  api.modifyWebpackChain((chain, { CHAIN_ID }) => {
31
- var _a;
32
30
  chain.resolve.modules.add("node_modules").add((0, import_path.join)(api.context.rootPath, "node_modules"));
33
31
  if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
34
32
  const defaultCopyPattern = (0, import_shared.createCopyPattern)(
@@ -38,23 +36,14 @@ const builderPluginCompatModern = (options) => ({
38
36
  chain
39
37
  );
40
38
  chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
41
- var _a2;
39
+ var _a;
42
40
  return [
43
41
  {
44
- patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
42
+ patterns: [...((_a = args[0]) == null ? void 0 : _a.patterns) || [], defaultCopyPattern]
45
43
  }
46
44
  ];
47
45
  });
48
46
  }
49
- const { entrypoints } = appContext;
50
- const existNestedRoutes = entrypoints.some(
51
- (entrypoint) => entrypoint.nestedRoutesEntry
52
- );
53
- const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
54
- const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
55
- if (existNestedRoutes || routerManifest) {
56
- chain.plugin("route-plugin").use(import_webpackPlugins.RouterPlugin);
57
- }
58
47
  });
59
48
  }
60
49
  });
@@ -53,8 +53,16 @@ async function generateBuilder(options, generateProvider, utils) {
53
53
  return builder;
54
54
  }
55
55
  async function applyBuilderPlugins(builder, options) {
56
- const { builderPluginAdapterModern } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins/adapterModern")));
57
- builder.addPlugins([builderPluginAdapterModern(options)]);
56
+ const {
57
+ builderPluginAdapterBasic,
58
+ builderPluginAdapterHtml,
59
+ builderPluginAdapterSSR
60
+ } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins")));
61
+ builder.addPlugins([
62
+ builderPluginAdapterBasic(options),
63
+ builderPluginAdapterSSR(options),
64
+ builderPluginAdapterHtml(options)
65
+ ]);
58
66
  }
59
67
  // Annotate the CommonJS export names for ESM import in node:
60
68
  0 && (module.exports = {
@@ -0,0 +1,101 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var adapterBasic_exports = {};
29
+ __export(adapterBasic_exports, {
30
+ applyCallbacks: () => applyCallbacks,
31
+ builderPluginAdapterBasic: () => builderPluginAdapterBasic
32
+ });
33
+ module.exports = __toCommonJS(adapterBasic_exports);
34
+ const builderPluginAdapterBasic = (options) => ({
35
+ name: "builder-plugin-adapter-modern-basic",
36
+ setup(api) {
37
+ api.modifyBundlerChain((chain, { target, CHAIN_ID }) => {
38
+ if (target === "node") {
39
+ chain.name("server");
40
+ } else if (target === "service-worker") {
41
+ chain.name("service-worker");
42
+ } else if (target === "web-worker") {
43
+ chain.name("worker");
44
+ } else if (target === "modern-web") {
45
+ chain.name("modern");
46
+ } else {
47
+ chain.name("client");
48
+ }
49
+ if (target === "node" || target === "service-worker") {
50
+ applyNodeCompat(target, chain);
51
+ }
52
+ if (target === "web" || target === "modern-web") {
53
+ const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
54
+ chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
55
+ chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
56
+ }
57
+ });
58
+ applyCallbacks(api, options);
59
+ }
60
+ });
61
+ function applyCallbacks(api, options) {
62
+ options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
63
+ options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
64
+ options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
65
+ options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
66
+ options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
67
+ options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
68
+ options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
69
+ options.onExit && api.onExit(options.onExit);
70
+ }
71
+ function applyNodeCompat(target, chain) {
72
+ const nodeExts = [
73
+ ".node.js",
74
+ ".node.jsx",
75
+ ".node.ts",
76
+ ".node.tsx",
77
+ ".server.js",
78
+ ".server.ts",
79
+ ".server.ts",
80
+ ".server.tsx"
81
+ ];
82
+ const webWorkerExts = [
83
+ ".worker.js",
84
+ ".worker.jsx",
85
+ ".worker.ts",
86
+ ".worker.tsx"
87
+ ];
88
+ for (const ext of nodeExts) {
89
+ chain.resolve.extensions.prepend(ext);
90
+ }
91
+ if (target === "service-worker") {
92
+ for (const ext of webWorkerExts) {
93
+ chain.resolve.extensions.prepend(ext);
94
+ }
95
+ }
96
+ }
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ applyCallbacks,
100
+ builderPluginAdapterBasic
101
+ });
@@ -0,0 +1,91 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var adapterHtml_exports = {};
19
+ __export(adapterHtml_exports, {
20
+ builderPluginAdapterHtml: () => builderPluginAdapterHtml,
21
+ isHtmlEnabled: () => isHtmlEnabled
22
+ });
23
+ module.exports = __toCommonJS(adapterHtml_exports);
24
+ var import_utils = require("@modern-js/utils");
25
+ var import_lodash = require("@modern-js/utils/lodash");
26
+ var import_bundlerPlugins = require("../bundlerPlugins");
27
+ function isHtmlEnabled(config, target) {
28
+ var _a;
29
+ return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
30
+ }
31
+ const builderPluginAdapterHtml = (options) => ({
32
+ name: "builder-plugin-adpater-modern-html",
33
+ setup(api) {
34
+ api.modifyBundlerChain(
35
+ (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin }) => {
36
+ const builderConfig = api.getNormalizedConfig();
37
+ if (isHtmlEnabled(builderConfig, target)) {
38
+ applyBottomHtmlPlugin({
39
+ api,
40
+ options,
41
+ chain,
42
+ CHAIN_ID,
43
+ HtmlBundlerPlugin
44
+ });
45
+ }
46
+ }
47
+ );
48
+ }
49
+ });
50
+ function applyBottomHtmlPlugin({
51
+ api,
52
+ chain,
53
+ options,
54
+ CHAIN_ID,
55
+ HtmlBundlerPlugin
56
+ }) {
57
+ const { normalizedConfig: modernConfig, appContext } = options;
58
+ for (const entryName of Object.keys(api.context.entry)) {
59
+ const baseTemplateParams = {
60
+ entryName,
61
+ title: (0, import_utils.getEntryOptions)(
62
+ entryName,
63
+ modernConfig.html.title,
64
+ modernConfig.html.titleByEntries,
65
+ appContext.packageName
66
+ ),
67
+ mountId: modernConfig.html.mountId,
68
+ ...(0, import_utils.getEntryOptions)(
69
+ entryName,
70
+ modernConfig.html.templateParameters,
71
+ modernConfig.html.templateParametersByEntries,
72
+ appContext.packageName
73
+ )
74
+ };
75
+ chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
76
+ {
77
+ ...args[0] || {},
78
+ __internal__: true,
79
+ bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && (0, import_lodash.template)(appContext.htmlTemplates[`__${entryName}-bottom__`])(
80
+ baseTemplateParams
81
+ )
82
+ }
83
+ ]);
84
+ }
85
+ chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(import_bundlerPlugins.BottomTemplatePlugin, [HtmlBundlerPlugin]);
86
+ }
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ builderPluginAdapterHtml,
90
+ isHtmlEnabled
91
+ });
@@ -0,0 +1,140 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var adapterSSR_exports = {};
19
+ __export(adapterSSR_exports, {
20
+ builderPluginAdapterSSR: () => builderPluginAdapterSSR
21
+ });
22
+ module.exports = __toCommonJS(adapterSSR_exports);
23
+ var import_builder_shared = require("@modern-js/builder-shared");
24
+ var import_bundlerPlugins = require("../bundlerPlugins");
25
+ var import_adapterHtml = require("./adapterHtml");
26
+ const builderPluginAdapterSSR = (options) => ({
27
+ name: "builder-plugin-adapter-modern-ssr",
28
+ setup(api) {
29
+ const { normalizedConfig } = options;
30
+ api.modifyBuilderConfig((config) => {
31
+ if (isStreamingSSR(normalizedConfig)) {
32
+ return (0, import_builder_shared.mergeBuilderConfig)(config, {
33
+ html: {
34
+ inject: "body"
35
+ }
36
+ });
37
+ }
38
+ return config;
39
+ });
40
+ api.modifyBundlerChain(
41
+ (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin }) => {
42
+ const builderConfig = api.getNormalizedConfig();
43
+ applyRouterPlugin(chain, options);
44
+ if (["node", "service-worker"].includes(target)) {
45
+ applyFilterEntriesBySSRConfig({
46
+ isProd,
47
+ chain,
48
+ appNormalizedConfig: options.normalizedConfig
49
+ });
50
+ }
51
+ if ((0, import_adapterHtml.isHtmlEnabled)(builderConfig, target)) {
52
+ applyAsyncChunkHtmlPlugin({
53
+ chain,
54
+ modernConfig: options.normalizedConfig,
55
+ CHAIN_ID,
56
+ HtmlBundlerPlugin
57
+ });
58
+ }
59
+ }
60
+ );
61
+ }
62
+ });
63
+ const isStreamingSSR = (userConfig) => {
64
+ const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
65
+ const { server } = userConfig;
66
+ if (isStreaming(server.ssr)) {
67
+ return true;
68
+ }
69
+ if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
70
+ for (const name of Object.keys(server.ssrByEntries)) {
71
+ if (isStreaming(server.ssrByEntries[name])) {
72
+ return true;
73
+ }
74
+ }
75
+ }
76
+ return false;
77
+ };
78
+ function applyAsyncChunkHtmlPlugin({
79
+ chain,
80
+ modernConfig,
81
+ CHAIN_ID,
82
+ HtmlBundlerPlugin
83
+ }) {
84
+ if (isStreamingSSR(modernConfig)) {
85
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(import_bundlerPlugins.HtmlAsyncChunkPlugin, [HtmlBundlerPlugin]);
86
+ }
87
+ }
88
+ function applyRouterPlugin(chain, options) {
89
+ var _a;
90
+ const { appContext, normalizedConfig } = options;
91
+ const { entrypoints } = appContext;
92
+ const existNestedRoutes = entrypoints.some(
93
+ (entrypoint) => entrypoint.nestedRoutesEntry
94
+ );
95
+ const routerConfig = (_a = normalizedConfig == null ? void 0 : normalizedConfig.runtime) == null ? void 0 : _a.router;
96
+ const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
97
+ if (existNestedRoutes || routerManifest) {
98
+ chain.plugin("route-plugin").use(import_bundlerPlugins.RouterPlugin);
99
+ }
100
+ }
101
+ function applyFilterEntriesBySSRConfig({
102
+ isProd,
103
+ chain,
104
+ appNormalizedConfig
105
+ }) {
106
+ var _a;
107
+ const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
108
+ const entries = chain.entryPoints.entries();
109
+ if (isProd && ((outputConfig == null ? void 0 : outputConfig.ssg) === true || typeof ((_a = outputConfig == null ? void 0 : outputConfig.ssg) == null ? void 0 : _a[0]) === "function")) {
110
+ return;
111
+ }
112
+ if (typeof entries === "undefined") {
113
+ throw new Error(
114
+ "No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required"
115
+ );
116
+ }
117
+ const entryNames = Object.keys(entries);
118
+ if (isProd && entryNames.length === 1 && (outputConfig == null ? void 0 : outputConfig.ssg)) {
119
+ return;
120
+ }
121
+ const ssgEntries = [];
122
+ if (isProd && (outputConfig == null ? void 0 : outputConfig.ssg)) {
123
+ const { ssg } = outputConfig;
124
+ entryNames.forEach((name) => {
125
+ if (ssg[name]) {
126
+ ssgEntries.push(name);
127
+ }
128
+ });
129
+ }
130
+ const { ssr, ssrByEntries } = serverConfig || {};
131
+ entryNames.forEach((name) => {
132
+ if (!ssgEntries.includes(name) && (ssr && (ssrByEntries == null ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries == null ? void 0 : ssrByEntries[name]))) {
133
+ chain.entryPoints.delete(name);
134
+ }
135
+ });
136
+ }
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ builderPluginAdapterSSR
140
+ });
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var builderPlugins_exports = {};
16
+ module.exports = __toCommonJS(builderPlugins_exports);
17
+ __reExport(builderPlugins_exports, require("./adapterBasic"), module.exports);
18
+ __reExport(builderPlugins_exports, require("./adapterHtml"), module.exports);
19
+ __reExport(builderPlugins_exports, require("./adapterSSR"), module.exports);