@modern-js/app-tools 2.69.4 → 3.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 (578) hide show
  1. package/bin/modern.js +2 -8
  2. package/dist/cjs/builder/builder-rspack/index.js +35 -27
  3. package/dist/cjs/builder/generator/adapterCopy.js +75 -46
  4. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +83 -81
  5. package/dist/cjs/builder/generator/createCopyPattern.js +59 -58
  6. package/dist/cjs/builder/generator/getBuilderEnvironments.js +80 -82
  7. package/dist/cjs/builder/generator/index.js +70 -85
  8. package/dist/cjs/builder/index.js +44 -47
  9. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +106 -83
  10. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +79 -74
  11. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +131 -165
  12. package/dist/cjs/builder/shared/builderPlugins/builderHooks.js +47 -46
  13. package/dist/cjs/builder/shared/builderPlugins/index.js +76 -25
  14. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +66 -49
  15. package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +51 -50
  16. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +178 -317
  17. package/dist/cjs/builder/shared/bundlerPlugins/index.js +69 -23
  18. package/dist/cjs/builder/shared/createCopyInfo.js +54 -43
  19. package/dist/cjs/builder/shared/index.js +69 -23
  20. package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +35 -23
  21. package/dist/cjs/builder/shared/types.js +17 -15
  22. package/dist/cjs/commands/build.js +107 -96
  23. package/dist/cjs/commands/deploy.js +40 -32
  24. package/dist/cjs/commands/dev.js +122 -141
  25. package/dist/cjs/commands/index.js +74 -121
  26. package/dist/cjs/commands/inspect.js +45 -39
  27. package/dist/cjs/commands/serve.js +87 -84
  28. package/dist/cjs/compat/hooks.js +97 -177
  29. package/dist/cjs/compat/index.js +57 -59
  30. package/dist/cjs/compat/utils.js +125 -116
  31. package/dist/cjs/config/default.js +118 -225
  32. package/dist/cjs/config/index.js +62 -23
  33. package/dist/cjs/config/initialize/index.js +37 -29
  34. package/dist/cjs/config/initialize/inits.js +92 -106
  35. package/dist/cjs/constants.js +37 -37
  36. package/dist/cjs/defineConfig.js +33 -35
  37. package/dist/cjs/esm/esbuild-loader.js +62 -0
  38. package/dist/cjs/esm/esbuild-loader.mjs +11 -23
  39. package/dist/cjs/esm/register-esm.js +85 -0
  40. package/dist/cjs/esm/register-esm.mjs +41 -54
  41. package/dist/cjs/esm/ts-node-loader.js +62 -0
  42. package/dist/cjs/esm/ts-node-loader.mjs +11 -23
  43. package/dist/cjs/esm/utils.js +69 -0
  44. package/dist/cjs/esm/utils.mjs +24 -36
  45. package/dist/cjs/exports/server.js +16 -26
  46. package/dist/cjs/index.js +288 -199
  47. package/dist/cjs/locale/en.js +70 -62
  48. package/dist/cjs/locale/index.js +42 -33
  49. package/dist/cjs/locale/zh.js +70 -62
  50. package/dist/cjs/plugins/analyze/constants.js +43 -36
  51. package/dist/cjs/plugins/analyze/getBundleEntry.js +90 -94
  52. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +110 -137
  53. package/dist/cjs/plugins/analyze/getHtmlTemplate.js +125 -127
  54. package/dist/cjs/plugins/analyze/getServerRoutes.js +160 -164
  55. package/dist/cjs/plugins/analyze/index.js +221 -208
  56. package/dist/cjs/plugins/analyze/isDefaultExportFunction.js +81 -76
  57. package/dist/cjs/plugins/analyze/templates.js +36 -28
  58. package/dist/cjs/plugins/analyze/utils.js +109 -104
  59. package/dist/cjs/plugins/deploy/index.js +64 -56
  60. package/dist/cjs/plugins/deploy/platforms/gh-pages.js +82 -86
  61. package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +35 -2
  62. package/dist/cjs/plugins/deploy/platforms/netlify-handler.js +86 -62
  63. package/dist/cjs/plugins/deploy/platforms/netlify.js +145 -157
  64. package/dist/cjs/plugins/deploy/platforms/node-entry.js +73 -45
  65. package/dist/cjs/plugins/deploy/platforms/node.js +113 -113
  66. package/dist/cjs/plugins/deploy/platforms/platform.js +17 -15
  67. package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +36 -2
  68. package/dist/cjs/plugins/deploy/platforms/vercel-handler.js +87 -63
  69. package/dist/cjs/plugins/deploy/platforms/vercel.js +165 -169
  70. package/dist/cjs/plugins/deploy/utils.js +85 -85
  71. package/dist/cjs/plugins/initialize/index.js +86 -91
  72. package/dist/cjs/plugins/serverBuild.js +85 -78
  73. package/dist/cjs/plugins/serverRuntime.js +46 -34
  74. package/dist/cjs/run/index.js +86 -128
  75. package/dist/cjs/types/config/deploy.js +17 -15
  76. package/dist/cjs/types/config/dev.js +17 -15
  77. package/dist/cjs/types/config/experiments.js +17 -15
  78. package/dist/cjs/types/config/html.js +17 -15
  79. package/dist/cjs/types/config/index.js +55 -19
  80. package/dist/cjs/types/config/output.js +17 -15
  81. package/dist/cjs/types/config/performance.js +17 -15
  82. package/dist/cjs/types/config/resolve.js +17 -15
  83. package/dist/cjs/types/config/security.js +17 -15
  84. package/dist/cjs/types/config/source.js +17 -15
  85. package/dist/cjs/types/config/testing.js +17 -15
  86. package/dist/cjs/types/config/tools.js +17 -15
  87. package/dist/cjs/types/index.js +55 -23
  88. package/dist/cjs/types/plugin.js +18 -0
  89. package/dist/cjs/types/utils.js +17 -15
  90. package/dist/cjs/utils/config.js +40 -80
  91. package/dist/cjs/utils/createServer.js +46 -47
  92. package/dist/cjs/utils/env.js +41 -35
  93. package/dist/cjs/utils/generateWatchFiles.js +49 -60
  94. package/dist/cjs/utils/getConfigFile.js +46 -38
  95. package/dist/cjs/utils/getSelectedEntries.js +55 -53
  96. package/dist/cjs/utils/initAppContext.js +66 -59
  97. package/dist/cjs/utils/loadPlugins.js +77 -70
  98. package/dist/cjs/utils/printInstructions.js +39 -31
  99. package/dist/cjs/utils/register.js +108 -117
  100. package/dist/cjs/utils/restart.js +46 -41
  101. package/dist/cjs/utils/routes.js +60 -52
  102. package/dist/cjs/utils/types.js +17 -15
  103. package/dist/esm/builder/builder-rspack/index.mjs +6 -0
  104. package/dist/esm/builder/generator/adapterCopy.mjs +35 -0
  105. package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +59 -0
  106. package/dist/esm/builder/generator/createCopyPattern.mjs +30 -0
  107. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +56 -0
  108. package/dist/esm/builder/generator/index.mjs +45 -0
  109. package/dist/esm/builder/index.mjs +7 -0
  110. package/dist/esm/builder/shared/builderPlugins/adapterBasic.mjs +78 -0
  111. package/dist/esm/builder/shared/builderPlugins/adapterHtml.mjs +55 -0
  112. package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +117 -0
  113. package/dist/esm/builder/shared/builderPlugins/builderHooks.mjs +17 -0
  114. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +37 -0
  115. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.mjs +22 -0
  116. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.mjs +157 -0
  117. package/dist/esm/builder/shared/createCopyInfo.mjs +15 -0
  118. package/dist/esm/builder/shared/loaders/serverModuleLoader.mjs +5 -0
  119. package/dist/esm/commands/build.mjs +68 -0
  120. package/dist/esm/commands/deploy.mjs +10 -0
  121. package/dist/esm/commands/dev.mjs +82 -0
  122. package/dist/esm/commands/index.mjs +37 -0
  123. package/dist/esm/commands/inspect.mjs +15 -0
  124. package/dist/esm/commands/serve.mjs +47 -0
  125. package/dist/esm/compat/hooks.mjs +67 -0
  126. package/dist/esm/compat/index.mjs +28 -0
  127. package/dist/esm/compat/utils.mjs +95 -0
  128. package/dist/esm/config/default.mjs +90 -0
  129. package/dist/{esm-node/config/index.js → esm/config/index.mjs} +0 -1
  130. package/dist/esm/config/initialize/index.mjs +7 -0
  131. package/dist/esm/config/initialize/inits.mjs +54 -0
  132. package/dist/esm/constants.mjs +3 -0
  133. package/dist/esm/defineConfig.mjs +2 -0
  134. package/dist/esm/esm/esbuild-loader.mjs +18 -29
  135. package/dist/esm/esm/register-esm.mjs +45 -57
  136. package/dist/esm/esm/ts-node-loader.mjs +18 -30
  137. package/dist/esm/esm/utils.mjs +31 -42
  138. package/dist/esm/index.mjs +121 -0
  139. package/dist/esm/locale/en.mjs +42 -0
  140. package/dist/esm/locale/index.mjs +9 -0
  141. package/dist/esm/locale/zh.mjs +42 -0
  142. package/dist/esm/plugins/analyze/constants.mjs +8 -0
  143. package/dist/esm/plugins/analyze/getBundleEntry.mjs +53 -0
  144. package/dist/esm/plugins/analyze/getFileSystemEntry.mjs +66 -0
  145. package/dist/esm/plugins/analyze/getHtmlTemplate.mjs +85 -0
  146. package/dist/esm/plugins/analyze/getServerRoutes.mjs +130 -0
  147. package/dist/esm/plugins/analyze/index.mjs +193 -0
  148. package/dist/esm/plugins/analyze/isDefaultExportFunction.mjs +41 -0
  149. package/dist/esm/plugins/analyze/templates.mjs +22 -0
  150. package/dist/esm/plugins/analyze/utils.mjs +55 -0
  151. package/dist/esm/plugins/deploy/index.mjs +38 -0
  152. package/dist/esm/plugins/deploy/platforms/gh-pages.mjs +43 -0
  153. package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +2 -1
  154. package/dist/esm/plugins/deploy/platforms/netlify-handler.mjs +85 -0
  155. package/dist/esm/plugins/deploy/platforms/netlify.mjs +111 -0
  156. package/dist/esm/plugins/deploy/platforms/node-entry.mjs +68 -0
  157. package/dist/esm/plugins/deploy/platforms/node.mjs +77 -0
  158. package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +3 -3
  159. package/dist/esm/plugins/deploy/platforms/vercel-handler.mjs +85 -0
  160. package/dist/esm/plugins/deploy/platforms/vercel.mjs +131 -0
  161. package/dist/esm/plugins/deploy/utils.mjs +39 -0
  162. package/dist/esm/plugins/initialize/index.mjs +59 -0
  163. package/dist/esm/plugins/serverBuild.mjs +48 -0
  164. package/dist/esm/plugins/serverRuntime.mjs +15 -0
  165. package/dist/esm/run/index.mjs +60 -0
  166. package/dist/esm/types/index.mjs +1 -0
  167. package/dist/esm/utils/config.mjs +11 -0
  168. package/dist/esm/utils/createServer.mjs +12 -0
  169. package/dist/esm/utils/env.mjs +12 -0
  170. package/dist/esm/utils/generateWatchFiles.mjs +10 -0
  171. package/dist/esm/utils/getConfigFile.mjs +5 -0
  172. package/dist/esm/utils/getSelectedEntries.mjs +26 -0
  173. package/dist/esm/utils/initAppContext.mjs +26 -0
  174. package/dist/esm/utils/loadPlugins.mjs +45 -0
  175. package/dist/esm/utils/printInstructions.mjs +9 -0
  176. package/dist/esm/utils/register.mjs +75 -0
  177. package/dist/esm/utils/restart.mjs +18 -0
  178. package/dist/esm/utils/routes.mjs +15 -0
  179. package/dist/esm-node/builder/builder-rspack/index.mjs +6 -0
  180. package/dist/esm-node/builder/generator/adapterCopy.mjs +35 -0
  181. package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +59 -0
  182. package/dist/esm-node/builder/generator/createCopyPattern.mjs +30 -0
  183. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +56 -0
  184. package/dist/esm-node/builder/generator/index.mjs +45 -0
  185. package/dist/esm-node/builder/index.mjs +7 -0
  186. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.mjs +78 -0
  187. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.mjs +55 -0
  188. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +117 -0
  189. package/dist/esm-node/builder/shared/builderPlugins/builderHooks.mjs +17 -0
  190. package/dist/esm-node/builder/shared/builderPlugins/index.mjs +4 -0
  191. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +37 -0
  192. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.mjs +22 -0
  193. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.mjs +157 -0
  194. package/dist/esm-node/builder/shared/bundlerPlugins/index.mjs +3 -0
  195. package/dist/esm-node/builder/shared/createCopyInfo.mjs +15 -0
  196. package/dist/esm-node/builder/shared/index.mjs +3 -0
  197. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.mjs +5 -0
  198. package/dist/esm-node/commands/build.mjs +68 -0
  199. package/dist/esm-node/commands/deploy.mjs +10 -0
  200. package/dist/esm-node/commands/dev.mjs +82 -0
  201. package/dist/esm-node/commands/index.mjs +37 -0
  202. package/dist/esm-node/commands/inspect.mjs +15 -0
  203. package/dist/esm-node/commands/serve.mjs +47 -0
  204. package/dist/esm-node/compat/hooks.mjs +67 -0
  205. package/dist/esm-node/compat/index.mjs +28 -0
  206. package/dist/esm-node/compat/utils.mjs +95 -0
  207. package/dist/esm-node/config/default.mjs +90 -0
  208. package/dist/esm-node/config/index.mjs +2 -0
  209. package/dist/esm-node/config/initialize/index.mjs +7 -0
  210. package/dist/esm-node/config/initialize/inits.mjs +54 -0
  211. package/dist/esm-node/constants.mjs +3 -0
  212. package/dist/esm-node/defineConfig.mjs +2 -0
  213. package/dist/esm-node/esm/esbuild-loader.mjs +18 -29
  214. package/dist/esm-node/esm/register-esm.mjs +45 -57
  215. package/dist/esm-node/esm/ts-node-loader.mjs +18 -30
  216. package/dist/esm-node/esm/utils.mjs +31 -42
  217. package/dist/esm-node/index.mjs +121 -0
  218. package/dist/esm-node/locale/en.mjs +42 -0
  219. package/dist/esm-node/locale/index.mjs +9 -0
  220. package/dist/esm-node/locale/zh.mjs +42 -0
  221. package/dist/esm-node/plugins/analyze/constants.mjs +8 -0
  222. package/dist/esm-node/plugins/analyze/getBundleEntry.mjs +53 -0
  223. package/dist/esm-node/plugins/analyze/getFileSystemEntry.mjs +66 -0
  224. package/dist/esm-node/plugins/analyze/getHtmlTemplate.mjs +85 -0
  225. package/dist/esm-node/plugins/analyze/getServerRoutes.mjs +130 -0
  226. package/dist/esm-node/plugins/analyze/index.mjs +193 -0
  227. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.mjs +41 -0
  228. package/dist/esm-node/plugins/analyze/{templates.js → templates.mjs} +5 -7
  229. package/dist/esm-node/plugins/analyze/utils.mjs +55 -0
  230. package/dist/esm-node/plugins/deploy/index.mjs +38 -0
  231. package/dist/esm-node/plugins/deploy/platforms/gh-pages.mjs +43 -0
  232. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +2 -1
  233. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.mjs +85 -0
  234. package/dist/esm-node/plugins/deploy/platforms/netlify.mjs +111 -0
  235. package/dist/esm-node/plugins/deploy/platforms/node-entry.mjs +68 -0
  236. package/dist/esm-node/plugins/deploy/platforms/node.mjs +77 -0
  237. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +3 -3
  238. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.mjs +85 -0
  239. package/dist/esm-node/plugins/deploy/platforms/vercel.mjs +131 -0
  240. package/dist/esm-node/plugins/deploy/utils.mjs +39 -0
  241. package/dist/esm-node/plugins/initialize/index.mjs +59 -0
  242. package/dist/esm-node/plugins/serverBuild.mjs +48 -0
  243. package/dist/esm-node/plugins/serverRuntime.mjs +15 -0
  244. package/dist/esm-node/run/index.mjs +60 -0
  245. package/dist/esm-node/types/config/index.mjs +1 -0
  246. package/dist/esm-node/types/index.mjs +1 -0
  247. package/dist/esm-node/utils/config.mjs +11 -0
  248. package/dist/esm-node/utils/createServer.mjs +12 -0
  249. package/dist/esm-node/utils/env.mjs +12 -0
  250. package/dist/esm-node/utils/generateWatchFiles.mjs +10 -0
  251. package/dist/esm-node/utils/getConfigFile.mjs +5 -0
  252. package/dist/esm-node/utils/getSelectedEntries.mjs +26 -0
  253. package/dist/esm-node/utils/initAppContext.mjs +26 -0
  254. package/dist/esm-node/utils/loadPlugins.mjs +45 -0
  255. package/dist/esm-node/utils/printInstructions.mjs +9 -0
  256. package/dist/esm-node/utils/register.mjs +75 -0
  257. package/dist/esm-node/utils/restart.mjs +18 -0
  258. package/dist/esm-node/utils/routes.mjs +15 -0
  259. package/dist/types/builder/builder-rspack/index.d.ts +1 -1
  260. package/dist/types/builder/generator/adapterCopy.d.ts +2 -3
  261. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -3
  262. package/dist/types/builder/generator/createCopyPattern.d.ts +5 -5
  263. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +4 -4
  264. package/dist/types/builder/generator/index.d.ts +2 -3
  265. package/dist/types/builder/index.d.ts +2 -2
  266. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +1 -2
  267. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -2
  268. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -2
  269. package/dist/types/builder/shared/builderPlugins/builderHooks.d.ts +1 -2
  270. package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +4 -4
  271. package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +4 -4
  272. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +3 -5
  273. package/dist/types/builder/shared/createCopyInfo.d.ts +4 -3
  274. package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +2 -2
  275. package/dist/types/builder/shared/types.d.ts +5 -5
  276. package/dist/types/commands/build.d.ts +2 -2
  277. package/dist/types/commands/deploy.d.ts +2 -2
  278. package/dist/types/commands/dev.d.ts +2 -2
  279. package/dist/types/commands/index.d.ts +7 -9
  280. package/dist/types/commands/inspect.d.ts +2 -2
  281. package/dist/types/commands/serve.d.ts +2 -2
  282. package/dist/types/compat/hooks.d.ts +2 -2
  283. package/dist/types/compat/index.d.ts +2 -2
  284. package/dist/types/config/default.d.ts +3 -4
  285. package/dist/types/config/index.d.ts +0 -1
  286. package/dist/types/config/initialize/index.d.ts +2 -2
  287. package/dist/types/config/initialize/inits.d.ts +3 -4
  288. package/dist/types/constants.d.ts +0 -3
  289. package/dist/types/defineConfig.d.ts +7 -8
  290. package/dist/types/exports/server.d.ts +1 -5
  291. package/dist/types/index.d.ts +4 -5
  292. package/dist/types/locale/index.d.ts +1 -1
  293. package/dist/types/plugins/analyze/constants.d.ts +0 -1
  294. package/dist/types/plugins/analyze/getBundleEntry.d.ts +2 -2
  295. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +2 -2
  296. package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +4 -4
  297. package/dist/types/plugins/analyze/getServerRoutes.d.ts +3 -3
  298. package/dist/types/plugins/analyze/index.d.ts +2 -4
  299. package/dist/types/plugins/deploy/index.d.ts +2 -2
  300. package/dist/types/plugins/deploy/platforms/platform.d.ts +2 -2
  301. package/dist/types/plugins/deploy/utils.d.ts +2 -2
  302. package/dist/types/plugins/initialize/index.d.ts +2 -4
  303. package/dist/types/plugins/serverBuild.d.ts +2 -2
  304. package/dist/types/plugins/serverRuntime.d.ts +2 -2
  305. package/dist/types/run/index.d.ts +3 -8
  306. package/dist/types/types/config/deploy.d.ts +0 -1
  307. package/dist/types/types/config/dev.d.ts +50 -9
  308. package/dist/types/types/config/experiments.d.ts +2 -2
  309. package/dist/types/types/config/html.d.ts +2 -2
  310. package/dist/types/types/config/index.d.ts +10 -14
  311. package/dist/types/types/config/output.d.ts +8 -8
  312. package/dist/types/types/config/performance.d.ts +2 -2
  313. package/dist/types/types/config/resolve.d.ts +2 -2
  314. package/dist/types/types/config/security.d.ts +2 -2
  315. package/dist/types/types/config/source.d.ts +2 -23
  316. package/dist/types/types/config/tools.d.ts +5 -22
  317. package/dist/types/types/index.d.ts +7 -34
  318. package/dist/types/types/{new.d.ts → plugin.d.ts} +10 -39
  319. package/dist/types/types/utils.d.ts +0 -6
  320. package/dist/types/utils/config.d.ts +1 -11
  321. package/dist/types/utils/createServer.d.ts +1 -3
  322. package/dist/types/utils/env.d.ts +2 -2
  323. package/dist/types/utils/generateWatchFiles.d.ts +2 -3
  324. package/dist/types/utils/initAppContext.d.ts +1 -3
  325. package/dist/types/utils/loadPlugins.d.ts +5 -5
  326. package/dist/types/utils/printInstructions.d.ts +2 -2
  327. package/dist/types/utils/restart.d.ts +2 -2
  328. package/dist/types/utils/routes.d.ts +2 -3
  329. package/lib/types.d.ts +5 -16
  330. package/package.json +51 -38
  331. package/rslib.config.mts +20 -0
  332. package/dist/cjs/builder/builder-webpack/index.js +0 -50
  333. package/dist/cjs/config/legacy/createHtmlConfig.js +0 -45
  334. package/dist/cjs/config/legacy/createOutputConfig.js +0 -69
  335. package/dist/cjs/config/legacy/createSourceConfig.js +0 -53
  336. package/dist/cjs/config/legacy/createToolsConfig.js +0 -52
  337. package/dist/cjs/config/legacy/index.js +0 -68
  338. package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +0 -1
  339. package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +0 -3
  340. package/dist/cjs/types/hooks.js +0 -16
  341. package/dist/cjs/types/legacyConfig/deploy.js +0 -16
  342. package/dist/cjs/types/legacyConfig/dev.js +0 -16
  343. package/dist/cjs/types/legacyConfig/index.js +0 -16
  344. package/dist/cjs/types/legacyConfig/output.js +0 -16
  345. package/dist/cjs/types/legacyConfig/source.js +0 -16
  346. package/dist/cjs/types/legacyConfig/testing.js +0 -16
  347. package/dist/cjs/types/legacyConfig/tools.js +0 -16
  348. package/dist/cjs/types/new.js +0 -16
  349. package/dist/cjs/utils/getUserConfig.js +0 -34
  350. package/dist/esm/builder/builder-rspack/index.js +0 -30
  351. package/dist/esm/builder/builder-webpack/index.js +0 -48
  352. package/dist/esm/builder/generator/adapterCopy.js +0 -29
  353. package/dist/esm/builder/generator/createBuilderProviderConfig.js +0 -56
  354. package/dist/esm/builder/generator/createCopyPattern.js +0 -43
  355. package/dist/esm/builder/generator/getBuilderEnvironments.js +0 -89
  356. package/dist/esm/builder/generator/index.js +0 -116
  357. package/dist/esm/builder/index.js +0 -50
  358. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +0 -92
  359. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +0 -126
  360. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +0 -262
  361. package/dist/esm/builder/shared/builderPlugins/builderHooks.js +0 -120
  362. package/dist/esm/builder/shared/builderPlugins/index.js +0 -4
  363. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -51
  364. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -37
  365. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +0 -420
  366. package/dist/esm/builder/shared/bundlerPlugins/index.js +0 -3
  367. package/dist/esm/builder/shared/createCopyInfo.js +0 -14
  368. package/dist/esm/builder/shared/index.js +0 -3
  369. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +0 -7
  370. package/dist/esm/commands/build.js +0 -142
  371. package/dist/esm/commands/deploy.js +0 -48
  372. package/dist/esm/commands/dev.js +0 -197
  373. package/dist/esm/commands/index.js +0 -401
  374. package/dist/esm/commands/inspect.js +0 -31
  375. package/dist/esm/commands/serve.js +0 -96
  376. package/dist/esm/compat/hooks.js +0 -503
  377. package/dist/esm/compat/index.js +0 -45
  378. package/dist/esm/compat/utils.js +0 -100
  379. package/dist/esm/config/default.js +0 -205
  380. package/dist/esm/config/index.js +0 -3
  381. package/dist/esm/config/initialize/index.js +0 -9
  382. package/dist/esm/config/initialize/inits.js +0 -89
  383. package/dist/esm/config/legacy/createHtmlConfig.js +0 -21
  384. package/dist/esm/config/legacy/createOutputConfig.js +0 -45
  385. package/dist/esm/config/legacy/createSourceConfig.js +0 -46
  386. package/dist/esm/config/legacy/createToolsConfig.js +0 -28
  387. package/dist/esm/config/legacy/index.js +0 -43
  388. package/dist/esm/constants.js +0 -12
  389. package/dist/esm/defineConfig.js +0 -16
  390. package/dist/esm/exports/server.js +0 -4
  391. package/dist/esm/index.js +0 -265
  392. package/dist/esm/locale/en.js +0 -44
  393. package/dist/esm/locale/index.js +0 -12
  394. package/dist/esm/locale/zh.js +0 -44
  395. package/dist/esm/plugins/analyze/constants.js +0 -14
  396. package/dist/esm/plugins/analyze/getBundleEntry.js +0 -108
  397. package/dist/esm/plugins/analyze/getFileSystemEntry.js +0 -268
  398. package/dist/esm/plugins/analyze/getHtmlTemplate.js +0 -251
  399. package/dist/esm/plugins/analyze/getServerRoutes.js +0 -148
  400. package/dist/esm/plugins/analyze/index.js +0 -439
  401. package/dist/esm/plugins/analyze/isDefaultExportFunction.js +0 -49
  402. package/dist/esm/plugins/analyze/templates.js +0 -6
  403. package/dist/esm/plugins/analyze/utils.js +0 -106
  404. package/dist/esm/plugins/deploy/index.js +0 -133
  405. package/dist/esm/plugins/deploy/platforms/gh-pages.js +0 -184
  406. package/dist/esm/plugins/deploy/platforms/netlify-entry.js +0 -11
  407. package/dist/esm/plugins/deploy/platforms/netlify-handler.js +0 -207
  408. package/dist/esm/plugins/deploy/platforms/netlify.js +0 -346
  409. package/dist/esm/plugins/deploy/platforms/node-entry.js +0 -110
  410. package/dist/esm/plugins/deploy/platforms/node.js +0 -178
  411. package/dist/esm/plugins/deploy/platforms/vercel-entry.js +0 -11
  412. package/dist/esm/plugins/deploy/platforms/vercel-handler.js +0 -207
  413. package/dist/esm/plugins/deploy/platforms/vercel.js +0 -280
  414. package/dist/esm/plugins/deploy/utils.js +0 -59
  415. package/dist/esm/plugins/initialize/index.js +0 -116
  416. package/dist/esm/plugins/serverBuild.js +0 -83
  417. package/dist/esm/plugins/serverRuntime.js +0 -22
  418. package/dist/esm/run/index.js +0 -134
  419. package/dist/esm/types/config/index.js +0 -1
  420. package/dist/esm/types/config/source.js +0 -0
  421. package/dist/esm/types/config/testing.js +0 -0
  422. package/dist/esm/types/config/tools.js +0 -0
  423. package/dist/esm/types/hooks.js +0 -0
  424. package/dist/esm/types/index.js +0 -3
  425. package/dist/esm/types/legacyConfig/deploy.js +0 -0
  426. package/dist/esm/types/legacyConfig/dev.js +0 -0
  427. package/dist/esm/types/legacyConfig/index.js +0 -0
  428. package/dist/esm/types/legacyConfig/output.js +0 -0
  429. package/dist/esm/types/legacyConfig/source.js +0 -0
  430. package/dist/esm/types/legacyConfig/testing.js +0 -0
  431. package/dist/esm/types/legacyConfig/tools.js +0 -0
  432. package/dist/esm/types/new.js +0 -0
  433. package/dist/esm/types/utils.js +0 -0
  434. package/dist/esm/utils/config.js +0 -122
  435. package/dist/esm/utils/createServer.js +0 -58
  436. package/dist/esm/utils/env.js +0 -16
  437. package/dist/esm/utils/generateWatchFiles.js +0 -71
  438. package/dist/esm/utils/getConfigFile.js +0 -11
  439. package/dist/esm/utils/getSelectedEntries.js +0 -67
  440. package/dist/esm/utils/getUserConfig.js +0 -32
  441. package/dist/esm/utils/initAppContext.js +0 -30
  442. package/dist/esm/utils/loadPlugins.js +0 -162
  443. package/dist/esm/utils/printInstructions.js +0 -32
  444. package/dist/esm/utils/register.js +0 -182
  445. package/dist/esm/utils/restart.js +0 -68
  446. package/dist/esm/utils/routes.js +0 -42
  447. package/dist/esm/utils/types.js +0 -0
  448. package/dist/esm-node/builder/builder-rspack/index.js +0 -8
  449. package/dist/esm-node/builder/builder-webpack/index.js +0 -16
  450. package/dist/esm-node/builder/generator/adapterCopy.js +0 -26
  451. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +0 -67
  452. package/dist/esm-node/builder/generator/createCopyPattern.js +0 -41
  453. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +0 -68
  454. package/dist/esm-node/builder/generator/index.js +0 -60
  455. package/dist/esm-node/builder/index.js +0 -16
  456. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +0 -55
  457. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +0 -60
  458. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +0 -151
  459. package/dist/esm-node/builder/shared/builderPlugins/builderHooks.js +0 -26
  460. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -30
  461. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +0 -31
  462. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +0 -305
  463. package/dist/esm-node/builder/shared/createCopyInfo.js +0 -14
  464. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +0 -7
  465. package/dist/esm-node/commands/build.js +0 -67
  466. package/dist/esm-node/commands/deploy.js +0 -12
  467. package/dist/esm-node/commands/dev.js +0 -111
  468. package/dist/esm-node/commands/index.js +0 -90
  469. package/dist/esm-node/commands/inspect.js +0 -19
  470. package/dist/esm-node/commands/serve.js +0 -54
  471. package/dist/esm-node/compat/hooks.js +0 -159
  472. package/dist/esm-node/compat/index.js +0 -40
  473. package/dist/esm-node/compat/utils.js +0 -100
  474. package/dist/esm-node/config/default.js +0 -206
  475. package/dist/esm-node/config/initialize/index.js +0 -9
  476. package/dist/esm-node/config/initialize/inits.js +0 -79
  477. package/dist/esm-node/config/legacy/createHtmlConfig.js +0 -21
  478. package/dist/esm-node/config/legacy/createOutputConfig.js +0 -45
  479. package/dist/esm-node/config/legacy/createSourceConfig.js +0 -29
  480. package/dist/esm-node/config/legacy/createToolsConfig.js +0 -28
  481. package/dist/esm-node/config/legacy/index.js +0 -43
  482. package/dist/esm-node/constants.js +0 -12
  483. package/dist/esm-node/defineConfig.js +0 -13
  484. package/dist/esm-node/exports/server.js +0 -4
  485. package/dist/esm-node/index.js +0 -160
  486. package/dist/esm-node/locale/en.js +0 -44
  487. package/dist/esm-node/locale/index.js +0 -12
  488. package/dist/esm-node/locale/zh.js +0 -44
  489. package/dist/esm-node/plugins/analyze/constants.js +0 -14
  490. package/dist/esm-node/plugins/analyze/getBundleEntry.js +0 -67
  491. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +0 -108
  492. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +0 -99
  493. package/dist/esm-node/plugins/analyze/getServerRoutes.js +0 -146
  494. package/dist/esm-node/plugins/analyze/index.js +0 -184
  495. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +0 -47
  496. package/dist/esm-node/plugins/analyze/utils.js +0 -73
  497. package/dist/esm-node/plugins/deploy/index.js +0 -44
  498. package/dist/esm-node/plugins/deploy/platforms/gh-pages.js +0 -57
  499. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +0 -11
  500. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +0 -73
  501. package/dist/esm-node/plugins/deploy/platforms/netlify.js +0 -133
  502. package/dist/esm-node/plugins/deploy/platforms/node-entry.js +0 -46
  503. package/dist/esm-node/plugins/deploy/platforms/node.js +0 -87
  504. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.js +0 -11
  505. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +0 -73
  506. package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -145
  507. package/dist/esm-node/plugins/deploy/utils.js +0 -55
  508. package/dist/esm-node/plugins/initialize/index.js +0 -78
  509. package/dist/esm-node/plugins/serverBuild.js +0 -56
  510. package/dist/esm-node/plugins/serverRuntime.js +0 -17
  511. package/dist/esm-node/run/index.js +0 -104
  512. package/dist/esm-node/types/index.js +0 -3
  513. package/dist/esm-node/utils/config.js +0 -49
  514. package/dist/esm-node/utils/createServer.js +0 -26
  515. package/dist/esm-node/utils/env.js +0 -16
  516. package/dist/esm-node/utils/generateWatchFiles.js +0 -30
  517. package/dist/esm-node/utils/getConfigFile.js +0 -7
  518. package/dist/esm-node/utils/getSelectedEntries.js +0 -34
  519. package/dist/esm-node/utils/getUserConfig.js +0 -10
  520. package/dist/esm-node/utils/initAppContext.js +0 -29
  521. package/dist/esm-node/utils/loadPlugins.js +0 -52
  522. package/dist/esm-node/utils/printInstructions.js +0 -11
  523. package/dist/esm-node/utils/register.js +0 -94
  524. package/dist/esm-node/utils/restart.js +0 -23
  525. package/dist/esm-node/utils/routes.js +0 -21
  526. package/dist/types/builder/builder-webpack/index.d.ts +0 -2
  527. package/dist/types/config/legacy/createHtmlConfig.d.ts +0 -2
  528. package/dist/types/config/legacy/createOutputConfig.d.ts +0 -2
  529. package/dist/types/config/legacy/createSourceConfig.d.ts +0 -2
  530. package/dist/types/config/legacy/createToolsConfig.d.ts +0 -2
  531. package/dist/types/config/legacy/index.d.ts +0 -3
  532. package/dist/types/types/hooks.d.ts +0 -69
  533. package/dist/types/types/legacyConfig/deploy.d.ts +0 -8
  534. package/dist/types/types/legacyConfig/dev.d.ts +0 -12
  535. package/dist/types/types/legacyConfig/index.d.ts +0 -35
  536. package/dist/types/types/legacyConfig/output.d.ts +0 -50
  537. package/dist/types/types/legacyConfig/source.d.ts +0 -28
  538. package/dist/types/types/legacyConfig/testing.d.ts +0 -8
  539. package/dist/types/types/legacyConfig/tools.d.ts +0 -15
  540. package/dist/types/utils/getUserConfig.d.ts +0 -6
  541. /package/dist/{esm-node/builder/shared/builderPlugins/index.js → esm/builder/shared/builderPlugins/index.mjs} +0 -0
  542. /package/dist/{esm-node/builder/shared/bundlerPlugins/index.js → esm/builder/shared/bundlerPlugins/index.mjs} +0 -0
  543. /package/dist/{esm-node/builder/shared/index.js → esm/builder/shared/index.mjs} +0 -0
  544. /package/dist/{esm-node/types/legacyConfig/output.js → esm/builder/shared/types.mjs} +0 -0
  545. /package/dist/{esm-node/types/legacyConfig/source.js → esm/exports/server.mjs} +0 -0
  546. /package/dist/{esm-node/types/legacyConfig/testing.js → esm/plugins/deploy/platforms/platform.mjs} +0 -0
  547. /package/dist/{esm-node/types/legacyConfig/tools.js → esm/types/config/deploy.mjs} +0 -0
  548. /package/dist/{esm-node/types/new.js → esm/types/config/dev.mjs} +0 -0
  549. /package/dist/{esm-node/types/utils.js → esm/types/config/experiments.mjs} +0 -0
  550. /package/dist/{esm-node/utils/types.js → esm/types/config/html.mjs} +0 -0
  551. /package/dist/{esm-node/types/config/index.js → esm/types/config/index.mjs} +0 -0
  552. /package/dist/esm/{builder/shared/types.js → types/config/output.mjs} +0 -0
  553. /package/dist/esm/{plugins/deploy/platforms/platform.js → types/config/performance.mjs} +0 -0
  554. /package/dist/esm/types/config/{deploy.js → resolve.mjs} +0 -0
  555. /package/dist/esm/types/config/{dev.js → security.mjs} +0 -0
  556. /package/dist/esm/types/config/{experiments.js → source.mjs} +0 -0
  557. /package/dist/esm/types/config/{html.js → testing.mjs} +0 -0
  558. /package/dist/esm/types/config/{output.js → tools.mjs} +0 -0
  559. /package/dist/esm/types/{config/performance.js → plugin.mjs} +0 -0
  560. /package/dist/esm/types/{config/resolve.js → utils.mjs} +0 -0
  561. /package/dist/esm/{types/config/security.js → utils/types.mjs} +0 -0
  562. /package/dist/esm-node/builder/shared/{types.js → types.mjs} +0 -0
  563. /package/dist/esm-node/{plugins/deploy/platforms/platform.js → exports/server.mjs} +0 -0
  564. /package/dist/esm-node/{types/config/deploy.js → plugins/deploy/platforms/platform.mjs} +0 -0
  565. /package/dist/esm-node/types/config/{dev.js → deploy.mjs} +0 -0
  566. /package/dist/esm-node/types/config/{experiments.js → dev.mjs} +0 -0
  567. /package/dist/esm-node/types/config/{html.js → experiments.mjs} +0 -0
  568. /package/dist/esm-node/types/config/{output.js → html.mjs} +0 -0
  569. /package/dist/esm-node/types/config/{performance.js → output.mjs} +0 -0
  570. /package/dist/esm-node/types/config/{resolve.js → performance.mjs} +0 -0
  571. /package/dist/esm-node/types/config/{security.js → resolve.mjs} +0 -0
  572. /package/dist/esm-node/types/config/{source.js → security.mjs} +0 -0
  573. /package/dist/esm-node/types/config/{testing.js → source.mjs} +0 -0
  574. /package/dist/esm-node/types/config/{tools.js → testing.mjs} +0 -0
  575. /package/dist/esm-node/types/{hooks.js → config/tools.mjs} +0 -0
  576. /package/dist/esm-node/types/{legacyConfig/deploy.js → plugin.mjs} +0 -0
  577. /package/dist/esm-node/types/{legacyConfig/dev.js → utils.mjs} +0 -0
  578. /package/dist/esm-node/{types/legacyConfig/index.js → utils/types.mjs} +0 -0
@@ -0,0 +1,85 @@
1
+ import path from "path";
2
+ import { findExists, fs } from "@modern-js/utils";
3
+ import { HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER } from "./constants.mjs";
4
+ import { html } from "./templates.mjs";
5
+ const findPartials = (dir, entryName, position)=>{
6
+ if (fs.existsSync(dir)) {
7
+ const base = findExists(HTML_PARTIALS_EXTENSIONS.map((ext)=>path.resolve(dir, `${position}${ext}`)));
8
+ const file = entryName ? findExists(HTML_PARTIALS_EXTENSIONS.map((ext)=>path.resolve(dir, entryName, `${position}${ext}`))) || base : base;
9
+ return file ? {
10
+ file,
11
+ content: fs.readFileSync(file, 'utf8')
12
+ } : null;
13
+ }
14
+ return null;
15
+ };
16
+ const getModifyHtmlPartials = (partials)=>{
17
+ const append = (type, ...script)=>{
18
+ script.forEach((item)=>{
19
+ partials[type].push(item);
20
+ });
21
+ };
22
+ const prepend = (type, ...script)=>{
23
+ script.forEach((item)=>{
24
+ partials[type].unshift(item);
25
+ });
26
+ };
27
+ return {
28
+ top: {
29
+ append: (...script)=>append("top", ...script),
30
+ prepend: (...script)=>prepend("top", ...script),
31
+ current: partials.top
32
+ },
33
+ head: {
34
+ append: (...script)=>append("head", ...script),
35
+ prepend: (...script)=>prepend("head", ...script),
36
+ current: partials.head
37
+ },
38
+ body: {
39
+ append: (...script)=>append("body", ...script),
40
+ prepend: (...script)=>prepend("body", ...script),
41
+ current: partials.body
42
+ }
43
+ };
44
+ };
45
+ const getHtmlTemplate = async (entrypoints, hooks, { appContext, config })=>{
46
+ const { appDirectory, internalDirectory } = appContext;
47
+ const { source: { configDir } } = config;
48
+ const htmlDir = path.resolve(appDirectory, configDir || '', HTML_PARTIALS_FOLDER);
49
+ const htmlTemplates = {};
50
+ const partialsByEntrypoint = {};
51
+ for (const entrypoint of entrypoints){
52
+ const { entryName, isMainEntry } = entrypoint;
53
+ const name = 1 === entrypoints.length && isMainEntry ? '' : entryName;
54
+ const customIndexTemplate = findPartials(htmlDir, name, "index");
55
+ if (customIndexTemplate) htmlTemplates[entryName] = customIndexTemplate.file.replace(/\\/g, '/');
56
+ else {
57
+ const getPartialInitValue = (position)=>{
58
+ const partial = findPartials(htmlDir, name, position);
59
+ return partial ? [
60
+ partial.content
61
+ ] : [];
62
+ };
63
+ const partials = {
64
+ top: getPartialInitValue("top"),
65
+ head: getPartialInitValue("head"),
66
+ body: getPartialInitValue("body")
67
+ };
68
+ await hooks.modifyHtmlPartials.call({
69
+ entrypoint,
70
+ partials: getModifyHtmlPartials(partials)
71
+ });
72
+ const templatePath = path.resolve(internalDirectory, entryName, 'index.html');
73
+ fs.outputFileSync(templatePath, html(partials), 'utf8');
74
+ htmlTemplates[entryName] = templatePath.replace(/\\/g, '/');
75
+ partialsByEntrypoint[entryName] = partials;
76
+ const bottomTemplate = findPartials(htmlDir, name, "bottom");
77
+ if (bottomTemplate) htmlTemplates[`__${entryName}-bottom__`] = bottomTemplate.content;
78
+ }
79
+ }
80
+ return {
81
+ partialsByEntrypoint,
82
+ htmlTemplates
83
+ };
84
+ };
85
+ export { getHtmlTemplate, getModifyHtmlPartials };
@@ -0,0 +1,130 @@
1
+ import path from "path";
2
+ import { ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_WORKER_BUNDLE_DIRECTORY, fs, getEntryOptions, isPlainObject, removeLeadingSlash, removeTailSlash, urlJoin } from "@modern-js/utils";
3
+ import { isMainEntry } from "../../utils/routes.mjs";
4
+ import { walkDirectory } from "./utils.mjs";
5
+ const applyBaseUrl = (baseUrl, routes)=>{
6
+ if (baseUrl) if (Array.isArray(baseUrl)) return baseUrl.reduce((previous, current)=>[
7
+ ...previous,
8
+ ...applyBaseUrl(current, routes)
9
+ ], []);
10
+ else return routes.map((route)=>{
11
+ const urlPath = urlJoin(baseUrl, route.urlPath);
12
+ return {
13
+ ...route,
14
+ urlPath: '/' === urlPath ? urlPath : removeTailSlash(urlPath)
15
+ };
16
+ });
17
+ return routes;
18
+ };
19
+ const applyRouteOptions = (original, routeOptions)=>{
20
+ const { route, disableSpa } = routeOptions;
21
+ original.isSPA = !disableSpa;
22
+ original.isSPA || (original.entryPath = path.dirname(original.entryPath));
23
+ let routes;
24
+ if (route) if (Array.isArray(route)) routes = route.map((url)=>{
25
+ if (!isPlainObject(url)) return {
26
+ ...original,
27
+ urlPath: url
28
+ };
29
+ {
30
+ const { path: urlPath, ...other } = url;
31
+ return {
32
+ ...original,
33
+ ...other,
34
+ urlPath
35
+ };
36
+ }
37
+ });
38
+ else if (isPlainObject(route)) {
39
+ const { path: urlPath, ...other } = route;
40
+ routes = [
41
+ {
42
+ ...original,
43
+ ...other,
44
+ urlPath
45
+ }
46
+ ];
47
+ } else routes = [
48
+ {
49
+ ...original,
50
+ urlPath: route
51
+ }
52
+ ];
53
+ else routes = [
54
+ original
55
+ ];
56
+ return routes;
57
+ };
58
+ const collectHtmlRoutes = (entrypoints, appContext, config)=>{
59
+ const { source: { mainEntryName }, html: { outputStructure }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries, rsc }, deploy } = config;
60
+ const { packageName } = appContext;
61
+ const workerSSR = deploy?.worker?.ssr;
62
+ let htmlRoutes = entrypoints.reduce((previous, { entryName })=>{
63
+ const isMain = isMainEntry(entryName, mainEntryName);
64
+ const entryOptions = getEntryOptions(entryName, isMain, ssr, ssrByEntries, packageName);
65
+ const isSSR = Boolean(entryOptions);
66
+ const isWorker = Boolean(workerSSR);
67
+ const isStream = 'object' == typeof entryOptions && 'stream' === entryOptions.mode;
68
+ const { resHeaders } = routes?.[entryName] || {};
69
+ const isRSC = !!rsc;
70
+ let route = {
71
+ urlPath: `/${isMain ? '' : entryName}`,
72
+ entryName,
73
+ entryPath: removeLeadingSlash(path.posix.normalize(`${htmlPath}/${entryName}${'flat' === outputStructure ? '.html' : '/index.html'}`)),
74
+ isSPA: true,
75
+ isStream: isStream || isRSC,
76
+ isSSR,
77
+ isRSC,
78
+ responseHeaders: resHeaders,
79
+ worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
80
+ bundle: isSSR || isRSC ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
81
+ };
82
+ if (routes?.hasOwnProperty(entryName)) {
83
+ const routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
84
+ route: routes[entryName]
85
+ };
86
+ route = applyRouteOptions(route, routeOptions);
87
+ }
88
+ return Array.isArray(route) ? [
89
+ ...previous,
90
+ ...route
91
+ ] : [
92
+ ...previous,
93
+ route
94
+ ];
95
+ }, []);
96
+ htmlRoutes = applyBaseUrl(baseUrl, htmlRoutes);
97
+ return htmlRoutes;
98
+ };
99
+ const collectStaticRoutes = (appContext, config)=>{
100
+ const { appDirectory } = appContext;
101
+ const { source: { configDir }, server: { publicRoutes = {} } } = config;
102
+ const publicFolder = path.resolve(appDirectory, configDir || '', 'public');
103
+ const ignoreFiles = [
104
+ '.gitkeep'
105
+ ];
106
+ return fs.existsSync(publicFolder) ? walkDirectory(publicFolder).filter((filePath)=>!ignoreFiles.includes(path.basename(filePath))).map((filePath)=>{
107
+ const urlPath = `${urlJoin(toPosix(filePath).slice(toPosix(publicFolder).length))}`;
108
+ return {
109
+ urlPath: publicRoutes[removeLeadingSlash(urlPath)] || urlPath,
110
+ isSPA: true,
111
+ isSSR: false,
112
+ entryPath: toPosix(path.relative(path.resolve(appDirectory, configDir || ''), filePath))
113
+ };
114
+ }) : [];
115
+ };
116
+ const getServerRoutes = (entrypoints, { appContext, config })=>[
117
+ ...collectHtmlRoutes(entrypoints, appContext, config),
118
+ ...collectStaticRoutes(appContext, config)
119
+ ];
120
+ const toPosix = (pathStr)=>pathStr.split(path.sep).join(path.posix.sep);
121
+ const getProdServerRoutes = (distDirectory)=>{
122
+ const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
123
+ try {
124
+ const { routes } = fs.readJSONSync(routeJSON);
125
+ return routes;
126
+ } catch (e) {
127
+ throw new Error(`Failed to read routes from ${routeJSON}, please check if the file exists.`);
128
+ }
129
+ };
130
+ export { getProdServerRoutes, getServerRoutes };
@@ -0,0 +1,193 @@
1
+ import { extname, resolve } from "path";
2
+ import { createDebugger, fs, getArgv, getMeta, isApiOnly, isDevCommand, minimist } from "@modern-js/utils";
3
+ import { createBuilderGenerator } from "../../builder/index.mjs";
4
+ import { initialNormalizedConfig } from "../../config/index.mjs";
5
+ import { emitResolvedConfig } from "../../utils/config.mjs";
6
+ import { getSelectedEntries } from "../../utils/getSelectedEntries.mjs";
7
+ import { printInstructions } from "../../utils/printInstructions.mjs";
8
+ import { generateRoutes } from "../../utils/routes.mjs";
9
+ import { checkIsBuildCommands, checkIsServeCommand } from "./utils.mjs";
10
+ const debug = createDebugger('plugin-analyze');
11
+ const analyze = ()=>({
12
+ name: '@modern-js/plugin-analyze',
13
+ post: [
14
+ '@modern-js/runtime'
15
+ ],
16
+ setup: (api)=>{
17
+ let pagesDir = [];
18
+ let nestedRouteEntries = [];
19
+ const routesConfigFiles = [];
20
+ api.onPrepare(async ()=>{
21
+ let appContext = api.getAppContext();
22
+ const resolvedConfig = api.getNormalizedConfig();
23
+ const hooks = api.getHooks();
24
+ try {
25
+ if (checkIsBuildCommands()) fs.emptydirSync(appContext.internalDirectory);
26
+ } catch {}
27
+ const apiOnly = await isApiOnly(appContext.appDirectory, resolvedConfig.source?.entriesDir, appContext.apiDirectory);
28
+ const [{ getProdServerRoutes }] = await Promise.all([
29
+ import("./getServerRoutes.mjs")
30
+ ]);
31
+ if (apiOnly) {
32
+ const routes = [];
33
+ if (checkIsServeCommand()) routes.push(...getProdServerRoutes(appContext.distDirectory));
34
+ else {
35
+ const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
36
+ routes: []
37
+ });
38
+ routes.push(...modifiedRoutes);
39
+ }
40
+ debug("server routes: %o", routes);
41
+ api.updateAppContext({
42
+ apiOnly,
43
+ serverRoutes: routes
44
+ });
45
+ return;
46
+ }
47
+ const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
48
+ import("./getBundleEntry.mjs"),
49
+ import("./getServerRoutes.mjs"),
50
+ import("./getHtmlTemplate.mjs")
51
+ ]);
52
+ const { entrypoints } = await hooks.modifyEntrypoints.call({
53
+ entrypoints: await getBundleEntry(hooks, appContext, resolvedConfig)
54
+ });
55
+ debug("entrypoints: %o", entrypoints);
56
+ const routes = [];
57
+ if (checkIsServeCommand()) routes.push(...getProdServerRoutes(appContext.distDirectory));
58
+ else {
59
+ const initialRoutes = getServerRoutes(entrypoints, {
60
+ appContext,
61
+ config: resolvedConfig
62
+ });
63
+ const { routes: modifiedRoutes } = await hooks.modifyServerRoutes.call({
64
+ routes: initialRoutes
65
+ });
66
+ routes.push(...modifiedRoutes);
67
+ }
68
+ debug("server routes: %o", routes);
69
+ appContext = {
70
+ ...api.getAppContext(),
71
+ entrypoints,
72
+ serverRoutes: routes
73
+ };
74
+ api.updateAppContext(appContext);
75
+ nestedRouteEntries = entrypoints.map((point)=>point.nestedRoutesEntry).filter(Boolean);
76
+ pagesDir = entrypoints.map((point)=>point.entry).filter((entry)=>entry && !extname(entry)).concat(nestedRouteEntries);
77
+ const meta = getMeta(api.getAppContext().metaName);
78
+ const possibleNames = [
79
+ `${meta}.routes.ts`,
80
+ `${meta}.routes.mts`,
81
+ `${meta}.routes.tsx`,
82
+ `${meta}.routes.js`,
83
+ `${meta}.routes.mjs`,
84
+ `${meta}.routes.jsx`
85
+ ];
86
+ await Promise.all(entrypoints.map(async (entrypoint)=>{
87
+ const { absoluteEntryDir } = entrypoint;
88
+ if (!absoluteEntryDir) return;
89
+ for (const filename of possibleNames){
90
+ const filePath = resolve(absoluteEntryDir, filename);
91
+ if (await fs.pathExists(filePath)) {
92
+ const stats = await fs.stat(filePath);
93
+ if (stats.isFile()) routesConfigFiles.push(filePath);
94
+ }
95
+ }
96
+ }));
97
+ const { partialsByEntrypoint, htmlTemplates } = await getHtmlTemplate(entrypoints, hooks, {
98
+ appContext,
99
+ config: resolvedConfig
100
+ });
101
+ debug("html templates: %o", htmlTemplates);
102
+ api.updateAppContext({
103
+ partialsByEntrypoint
104
+ });
105
+ let checkedEntries = entrypoints.map((point)=>point.entryName);
106
+ if (isDevCommand()) {
107
+ const { entry } = minimist(getArgv());
108
+ checkedEntries = await getSelectedEntries('string' == typeof entry ? entry.split(',') : entry, entrypoints);
109
+ }
110
+ appContext = {
111
+ ...api.getAppContext(),
112
+ entrypoints,
113
+ checkedEntries,
114
+ apiOnly,
115
+ serverRoutes: routes,
116
+ htmlTemplates
117
+ };
118
+ api.updateAppContext(appContext);
119
+ if (checkIsBuildCommands()) {
120
+ await hooks.generateEntryCode.call({
121
+ entrypoints
122
+ });
123
+ const normalizedConfig = api.getNormalizedConfig();
124
+ const createBuilderForModern = await createBuilderGenerator();
125
+ const builder = await createBuilderForModern({
126
+ normalizedConfig: normalizedConfig,
127
+ appContext: appContext
128
+ });
129
+ builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile, environments, isWatch })=>{
130
+ if (!isFirstCompile) return;
131
+ await generateRoutes(appContext);
132
+ await hooks.onBeforeBuild.call({
133
+ isFirstCompile,
134
+ isWatch,
135
+ environments,
136
+ bundlerConfigs
137
+ });
138
+ });
139
+ builder.onAfterBuild(async ({ stats, environments, isFirstCompile, isWatch })=>{
140
+ await hooks.onAfterBuild.call({
141
+ stats,
142
+ environments,
143
+ isFirstCompile,
144
+ isWatch
145
+ });
146
+ await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
147
+ });
148
+ builder.onDevCompileDone(async ({ isFirstCompile, stats, environments })=>{
149
+ hooks.onDevCompileDone.call({
150
+ isFirstCompile,
151
+ stats,
152
+ environments
153
+ });
154
+ if (isFirstCompile) printInstructions(hooks, appContext, normalizedConfig);
155
+ });
156
+ builder.onBeforeCreateCompiler(async ({ bundlerConfigs, environments })=>{
157
+ await hooks.onBeforeCreateCompiler.call({
158
+ environments,
159
+ bundlerConfigs
160
+ });
161
+ });
162
+ builder.onAfterCreateCompiler(async ({ compiler, environments })=>{
163
+ await hooks.onAfterCreateCompiler.call({
164
+ environments,
165
+ compiler
166
+ });
167
+ });
168
+ builder.onAfterStartDevServer(async ({ port })=>{
169
+ await hooks.onAfterDev.call({
170
+ port
171
+ });
172
+ });
173
+ builder.addPlugins(resolvedConfig.builderPlugins);
174
+ api.updateAppContext({
175
+ builder
176
+ });
177
+ }
178
+ });
179
+ api.addWatchFiles(()=>({
180
+ files: [
181
+ ...pagesDir,
182
+ ...routesConfigFiles
183
+ ],
184
+ isPrivate: true
185
+ }));
186
+ api.modifyResolvedConfig((resolved)=>{
187
+ const appContext = api.getAppContext();
188
+ const config = initialNormalizedConfig(resolved, appContext);
189
+ return config;
190
+ });
191
+ }
192
+ });
193
+ export { analyze as default };
@@ -0,0 +1,41 @@
1
+ import fs from "fs";
2
+ import { parse } from "@babel/parser";
3
+ import traverse from "@babel/traverse";
4
+ import { isArrowFunctionExpression, isFunctionDeclaration, isFunctionExpression } from "@babel/types";
5
+ const isFunction = (node)=>isFunctionDeclaration(node) || isFunctionExpression(node) || isArrowFunctionExpression(node);
6
+ const isDefaultExportFunction = (file)=>{
7
+ if (!file || !fs.existsSync(file)) return false;
8
+ const ast = parse(fs.readFileSync(file, 'utf8'), {
9
+ sourceType: 'unambiguous',
10
+ plugins: [
11
+ 'jsx',
12
+ "typescript",
13
+ 'classProperties',
14
+ 'dynamicImport',
15
+ 'exportDefaultFrom',
16
+ 'exportNamespaceFrom',
17
+ 'decorators-legacy',
18
+ 'functionBind',
19
+ 'classPrivateMethods',
20
+ [
21
+ 'pipelineOperator',
22
+ {
23
+ proposal: 'minimal'
24
+ }
25
+ ],
26
+ 'optionalChaining',
27
+ 'optionalCatchBinding',
28
+ 'objectRestSpread',
29
+ 'numericSeparator'
30
+ ]
31
+ });
32
+ let isExportFunction = false;
33
+ traverse(ast, {
34
+ ExportDefaultDeclaration: (path)=>{
35
+ const { declaration } = path.node;
36
+ if (isFunction(declaration)) isExportFunction = true;
37
+ }
38
+ });
39
+ return isExportFunction;
40
+ };
41
+ export { isDefaultExportFunction };
@@ -1,17 +1,17 @@
1
- const html = (partials) => `
1
+ const html = (partials)=>`
2
2
  <!DOCTYPE html>
3
3
  <html>
4
4
  <head>
5
5
 
6
- ${partials.top.join("\n")}
6
+ ${partials.top.join('\n')}
7
7
 
8
- ${partials.head.join("\n")}
8
+ ${partials.head.join('\n')}
9
9
 
10
10
  </head>
11
11
 
12
12
  <body>
13
13
  <div id="<%= mountId %>"><!--<?- html ?>--></div>
14
- ${partials.body.join("\n")}
14
+ ${partials.body.join('\n')}
15
15
  <!--<?- chunksMap.js ?>-->
16
16
  <!--<?- SSRDataScript ?>-->
17
17
  <!--<?- bottomTemplate ?>-->
@@ -19,6 +19,4 @@ const html = (partials) => `
19
19
 
20
20
  </html>
21
21
  `;
22
- export {
23
- html
24
- };
22
+ export { html };
@@ -0,0 +1,55 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { JS_EXTENSIONS, getCommand, normalizeToPosixPath } from "@modern-js/utils";
4
+ import { parse } from "es-module-lexer";
5
+ import { transform } from "esbuild";
6
+ const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
7
+ const filePath = path.join(dir, filename);
8
+ if (fs.statSync(filePath).isDirectory()) return [
9
+ ...previous,
10
+ ...walkDirectory(filePath)
11
+ ];
12
+ return [
13
+ ...previous,
14
+ filePath
15
+ ];
16
+ }, []);
17
+ const replaceWithAlias = (base, filePath, alias)=>{
18
+ if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
19
+ return filePath;
20
+ };
21
+ const parseModule = async ({ source, filename })=>{
22
+ let content = source;
23
+ if (JS_EXTENSIONS.some((ext)=>filename.endsWith(ext))) {
24
+ const result = await transform(content, {
25
+ loader: path.extname(filename).slice(1),
26
+ format: 'esm'
27
+ });
28
+ content = result.code;
29
+ }
30
+ return await parse(content);
31
+ };
32
+ const getServerCombinedModueFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
33
+ const checkIsBuildCommands = ()=>{
34
+ const buildCommands = [
35
+ 'dev',
36
+ 'start',
37
+ 'build',
38
+ 'inspect',
39
+ 'deploy',
40
+ 'dev-worker'
41
+ ];
42
+ const command = getCommand();
43
+ return buildCommands.includes(command);
44
+ };
45
+ const checkIsServeCommand = ()=>{
46
+ const command = getCommand();
47
+ return 'serve' === command;
48
+ };
49
+ const isSubDirOrEqual = (parent, child)=>{
50
+ if (parent === child) return true;
51
+ const relative = path.relative(parent, child);
52
+ const isSubdir = relative && !relative.startsWith('..') && !path.isAbsolute(relative);
53
+ return Boolean(isSubdir);
54
+ };
55
+ export { checkIsBuildCommands, checkIsServeCommand, getServerCombinedModueFile, isSubDirOrEqual, parseModule, replaceWithAlias, walkDirectory };
@@ -0,0 +1,38 @@
1
+ import { provider } from "std-env";
2
+ import { createGhPagesPreset } from "./platforms/gh-pages.mjs";
3
+ import { createNetlifyPreset } from "./platforms/netlify.mjs";
4
+ import { createNodePreset } from "./platforms/node.mjs";
5
+ import { createVercelPreset } from "./platforms/vercel.mjs";
6
+ import { getProjectUsage } from "./utils.mjs";
7
+ const deployPresets = {
8
+ node: createNodePreset,
9
+ vercel: createVercelPreset,
10
+ netlify: createNetlifyPreset,
11
+ ghPages: createGhPagesPreset
12
+ };
13
+ async function getDeployPreset(appContext, modernConfig, deployTarget) {
14
+ const { appDirectory, distDirectory, metaName } = appContext;
15
+ const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
16
+ const needModernServer = useSSR || useAPI || useWebServer;
17
+ const createPreset = deployPresets[deployTarget];
18
+ if (!createPreset) throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
19
+ return createPreset(appContext, modernConfig, needModernServer);
20
+ }
21
+ const deploy = ()=>({
22
+ name: '@modern-js/plugin-deploy',
23
+ setup: (api)=>{
24
+ const deployTarget = process.env.MODERNJS_DEPLOY || provider || 'node';
25
+ api.deploy(async ()=>{
26
+ const appContext = api.getAppContext();
27
+ const { metaName } = appContext;
28
+ if ('modern-js' !== metaName && !process.env.MODERNJS_DEPLOY) return;
29
+ const modernConfig = api.getNormalizedConfig();
30
+ const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
31
+ deployPreset?.prepare && await deployPreset?.prepare();
32
+ deployPreset?.writeOutput && await deployPreset?.writeOutput();
33
+ deployPreset?.genEntry && await deployPreset?.genEntry();
34
+ deployPreset?.end && await deployPreset?.end();
35
+ });
36
+ }
37
+ });
38
+ export { deploy as default };
@@ -0,0 +1,43 @@
1
+ import path from "path";
2
+ import { fs, logger } from "@modern-js/utils";
3
+ async function reorganizeHtmlFiles(routes, baseDir, baseUrl = '/') {
4
+ if (!routes || !Array.isArray(routes)) return void logger.error('Invalid server routes');
5
+ await fs.ensureDir(baseDir);
6
+ const baseUrlRegexp = new RegExp(`^${baseUrl}\\/?`);
7
+ const collectedEntryPaths = new Set();
8
+ const copyPromises = routes.map(async (route)=>{
9
+ const { urlPath, entryPath } = route;
10
+ if (!entryPath) return void logger.warn(`Route ${urlPath} does not specify entryPath, skipping`);
11
+ if (collectedEntryPaths.has(entryPath)) return;
12
+ collectedEntryPaths.add(entryPath);
13
+ const sourceHtmlPath = path.join(baseDir, entryPath);
14
+ if (!await fs.pathExists(sourceHtmlPath)) return void logger.error(`Source HTML file does not exist: ${sourceHtmlPath}`);
15
+ const targetDir = urlPath.replace(baseUrlRegexp, '');
16
+ await fs.ensureDir(path.dirname(targetDir));
17
+ const targetHtmlPath = path.join(baseDir, targetDir, 'index.html');
18
+ try {
19
+ await fs.move(sourceHtmlPath, targetHtmlPath);
20
+ } catch (error) {
21
+ logger.error(`Failed to copy HTML file: ${error.message}`);
22
+ }
23
+ });
24
+ await Promise.all(copyPromises);
25
+ }
26
+ const createGhPagesPreset = (appContext, modernConfig)=>{
27
+ const { serverRoutes, appDirectory, distDirectory } = appContext;
28
+ const { server: { baseUrl } } = modernConfig;
29
+ const outputDirectory = path.join(appDirectory, '.output');
30
+ return {
31
+ name: 'gh-pages',
32
+ async prepare () {
33
+ await fs.remove(outputDirectory);
34
+ },
35
+ async writeOutput () {
36
+ await fs.copy(distDirectory, outputDirectory);
37
+ },
38
+ async end () {
39
+ await reorganizeHtmlFiles(serverRoutes, outputDirectory, Array.isArray(baseUrl) ? baseUrl[0] : baseUrl);
40
+ }
41
+ };
42
+ };
43
+ export { createGhPagesPreset };
@@ -1 +1,2 @@
1
- export { handler as default } from './netlify-handler.cjs';
1
+ import { handler } from "./netlify-handler.mjs";
2
+ export { handler as default };