@ecopages/core 0.6.1 → 0.7.1

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 (350) hide show
  1. package/README.md +8 -143
  2. package/package.json +16 -3
  3. package/src/adapters/node/dev-session.js +2 -1
  4. package/src/adapters/node/node-client-bridge.d.ts +5 -7
  5. package/src/adapters/node/node-client-bridge.js +4 -14
  6. package/src/adapters/node/server-adapter.d.ts +4 -2
  7. package/src/adapters/node/server-adapter.js +13 -12
  8. package/src/adapters/shared/hmr/client-bridge.d.ts +25 -0
  9. package/src/adapters/shared/hmr/client-bridge.js +35 -0
  10. package/src/adapters/shared/hmr/dev-transform-entrypoint-registry.js +1 -1
  11. package/src/adapters/shared/hmr/hmr-manager.d.ts +9 -2
  12. package/src/adapters/shared/hmr/hmr-manager.js +36 -6
  13. package/src/adapters/shared/http/dist-file-handler.js +3 -7
  14. package/src/adapters/shared/http/response-headers.d.ts +29 -0
  15. package/src/adapters/shared/http/response-headers.js +89 -0
  16. package/src/adapters/shared/runtime/copy-runtime-public-dir.js +1 -1
  17. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +3 -2
  18. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +4 -3
  19. package/src/adapters/shared/runtime/server-request-pipeline.js +4 -4
  20. package/src/adapters/shared/runtime/server-static-builder.d.ts +19 -8
  21. package/src/adapters/shared/runtime/server-static-builder.js +23 -4
  22. package/src/adapters/shared/ws/node-http-websocket-upgrades.d.ts +1 -1
  23. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +23 -16
  24. package/src/assets/app-browser-client-build.d.ts +5 -12
  25. package/src/assets/app-browser-client-build.js +121 -336
  26. package/src/assets/asset-processing-service/app-browser-client-bundle.d.ts +4 -0
  27. package/src/assets/asset-processing-service/app-browser-client-bundle.js +6 -0
  28. package/src/assets/asset-processing-service/asset-dependency-keys.d.ts +28 -8
  29. package/src/assets/asset-processing-service/asset-dependency-keys.js +104 -29
  30. package/src/assets/asset-processing-service/asset-processing.service.d.ts +60 -2
  31. package/src/assets/asset-processing-service/asset-processing.service.js +189 -58
  32. package/src/assets/asset-processing-service/bundleable-script.d.ts +3 -0
  33. package/src/assets/asset-processing-service/bundleable-script.js +4 -0
  34. package/src/assets/asset-processing-service/grouped-content-bundles.d.ts +2 -2
  35. package/src/assets/asset-processing-service/grouped-content-bundles.js +5 -10
  36. package/src/assets/asset-processing-service/index.d.ts +0 -3
  37. package/src/assets/asset-processing-service/index.js +0 -3
  38. package/src/assets/asset-processing-service/last-good-output.d.ts +21 -0
  39. package/src/assets/asset-processing-service/last-good-output.js +32 -0
  40. package/src/assets/asset-processing-service/page-package.js +1 -4
  41. package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +63 -0
  42. package/src/assets/asset-processing-service/processed-asset-ledger.js +101 -0
  43. package/src/assets/asset-processing-service/processors/base/base-processor.js +1 -1
  44. package/src/assets/asset-processing-service/processors/base/base-script-processor.js +1 -1
  45. package/src/assets/asset-processing-service/processors/script/content-script.processor.d.ts +24 -0
  46. package/src/assets/asset-processing-service/processors/script/content-script.processor.js +59 -4
  47. package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +8 -4
  48. package/src/assets/asset-processing-service/processors/script/file-script.processor.js +18 -6
  49. package/src/assets/asset-processing-service/processors/script/node-module-script.processor.js +2 -3
  50. package/src/assets/asset-processing-service/processors/stylesheet/app-stylesheet-imports.d.ts +34 -0
  51. package/src/assets/asset-processing-service/processors/stylesheet/app-stylesheet-imports.js +115 -0
  52. package/src/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +2 -2
  53. package/src/assets/asset-processing-service/processors/stylesheet/css-module-types.d.ts +39 -0
  54. package/src/assets/asset-processing-service/processors/stylesheet/css-module-types.js +150 -0
  55. package/src/assets/asset-processing-service/processors/stylesheet/css-scanner.d.ts +84 -0
  56. package/src/assets/asset-processing-service/processors/stylesheet/css-scanner.js +379 -0
  57. package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +16 -0
  58. package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +50 -24
  59. package/src/assets/asset-processing-service/processors/stylesheet/import-order.d.ts +33 -0
  60. package/src/assets/asset-processing-service/processors/stylesheet/import-order.js +67 -0
  61. package/src/assets/asset-processing-service/processors/stylesheet/package-stylesheet.d.ts +44 -0
  62. package/src/assets/asset-processing-service/processors/stylesheet/package-stylesheet.js +149 -0
  63. package/src/assets/asset-processing-service/processors/stylesheet/processed-stylesheet-cache.d.ts +31 -0
  64. package/src/assets/asset-processing-service/processors/stylesheet/processed-stylesheet-cache.js +59 -0
  65. package/src/assets/asset-processing-service/processors/stylesheet/source-relative-stylesheet.d.ts +20 -0
  66. package/src/assets/asset-processing-service/processors/stylesheet/source-relative-stylesheet.js +51 -0
  67. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-failure.d.ts +2 -0
  68. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-failure.js +5 -0
  69. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-module.d.ts +37 -0
  70. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-module.js +48 -0
  71. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.d.ts +25 -1
  72. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.js +56 -15
  73. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-warnings.d.ts +9 -0
  74. package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-warnings.js +21 -0
  75. package/src/assets/browser-asset-output.js +1 -1
  76. package/src/assets/hashed-browser-asset.js +1 -1
  77. package/src/assets/{browser-runtime-asset-page-cache.d.ts → page-script-page-cache.d.ts} +3 -3
  78. package/src/assets/{browser-runtime-asset-page-cache.js → page-script-page-cache.js} +3 -3
  79. package/src/build/app-build-manifest-runtime.d.ts +23 -11
  80. package/src/build/app-build-manifest-runtime.js +52 -13
  81. package/src/build/browser/jsx-ownership-plugins.d.ts +4 -1
  82. package/src/build/browser/jsx-ownership-plugins.js +6 -0
  83. package/src/build/build-adapter.d.ts +1 -1
  84. package/src/build/build-adapter.js +1 -1
  85. package/src/build/build-graph.d.ts +4 -2
  86. package/src/build/build-graph.js +12 -46
  87. package/src/build/cache/build-input-dependency-index.d.ts +0 -19
  88. package/src/build/cache/build-input-dependency-index.js +1 -34
  89. package/src/build/cache/pages-unified-graph-build.js +7 -43
  90. package/src/build/cache/server-module-entries.d.ts +1 -1
  91. package/src/build/cache/server-module-entries.js +9 -9
  92. package/src/build/contracts/build-contracts.d.ts +59 -12
  93. package/src/build/contracts/build-manifest.d.ts +3 -6
  94. package/src/build/contracts/build-manifest.js +2 -12
  95. package/src/build/contracts/content-virtual-modules.js +1 -3
  96. package/src/build/copy-server-files.js +1 -1
  97. package/src/build/preserve-import-meta-transform.d.ts +3 -1
  98. package/src/build/preserve-import-meta-transform.js +7 -4
  99. package/src/build/production-asset-ledger.d.ts +36 -0
  100. package/src/build/production-asset-ledger.js +104 -0
  101. package/src/build/production-dist-complete.js +12 -13
  102. package/src/build/production-route-list.js +1 -1
  103. package/src/build/rolldown/app-package-declarations.js +1 -1
  104. package/src/build/rolldown/entry-module-closures.d.ts +5 -1
  105. package/src/build/rolldown/entry-module-closures.js +21 -8
  106. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +19 -8
  107. package/src/build/rolldown/rolldown-adapter-helpers.js +82 -45
  108. package/src/build/rolldown/rolldown-build-adapter.js +10 -13
  109. package/src/build/rolldown/rolldown-module-id.d.ts +18 -0
  110. package/src/build/rolldown/rolldown-module-id.js +29 -0
  111. package/src/build/rolldown/rolldown-plugin-bridge.d.ts +24 -60
  112. package/src/build/rolldown/rolldown-plugin-bridge.js +201 -373
  113. package/src/build/rolldown/stylesheet-module-plugin.d.ts +34 -0
  114. package/src/build/rolldown/stylesheet-module-plugin.js +160 -0
  115. package/src/build/rolldown/worker-entries-plugin.d.ts +13 -0
  116. package/src/build/rolldown/worker-entries-plugin.js +57 -0
  117. package/src/build/runtime/build-environment-options.js +13 -3
  118. package/src/build/runtime/build-request-identity.js +1 -1
  119. package/src/build/runtime/build-request-policy.d.ts +7 -12
  120. package/src/build/runtime/build-request-policy.js +63 -17
  121. package/src/build/server/imported-view-plugin.d.ts +1 -0
  122. package/src/build/server/imported-view-plugin.js +6 -4
  123. package/src/build/server/page-module-import.service.d.ts +1 -2
  124. package/src/build/server/page-module-import.service.js +4 -6
  125. package/src/build/server/resolve-static-view.js +3 -2
  126. package/src/build/server/route-module-build-cache-registry.js +1 -1
  127. package/src/build/server/route-module-build-cache.store.js +1 -1
  128. package/src/build/server/route-module-build-manifest.js +1 -1
  129. package/src/build/server/route-module-dependency-hasher.d.ts +1 -1
  130. package/src/build/server/route-module-dependency-hasher.js +2 -2
  131. package/src/build/server/server-modules-manifest.d.ts +3 -5
  132. package/src/build/server/server-modules-manifest.js +6 -21
  133. package/src/build/server/view-module.d.ts +12 -0
  134. package/src/build/server/view-module.js +23 -0
  135. package/src/build/server/view-reference.d.ts +16 -5
  136. package/src/build/server/view-reference.js +25 -14
  137. package/src/build/server-bundle-deploy-manifest.d.ts +1 -1
  138. package/src/build/server-bundle-deploy-manifest.js +2 -2
  139. package/src/build/server-bundle-publication.d.ts +7 -1
  140. package/src/build/server-bundle-publication.js +11 -4
  141. package/src/build/server-module.js +1 -1
  142. package/src/build/worker-urls.d.ts +60 -0
  143. package/src/build/worker-urls.js +197 -0
  144. package/src/build.d.ts +7 -5
  145. package/src/build.js +7 -5
  146. package/src/cache/module-parse-cache.js +2 -2
  147. package/src/client/navigation-attributes.d.ts +8 -0
  148. package/src/client/navigation-attributes.js +8 -0
  149. package/src/client/navigation-scripts/global-scripts.d.ts +14 -0
  150. package/src/client/navigation-scripts/global-scripts.js +65 -0
  151. package/src/client/navigation-scripts/index.d.ts +1 -0
  152. package/src/client/navigation-scripts/index.js +1 -0
  153. package/src/client.d.ts +2 -2
  154. package/src/client.js +2 -2
  155. package/src/config/assembly/app-runtime.d.ts +45 -5
  156. package/src/config/assembly/app-runtime.js +11 -2
  157. package/src/config/assembly/finalize-config.js +13 -5
  158. package/src/config/config-module-files.js +10 -6
  159. package/src/config/index.d.ts +2 -1
  160. package/src/config/internal-types.d.ts +3 -0
  161. package/src/config/load-eco-config.js +8 -5
  162. package/src/config/resolve-eco-config-path.js +3 -3
  163. package/src/config/server-config-bundle.js +1 -1
  164. package/src/config/user-config-types.d.ts +54 -1
  165. package/src/config/write-types.js +4 -1
  166. package/src/css-imports.d.ts +12 -0
  167. package/src/declarations.d.ts +2 -0
  168. package/src/dev/development-restart-watch-paths.js +1 -1
  169. package/src/dev/development-restart.js +1 -1
  170. package/src/dev/invalidation/development-invalidation.service.d.ts +6 -1
  171. package/src/dev/invalidation/development-invalidation.service.js +18 -2
  172. package/src/dev/stylesheets/development-stylesheet.service.d.ts +149 -0
  173. package/src/dev/stylesheets/development-stylesheet.service.js +350 -0
  174. package/src/dev/transform-server/dev-transform-bundler.d.ts +12 -3
  175. package/src/dev/transform-server/dev-transform-bundler.js +32 -21
  176. package/src/dev/transform-server/dev-transform-externalize-plugin.d.ts +3 -5
  177. package/src/dev/transform-server/dev-transform-externalize-plugin.js +8 -9
  178. package/src/dev/transform-server/dev-transform-import-rewriter.d.ts +15 -2
  179. package/src/dev/transform-server/dev-transform-import-rewriter.js +204 -35
  180. package/src/dev/transform-server/dev-transform-install-stamp.d.ts +17 -0
  181. package/src/dev/transform-server/dev-transform-install-stamp.js +79 -0
  182. package/src/dev/transform-server/dev-transform-server.d.ts +38 -2
  183. package/src/dev/transform-server/dev-transform-server.js +96 -33
  184. package/src/dev/transform-server/dev-transform-url.d.ts +4 -2
  185. package/src/dev/transform-server/dev-transform-url.js +13 -12
  186. package/src/dev/transform-server/dev-transform-vendor-registry.d.ts +178 -21
  187. package/src/dev/transform-server/dev-transform-vendor-registry.js +675 -99
  188. package/src/dev/transform-server/index.d.ts +1 -1
  189. package/src/dev-toolbar/dev-toolbar-package.js +4 -4
  190. package/src/eco/component-render-output.d.ts +6 -1
  191. package/src/eco/component-render-output.js +32 -7
  192. package/src/eco/discovered-dependencies.d.ts +30 -11
  193. package/src/eco/discovered-dependencies.js +25 -13
  194. package/src/eco/discovered-dependency-paths.d.ts +36 -0
  195. package/src/eco/discovered-dependency-paths.js +58 -0
  196. package/src/eco/eco.browser.js +8 -12
  197. package/src/eco/eco.js +0 -30
  198. package/src/eco/mdx-page-metadata.d.ts +14 -0
  199. package/src/eco/mdx-page-metadata.js +15 -0
  200. package/src/eco/page-layout-normalization.d.ts +6 -2
  201. package/src/eco/page-layout-normalization.js +9 -6
  202. package/src/env.js +17 -0
  203. package/src/hmr/client/hmr-runtime.js +14 -13
  204. package/src/hmr/dev-client-runtime.d.ts +5 -2
  205. package/src/hmr/dev-client-runtime.js +14 -4
  206. package/src/hmr/hmr-entrypoint-output.js +1 -1
  207. package/src/hmr/hmr-strategy.d.ts +2 -2
  208. package/src/hmr/hmr-strategy.js +2 -2
  209. package/src/hmr/strategies/js-hmr-strategy.d.ts +4 -1
  210. package/src/hmr/strategies/js-hmr-strategy.js +7 -6
  211. package/src/hmr/strategies/template-source-hmr-strategy.d.ts +25 -0
  212. package/src/hmr/strategies/template-source-hmr-strategy.js +36 -0
  213. package/src/html-pages/html-page-module-scripts.d.ts +2 -1
  214. package/src/html-pages/html-page-module-scripts.js +37 -14
  215. package/src/html-pages/html-page-module.js +1 -1
  216. package/src/html-pages/html-page-renderer.js +7 -6
  217. package/src/html-pages/html-page-template.d.ts +0 -5
  218. package/src/html-pages/html-page-template.js +3 -15
  219. package/src/html-pages/html-pages.plugin.js +2 -2
  220. package/src/integration.d.ts +8 -6
  221. package/src/integration.js +5 -3
  222. package/src/page-cache/html-page-cache-dependency-index.js +1 -1
  223. package/src/page-cache/page-cache-service.js +1 -1
  224. package/src/plugins/alias-resolver-plugin.d.ts +7 -0
  225. package/src/plugins/alias-resolver-plugin.js +16 -6
  226. package/src/plugins/component-import-discovery.d.ts +178 -7
  227. package/src/plugins/component-import-discovery.js +696 -112
  228. package/src/plugins/eco-component-meta-plugin.d.ts +47 -6
  229. package/src/plugins/eco-component-meta-plugin.js +227 -59
  230. package/src/plugins/foreign-jsx-override-plugin.d.ts +14 -1
  231. package/src/plugins/foreign-jsx-override-plugin.js +18 -8
  232. package/src/plugins/integration-plugin.d.ts +47 -11
  233. package/src/plugins/integration-plugin.js +57 -8
  234. package/src/plugins/processor.d.ts +72 -7
  235. package/src/plugins/processor.js +44 -9
  236. package/src/plugins/stylesheet-kinds.d.ts +57 -0
  237. package/src/plugins/stylesheet-kinds.js +114 -0
  238. package/src/plugins/tsconfig-import-resolver.d.ts +49 -3
  239. package/src/plugins/tsconfig-import-resolver.js +120 -6
  240. package/src/processor-contract.d.ts +66 -0
  241. package/src/processor-contract.js +389 -0
  242. package/src/processor.d.ts +6 -1
  243. package/src/processor.js +6 -1
  244. package/src/route-renderer/error-pages/default-error-pages.d.ts +1 -0
  245. package/src/route-renderer/error-pages/default-error-pages.js +27 -7
  246. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +8 -0
  247. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +12 -0
  248. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +77 -24
  249. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +97 -32
  250. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +1 -1
  251. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +9 -0
  252. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +16 -2
  253. package/src/route-renderer/orchestration/document-shell/layout-children-not-rendered-error.d.ts +35 -0
  254. package/src/route-renderer/orchestration/document-shell/layout-children-not-rendered-error.js +53 -0
  255. package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +4 -8
  256. package/src/route-renderer/orchestration/foreign-child/render-session.js +2 -5
  257. package/src/route-renderer/orchestration/integration-renderer.d.ts +171 -64
  258. package/src/route-renderer/orchestration/integration-renderer.js +293 -332
  259. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +8 -5
  260. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +27 -25
  261. package/src/route-renderer/orchestration/ownership-graph/component-graph.d.ts +0 -6
  262. package/src/route-renderer/orchestration/page-browser-graph/global-injector-assets.service.js +3 -3
  263. package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.d.ts +12 -25
  264. package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.js +1 -14
  265. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +0 -16
  266. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +1 -87
  267. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +8 -16
  268. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +25 -271
  269. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +0 -24
  270. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +0 -67
  271. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +28 -15
  272. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +63 -41
  273. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -1
  274. package/src/route-renderer/page-loading/component-dependency-collection.js +51 -15
  275. package/src/route-renderer/page-loading/dependency-resolver.d.ts +10 -0
  276. package/src/route-renderer/page-loading/dependency-resolver.js +27 -6
  277. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +4 -2
  278. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +22 -17
  279. package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +5 -0
  280. package/src/route-renderer/page-loading/lazy-entry-collection.js +6 -4
  281. package/src/route-renderer/page-loading/page-dependency-bundling.d.ts +5 -2
  282. package/src/route-renderer/page-loading/page-dependency-bundling.js +15 -31
  283. package/src/route-renderer/page-loading/page-module-loader.d.ts +13 -2
  284. package/src/route-renderer/page-loading/page-module-loader.js +23 -5
  285. package/src/route-renderer/route-renderer.d.ts +1 -1
  286. package/src/router/client/navigation-commit.d.ts +2 -0
  287. package/src/router/client/navigation-commit.js +4 -1
  288. package/src/router/client/navigation-coordinator.d.ts +18 -0
  289. package/src/router/client/navigation-coordinator.js +14 -0
  290. package/src/router/client/navigation-lifecycle.d.ts +18 -1
  291. package/src/router/client/navigation-lifecycle.js +6 -3
  292. package/src/router/client/navigation-pipeline.d.ts +1 -0
  293. package/src/router/client/navigation-pipeline.js +1 -0
  294. package/src/router/server/route-registry.d.ts +3 -2
  295. package/src/router/server/route-registry.js +6 -5
  296. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +30 -18
  297. package/src/static-site-generator/production-page-browser-graph-prebuild.js +82 -143
  298. package/src/static-site-generator/static-site-generator.d.ts +37 -4
  299. package/src/static-site-generator/static-site-generator.js +99 -51
  300. package/src/types/asset-types.d.ts +19 -1
  301. package/src/types/build-types.d.ts +53 -35
  302. package/src/types/component-identity.d.ts +8 -0
  303. package/src/types/contracts.d.ts +69 -21
  304. package/src/types/dev-transform-types.d.ts +33 -6
  305. package/src/types/eco-api-types.d.ts +13 -18
  306. package/src/types/integration-types.d.ts +1 -1
  307. package/src/types/public-types.d.ts +1 -1
  308. package/src/utils/additional-watch-paths.js +3 -5
  309. package/src/utils/entry-command-flags.d.ts +23 -0
  310. package/src/utils/entry-command-flags.js +24 -0
  311. package/src/utils/package-path.d.ts +42 -0
  312. package/src/utils/package-path.js +114 -0
  313. package/src/utils/parse-cli-args.d.ts +18 -1
  314. package/src/utils/parse-cli-args.js +54 -37
  315. package/src/utils/path-containment.js +3 -10
  316. package/src/utils/resolve-work-dir.js +2 -2
  317. package/src/utils/root-relative-path.js +2 -2
  318. package/src/utils/server-bundle-context.d.ts +5 -0
  319. package/src/utils/server-bundle-context.js +7 -1
  320. package/src/utils/server-utils.module.js +1 -1
  321. package/src/watchers/project-watcher-ignore.js +3 -3
  322. package/src/watchers/project-watcher.d.ts +14 -2
  323. package/src/watchers/project-watcher.js +37 -6
  324. package/src/watchers/workspace-package-watch-roots.js +2 -2
  325. package/src/assets/app-browser-client-manifest.d.ts +0 -66
  326. package/src/assets/app-browser-client-manifest.js +0 -260
  327. package/src/assets/asset-processing-service/asset-package-role.d.ts +0 -2
  328. package/src/assets/asset-processing-service/asset-package-role.js +0 -3
  329. package/src/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +0 -58
  330. package/src/assets/asset-processing-service/browser-runtime-asset.factory.js +0 -61
  331. package/src/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +0 -79
  332. package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +0 -200
  333. package/src/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +0 -24
  334. package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +0 -67
  335. package/src/build/browser/browser-runtime-manifest.d.ts +0 -35
  336. package/src/build/browser/browser-runtime-manifest.js +0 -65
  337. package/src/build/browser/browser-runtime-plugin-helpers.d.ts +0 -14
  338. package/src/build/browser/browser-runtime-plugin-helpers.js +0 -21
  339. package/src/build/browser/browser-runtime-plugin.d.ts +0 -54
  340. package/src/build/browser/browser-runtime-plugin.js +0 -76
  341. package/src/build/rolldown/server-side-css-shim-plugin.d.ts +0 -28
  342. package/src/build/rolldown/server-side-css-shim-plugin.js +0 -59
  343. package/src/dev/transform-server/dev-transform-module-kind.d.ts +0 -13
  344. package/src/dev/transform-server/dev-transform-module-kind.js +0 -17
  345. package/src/dev/transform-server/dev-transform-runtime-specifiers.d.ts +0 -5
  346. package/src/dev/transform-server/dev-transform-runtime-specifiers.js +0 -16
  347. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +0 -15
  348. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +0 -65
  349. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +0 -21
  350. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +0 -31
@@ -1,14 +1,16 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { getServerModuleBuildCacheOutdir } from '../../../build/server/route-module-build-cache-registry.js';
3
- import { fileURLToPath } from 'node:url';
4
3
  import { HMR_RUNTIME_SCRIPT_URL, resolveHmrRuntimeWorkDir } from '../../../hmr/hmr-runtime-paths.js';
5
4
  import { bundleDevClientRuntime, injectDevClientRuntimes, readDevClientRuntime, } from '../../../hmr/dev-client-runtime.js';
6
5
  import { isDevToolbarEnabled } from '../../../dev-toolbar/dev-toolbar-config.js';
7
6
  import { createDevToolbarClientRuntime } from '../../../dev-toolbar/dev-toolbar-runtime.js';
8
7
  import { isRegisteredDevTransformEntrypoint } from '../../../hmr/hmr-entrypoint-output.js';
8
+ import { getDevelopmentStylesheetService } from '../../../dev/stylesheets/development-stylesheet.service.js';
9
+ import { clearFailedCustomElementScriptPreloads } from '../../../route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js';
9
10
  import { fileSystem } from '@ecopages/file-system';
10
11
  import { HmrStrategyType } from '../../../hmr/hmr-strategy.js';
11
12
  import { DefaultHmrStrategy } from '../../../hmr/strategies/default-hmr-strategy.js';
13
+ import { TemplateSourceHmrStrategy } from '../../../hmr/strategies/template-source-hmr-strategy.js';
12
14
  import { JsHmrStrategy } from '../../../hmr/strategies/js-hmr-strategy.js';
13
15
  import { ServerRenderedTemplateHmrStrategy } from '../../../hmr/strategies/server-rendered-template-hmr-strategy.js';
14
16
  import { getDevelopmentInvalidationService, } from '../../../dev/invalidation/development-invalidation.service.js';
@@ -18,6 +20,7 @@ import { BrowserBundleService } from '../../../assets/browser-bundle.service.js'
18
20
  import { requireAppRuntime } from '../../../utils/app-runtime.js';
19
21
  import { resolveInternalWorkDir } from '../../../utils/resolve-work-dir.js';
20
22
  import { DevTransformServer } from '../../../dev/transform-server/dev-transform-server.js';
23
+ import { getStylesheetKinds } from '../../../plugins/stylesheet-kinds.js';
21
24
  export class HmrManager {
22
25
  appConfig;
23
26
  bridge;
@@ -40,6 +43,8 @@ export class HmrManager {
40
43
  * request the way a dev-transform failure is.
41
44
  */
42
45
  fileChangeErrors = new Map();
46
+ /** Build errors found while answering a request, by the file that failed, until the next file change. */
47
+ requestBuildErrors = new Map();
43
48
  entrypointRegistry;
44
49
  browserBundleService;
45
50
  invalidationService;
@@ -52,6 +57,7 @@ export class HmrManager {
52
57
  runtimeBuilds = new Map();
53
58
  readyRuntimes = new Set();
54
59
  devTransformServer;
60
+ stylesheetKinds;
55
61
  constructor({ appConfig, bridge }) {
56
62
  this.appConfig = appConfig;
57
63
  this.bridge = bridge;
@@ -60,7 +66,7 @@ export class HmrManager {
60
66
  name: 'HMR',
61
67
  url: HMR_RUNTIME_SCRIPT_URL,
62
68
  workDir: this.runtimeWorkDir,
63
- resolveEntry: () => fileURLToPath(import.meta.resolve('@ecopages/core/hmr/client/hmr-runtime')),
69
+ resolveEntry: () => path.fromFileUrl(import.meta.resolve('@ecopages/core/hmr/client/hmr-runtime')),
64
70
  onFailure: (error) => this.onRuntimeBundleFailure(error),
65
71
  };
66
72
  this.devToolbarRuntime = createDevToolbarClientRuntime(appConfig);
@@ -80,6 +86,7 @@ export class HmrManager {
80
86
  ]);
81
87
  },
82
88
  onTransformError: (message) => this.broadcast({ type: 'error', message }),
89
+ onVendorGraphChange: () => this.broadcast({ type: 'reload' }),
83
90
  });
84
91
  this.ensureRuntimeWorkDir();
85
92
  this.initializeStrategies();
@@ -132,6 +139,7 @@ export class HmrManager {
132
139
  getPagesDir: () => this.appConfig.absolutePaths.pagesDir,
133
140
  getLayoutsDir: () => this.appConfig.absolutePaths.layoutsDir,
134
141
  getTemplateExtensions: () => this.appConfig.templatesExt,
142
+ isStylesheet: (filePath) => (this.stylesheetKinds ??= getStylesheetKinds(this.appConfig)).isStylesheet(filePath),
135
143
  getEntrypointDependencyGraph: () => this.entrypointDependencyGraph,
136
144
  shouldProcessEntrypoint: (entrypointPath) => this.shouldJsStrategyProcessEntrypoint(entrypointPath),
137
145
  consumeRegisteredScriptReloadRequired: (sourcePath) => this.consumeRegisteredScriptReloadRequired(sourcePath),
@@ -139,6 +147,7 @@ export class HmrManager {
139
147
  this.strategies = [
140
148
  new JsHmrStrategy(jsContext),
141
149
  new ServerRenderedTemplateHmrStrategy(this.invalidationService),
150
+ new TemplateSourceHmrStrategy(this.invalidationService, jsContext),
142
151
  ];
143
152
  }
144
153
  registerStrategy(strategy) {
@@ -195,11 +204,17 @@ export class HmrManager {
195
204
  appLogger.debug(`[HMR] Broadcasting ${event.type} event, path=${event.path || 'all'}, subscribers=${this.bridge.subscriberCount}`);
196
205
  this.bridge.broadcast(event);
197
206
  }
207
+ reportBuildError(source, message) {
208
+ this.requestBuildErrors.set(path.resolve(source), message);
209
+ this.broadcast({ type: 'error', message });
210
+ }
198
211
  async handleFileChanges(filePaths, options = {}) {
199
212
  if (filePaths.length === 0) {
200
213
  return;
201
214
  }
202
215
  this.devTransformServer.clearFailures();
216
+ this.requestBuildErrors.clear();
217
+ clearFailedCustomElementScriptPreloads(requireAppRuntime(this.appConfig).customElementSsrPreloadScopes);
203
218
  const events = [];
204
219
  const uniqueFilePaths = [...new Set(filePaths.map((candidate) => path.resolve(candidate)))];
205
220
  for (const filePath of uniqueFilePaths) {
@@ -214,8 +229,14 @@ export class HmrManager {
214
229
  events.push({ type: 'error', message });
215
230
  }
216
231
  }
232
+ for (const message of this.stylesheetFailures())
233
+ events.push({ type: 'error', message });
217
234
  this.broadcastBatchEvents(events, options, uniqueFilePaths);
218
235
  }
236
+ /** The errors of the stylesheets that fail to process, which the development stylesheet service keeps. */
237
+ stylesheetFailures() {
238
+ return getDevelopmentStylesheetService(this.appConfig).failureMessages();
239
+ }
219
240
  async processFileChange(filePath) {
220
241
  const resolvedFilePath = path.resolve(filePath);
221
242
  const isRegisteredDevTransformEdit = isRegisteredDevTransformEntrypoint(this.entrypointRegistry.getRegisteredEntrypoints(), resolvedFilePath);
@@ -318,8 +339,8 @@ export class HmrManager {
318
339
  return this.entrypointRegistry.getRegisteredEntrypoints();
319
340
  }
320
341
  /**
321
- * Sends a browser that just connected the build errors of modules that still fail to transpile, and of
322
- * changed files whose last processing failed.
342
+ * Sends a browser that just connected the build errors of modules that still fail to transpile, of
343
+ * changed files whose last processing failed, and of assets a request failed to build.
323
344
  *
324
345
  * @remarks
325
346
  * A build error is broadcast while the failing module is served, which can happen before the page's HMR
@@ -327,7 +348,12 @@ export class HmrManager {
327
348
  * it. Without this replay that browser would never show the error.
328
349
  */
329
350
  sendPendingBuildErrors(client) {
330
- for (const message of [...this.devTransformServer.getFailureMessages(), ...this.fileChangeErrors.values()]) {
351
+ for (const message of [
352
+ ...this.devTransformServer.getFailureMessages(),
353
+ ...this.fileChangeErrors.values(),
354
+ ...this.requestBuildErrors.values(),
355
+ ...this.stylesheetFailures(),
356
+ ]) {
331
357
  client.send(JSON.stringify({ type: 'error', message }));
332
358
  }
333
359
  }
@@ -360,6 +386,7 @@ export class HmrManager {
360
386
  this.scriptEntrypointChangeHandlers.length = 0;
361
387
  this.registeredScriptReloadRequired.clear();
362
388
  this.fileChangeErrors.clear();
389
+ this.requestBuildErrors.clear();
363
390
  this.entrypointRegistry.clearAll();
364
391
  this.devTransformServer.reset();
365
392
  this.buildInputIndex.clearConsumer('entrypoint');
@@ -374,6 +401,9 @@ export class HmrManager {
374
401
  async registerEntrypoint(entrypointPath) {
375
402
  return this.registerDevTransformEntrypoint(entrypointPath, 'page').outputUrl;
376
403
  }
404
+ rewriteModuleImports(code, importerPath) {
405
+ return this.devTransformServer.rewriteImports(code, importerPath);
406
+ }
377
407
  async registerScriptEntrypoint(entrypointPath) {
378
408
  const { normalized, outputUrl, role } = this.registerDevTransformEntrypoint(entrypointPath, 'script');
379
409
  return {
@@ -1,7 +1,7 @@
1
1
  import { STATUS_MESSAGE } from '../../../constants.js';
2
2
  import { appLogger } from '../../../global/app-logger.js';
3
3
  import { fileSystem } from '@ecopages/file-system';
4
- import path from 'node:path';
4
+ import { path } from '@ecopages/file-system/path';
5
5
  import { HASHED_BROWSER_ASSET_INDEX_FILENAME, hashBrowserAssetBytes, isHashedBrowserAsset, } from '../../../assets/hashed-browser-asset.js';
6
6
  import { ServerUtils } from '../../../utils/server-utils.module.js';
7
7
  /**
@@ -44,7 +44,7 @@ function resolveRequestTarget(request, distDir) {
44
44
  }
45
45
  const relativePath = pathname === '/' ? 'index.html' : pathname.replace(/^\/+/, '');
46
46
  const requestedPath = path.resolve(distDir, relativePath);
47
- return isPathInside(distDir, requestedPath) ? { pathname, requestedPath } : undefined;
47
+ return path.isWithin(distDir, requestedPath) ? { pathname, requestedPath } : undefined;
48
48
  }
49
49
  /**
50
50
  * Resolves a requested file only when its real path remains inside the served directory.
@@ -71,10 +71,6 @@ async function createNotFoundResponse(request, options, distDir, method) {
71
71
  : await createDistNotFoundResponse(request, distDir);
72
72
  return method === 'HEAD' ? responseWithoutBody(response) : response;
73
73
  }
74
- function isPathInside(root, candidate) {
75
- const relativePath = path.relative(root, candidate);
76
- return relativePath !== '..' && !relativePath.startsWith(`..${path.sep}`) && !path.isAbsolute(relativePath);
77
- }
78
74
  function createBadRequestResponse(method) {
79
75
  return new Response(method === 'HEAD' ? null : 'Invalid path', {
80
76
  status: 400,
@@ -99,7 +95,7 @@ async function createDistNotFoundResponse(request, distDir) {
99
95
  }
100
96
  function isRealPathInside(root, candidate) {
101
97
  try {
102
- return isPathInside(fileSystem.realpath(root), fileSystem.realpath(candidate));
98
+ return path.isWithin(fileSystem.realpath(root), fileSystem.realpath(candidate));
103
99
  }
104
100
  catch {
105
101
  return false;
@@ -0,0 +1,29 @@
1
+ import type { ResponseHeaderRule } from '../../../config/user-config-types.js';
2
+ /**
3
+ * Checks the `headers` option of `eco.config.ts`.
4
+ *
5
+ * @remarks
6
+ * A `source` is a URL pathname pattern: it starts with `/`, `*` matches any characters except `/` and `**`
7
+ * matches any characters including `/`. Other pattern syntax is rejected instead of being read as literal text.
8
+ *
9
+ * @throws When a rule has no usable `source` pattern, or a header has an invalid name or value.
10
+ */
11
+ export declare function assertResponseHeaderRules(rules: unknown): asserts rules is readonly ResponseHeaderRule[];
12
+ /**
13
+ * Tests a URL pathname against a `source` pattern of the `headers` option.
14
+ *
15
+ * @remarks
16
+ * The pattern must match the whole pathname. `**` followed by `/` also matches no segment, so `/**\/*.wasm`
17
+ * matches `/a.wasm` as well as `/a/b.wasm`. The pathname is matched as the request sends it, percent-encoding included.
18
+ */
19
+ export declare function matchesResponseHeaderSource(source: string, pathname: string): boolean;
20
+ /**
21
+ * Adds the configured headers whose `source` matches the request path to a response.
22
+ *
23
+ * @remarks
24
+ * Rules apply in config order, so a later rule wins over an earlier one. A configured header replaces a header
25
+ * of the same name the framework or a handler already set, which is how an app overrides one deliberately; every
26
+ * other header stays. A response no rule matches is returned as it is. Otherwise the result is a new
27
+ * `Response` over the same body, because a handler may return a response whose headers are immutable.
28
+ */
29
+ export declare function applyResponseHeaders(response: Response, request: Request, rules: readonly ResponseHeaderRule[] | undefined): Response;
@@ -0,0 +1,89 @@
1
+ const HEADER_NAME = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
2
+ const FORBIDDEN_VALUE = /[\r\n\0]/;
3
+ const FORBIDDEN_SOURCE = /[?#\s]|[[\](){}!+@|\\]/;
4
+ /**
5
+ * Checks the `headers` option of `eco.config.ts`.
6
+ *
7
+ * @remarks
8
+ * A `source` is a URL pathname pattern: it starts with `/`, `*` matches any characters except `/` and `**`
9
+ * matches any characters including `/`. Other pattern syntax is rejected instead of being read as literal text.
10
+ *
11
+ * @throws When a rule has no usable `source` pattern, or a header has an invalid name or value.
12
+ */
13
+ export function assertResponseHeaderRules(rules) {
14
+ if (!Array.isArray(rules)) {
15
+ throw new Error('Invalid "headers" option: expected an array of { source, headers } rules.');
16
+ }
17
+ rules.forEach((rule, index) => {
18
+ const where = `Invalid "headers" option at index ${index}`;
19
+ if (typeof rule !== 'object' || rule === null) {
20
+ throw new Error(`${where}: expected an object with "source" and "headers".`);
21
+ }
22
+ const { source, headers } = rule;
23
+ if (typeof source !== 'string' || !source.startsWith('/')) {
24
+ throw new Error(`${where}: "source" must be a path pattern starting with "/", such as "/**" or "/assets/*".`);
25
+ }
26
+ if (FORBIDDEN_SOURCE.test(source)) {
27
+ throw new Error(`${where}: "source" ${JSON.stringify(source)} uses unsupported pattern syntax. Only "*" and "**" are supported.`);
28
+ }
29
+ if (typeof headers !== 'object' || headers === null || Array.isArray(headers)) {
30
+ throw new Error(`${where}: "headers" must be an object of header names to string values.`);
31
+ }
32
+ for (const [name, value] of Object.entries(headers)) {
33
+ if (!HEADER_NAME.test(name)) {
34
+ throw new Error(`${where}: ${JSON.stringify(name)} is not a valid header name.`);
35
+ }
36
+ if (typeof value !== 'string' || FORBIDDEN_VALUE.test(value)) {
37
+ throw new Error(`${where}: the value of "${name}" must be a string without line breaks.`);
38
+ }
39
+ }
40
+ });
41
+ }
42
+ /**
43
+ * Tests a URL pathname against a `source` pattern of the `headers` option.
44
+ *
45
+ * @remarks
46
+ * The pattern must match the whole pathname. `**` followed by `/` also matches no segment, so `/**\/*.wasm`
47
+ * matches `/a.wasm` as well as `/a/b.wasm`. The pathname is matched as the request sends it, percent-encoding included.
48
+ */
49
+ export function matchesResponseHeaderSource(source, pathname) {
50
+ let pattern = '';
51
+ for (let index = 0; index < source.length; index += 1) {
52
+ const char = source[index];
53
+ if (char === '*' && source[index + 1] === '*') {
54
+ const slash = source[index + 2] === '/';
55
+ pattern += slash ? '(?:.*/)?' : '.*';
56
+ index += slash ? 2 : 1;
57
+ }
58
+ else if (char === '*') {
59
+ pattern += '[^/]*';
60
+ }
61
+ else {
62
+ pattern += char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
63
+ }
64
+ }
65
+ return new RegExp(`^${pattern}$`, 's').test(pathname);
66
+ }
67
+ /**
68
+ * Adds the configured headers whose `source` matches the request path to a response.
69
+ *
70
+ * @remarks
71
+ * Rules apply in config order, so a later rule wins over an earlier one. A configured header replaces a header
72
+ * of the same name the framework or a handler already set, which is how an app overrides one deliberately; every
73
+ * other header stays. A response no rule matches is returned as it is. Otherwise the result is a new
74
+ * `Response` over the same body, because a handler may return a response whose headers are immutable.
75
+ */
76
+ export function applyResponseHeaders(response, request, rules) {
77
+ if (!rules?.length)
78
+ return response;
79
+ const { pathname } = new URL(request.url);
80
+ const matching = rules.filter((rule) => matchesResponseHeaderSource(rule.source, pathname));
81
+ if (matching.length === 0)
82
+ return response;
83
+ const headers = new Headers(response.headers);
84
+ for (const rule of matching) {
85
+ for (const [name, value] of Object.entries(rule.headers))
86
+ headers.set(name, value);
87
+ }
88
+ return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
89
+ }
@@ -1,4 +1,4 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { fileSystem } from '@ecopages/file-system';
3
3
  function tryLstat(filePath) {
4
4
  try {
@@ -17,9 +17,10 @@ export declare function attachHmrToIntegrations(appConfig: EcoPagesAppConfig): v
17
17
  * @remarks
18
18
  * Awaited before network request readiness is released, so requests do not
19
19
  * compete with cold Integration `setup()`. The listener may already be bound.
20
+ * Each activation resolves the Integration's global scripts after its setup.
20
21
  * Failures are logged after all setup attempts settle and do not crash the
21
- * server. Concurrent first-page renders still join the same coalesced
22
- * {@link ensureIntegrationRuntimeReady} promise.
22
+ * server; a later request retries a failed activation. Concurrent first-page
23
+ * renders still join the same coalesced {@link ensureIntegrationRuntimeReady} promise.
23
24
  */
24
25
  export declare function startDevWarmup(options: {
25
26
  appConfig: EcoPagesAppConfig;
@@ -1,4 +1,4 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { fileSystem } from '@ecopages/file-system';
3
3
  import { requireAppRuntime } from '../../../utils/app-runtime.js';
4
4
  import { RESOLVED_ASSETS_DIR } from '../../../constants.js';
@@ -37,9 +37,10 @@ export function attachHmrToIntegrations(appConfig) {
37
37
  * @remarks
38
38
  * Awaited before network request readiness is released, so requests do not
39
39
  * compete with cold Integration `setup()`. The listener may already be bound.
40
+ * Each activation resolves the Integration's global scripts after its setup.
40
41
  * Failures are logged after all setup attempts settle and do not crash the
41
- * server. Concurrent first-page renders still join the same coalesced
42
- * {@link ensureIntegrationRuntimeReady} promise.
42
+ * server; a later request retries a failed activation. Concurrent first-page
43
+ * renders still join the same coalesced {@link ensureIntegrationRuntimeReady} promise.
43
44
  */
44
45
  export async function startDevWarmup(options) {
45
46
  const { appConfig } = options;
@@ -1,4 +1,4 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { getServerModuleBuildCacheOutdir } from '../../../build/server/route-module-build-cache-registry.js';
3
3
  import { RouteRendererFactory } from '../../../route-renderer/route-renderer.js';
4
4
  import { RouteRegistry } from '../../../router/server/route-registry.js';
@@ -131,8 +131,8 @@ export class ServerRequestPipeline {
131
131
  const page = module.default;
132
132
  const pageComponent = page;
133
133
  return {
134
- staticPaths: pageComponent?.staticPaths ?? module.getStaticPaths,
135
- staticProps: pageComponent?.staticProps ?? module.getStaticProps,
134
+ staticPaths: pageComponent?.staticPaths,
135
+ staticProps: pageComponent?.staticProps,
136
136
  cache: pageComponent?.cache,
137
137
  };
138
138
  },
@@ -215,7 +215,7 @@ export class ServerRequestPipeline {
215
215
  return createRenderContext({
216
216
  integrations: this.appConfig.integrations,
217
217
  ensureIntegrationReady: (integrationName) => ensureIntegrationRuntimeReady({ appConfig: this.appConfig, integrationName }),
218
- importServerModule: (filePath) => this.importServerModule(filePath),
218
+ importServerModule: (filePath) => this.importServerModule(path.resolve(this.appConfig.rootDir, filePath)),
219
219
  });
220
220
  }
221
221
  async importServerModule(filePath) {
@@ -5,6 +5,13 @@ import type { RouteRegistry } from '../../../router/server/route-registry.js';
5
5
  import type { StaticSiteGenerator } from '../../../static-site-generator/static-site-generator.js';
6
6
  import type { StaticGenerationRendererResolver } from '../../../route-renderer/route-renderer.js';
7
7
  import { type EndpointRouteHandlerOptions } from '../http/endpoint-route-handler.js';
8
+ type StaticBuildDependencies = {
9
+ router: RouteRegistry;
10
+ routeRendererFactory: StaticGenerationRendererResolver;
11
+ staticRoutes?: StaticRoute[];
12
+ errorPageLoaders?: ErrorPageLoaders;
13
+ importServerModule: EndpointRouteHandlerOptions['importServerModule'];
14
+ };
8
15
  export interface StaticBuildOptions {
9
16
  baseUrl?: string;
10
17
  force?: boolean;
@@ -98,6 +105,13 @@ export declare class ServerStaticBuilder {
98
105
  * @throws If the build adapter is unavailable or bundling fails.
99
106
  */
100
107
  private bundleServerEntry;
108
+ /**
109
+ * Records the processed file dependencies beside the server bundle, which is the only consumer of them.
110
+ *
111
+ * @remarks
112
+ * The production prebuild already wrote the app-wide browser build there; this adds what rendering processed.
113
+ */
114
+ private writeAssetLedger;
101
115
  /**
102
116
  * Generates a static build of the site for deployment.
103
117
  * @param dependencies.router - The initialized router
@@ -108,13 +122,10 @@ export declare class ServerStaticBuilder {
108
122
  * @remarks
109
123
  * Every server entry is emitted into `dist/server/` before endpoints are checked, so a broken
110
124
  * module fails the build with the error its first request would log. `ecopages start` loads those
111
- * emitted modules and never compiles.
125
+ * emitted modules and never compiles. Static generation resolves each Integration's global scripts after the
126
+ * app-wide browser build, so none is bundled on its own into `dist/`.
112
127
  */
113
- build(options: StaticBuildOptions | undefined, dependencies: {
114
- router: RouteRegistry;
115
- routeRendererFactory: StaticGenerationRendererResolver;
116
- staticRoutes?: StaticRoute[];
117
- errorPageLoaders?: ErrorPageLoaders;
118
- importServerModule: EndpointRouteHandlerOptions['importServerModule'];
119
- }): Promise<void>;
128
+ build(options: StaticBuildOptions | undefined, dependencies: StaticBuildDependencies): Promise<void>;
129
+ private buildPreparedExport;
120
130
  }
131
+ export {};
@@ -1,4 +1,4 @@
1
- import path from 'node:path';
1
+ import { path } from '@ecopages/file-system/path';
2
2
  import { isEcopagesEnvEnabled } from '../../../env.js';
3
3
  import { fileSystem } from '@ecopages/file-system';
4
4
  import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT, RESOLVED_ASSETS_DIR } from '../../../constants.js';
@@ -10,6 +10,8 @@ import { createServerBuildRequest } from '../../../build/runtime/build-request-p
10
10
  import { buildOrThrow } from '../../../build/runtime/build-queue.js';
11
11
  import { attachHmrToIntegrations } from './runtime-server-lifecycle.js';
12
12
  import { copyDeclaredServerFiles } from '../../../build/copy-server-files.js';
13
+ import { writeProductionAssetLedger } from '../../../build/production-asset-ledger.js';
14
+ import { getPrebuiltHtmlPageModuleScriptUrls } from '../../../html-pages/html-page-module-scripts.js';
13
15
  import { writeProductionRouteList } from '../../../build/production-route-list.js';
14
16
  import { getServerBundleOutputPaths, writeServerBundleDeployManifest, } from '../../../build/server-bundle-deploy-manifest.js';
15
17
  import { bundleEcoConfigModule, EMITTED_ECO_CONFIG_FILENAME } from '../../../config/server-config-bundle.js';
@@ -146,6 +148,17 @@ export class ServerStaticBuilder {
146
148
  }
147
149
  this.logger.info('Server entry file bundled successfully');
148
150
  }
151
+ /**
152
+ * Records the processed file dependencies beside the server bundle, which is the only consumer of them.
153
+ *
154
+ * @remarks
155
+ * The production prebuild already wrote the app-wide browser build there; this adds what rendering processed.
156
+ */
157
+ async writeAssetLedger(buildsServerBundle) {
158
+ if (buildsServerBundle) {
159
+ writeProductionAssetLedger(this.appConfig, await getPrebuiltHtmlPageModuleScriptUrls(this.appConfig));
160
+ }
161
+ }
149
162
  /**
150
163
  * Generates a static build of the site for deployment.
151
164
  * @param dependencies.router - The initialized router
@@ -156,7 +169,8 @@ export class ServerStaticBuilder {
156
169
  * @remarks
157
170
  * Every server entry is emitted into `dist/server/` before endpoints are checked, so a broken
158
171
  * module fails the build with the error its first request would log. `ecopages start` loads those
159
- * emitted modules and never compiles.
172
+ * emitted modules and never compiles. Static generation resolves each Integration's global scripts after the
173
+ * app-wide browser build, so none is bundled on its own into `dist/`.
160
174
  */
161
175
  async build(options, dependencies) {
162
176
  const { baseUrl: explicitBaseUrl, force = false } = options ?? {};
@@ -166,8 +180,12 @@ export class ServerStaticBuilder {
166
180
  await this.prepareExport();
167
181
  }
168
182
  this.exportPrepared = false;
183
+ await this.buildPreparedExport(baseUrl, force, dependencies, options?.keepGoing);
184
+ }
185
+ async buildPreparedExport(baseUrl, force, dependencies, keepGoing) {
169
186
  const endpointRoutes = dependencies.router.templateRoutes.filter((route) => route.role === 'endpoint');
170
- if (this.needsServerBundle || endpointRoutes.length > 0) {
187
+ const buildsServerBundle = this.needsServerBundle || endpointRoutes.length > 0;
188
+ if (buildsServerBundle) {
171
189
  await this.bundleServerEntry();
172
190
  }
173
191
  if (shouldBuildPagesUnifiedGraph()) {
@@ -190,8 +208,9 @@ export class ServerStaticBuilder {
190
208
  staticRoutes: dependencies.staticRoutes,
191
209
  errorPageLoaders: dependencies.errorPageLoaders,
192
210
  force,
193
- keepGoing: options?.keepGoing,
211
+ keepGoing,
194
212
  });
213
+ await this.writeAssetLedger(buildsServerBundle);
195
214
  if (isEcopagesEnvEnabled('ECOPAGES_BENCH') && !isEcopagesEnvEnabled('ECOPAGES_BENCH_VERBOSE')) {
196
215
  this.logger.debug('Build completed');
197
216
  }
@@ -1,5 +1,5 @@
1
1
  import type { Duplex } from 'node:stream';
2
- import type { Server as NodeHttpServer, IncomingMessage } from 'node:http';
2
+ import { type Server as NodeHttpServer, type IncomingMessage } from 'node:http';
3
3
  import type { EcopagesWebSocketHandler } from '../../../types/contracts.js';
4
4
  export type NodeHttpWebSocketUpgradePreflight = (req: IncomingMessage, socket: Duplex, head: Buffer) => boolean;
5
5
  export type AttachNodeHttpWebSocketUpgradesOptions = {
@@ -1,3 +1,4 @@
1
+ import { STATUS_CODES } from 'node:http';
1
2
  import { WebSocketServer } from 'ws';
2
3
  import { HttpError } from '../../../errors/http-error.js';
3
4
  import { appLogger } from '../../../global/app-logger.js';
@@ -26,21 +27,16 @@ async function resolveNodeContext(request, handler, kind, params, search) {
26
27
  return (await handler.context({ request, kind, params, search }));
27
28
  }
28
29
  catch (error) {
29
- appLogger.error(`[WS:${kind}] context() failed; closing connection.`, error);
30
+ appLogger.error(`[WS:${kind}] context() failed; refusing upgrade.`, error);
30
31
  throw error;
31
32
  }
32
33
  }
33
- async function setupNodeWebSocketConnection(ws, wsMatch, req, runtimeOrigin, search) {
34
+ function refuseUpgrade(socket, error) {
35
+ const status = HttpError.isHttpError(error) && error.status >= 400 && error.status < 600 ? error.status : 403;
36
+ socket.end(`HTTP/1.1 ${status} ${STATUS_CODES[status] ?? 'Error'}\r\nConnection: close\r\nContent-Length: 0\r\n\r\n`);
37
+ }
38
+ async function setupNodeWebSocketConnection(ws, wsMatch, search, context) {
34
39
  const handler = wsMatch.handler;
35
- const baseRequest = toUpgradeRequest(runtimeOrigin, req);
36
- let context;
37
- try {
38
- context = await resolveNodeContext(baseRequest, handler, wsMatch.kind, wsMatch.params, search);
39
- }
40
- catch {
41
- ws.close(1011, 'context initialization failed');
42
- return;
43
- }
44
40
  const socket = adaptNodeWebSocket(ws, wsMatch.kind, wsMatch.params, search, context);
45
41
  try {
46
42
  await handler.onConnect?.(socket);
@@ -112,12 +108,23 @@ export function attachNodeHttpWebSocketUpgrades(server, options) {
112
108
  socket.destroy();
113
109
  return;
114
110
  }
115
- userWss.handleUpgrade(req, socket, head, (ws) => {
116
- const search = parseSearchParams(url.searchParams);
117
- void setupNodeWebSocketConnection(ws, wsMatch, req, options.runtimeOrigin, search).catch((error) => {
118
- appLogger.error(`[WS:${wsMatch.kind}] unexpected error:`, error);
119
- ws.close(1011, 'internal error');
111
+ const search = parseSearchParams(url.searchParams);
112
+ const handler = wsMatch.handler;
113
+ const baseRequest = toUpgradeRequest(options.runtimeOrigin, req);
114
+ void resolveNodeContext(baseRequest, handler, wsMatch.kind, wsMatch.params, search).then((context) => {
115
+ if (socket.destroyed) {
116
+ return;
117
+ }
118
+ userWss.handleUpgrade(req, socket, head, (ws) => {
119
+ void setupNodeWebSocketConnection(ws, wsMatch, search, context).catch((error) => {
120
+ appLogger.error(`[WS:${wsMatch.kind}] unexpected error:`, error);
121
+ ws.close(1011, 'internal error');
122
+ });
120
123
  });
124
+ }, (error) => {
125
+ if (!socket.destroyed) {
126
+ refuseUpgrade(socket, error);
127
+ }
121
128
  });
122
129
  });
123
130
  }
@@ -1,18 +1,11 @@
1
1
  import type { GroupedGraphBuildPlan } from '../route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.js';
2
2
  import type { EcoPagesAppConfig } from '../config/internal-types.js';
3
- import type { AssetDefinition } from './asset-processing-service/assets.types.js';
4
3
  /**
5
- * Results produced by the application-wide browser build.
4
+ * Builds the production browser client once for the app.
6
5
  *
7
6
  * @remarks
8
- * Route-instance identity and HTML Page script inputs currently come from rendering modules; #556 tracks
9
- * moving those shared build inputs behind the Build layer.
7
+ * Every script the plans declare and every HTML module script are entries of one build per set of build-wide
8
+ * options, so a module they share is one chunk. Each entry's output is recorded in `AppRuntime.processedAssets`,
9
+ * along with every emitted file; HTML module-script URLs go to the HTML Page state.
10
10
  */
11
- export type AppBrowserClientBuildResult = {
12
- plans: GroupedGraphBuildPlan[];
13
- sourceFiles: string[];
14
- outputPaths: string[];
15
- };
16
- export declare function createAppBrowserClientEntryKey(integrationName: string, dependency: AssetDefinition): string;
17
- /** Builds the production browser client once for the app and attaches its route assets to plans. */
18
- export declare function buildAppBrowserClient(appConfig: EcoPagesAppConfig, plans: readonly GroupedGraphBuildPlan[]): Promise<AppBrowserClientBuildResult>;
11
+ export declare function buildAppBrowserClient(appConfig: EcoPagesAppConfig, plans: readonly GroupedGraphBuildPlan[]): Promise<void>;