@modern-js/app-tools 2.3.1-alpha.2 → 2.5.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 (362) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +14 -18
  3. package/dist/{js/node → cjs}/analyze/constants.js +0 -0
  4. package/dist/cjs/analyze/generateCode.js +249 -0
  5. package/dist/{js/node → cjs}/analyze/getBundleEntry.js +6 -0
  6. package/dist/{js/node → cjs}/analyze/getClientRoutes/getRoutes.js +1 -18
  7. package/dist/{js/node → cjs}/analyze/getClientRoutes/getRoutesLegacy.js +1 -18
  8. package/dist/{js/node → cjs}/analyze/getClientRoutes/index.js +0 -0
  9. package/dist/{js/node → cjs}/analyze/getClientRoutes/utils.js +0 -0
  10. package/dist/{js/node → cjs}/analyze/getFileSystemEntry.js +0 -0
  11. package/dist/{js/node → cjs}/analyze/getHtmlTemplate.js +4 -24
  12. package/dist/{js/node → cjs}/analyze/getServerRoutes.js +22 -42
  13. package/dist/cjs/analyze/index.js +290 -0
  14. package/dist/{js/node → cjs}/analyze/isDefaultExportFunction.js +0 -0
  15. package/dist/{js/node → cjs}/analyze/makeLegalIdentifier.js +0 -0
  16. package/dist/{js/node → cjs}/analyze/nestedRoutes.js +16 -50
  17. package/dist/{js/node → cjs}/analyze/templates.js +16 -49
  18. package/dist/{js/node → cjs}/analyze/utils.js +9 -29
  19. package/dist/cjs/builder/builder-rspack/index.js +31 -0
  20. package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  21. package/dist/cjs/builder/builder-webpack/index.js +78 -0
  22. package/dist/{js/node/builder/webpackPlugins/routerPlugin.js → cjs/builder/builder-webpack/webpackPlugins/RouterPlugin.js} +14 -29
  23. package/dist/cjs/builder/builder-webpack/webpackPlugins/index.js +17 -0
  24. package/dist/cjs/builder/generator/createBuilderOptions.js +47 -0
  25. package/dist/{js/node/config/initial/index.js → cjs/builder/generator/createBuilderProviderConfig.js} +26 -18
  26. package/dist/cjs/builder/generator/getBuilderTargets.js +39 -0
  27. package/dist/cjs/builder/generator/index.js +58 -0
  28. package/dist/cjs/builder/index.js +46 -0
  29. package/dist/{js/node/builder/builderPlugins/compatModern.js → cjs/builder/shared/builderPlugins/adapterModern.js} +109 -137
  30. package/dist/{js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js → cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
  31. package/dist/{js/node/builder/webpackPlugins/htmlBottomTemplate.js → cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
  32. package/dist/{js/node/builder/share.js → cjs/builder/shared/createCopyPattern.js} +3 -3
  33. package/dist/cjs/builder/shared/index.js +19 -0
  34. package/dist/{js/node/builder → cjs/builder/shared}/loaders/serverModuleLoader.js +0 -0
  35. package/dist/{js/node/utils → cjs/builder/shared}/types.js +0 -0
  36. package/dist/{js/node → cjs}/commands/build.js +9 -46
  37. package/dist/cjs/commands/deploy.js +31 -0
  38. package/dist/{js/node → cjs}/commands/dev.js +17 -52
  39. package/dist/{js/node → cjs}/commands/index.js +0 -0
  40. package/dist/{js/node → cjs}/commands/inspect.js +2 -22
  41. package/dist/{js/node → cjs}/commands/serve.js +8 -28
  42. package/dist/{js/node → cjs}/config/default.js +16 -27
  43. package/dist/cjs/config/index.js +19 -0
  44. package/dist/cjs/config/initialize/index.js +35 -0
  45. package/dist/{js/node/config/initial → cjs/config/initialize}/inits.js +8 -22
  46. package/dist/{js/node/config/initial → cjs/config/legacy}/createHtmlConfig.js +0 -0
  47. package/dist/{js/node/config/initial → cjs/config/legacy}/createOutputConfig.js +0 -0
  48. package/dist/{js/node/config/initial → cjs/config/legacy}/createSourceConfig.js +0 -0
  49. package/dist/{js/node/config/initial → cjs/config/legacy}/createToolsConfig.js +0 -0
  50. package/dist/{js/node/config/initial/transformNormalizedConfig.js → cjs/config/legacy/index.js} +8 -3
  51. package/dist/cjs/defineConfig.js +33 -0
  52. package/dist/{js/node → cjs}/exports/server.js +0 -0
  53. package/dist/{js/node → cjs}/hooks.js +0 -0
  54. package/dist/cjs/index.js +198 -0
  55. package/dist/cjs/initialize/index.js +102 -0
  56. package/dist/{js/node → cjs}/locale/en.js +0 -0
  57. package/dist/{js/node → cjs}/locale/index.js +0 -0
  58. package/dist/{js/node → cjs}/locale/zh.js +1 -1
  59. package/dist/{js/node → cjs}/schema/Schema.js +0 -0
  60. package/dist/{js/node → cjs}/schema/index.js +0 -0
  61. package/dist/{js/node → cjs}/schema/legacy.js +0 -0
  62. package/dist/{js/node → cjs}/types/config/deploy.js +0 -0
  63. package/dist/{js/node → cjs}/types/config/dev.js +0 -0
  64. package/dist/{js/node → cjs}/types/config/experiments.js +0 -0
  65. package/dist/{js/node → cjs}/types/config/html.js +0 -0
  66. package/dist/{js/node → cjs}/types/config/index.js +0 -0
  67. package/dist/{js/node → cjs}/types/config/output.js +0 -0
  68. package/dist/{js/node → cjs}/types/config/performance.js +0 -0
  69. package/dist/{js/node → cjs}/types/config/security.js +0 -0
  70. package/dist/{js/node → cjs}/types/config/source.js +0 -0
  71. package/dist/{js/node → cjs}/types/config/tools.js +0 -0
  72. package/dist/{js/node → cjs}/types/hooks.js +0 -0
  73. package/dist/{js/node → cjs}/types/index.js +0 -0
  74. package/dist/{js/node → cjs}/types/legacyConfig/deploy.js +0 -0
  75. package/dist/{js/node → cjs}/types/legacyConfig/dev.js +0 -0
  76. package/dist/{js/node → cjs}/types/legacyConfig/index.js +0 -0
  77. package/dist/{js/node → cjs}/types/legacyConfig/output.js +0 -0
  78. package/dist/{js/node → cjs}/types/legacyConfig/source.js +0 -0
  79. package/dist/{js/node → cjs}/types/legacyConfig/tools.js +0 -0
  80. package/dist/cjs/types/utils.js +15 -0
  81. package/dist/{js/node → cjs}/utils/config.js +19 -57
  82. package/dist/{js/node → cjs}/utils/createServer.js +10 -46
  83. package/dist/{js/node → cjs}/utils/env.js +0 -0
  84. package/dist/{js/node → cjs}/utils/generateWatchFiles.js +16 -38
  85. package/dist/{js/node → cjs}/utils/getSelectedEntries.js +3 -23
  86. package/dist/{js/node/config/index.js → cjs/utils/getServerInternalPlugins.js} +20 -13
  87. package/dist/{js/node → cjs}/utils/language.js +0 -0
  88. package/dist/{js/node → cjs}/utils/printInstructions.js +3 -23
  89. package/dist/cjs/utils/restart.js +45 -0
  90. package/dist/{js/node → cjs}/utils/routes.js +3 -23
  91. package/dist/cjs/utils/types.js +15 -0
  92. package/dist/{js/treeshaking → esm}/analyze/constants.js +0 -0
  93. package/dist/{js/treeshaking → esm}/analyze/generateCode.js +14 -14
  94. package/dist/{js/treeshaking → esm}/analyze/getBundleEntry.js +4 -2
  95. package/dist/{js/treeshaking → esm}/analyze/getClientRoutes/getRoutes.js +1 -1
  96. package/dist/{js/treeshaking → esm}/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  97. package/dist/{js/treeshaking → esm}/analyze/getClientRoutes/index.js +0 -0
  98. package/dist/{js/treeshaking → esm}/analyze/getClientRoutes/utils.js +0 -0
  99. package/dist/{js/treeshaking → esm}/analyze/getFileSystemEntry.js +1 -1
  100. package/dist/{js/treeshaking → esm}/analyze/getHtmlTemplate.js +0 -0
  101. package/dist/{js/treeshaking → esm}/analyze/getServerRoutes.js +8 -6
  102. package/dist/{js/treeshaking → esm}/analyze/index.js +142 -137
  103. package/dist/{js/treeshaking → esm}/analyze/isDefaultExportFunction.js +0 -0
  104. package/dist/{js/treeshaking → esm}/analyze/makeLegalIdentifier.js +0 -0
  105. package/dist/{js/treeshaking → esm}/analyze/nestedRoutes.js +5 -5
  106. package/dist/{js/treeshaking → esm}/analyze/templates.js +8 -7
  107. package/dist/{js/treeshaking → esm}/analyze/utils.js +3 -3
  108. package/dist/esm/builder/builder-rspack/index.js +6 -0
  109. package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  110. package/dist/{js/treeshaking/builder → esm/builder/builder-webpack}/index.js +44 -117
  111. package/dist/{js/treeshaking/builder/webpackPlugins/routerPlugin.js → esm/builder/builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
  112. package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +1 -0
  113. package/dist/esm/builder/generator/createBuilderOptions.js +41 -0
  114. package/dist/esm/builder/generator/createBuilderProviderConfig.js +70 -0
  115. package/dist/esm/builder/generator/getBuilderTargets.js +16 -0
  116. package/dist/esm/builder/generator/index.js +199 -0
  117. package/dist/esm/builder/index.js +175 -0
  118. package/dist/{js/treeshaking/builder/builderPlugins/compatModern.js → esm/builder/shared/builderPlugins/adapterModern.js} +138 -142
  119. package/dist/{js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js → esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
  120. package/dist/{js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js → esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
  121. package/dist/{js/treeshaking/builder/share.js → esm/builder/shared/createCopyPattern.js} +0 -0
  122. package/dist/esm/builder/shared/index.js +3 -0
  123. package/dist/{js/treeshaking/builder → esm/builder/shared}/loaders/serverModuleLoader.js +0 -0
  124. package/dist/{js/treeshaking/utils → esm/builder/shared}/types.js +0 -0
  125. package/dist/{js/treeshaking → esm}/commands/build.js +0 -0
  126. package/dist/{js/treeshaking → esm}/commands/deploy.js +0 -0
  127. package/dist/{js/treeshaking → esm}/commands/dev.js +2 -2
  128. package/dist/{js/treeshaking → esm}/commands/index.js +0 -0
  129. package/dist/{js/treeshaking → esm}/commands/inspect.js +0 -0
  130. package/dist/{js/treeshaking → esm}/commands/serve.js +2 -2
  131. package/dist/{js/treeshaking → esm}/config/default.js +2 -2
  132. package/dist/esm/config/index.js +3 -0
  133. package/dist/esm/config/initialize/index.js +10 -0
  134. package/dist/{js/treeshaking/config/initial → esm/config/initialize}/inits.js +6 -4
  135. package/dist/esm/config/legacy/createHtmlConfig.js +19 -0
  136. package/dist/{js/treeshaking/config/initial → esm/config/legacy}/createOutputConfig.js +1 -1
  137. package/dist/{js/treeshaking/config/initial → esm/config/legacy}/createSourceConfig.js +1 -1
  138. package/dist/{js/treeshaking/config/initial → esm/config/legacy}/createToolsConfig.js +1 -1
  139. package/dist/{js/treeshaking/config/initial/transformNormalizedConfig.js → esm/config/legacy/index.js} +4 -1
  140. package/dist/{js/treeshaking → esm}/defineConfig.js +0 -0
  141. package/dist/{js/treeshaking → esm}/exports/server.js +0 -0
  142. package/dist/{js/treeshaking → esm}/hooks.js +0 -0
  143. package/dist/{js/treeshaking → esm}/index.js +19 -12
  144. package/dist/{js/treeshaking → esm}/initialize/index.js +36 -28
  145. package/dist/{js/treeshaking → esm}/locale/en.js +0 -0
  146. package/dist/{js/treeshaking → esm}/locale/index.js +0 -0
  147. package/dist/{js/treeshaking → esm}/locale/zh.js +1 -1
  148. package/dist/{js/treeshaking → esm}/schema/Schema.js +0 -0
  149. package/dist/{js/treeshaking → esm}/schema/index.js +0 -0
  150. package/dist/{js/treeshaking → esm}/schema/legacy.js +0 -0
  151. package/dist/{js/treeshaking → esm}/types/config/deploy.js +0 -0
  152. package/dist/{js/treeshaking → esm}/types/config/dev.js +0 -0
  153. package/dist/{js/treeshaking → esm}/types/config/experiments.js +0 -0
  154. package/dist/{js/treeshaking → esm}/types/config/html.js +0 -0
  155. package/dist/{js/treeshaking → esm}/types/config/index.js +0 -0
  156. package/dist/{js/treeshaking → esm}/types/config/output.js +0 -0
  157. package/dist/{js/treeshaking → esm}/types/config/performance.js +0 -0
  158. package/dist/{js/treeshaking → esm}/types/config/security.js +0 -0
  159. package/dist/{js/treeshaking → esm}/types/config/source.js +0 -0
  160. package/dist/{js/treeshaking → esm}/types/config/tools.js +0 -0
  161. package/dist/{js/treeshaking → esm}/types/hooks.js +0 -0
  162. package/dist/{js/treeshaking → esm}/types/index.js +0 -0
  163. package/dist/{js/treeshaking → esm}/types/legacyConfig/deploy.js +0 -0
  164. package/dist/{js/treeshaking → esm}/types/legacyConfig/dev.js +0 -0
  165. package/dist/{js/treeshaking → esm}/types/legacyConfig/index.js +0 -0
  166. package/dist/{js/treeshaking → esm}/types/legacyConfig/output.js +0 -0
  167. package/dist/{js/treeshaking → esm}/types/legacyConfig/source.js +0 -0
  168. package/dist/{js/treeshaking → esm}/types/legacyConfig/tools.js +0 -0
  169. package/dist/esm/types/utils.js +1 -0
  170. package/dist/{js/treeshaking → esm}/utils/config.js +2 -2
  171. package/dist/{js/treeshaking → esm}/utils/createServer.js +0 -0
  172. package/dist/{js/treeshaking → esm}/utils/env.js +0 -0
  173. package/dist/{js/treeshaking → esm}/utils/generateWatchFiles.js +0 -0
  174. package/dist/{js/treeshaking → esm}/utils/getSelectedEntries.js +0 -0
  175. package/dist/{js/treeshaking → esm}/utils/getServerInternalPlugins.js +2 -2
  176. package/dist/{js/treeshaking → esm}/utils/language.js +0 -0
  177. package/dist/{js/treeshaking → esm}/utils/printInstructions.js +0 -0
  178. package/dist/{js/treeshaking → esm}/utils/restart.js +0 -0
  179. package/dist/{js/treeshaking → esm}/utils/routes.js +0 -0
  180. package/dist/esm/utils/types.js +1 -0
  181. package/dist/{js/modern → esm-node}/analyze/constants.js +0 -0
  182. package/dist/esm-node/analyze/generateCode.js +225 -0
  183. package/dist/{js/modern → esm-node}/analyze/getBundleEntry.js +6 -0
  184. package/dist/{js/modern → esm-node}/analyze/getClientRoutes/getRoutes.js +1 -20
  185. package/dist/{js/modern → esm-node}/analyze/getClientRoutes/getRoutesLegacy.js +1 -20
  186. package/dist/{js/modern → esm-node}/analyze/getClientRoutes/index.js +0 -0
  187. package/dist/{js/modern → esm-node}/analyze/getClientRoutes/utils.js +0 -0
  188. package/dist/{js/modern → esm-node}/analyze/getFileSystemEntry.js +0 -0
  189. package/dist/{js/modern → esm-node}/analyze/getHtmlTemplate.js +4 -24
  190. package/dist/{js/modern → esm-node}/analyze/getServerRoutes.js +24 -45
  191. package/dist/esm-node/analyze/index.js +281 -0
  192. package/dist/{js/modern → esm-node}/analyze/isDefaultExportFunction.js +0 -0
  193. package/dist/{js/modern → esm-node}/analyze/makeLegalIdentifier.js +0 -0
  194. package/dist/{js/modern → esm-node}/analyze/nestedRoutes.js +16 -52
  195. package/dist/{js/modern → esm-node}/analyze/templates.js +16 -51
  196. package/dist/{js/modern → esm-node}/analyze/utils.js +9 -29
  197. package/dist/esm-node/builder/builder-rspack/index.js +8 -0
  198. package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
  199. package/dist/esm-node/builder/builder-webpack/index.js +51 -0
  200. package/dist/{js/modern/builder/webpackPlugins/routerPlugin.js → esm-node/builder/builder-webpack/webpackPlugins/RouterPlugin.js} +8 -25
  201. package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +1 -0
  202. package/dist/esm-node/builder/generator/createBuilderOptions.js +24 -0
  203. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +26 -0
  204. package/dist/esm-node/builder/generator/getBuilderTargets.js +21 -0
  205. package/dist/esm-node/builder/generator/index.js +29 -0
  206. package/dist/esm-node/builder/index.js +17 -0
  207. package/dist/{js/modern/builder/builderPlugins/compatModern.js → esm-node/builder/shared/builderPlugins/adapterModern.js} +104 -135
  208. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
  209. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
  210. package/dist/{js/modern/builder/share.js → esm-node/builder/shared/createCopyPattern.js} +0 -0
  211. package/dist/esm-node/builder/shared/index.js +3 -0
  212. package/dist/{js/modern/builder → esm-node/builder/shared}/loaders/serverModuleLoader.js +0 -0
  213. package/dist/{js/modern/utils → esm-node/builder/shared}/types.js +0 -0
  214. package/dist/esm-node/commands/build.js +52 -0
  215. package/dist/esm-node/commands/deploy.js +8 -0
  216. package/dist/esm-node/commands/dev.js +72 -0
  217. package/dist/{js/modern → esm-node}/commands/index.js +0 -0
  218. package/dist/esm-node/commands/inspect.js +18 -0
  219. package/dist/{js/modern → esm-node}/commands/serve.js +8 -28
  220. package/dist/{js/modern → esm-node}/config/default.js +16 -29
  221. package/dist/esm-node/config/index.js +3 -0
  222. package/dist/esm-node/config/initialize/index.js +12 -0
  223. package/dist/{js/modern/config/initial → esm-node/config/initialize}/inits.js +8 -24
  224. package/dist/{js/modern/config/initial → esm-node/config/legacy}/createHtmlConfig.js +0 -0
  225. package/dist/{js/modern/config/initial → esm-node/config/legacy}/createOutputConfig.js +0 -0
  226. package/dist/{js/modern/config/initial → esm-node/config/legacy}/createSourceConfig.js +0 -0
  227. package/dist/{js/modern/config/initial → esm-node/config/legacy}/createToolsConfig.js +0 -0
  228. package/dist/{js/modern/config/initial/transformNormalizedConfig.js → esm-node/config/legacy/index.js} +4 -0
  229. package/dist/esm-node/defineConfig.js +9 -0
  230. package/dist/{js/modern → esm-node}/exports/server.js +0 -0
  231. package/dist/{js/modern → esm-node}/hooks.js +0 -0
  232. package/dist/esm-node/index.js +172 -0
  233. package/dist/esm-node/initialize/index.js +91 -0
  234. package/dist/{js/modern → esm-node}/locale/en.js +0 -0
  235. package/dist/{js/modern → esm-node}/locale/index.js +0 -0
  236. package/dist/{js/modern → esm-node}/locale/zh.js +1 -1
  237. package/dist/{js/modern → esm-node}/schema/Schema.js +0 -0
  238. package/dist/{js/modern → esm-node}/schema/index.js +0 -0
  239. package/dist/{js/modern → esm-node}/schema/legacy.js +0 -0
  240. package/dist/{js/modern → esm-node}/types/config/deploy.js +0 -0
  241. package/dist/{js/modern → esm-node}/types/config/dev.js +0 -0
  242. package/dist/{js/modern → esm-node}/types/config/experiments.js +0 -0
  243. package/dist/{js/modern → esm-node}/types/config/html.js +0 -0
  244. package/dist/{js/modern → esm-node}/types/config/index.js +0 -0
  245. package/dist/{js/modern → esm-node}/types/config/output.js +0 -0
  246. package/dist/{js/modern → esm-node}/types/config/performance.js +0 -0
  247. package/dist/{js/modern → esm-node}/types/config/security.js +0 -0
  248. package/dist/{js/modern → esm-node}/types/config/source.js +0 -0
  249. package/dist/{js/modern → esm-node}/types/config/tools.js +0 -0
  250. package/dist/{js/modern → esm-node}/types/hooks.js +0 -0
  251. package/dist/{js/modern → esm-node}/types/index.js +0 -0
  252. package/dist/{js/modern → esm-node}/types/legacyConfig/deploy.js +0 -0
  253. package/dist/{js/modern → esm-node}/types/legacyConfig/dev.js +0 -0
  254. package/dist/{js/modern → esm-node}/types/legacyConfig/index.js +0 -0
  255. package/dist/{js/modern → esm-node}/types/legacyConfig/output.js +0 -0
  256. package/dist/{js/modern → esm-node}/types/legacyConfig/source.js +0 -0
  257. package/dist/{js/modern → esm-node}/types/legacyConfig/tools.js +0 -0
  258. package/dist/esm-node/types/utils.js +0 -0
  259. package/dist/esm-node/utils/config.js +88 -0
  260. package/dist/esm-node/utils/createServer.js +37 -0
  261. package/dist/{js/modern → esm-node}/utils/env.js +0 -0
  262. package/dist/esm-node/utils/generateWatchFiles.js +33 -0
  263. package/dist/{js/modern → esm-node}/utils/getSelectedEntries.js +3 -23
  264. package/dist/esm-node/utils/getServerInternalPlugins.js +18 -0
  265. package/dist/{js/modern → esm-node}/utils/language.js +0 -0
  266. package/dist/esm-node/utils/printInstructions.js +11 -0
  267. package/dist/esm-node/utils/restart.js +22 -0
  268. package/dist/esm-node/utils/routes.js +10 -0
  269. package/dist/esm-node/utils/types.js +0 -0
  270. package/dist/types/analyze/generateCode.d.ts +1 -1
  271. package/dist/types/analyze/getBundleEntry.d.ts +1 -1
  272. package/dist/types/analyze/getFileSystemEntry.d.ts +1 -1
  273. package/dist/types/analyze/getHtmlTemplate.d.ts +2 -2
  274. package/dist/types/analyze/getServerRoutes.d.ts +1 -1
  275. package/dist/types/analyze/index.d.ts +5 -1
  276. package/dist/types/builder/builder-rspack/index.d.ts +2 -0
  277. package/dist/types/builder/{builderPlugins → builder-webpack/builderPlugins}/compatModern.d.ts +2 -2
  278. package/dist/types/builder/builder-webpack/index.d.ts +4 -0
  279. package/dist/types/builder/{webpackPlugins/routerPlugin.d.ts → builder-webpack/webpackPlugins/RouterPlugin.d.ts} +1 -1
  280. package/dist/types/builder/builder-webpack/webpackPlugins/index.d.ts +1 -0
  281. package/dist/types/builder/generator/createBuilderOptions.d.ts +3 -0
  282. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +2 -0
  283. package/dist/types/builder/generator/getBuilderTargets.d.ts +3 -0
  284. package/dist/types/builder/generator/index.d.ts +17 -0
  285. package/dist/types/builder/index.d.ts +1 -18
  286. package/dist/types/builder/shared/builderPlugins/adapterModern.d.ts +13 -0
  287. package/dist/types/builder/{webpackPlugins/htmlAsyncChunkPlugin.d.ts → shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts} +2 -1
  288. package/dist/types/builder/{webpackPlugins/htmlBottomTemplate.d.ts → shared/bundlerPlugins/HtmlBottomTemplate.d.ts} +2 -1
  289. package/dist/types/builder/{share.d.ts → shared/createCopyPattern.d.ts} +1 -1
  290. package/dist/types/builder/shared/index.d.ts +3 -0
  291. package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +4 -0
  292. package/dist/types/builder/shared/types.d.ts +16 -0
  293. package/dist/types/commands/build.d.ts +1 -1
  294. package/dist/types/commands/deploy.d.ts +1 -1
  295. package/dist/types/commands/dev.d.ts +1 -1
  296. package/dist/types/commands/inspect.d.ts +1 -1
  297. package/dist/types/commands/serve.d.ts +1 -1
  298. package/dist/types/config/default.d.ts +1 -1
  299. package/dist/types/config/index.d.ts +3 -2
  300. package/dist/types/config/initialize/index.d.ts +2 -0
  301. package/dist/types/config/{initial → initialize}/inits.d.ts +3 -3
  302. package/dist/types/config/{initial → legacy}/createHtmlConfig.d.ts +1 -1
  303. package/dist/types/config/{initial → legacy}/createOutputConfig.d.ts +1 -1
  304. package/dist/types/config/{initial → legacy}/createSourceConfig.d.ts +1 -1
  305. package/dist/types/config/{initial → legacy}/createToolsConfig.d.ts +1 -1
  306. package/dist/types/config/legacy/index.d.ts +3 -0
  307. package/dist/types/defineConfig.d.ts +2 -2
  308. package/dist/types/index.d.ts +7 -3
  309. package/dist/types/initialize/index.d.ts +6 -2
  310. package/dist/types/types/config/deploy.d.ts +1 -2
  311. package/dist/types/types/config/dev.d.ts +2 -3
  312. package/dist/types/types/config/experiments.d.ts +1 -2
  313. package/dist/types/types/config/html.d.ts +5 -3
  314. package/dist/types/types/config/index.d.ts +41 -48
  315. package/dist/types/types/config/output.d.ts +8 -3
  316. package/dist/types/types/config/performance.d.ts +6 -3
  317. package/dist/types/types/config/security.d.ts +3 -3
  318. package/dist/types/types/config/source.d.ts +7 -3
  319. package/dist/types/types/config/tools.d.ts +10 -4
  320. package/dist/types/types/hooks.d.ts +6 -4
  321. package/dist/types/types/index.d.ts +19 -7
  322. package/dist/types/types/utils.d.ts +7 -0
  323. package/dist/types/utils/config.d.ts +1 -1
  324. package/dist/types/utils/getServerInternalPlugins.d.ts +1 -1
  325. package/dist/types/utils/printInstructions.d.ts +1 -1
  326. package/package.json +40 -32
  327. package/dist/js/modern/analyze/generateCode.js +0 -247
  328. package/dist/js/modern/analyze/index.js +0 -332
  329. package/dist/js/modern/builder/index.js +0 -159
  330. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
  331. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
  332. package/dist/js/modern/commands/build.js +0 -91
  333. package/dist/js/modern/commands/deploy.js +0 -28
  334. package/dist/js/modern/commands/dev.js +0 -109
  335. package/dist/js/modern/commands/inspect.js +0 -38
  336. package/dist/js/modern/config/index.js +0 -8
  337. package/dist/js/modern/config/initial/index.js +0 -16
  338. package/dist/js/modern/defineConfig.js +0 -27
  339. package/dist/js/modern/index.js +0 -211
  340. package/dist/js/modern/initialize/index.js +0 -124
  341. package/dist/js/modern/utils/config.js +0 -128
  342. package/dist/js/modern/utils/createServer.js +0 -75
  343. package/dist/js/modern/utils/generateWatchFiles.js +0 -55
  344. package/dist/js/modern/utils/getServerInternalPlugins.js +0 -58
  345. package/dist/js/modern/utils/printInstructions.js +0 -31
  346. package/dist/js/modern/utils/restart.js +0 -44
  347. package/dist/js/modern/utils/routes.js +0 -30
  348. package/dist/js/node/analyze/generateCode.js +0 -271
  349. package/dist/js/node/analyze/index.js +0 -339
  350. package/dist/js/node/builder/index.js +0 -177
  351. package/dist/js/node/commands/deploy.js +0 -51
  352. package/dist/js/node/defineConfig.js +0 -49
  353. package/dist/js/node/index.js +0 -235
  354. package/dist/js/node/initialize/index.js +0 -134
  355. package/dist/js/node/utils/getServerInternalPlugins.js +0 -79
  356. package/dist/js/node/utils/restart.js +0 -67
  357. package/dist/js/treeshaking/config/index.js +0 -3
  358. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
  359. package/dist/js/treeshaking/config/initial/index.js +0 -12
  360. package/dist/types/builder/loaders/serverModuleLoader.d.ts +0 -3
  361. package/dist/types/config/initial/index.d.ts +0 -4
  362. package/dist/types/config/initial/transformNormalizedConfig.d.ts +0 -2
@@ -0,0 +1,51 @@
1
+ import {
2
+ builderWebpackProvider
3
+ } from "@modern-js/builder-webpack-provider";
4
+ import { applyOptionsChain } from "@modern-js/utils";
5
+ import { createCopyPattern } from "../shared";
6
+ import { generateBuilder } from "../generator";
7
+ import { PluginCompatModern } from "./builderPlugins/compatModern";
8
+ function createWebpackBuilderForModern(options) {
9
+ return generateBuilder(options, builderWebpackProvider, {
10
+ modifyBuilderConfig(config) {
11
+ modifyOutputConfig(config, options.appContext);
12
+ },
13
+ async modifyBuilderInstance(builder) {
14
+ await applyBuilderPlugins(builder, options);
15
+ }
16
+ });
17
+ }
18
+ function modifyOutputConfig(config, appContext) {
19
+ config.output = createOutputConfig(config, appContext);
20
+ function createOutputConfig(config2, appContext2) {
21
+ const defaultCopyPattern = createCopyPattern(appContext2, config2, "upload");
22
+ const { copy } = config2.output;
23
+ const copyOptions = Array.isArray(copy) ? copy : copy == null ? void 0 : copy.patterns;
24
+ const builderCopy = [...copyOptions || [], defaultCopyPattern];
25
+ return {
26
+ ...config2.output,
27
+ copy: builderCopy
28
+ };
29
+ }
30
+ }
31
+ async function applyBuilderPlugins(builder, options) {
32
+ const { normalizedConfig } = options;
33
+ if (!normalizedConfig.output.disableNodePolyfill) {
34
+ const { PluginNodePolyfill } = await import("@modern-js/builder-plugin-node-polyfill");
35
+ builder.addPlugins([PluginNodePolyfill()]);
36
+ }
37
+ if (normalizedConfig.tools.esbuild) {
38
+ const { esbuild: esbuildOptions } = normalizedConfig.tools;
39
+ const { PluginEsbuild } = await import("@modern-js/builder-plugin-esbuild");
40
+ builder.addPlugins([
41
+ PluginEsbuild({
42
+ loader: false,
43
+ minimize: applyOptionsChain({}, esbuildOptions)
44
+ })
45
+ ]);
46
+ }
47
+ builder.addPlugins([PluginCompatModern(options)]);
48
+ }
49
+ export {
50
+ createWebpackBuilderForModern
51
+ };
@@ -1,23 +1,3 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
1
  import path from "path";
22
2
  import {
23
3
  fs,
@@ -32,6 +12,9 @@ class RouterPlugin {
32
12
  if (target === "node" || Array.isArray(target) && target.includes("node")) {
33
13
  return;
34
14
  }
15
+ if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
16
+ return;
17
+ }
35
18
  const { webpack } = compiler;
36
19
  const { Compilation, sources } = webpack;
37
20
  const { RawSource } = sources;
@@ -50,7 +33,7 @@ class RouterPlugin {
50
33
  name: PLUGIN_NAME,
51
34
  stage: PROCESS_ASSETS_STAGE_REPORT
52
35
  },
53
- () => __async(this, null, function* () {
36
+ async () => {
54
37
  const stats = compilation.getStats().toJson({
55
38
  chunkGroups: true,
56
39
  chunks: true
@@ -101,13 +84,13 @@ class RouterPlugin {
101
84
  compilation.updateAsset(file, new RawSource(newContent));
102
85
  }
103
86
  const filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
104
- yield fs.ensureFile(filename);
105
- yield fs.writeFile(filename, JSON.stringify(manifest, null, 2));
106
- })
87
+ await fs.ensureFile(filename);
88
+ await fs.writeFile(filename, JSON.stringify(manifest, null, 2));
89
+ }
107
90
  );
108
91
  });
109
92
  }
110
93
  }
111
94
  export {
112
- RouterPlugin as default
95
+ RouterPlugin
113
96
  };
@@ -0,0 +1 @@
1
+ export * from "./RouterPlugin";
@@ -0,0 +1,24 @@
1
+ function createBuilderOptions(target, appContext) {
2
+ const entries = {};
3
+ const { entrypoints = [], checkedEntries } = appContext;
4
+ for (const { entryName, entry } of entrypoints) {
5
+ if (checkedEntries && !checkedEntries.includes(entryName)) {
6
+ continue;
7
+ }
8
+ if (entryName in entries) {
9
+ entries[entryName].push(entry);
10
+ } else {
11
+ entries[entryName] = [entry];
12
+ }
13
+ }
14
+ return {
15
+ cwd: appContext.appDirectory,
16
+ target,
17
+ configPath: appContext.configFile || void 0,
18
+ entry: entries,
19
+ framework: appContext.metaName
20
+ };
21
+ }
22
+ export {
23
+ createBuilderOptions
24
+ };
@@ -0,0 +1,26 @@
1
+ function createBuilderProviderConfig(resolveConfig, appContext, modifyBuilderConfig) {
2
+ const htmlConfig = { ...resolveConfig.html };
3
+ if (!htmlConfig.template) {
4
+ htmlConfig.templateByEntries = {
5
+ ...htmlConfig.templateByEntries,
6
+ ...appContext.htmlTemplates
7
+ };
8
+ }
9
+ const config = {
10
+ ...resolveConfig,
11
+ dev: {
12
+ ...resolveConfig.dev,
13
+ port: appContext.port
14
+ },
15
+ html: htmlConfig,
16
+ output: {
17
+ ...resolveConfig.output,
18
+ cleanDistPath: false
19
+ }
20
+ };
21
+ modifyBuilderConfig == null ? void 0 : modifyBuilderConfig(config);
22
+ return config;
23
+ }
24
+ export {
25
+ createBuilderProviderConfig
26
+ };
@@ -0,0 +1,21 @@
1
+ import {
2
+ isProd,
3
+ isServiceWorker,
4
+ isSSR,
5
+ isUseSSRBundle
6
+ } from "@modern-js/utils";
7
+ function getBuilderTargets(normalizedConfig) {
8
+ const targets = ["web"];
9
+ const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
10
+ if (useNodeTarget) {
11
+ targets.push("node");
12
+ }
13
+ const useWorkerTarget = isProd() ? isServiceWorker(normalizedConfig) : false;
14
+ if (useWorkerTarget) {
15
+ targets.push("service-worker");
16
+ }
17
+ return targets;
18
+ }
19
+ export {
20
+ getBuilderTargets
21
+ };
@@ -0,0 +1,29 @@
1
+ import { createBuilder } from "@modern-js/builder";
2
+ import { createBuilderProviderConfig } from "./createBuilderProviderConfig";
3
+ import { getBuilderTargets } from "./getBuilderTargets";
4
+ import { createBuilderOptions } from "./createBuilderOptions";
5
+ async function generateBuilder(options, generateProvider, utils) {
6
+ const { normalizedConfig, appContext } = options;
7
+ const { modifyBuilderConfig, modifyBuilderInstance } = utils || {};
8
+ const builderConfig = createBuilderProviderConfig(
9
+ normalizedConfig,
10
+ appContext,
11
+ modifyBuilderConfig
12
+ );
13
+ const provider = generateProvider({
14
+ builderConfig
15
+ });
16
+ const target = getBuilderTargets(normalizedConfig);
17
+ const builderOptions = createBuilderOptions(target, appContext);
18
+ const builder = await createBuilder(provider, builderOptions);
19
+ await applyBuilderPlugins(builder, options);
20
+ await (modifyBuilderInstance == null ? void 0 : modifyBuilderInstance(builder));
21
+ return builder;
22
+ }
23
+ async function applyBuilderPlugins(builder, options) {
24
+ const { builderPluginAdapterModern } = await import("../shared/builderPlugins/adapterModern");
25
+ builder.addPlugins([builderPluginAdapterModern(options)]);
26
+ }
27
+ export {
28
+ generateBuilder
29
+ };
@@ -0,0 +1,17 @@
1
+ async function createBuilderGenerator(bundler) {
2
+ if (bundler === "rspack") {
3
+ try {
4
+ const { createRspackBuilderForModern } = await import("./builder-rspack");
5
+ return createRspackBuilderForModern;
6
+ } catch (_) {
7
+ throw new Error(
8
+ "Failed to use rspack, please check if you have `@modern-js/builder-rspack-provider` installed"
9
+ );
10
+ }
11
+ }
12
+ const { createWebpackBuilderForModern } = await import("./builder-webpack");
13
+ return createWebpackBuilderForModern;
14
+ }
15
+ export {
16
+ createBuilderGenerator
17
+ };
@@ -1,38 +1,32 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { join } from "path";
21
1
  import {
22
2
  mergeBuilderConfig
23
3
  } from "@modern-js/builder-shared";
24
- import { template as lodashTemplate } from "@modern-js/utils/lodash";
25
- import HtmlWebpackPlugin from "@modern-js/builder-webpack-provider/html-webpack-plugin";
26
4
  import { getEntryOptions } from "@modern-js/utils";
27
- import { BottomTemplatePlugin } from "../webpackPlugins/htmlBottomTemplate";
28
- import { HtmlAsyncChunkPlugin } from "../webpackPlugins/htmlAsyncChunkPlugin";
29
- import { createCopyPattern } from "../share";
30
- import RouterPlugin from "../webpackPlugins/routerPlugin";
31
- const PluginCompatModern = (appContext, modernConfig, options) => ({
32
- name: "builder-plugin-compat-modern",
5
+ import HtmlWebpackPlugin from "@modern-js/builder-webpack-provider/html-webpack-plugin";
6
+ import { template as lodashTemplate } from "@modern-js/utils/lodash";
7
+ import { HtmlAsyncChunkPlugin } from "../bundlerPlugins/HtmlAsyncChunkPlugin";
8
+ import { BottomTemplatePlugin } from "../bundlerPlugins/HtmlBottomTemplate";
9
+ const isStreamingSSR = (userConfig) => {
10
+ const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
11
+ const { server } = userConfig;
12
+ if (isStreaming(server.ssr)) {
13
+ return true;
14
+ }
15
+ if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
16
+ for (const name of Object.keys(server.ssrByEntries)) {
17
+ if (isStreaming(server.ssrByEntries[name])) {
18
+ return true;
19
+ }
20
+ }
21
+ }
22
+ return false;
23
+ };
24
+ const builderPluginAdapterModern = (options) => ({
25
+ name: "builder-plugin-adapter-modern",
33
26
  setup(api) {
27
+ const { normalizedConfig, appContext } = options;
34
28
  api.modifyBuilderConfig((config) => {
35
- if (isStreamingSSR(modernConfig)) {
29
+ if (isStreamingSSR(normalizedConfig)) {
36
30
  return mergeBuilderConfig(config, {
37
31
  html: {
38
32
  inject: "body"
@@ -41,71 +35,46 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
41
35
  }
42
36
  return config;
43
37
  });
44
- api.modifyWebpackChain((chain, { target, CHAIN_ID, isProd }) => {
45
- var _a;
46
- const builderNormalizedConfig = api.getNormalizedConfig();
38
+ api.modifyBundlerChain((chain, { target, CHAIN_ID, isProd }) => {
39
+ const builderConfig = api.getNormalizedConfig();
47
40
  if (target === "node") {
48
41
  chain.name("server");
42
+ } else if (target === "service-worker") {
43
+ chain.name("service-worker");
44
+ } else if (target === "web-worker") {
45
+ chain.name("worker");
49
46
  } else if (target === "modern-web") {
50
47
  chain.name("modern");
51
48
  } else {
52
49
  chain.name("client");
53
50
  }
54
- chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
55
- if (target === "node") {
56
- applyNodeCompat(chain, modernConfig, isProd);
51
+ if (target === "node" || target === "service-worker") {
52
+ applyNodeCompat(target, chain, normalizedConfig, isProd);
57
53
  }
58
- if (isHtmlEnabled(builderNormalizedConfig, target)) {
59
- applyBottomHtmlWebpackPlugin({
54
+ if (isHtmlEnabled(builderConfig, target)) {
55
+ applyBottomHtmlPlugin({
60
56
  api,
61
57
  chain,
62
- CHAIN_ID,
58
+ modernConfig: normalizedConfig,
63
59
  appContext,
64
- modernConfig
60
+ CHAIN_ID
65
61
  });
66
62
  applyAsyncChunkHtmlPlugin({
67
63
  chain,
68
- CHAIN_ID,
69
- modernConfig
70
- });
71
- }
72
- if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
73
- const defaultCopyPattern = createCopyPattern(
74
- appContext,
75
- modernConfig,
76
- "public",
77
- chain
78
- );
79
- chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
80
- var _a2;
81
- return [
82
- {
83
- patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
84
- }
85
- ];
64
+ modernConfig: normalizedConfig,
65
+ CHAIN_ID
86
66
  });
87
67
  }
88
- const { entrypoints } = appContext;
89
- const existNestedRoutes = entrypoints.some(
90
- (entrypoint) => entrypoint.nestedRoutesEntry
91
- );
92
- const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
93
- const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
94
- if (existNestedRoutes || routerManifest) {
95
- chain.plugin("route-plugin").use(RouterPlugin);
96
- }
97
- if (target !== "node") {
68
+ if (target !== "node" && target !== "web-worker" && target !== "service-worker") {
98
69
  const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
99
70
  chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
100
71
  chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
101
72
  }
102
- function isHtmlEnabled(config, target2) {
103
- var _a2;
104
- return ((_a2 = config.tools) == null ? void 0 : _a2.htmlPlugin) !== false && target2 !== "node" && target2 !== "web-worker";
105
- }
106
73
  });
107
- if (options) {
108
- applyCallbacks(api, options);
74
+ applyCallbacks(api, options);
75
+ function isHtmlEnabled(config, target) {
76
+ var _a;
77
+ return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
109
78
  }
110
79
  }
111
80
  });
@@ -119,8 +88,53 @@ function applyCallbacks(api, options) {
119
88
  options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
120
89
  options.onExit && api.onExit(options.onExit);
121
90
  }
122
- function applyNodeCompat(chain, modernConfig, isProd) {
123
- for (const ext of [
91
+ function applyBottomHtmlPlugin({
92
+ api,
93
+ chain,
94
+ modernConfig,
95
+ appContext,
96
+ CHAIN_ID
97
+ }) {
98
+ for (const entryName of Object.keys(api.context.entry)) {
99
+ const baseTemplateParams = {
100
+ entryName,
101
+ title: getEntryOptions(
102
+ entryName,
103
+ modernConfig.html.title,
104
+ modernConfig.html.titleByEntries,
105
+ appContext.packageName
106
+ ),
107
+ mountId: modernConfig.html.mountId,
108
+ ...getEntryOptions(
109
+ entryName,
110
+ modernConfig.html.templateParameters,
111
+ modernConfig.html.templateParametersByEntries,
112
+ appContext.packageName
113
+ )
114
+ };
115
+ chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
116
+ {
117
+ ...args[0] || {},
118
+ __internal__: true,
119
+ bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(
120
+ baseTemplateParams
121
+ )
122
+ }
123
+ ]);
124
+ }
125
+ chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
126
+ }
127
+ function applyAsyncChunkHtmlPlugin({
128
+ chain,
129
+ modernConfig,
130
+ CHAIN_ID
131
+ }) {
132
+ if (isStreamingSSR(modernConfig)) {
133
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlWebpackPlugin]);
134
+ }
135
+ }
136
+ function applyNodeCompat(target, chain, modernConfig, isProd) {
137
+ const nodeExts = [
124
138
  ".node.js",
125
139
  ".node.jsx",
126
140
  ".node.ts",
@@ -129,9 +143,21 @@ function applyNodeCompat(chain, modernConfig, isProd) {
129
143
  ".server.ts",
130
144
  ".server.ts",
131
145
  ".server.tsx"
132
- ]) {
146
+ ];
147
+ const webWorkerExts = [
148
+ ".worker.js",
149
+ ".worker.jsx",
150
+ ".worker.ts",
151
+ ".worker.tsx"
152
+ ];
153
+ for (const ext of nodeExts) {
133
154
  chain.resolve.extensions.prepend(ext);
134
155
  }
156
+ if (target === "service-worker") {
157
+ for (const ext of webWorkerExts) {
158
+ chain.resolve.extensions.prepend(ext);
159
+ }
160
+ }
135
161
  filterEntriesBySSRConfig(
136
162
  isProd,
137
163
  chain,
@@ -170,64 +196,7 @@ function applyNodeCompat(chain, modernConfig, isProd) {
170
196
  });
171
197
  }
172
198
  }
173
- function applyBottomHtmlWebpackPlugin({
174
- api,
175
- chain,
176
- modernConfig,
177
- appContext,
178
- CHAIN_ID
179
- }) {
180
- for (const entryName of Object.keys(api.context.entry)) {
181
- const baseTemplateParams = __spreadValues({
182
- entryName,
183
- title: getEntryOptions(
184
- entryName,
185
- modernConfig.html.title,
186
- modernConfig.html.titleByEntries,
187
- appContext.packageName
188
- ),
189
- mountId: modernConfig.html.mountId
190
- }, getEntryOptions(
191
- entryName,
192
- modernConfig.html.templateParameters,
193
- modernConfig.html.templateParametersByEntries,
194
- appContext.packageName
195
- ));
196
- chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
197
- __spreadProps(__spreadValues({}, args[0] || {}), {
198
- __internal__: true,
199
- bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(
200
- baseTemplateParams
201
- )
202
- })
203
- ]);
204
- }
205
- chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
206
- }
207
- const isStreamingSSR = (userConfig) => {
208
- const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
209
- const { server } = userConfig;
210
- if (isStreaming(server.ssr)) {
211
- return true;
212
- }
213
- if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
214
- for (const name of Object.keys(server.ssrByEntries)) {
215
- if (isStreaming(server.ssrByEntries[name])) {
216
- return true;
217
- }
218
- }
219
- }
220
- return false;
221
- };
222
- function applyAsyncChunkHtmlPlugin({
223
- chain,
224
- modernConfig,
225
- CHAIN_ID
226
- }) {
227
- if (isStreamingSSR(modernConfig)) {
228
- chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlWebpackPlugin]);
229
- }
230
- }
231
199
  export {
232
- PluginCompatModern
200
+ applyCallbacks,
201
+ builderPluginAdapterModern
233
202
  };
@@ -0,0 +1,27 @@
1
+ class HtmlAsyncChunkPlugin {
2
+ constructor(htmlWebpackPlugin) {
3
+ this.name = "HtmlAsyncChunkPlugin";
4
+ this.htmlWebpackPlugin = htmlWebpackPlugin;
5
+ }
6
+ apply(compiler) {
7
+ compiler.hooks.compilation.tap(this.name, (compilation) => {
8
+ const hooks = this.htmlWebpackPlugin.getHooks(compilation);
9
+ hooks.alterAssetTagGroups.tap(this.name, (assets) => {
10
+ const tags = [...assets.headTags, ...assets.bodyTags];
11
+ for (const tag of tags) {
12
+ if (tag.tagName === "script") {
13
+ const { attributes } = tag;
14
+ if (attributes && attributes.defer === true) {
15
+ attributes.async = true;
16
+ delete attributes.defer;
17
+ }
18
+ }
19
+ }
20
+ return assets;
21
+ });
22
+ });
23
+ }
24
+ }
25
+ export {
26
+ HtmlAsyncChunkPlugin
27
+ };
@@ -0,0 +1,34 @@
1
+ class BottomTemplatePlugin {
2
+ constructor(htmlWebpackPlugin) {
3
+ this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
4
+ this.bodyRegExp = /(<\/\s*body\s*>)/i;
5
+ this.htmlWebpackPlugin = htmlWebpackPlugin;
6
+ this.name = "bottom-template";
7
+ }
8
+ apply(compiler) {
9
+ compiler.hooks.compilation.tap(this.name, (compilation) => {
10
+ this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
11
+ var _a;
12
+ if (!((_a = data.plugin.options) == null ? void 0 : _a.__internal__)) {
13
+ return data;
14
+ }
15
+ if (this.bottomTemplateReg.test(data.html)) {
16
+ data.html = data.html.replace(this.bottomTemplateReg, "");
17
+ const { bottomTemplate } = data.plugin.options;
18
+ if (bottomTemplate) {
19
+ data.html = data.html.replace(
20
+ this.bodyRegExp,
21
+ (match) => `
22
+ ${bottomTemplate}
23
+ ${match}`
24
+ );
25
+ }
26
+ }
27
+ return data;
28
+ });
29
+ });
30
+ }
31
+ }
32
+ export {
33
+ BottomTemplatePlugin
34
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./createCopyPattern";
2
+ export * from "./types";
3
+ export * from "./builderPlugins/adapterModern";
@@ -0,0 +1,52 @@
1
+ import { ResolvedConfigContext } from "@modern-js/core";
2
+ import { logger, printBuildError } from "@modern-js/utils";
3
+ import { generateRoutes } from "../utils/routes";
4
+ import { buildServerConfig } from "../utils/config";
5
+ const build = async (api, options) => {
6
+ if (options == null ? void 0 : options.analyze) {
7
+ process.env.BUNDLE_ANALYZE = "true";
8
+ }
9
+ let resolvedConfig = api.useResolvedConfigContext();
10
+ const appContext = api.useAppContext();
11
+ const hookRunners = api.useHookRunners();
12
+ const { apiOnly } = appContext;
13
+ if (apiOnly) {
14
+ const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
15
+ await hookRunners.beforeBuild({
16
+ bundlerConfigs: void 0
17
+ });
18
+ await buildServerConfig({
19
+ appDirectory: appDirectory2,
20
+ distDirectory: distDirectory2,
21
+ configFile: serverConfigFile2
22
+ });
23
+ await generateRoutes(appContext);
24
+ await hookRunners.afterBuild({
25
+ stats: void 0
26
+ });
27
+ return;
28
+ }
29
+ resolvedConfig = { ...resolvedConfig, cliOptions: options };
30
+ ResolvedConfigContext.set(resolvedConfig);
31
+ const { distDirectory, appDirectory, serverConfigFile } = appContext;
32
+ await buildServerConfig({
33
+ appDirectory,
34
+ distDirectory,
35
+ configFile: serverConfigFile
36
+ });
37
+ try {
38
+ logger.info("Create a production build...\n");
39
+ if (!appContext.builder) {
40
+ throw new Error(
41
+ "Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
42
+ );
43
+ }
44
+ await appContext.builder.build();
45
+ } catch (error) {
46
+ printBuildError(error);
47
+ process.exit(1);
48
+ }
49
+ };
50
+ export {
51
+ build
52
+ };
@@ -0,0 +1,8 @@
1
+ const deploy = async (api, options) => {
2
+ const hookRunners = api.useHookRunners();
3
+ await hookRunners.beforeDeploy(options);
4
+ await hookRunners.afterDeploy(options);
5
+ };
6
+ export {
7
+ deploy
8
+ };