@ecopages/core 0.2.0-beta.30 → 0.2.0-beta.32

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 (338) hide show
  1. package/README.md +1 -0
  2. package/package.json +82 -3
  3. package/src/adapters/abstract/application-adapter.d.ts +0 -8
  4. package/src/adapters/abstract/application-adapter.js +252 -261
  5. package/src/adapters/abstract/router-adapter.js +12 -4
  6. package/src/adapters/abstract/segment-path-matcher.js +132 -134
  7. package/src/adapters/abstract/server-adapter.js +22 -14
  8. package/src/adapters/abstract/ws-pattern-matcher.js +24 -26
  9. package/src/adapters/bun/bun-user-websocket-lifecycle.js +83 -86
  10. package/src/adapters/bun/client-bridge.js +51 -50
  11. package/src/adapters/bun/create-app.js +171 -161
  12. package/src/adapters/bun/hmr-manager.js +62 -57
  13. package/src/adapters/bun/index.js +2 -31
  14. package/src/adapters/bun/runtime-host.js +61 -54
  15. package/src/adapters/bun/server-adapter.d.ts +0 -1
  16. package/src/adapters/bun/server-adapter.js +561 -561
  17. package/src/adapters/bun/static-preview-host.js +43 -46
  18. package/src/adapters/create-app.js +11 -14
  19. package/src/adapters/index.js +2 -30
  20. package/src/adapters/node/create-app.js +123 -129
  21. package/src/adapters/node/http-request-bridge.js +147 -106
  22. package/src/adapters/node/node-client-bridge.js +62 -64
  23. package/src/adapters/node/node-hmr-manager.js +58 -48
  24. package/src/adapters/node/runtime-host.js +96 -89
  25. package/src/adapters/node/server-adapter-dependencies.js +18 -21
  26. package/src/adapters/node/server-adapter.d.ts +0 -1
  27. package/src/adapters/node/server-adapter.js +347 -326
  28. package/src/adapters/node/static-content-server.js +172 -191
  29. package/src/adapters/node/static-preview-host.js +87 -78
  30. package/src/adapters/shared/hmr/dev-transform-entrypoint-registry.d.ts +16 -0
  31. package/src/adapters/shared/hmr/dev-transform-entrypoint-registry.js +32 -0
  32. package/src/adapters/shared/hmr/hmr-html-response.js +46 -32
  33. package/src/adapters/shared/hmr/shared-hmr-manager.d.ts +29 -38
  34. package/src/adapters/shared/hmr/shared-hmr-manager.js +439 -425
  35. package/src/adapters/shared/http/api-request-pipeline.js +122 -119
  36. package/src/adapters/shared/http/api-response.js +77 -77
  37. package/src/adapters/shared/http/create-body-response.js +22 -19
  38. package/src/adapters/shared/http/define-api-handler.js +41 -55
  39. package/src/adapters/shared/http/explicit-static-render-preparation.js +26 -23
  40. package/src/adapters/shared/http/explicit-static-route-matcher.js +55 -62
  41. package/src/adapters/shared/http/file-route-middleware-pipeline.js +81 -75
  42. package/src/adapters/shared/http/fs-server-response-factory.js +101 -96
  43. package/src/adapters/shared/http/fs-server-response-matcher.js +239 -257
  44. package/src/adapters/shared/http/run-middleware-chain.js +15 -15
  45. package/src/adapters/shared/runtime/application-adapter.js +72 -87
  46. package/src/adapters/shared/runtime/copy-runtime-public-dir.js +25 -22
  47. package/src/adapters/shared/runtime/port-manager.js +207 -177
  48. package/src/adapters/shared/runtime/render-context.js +94 -79
  49. package/src/adapters/shared/runtime/runtime-app-bootstrap.js +33 -38
  50. package/src/adapters/shared/runtime/runtime-host.js +1 -0
  51. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +2 -3
  52. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +65 -51
  53. package/src/adapters/shared/runtime/server-adapter.d.ts +1 -0
  54. package/src/adapters/shared/runtime/server-adapter.js +233 -217
  55. package/src/adapters/shared/runtime/server-route-handler.js +74 -70
  56. package/src/adapters/shared/runtime/server-static-builder.js +165 -184
  57. package/src/adapters/shared/runtime/static-preview-host.js +1 -0
  58. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +97 -88
  59. package/src/adapters/shared/ws/websocket-lifecycle.js +57 -50
  60. package/src/build/README.md +52 -1
  61. package/src/build/app-build-manifest-runtime.js +129 -108
  62. package/src/build/browser/browser-runtime-manifest.js +47 -50
  63. package/src/build/browser/browser-runtime-plugin-helpers.js +32 -12
  64. package/src/build/browser/browser-runtime-plugin.js +206 -160
  65. package/src/build/browser/jsx-ownership-plugins.js +51 -37
  66. package/src/build/browser/lit-static-render-worker-context.js +3 -5
  67. package/src/build/build-adapter.js +276 -139
  68. package/src/build/cache/build-input-fingerprint.js +28 -26
  69. package/src/build/cache/cache-constants.js +4 -6
  70. package/src/build/cache/cache-keys.js +64 -56
  71. package/src/build/cache/pages-unified-graph-build.js +179 -178
  72. package/src/build/cache/production-build-cache.js +47 -54
  73. package/src/build/cache/server-entry-build-cache.js +134 -146
  74. package/src/build/contracts/build-contracts.d.ts +4 -4
  75. package/src/build/contracts/build-contracts.js +1 -0
  76. package/src/build/contracts/build-manifest.js +58 -43
  77. package/src/build/contracts/build-types.js +1 -0
  78. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +9 -0
  79. package/src/build/rolldown/rolldown-adapter-helpers.js +405 -298
  80. package/src/build/rolldown/rolldown-build-adapter.js +53 -61
  81. package/src/build/rolldown/rolldown-build-invocation-metrics.js +31 -35
  82. package/src/build/rolldown/rolldown-plugin-bridge.js +264 -194
  83. package/src/build/rolldown/rolldown-source-transform-pass.js +59 -50
  84. package/src/build/rolldown/runtime-build-output-normalizer.js +227 -175
  85. package/src/build/rolldown/server-side-css-shim-plugin.js +54 -31
  86. package/src/build/runtime/build-profile-options.js +36 -36
  87. package/src/build/runtime/build-request-identity.js +70 -45
  88. package/src/build/runtime/build-request-policy.js +80 -42
  89. package/src/build/runtime/build-runtime.js +64 -54
  90. package/src/build/runtime/deduping-build-executor.js +38 -32
  91. package/src/build/runtime/parallel-build-executor.js +58 -50
  92. package/src/build/runtime/serialized-build-executor.js +78 -62
  93. package/src/cache/index.js +6 -6
  94. package/src/cache/module-parse-cache.js +99 -68
  95. package/src/client/navigation-scripts/classification.js +45 -37
  96. package/src/client/navigation-scripts/index.js +3 -23
  97. package/src/client/navigation-scripts/navigation-scripts.test.browser.js +58 -62
  98. package/src/client/navigation-scripts/registry.js +15 -11
  99. package/src/client/navigation-scripts/rerun-queue.js +81 -64
  100. package/src/client/scroll.js +32 -24
  101. package/src/client/scroll.test.browser.js +27 -33
  102. package/src/client/view-transitions.js +68 -55
  103. package/src/config/config-builder.d.ts +8 -0
  104. package/src/config/config-builder.js +637 -642
  105. package/src/config/constants.js +44 -24
  106. package/src/declarations.d.ts +1 -0
  107. package/src/dev/README.md +24 -0
  108. package/src/dev/client-bridge-registry.js +7 -12
  109. package/src/dev/dev-client-ownership.js +7 -5
  110. package/src/dev/hmr-manager-registry.js +7 -12
  111. package/src/dev/host-runtime.js +25 -30
  112. package/src/dev/runtime-server-started-message.js +2 -5
  113. package/src/dev/sc-server.js +106 -103
  114. package/src/dev/transform-server/dev-transform-bundler.d.ts +24 -0
  115. package/src/dev/transform-server/dev-transform-bundler.js +79 -0
  116. package/src/dev/transform-server/dev-transform-externalize-plugin.d.ts +12 -0
  117. package/src/dev/transform-server/dev-transform-externalize-plugin.js +29 -0
  118. package/src/dev/transform-server/dev-transform-import-rewriter.d.ts +16 -0
  119. package/src/dev/transform-server/dev-transform-import-rewriter.js +110 -0
  120. package/src/dev/transform-server/dev-transform-module-kind.d.ts +13 -0
  121. package/src/dev/transform-server/dev-transform-module-kind.js +17 -0
  122. package/src/dev/transform-server/dev-transform-runtime-specifiers.d.ts +5 -0
  123. package/src/dev/transform-server/dev-transform-runtime-specifiers.js +16 -0
  124. package/src/dev/transform-server/dev-transform-server.d.ts +41 -0
  125. package/src/dev/transform-server/dev-transform-server.js +191 -0
  126. package/src/dev/transform-server/dev-transform-url.d.ts +13 -0
  127. package/src/dev/transform-server/dev-transform-url.js +58 -0
  128. package/src/dev/transform-server/dev-transform-vendor-registry.d.ts +27 -0
  129. package/src/dev/transform-server/dev-transform-vendor-registry.js +145 -0
  130. package/src/dev/transform-server/index.d.ts +6 -0
  131. package/src/dev/transform-server/index.js +4 -0
  132. package/src/dev/transform-server/types.d.ts +15 -0
  133. package/src/dev/transform-server/types.js +1 -0
  134. package/src/dev-toolbar/README.md +51 -0
  135. package/src/dev-toolbar/define-dev-tool.d.ts +21 -0
  136. package/src/dev-toolbar/define-dev-tool.js +9 -0
  137. package/src/dev-toolbar/dev-toolbar-config.d.ts +25 -0
  138. package/src/dev-toolbar/dev-toolbar-config.js +19 -0
  139. package/src/dev-toolbar/dev-toolbar-host.d.ts +49 -0
  140. package/src/dev-toolbar/dev-toolbar-host.js +117 -0
  141. package/src/dev-toolbar/dev-toolbar-html-response.d.ts +11 -0
  142. package/src/dev-toolbar/dev-toolbar-html-response.js +14 -0
  143. package/src/dev-toolbar/dev-toolbar-manifest.d.ts +15 -0
  144. package/src/dev-toolbar/dev-toolbar-manifest.js +52 -0
  145. package/src/dev-toolbar/dev-toolbar-package.d.ts +31 -0
  146. package/src/dev-toolbar/dev-toolbar-package.js +72 -0
  147. package/src/dev-toolbar/dev-toolbar-runtime-paths.d.ts +10 -0
  148. package/src/dev-toolbar/dev-toolbar-runtime-paths.js +13 -0
  149. package/src/diagnostics/request-build-dedupe.js +34 -28
  150. package/src/diagnostics/startup-trace.d.ts +10 -1
  151. package/src/diagnostics/startup-trace.js +269 -241
  152. package/src/eco/README.md +6 -0
  153. package/src/eco/eco-declared-component.js +19 -14
  154. package/src/eco/eco.browser.js +56 -69
  155. package/src/eco/eco.js +156 -96
  156. package/src/eco/eco.types.js +5 -0
  157. package/src/eco/eco.utils.js +1 -10
  158. package/src/eco/global-injector-map.js +55 -41
  159. package/src/eco/lazy-injector-map.js +90 -60
  160. package/src/eco/module-dependencies.js +52 -44
  161. package/src/eco/page-layout-normalization.js +59 -49
  162. package/src/errors/http-error.js +50 -49
  163. package/src/errors/index.js +3 -12
  164. package/src/errors/locals-access-error.js +5 -8
  165. package/src/errors/undeclared-component-dependency-error.js +15 -15
  166. package/src/global/app-logger.js +3 -6
  167. package/src/hmr/README.md +10 -0
  168. package/src/hmr/client/hmr-runtime.js +117 -113
  169. package/src/hmr/client/module-update.d.ts +13 -0
  170. package/src/hmr/client/module-update.js +39 -0
  171. package/src/hmr/hmr-asset-paths.d.ts +14 -0
  172. package/src/hmr/hmr-asset-paths.js +22 -0
  173. package/src/hmr/hmr-entrypoint-output.d.ts +11 -39
  174. package/src/hmr/hmr-entrypoint-output.js +28 -54
  175. package/src/hmr/hmr-file-change-prep.js +13 -16
  176. package/src/hmr/hmr-registered-entrypoints-context.d.ts +7 -0
  177. package/src/hmr/hmr-registered-entrypoints-context.js +1 -0
  178. package/src/hmr/hmr-runtime-paths.d.ts +10 -0
  179. package/src/hmr/hmr-runtime-paths.js +13 -0
  180. package/src/hmr/hmr-strategy.d.ts +5 -11
  181. package/src/hmr/hmr-strategy.js +113 -61
  182. package/src/hmr/strategies/default-hmr-strategy.js +55 -33
  183. package/src/hmr/strategies/js-hmr-strategy.d.ts +6 -95
  184. package/src/hmr/strategies/js-hmr-strategy.js +104 -217
  185. package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +33 -27
  186. package/src/index.browser.js +1 -4
  187. package/src/index.d.ts +1 -0
  188. package/src/index.js +6 -47
  189. package/src/integrations/ghtml/ghtml-renderer.js +12 -7
  190. package/src/integrations/ghtml/ghtml.constants.js +1 -4
  191. package/src/integrations/ghtml/ghtml.plugin.js +9 -12
  192. package/src/islands/README.md +25 -0
  193. package/src/islands/island-host.d.ts +37 -0
  194. package/src/islands/island-host.js +55 -0
  195. package/src/plugins/alias-resolver-cache.js +114 -97
  196. package/src/plugins/alias-resolver-plugin.js +33 -47
  197. package/src/plugins/define-integration.js +18 -17
  198. package/src/plugins/eco-component-meta-plugin.js +387 -145
  199. package/src/plugins/foreign-jsx-override-plugin.js +49 -35
  200. package/src/plugins/integration-plugin.js +212 -203
  201. package/src/plugins/jsx-import-source.utils.js +16 -21
  202. package/src/plugins/processor.js +159 -149
  203. package/src/plugins/runtime-capability.js +1 -0
  204. package/src/plugins/source-transform.js +109 -79
  205. package/src/plugins/tsconfig-import-resolver.d.ts +17 -0
  206. package/src/plugins/tsconfig-import-resolver.js +218 -142
  207. package/src/route-renderer/README.md +12 -1
  208. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +143 -136
  209. package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +33 -27
  210. package/src/route-renderer/orchestration/foreign-child/component-render-context.js +173 -126
  211. package/src/route-renderer/orchestration/foreign-child/foreign-child-output.utils.js +165 -154
  212. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +329 -341
  213. package/src/route-renderer/orchestration/foreign-child/owning-renderer-resolution.js +33 -32
  214. package/src/route-renderer/orchestration/integration-renderer.d.ts +1 -0
  215. package/src/route-renderer/orchestration/integration-renderer.js +731 -750
  216. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +168 -172
  217. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +119 -131
  218. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +82 -91
  219. package/src/route-renderer/orchestration/ownership-graph/ownership-validation.service.js +82 -76
  220. package/src/route-renderer/orchestration/page-browser-graph/global-injector-assets.service.js +29 -31
  221. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-contribution.loader.js +10 -6
  222. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.js +31 -28
  223. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +3 -0
  224. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +430 -413
  225. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +191 -212
  226. package/src/route-renderer/orchestration/page-browser-graph/processed-asset-dedupe.js +20 -24
  227. package/src/route-renderer/orchestration/route-pipeline/integration-route-render-adapter.d.ts +4 -0
  228. package/src/route-renderer/orchestration/route-pipeline/integration-route-render-adapter.js +24 -24
  229. package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.js +22 -24
  230. package/src/route-renderer/orchestration/route-pipeline/robots-meta.contribution.js +41 -34
  231. package/src/route-renderer/orchestration/route-pipeline/route-html-finalization.service.d.ts +5 -0
  232. package/src/route-renderer/orchestration/route-pipeline/route-html-finalization.service.js +42 -22
  233. package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.builder.js +50 -48
  234. package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.js +29 -32
  235. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +150 -156
  236. package/src/route-renderer/orchestration/string-markup-renderer.js +48 -51
  237. package/src/route-renderer/page-loading/component-dependency-collection.js +120 -124
  238. package/src/route-renderer/page-loading/declared-asset-collection.js +66 -94
  239. package/src/route-renderer/page-loading/dependency-resolver.js +101 -104
  240. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +68 -54
  241. package/src/route-renderer/page-loading/lazy-entry-collection.js +75 -98
  242. package/src/route-renderer/page-loading/lazy-trigger-planning.js +46 -36
  243. package/src/route-renderer/page-loading/module-declaration-aggregation.js +38 -31
  244. package/src/route-renderer/page-loading/module-declaration-scripts.js +10 -15
  245. package/src/route-renderer/page-loading/page-dependency-bundling.js +156 -113
  246. package/src/route-renderer/page-loading/page-module-loader.js +130 -124
  247. package/src/route-renderer/route-renderer.js +74 -76
  248. package/src/router/client/link-intent.js +55 -39
  249. package/src/router/client/link-intent.test.browser.js +49 -49
  250. package/src/router/client/link-navigation-policy.js +114 -93
  251. package/src/router/client/link-navigation-policy.test.browser.js +70 -80
  252. package/src/router/client/navigation-coordinator.js +235 -211
  253. package/src/router/server/route-registry.js +237 -242
  254. package/src/services/assets/asset-processing-service/asset-dependency-keys.js +64 -53
  255. package/src/services/assets/asset-processing-service/asset-processing.service.js +287 -303
  256. package/src/services/assets/asset-processing-service/asset.factory.js +78 -81
  257. package/src/services/assets/asset-processing-service/assets.types.js +1 -0
  258. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.js +57 -46
  259. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +106 -69
  260. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +53 -53
  261. package/src/services/assets/asset-processing-service/finalize-processed-asset.js +4 -6
  262. package/src/services/assets/asset-processing-service/grouped-content-bundles.js +79 -80
  263. package/src/services/assets/asset-processing-service/index.js +8 -8
  264. package/src/services/assets/asset-processing-service/inline-content-script-body.js +22 -16
  265. package/src/services/assets/asset-processing-service/materialize-content-script-asset.js +21 -17
  266. package/src/services/assets/asset-processing-service/page-package.js +70 -72
  267. package/src/services/assets/asset-processing-service/processor.interface.js +7 -5
  268. package/src/services/assets/asset-processing-service/processor.registry.js +11 -14
  269. package/src/services/assets/asset-processing-service/processors/base/base-processor.js +59 -62
  270. package/src/services/assets/asset-processing-service/processors/base/base-script-processor.js +102 -117
  271. package/src/services/assets/asset-processing-service/processors/index.js +5 -5
  272. package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +110 -115
  273. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +95 -97
  274. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +136 -135
  275. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +27 -29
  276. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +34 -40
  277. package/src/services/assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.js +36 -35
  278. package/src/services/assets/asset-processing-service/resolve-integration-plugin.js +14 -16
  279. package/src/services/assets/asset-processing-service/ungrouped-dependency-processing.js +27 -39
  280. package/src/services/assets/browser-bundle.service.js +52 -47
  281. package/src/services/cache/cache.types.js +5 -0
  282. package/src/services/cache/index.js +6 -7
  283. package/src/services/cache/memory-cache-store.js +101 -89
  284. package/src/services/cache/page-cache-service.js +156 -145
  285. package/src/services/cache/page-request-cache-coordinator.service.js +102 -102
  286. package/src/services/html/html-rewriter-provider.service.js +61 -61
  287. package/src/services/html/html-transformer.service.js +249 -266
  288. package/src/services/invalidation/development-invalidation.service.js +252 -241
  289. package/src/services/module-loading/app-module-loader.service.js +1 -0
  290. package/src/services/module-loading/app-server-module-transpiler.service.js +107 -101
  291. package/src/services/module-loading/host-module-loader-registry.js +6 -11
  292. package/src/services/module-loading/module-loading-types.js +1 -0
  293. package/src/services/module-loading/page-module-import.service.js +235 -243
  294. package/src/services/module-loading/route-module-build-cache-registry.js +47 -33
  295. package/src/services/module-loading/route-module-build-cache.js +3 -38
  296. package/src/services/module-loading/route-module-build-cache.store.js +195 -200
  297. package/src/services/module-loading/route-module-build-manifest.js +61 -74
  298. package/src/services/module-loading/route-module-dependency-hasher.js +136 -110
  299. package/src/services/module-loading/server-module-transpiler.service.js +68 -62
  300. package/src/services/module-loading/source-module-support.js +15 -7
  301. package/src/services/runtime-state/dev-graph.service.js +165 -157
  302. package/src/services/runtime-state/entrypoint-dependency-graph.service.js +85 -76
  303. package/src/services/runtime-state/server-invalidation-state.service.js +38 -30
  304. package/src/services/validation/schema-validation-service.js +157 -95
  305. package/src/services/validation/standard-schema.types.js +1 -0
  306. package/src/services/validation/validate-standard-schema.js +13 -13
  307. package/src/static-site-generator/production-page-browser-graph-prebuild.js +35 -19
  308. package/src/static-site-generator/sitemap-routes.js +33 -28
  309. package/src/static-site-generator/sitemap.js +38 -29
  310. package/src/static-site-generator/static-build-invalidation.js +34 -56
  311. package/src/static-site-generator/static-export-context.js +1 -0
  312. package/src/static-site-generator/static-site-generator.js +517 -553
  313. package/src/types/internal-types.d.ts +19 -3
  314. package/src/types/internal-types.js +1 -0
  315. package/src/types/public-types.d.ts +16 -46
  316. package/src/types/public-types.js +1 -0
  317. package/src/utils/deep-merge.js +39 -26
  318. package/src/utils/ecopages-route-info.js +27 -23
  319. package/src/utils/hash.js +3 -6
  320. package/src/utils/html-escaping.js +21 -8
  321. package/src/utils/html.js +1 -4
  322. package/src/utils/invariant.js +11 -10
  323. package/src/utils/locals-utils.js +32 -22
  324. package/src/utils/parse-cli-args.js +73 -65
  325. package/src/utils/path-pattern.js +38 -23
  326. package/src/utils/path-utils.module.js +8 -11
  327. package/src/utils/resolve-entry-file.js +70 -38
  328. package/src/utils/resolve-work-dir.js +23 -27
  329. package/src/utils/runtime.js +24 -33
  330. package/src/utils/server-utils.module.js +60 -52
  331. package/src/utils/static-file-extensions.js +52 -46
  332. package/src/watchers/project-watcher-ignore.js +16 -15
  333. package/src/watchers/project-watcher.js +385 -366
  334. package/src/watchers/project-watcher.test-helpers.js +45 -50
  335. package/src/adapters/shared/hmr/hmr-entrypoint-registrar.d.ts +0 -56
  336. package/src/adapters/shared/hmr/hmr-entrypoint-registrar.js +0 -106
  337. package/src/build/cache/dev-browser-script-cache.d.ts +0 -34
  338. package/src/build/cache/dev-browser-script-cache.js +0 -90
@@ -1,645 +1,640 @@
1
- import path from "node:path";
2
- import {
3
- DEFAULT_ECOPAGES_DIST_DIR,
4
- DEFAULT_ECOPAGES_HOSTNAME,
5
- DEFAULT_ECOPAGES_PORT,
6
- DEFAULT_ECOPAGES_WORK_DIR
7
- } from "../config/constants.js";
8
- import {
9
- collectConfiguredAppBuildManifestContributions,
10
- createBuildAdapter,
11
- setAppBuildAdapter,
12
- updateAppBuildManifest
13
- } from "../build/build-adapter.js";
14
- import { GHTML_PLUGIN_NAME } from "../integrations/ghtml/ghtml.constants.js";
15
- import { ghtmlPlugin } from "../integrations/ghtml/ghtml.plugin.js";
16
- import { createEcoComponentMetaPlugin } from "../plugins/eco-component-meta-plugin.js";
17
- import { createEcoComponentMetaTransform } from "../plugins/eco-component-meta-plugin.js";
18
- import {
19
- NoopEntrypointDependencyGraph,
20
- setAppEntrypointDependencyGraph
21
- } from "../services/runtime-state/entrypoint-dependency-graph.service.js";
22
- import {
23
- CounterServerInvalidationState,
24
- setAppServerInvalidationState
25
- } from "../services/runtime-state/server-invalidation-state.service.js";
26
- import { invariant } from "../utils/invariant.js";
27
- import { appLogger } from "../global/app-logger.js";
28
- import { fileSystem } from "@ecopages/file-system";
29
- const CONFIG_BUILDER_ERRORS = {
30
- DUPLICATE_INTEGRATION_NAMES: "Integrations names must be unique",
31
- DUPLICATE_INTEGRATION_EXTENSIONS: "Integrations extensions must be unique",
32
- MIXED_JSX_ENGINES: "Both kitajs and react integrations are enabled. Use per-file JSX import source/pragma consistently (e.g. `/** @jsxImportSource react */` for React files and `/** @jsxImportSource @kitajs/html */` for Kita files).",
33
- duplicateProcessorName: (name) => `Processor with name "${name}" already exists`,
34
- duplicateLoaderName: (name) => `Loader with name "${name}" already exists`,
35
- duplicateSemanticTemplate: (kind, matches) => `Multiple ${kind} templates found: ${matches.join(", ")}`,
36
- incompatibleRuntimeCapability: (kind, name, runtime, reason) => `Cannot enable ${kind} "${name}" on ${runtime}: ${reason}`,
37
- unsupportedRuntimeVersion: (kind, name, runtime, current, min) => `Cannot enable ${kind} "${name}" on ${runtime} ${current}: requires runtime version ${min} or newer`,
38
- invalidRuntimeVersion: (kind, name, version) => `Cannot validate ${kind} "${name}" runtimeCapability.minRuntimeVersion "${version}" because it is not a dot-separated numeric version`
1
+ /**
2
+ * This module contains the ConfigBuilder class, which is used to build the EcoPagesAppConfig object.
3
+ * @module
4
+ */
5
+ import path from 'node:path';
6
+ import { DEFAULT_ECOPAGES_DIST_DIR, DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT, DEFAULT_ECOPAGES_WORK_DIR, } from '../config/constants.js';
7
+ import { collectConfiguredAppBuildManifestContributions, createBuildAdapter, setAppBuildAdapter, updateAppBuildManifest, } from '../build/build-adapter.js';
8
+ import { GHTML_PLUGIN_NAME } from '../integrations/ghtml/ghtml.constants.js';
9
+ import { ghtmlPlugin } from '../integrations/ghtml/ghtml.plugin.js';
10
+ import { createEcoComponentMetaPlugin } from '../plugins/eco-component-meta-plugin.js';
11
+ import { createEcoComponentMetaTransform } from '../plugins/eco-component-meta-plugin.js';
12
+ import { NoopEntrypointDependencyGraph, setAppEntrypointDependencyGraph, } from '../services/runtime-state/entrypoint-dependency-graph.service.js';
13
+ import { CounterServerInvalidationState, setAppServerInvalidationState, } from '../services/runtime-state/server-invalidation-state.service.js';
14
+ import { invariant } from '../utils/invariant.js';
15
+ import { appLogger } from '../global/app-logger.js';
16
+ import { fileSystem } from '@ecopages/file-system';
17
+ export const CONFIG_BUILDER_ERRORS = {
18
+ DUPLICATE_INTEGRATION_NAMES: 'Integrations names must be unique',
19
+ DUPLICATE_INTEGRATION_EXTENSIONS: 'Integrations extensions must be unique',
20
+ MIXED_JSX_ENGINES: 'Both kitajs and react integrations are enabled. Use per-file JSX import source/pragma consistently (e.g. `/** @jsxImportSource react */` for React files and `/** @jsxImportSource @kitajs/html */` for Kita files).',
21
+ duplicateProcessorName: (name) => `Processor with name "${name}" already exists`,
22
+ duplicateLoaderName: (name) => `Loader with name "${name}" already exists`,
23
+ duplicateSemanticTemplate: (kind, matches) => `Multiple ${kind} templates found: ${matches.join(', ')}`,
24
+ incompatibleRuntimeCapability: (kind, name, runtime, reason) => `Cannot enable ${kind} "${name}" on ${runtime}: ${reason}`,
25
+ unsupportedRuntimeVersion: (kind, name, runtime, current, min) => `Cannot enable ${kind} "${name}" on ${runtime} ${current}: requires runtime version ${min} or newer`,
26
+ invalidRuntimeVersion: (kind, name, version) => `Cannot validate ${kind} "${name}" runtimeCapability.minRuntimeVersion "${version}" because it is not a dot-separated numeric version`,
39
27
  };
40
- class ConfigBuilder {
41
- buildOwnership = "rolldown";
42
- config = {
43
- baseUrl: "",
44
- rootDir: ".",
45
- srcDir: "src",
46
- pagesDir: "pages",
47
- includesDir: "includes",
48
- componentsDir: "components",
49
- layoutsDir: "layouts",
50
- publicDir: "public",
51
- robotsTxt: {
52
- preferences: {
53
- "*": []
54
- }
55
- },
56
- sitemap: {
57
- enabled: false,
58
- fileName: "sitemap.xml",
59
- extraUrls: [],
60
- exclude: []
61
- },
62
- integrations: [],
63
- integrationsDependencies: [],
64
- distDir: DEFAULT_ECOPAGES_DIST_DIR,
65
- defaultMetadata: {
66
- title: "Ecopages",
67
- description: "This is a static site generated with Ecopages"
68
- },
69
- additionalWatchPaths: [],
70
- templatesExt: [],
71
- absolutePaths: {
72
- config: "",
73
- componentsDir: "",
74
- distDir: "",
75
- workDir: "",
76
- includesDir: "",
77
- layoutsDir: "",
78
- pagesDir: "",
79
- projectDir: "",
80
- publicDir: "",
81
- srcDir: "",
82
- htmlTemplatePath: "",
83
- error404TemplatePath: "",
84
- error500TemplatePath: ""
85
- },
86
- processors: /* @__PURE__ */ new Map(),
87
- loaders: /* @__PURE__ */ new Map(),
88
- sourceTransforms: /* @__PURE__ */ new Map(),
89
- workDir: DEFAULT_ECOPAGES_WORK_DIR
90
- };
91
- /**
92
- * Sets the base URL for the application.
93
- * This URL is used as the root URL for all pages and assets.
94
- *
95
- * @param baseUrl - The base URL for the application (e.g., 'https://example.com')
96
- * @returns The ConfigBuilder instance for method chaining
97
- */
98
- setBaseUrl(baseUrl) {
99
- this.config.baseUrl = baseUrl;
100
- return this;
101
- }
102
- /**
103
- * Sets the root directory of the project.
104
- * This is the base directory from which all other paths are resolved.
105
- *
106
- * @param rootDir - The root directory path
107
- * @returns The ConfigBuilder instance for method chaining
108
- */
109
- setRootDir(rootDir) {
110
- this.config.rootDir = rootDir;
111
- return this;
112
- }
113
- /**
114
- * Sets which runtime path owns build execution for the finalized app config.
115
- *
116
- * @remarks
117
- * Three ownership values are accepted:
118
- *
119
- * - `'rolldown'` (default): Ecopages runs builds through
120
- * {@link RolldownBuildAdapter}, creating a new `rolldown()` instance
121
- * per build.
122
- * - `'vite-host'`: a host runtime owns the build. Ecopages exposes a
123
- * {@link ViteHostBuildAdapter} boundary marker that throws on direct
124
- * use. Select this only for host-driven compatibility flows where
125
- * core must not silently fall back to app build execution.
126
- *
127
- * Defaults to `'rolldown'` when {@link ConfigBuilder.build} runs
128
- * without an explicit ownership.
129
- */
130
- setBuildOwnership(buildOwnership) {
131
- this.buildOwnership = buildOwnership;
132
- return this;
133
- }
134
- /**
135
- * Sets the source directory relative to the root directory.
136
- * This directory contains all the source files for the application.
137
- *
138
- * @param srcDir - The source directory name (default: 'src')
139
- * @returns The ConfigBuilder instance for method chaining
140
- */
141
- setSrcDir(srcDir) {
142
- this.config.srcDir = srcDir;
143
- return this;
144
- }
145
- /**
146
- * Sets the pages directory relative to the source directory.
147
- * This directory contains all the page files for the application.
148
- *
149
- * @param pagesDir - The pages directory name (default: 'pages')
150
- * @returns The ConfigBuilder instance for method chaining
151
- */
152
- setPagesDir(pagesDir) {
153
- this.config.pagesDir = pagesDir;
154
- return this;
155
- }
156
- /**
157
- * Sets the includes directory relative to the source directory.
158
- * This directory contains template includes and partials.
159
- *
160
- * @param includesDir - The includes directory name (default: 'includes')
161
- * @returns The ConfigBuilder instance for method chaining
162
- */
163
- setIncludesDir(includesDir) {
164
- this.config.includesDir = includesDir;
165
- return this;
166
- }
167
- /**
168
- * Sets the components directory relative to the source directory.
169
- * This directory contains reusable components.
170
- *
171
- * @param componentsDir - The components directory name (default: 'components')
172
- * @returns The ConfigBuilder instance for method chaining
173
- */
174
- setComponentsDir(componentsDir) {
175
- this.config.componentsDir = componentsDir;
176
- return this;
177
- }
178
- /**
179
- * Sets the layouts directory relative to the source directory.
180
- * This directory contains layout templates.
181
- *
182
- * @param layoutsDir - The layouts directory name (default: 'layouts')
183
- * @returns The ConfigBuilder instance for method chaining
184
- */
185
- setLayoutsDir(layoutsDir) {
186
- this.config.layoutsDir = layoutsDir;
187
- return this;
188
- }
189
- /**
190
- * Sets the public directory relative to the source directory.
191
- * This directory contains static assets that should be served as-is.
192
- *
193
- * @param publicDir - The public directory name (default: 'public')
194
- * @returns The ConfigBuilder instance for method chaining
195
- */
196
- setPublicDir(publicDir) {
197
- this.config.publicDir = publicDir;
198
- return this;
199
- }
200
- /**
201
- * Sets the robots.txt configuration.
202
- * This determines which paths are allowed/disallowed for search engines.
203
- *
204
- * @param robotsTxt - The robots.txt configuration object
205
- * @returns The ConfigBuilder instance for method chaining
206
- */
207
- setRobotsTxt(robotsTxt) {
208
- this.config.robotsTxt = robotsTxt;
209
- return this;
210
- }
211
- /**
212
- * Sets automatic sitemap.xml generation during static export.
213
- *
214
- * @remarks
215
- * Merged over `{ enabled: false, fileName: 'sitemap.xml', extraUrls: [], exclude: [] }`.
216
- * Existing apps stay unchanged until `enabled: true` is set. Page-level
217
- * `metadata.robots.index: false` and metadata resolution failures are handled
218
- * during static generation (not by this config merge).
219
- */
220
- setSitemap(sitemap) {
221
- const defaults = {
222
- enabled: false,
223
- fileName: "sitemap.xml",
224
- extraUrls: [],
225
- exclude: []
28
+ /**
29
+ * A builder class for creating and configuring EcoPages application configuration.
30
+ * Provides a fluent interface for setting various configuration options and managing
31
+ * application settings.
32
+ *
33
+ * @remarks
34
+ * The ConfigBuilder follows the builder pattern and allows for:
35
+ * - Setting directory paths for various components (pages, includes, layouts, etc.)
36
+ * - Configuring templates and includes
37
+ * - Managing integrations and plugins
38
+ * - Setting up processors and loaders
39
+ * - Configuring API handlers
40
+ * - Managing metadata and robots.txt preferences
41
+ *
42
+ * All setter methods return the instance of the builder for method chaining.
43
+ * The configuration is finalized by calling the `build()` method, which performs
44
+ * validation and initialization of the configuration.
45
+ *
46
+ * @throws {Error} When building configuration without required fields (e.g., baseUrl)
47
+ * @throws {Error} When adding duplicate processors or loaders
48
+ */
49
+ export class ConfigBuilder {
50
+ buildOwnership = 'rolldown';
51
+ config = {
52
+ baseUrl: '',
53
+ rootDir: '.',
54
+ srcDir: 'src',
55
+ pagesDir: 'pages',
56
+ includesDir: 'includes',
57
+ componentsDir: 'components',
58
+ layoutsDir: 'layouts',
59
+ publicDir: 'public',
60
+ robotsTxt: {
61
+ preferences: {
62
+ '*': [],
63
+ },
64
+ },
65
+ sitemap: {
66
+ enabled: false,
67
+ fileName: 'sitemap.xml',
68
+ extraUrls: [],
69
+ exclude: [],
70
+ },
71
+ integrations: [],
72
+ integrationsDependencies: [],
73
+ distDir: DEFAULT_ECOPAGES_DIST_DIR,
74
+ defaultMetadata: {
75
+ title: 'Ecopages',
76
+ description: 'This is a static site generated with Ecopages',
77
+ },
78
+ additionalWatchPaths: [],
79
+ templatesExt: [],
80
+ absolutePaths: {
81
+ config: '',
82
+ componentsDir: '',
83
+ distDir: '',
84
+ workDir: '',
85
+ includesDir: '',
86
+ layoutsDir: '',
87
+ pagesDir: '',
88
+ projectDir: '',
89
+ publicDir: '',
90
+ srcDir: '',
91
+ htmlTemplatePath: '',
92
+ error404TemplatePath: '',
93
+ error500TemplatePath: '',
94
+ },
95
+ processors: new Map(),
96
+ loaders: new Map(),
97
+ sourceTransforms: new Map(),
98
+ workDir: DEFAULT_ECOPAGES_WORK_DIR,
226
99
  };
227
- this.config.sitemap = {
228
- ...defaults,
229
- ...this.config.sitemap,
230
- ...sitemap,
231
- extraUrls: sitemap.extraUrls ?? this.config.sitemap.extraUrls ?? defaults.extraUrls,
232
- exclude: sitemap.exclude ?? this.config.sitemap.exclude ?? defaults.exclude
233
- };
234
- return this;
235
- }
236
- /**
237
- * Sets the integration plugins to use.
238
- * These plugins provide additional functionality to the application.
239
- *
240
- * @param integrations - An array of integration plugins
241
- * @returns The ConfigBuilder instance for method chaining
242
- */
243
- setIntegrations(integrations) {
244
- this.config.integrations = integrations;
245
- return this;
246
- }
247
- /**
248
- * Sets the output directory for the built application.
249
- *
250
- * @param distDir - The distribution directory name (default: 'dist')
251
- * @returns The ConfigBuilder instance for method chaining
252
- */
253
- setDistDir(distDir) {
254
- this.config.distDir = distDir;
255
- return this;
256
- }
257
- /**
258
- * Sets the internal work directory for runtime-only artifacts.
259
- *
260
- * @remarks
261
- * Use this when deployable output should stay clean while Ecopages still
262
- * needs a separate workspace for server transpilation caches, runtime
263
- * manifests, and other internal build products.
264
- *
265
- * @param workDir - The internal work directory name
266
- * @returns The ConfigBuilder instance for method chaining
267
- */
268
- setWorkDir(workDir) {
269
- this.config.workDir = workDir;
270
- return this;
271
- }
272
- /**
273
- * Sets the default metadata for pages.
274
- * This is used when a page doesn't specify its own metadata.
275
- *
276
- * @param defaultMetadata - The default metadata object
277
- * @returns The ConfigBuilder instance for method chaining
278
- */
279
- setDefaultMetadata(defaultMetadata) {
280
- this.config.defaultMetadata = {
281
- ...this.config.defaultMetadata,
282
- ...defaultMetadata
283
- };
284
- return this;
285
- }
286
- /**
287
- * Sets additional paths to watch for changes during development.
288
- *
289
- * @param additionalWatchPaths - An array of additional paths to watch
290
- * @returns The ConfigBuilder instance for method chaining
291
- */
292
- setAdditionalWatchPaths(additionalWatchPaths) {
293
- this.config.additionalWatchPaths = additionalWatchPaths;
294
- return this;
295
- }
296
- /**
297
- * Sets the processors to use for the application.
298
- * This replaces any existing processors.
299
- *
300
- * @param processors - An array of processors
301
- * @returns The ConfigBuilder instance for method chaining
302
- */
303
- setProcessors(processors) {
304
- this.config.processors.clear();
305
- for (const processor of processors) {
306
- this.addProcessor(processor);
307
- }
308
- return this;
309
- }
310
- /**
311
- * Adds a processor to the application.
312
- *
313
- * @param processor - The processor to add
314
- * @returns The ConfigBuilder instance for method chaining
315
- * @throws Error if a processor with the same name already exists
316
- */
317
- addProcessor(processor) {
318
- if (this.config.processors.has(processor.name)) {
319
- throw new Error(CONFIG_BUILDER_ERRORS.duplicateProcessorName(processor.name));
320
- }
321
- this.config.processors.set(processor.name, processor);
322
- return this;
323
- }
324
- /**
325
- * Sets the loaders to use for the application.
326
- * This replaces any existing loaders.
327
- *
328
- * @param loaders - An array of build plugins to use as loaders
329
- * @returns The ConfigBuilder instance for method chaining
330
- */
331
- setLoaders(loaders) {
332
- this.config.loaders.clear();
333
- for (const loader of loaders) {
334
- this.addLoader(loader.name, loader);
335
- }
336
- return this;
337
- }
338
- /**
339
- * Sets the source transforms to use for transform-first bundlers such as Vite.
340
- * This replaces any existing source transforms.
341
- */
342
- setSourceTransforms(sourceTransforms) {
343
- this.config.sourceTransforms.clear();
344
- for (const sourceTransform of sourceTransforms) {
345
- this.addSourceTransform(sourceTransform.name, sourceTransform);
346
- }
347
- return this;
348
- }
349
- /**
350
- * Adds a loader to the application.
351
- *
352
- * @param name - The name of the loader
353
- * @param loader - The build plugin to use as a loader
354
- * @returns The ConfigBuilder instance for method chaining
355
- * @throws Error if a loader with the same name already exists
356
- */
357
- addLoader(name, loader) {
358
- if (this.config.loaders.has(name)) {
359
- throw new Error(CONFIG_BUILDER_ERRORS.duplicateLoaderName(name));
360
- }
361
- this.config.loaders.set(name, loader);
362
- return this;
363
- }
364
- /**
365
- * Adds a source transform to the application.
366
- *
367
- * @throws Error if a source transform with the same name already exists.
368
- */
369
- addSourceTransform(name, sourceTransform) {
370
- if (this.config.sourceTransforms.has(name)) {
371
- throw new Error(CONFIG_BUILDER_ERRORS.duplicateLoaderName(name));
372
- }
373
- this.config.sourceTransforms.set(name, sourceTransform);
374
- return this;
375
- }
376
- /**
377
- * Sets the cache configuration for ISR and page caching.
378
- *
379
- * @param cacheConfig - The cache configuration object
380
- * @returns The ConfigBuilder instance for method chaining
381
- */
382
- setCacheConfig(cacheConfig) {
383
- this.config.cache = cacheConfig;
384
- return this;
385
- }
386
- setExperimental(experimental) {
387
- this.config.experimental = experimental;
388
- return this;
389
- }
390
- createAbsolutePaths(config) {
391
- const { srcDir, componentsDir, includesDir, layoutsDir, pagesDir, publicDir, distDir, workDir } = config;
392
- const projectDir = config.rootDir;
393
- const absoluteSrcDir = path.resolve(projectDir, srcDir);
394
- const absoluteDistDir = path.resolve(projectDir, distDir);
395
- const absoluteWorkDir = path.resolve(projectDir, workDir);
396
- const absoluteIncludesDir = path.join(absoluteSrcDir, includesDir);
397
- const absolutePagesDir = path.join(absoluteSrcDir, pagesDir);
398
- this.config.absolutePaths = {
399
- config: path.join(projectDir, "eco.config.ts"),
400
- projectDir,
401
- srcDir: absoluteSrcDir,
402
- distDir: absoluteDistDir,
403
- workDir: absoluteWorkDir,
404
- componentsDir: path.join(absoluteSrcDir, componentsDir),
405
- includesDir: absoluteIncludesDir,
406
- layoutsDir: path.join(absoluteSrcDir, layoutsDir),
407
- pagesDir: absolutePagesDir,
408
- publicDir: path.join(absoluteSrcDir, publicDir),
409
- htmlTemplatePath: this.resolveSemanticTemplatePath({
410
- dirPath: absoluteIncludesDir,
411
- basename: "html"
412
- }),
413
- error404TemplatePath: this.resolveSemanticTemplatePath({
414
- dirPath: absolutePagesDir,
415
- basename: "404"
416
- }),
417
- error500TemplatePath: this.resolveSemanticTemplatePath({
418
- dirPath: absolutePagesDir,
419
- basename: "500"
420
- })
421
- };
422
- return this;
423
- }
424
- resolveSemanticTemplatePath({
425
- dirPath,
426
- basename
427
- }) {
428
- const extensions = this.config.templatesExt.length > 0 ? this.config.templatesExt : [".ghtml.ts"];
429
- const matches = extensions.map((extension) => path.join(dirPath, `${basename}${extension}`)).filter((candidate) => fileSystem.exists(candidate));
430
- invariant(matches.length <= 1, CONFIG_BUILDER_ERRORS.duplicateSemanticTemplate(basename, matches));
431
- if (matches.length === 1) {
432
- return matches[0];
433
- }
434
- return path.join(dirPath, `${basename}${extensions[0]}`);
435
- }
436
- createIntegrationTemplatesExt(integrations) {
437
- const integrationName = integrations.map((integration) => integration.name);
438
- const uniqueName = new Set(integrationName);
439
- invariant(integrationName.length === uniqueName.size, CONFIG_BUILDER_ERRORS.DUPLICATE_INTEGRATION_NAMES);
440
- const hasKitaJs = uniqueName.has("kitajs");
441
- const hasReact = uniqueName.has("react");
442
- if (hasKitaJs && hasReact) {
443
- appLogger.debug(CONFIG_BUILDER_ERRORS.MIXED_JSX_ENGINES);
444
- }
445
- const integrationsExtensions = integrations.flatMap((integration) => integration.extensions);
446
- const uniqueExtensions = new Set(integrationsExtensions);
447
- invariant(
448
- integrationsExtensions.length === uniqueExtensions.size,
449
- CONFIG_BUILDER_ERRORS.DUPLICATE_INTEGRATION_EXTENSIONS
450
- );
451
- this.config.templatesExt = integrationsExtensions;
452
- }
453
- initializeProcessors() {
454
- for (const processor of this.config.processors.values()) {
455
- processor.setContext(this.config);
456
- }
457
- }
458
- validateRuntimeCapabilities() {
459
- const runtimeEnvironment = this.detectRuntimeEnvironment();
460
- const contributors = [
461
- ...this.config.integrations.map((integration) => ({
462
- kind: "integration",
463
- name: integration.name,
464
- runtimeCapability: integration.runtimeCapability
465
- })),
466
- ...Array.from(this.config.processors.values(), (processor) => ({
467
- kind: "processor",
468
- name: processor.name,
469
- runtimeCapability: processor.runtimeCapability
470
- }))
471
- ];
472
- for (const contributor of contributors) {
473
- this.validateRuntimeCapability(contributor, runtimeEnvironment);
474
- }
475
- }
476
- validateRuntimeCapability(contributor, environment) {
477
- const declaration = contributor.runtimeCapability;
478
- if (!declaration) {
479
- return;
480
- }
481
- for (const tag of declaration.tags) {
482
- if (environment.supportedTags.has(tag)) {
483
- continue;
484
- }
485
- throw new Error(
486
- CONFIG_BUILDER_ERRORS.incompatibleRuntimeCapability(
487
- contributor.kind,
488
- contributor.name,
489
- environment.runtime,
490
- this.describeUnsupportedRuntimeTag(tag)
491
- )
492
- );
493
- }
494
- if (!declaration.minRuntimeVersion) {
495
- return;
496
- }
497
- const minVersion = this.parseVersion(declaration.minRuntimeVersion);
498
- if (!minVersion) {
499
- throw new Error(
500
- CONFIG_BUILDER_ERRORS.invalidRuntimeVersion(
501
- contributor.kind,
502
- contributor.name,
503
- declaration.minRuntimeVersion
504
- )
505
- );
506
- }
507
- const currentVersion = this.parseVersion(environment.version);
508
- if (!currentVersion) {
509
- return;
510
- }
511
- if (this.compareVersions(currentVersion, minVersion) >= 0) {
512
- return;
513
- }
514
- throw new Error(
515
- CONFIG_BUILDER_ERRORS.unsupportedRuntimeVersion(
516
- contributor.kind,
517
- contributor.name,
518
- environment.runtime,
519
- environment.version,
520
- declaration.minRuntimeVersion
521
- )
522
- );
523
- }
524
- detectRuntimeEnvironment() {
525
- const bunVersion = this.getBunVersion();
526
- if (bunVersion) {
527
- return {
528
- runtime: "bun",
529
- version: bunVersion,
530
- supportedTags: /* @__PURE__ */ new Set([
531
- "bun-only",
532
- "node-compatible",
533
- "requires-native-bun-api",
534
- "requires-node-builtins"
535
- ])
536
- };
537
- }
538
- return {
539
- runtime: "node",
540
- version: process.versions.node,
541
- supportedTags: /* @__PURE__ */ new Set(["node-compatible", "requires-node-builtins"])
542
- };
543
- }
544
- getBunVersion() {
545
- const bun = globalThis;
546
- return typeof bun.Bun?.version === "string" ? bun.Bun.version : void 0;
547
- }
548
- describeUnsupportedRuntimeTag(tag) {
549
- switch (tag) {
550
- case "bun-only":
551
- return "it is Bun-only";
552
- case "requires-native-bun-api":
553
- return "it requires the native Bun API";
554
- case "requires-node-builtins":
555
- return "it requires Node builtins";
556
- case "node-compatible":
557
- return "it requires a Node-compatible runtime";
558
- }
559
- }
560
- parseVersion(version) {
561
- const normalized = version.trim().replace(/^v/i, "");
562
- if (!/^\d+(?:\.\d+)*$/.test(normalized)) {
563
- return void 0;
564
- }
565
- return normalized.split(".").map((segment) => Number(segment));
566
- }
567
- compareVersions(left, right) {
568
- const maxLength = Math.max(left.length, right.length);
569
- for (let index = 0; index < maxLength; index += 1) {
570
- const leftValue = left[index] ?? 0;
571
- const rightValue = right[index] ?? 0;
572
- if (leftValue > rightValue) {
573
- return 1;
574
- }
575
- if (leftValue < rightValue) {
576
- return -1;
577
- }
578
- }
579
- return 0;
580
- }
581
- /**
582
- * Initializes default loaders that are required for EcoPages to function.
583
- *
584
- * @remarks
585
- * `eco-component-meta` is registered twice on purpose:
586
- *
587
- * - `sourceTransforms` is the canonical browser/HMR path. The Rolldown bridge
588
- * runs these after first-wins `onLoad` plugins rewrite module source.
589
- * - `loaders` keeps the same transform available to server-oriented builds
590
- * that still use competing `onLoad` handlers directly.
591
- *
592
- * Browser builds exclude the loader copy in {@link getAppBrowserBuildPlugins}
593
- * when the transform name is already present in `sourceTransforms`.
594
- */
595
- async initializeDefaultLoaders() {
596
- const componentMetaTransform = createEcoComponentMetaTransform({ config: this.config });
597
- if (!this.config.sourceTransforms.has(componentMetaTransform.name)) {
598
- this.config.sourceTransforms.set(componentMetaTransform.name, componentMetaTransform);
599
- }
600
- const componentMetaPlugin = createEcoComponentMetaPlugin({ config: this.config });
601
- if (!this.config.loaders.has(componentMetaPlugin.name)) {
602
- this.config.loaders.set(componentMetaPlugin.name, componentMetaPlugin);
603
- }
604
- }
605
- reviewBaseUrl(baseUrl) {
606
- if (baseUrl) {
607
- this.config.baseUrl = baseUrl;
608
- return;
609
- }
610
- const envBaseUrl = process.env.ECOPAGES_BASE_URL;
611
- if (envBaseUrl) {
612
- this.config.baseUrl = envBaseUrl;
613
- } else if (!this.config.baseUrl) {
614
- this.config.baseUrl = `http://${DEFAULT_ECOPAGES_HOSTNAME}:${DEFAULT_ECOPAGES_PORT}`;
615
- }
616
- }
617
- /**
618
- * Builds and returns the final configuration object.
619
- * This performs validation and initialization of the configuration.
620
- *
621
- * @returns A promise that resolves to the final EcoPagesAppConfig
622
- * @throws Error if required configuration is missing (e.g., baseUrl)
623
- */
624
- async build() {
625
- this.reviewBaseUrl(this.config.baseUrl);
626
- if (!this.config.integrations.some((integration) => integration.name === GHTML_PLUGIN_NAME)) {
627
- this.config.integrations.push(ghtmlPlugin());
628
- }
629
- this.createIntegrationTemplatesExt(this.config.integrations);
630
- this.createAbsolutePaths(this.config);
631
- await this.initializeDefaultLoaders();
632
- this.initializeProcessors();
633
- this.validateRuntimeCapabilities();
634
- const buildAdapter = createBuildAdapter({ ownership: this.buildOwnership });
635
- setAppBuildAdapter(this.config, buildAdapter);
636
- updateAppBuildManifest(this.config, await collectConfiguredAppBuildManifestContributions(this.config));
637
- setAppServerInvalidationState(this.config, new CounterServerInvalidationState());
638
- setAppEntrypointDependencyGraph(this.config, new NoopEntrypointDependencyGraph());
639
- return this.config;
640
- }
100
+ /**
101
+ * Sets the base URL for the application.
102
+ * This URL is used as the root URL for all pages and assets.
103
+ *
104
+ * @param baseUrl - The base URL for the application (e.g., 'https://example.com')
105
+ * @returns The ConfigBuilder instance for method chaining
106
+ */
107
+ setBaseUrl(baseUrl) {
108
+ this.config.baseUrl = baseUrl;
109
+ return this;
110
+ }
111
+ /**
112
+ * Sets the root directory of the project.
113
+ * This is the base directory from which all other paths are resolved.
114
+ *
115
+ * @param rootDir - The root directory path
116
+ * @returns The ConfigBuilder instance for method chaining
117
+ */
118
+ setRootDir(rootDir) {
119
+ this.config.rootDir = rootDir;
120
+ return this;
121
+ }
122
+ /**
123
+ * Sets which runtime path owns build execution for the finalized app config.
124
+ *
125
+ * @remarks
126
+ * Three ownership values are accepted:
127
+ *
128
+ * - `'rolldown'` (default): Ecopages runs builds through
129
+ * {@link RolldownBuildAdapter}, creating a new `rolldown()` instance
130
+ * per build.
131
+ * - `'vite-host'`: a host runtime owns the build. Ecopages exposes a
132
+ * {@link ViteHostBuildAdapter} boundary marker that throws on direct
133
+ * use. Select this only for host-driven compatibility flows where
134
+ * core must not silently fall back to app build execution.
135
+ *
136
+ * Defaults to `'rolldown'` when {@link ConfigBuilder.build} runs
137
+ * without an explicit ownership.
138
+ */
139
+ setBuildOwnership(buildOwnership) {
140
+ this.buildOwnership = buildOwnership;
141
+ return this;
142
+ }
143
+ /**
144
+ * Sets the source directory relative to the root directory.
145
+ * This directory contains all the source files for the application.
146
+ *
147
+ * @param srcDir - The source directory name (default: 'src')
148
+ * @returns The ConfigBuilder instance for method chaining
149
+ */
150
+ setSrcDir(srcDir) {
151
+ this.config.srcDir = srcDir;
152
+ return this;
153
+ }
154
+ /**
155
+ * Sets the pages directory relative to the source directory.
156
+ * This directory contains all the page files for the application.
157
+ *
158
+ * @param pagesDir - The pages directory name (default: 'pages')
159
+ * @returns The ConfigBuilder instance for method chaining
160
+ */
161
+ setPagesDir(pagesDir) {
162
+ this.config.pagesDir = pagesDir;
163
+ return this;
164
+ }
165
+ /**
166
+ * Sets the includes directory relative to the source directory.
167
+ * This directory contains template includes and partials.
168
+ *
169
+ * @param includesDir - The includes directory name (default: 'includes')
170
+ * @returns The ConfigBuilder instance for method chaining
171
+ */
172
+ setIncludesDir(includesDir) {
173
+ this.config.includesDir = includesDir;
174
+ return this;
175
+ }
176
+ /**
177
+ * Sets the components directory relative to the source directory.
178
+ * This directory contains reusable components.
179
+ *
180
+ * @param componentsDir - The components directory name (default: 'components')
181
+ * @returns The ConfigBuilder instance for method chaining
182
+ */
183
+ setComponentsDir(componentsDir) {
184
+ this.config.componentsDir = componentsDir;
185
+ return this;
186
+ }
187
+ /**
188
+ * Sets the layouts directory relative to the source directory.
189
+ * This directory contains layout templates.
190
+ *
191
+ * @param layoutsDir - The layouts directory name (default: 'layouts')
192
+ * @returns The ConfigBuilder instance for method chaining
193
+ */
194
+ setLayoutsDir(layoutsDir) {
195
+ this.config.layoutsDir = layoutsDir;
196
+ return this;
197
+ }
198
+ /**
199
+ * Sets the public directory relative to the source directory.
200
+ * This directory contains static assets that should be served as-is.
201
+ *
202
+ * @param publicDir - The public directory name (default: 'public')
203
+ * @returns The ConfigBuilder instance for method chaining
204
+ */
205
+ setPublicDir(publicDir) {
206
+ this.config.publicDir = publicDir;
207
+ return this;
208
+ }
209
+ /**
210
+ * Sets the robots.txt configuration.
211
+ * This determines which paths are allowed/disallowed for search engines.
212
+ *
213
+ * @param robotsTxt - The robots.txt configuration object
214
+ * @returns The ConfigBuilder instance for method chaining
215
+ */
216
+ setRobotsTxt(robotsTxt) {
217
+ this.config.robotsTxt = robotsTxt;
218
+ return this;
219
+ }
220
+ /**
221
+ * Sets automatic sitemap.xml generation during static export.
222
+ *
223
+ * @remarks
224
+ * Merged over `{ enabled: false, fileName: 'sitemap.xml', extraUrls: [], exclude: [] }`.
225
+ * Existing apps stay unchanged until `enabled: true` is set. Page-level
226
+ * `metadata.robots.index: false` and metadata resolution failures are handled
227
+ * during static generation (not by this config merge).
228
+ */
229
+ setSitemap(sitemap) {
230
+ const defaults = {
231
+ enabled: false,
232
+ fileName: 'sitemap.xml',
233
+ extraUrls: [],
234
+ exclude: [],
235
+ };
236
+ this.config.sitemap = {
237
+ ...defaults,
238
+ ...this.config.sitemap,
239
+ ...sitemap,
240
+ extraUrls: sitemap.extraUrls ?? this.config.sitemap.extraUrls ?? defaults.extraUrls,
241
+ exclude: sitemap.exclude ?? this.config.sitemap.exclude ?? defaults.exclude,
242
+ };
243
+ return this;
244
+ }
245
+ /**
246
+ * Configures the in-browser development toolbar shown during watch mode.
247
+ *
248
+ * @remarks
249
+ * Requires `package` to point at a browser bootstrap module installed in the app.
250
+ * Prefer {@link defineDevTool} for config authoring.
251
+ */
252
+ setDevToolbar(devToolbar) {
253
+ this.config.devToolbar = {
254
+ ...this.config.devToolbar,
255
+ ...devToolbar,
256
+ };
257
+ return this;
258
+ }
259
+ /**
260
+ * Sets the integration plugins to use.
261
+ * These plugins provide additional functionality to the application.
262
+ *
263
+ * @param integrations - An array of integration plugins
264
+ * @returns The ConfigBuilder instance for method chaining
265
+ */
266
+ setIntegrations(integrations) {
267
+ this.config.integrations = integrations;
268
+ return this;
269
+ }
270
+ /**
271
+ * Sets the output directory for the built application.
272
+ *
273
+ * @param distDir - The distribution directory name (default: 'dist')
274
+ * @returns The ConfigBuilder instance for method chaining
275
+ */
276
+ setDistDir(distDir) {
277
+ this.config.distDir = distDir;
278
+ return this;
279
+ }
280
+ /**
281
+ * Sets the internal work directory for runtime-only artifacts.
282
+ *
283
+ * @remarks
284
+ * Use this when deployable output should stay clean while Ecopages still
285
+ * needs a separate workspace for server transpilation caches, runtime
286
+ * manifests, and other internal build products.
287
+ *
288
+ * @param workDir - The internal work directory name
289
+ * @returns The ConfigBuilder instance for method chaining
290
+ */
291
+ setWorkDir(workDir) {
292
+ this.config.workDir = workDir;
293
+ return this;
294
+ }
295
+ /**
296
+ * Sets the default metadata for pages.
297
+ * This is used when a page doesn't specify its own metadata.
298
+ *
299
+ * @param defaultMetadata - The default metadata object
300
+ * @returns The ConfigBuilder instance for method chaining
301
+ */
302
+ setDefaultMetadata(defaultMetadata) {
303
+ this.config.defaultMetadata = {
304
+ ...this.config.defaultMetadata,
305
+ ...defaultMetadata,
306
+ };
307
+ return this;
308
+ }
309
+ /**
310
+ * Sets additional paths to watch for changes during development.
311
+ *
312
+ * @param additionalWatchPaths - An array of additional paths to watch
313
+ * @returns The ConfigBuilder instance for method chaining
314
+ */
315
+ setAdditionalWatchPaths(additionalWatchPaths) {
316
+ this.config.additionalWatchPaths = additionalWatchPaths;
317
+ return this;
318
+ }
319
+ /**
320
+ * Sets the processors to use for the application.
321
+ * This replaces any existing processors.
322
+ *
323
+ * @param processors - An array of processors
324
+ * @returns The ConfigBuilder instance for method chaining
325
+ */
326
+ setProcessors(processors) {
327
+ this.config.processors.clear();
328
+ for (const processor of processors) {
329
+ this.addProcessor(processor);
330
+ }
331
+ return this;
332
+ }
333
+ /**
334
+ * Adds a processor to the application.
335
+ *
336
+ * @param processor - The processor to add
337
+ * @returns The ConfigBuilder instance for method chaining
338
+ * @throws Error if a processor with the same name already exists
339
+ */
340
+ addProcessor(processor) {
341
+ if (this.config.processors.has(processor.name)) {
342
+ throw new Error(CONFIG_BUILDER_ERRORS.duplicateProcessorName(processor.name));
343
+ }
344
+ this.config.processors.set(processor.name, processor);
345
+ return this;
346
+ }
347
+ /**
348
+ * Sets the loaders to use for the application.
349
+ * This replaces any existing loaders.
350
+ *
351
+ * @param loaders - An array of build plugins to use as loaders
352
+ * @returns The ConfigBuilder instance for method chaining
353
+ */
354
+ setLoaders(loaders) {
355
+ this.config.loaders.clear();
356
+ for (const loader of loaders) {
357
+ this.addLoader(loader.name, loader);
358
+ }
359
+ return this;
360
+ }
361
+ /**
362
+ * Sets the source transforms to use for transform-first bundlers such as Vite.
363
+ * This replaces any existing source transforms.
364
+ */
365
+ setSourceTransforms(sourceTransforms) {
366
+ this.config.sourceTransforms.clear();
367
+ for (const sourceTransform of sourceTransforms) {
368
+ this.addSourceTransform(sourceTransform.name, sourceTransform);
369
+ }
370
+ return this;
371
+ }
372
+ /**
373
+ * Adds a loader to the application.
374
+ *
375
+ * @param name - The name of the loader
376
+ * @param loader - The build plugin to use as a loader
377
+ * @returns The ConfigBuilder instance for method chaining
378
+ * @throws Error if a loader with the same name already exists
379
+ */
380
+ addLoader(name, loader) {
381
+ if (this.config.loaders.has(name)) {
382
+ throw new Error(CONFIG_BUILDER_ERRORS.duplicateLoaderName(name));
383
+ }
384
+ this.config.loaders.set(name, loader);
385
+ return this;
386
+ }
387
+ /**
388
+ * Adds a source transform to the application.
389
+ *
390
+ * @throws Error if a source transform with the same name already exists.
391
+ */
392
+ addSourceTransform(name, sourceTransform) {
393
+ if (this.config.sourceTransforms.has(name)) {
394
+ throw new Error(CONFIG_BUILDER_ERRORS.duplicateLoaderName(name));
395
+ }
396
+ this.config.sourceTransforms.set(name, sourceTransform);
397
+ return this;
398
+ }
399
+ /**
400
+ * Sets the cache configuration for ISR and page caching.
401
+ *
402
+ * @param cacheConfig - The cache configuration object
403
+ * @returns The ConfigBuilder instance for method chaining
404
+ */
405
+ setCacheConfig(cacheConfig) {
406
+ this.config.cache = cacheConfig;
407
+ return this;
408
+ }
409
+ setExperimental(experimental) {
410
+ this.config.experimental = experimental;
411
+ return this;
412
+ }
413
+ createAbsolutePaths(config) {
414
+ const { srcDir, componentsDir, includesDir, layoutsDir, pagesDir, publicDir, distDir, workDir } = config;
415
+ const projectDir = config.rootDir;
416
+ const absoluteSrcDir = path.resolve(projectDir, srcDir);
417
+ const absoluteDistDir = path.resolve(projectDir, distDir);
418
+ const absoluteWorkDir = path.resolve(projectDir, workDir);
419
+ const absoluteIncludesDir = path.join(absoluteSrcDir, includesDir);
420
+ const absolutePagesDir = path.join(absoluteSrcDir, pagesDir);
421
+ this.config.absolutePaths = {
422
+ config: path.join(projectDir, 'eco.config.ts'),
423
+ projectDir: projectDir,
424
+ srcDir: absoluteSrcDir,
425
+ distDir: absoluteDistDir,
426
+ workDir: absoluteWorkDir,
427
+ componentsDir: path.join(absoluteSrcDir, componentsDir),
428
+ includesDir: absoluteIncludesDir,
429
+ layoutsDir: path.join(absoluteSrcDir, layoutsDir),
430
+ pagesDir: absolutePagesDir,
431
+ publicDir: path.join(absoluteSrcDir, publicDir),
432
+ htmlTemplatePath: this.resolveSemanticTemplatePath({
433
+ dirPath: absoluteIncludesDir,
434
+ basename: 'html',
435
+ }),
436
+ error404TemplatePath: this.resolveSemanticTemplatePath({
437
+ dirPath: absolutePagesDir,
438
+ basename: '404',
439
+ }),
440
+ error500TemplatePath: this.resolveSemanticTemplatePath({
441
+ dirPath: absolutePagesDir,
442
+ basename: '500',
443
+ }),
444
+ };
445
+ return this;
446
+ }
447
+ resolveSemanticTemplatePath({ dirPath, basename, }) {
448
+ const extensions = this.config.templatesExt.length > 0 ? this.config.templatesExt : ['.ghtml.ts'];
449
+ const matches = extensions
450
+ .map((extension) => path.join(dirPath, `${basename}${extension}`))
451
+ .filter((candidate) => fileSystem.exists(candidate));
452
+ invariant(matches.length <= 1, CONFIG_BUILDER_ERRORS.duplicateSemanticTemplate(basename, matches));
453
+ if (matches.length === 1) {
454
+ return matches[0];
455
+ }
456
+ return path.join(dirPath, `${basename}${extensions[0]}`);
457
+ }
458
+ createIntegrationTemplatesExt(integrations) {
459
+ const integrationName = integrations.map((integration) => integration.name);
460
+ const uniqueName = new Set(integrationName);
461
+ invariant(integrationName.length === uniqueName.size, CONFIG_BUILDER_ERRORS.DUPLICATE_INTEGRATION_NAMES);
462
+ const hasKitaJs = uniqueName.has('kitajs');
463
+ const hasReact = uniqueName.has('react');
464
+ if (hasKitaJs && hasReact) {
465
+ appLogger.debug(CONFIG_BUILDER_ERRORS.MIXED_JSX_ENGINES);
466
+ }
467
+ const integrationsExtensions = integrations.flatMap((integration) => integration.extensions);
468
+ const uniqueExtensions = new Set(integrationsExtensions);
469
+ invariant(integrationsExtensions.length === uniqueExtensions.size, CONFIG_BUILDER_ERRORS.DUPLICATE_INTEGRATION_EXTENSIONS);
470
+ this.config.templatesExt = integrationsExtensions;
471
+ }
472
+ initializeProcessors() {
473
+ for (const processor of this.config.processors.values()) {
474
+ processor.setContext(this.config);
475
+ }
476
+ }
477
+ validateRuntimeCapabilities() {
478
+ const runtimeEnvironment = this.detectRuntimeEnvironment();
479
+ const contributors = [
480
+ ...this.config.integrations.map((integration) => ({
481
+ kind: 'integration',
482
+ name: integration.name,
483
+ runtimeCapability: integration.runtimeCapability,
484
+ })),
485
+ ...Array.from(this.config.processors.values(), (processor) => ({
486
+ kind: 'processor',
487
+ name: processor.name,
488
+ runtimeCapability: processor.runtimeCapability,
489
+ })),
490
+ ];
491
+ for (const contributor of contributors) {
492
+ this.validateRuntimeCapability(contributor, runtimeEnvironment);
493
+ }
494
+ }
495
+ validateRuntimeCapability(contributor, environment) {
496
+ const declaration = contributor.runtimeCapability;
497
+ if (!declaration) {
498
+ return;
499
+ }
500
+ for (const tag of declaration.tags) {
501
+ if (environment.supportedTags.has(tag)) {
502
+ continue;
503
+ }
504
+ throw new Error(CONFIG_BUILDER_ERRORS.incompatibleRuntimeCapability(contributor.kind, contributor.name, environment.runtime, this.describeUnsupportedRuntimeTag(tag)));
505
+ }
506
+ if (!declaration.minRuntimeVersion) {
507
+ return;
508
+ }
509
+ const minVersion = this.parseVersion(declaration.minRuntimeVersion);
510
+ if (!minVersion) {
511
+ throw new Error(CONFIG_BUILDER_ERRORS.invalidRuntimeVersion(contributor.kind, contributor.name, declaration.minRuntimeVersion));
512
+ }
513
+ const currentVersion = this.parseVersion(environment.version);
514
+ if (!currentVersion) {
515
+ return;
516
+ }
517
+ if (this.compareVersions(currentVersion, minVersion) >= 0) {
518
+ return;
519
+ }
520
+ throw new Error(CONFIG_BUILDER_ERRORS.unsupportedRuntimeVersion(contributor.kind, contributor.name, environment.runtime, environment.version, declaration.minRuntimeVersion));
521
+ }
522
+ detectRuntimeEnvironment() {
523
+ const bunVersion = this.getBunVersion();
524
+ if (bunVersion) {
525
+ return {
526
+ runtime: 'bun',
527
+ version: bunVersion,
528
+ supportedTags: new Set([
529
+ 'bun-only',
530
+ 'node-compatible',
531
+ 'requires-native-bun-api',
532
+ 'requires-node-builtins',
533
+ ]),
534
+ };
535
+ }
536
+ return {
537
+ runtime: 'node',
538
+ version: process.versions.node,
539
+ supportedTags: new Set(['node-compatible', 'requires-node-builtins']),
540
+ };
541
+ }
542
+ getBunVersion() {
543
+ const bun = globalThis;
544
+ return typeof bun.Bun?.version === 'string' ? bun.Bun.version : undefined;
545
+ }
546
+ describeUnsupportedRuntimeTag(tag) {
547
+ switch (tag) {
548
+ case 'bun-only':
549
+ return 'it is Bun-only';
550
+ case 'requires-native-bun-api':
551
+ return 'it requires the native Bun API';
552
+ case 'requires-node-builtins':
553
+ return 'it requires Node builtins';
554
+ case 'node-compatible':
555
+ return 'it requires a Node-compatible runtime';
556
+ }
557
+ }
558
+ parseVersion(version) {
559
+ const normalized = version.trim().replace(/^v/i, '');
560
+ if (!/^\d+(?:\.\d+)*$/.test(normalized)) {
561
+ return undefined;
562
+ }
563
+ return normalized.split('.').map((segment) => Number(segment));
564
+ }
565
+ compareVersions(left, right) {
566
+ const maxLength = Math.max(left.length, right.length);
567
+ for (let index = 0; index < maxLength; index += 1) {
568
+ const leftValue = left[index] ?? 0;
569
+ const rightValue = right[index] ?? 0;
570
+ if (leftValue > rightValue) {
571
+ return 1;
572
+ }
573
+ if (leftValue < rightValue) {
574
+ return -1;
575
+ }
576
+ }
577
+ return 0;
578
+ }
579
+ /**
580
+ * Initializes default loaders that are required for EcoPages to function.
581
+ *
582
+ * @remarks
583
+ * `eco-component-meta` is registered twice on purpose:
584
+ *
585
+ * - `sourceTransforms` is the canonical browser/HMR path. The Rolldown bridge
586
+ * runs these after first-wins `onLoad` plugins rewrite module source.
587
+ * - `loaders` keeps the same transform available to server-oriented builds
588
+ * that still use competing `onLoad` handlers directly.
589
+ *
590
+ * Browser builds exclude the loader copy in {@link getAppBrowserBuildPlugins}
591
+ * when the transform name is already present in `sourceTransforms`.
592
+ */
593
+ async initializeDefaultLoaders() {
594
+ const componentMetaTransform = createEcoComponentMetaTransform({ config: this.config });
595
+ if (!this.config.sourceTransforms.has(componentMetaTransform.name)) {
596
+ this.config.sourceTransforms.set(componentMetaTransform.name, componentMetaTransform);
597
+ }
598
+ const componentMetaPlugin = createEcoComponentMetaPlugin({ config: this.config });
599
+ if (!this.config.loaders.has(componentMetaPlugin.name)) {
600
+ this.config.loaders.set(componentMetaPlugin.name, componentMetaPlugin);
601
+ }
602
+ }
603
+ reviewBaseUrl(baseUrl) {
604
+ if (baseUrl) {
605
+ this.config.baseUrl = baseUrl;
606
+ return;
607
+ }
608
+ const envBaseUrl = process.env.ECOPAGES_BASE_URL;
609
+ if (envBaseUrl) {
610
+ this.config.baseUrl = envBaseUrl;
611
+ }
612
+ else if (!this.config.baseUrl) {
613
+ this.config.baseUrl = `http://${DEFAULT_ECOPAGES_HOSTNAME}:${DEFAULT_ECOPAGES_PORT}`;
614
+ }
615
+ }
616
+ /**
617
+ * Builds and returns the final configuration object.
618
+ * This performs validation and initialization of the configuration.
619
+ *
620
+ * @returns A promise that resolves to the final EcoPagesAppConfig
621
+ * @throws Error if required configuration is missing (e.g., baseUrl)
622
+ */
623
+ async build() {
624
+ this.reviewBaseUrl(this.config.baseUrl);
625
+ if (!this.config.integrations.some((integration) => integration.name === GHTML_PLUGIN_NAME)) {
626
+ this.config.integrations.push(ghtmlPlugin());
627
+ }
628
+ this.createIntegrationTemplatesExt(this.config.integrations);
629
+ this.createAbsolutePaths(this.config);
630
+ await this.initializeDefaultLoaders();
631
+ this.initializeProcessors();
632
+ this.validateRuntimeCapabilities();
633
+ const buildAdapter = createBuildAdapter({ ownership: this.buildOwnership });
634
+ setAppBuildAdapter(this.config, buildAdapter);
635
+ updateAppBuildManifest(this.config, await collectConfiguredAppBuildManifestContributions(this.config));
636
+ setAppServerInvalidationState(this.config, new CounterServerInvalidationState());
637
+ setAppEntrypointDependencyGraph(this.config, new NoopEntrypointDependencyGraph());
638
+ return this.config;
639
+ }
641
640
  }
642
- export {
643
- CONFIG_BUILDER_ERRORS,
644
- ConfigBuilder
645
- };