@modern-js/app-tools 2.58.2 → 2.59.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. package/dist/cjs/builder/builder-rspack/adapterCopy.js +1 -1
  2. package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -1
  3. package/dist/cjs/builder/generator/index.js +2 -3
  4. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +8 -13
  5. package/dist/cjs/builder/shared/builderPlugins/index.js +1 -3
  6. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
  7. package/dist/cjs/commands/build.js +2 -2
  8. package/dist/cjs/commands/dev.js +6 -5
  9. package/dist/cjs/commands/index.js +1 -1
  10. package/dist/cjs/commands/serve.js +4 -3
  11. package/dist/cjs/config/legacy/index.js +3 -3
  12. package/dist/cjs/esm/register-esm.mjs +2 -3
  13. package/dist/cjs/esm/utils.mjs +2 -2
  14. package/dist/cjs/index.js +17 -10
  15. package/dist/cjs/locale/index.js +1 -1
  16. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +50 -44
  17. package/dist/cjs/plugins/analyze/getServerRoutes.js +2 -2
  18. package/dist/cjs/plugins/analyze/index.js +6 -6
  19. package/dist/cjs/plugins/analyze/utils.js +1 -1
  20. package/dist/cjs/plugins/deploy/dependencies/index.js +1 -1
  21. package/dist/cjs/plugins/deploy/dependencies/utils.js +2 -2
  22. package/dist/cjs/plugins/deploy/index.js +2 -2
  23. package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
  24. package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
  25. package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
  26. package/dist/cjs/plugins/serverBuild.js +2 -2
  27. package/dist/cjs/utils/createServer.js +1 -1
  28. package/dist/esm/builder/builder-rspack/adapterCopy.js +166 -0
  29. package/dist/esm/builder/builder-rspack/index.js +34 -0
  30. package/dist/esm/builder/builder-webpack/adapterModern.js +29 -0
  31. package/dist/esm/builder/builder-webpack/createCopyPattern.js +43 -0
  32. package/dist/esm/builder/builder-webpack/index.js +52 -0
  33. package/dist/esm/builder/generator/createBuilderProviderConfig.js +37 -0
  34. package/dist/esm/builder/generator/getBuilderEnvironments.js +81 -0
  35. package/dist/esm/builder/generator/index.js +93 -0
  36. package/dist/esm/builder/index.js +45 -0
  37. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +85 -0
  38. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +126 -0
  39. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +261 -0
  40. package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
  41. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +51 -0
  42. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +37 -0
  43. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +314 -0
  44. package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
  45. package/dist/esm/builder/shared/createCopyInfo.js +14 -0
  46. package/dist/esm/builder/shared/index.js +3 -0
  47. package/dist/esm/builder/shared/loaders/serverModuleLoader.js +7 -0
  48. package/dist/esm/builder/shared/types.js +0 -0
  49. package/dist/esm/commands/build.js +140 -0
  50. package/dist/esm/commands/deploy.js +48 -0
  51. package/dist/esm/commands/dev.js +193 -0
  52. package/dist/esm/commands/index.js +411 -0
  53. package/dist/esm/commands/inspect.js +28 -0
  54. package/dist/esm/commands/serve.js +94 -0
  55. package/dist/esm/config/default.js +190 -0
  56. package/dist/esm/config/index.js +3 -0
  57. package/dist/esm/config/initialize/index.js +9 -0
  58. package/dist/esm/config/initialize/inits.js +89 -0
  59. package/dist/esm/config/legacy/createHtmlConfig.js +21 -0
  60. package/dist/esm/config/legacy/createOutputConfig.js +45 -0
  61. package/dist/esm/config/legacy/createSourceConfig.js +46 -0
  62. package/dist/esm/config/legacy/createToolsConfig.js +28 -0
  63. package/dist/esm/config/legacy/index.js +43 -0
  64. package/dist/esm/defineConfig.js +16 -0
  65. package/dist/esm/esm/esbuild-loader.mjs +20 -0
  66. package/dist/esm/esm/register-esm.mjs +66 -0
  67. package/dist/esm/esm/ts-node-loader.mjs +21 -0
  68. package/dist/esm/esm/utils.mjs +43 -0
  69. package/dist/esm/exports/server.js +4 -0
  70. package/dist/esm/hooks.js +34 -0
  71. package/dist/esm/index.js +246 -0
  72. package/dist/esm/locale/en.js +43 -0
  73. package/dist/esm/locale/index.js +12 -0
  74. package/dist/esm/locale/zh.js +43 -0
  75. package/dist/esm/plugins/analyze/constants.js +14 -0
  76. package/dist/esm/plugins/analyze/getBundleEntry.js +102 -0
  77. package/dist/esm/plugins/analyze/getFileSystemEntry.js +266 -0
  78. package/dist/esm/plugins/analyze/getHtmlTemplate.js +178 -0
  79. package/dist/esm/plugins/analyze/getServerRoutes.js +132 -0
  80. package/dist/esm/plugins/analyze/index.js +380 -0
  81. package/dist/esm/plugins/analyze/isDefaultExportFunction.js +49 -0
  82. package/dist/esm/plugins/analyze/templates.js +6 -0
  83. package/dist/esm/plugins/analyze/utils.js +101 -0
  84. package/dist/esm/plugins/deploy/dependencies/index.js +615 -0
  85. package/dist/esm/plugins/deploy/dependencies/utils.js +421 -0
  86. package/dist/esm/plugins/deploy/exports.js +4 -0
  87. package/dist/esm/plugins/deploy/index.js +135 -0
  88. package/dist/esm/plugins/deploy/platforms/netlify-entry.js +11 -0
  89. package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  90. package/dist/esm/plugins/deploy/platforms/netlify-handler.js +205 -0
  91. package/dist/esm/plugins/deploy/platforms/netlify.js +327 -0
  92. package/dist/esm/plugins/deploy/platforms/node-entry.js +108 -0
  93. package/dist/esm/plugins/deploy/platforms/node.js +161 -0
  94. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  95. package/dist/esm/plugins/deploy/platforms/vercel-entry.js +11 -0
  96. package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  97. package/dist/esm/plugins/deploy/platforms/vercel-handler.js +206 -0
  98. package/dist/esm/plugins/deploy/platforms/vercel.js +261 -0
  99. package/dist/esm/plugins/deploy/utils.js +47 -0
  100. package/dist/esm/plugins/initialize/index.js +119 -0
  101. package/dist/esm/plugins/serverBuild.js +87 -0
  102. package/dist/esm/types/config/deploy.js +0 -0
  103. package/dist/esm/types/config/dev.js +0 -0
  104. package/dist/esm/types/config/experiments.js +0 -0
  105. package/dist/esm/types/config/html.js +0 -0
  106. package/dist/esm/types/config/index.js +1 -0
  107. package/dist/esm/types/config/output.js +0 -0
  108. package/dist/esm/types/config/performance.js +0 -0
  109. package/dist/esm/types/config/security.js +0 -0
  110. package/dist/esm/types/config/source.js +0 -0
  111. package/dist/esm/types/config/testing.js +0 -0
  112. package/dist/esm/types/config/tools.js +0 -0
  113. package/dist/esm/types/hooks.js +0 -0
  114. package/dist/esm/types/index.js +3 -0
  115. package/dist/esm/types/legacyConfig/deploy.js +0 -0
  116. package/dist/esm/types/legacyConfig/dev.js +0 -0
  117. package/dist/esm/types/legacyConfig/index.js +0 -0
  118. package/dist/esm/types/legacyConfig/output.js +0 -0
  119. package/dist/esm/types/legacyConfig/source.js +0 -0
  120. package/dist/esm/types/legacyConfig/testing.js +0 -0
  121. package/dist/esm/types/legacyConfig/tools.js +0 -0
  122. package/dist/esm/types/utils.js +0 -0
  123. package/dist/esm/utils/config.js +122 -0
  124. package/dist/esm/utils/createServer.js +58 -0
  125. package/dist/esm/utils/env.js +16 -0
  126. package/dist/esm/utils/generateWatchFiles.js +71 -0
  127. package/dist/esm/utils/getSelectedEntries.js +67 -0
  128. package/dist/esm/utils/loadPlugins.js +74 -0
  129. package/dist/esm/utils/printInstructions.js +32 -0
  130. package/dist/esm/utils/register.js +188 -0
  131. package/dist/esm/utils/restart.js +67 -0
  132. package/dist/esm/utils/routes.js +42 -0
  133. package/dist/esm/utils/types.js +0 -0
  134. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +67 -0
  135. package/dist/esm-node/builder/builder-rspack/index.js +12 -0
  136. package/dist/esm-node/builder/builder-webpack/adapterModern.js +26 -0
  137. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +41 -0
  138. package/dist/esm-node/builder/builder-webpack/index.js +20 -0
  139. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +44 -0
  140. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
  141. package/dist/esm-node/builder/generator/index.js +36 -0
  142. package/dist/esm-node/builder/index.js +11 -0
  143. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +48 -0
  144. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +60 -0
  145. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +151 -0
  146. package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
  147. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -0
  148. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +31 -0
  149. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +228 -0
  150. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
  151. package/dist/esm-node/builder/shared/createCopyInfo.js +14 -0
  152. package/dist/esm-node/builder/shared/index.js +3 -0
  153. package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -0
  154. package/dist/esm-node/builder/shared/types.js +0 -0
  155. package/dist/esm-node/commands/build.js +64 -0
  156. package/dist/esm-node/commands/deploy.js +12 -0
  157. package/dist/esm-node/commands/dev.js +105 -0
  158. package/dist/esm-node/commands/index.js +92 -0
  159. package/dist/esm-node/commands/inspect.js +15 -0
  160. package/dist/esm-node/commands/serve.js +52 -0
  161. package/dist/esm-node/config/default.js +197 -0
  162. package/dist/esm-node/config/index.js +3 -0
  163. package/dist/esm-node/config/initialize/index.js +9 -0
  164. package/dist/esm-node/config/initialize/inits.js +79 -0
  165. package/dist/esm-node/config/legacy/createHtmlConfig.js +21 -0
  166. package/dist/esm-node/config/legacy/createOutputConfig.js +45 -0
  167. package/dist/esm-node/config/legacy/createSourceConfig.js +29 -0
  168. package/dist/esm-node/config/legacy/createToolsConfig.js +28 -0
  169. package/dist/esm-node/config/legacy/index.js +43 -0
  170. package/dist/esm-node/defineConfig.js +13 -0
  171. package/dist/esm-node/esm/esbuild-loader.mjs +20 -0
  172. package/dist/esm-node/esm/register-esm.mjs +66 -0
  173. package/dist/esm-node/esm/ts-node-loader.mjs +21 -0
  174. package/dist/esm-node/esm/utils.mjs +43 -0
  175. package/dist/esm-node/exports/server.js +4 -0
  176. package/dist/esm-node/hooks.js +34 -0
  177. package/dist/esm-node/index.js +131 -0
  178. package/dist/esm-node/locale/en.js +43 -0
  179. package/dist/esm-node/locale/index.js +12 -0
  180. package/dist/esm-node/locale/zh.js +43 -0
  181. package/dist/esm-node/plugins/analyze/constants.js +14 -0
  182. package/dist/esm-node/plugins/analyze/getBundleEntry.js +61 -0
  183. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +106 -0
  184. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +74 -0
  185. package/dist/esm-node/plugins/analyze/getServerRoutes.js +132 -0
  186. package/dist/esm-node/plugins/analyze/index.js +166 -0
  187. package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +47 -0
  188. package/dist/esm-node/plugins/analyze/templates.js +24 -0
  189. package/dist/esm-node/plugins/analyze/utils.js +68 -0
  190. package/dist/esm-node/plugins/deploy/dependencies/index.js +202 -0
  191. package/dist/esm-node/plugins/deploy/dependencies/utils.js +137 -0
  192. package/dist/esm-node/plugins/deploy/exports.js +4 -0
  193. package/dist/esm-node/plugins/deploy/index.js +44 -0
  194. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +11 -0
  195. package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  196. package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +71 -0
  197. package/dist/esm-node/plugins/deploy/platforms/netlify.js +117 -0
  198. package/dist/esm-node/plugins/deploy/platforms/node-entry.js +44 -0
  199. package/dist/esm-node/plugins/deploy/platforms/node.js +72 -0
  200. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  201. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.js +11 -0
  202. package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  203. package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +72 -0
  204. package/dist/esm-node/plugins/deploy/platforms/vercel.js +129 -0
  205. package/dist/esm-node/plugins/deploy/utils.js +44 -0
  206. package/dist/esm-node/plugins/initialize/index.js +84 -0
  207. package/dist/esm-node/plugins/serverBuild.js +58 -0
  208. package/dist/esm-node/types/config/deploy.js +0 -0
  209. package/dist/esm-node/types/config/dev.js +0 -0
  210. package/dist/esm-node/types/config/experiments.js +0 -0
  211. package/dist/esm-node/types/config/html.js +0 -0
  212. package/dist/esm-node/types/config/index.js +1 -0
  213. package/dist/esm-node/types/config/output.js +0 -0
  214. package/dist/esm-node/types/config/performance.js +0 -0
  215. package/dist/esm-node/types/config/security.js +0 -0
  216. package/dist/esm-node/types/config/source.js +0 -0
  217. package/dist/esm-node/types/config/testing.js +0 -0
  218. package/dist/esm-node/types/config/tools.js +0 -0
  219. package/dist/esm-node/types/hooks.js +0 -0
  220. package/dist/esm-node/types/index.js +3 -0
  221. package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
  222. package/dist/esm-node/types/legacyConfig/dev.js +0 -0
  223. package/dist/esm-node/types/legacyConfig/index.js +0 -0
  224. package/dist/esm-node/types/legacyConfig/output.js +0 -0
  225. package/dist/esm-node/types/legacyConfig/source.js +0 -0
  226. package/dist/esm-node/types/legacyConfig/testing.js +0 -0
  227. package/dist/esm-node/types/legacyConfig/tools.js +0 -0
  228. package/dist/esm-node/types/utils.js +0 -0
  229. package/dist/esm-node/utils/config.js +49 -0
  230. package/dist/esm-node/utils/createServer.js +26 -0
  231. package/dist/esm-node/utils/env.js +16 -0
  232. package/dist/esm-node/utils/generateWatchFiles.js +30 -0
  233. package/dist/esm-node/utils/getSelectedEntries.js +34 -0
  234. package/dist/esm-node/utils/loadPlugins.js +22 -0
  235. package/dist/esm-node/utils/printInstructions.js +11 -0
  236. package/dist/esm-node/utils/register.js +96 -0
  237. package/dist/esm-node/utils/restart.js +22 -0
  238. package/dist/esm-node/utils/routes.js +21 -0
  239. package/dist/esm-node/utils/types.js +0 -0
  240. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
  241. package/dist/types/builder/generator/index.d.ts +2 -2
  242. package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
  243. package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +1 -1
  244. package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +1 -1
  245. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
  246. package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
  247. package/dist/types/builder/shared/types.d.ts +1 -1
  248. package/dist/types/commands/build.d.ts +1 -1
  249. package/dist/types/commands/dev.d.ts +1 -1
  250. package/dist/types/commands/inspect.d.ts +1 -1
  251. package/dist/types/config/default.d.ts +1 -1
  252. package/dist/types/index.d.ts +1 -1
  253. package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
  254. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
  255. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -1
  256. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -1
  257. package/dist/types/plugins/initialize/index.d.ts +1 -1
  258. package/dist/types/plugins/serverBuild.d.ts +1 -1
  259. package/dist/types/types/config/index.d.ts +8 -8
  260. package/dist/types/types/config/output.d.ts +1 -1
  261. package/dist/types/types/config/tools.d.ts +3 -3
  262. package/dist/types/types/hooks.d.ts +2 -2
  263. package/dist/types/types/index.d.ts +2 -2
  264. package/dist/types/types/legacyConfig/index.d.ts +3 -3
  265. package/dist/types/types/legacyConfig/tools.d.ts +1 -1
  266. package/dist/types/utils/printInstructions.d.ts +1 -1
  267. package/package.json +20 -20
  268. package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +0 -51
  269. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +0 -2
@@ -0,0 +1,126 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
+ import { isHtmlDisabled } from "@modern-js/uni-builder";
6
+ import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
7
+ import { template as lodashTemplate } from "@modern-js/utils/lodash";
8
+ import { BottomTemplatePlugin } from "../bundlerPlugins";
9
+ var createVirtualModule = function(content) {
10
+ return "data:text/javascript,".concat(content);
11
+ };
12
+ var builderPluginAdapterHtml = function(options) {
13
+ return {
14
+ name: "builder-plugin-adapter-modern-html",
15
+ setup: function setup(api) {
16
+ api.modifyBundlerChain(function() {
17
+ var _ref = _async_to_generator(function(chain, param) {
18
+ var CHAIN_ID, target, HtmlBundlerPlugin, environment, builderConfig;
19
+ return _ts_generator(this, function(_state) {
20
+ switch (_state.label) {
21
+ case 0:
22
+ CHAIN_ID = param.CHAIN_ID, target = param.target, HtmlBundlerPlugin = param.HtmlPlugin, environment = param.environment;
23
+ builderConfig = environment.config;
24
+ if (!!isHtmlDisabled(builderConfig, target))
25
+ return [
26
+ 3,
27
+ 2
28
+ ];
29
+ applyBottomHtmlPlugin({
30
+ options,
31
+ chain,
32
+ CHAIN_ID,
33
+ HtmlBundlerPlugin,
34
+ htmlPaths: environment.htmlPaths
35
+ });
36
+ return [
37
+ 4,
38
+ injectAssetPrefix({
39
+ chain
40
+ })
41
+ ];
42
+ case 1:
43
+ _state.sent();
44
+ _state.label = 2;
45
+ case 2:
46
+ return [
47
+ 2
48
+ ];
49
+ }
50
+ });
51
+ });
52
+ return function(chain, _) {
53
+ return _ref.apply(this, arguments);
54
+ };
55
+ }());
56
+ }
57
+ };
58
+ };
59
+ function injectAssetPrefix(_) {
60
+ return _injectAssetPrefix.apply(this, arguments);
61
+ }
62
+ function _injectAssetPrefix() {
63
+ _injectAssetPrefix = _async_to_generator(function(param) {
64
+ var chain, entries, entryNames, assetPrefix, code;
65
+ return _ts_generator(this, function(_state) {
66
+ chain = param.chain;
67
+ entries = chain.entryPoints.entries() || {};
68
+ entryNames = Object.keys(entries);
69
+ assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
70
+ code = "window.__assetPrefix__ = '".concat(assetPrefix, "';");
71
+ entryNames.forEach(function(entryName) {
72
+ entries[entryName].prepend(createVirtualModule(code));
73
+ });
74
+ return [
75
+ 2
76
+ ];
77
+ });
78
+ });
79
+ return _injectAssetPrefix.apply(this, arguments);
80
+ }
81
+ function applyBottomHtmlPlugin(param) {
82
+ var chain = param.chain, options = param.options, CHAIN_ID = param.CHAIN_ID, HtmlBundlerPlugin = param.HtmlBundlerPlugin, htmlPaths = param.htmlPaths;
83
+ var modernConfig = options.normalizedConfig, appContext = options.appContext;
84
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
85
+ try {
86
+ var _loop = function() {
87
+ var entryName = _step.value;
88
+ var mainEntryName = modernConfig.source.mainEntryName;
89
+ var isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
90
+ var baseTemplateParams = _object_spread({
91
+ entryName,
92
+ title: getEntryOptions(entryName, isMainEntry, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
93
+ mountId: modernConfig.html.mountId
94
+ }, getEntryOptions(entryName, isMainEntry, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
95
+ chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function(args) {
96
+ return [
97
+ _object_spread_props(_object_spread({}, args[0] || {}), {
98
+ __internal__: true,
99
+ bottomTemplate: appContext.htmlTemplates["__".concat(entryName, "-bottom__")] && lodashTemplate(appContext.htmlTemplates["__".concat(entryName, "-bottom__")])(baseTemplateParams)
100
+ })
101
+ ];
102
+ });
103
+ };
104
+ for (var _iterator = Object.keys(htmlPaths)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
105
+ _loop();
106
+ } catch (err) {
107
+ _didIteratorError = true;
108
+ _iteratorError = err;
109
+ } finally {
110
+ try {
111
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
112
+ _iterator.return();
113
+ }
114
+ } finally {
115
+ if (_didIteratorError) {
116
+ throw _iteratorError;
117
+ }
118
+ }
119
+ }
120
+ chain.plugin("bottom-template").use(BottomTemplatePlugin, [
121
+ HtmlBundlerPlugin
122
+ ]);
123
+ }
124
+ export {
125
+ builderPluginAdapterHtml
126
+ };
@@ -0,0 +1,261 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import * as path from "path";
4
+ import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/uni-builder";
5
+ import { fs, isUseSSRBundle } from "@modern-js/utils";
6
+ import { mergeRsbuildConfig } from "@rsbuild/core";
7
+ import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
8
+ import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
9
+ var builderPluginAdapterSSR = function(options) {
10
+ return {
11
+ name: "builder-plugin-adapter-modern-ssr",
12
+ setup: function setup(api) {
13
+ var normalizedConfig = options.normalizedConfig;
14
+ api.modifyRsbuildConfig(function(config) {
15
+ return mergeRsbuildConfig(config, {
16
+ html: {
17
+ inject: isStreamingSSR(normalizedConfig) ? "body" : void 0
18
+ },
19
+ server: {
20
+ // the http-compression can't handler stream http.
21
+ // so we disable compress when user use stream ssr temporarily.
22
+ compress: isStreamingSSR(normalizedConfig) ? false : void 0
23
+ }
24
+ });
25
+ });
26
+ api.modifyBundlerChain(function() {
27
+ var _ref = _async_to_generator(function(chain, param) {
28
+ var target, isProd, HtmlBundlerPlugin, isServer, environment, builderConfig, normalizedConfig2, isServiceWorker;
29
+ return _ts_generator(this, function(_state) {
30
+ switch (_state.label) {
31
+ case 0:
32
+ target = param.target, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer, environment = param.environment;
33
+ builderConfig = environment.config;
34
+ normalizedConfig2 = options.normalizedConfig;
35
+ applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
36
+ isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
37
+ if (target === "node" || isServiceWorker) {
38
+ applyFilterEntriesBySSRConfig({
39
+ isProd,
40
+ chain,
41
+ appNormalizedConfig: normalizedConfig2
42
+ });
43
+ }
44
+ if (!isUseSSRBundle(normalizedConfig2))
45
+ return [
46
+ 3,
47
+ 2
48
+ ];
49
+ return [
50
+ 4,
51
+ applySSRLoaderEntry(chain, options, isServer)
52
+ ];
53
+ case 1:
54
+ _state.sent();
55
+ applySSRDataLoader(chain, options);
56
+ _state.label = 2;
57
+ case 2:
58
+ if (!isHtmlDisabled(builderConfig, target)) {
59
+ applyAsyncChunkHtmlPlugin({
60
+ chain,
61
+ modernConfig: options.normalizedConfig,
62
+ HtmlBundlerPlugin
63
+ });
64
+ }
65
+ return [
66
+ 2
67
+ ];
68
+ }
69
+ });
70
+ });
71
+ return function(chain, _) {
72
+ return _ref.apply(this, arguments);
73
+ };
74
+ }());
75
+ }
76
+ };
77
+ };
78
+ var isStreamingSSR = function(userConfig) {
79
+ var isStreaming = function(ssr) {
80
+ return ssr && typeof ssr === "object" && ssr.mode === "stream";
81
+ };
82
+ var server = userConfig.server;
83
+ if (isStreaming(server.ssr)) {
84
+ return true;
85
+ }
86
+ if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
87
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
88
+ try {
89
+ for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
90
+ var name = _step.value;
91
+ if (isStreaming(server.ssrByEntries[name])) {
92
+ return true;
93
+ }
94
+ }
95
+ } catch (err) {
96
+ _didIteratorError = true;
97
+ _iteratorError = err;
98
+ } finally {
99
+ try {
100
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
101
+ _iterator.return();
102
+ }
103
+ } finally {
104
+ if (_didIteratorError) {
105
+ throw _iteratorError;
106
+ }
107
+ }
108
+ }
109
+ }
110
+ return false;
111
+ };
112
+ function applyAsyncChunkHtmlPlugin(param) {
113
+ var chain = param.chain, modernConfig = param.modernConfig, HtmlBundlerPlugin = param.HtmlBundlerPlugin;
114
+ if (isStreamingSSR(modernConfig)) {
115
+ chain.plugin("html-async-chunk").use(HtmlAsyncChunkPlugin, [
116
+ HtmlBundlerPlugin
117
+ ]);
118
+ }
119
+ }
120
+ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
121
+ var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
122
+ var appContext = options.appContext, normalizedConfig = options.normalizedConfig;
123
+ var entrypoints = appContext.entrypoints;
124
+ var existNestedRoutes = entrypoints.some(function(entrypoint) {
125
+ return entrypoint.nestedRoutesEntry;
126
+ });
127
+ var routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
128
+ var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
129
+ var workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
130
+ var _normalizedConfig_output = normalizedConfig.output, enableInlineRouteManifests = _normalizedConfig_output.enableInlineRouteManifests, disableInlineRouteManifests = _normalizedConfig_output.disableInlineRouteManifests;
131
+ var inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
132
+ if (existNestedRoutes || routerManifest || workerSSR) {
133
+ var _normalizedConfig_output_distPath, _normalizedConfig_output1, _normalizedConfig_output2, _normalizedConfig_html, _normalizedConfig_security;
134
+ chain.plugin(pluginName).use(RouterPlugin, [
135
+ {
136
+ HtmlBundlerPlugin,
137
+ enableInlineRouteManifests: inlineRouteManifests,
138
+ staticJsDir: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output1.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
139
+ disableFilenameHash: (_normalizedConfig_output2 = normalizedConfig.output) === null || _normalizedConfig_output2 === void 0 ? void 0 : _normalizedConfig_output2.disableFilenameHash,
140
+ scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
141
+ nonce: (_normalizedConfig_security = normalizedConfig.security) === null || _normalizedConfig_security === void 0 ? void 0 : _normalizedConfig_security.nonce
142
+ }
143
+ ]);
144
+ }
145
+ }
146
+ function applyFilterEntriesBySSRConfig(param) {
147
+ var isProd = param.isProd, chain = param.chain, appNormalizedConfig = param.appNormalizedConfig;
148
+ var _this;
149
+ var serverConfig = appNormalizedConfig.server, outputConfig = appNormalizedConfig.output;
150
+ var entries = chain.entryPoints.entries();
151
+ if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof ((_this = outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
152
+ return;
153
+ }
154
+ if (typeof entries === "undefined") {
155
+ throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
156
+ }
157
+ var entryNames = Object.keys(entries);
158
+ if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
159
+ return;
160
+ }
161
+ var ssgEntries = [];
162
+ if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
163
+ var ssg = outputConfig.ssg;
164
+ entryNames.forEach(function(name) {
165
+ if (ssg[name]) {
166
+ ssgEntries.push(name);
167
+ }
168
+ });
169
+ }
170
+ var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
171
+ entryNames.forEach(function(name) {
172
+ if (!ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
173
+ chain.entryPoints.delete(name);
174
+ }
175
+ });
176
+ }
177
+ function applySSRLoaderEntry(chain, optinos, isServer) {
178
+ return _applySSRLoaderEntry.apply(this, arguments);
179
+ }
180
+ function _applySSRLoaderEntry() {
181
+ _applySSRLoaderEntry = _async_to_generator(function(chain, optinos, isServer) {
182
+ var appContext, internalDirectory, entrypoints;
183
+ return _ts_generator(this, function(_state) {
184
+ switch (_state.label) {
185
+ case 0:
186
+ appContext = optinos.appContext;
187
+ internalDirectory = appContext.internalDirectory;
188
+ entrypoints = appContext.entrypoints;
189
+ return [
190
+ 4,
191
+ Promise.all(entrypoints.map(function() {
192
+ var _ref = _async_to_generator(function(entrypoint) {
193
+ var entryName, serverLoadersFile, err;
194
+ return _ts_generator(this, function(_state2) {
195
+ switch (_state2.label) {
196
+ case 0:
197
+ entryName = entrypoint.entryName;
198
+ serverLoadersFile = getServerCombinedModueFile(internalDirectory, entryName);
199
+ if (!isServer)
200
+ return [
201
+ 3,
202
+ 4
203
+ ];
204
+ _state2.label = 1;
205
+ case 1:
206
+ _state2.trys.push([
207
+ 1,
208
+ 3,
209
+ ,
210
+ 4
211
+ ]);
212
+ return [
213
+ 4,
214
+ fs.access(serverLoadersFile, fs.constants.F_OK)
215
+ ];
216
+ case 2:
217
+ _state2.sent();
218
+ chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
219
+ return [
220
+ 3,
221
+ 4
222
+ ];
223
+ case 3:
224
+ err = _state2.sent();
225
+ return [
226
+ 3,
227
+ 4
228
+ ];
229
+ case 4:
230
+ return [
231
+ 2
232
+ ];
233
+ }
234
+ });
235
+ });
236
+ return function(entrypoint) {
237
+ return _ref.apply(this, arguments);
238
+ };
239
+ }()))
240
+ ];
241
+ case 1:
242
+ _state.sent();
243
+ return [
244
+ 2
245
+ ];
246
+ }
247
+ });
248
+ });
249
+ return _applySSRLoaderEntry.apply(this, arguments);
250
+ }
251
+ function applySSRDataLoader(chain, options) {
252
+ var normalizedConfig = options.normalizedConfig, appContext = options.appContext;
253
+ var appDirectory = appContext.appDirectory;
254
+ var _normalizedConfig_source = normalizedConfig.source, _normalizedConfig_source_entriesDir = _normalizedConfig_source.entriesDir, entriesDir = _normalizedConfig_source_entriesDir === void 0 ? "./src" : _normalizedConfig_source_entriesDir;
255
+ var absolutePath = path.resolve(appDirectory, entriesDir).split(path.sep).join("(\\\\|/)");
256
+ var reg = new RegExp("".concat(absolutePath, ".*\\.(loader|data|data.client)\\.[t|j]sx?$"));
257
+ chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
258
+ }
259
+ export {
260
+ builderPluginAdapterSSR
261
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./adapterBasic";
2
+ export * from "./adapterHtml";
3
+ export * from "./adapterSSR";
@@ -0,0 +1,51 @@
1
+ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
+ var HtmlAsyncChunkPlugin = /* @__PURE__ */ function() {
4
+ "use strict";
5
+ function HtmlAsyncChunkPlugin2(htmlWebpackPlugin) {
6
+ _class_call_check(this, HtmlAsyncChunkPlugin2);
7
+ this.name = "HtmlAsyncChunkPlugin";
8
+ this.htmlWebpackPlugin = htmlWebpackPlugin;
9
+ }
10
+ var _proto = HtmlAsyncChunkPlugin2.prototype;
11
+ _proto.apply = function apply(compiler) {
12
+ var _this = this;
13
+ compiler.hooks.compilation.tap(this.name, function(compilation) {
14
+ var hooks = _this.htmlWebpackPlugin.getHooks(compilation);
15
+ hooks.alterAssetTagGroups.tap(_this.name, function(assets) {
16
+ var tags = _to_consumable_array(assets.headTags).concat(_to_consumable_array(assets.bodyTags));
17
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
18
+ try {
19
+ for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
20
+ var tag = _step.value;
21
+ if (tag.tagName === "script") {
22
+ var attributes = tag.attributes;
23
+ if (attributes && attributes.defer === true) {
24
+ attributes.async = true;
25
+ delete attributes.defer;
26
+ }
27
+ }
28
+ }
29
+ } catch (err) {
30
+ _didIteratorError = true;
31
+ _iteratorError = err;
32
+ } finally {
33
+ try {
34
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
35
+ _iterator.return();
36
+ }
37
+ } finally {
38
+ if (_didIteratorError) {
39
+ throw _iteratorError;
40
+ }
41
+ }
42
+ }
43
+ return assets;
44
+ });
45
+ });
46
+ };
47
+ return HtmlAsyncChunkPlugin2;
48
+ }();
49
+ export {
50
+ HtmlAsyncChunkPlugin
51
+ };
@@ -0,0 +1,37 @@
1
+ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
+ var BottomTemplatePlugin = /* @__PURE__ */ function() {
3
+ "use strict";
4
+ function BottomTemplatePlugin2(htmlWebpackPlugin) {
5
+ _class_call_check(this, BottomTemplatePlugin2);
6
+ this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
7
+ this.bodyRegExp = /(<\/\s*body\s*>)/i;
8
+ this.htmlWebpackPlugin = htmlWebpackPlugin;
9
+ this.name = "bottom-template";
10
+ }
11
+ var _proto = BottomTemplatePlugin2.prototype;
12
+ _proto.apply = function apply(compiler) {
13
+ var _this = this;
14
+ compiler.hooks.compilation.tap(this.name, function(compilation) {
15
+ _this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function(data) {
16
+ var _data_plugin_options;
17
+ if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
18
+ return data;
19
+ }
20
+ if (_this.bottomTemplateReg.test(data.html)) {
21
+ data.html = data.html.replace(_this.bottomTemplateReg, "");
22
+ var bottomTemplate = data.plugin.options.bottomTemplate;
23
+ if (bottomTemplate) {
24
+ data.html = data.html.replace(_this.bodyRegExp, function(match) {
25
+ return "\n".concat(bottomTemplate, "\n").concat(match);
26
+ });
27
+ }
28
+ }
29
+ return data;
30
+ });
31
+ });
32
+ };
33
+ return BottomTemplatePlugin2;
34
+ }();
35
+ export {
36
+ BottomTemplatePlugin
37
+ };