@modern-js/app-tools 3.9.2 → 3.10.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 (311) hide show
  1. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +54 -2
  2. package/dist/cjs/commands/build.js +1 -2
  3. package/dist/cjs/commands/deploy.js +1 -3
  4. package/dist/cjs/commands/index.js +4 -0
  5. package/dist/cjs/compat/hooks.js +0 -5
  6. package/dist/cjs/compat/index.js +0 -5
  7. package/dist/cjs/compat/utils.js +0 -5
  8. package/dist/cjs/index.js +15 -39
  9. package/dist/cjs/plugins/analyze/index.js +2 -2
  10. package/dist/cjs/plugins/analyze/utils.js +2 -3
  11. package/dist/cjs/plugins/initialize/index.js +3 -5
  12. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +54 -2
  13. package/dist/esm/commands/build.mjs +1 -2
  14. package/dist/esm/commands/deploy.mjs +1 -3
  15. package/dist/esm/commands/index.mjs +4 -0
  16. package/dist/esm/compat/hooks.mjs +0 -5
  17. package/dist/esm/compat/index.mjs +0 -5
  18. package/dist/esm/compat/utils.mjs +0 -5
  19. package/dist/esm/index.mjs +2 -10
  20. package/dist/esm/plugins/analyze/index.mjs +2 -2
  21. package/dist/esm/plugins/analyze/utils.mjs +2 -3
  22. package/dist/esm/plugins/initialize/index.mjs +3 -5
  23. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +54 -2
  24. package/dist/esm-node/commands/build.mjs +1 -2
  25. package/dist/esm-node/commands/deploy.mjs +1 -3
  26. package/dist/esm-node/commands/index.mjs +4 -0
  27. package/dist/esm-node/compat/hooks.mjs +0 -5
  28. package/dist/esm-node/compat/index.mjs +0 -5
  29. package/dist/esm-node/compat/utils.mjs +0 -5
  30. package/dist/esm-node/index.mjs +2 -10
  31. package/dist/esm-node/plugins/analyze/index.mjs +2 -2
  32. package/dist/esm-node/plugins/analyze/utils.mjs +2 -3
  33. package/dist/esm-node/plugins/initialize/index.mjs +3 -5
  34. package/dist/types/index.d.ts +1 -3
  35. package/dist/types/plugins/analyze/utils.d.ts +1 -1
  36. package/dist/types/types/config/index.d.ts +0 -2
  37. package/dist/types/types/config/tools.d.ts +0 -8
  38. package/docs/apis/app/commands.md +2 -0
  39. package/docs/apis/app/hooks/api/lambda.md +2 -0
  40. package/docs/apis/app/hooks/config/favicon.md +2 -0
  41. package/docs/apis/app/hooks/config/html.md +2 -0
  42. package/docs/apis/app/hooks/config/icon.md +2 -0
  43. package/docs/apis/app/hooks/config/mock.md +2 -0
  44. package/docs/apis/app/hooks/config/public.md +2 -0
  45. package/docs/apis/app/hooks/config/upload.md +3 -3
  46. package/docs/apis/app/hooks/modern-config.md +2 -0
  47. package/docs/apis/app/hooks/server/server.md +2 -0
  48. package/docs/apis/app/hooks/shared.md +2 -0
  49. package/docs/apis/app/hooks/src/app.md +2 -0
  50. package/docs/apis/app/hooks/src/entry.md +2 -0
  51. package/docs/apis/app/hooks/src/entry.server.md +2 -0
  52. package/docs/apis/app/hooks/src/modern.runtime.md +2 -0
  53. package/docs/apis/app/hooks/src/routes.md +2 -0
  54. package/docs/apis/app/hooks/src/server.md +2 -0
  55. package/docs/apis/app/runtime/bff/use-hono-context.md +2 -0
  56. package/docs/apis/app/runtime/core/create-root.md +5 -1
  57. package/docs/apis/app/runtime/core/render.md +7 -2
  58. package/docs/apis/app/runtime/core/runtime-context.md +18 -16
  59. package/docs/apis/app/runtime/router/router.md +11 -6
  60. package/docs/apis/app/runtime/ssr/no-ssr.md +2 -0
  61. package/docs/apis/app/runtime/ssr/renderStreaming.md +2 -0
  62. package/docs/apis/app/runtime/ssr/renderString.md +2 -0
  63. package/docs/apis/app/runtime/ssr/requestHandler.md +2 -0
  64. package/docs/apis/app/runtime/utility/css-in-js.md +2 -0
  65. package/docs/apis/app/runtime/utility/head.md +2 -0
  66. package/docs/apis/app/runtime/utility/loadable.md +2 -0
  67. package/docs/community/blog/2022-0708-updates.md +2 -0
  68. package/docs/community/blog/2022-0910-updates.md +2 -0
  69. package/docs/community/blog/overview.md +2 -0
  70. package/docs/community/blog/v2-release-note.md +2 -0
  71. package/docs/community/blog/v3-release-note.md +18 -13
  72. package/docs/community/contributing-guide.md +17 -33
  73. package/docs/community/releases.md +2 -0
  74. package/docs/community/showcase.md +2 -0
  75. package/docs/community/team.md +2 -0
  76. package/docs/configure/app/bff/cross-project.md +2 -0
  77. package/docs/configure/app/bff/prefix.md +2 -0
  78. package/docs/configure/app/builder-plugins.md +2 -0
  79. package/docs/configure/app/dev/asset-prefix.md +2 -0
  80. package/docs/configure/app/dev/before-start-url.md +2 -0
  81. package/docs/configure/app/dev/client.md +2 -0
  82. package/docs/configure/app/dev/hmr.md +2 -0
  83. package/docs/configure/app/dev/host.md +2 -0
  84. package/docs/configure/app/dev/https.md +2 -0
  85. package/docs/configure/app/dev/lazy-compilation.md +19 -1
  86. package/docs/configure/app/dev/live-reload.md +2 -0
  87. package/docs/configure/app/dev/mock-dir.md +2 -0
  88. package/docs/configure/app/dev/progress-bar.md +2 -0
  89. package/docs/configure/app/dev/server.md +2 -0
  90. package/docs/configure/app/dev/setup-middlewares.md +2 -0
  91. package/docs/configure/app/dev/start-url.md +2 -0
  92. package/docs/configure/app/dev/watch-files.md +2 -0
  93. package/docs/configure/app/dev/write-to-disk.md +2 -0
  94. package/docs/configure/app/experiments/source-build.md +2 -0
  95. package/docs/configure/app/html/app-icon.md +2 -0
  96. package/docs/configure/app/html/crossorigin.md +2 -0
  97. package/docs/configure/app/html/favicon.md +2 -0
  98. package/docs/configure/app/html/inject.md +2 -0
  99. package/docs/configure/app/html/meta.md +2 -0
  100. package/docs/configure/app/html/mount-id.md +2 -0
  101. package/docs/configure/app/html/output-structure.md +2 -0
  102. package/docs/configure/app/html/script-loading.md +2 -0
  103. package/docs/configure/app/html/tags.md +2 -0
  104. package/docs/configure/app/html/template-parameters.md +2 -0
  105. package/docs/configure/app/html/template.md +2 -0
  106. package/docs/configure/app/html/title.md +2 -0
  107. package/docs/configure/app/output/asset-prefix.md +2 -0
  108. package/docs/configure/app/output/assets-retry.md +2 -0
  109. package/docs/configure/app/output/charset.md +2 -0
  110. package/docs/configure/app/output/clean-dist-path.md +2 -0
  111. package/docs/configure/app/output/convert-to-rem.md +2 -0
  112. package/docs/configure/app/output/copy.md +2 -0
  113. package/docs/configure/app/output/css-modules.md +3 -5
  114. package/docs/configure/app/output/data-uri-limit.md +2 -0
  115. package/docs/configure/app/output/disable-css-module-extension.md +2 -0
  116. package/docs/configure/app/output/disable-inline-runtime-chunk.md +2 -0
  117. package/docs/configure/app/output/disable-svgr.md +6 -0
  118. package/docs/configure/app/output/disable-ts-checker.md +2 -0
  119. package/docs/configure/app/output/dist-path.md +2 -0
  120. package/docs/configure/app/output/enable-asset-manifest.md +2 -0
  121. package/docs/configure/app/output/enable-css-module-tsdeclaration.md +2 -0
  122. package/docs/configure/app/output/enable-inline-route-manifests.md +2 -0
  123. package/docs/configure/app/output/externals.md +2 -0
  124. package/docs/configure/app/output/filename-hash.md +2 -0
  125. package/docs/configure/app/output/filename.md +2 -0
  126. package/docs/configure/app/output/inject-styles.md +2 -0
  127. package/docs/configure/app/output/inline-scripts.md +3 -2
  128. package/docs/configure/app/output/inline-styles.md +3 -2
  129. package/docs/configure/app/output/legal-comments.md +2 -0
  130. package/docs/configure/app/output/minify.md +2 -0
  131. package/docs/configure/app/output/override-browserslist.md +2 -0
  132. package/docs/configure/app/output/polyfill.md +2 -0
  133. package/docs/configure/app/output/source-map.md +2 -0
  134. package/docs/configure/app/output/split-route-chunks.md +3 -1
  135. package/docs/configure/app/output/ssg.md +2 -0
  136. package/docs/configure/app/output/ssgByEntries.md +2 -0
  137. package/docs/configure/app/output/svg-default-export.md +6 -0
  138. package/docs/configure/app/output/temp-dir.md +2 -0
  139. package/docs/configure/app/performance/build-cache.md +2 -0
  140. package/docs/configure/app/performance/chunk-split.md +3 -4
  141. package/docs/configure/app/performance/dns-prefetch.md +2 -0
  142. package/docs/configure/app/performance/preconnect.md +2 -0
  143. package/docs/configure/app/performance/prefetch.md +2 -0
  144. package/docs/configure/app/performance/preload.md +2 -0
  145. package/docs/configure/app/performance/print-file-size.md +2 -0
  146. package/docs/configure/app/performance/profile.md +2 -0
  147. package/docs/configure/app/performance/remove-console.md +2 -0
  148. package/docs/configure/app/performance/remove-moment-locale.md +2 -0
  149. package/docs/configure/app/plugins.md +2 -0
  150. package/docs/configure/app/resolve/alias-strategy.md +2 -0
  151. package/docs/configure/app/resolve/alias.md +2 -0
  152. package/docs/configure/app/resolve/condition-names.md +2 -0
  153. package/docs/configure/app/resolve/dedupe.md +2 -0
  154. package/docs/configure/app/resolve/extensions.md +2 -0
  155. package/docs/configure/app/runtime/0-intro.md +2 -0
  156. package/docs/configure/app/runtime/plugins.md +8 -4
  157. package/docs/configure/app/runtime/router.md +2 -0
  158. package/docs/configure/app/security/check-syntax.md +2 -0
  159. package/docs/configure/app/security/nonce.md +2 -0
  160. package/docs/configure/app/security/sri.md +2 -0
  161. package/docs/configure/app/server/base-url.md +2 -0
  162. package/docs/configure/app/server/port.md +2 -0
  163. package/docs/configure/app/server/public-routes.md +2 -0
  164. package/docs/configure/app/server/routes.md +2 -0
  165. package/docs/configure/app/server/rsc.md +2 -0
  166. package/docs/configure/app/server/ssr-by-entries.md +2 -0
  167. package/docs/configure/app/server/ssr.md +3 -1
  168. package/docs/configure/app/server/tsconfig-path.md +4 -2
  169. package/docs/configure/app/source/alias-strategy.md +2 -0
  170. package/docs/configure/app/source/alias.md +2 -0
  171. package/docs/configure/app/source/config-dir.md +2 -0
  172. package/docs/configure/app/source/decorators.md +2 -0
  173. package/docs/configure/app/source/define.md +2 -0
  174. package/docs/configure/app/source/disable-default-entries.md +2 -0
  175. package/docs/configure/app/source/enable-async-entry.md +2 -0
  176. package/docs/configure/app/source/enable-async-pre-entry.md +2 -0
  177. package/docs/configure/app/source/entries-dir.md +2 -0
  178. package/docs/configure/app/source/entries.md +2 -0
  179. package/docs/configure/app/source/exclude.md +2 -0
  180. package/docs/configure/app/source/global-vars.md +2 -0
  181. package/docs/configure/app/source/include.md +2 -0
  182. package/docs/configure/app/source/main-entry-name.md +2 -0
  183. package/docs/configure/app/source/pre-entry.md +2 -0
  184. package/docs/configure/app/source/react-compiler.md +2 -0
  185. package/docs/configure/app/source/transform-import.md +2 -0
  186. package/docs/configure/app/split-chunks.md +2 -0
  187. package/docs/configure/app/tools/autoprefixer.md +2 -0
  188. package/docs/configure/app/tools/bundler-chain.md +2 -0
  189. package/docs/configure/app/tools/css-extract.md +2 -0
  190. package/docs/configure/app/tools/css-loader.md +2 -0
  191. package/docs/configure/app/tools/dev-server.md +2 -0
  192. package/docs/configure/app/tools/html-plugin.md +2 -0
  193. package/docs/configure/app/tools/less.md +96 -19
  194. package/docs/configure/app/tools/lightningcss-loader.md +2 -0
  195. package/docs/configure/app/tools/minify-css.md +2 -0
  196. package/docs/configure/app/tools/postcss.md +2 -0
  197. package/docs/configure/app/tools/rspack.md +2 -0
  198. package/docs/configure/app/tools/sass.md +89 -18
  199. package/docs/configure/app/tools/style-loader.md +2 -0
  200. package/docs/configure/app/tools/svgr.md +91 -0
  201. package/docs/configure/app/tools/swc.md +2 -0
  202. package/docs/configure/app/tools/ts-checker.md +2 -0
  203. package/docs/configure/app/usage.md +3 -5
  204. package/docs/guides/advanced-features/bff/cross-project.md +6 -4
  205. package/docs/guides/advanced-features/bff/extend-server.md +2 -0
  206. package/docs/guides/advanced-features/bff/frameworks.md +2 -0
  207. package/docs/guides/advanced-features/bff/function.md +2 -0
  208. package/docs/guides/advanced-features/bff/operators.md +2 -0
  209. package/docs/guides/advanced-features/bff/sdk.md +2 -0
  210. package/docs/guides/advanced-features/bff/upload.md +2 -0
  211. package/docs/guides/advanced-features/bff.md +2 -0
  212. package/docs/guides/advanced-features/build-performance.md +2 -0
  213. package/docs/guides/advanced-features/compatibility.md +2 -0
  214. package/docs/guides/advanced-features/international/advanced.md +3 -1
  215. package/docs/guides/advanced-features/international/api.md +21 -13
  216. package/docs/guides/advanced-features/international/best-practices.md +17 -15
  217. package/docs/guides/advanced-features/international/configuration.md +3 -1
  218. package/docs/guides/advanced-features/international/locale-detection.md +15 -4
  219. package/docs/guides/advanced-features/international/quick-start.md +2 -0
  220. package/docs/guides/advanced-features/international/resource-loading.md +11 -7
  221. package/docs/guides/advanced-features/international/routing.md +5 -1
  222. package/docs/guides/advanced-features/international.md +2 -0
  223. package/docs/guides/advanced-features/low-level.md +2 -0
  224. package/docs/guides/advanced-features/page-performance/code-split.md +2 -0
  225. package/docs/guides/advanced-features/page-performance/inline-assets.md +2 -0
  226. package/docs/guides/advanced-features/page-performance/optimize-bundle.md +2 -0
  227. package/docs/guides/advanced-features/page-performance/react-compiler.md +2 -0
  228. package/docs/guides/advanced-features/server-monitor/logger.md +2 -0
  229. package/docs/guides/advanced-features/server-monitor/metrics.md +2 -0
  230. package/docs/guides/advanced-features/server-monitor/monitors.md +3 -3
  231. package/docs/guides/advanced-features/source-build.md +3 -1
  232. package/docs/guides/advanced-features/web-server.md +5 -3
  233. package/docs/guides/basic-features/alias.md +2 -0
  234. package/docs/guides/basic-features/css/css-in-js.md +2 -0
  235. package/docs/guides/basic-features/css/css-modules.md +2 -0
  236. package/docs/guides/basic-features/css/css.md +2 -0
  237. package/docs/guides/basic-features/css/tailwindcss.md +2 -0
  238. package/docs/guides/basic-features/data/data-cache.md +2 -0
  239. package/docs/guides/basic-features/data/data-fetch.md +3 -3
  240. package/docs/guides/basic-features/data/data-write.md +25 -28
  241. package/docs/guides/basic-features/debug/mock.md +4 -2
  242. package/docs/guides/basic-features/debug/proxy.md +2 -0
  243. package/docs/guides/basic-features/debug/rsdoctor.md +2 -0
  244. package/docs/guides/basic-features/debug/using-storybook.md +6 -4
  245. package/docs/guides/basic-features/deploy.md +2 -0
  246. package/docs/guides/basic-features/env-vars.md +2 -0
  247. package/docs/guides/basic-features/html.md +4 -3
  248. package/docs/guides/basic-features/output-files.md +3 -1
  249. package/docs/guides/basic-features/render/before-render.md +2 -0
  250. package/docs/guides/basic-features/render/overview.md +2 -0
  251. package/docs/guides/basic-features/render/rsc.md +12 -2
  252. package/docs/guides/basic-features/render/ssg.md +2 -0
  253. package/docs/guides/basic-features/render/ssr-cache.md +2 -0
  254. package/docs/guides/basic-features/render/ssr.md +10 -12
  255. package/docs/guides/basic-features/render/streaming-ssr.md +4 -1
  256. package/docs/guides/basic-features/routes/config-routes.md +54 -54
  257. package/docs/guides/basic-features/routes/routes.md +2 -0
  258. package/docs/guides/basic-features/static-assets/json-files.md +2 -0
  259. package/docs/guides/basic-features/static-assets/svg-assets.md +31 -17
  260. package/docs/guides/basic-features/static-assets/wasm-assets.md +2 -0
  261. package/docs/guides/basic-features/static-assets.md +2 -0
  262. package/docs/guides/basic-features/testing/playwright.md +8 -6
  263. package/docs/guides/basic-features/testing/rstest.md +7 -5
  264. package/docs/guides/concept/builder.md +2 -0
  265. package/docs/guides/concept/entries.md +2 -0
  266. package/docs/guides/concept/server.md +2 -0
  267. package/docs/guides/get-started/ai-coding-agents.md +5 -3
  268. package/docs/guides/get-started/glossary.md +2 -0
  269. package/docs/guides/get-started/introduction.md +2 -0
  270. package/docs/guides/get-started/quick-start.md +13 -5
  271. package/docs/guides/get-started/tech-stack.md +2 -0
  272. package/docs/guides/get-started/upgrade.md +2 -0
  273. package/docs/guides/topic-detail/module-federation/application.md +2 -0
  274. package/docs/guides/topic-detail/module-federation/deploy.md +4 -2
  275. package/docs/guides/topic-detail/module-federation/i18n.md +2 -0
  276. package/docs/guides/topic-detail/module-federation/introduce.md +2 -0
  277. package/docs/guides/topic-detail/module-federation/ssr.md +2 -0
  278. package/docs/guides/topic-detail/module-federation/usage.md +2 -0
  279. package/docs/guides/troubleshooting/builder.md +2 -0
  280. package/docs/guides/troubleshooting/cli.md +2 -0
  281. package/docs/guides/troubleshooting/dependencies.md +2 -0
  282. package/docs/guides/troubleshooting/hmr.md +2 -0
  283. package/docs/guides/upgrade/config.md +14 -0
  284. package/docs/guides/upgrade/entry.md +2 -0
  285. package/docs/guides/upgrade/other.md +2 -0
  286. package/docs/guides/upgrade/overview.md +2 -0
  287. package/docs/guides/upgrade/tailwindcss.md +2 -0
  288. package/docs/guides/upgrade/web-server.md +25 -6
  289. package/docs/index.md +2 -0
  290. package/docs/llms.txt +8 -7
  291. package/docs/plugin/cli-plugins/api.md +2 -0
  292. package/docs/plugin/cli-plugins/life-cycle.md +2 -0
  293. package/docs/plugin/introduction.md +12 -10
  294. package/docs/plugin/official/cli-plugins/plugin-bff.md +2 -0
  295. package/docs/plugin/official/cli-plugins/plugin-ssg.md +2 -0
  296. package/docs/plugin/official/cli-plugins/plugin-styled-components.md +2 -0
  297. package/docs/plugin/official/cli-plugins.md +2 -0
  298. package/docs/plugin/plugin-system.md +3 -3
  299. package/docs/plugin/runtime-plugins/api.md +2 -0
  300. package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
  301. package/docs/plugin/server-plugins/api.md +2 -0
  302. package/docs/plugin/server-plugins/life-cycle.md +2 -0
  303. package/docs/tutorials/examples/csr-auth.md +2 -0
  304. package/docs/tutorials/foundations/introduction.md +2 -0
  305. package/lib/types.d.ts +0 -1
  306. package/package.json +18 -19
  307. package/{rslib.config.mts → rstack.config.mts} +4 -4
  308. package/dist/cjs/types/config/testing.js +0 -18
  309. package/dist/esm/types/config/testing.mjs +0 -0
  310. package/dist/esm-node/types/config/testing.mjs +0 -1
  311. package/dist/types/types/config/testing.d.ts +0 -8
@@ -35,9 +35,25 @@ class HtmlAsyncChunkPlugin {
35
35
  apply(compiler) {
36
36
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
37
37
  const hooks = this.htmlPlugin.getCompilationHooks(compilation);
38
- hooks.alterAssetTagGroups.tap(this.name, (assets)=>{
38
+ const runtimeInEntry = false === compiler.options.optimization.runtimeChunk;
39
+ const getEntryRuntimeUrls = (publicPath)=>new Set([
40
+ ...compilation.entrypoints.values()
41
+ ].flatMap((entrypoint)=>[
42
+ ...entrypoint.getRuntimeChunk().files
43
+ ].flatMap((file)=>{
44
+ const pathname = file.split('?', 1)[0];
45
+ return [
46
+ `${publicPath}${pathname}`,
47
+ `${publicPath}${pathname.split('/').map(encodeURIComponent).join('/')}`
48
+ ];
49
+ })));
50
+ hooks.alterAssetTagGroups.tap({
51
+ name: this.name,
52
+ stage: -1
53
+ }, (assets)=>{
39
54
  const headTags = [];
40
55
  const bodyTags = [];
56
+ const entryRuntimeUrls = runtimeInEntry ? getEntryRuntimeUrls(assets.publicPath) : new Set();
41
57
  const processScriptTag = (tag)=>{
42
58
  const { attributes } = tag;
43
59
  if (attributes && true === attributes.defer) {
@@ -45,7 +61,7 @@ class HtmlAsyncChunkPlugin {
45
61
  delete attributes.defer;
46
62
  }
47
63
  const src = attributes?.src;
48
- const isRuntimeChunk = src && builder_namespaceObject.RUNTIME_CHUNK_REGEX.test(src);
64
+ const isRuntimeChunk = 'string' == typeof src && (runtimeInEntry ? entryRuntimeUrls.has(src.split(/[?#]/, 1)[0]) : builder_namespaceObject.RUNTIME_CHUNK_REGEX.test(src));
49
65
  return isRuntimeChunk ? bodyTags : headTags;
50
66
  };
51
67
  for (const tag of [
@@ -59,6 +75,42 @@ class HtmlAsyncChunkPlugin {
59
75
  bodyTags
60
76
  };
61
77
  });
78
+ if (runtimeInEntry) hooks.alterAssetTagGroups.tap({
79
+ name: this.name,
80
+ stage: 1
81
+ }, (assets)=>{
82
+ const entryRuntimeUrls = getEntryRuntimeUrls(assets.publicPath);
83
+ for (const tag of assets.bodyTags){
84
+ const src = tag.attributes?.src;
85
+ if ("script" !== tag.tagName || 'string' != typeof src || !entryRuntimeUrls.has(src.split(/[?#]/, 1)[0])) continue;
86
+ const attributes = {
87
+ rel: 'module' === tag.attributes.type ? 'modulepreload' : 'preload',
88
+ href: src,
89
+ ...'module' === tag.attributes.type ? {} : {
90
+ as: "script"
91
+ }
92
+ };
93
+ const resourceAttributes = [
94
+ 'crossorigin',
95
+ 'integrity',
96
+ 'referrerpolicy',
97
+ 'fetchpriority',
98
+ 'nonce'
99
+ ];
100
+ for (const key of resourceAttributes)if (void 0 !== tag.attributes[key]) attributes[key] = tag.attributes[key];
101
+ if (!assets.headTags.some((existing)=>'link' === existing.tagName && [
102
+ 'rel',
103
+ 'href',
104
+ 'as',
105
+ ...resourceAttributes
106
+ ].every((key)=>existing.attributes?.[key] === attributes[key]))) assets.headTags.push({
107
+ tagName: 'link',
108
+ voidTag: true,
109
+ attributes
110
+ });
111
+ }
112
+ return assets;
113
+ });
62
114
  });
63
115
  }
64
116
  constructor(htmlPlugin){
@@ -98,10 +98,9 @@ const build = async (api, options)=>{
98
98
  utils_namespaceObject.logger.info('Starting production build...');
99
99
  if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
100
100
  await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
101
- const buildResult = await appContext.builder.build({
101
+ await appContext.builder.build({
102
102
  watch: options?.watch
103
103
  });
104
- if (!options?.watch) await buildResult?.close();
105
104
  };
106
105
  exports.build = __webpack_exports__.build;
107
106
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -31,12 +31,10 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  deploy: ()=>deploy
32
32
  });
33
33
  const loadPlugins_js_namespaceObject = require("../utils/loadPlugins.js");
34
- const external_build_js_namespaceObject = require("./build.js");
35
34
  const deploy = async (api, options = {})=>{
36
35
  const hooks = api.getHooks();
37
36
  const { metaName } = api.getAppContext();
38
- if (options.skipBuild) await (0, loadPlugins_js_namespaceObject.getServerPlugins)(api, metaName);
39
- else await (0, external_build_js_namespaceObject.build)(api);
37
+ await (0, loadPlugins_js_namespaceObject.getServerPlugins)(api, metaName);
40
38
  await hooks.onBeforeDeploy.call(options);
41
39
  await hooks.deploy.call();
42
40
  await hooks.onAfterDeploy.call(options);
@@ -56,6 +56,10 @@ const serverCommand = (program, api)=>{
56
56
  };
57
57
  const deployCommand = (program, api)=>{
58
58
  program.command('deploy').usage('[options]').option('-c --config <config>', index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.shared.config)).option('-s --skip-build', index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.shared.skipBuild)).description(index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.deploy.describe)).action(async (options)=>{
59
+ if (!options.skipBuild) {
60
+ const { build } = await import("./build.js");
61
+ await build(api);
62
+ }
59
63
  const { deploy } = await import("./deploy.js");
60
64
  await deploy(api, options);
61
65
  process.exit(0);
@@ -51,11 +51,6 @@ function getHookRunners(context) {
51
51
  const result = await hooks?.appendEntryCode.call(params);
52
52
  return result;
53
53
  },
54
- jestConfig: async (utils)=>{
55
- const result = await hooks?.jestConfig.call(utils, (utils)=>utils);
56
- return result;
57
- },
58
- afterTest: async ()=>hooks.afterTest.call(),
59
54
  config: async ()=>hooks.config.call(),
60
55
  resolvedConfig: (params)=>hooks.modifyResolvedConfig.call(params),
61
56
  htmlPartials: async (params)=>{
@@ -30,7 +30,6 @@ __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  compatPlugin: ()=>compatPlugin
32
32
  });
33
- const plugin_namespaceObject = require("@modern-js/plugin");
34
33
  const external_hooks_js_namespaceObject = require("./hooks.js");
35
34
  const compatPlugin = ()=>({
36
35
  name: '@modern-js/app-tools-compat',
@@ -47,10 +46,6 @@ const compatPlugin = ()=>({
47
46
  useHookRunners: ()=>(0, external_hooks_js_namespaceObject.getHookRunners)(getInternalContext())
48
47
  };
49
48
  },
50
- registryHooks: {
51
- jestConfig: (0, plugin_namespaceObject.createAsyncHook)(),
52
- afterTest: (0, plugin_namespaceObject.createAsyncHook)()
53
- },
54
49
  setup: (api)=>{
55
50
  api.updateAppContext({
56
51
  toolsType: 'app-tools'
@@ -101,11 +101,6 @@ function transformHookParams(hookRunnerName, params) {
101
101
  entrypoint: params[0].entrypoint
102
102
  }
103
103
  };
104
- case 'jestConfig':
105
- return {
106
- isMultiple: true,
107
- params: params
108
- };
109
104
  default:
110
105
  return {
111
106
  isMultiple: false,
package/dist/cjs/index.js CHANGED
@@ -1,11 +1,5 @@
1
1
  "use strict";
2
2
  var __webpack_modules__ = {
3
- "./commands/build" (module) {
4
- module.exports = require("./commands/build.js");
5
- },
6
- "./commands/deploy" (module) {
7
- module.exports = require("./commands/deploy.js");
8
- },
9
3
  "./commands/dev" (module) {
10
4
  module.exports = require("./commands/dev.js");
11
5
  },
@@ -155,21 +149,17 @@ var __webpack_exports__ = {};
155
149
  "serve",
156
150
  "generateWatchFiles",
157
151
  "initAppContext",
158
- "deploy",
159
152
  "defineConfig",
160
- "build",
161
153
  "closeServer"
162
154
  ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_defineConfig__rspack_import_16[__rspack_import_key];
163
155
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
164
- var _commands_build__rspack_import_17 = __webpack_require__("./commands/build");
165
- var _commands_deploy__rspack_import_18 = __webpack_require__("./commands/deploy");
166
- var _commands_dev__rspack_import_19 = __webpack_require__("./commands/dev");
167
- var _commands_serve__rspack_import_20 = __webpack_require__("./commands/serve");
168
- var _utils_createServer__rspack_import_21 = __webpack_require__("./utils/createServer");
169
- var _rsbuild__rspack_import_22 = __webpack_require__("./rsbuild");
170
- var _types__rspack_import_23 = __webpack_require__("./types?6efa");
156
+ var _commands_dev__rspack_import_17 = __webpack_require__("./commands/dev");
157
+ var _commands_serve__rspack_import_18 = __webpack_require__("./commands/serve");
158
+ var _utils_createServer__rspack_import_19 = __webpack_require__("./utils/createServer");
159
+ var _rsbuild__rspack_import_20 = __webpack_require__("./rsbuild");
160
+ var _types__rspack_import_21 = __webpack_require__("./types?6efa");
171
161
  var __rspack_reexport = {};
172
- for(const __rspack_import_key in _types__rspack_import_23)if ([
162
+ for(const __rspack_import_key in _types__rspack_import_21)if ([
173
163
  "dev",
174
164
  "resolveModernRsbuildConfig",
175
165
  "mergeConfig",
@@ -178,13 +168,11 @@ var __webpack_exports__ = {};
178
168
  "serve",
179
169
  "generateWatchFiles",
180
170
  "initAppContext",
181
- "deploy",
182
171
  "defineConfig",
183
- "build",
184
172
  "closeServer"
185
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_23[__rspack_import_key];
173
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_21[__rspack_import_key];
186
174
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
187
- var _modern_js_plugin_cli__rspack_import_24 = __webpack_require__("@modern-js/plugin/cli");
175
+ var _modern_js_plugin_cli__rspack_import_22 = __webpack_require__("@modern-js/plugin/cli");
188
176
  const appTools = ()=>({
189
177
  name: '@modern-js/app-tools',
190
178
  usePlugins: [
@@ -244,18 +232,12 @@ var __webpack_exports__ = {};
244
232
  ].some((tag)=>(0, _modern_js_utils__rspack_import_4.getArgv)().includes(tag));
245
233
  if (isSkipBuild) return;
246
234
  }
247
- const { command: contextCommand } = api.getAppContext();
248
- const shouldClean = [
235
+ if ([
249
236
  'dev',
250
237
  'start',
251
238
  'build',
252
239
  'deploy'
253
- ].includes(command) || [
254
- 'dev',
255
- 'start',
256
- 'build'
257
- ].includes(contextCommand);
258
- if (shouldClean) {
240
+ ].includes(command)) {
259
241
  const resolvedConfig = api.getNormalizedConfig();
260
242
  if (resolvedConfig.output.cleanDistPath) {
261
243
  const appContext = api.getAppContext();
@@ -295,27 +277,23 @@ var __webpack_exports__ = {};
295
277
  });
296
278
  const __rspack_default_export = appTools;
297
279
  __webpack_require__.d(__webpack_exports__, {
298
- build: ()=>_commands_build__rspack_import_17.build,
299
- closeServer: ()=>_utils_createServer__rspack_import_21.closeServer,
280
+ closeServer: ()=>_utils_createServer__rspack_import_19.closeServer,
300
281
  defineConfig: ()=>_defineConfig__rspack_import_16.defineConfig,
301
- deploy: ()=>_commands_deploy__rspack_import_18.deploy,
302
- dev: ()=>_commands_dev__rspack_import_19.dev,
282
+ dev: ()=>_commands_dev__rspack_import_17.dev,
303
283
  generateWatchFiles: ()=>_utils_generateWatchFiles__rspack_import_13.generateWatchFiles,
304
284
  initAppContext: ()=>_utils_initAppContext__rspack_import_14.initAppContext,
305
- mergeConfig: ()=>_modern_js_plugin_cli__rspack_import_24.mergeConfig,
306
- resolveModernRsbuildConfig: ()=>_rsbuild__rspack_import_22.resolveModernRsbuildConfig,
307
- serve: ()=>_commands_serve__rspack_import_20.serve
285
+ mergeConfig: ()=>_modern_js_plugin_cli__rspack_import_22.mergeConfig,
286
+ resolveModernRsbuildConfig: ()=>_rsbuild__rspack_import_20.resolveModernRsbuildConfig,
287
+ serve: ()=>_commands_serve__rspack_import_18.serve
308
288
  }, {
309
289
  appTools: appTools,
310
290
  default: __rspack_default_export
311
291
  });
312
292
  })();
313
293
  exports.appTools = __webpack_exports__.appTools;
314
- exports.build = __webpack_exports__.build;
315
294
  exports.closeServer = __webpack_exports__.closeServer;
316
295
  exports["default"] = __webpack_exports__["default"];
317
296
  exports.defineConfig = __webpack_exports__.defineConfig;
318
- exports.deploy = __webpack_exports__.deploy;
319
297
  exports.dev = __webpack_exports__.dev;
320
298
  exports.generateWatchFiles = __webpack_exports__.generateWatchFiles;
321
299
  exports.initAppContext = __webpack_exports__.initAppContext;
@@ -324,11 +302,9 @@ exports.resolveModernRsbuildConfig = __webpack_exports__.resolveModernRsbuildCon
324
302
  exports.serve = __webpack_exports__.serve;
325
303
  for(var __rspack_i in __webpack_exports__)if (-1 === [
326
304
  "appTools",
327
- "build",
328
305
  "closeServer",
329
306
  "default",
330
307
  "defineConfig",
331
- "deploy",
332
308
  "dev",
333
309
  "generateWatchFiles",
334
310
  "initAppContext",
@@ -55,7 +55,7 @@ const analyze = ()=>({
55
55
  const resolvedConfig = api.getNormalizedConfig();
56
56
  const hooks = api.getHooks();
57
57
  try {
58
- if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)(appContext.command)) utils_namespaceObject.fs.emptydirSync(appContext.internalDirectory);
58
+ if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)()) utils_namespaceObject.fs.emptydirSync(appContext.internalDirectory);
59
59
  } catch {}
60
60
  const apiOnly = await (0, utils_namespaceObject.isApiOnly)(appContext.appDirectory, resolvedConfig.source?.entriesDir, appContext.apiDirectory);
61
61
  const [{ getProdServerRoutes }] = await Promise.all([
@@ -149,7 +149,7 @@ const analyze = ()=>({
149
149
  htmlTemplates
150
150
  };
151
151
  api.updateAppContext(appContext);
152
- if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)(appContext.command)) {
152
+ if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)()) {
153
153
  await hooks.generateEntryCode.call({
154
154
  entrypoints
155
155
  });
@@ -101,7 +101,7 @@ const parseModule = async ({ source, filename })=>{
101
101
  return await (0, external_es_module_lexer_namespaceObject.parse)(content);
102
102
  };
103
103
  const getServerCombinedModuleFile = (internalDirectory, entryName)=>external_path_default().join(internalDirectory, entryName, 'server-loader-combined.js');
104
- const checkIsBuildCommands = (contextCommand)=>{
104
+ const checkIsBuildCommands = ()=>{
105
105
  const buildCommands = [
106
106
  'dev',
107
107
  'start',
@@ -111,8 +111,7 @@ const checkIsBuildCommands = (contextCommand)=>{
111
111
  'dev-worker'
112
112
  ];
113
113
  const command = (0, utils_namespaceObject.getCommand)();
114
- if (buildCommands.includes(command)) return true;
115
- return 'dev' === contextCommand || 'start' === contextCommand || 'build' === contextCommand || 'deploy' === contextCommand;
114
+ return buildCommands.includes(command);
116
115
  };
117
116
  const checkIsServeCommand = ()=>{
118
117
  const command = (0, utils_namespaceObject.getCommand)();
@@ -57,7 +57,7 @@ const initialize = ()=>({
57
57
  api.modifyResolvedConfig(async (resolved)=>{
58
58
  let appContext = api.getAppContext();
59
59
  const userConfig = api.getConfig();
60
- const port = await getServerPort(resolved, appContext.command);
60
+ const port = await getServerPort(resolved);
61
61
  appContext = {
62
62
  ...appContext,
63
63
  port,
@@ -77,7 +77,6 @@ const initialize = ()=>({
77
77
  'html',
78
78
  'output',
79
79
  'tools',
80
- 'testing',
81
80
  'plugins',
82
81
  'builderPlugins',
83
82
  'deploy',
@@ -92,10 +91,9 @@ function stabilizeConfig(resolve, config, keys) {
92
91
  resolve[key] = config[key] || {};
93
92
  });
94
93
  }
95
- async function getServerPort(config, contextCommand) {
94
+ async function getServerPort(config) {
96
95
  const prodPort = Number(process.env.PORT) || config.server.port || 8080;
97
- const isProgrammaticDev = 'dev' === contextCommand || 'start' === contextCommand;
98
- if ((0, utils_namespaceObject.isDev)() && ((0, utils_namespaceObject.isDevCommand)() || isProgrammaticDev)) return (0, utils_namespaceObject.getPort)(Number(process.env.PORT) || prodPort);
96
+ if ((0, utils_namespaceObject.isDev)() && (0, utils_namespaceObject.isDevCommand)()) return (0, utils_namespaceObject.getPort)(Number(process.env.PORT) || prodPort);
99
97
  return prodPort;
100
98
  }
101
99
  exports["default"] = __webpack_exports__["default"];
@@ -3,9 +3,25 @@ class HtmlAsyncChunkPlugin {
3
3
  apply(compiler) {
4
4
  compiler.hooks.compilation.tap(this.name, (compilation)=>{
5
5
  const hooks = this.htmlPlugin.getCompilationHooks(compilation);
6
- hooks.alterAssetTagGroups.tap(this.name, (assets)=>{
6
+ const runtimeInEntry = false === compiler.options.optimization.runtimeChunk;
7
+ const getEntryRuntimeUrls = (publicPath)=>new Set([
8
+ ...compilation.entrypoints.values()
9
+ ].flatMap((entrypoint)=>[
10
+ ...entrypoint.getRuntimeChunk().files
11
+ ].flatMap((file)=>{
12
+ const pathname = file.split('?', 1)[0];
13
+ return [
14
+ `${publicPath}${pathname}`,
15
+ `${publicPath}${pathname.split('/').map(encodeURIComponent).join('/')}`
16
+ ];
17
+ })));
18
+ hooks.alterAssetTagGroups.tap({
19
+ name: this.name,
20
+ stage: -1
21
+ }, (assets)=>{
7
22
  const headTags = [];
8
23
  const bodyTags = [];
24
+ const entryRuntimeUrls = runtimeInEntry ? getEntryRuntimeUrls(assets.publicPath) : new Set();
9
25
  const processScriptTag = (tag)=>{
10
26
  const { attributes } = tag;
11
27
  if (attributes && true === attributes.defer) {
@@ -13,7 +29,7 @@ class HtmlAsyncChunkPlugin {
13
29
  delete attributes.defer;
14
30
  }
15
31
  const src = attributes?.src;
16
- const isRuntimeChunk = src && RUNTIME_CHUNK_REGEX.test(src);
32
+ const isRuntimeChunk = 'string' == typeof src && (runtimeInEntry ? entryRuntimeUrls.has(src.split(/[?#]/, 1)[0]) : RUNTIME_CHUNK_REGEX.test(src));
17
33
  return isRuntimeChunk ? bodyTags : headTags;
18
34
  };
19
35
  for (const tag of [
@@ -27,6 +43,42 @@ class HtmlAsyncChunkPlugin {
27
43
  bodyTags
28
44
  };
29
45
  });
46
+ if (runtimeInEntry) hooks.alterAssetTagGroups.tap({
47
+ name: this.name,
48
+ stage: 1
49
+ }, (assets)=>{
50
+ const entryRuntimeUrls = getEntryRuntimeUrls(assets.publicPath);
51
+ for (const tag of assets.bodyTags){
52
+ const src = tag.attributes?.src;
53
+ if ("script" !== tag.tagName || 'string' != typeof src || !entryRuntimeUrls.has(src.split(/[?#]/, 1)[0])) continue;
54
+ const attributes = {
55
+ rel: 'module' === tag.attributes.type ? 'modulepreload' : 'preload',
56
+ href: src,
57
+ ...'module' === tag.attributes.type ? {} : {
58
+ as: "script"
59
+ }
60
+ };
61
+ const resourceAttributes = [
62
+ 'crossorigin',
63
+ 'integrity',
64
+ 'referrerpolicy',
65
+ 'fetchpriority',
66
+ 'nonce'
67
+ ];
68
+ for (const key of resourceAttributes)if (void 0 !== tag.attributes[key]) attributes[key] = tag.attributes[key];
69
+ if (!assets.headTags.some((existing)=>'link' === existing.tagName && [
70
+ 'rel',
71
+ 'href',
72
+ 'as',
73
+ ...resourceAttributes
74
+ ].every((key)=>existing.attributes?.[key] === attributes[key]))) assets.headTags.push({
75
+ tagName: 'link',
76
+ voidTag: true,
77
+ attributes
78
+ });
79
+ }
80
+ return assets;
81
+ });
30
82
  });
31
83
  }
32
84
  constructor(htmlPlugin){
@@ -56,9 +56,8 @@ const build = async (api, options)=>{
56
56
  logger.info('Starting production build...');
57
57
  if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
58
58
  await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
59
- const buildResult = await appContext.builder.build({
59
+ await appContext.builder.build({
60
60
  watch: options?.watch
61
61
  });
62
- if (!options?.watch) await buildResult?.close();
63
62
  };
64
63
  export { build };
@@ -1,10 +1,8 @@
1
1
  import { getServerPlugins } from "../utils/loadPlugins.mjs";
2
- import { build } from "./build.mjs";
3
2
  const deploy = async (api, options = {})=>{
4
3
  const hooks = api.getHooks();
5
4
  const { metaName } = api.getAppContext();
6
- if (options.skipBuild) await getServerPlugins(api, metaName);
7
- else await build(api);
5
+ await getServerPlugins(api, metaName);
8
6
  await hooks.onBeforeDeploy.call(options);
9
7
  await hooks.deploy.call();
10
8
  await hooks.onAfterDeploy.call(options);
@@ -19,6 +19,10 @@ const serverCommand = (program, api)=>{
19
19
  };
20
20
  const deployCommand = (program, api)=>{
21
21
  program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
22
+ if (!options.skipBuild) {
23
+ const { build } = await import("./build.mjs");
24
+ await build(api);
25
+ }
22
26
  const { deploy } = await import("./deploy.mjs");
23
27
  await deploy(api, options);
24
28
  process.exit(0);
@@ -18,11 +18,6 @@ function getHookRunners(context) {
18
18
  const result = await hooks?.appendEntryCode.call(params);
19
19
  return result;
20
20
  },
21
- jestConfig: async (utils)=>{
22
- const result = await hooks?.jestConfig.call(utils, (utils)=>utils);
23
- return result;
24
- },
25
- afterTest: async ()=>hooks.afterTest.call(),
26
21
  config: async ()=>hooks.config.call(),
27
22
  resolvedConfig: (params)=>hooks.modifyResolvedConfig.call(params),
28
23
  htmlPartials: async (params)=>{
@@ -1,4 +1,3 @@
1
- import { createAsyncHook } from "@modern-js/plugin";
2
1
  import { getHookRunners } from "./hooks.mjs";
3
2
  const compatPlugin = ()=>({
4
3
  name: '@modern-js/app-tools-compat',
@@ -15,10 +14,6 @@ const compatPlugin = ()=>({
15
14
  useHookRunners: ()=>getHookRunners(getInternalContext())
16
15
  };
17
16
  },
18
- registryHooks: {
19
- jestConfig: createAsyncHook(),
20
- afterTest: createAsyncHook()
21
- },
22
17
  setup: (api)=>{
23
18
  api.updateAppContext({
24
19
  toolsType: 'app-tools'
@@ -67,11 +67,6 @@ function transformHookParams(hookRunnerName, params) {
67
67
  entrypoint: params[0].entrypoint
68
68
  }
69
69
  };
70
- case 'jestConfig':
71
- return {
72
- isMultiple: true,
73
- params: params
74
- };
75
70
  default:
76
71
  return {
77
72
  isMultiple: false,
@@ -75,18 +75,12 @@ const appTools = ()=>({
75
75
  ].some((tag)=>getArgv().includes(tag));
76
76
  if (isSkipBuild) return;
77
77
  }
78
- const { command: contextCommand } = api.getAppContext();
79
- const shouldClean = [
78
+ if ([
80
79
  'dev',
81
80
  'start',
82
81
  'build',
83
82
  'deploy'
84
- ].includes(command) || [
85
- 'dev',
86
- 'start',
87
- 'build'
88
- ].includes(contextCommand);
89
- if (shouldClean) {
83
+ ].includes(command)) {
90
84
  const resolvedConfig = api.getNormalizedConfig();
91
85
  if (resolvedConfig.output.cleanDistPath) {
92
86
  const appContext = api.getAppContext();
@@ -126,8 +120,6 @@ const appTools = ()=>({
126
120
  });
127
121
  const src = appTools;
128
122
  export { defineConfig } from "./defineConfig.mjs";
129
- export { build } from "./commands/build.mjs";
130
- export { deploy } from "./commands/deploy.mjs";
131
123
  export { dev } from "./commands/dev.mjs";
132
124
  export { serve } from "./commands/serve.mjs";
133
125
  export { closeServer } from "./utils/createServer.mjs";
@@ -23,7 +23,7 @@ const analyze = ()=>({
23
23
  const resolvedConfig = api.getNormalizedConfig();
24
24
  const hooks = api.getHooks();
25
25
  try {
26
- if (checkIsBuildCommands(appContext.command)) fs.emptydirSync(appContext.internalDirectory);
26
+ if (checkIsBuildCommands()) fs.emptydirSync(appContext.internalDirectory);
27
27
  } catch {}
28
28
  const apiOnly = await isApiOnly(appContext.appDirectory, resolvedConfig.source?.entriesDir, appContext.apiDirectory);
29
29
  const [{ getProdServerRoutes }] = await Promise.all([
@@ -117,7 +117,7 @@ const analyze = ()=>({
117
117
  htmlTemplates
118
118
  };
119
119
  api.updateAppContext(appContext);
120
- if (checkIsBuildCommands(appContext.command)) {
120
+ if (checkIsBuildCommands()) {
121
121
  await hooks.generateEntryCode.call({
122
122
  entrypoints
123
123
  });
@@ -52,7 +52,7 @@ const parseModule = async ({ source, filename })=>{
52
52
  return await parse(content);
53
53
  };
54
54
  const getServerCombinedModuleFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
55
- const checkIsBuildCommands = (contextCommand)=>{
55
+ const checkIsBuildCommands = ()=>{
56
56
  const buildCommands = [
57
57
  'dev',
58
58
  'start',
@@ -62,8 +62,7 @@ const checkIsBuildCommands = (contextCommand)=>{
62
62
  'dev-worker'
63
63
  ];
64
64
  const command = getCommand();
65
- if (buildCommands.includes(command)) return true;
66
- return 'dev' === contextCommand || 'start' === contextCommand || 'build' === contextCommand || 'deploy' === contextCommand;
65
+ return buildCommands.includes(command);
67
66
  };
68
67
  const checkIsServeCommand = ()=>{
69
68
  const command = getCommand();
@@ -25,7 +25,7 @@ const initialize = ()=>({
25
25
  api.modifyResolvedConfig(async (resolved)=>{
26
26
  let appContext = api.getAppContext();
27
27
  const userConfig = api.getConfig();
28
- const port = await getServerPort(resolved, appContext.command);
28
+ const port = await getServerPort(resolved);
29
29
  appContext = {
30
30
  ...appContext,
31
31
  port,
@@ -45,7 +45,6 @@ const initialize = ()=>({
45
45
  'html',
46
46
  'output',
47
47
  'tools',
48
- 'testing',
49
48
  'plugins',
50
49
  'builderPlugins',
51
50
  'deploy',
@@ -60,10 +59,9 @@ function stabilizeConfig(resolve, config, keys) {
60
59
  resolve[key] = config[key] || {};
61
60
  });
62
61
  }
63
- async function getServerPort(config, contextCommand) {
62
+ async function getServerPort(config) {
64
63
  const prodPort = Number(process.env.PORT) || config.server.port || 8080;
65
- const isProgrammaticDev = 'dev' === contextCommand || 'start' === contextCommand;
66
- if (isDev() && (isDevCommand() || isProgrammaticDev)) return getPort(Number(process.env.PORT) || prodPort);
64
+ if (isDev() && isDevCommand()) return getPort(Number(process.env.PORT) || prodPort);
67
65
  return prodPort;
68
66
  }
69
67
  export default initialize;