@ecopages/core 0.2.0-rc.1 → 0.2.0-rc.11

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 (278) hide show
  1. package/README.md +50 -41
  2. package/package.json +50 -145
  3. package/src/adapters/README.md +11 -3
  4. package/src/adapters/abstract/application-adapter.d.ts +32 -36
  5. package/src/adapters/abstract/application-adapter.js +61 -47
  6. package/src/adapters/abstract/segment-path-matcher.js +56 -38
  7. package/src/adapters/abstract/server-adapter.d.ts +14 -0
  8. package/src/adapters/abstract/server-adapter.js +10 -0
  9. package/src/adapters/abstract/ws-pattern-matcher.d.ts +0 -5
  10. package/src/adapters/abstract/ws-pattern-matcher.js +0 -9
  11. package/src/adapters/bun/create-app.d.ts +15 -15
  12. package/src/adapters/bun/create-app.js +52 -67
  13. package/src/adapters/bun/hmr-manager.d.ts +0 -1
  14. package/src/adapters/bun/hmr-manager.js +2 -4
  15. package/src/adapters/bun/server-adapter.d.ts +15 -21
  16. package/src/adapters/bun/server-adapter.js +33 -67
  17. package/src/adapters/bun/static-preview-host.d.ts +1 -0
  18. package/src/adapters/bun/static-preview-host.js +1 -1
  19. package/src/adapters/create-app.d.ts +63 -8
  20. package/src/adapters/create-app.js +62 -5
  21. package/src/adapters/node/create-app.d.ts +8 -12
  22. package/src/adapters/node/create-app.js +22 -14
  23. package/src/adapters/node/runtime-host.d.ts +10 -10
  24. package/src/adapters/node/runtime-host.js +13 -8
  25. package/src/adapters/node/server-adapter-dependencies.d.ts +2 -10
  26. package/src/adapters/node/server-adapter-dependencies.js +8 -13
  27. package/src/adapters/node/server-adapter.d.ts +30 -32
  28. package/src/adapters/node/server-adapter.js +59 -65
  29. package/src/adapters/shared/hmr/shared-hmr-manager.d.ts +0 -4
  30. package/src/adapters/shared/hmr/shared-hmr-manager.js +0 -12
  31. package/src/adapters/shared/http/api-request-pipeline.d.ts +27 -1
  32. package/src/adapters/shared/http/api-request-pipeline.js +31 -16
  33. package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
  34. package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -9
  35. package/src/adapters/shared/http/fs-server-response-factory.js +5 -33
  36. package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
  37. package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
  38. package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
  39. package/src/adapters/shared/runtime/application-adapter.js +12 -0
  40. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
  41. package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
  42. package/src/adapters/shared/runtime/collect-dev-prewarm-plan.d.ts +1 -3
  43. package/src/adapters/shared/runtime/collect-dev-prewarm-plan.js +1 -4
  44. package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
  45. package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
  46. package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
  47. package/src/adapters/shared/runtime/port-manager.js +14 -45
  48. package/src/adapters/shared/runtime/runtime-app-bootstrap.d.ts +0 -10
  49. package/src/adapters/shared/runtime/runtime-app-bootstrap.js +0 -7
  50. package/src/adapters/shared/runtime/runtime-host.d.ts +5 -2
  51. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +1 -1
  52. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +1 -1
  53. package/src/adapters/shared/runtime/server-adapter.d.ts +27 -5
  54. package/src/adapters/shared/runtime/server-adapter.js +44 -30
  55. package/src/adapters/shared/runtime/server-route-handler.js +11 -3
  56. package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
  57. package/src/adapters/shared/runtime/server-static-builder.js +59 -37
  58. package/src/adapters/shared/ws/node-http-websocket-upgrades.d.ts +9 -1
  59. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +8 -2
  60. package/src/build/README.md +9 -6
  61. package/src/build/cache/cache-constants.d.ts +0 -2
  62. package/src/build/cache/cache-constants.js +0 -2
  63. package/src/build/cache/cache-keys.d.ts +0 -2
  64. package/src/build/cache/cache-keys.js +0 -2
  65. package/src/build/cache/output-imports.d.ts +27 -0
  66. package/src/build/cache/output-imports.js +80 -0
  67. package/src/build/cache/pages-unified-graph-build.d.ts +6 -1
  68. package/src/build/cache/pages-unified-graph-build.js +42 -17
  69. package/src/build/cache/production-build-cache.d.ts +2 -2
  70. package/src/build/cache/production-build-cache.js +2 -2
  71. package/src/build/cache/server-entry-build-cache.d.ts +25 -3
  72. package/src/build/cache/server-entry-build-cache.js +129 -13
  73. package/src/build/contracts/build-contracts.d.ts +1 -13
  74. package/src/build/contracts/content-virtual-modules.d.ts +3 -1
  75. package/src/build/contracts/content-virtual-modules.js +8 -0
  76. package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
  77. package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
  78. package/src/build/rolldown/runtime-build-output-normalizer.js +3 -6
  79. package/src/build/runtime/build-request-identity.d.ts +2 -6
  80. package/src/build/runtime/build-request-identity.js +2 -8
  81. package/src/build/runtime/build-request-policy.js +1 -1
  82. package/src/build/runtime/deduping-build-executor.d.ts +0 -1
  83. package/src/build/runtime/deduping-build-executor.js +0 -1
  84. package/src/build/server-bundle-publication.d.ts +14 -0
  85. package/src/build/server-bundle-publication.js +49 -0
  86. package/src/cache/index.d.ts +1 -1
  87. package/src/cache/index.js +1 -1
  88. package/src/cache/module-parse-cache.d.ts +2 -29
  89. package/src/cache/module-parse-cache.js +6 -39
  90. package/src/config/README.md +17 -2
  91. package/src/config/apply-user-config.d.ts +8 -0
  92. package/src/config/apply-user-config.js +68 -0
  93. package/src/config/config-builder.d.ts +11 -1
  94. package/src/config/config-builder.js +53 -12
  95. package/src/config/constants.d.ts +4 -4
  96. package/src/config/constants.js +4 -4
  97. package/src/config/define-config.d.ts +9 -0
  98. package/src/config/define-config.js +10 -0
  99. package/src/config/index.d.ts +5 -0
  100. package/src/config/index.js +4 -0
  101. package/src/config/is-finalized-app-config.d.ts +6 -0
  102. package/src/config/is-finalized-app-config.js +11 -0
  103. package/src/config/load-eco-config.d.ts +21 -0
  104. package/src/config/load-eco-config.js +107 -0
  105. package/src/config/resolve-eco-config-path.d.ts +32 -0
  106. package/src/config/resolve-eco-config-path.js +58 -0
  107. package/src/config/server-config-bundle.d.ts +25 -0
  108. package/src/config/server-config-bundle.js +148 -0
  109. package/src/config/user-config-types.d.ts +170 -0
  110. package/src/config/user-config-types.js +1 -0
  111. package/src/css-imports.d.ts +4 -0
  112. package/src/declarations.d.ts +11 -5
  113. package/src/dev/README.md +6 -0
  114. package/src/dev/development-restart-watch-paths.d.ts +13 -0
  115. package/src/dev/development-restart-watch-paths.js +37 -0
  116. package/src/dev/development-restart.d.ts +13 -0
  117. package/src/dev/development-restart.js +21 -0
  118. package/src/dev/host-runtime.d.ts +0 -1
  119. package/src/dev/host-runtime.js +0 -3
  120. package/src/dev/sc-server.d.ts +4 -1
  121. package/src/dev/sc-server.js +11 -20
  122. package/src/dev/transform-server/dev-transform-import-rewriter.js +2 -2
  123. package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
  124. package/src/dev/transform-server/dev-transform-server.js +16 -5
  125. package/src/eco/README.md +73 -5
  126. package/src/eco/component-identity.d.ts +3 -2
  127. package/src/eco/component-identity.js +5 -2
  128. package/src/eco/discovered-dependencies.d.ts +45 -0
  129. package/src/eco/discovered-dependencies.js +87 -0
  130. package/src/eco/eco.js +6 -0
  131. package/src/eco/eco.types.d.ts +18 -2
  132. package/src/eco/lazy-injector-map.js +57 -41
  133. package/src/eco/page-dependency-contributions.d.ts +19 -0
  134. package/src/eco/page-dependency-contributions.js +52 -0
  135. package/src/errors/http-error-page-contract.d.ts +77 -0
  136. package/src/errors/http-error-page-contract.js +106 -0
  137. package/src/hmr/hmr-file-change-prep.d.ts +0 -1
  138. package/src/hmr/hmr-file-change-prep.js +2 -5
  139. package/src/hmr/hmr-strategy.d.ts +3 -8
  140. package/src/hmr/hmr-strategy.js +3 -8
  141. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
  142. package/src/hmr/strategies/js-hmr-strategy.js +24 -16
  143. package/src/index.browser.d.ts +2 -0
  144. package/src/index.browser.js +2 -0
  145. package/src/index.d.ts +5 -3
  146. package/src/index.js +5 -3
  147. package/src/islands/README.md +5 -1
  148. package/src/islands/island-host.d.ts +0 -9
  149. package/src/islands/island-host.js +1 -13
  150. package/src/plugins/README.md +8 -1
  151. package/src/plugins/component-import-discovery.d.ts +19 -0
  152. package/src/plugins/component-import-discovery.js +241 -0
  153. package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
  154. package/src/plugins/eco-component-meta-plugin.js +120 -18
  155. package/src/plugins/integration-plugin.d.ts +0 -1
  156. package/src/plugins/integration-plugin.js +0 -4
  157. package/src/plugins/processor.d.ts +10 -2
  158. package/src/plugins/processor.js +4 -0
  159. package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
  160. package/src/plugins/tsconfig-import-resolver.js +4 -2
  161. package/src/route-renderer/GRAPH.md +1 -1
  162. package/src/route-renderer/README.md +15 -2
  163. package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
  164. package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
  165. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
  166. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
  167. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +80 -0
  168. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
  169. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
  170. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -0
  171. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
  172. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
  173. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
  174. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +3 -4
  175. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
  176. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
  177. package/src/route-renderer/orchestration/integration-renderer.d.ts +9 -11
  178. package/src/route-renderer/orchestration/integration-renderer.js +43 -40
  179. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +1 -1
  180. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
  181. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
  182. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
  183. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -1
  184. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +1 -1
  185. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
  186. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
  187. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +8 -10
  188. package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
  189. package/src/route-renderer/orchestration/string-markup-renderer.js +2 -1
  190. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
  191. package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
  192. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
  193. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
  194. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
  195. package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
  196. package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
  197. package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
  198. package/src/route-renderer/route-renderer.d.ts +9 -0
  199. package/src/route-renderer/route-renderer.js +18 -0
  200. package/src/router/README.md +7 -1
  201. package/src/router/server/route-registry.d.ts +13 -0
  202. package/src/router/server/route-registry.js +46 -32
  203. package/src/services/README.md +6 -1
  204. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
  205. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
  206. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
  207. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
  208. package/src/services/assets/asset-processing-service/page-package.js +42 -39
  209. package/src/services/assets/browser-bundle.service.d.ts +1 -6
  210. package/src/services/error-pages/README.md +9 -0
  211. package/src/services/error-pages/default-error-pages.d.ts +39 -0
  212. package/src/services/error-pages/default-error-pages.js +199 -0
  213. package/src/services/error-pages/error-page-renderer.d.ts +58 -0
  214. package/src/services/error-pages/error-page-renderer.js +146 -0
  215. package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
  216. package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
  217. package/src/services/html/html-rewriter.d.ts +77 -0
  218. package/src/services/html/html-rewriter.js +751 -0
  219. package/src/services/html/html-rewriter.parity.test.bun.d.ts +1 -0
  220. package/src/services/html/html-rewriter.parity.test.bun.js +74 -0
  221. package/src/services/html/html-transformer.service.d.ts +26 -39
  222. package/src/services/html/html-transformer.service.js +81 -153
  223. package/src/services/invalidation/development-invalidation.service.d.ts +9 -20
  224. package/src/services/invalidation/development-invalidation.service.js +35 -41
  225. package/src/services/module-loading/README.md +17 -14
  226. package/src/services/module-loading/app-module-loader.service.d.ts +0 -2
  227. package/src/services/module-loading/app-server-module-transpiler.service.d.ts +1 -1
  228. package/src/services/module-loading/app-server-module-transpiler.service.js +2 -10
  229. package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -1
  230. package/src/services/module-loading/collection-server-module-build.service.js +5 -5
  231. package/src/services/module-loading/host-module-loader-registry.d.ts +0 -1
  232. package/src/services/module-loading/host-module-loader-registry.js +0 -3
  233. package/src/services/module-loading/page-module-import.service.d.ts +8 -0
  234. package/src/services/module-loading/page-module-import.service.js +62 -28
  235. package/src/services/module-loading/route-module-build-cache-registry.d.ts +0 -4
  236. package/src/services/module-loading/route-module-build-cache-registry.js +0 -4
  237. package/src/services/module-loading/route-module-build-cache.store.d.ts +3 -0
  238. package/src/services/module-loading/route-module-build-cache.store.js +18 -5
  239. package/src/services/module-loading/route-module-build-manifest.d.ts +6 -1
  240. package/src/services/module-loading/route-module-build-manifest.js +1 -2
  241. package/src/services/module-loading/route-module-dependency-hasher.d.ts +3 -2
  242. package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
  243. package/src/services/module-loading/server-module-transpiler.service.d.ts +1 -15
  244. package/src/services/module-loading/server-module-transpiler.service.js +0 -24
  245. package/src/services/module-loading/view-module-loader.d.ts +10 -0
  246. package/src/services/module-loading/view-module-loader.js +46 -0
  247. package/src/services/runtime-state/entrypoint-dependency-graph.service.js +0 -12
  248. package/src/services/runtime-state/server-invalidation-state.service.d.ts +4 -2
  249. package/src/services/runtime-state/server-invalidation-state.service.js +7 -14
  250. package/src/services/validation/schema-validation-service.d.ts +1 -0
  251. package/src/services/validation/schema-validation-service.js +23 -36
  252. package/src/static-site-generator/README.md +6 -1
  253. package/src/static-site-generator/static-site-generator.d.ts +7 -2
  254. package/src/static-site-generator/static-site-generator.js +90 -49
  255. package/src/types/internal-types.d.ts +6 -39
  256. package/src/types/public-types.d.ts +29 -131
  257. package/src/utils/parse-cli-args.js +29 -22
  258. package/src/watchers/project-watcher.d.ts +14 -16
  259. package/src/watchers/project-watcher.js +86 -61
  260. package/src/watchers/project-watcher.test-helpers.d.ts +10 -1
  261. package/src/watchers/project-watcher.test-helpers.js +12 -0
  262. package/src/adapters/abstract/router-adapter.d.ts +0 -26
  263. package/src/adapters/abstract/router-adapter.js +0 -13
  264. package/src/adapters/bun/index.d.ts +0 -2
  265. package/src/adapters/bun/index.js +0 -2
  266. package/src/adapters/index.d.ts +0 -2
  267. package/src/adapters/index.js +0 -2
  268. package/src/eco/eco.utils.d.ts +0 -1
  269. package/src/eco/eco.utils.js +0 -1
  270. package/src/services/cache/index.d.ts +0 -9
  271. package/src/services/cache/index.js +0 -8
  272. package/src/services/html/html-rewriter-provider.service.d.ts +0 -40
  273. package/src/services/html/html-rewriter-provider.service.js +0 -68
  274. package/src/services/module-loading/route-module-build-cache.d.ts +0 -4
  275. package/src/services/module-loading/route-module-build-cache.js +0 -3
  276. package/src/services/runtime-state/dev-graph.service.d.ts +0 -118
  277. package/src/services/runtime-state/dev-graph.service.js +0 -170
  278. /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
@@ -9,7 +9,8 @@
9
9
  */
10
10
  import { appLogger } from '../../global/app-logger.js';
11
11
  import { SharedApplicationAdapter } from '../shared/runtime/application-adapter.js';
12
- import { resolveRuntimeBinding, resolveStaticRuntimeMode } from '../shared/runtime/runtime-app-bootstrap.js';
12
+ import { resolveRuntimeBinding } from '../shared/runtime/runtime-app-bootstrap.js';
13
+ import { bindRuntimeServer } from '../shared/runtime/bind-runtime-server.js';
13
14
  import { startupTrace } from '../../diagnostics/startup-trace.js';
14
15
  import { createBunServerAdapter } from './server-adapter.js';
15
16
  import { BunRuntimeHost } from './runtime-host.js';
@@ -42,16 +43,6 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
42
43
  }
43
44
  this.serverAdapter.attachUserWebSocketUpgrades(httpServer, options);
44
45
  }
45
- /**
46
- * Complete the initialization of the server adapter by processing dynamic routes
47
- * @param server The Bun server instance
48
- */
49
- async completeInitialization(server) {
50
- if (!this.serverAdapter) {
51
- throw new Error('Server adapter not initialized. Call start() first.');
52
- }
53
- await this.serverAdapter.completeInitialization(server);
54
- }
55
46
  /**
56
47
  * Initialize the Bun server adapter
57
48
  */
@@ -65,24 +56,18 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
65
56
  appConfig: this.appConfig,
66
57
  apiHandlers: this.apiHandlers,
67
58
  staticRoutes: this.staticRoutes,
59
+ errorPageLoaders: this.getErrorPageLoaders(),
68
60
  errorHandler: this.errorHandler,
69
61
  websocketHandlers: this.websocketHandlers.size > 0 ? this.websocketHandlers : undefined,
70
62
  options: { watch: binding.watch },
71
63
  serveOptions: binding.serveOptions,
72
64
  hostOwnsDevClient: hostOwnsDevClient(this.runtimeOptions),
73
- deferRuntimeAssetSetup: resolveStaticRuntimeMode({
74
- appConfig: this.appConfig,
75
- cliArgs: this.cliArgs,
76
- }).canBuildWithoutRuntimeServer,
65
+ deferRuntimeAssetSetup: this.cliArgs.build || this.cliArgs.preview,
77
66
  allowPortFallback: binding.allowPortFallback,
67
+ onDevelopmentRestart: this.createDevelopmentRestartHandler(),
78
68
  });
79
69
  }
80
- /**
81
- * Start the Bun application server
82
- * @param options Optional settings
83
- * @param options.autoCompleteInitialization Whether to automatically complete initialization with dynamic routes after server start (defaults to true)
84
- */
85
- async bootServer() {
70
+ async ensureServerAdapterReady() {
86
71
  if (this.stopped) {
87
72
  this.serverAdapter = undefined;
88
73
  this.stopped = false;
@@ -90,65 +75,65 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
90
75
  if (!this.serverAdapter) {
91
76
  this.serverAdapter = await this.initializeServerAdapter();
92
77
  }
78
+ return this.serverAdapter;
79
+ }
80
+ async bootPreviewServeOnly(serverAdapter) {
81
+ const previewOrigin = await serverAdapter.servePreviewOnly();
82
+ if (previewOrigin) {
83
+ await this.notifyListening(previewOrigin);
84
+ }
85
+ }
86
+ async bootStaticWithoutRuntimeServer(serverAdapter, preview, build, force) {
87
+ appLogger.debugTime('Building static pages');
88
+ const previewOrigin = await serverAdapter.buildStatic({ preview, force });
89
+ appLogger.debugTimeEnd('Building static pages');
90
+ if (preview && previewOrigin) {
91
+ await this.notifyListening(previewOrigin);
92
+ }
93
+ if (build) {
94
+ process.exit(0);
95
+ }
96
+ }
97
+ /**
98
+ * Starts the Bun application server, or runs the preview/build flow when the
99
+ * CLI requested one.
100
+ *
101
+ * @remarks
102
+ * HMR endpoints and Bun's `development` serve mode follow the `dev` flag only,
103
+ * matching the options `completeInitialization()` reloads the server with.
104
+ */
105
+ async bootServer() {
106
+ const serverAdapter = await this.ensureServerAdapterReady();
93
107
  const { dev, preview, build, force, serveOnly } = this.cliArgs;
94
- const staticRuntimeMode = resolveStaticRuntimeMode({
95
- appConfig: this.appConfig,
96
- cliArgs: this.cliArgs,
97
- });
98
108
  if (preview && serveOnly) {
99
- const previewOrigin = await this.serverAdapter.servePreviewOnly();
100
- if (previewOrigin) {
101
- await this.notifyListening(previewOrigin);
102
- }
109
+ await this.bootPreviewServeOnly(serverAdapter);
103
110
  return;
104
111
  }
105
- if (staticRuntimeMode.canBuildWithoutRuntimeServer) {
106
- appLogger.debugTime('Building static pages');
107
- const previewOrigin = await this.serverAdapter.buildStatic({ preview, force });
108
- appLogger.debugTimeEnd('Building static pages');
109
- if (preview && previewOrigin) {
110
- await this.notifyListening(previewOrigin);
111
- }
112
- if (build) {
113
- process.exit(0);
114
- }
112
+ if (build || preview) {
113
+ await this.bootStaticWithoutRuntimeServer(serverAdapter, preview, build, force);
115
114
  return;
116
115
  }
117
- const enableHmr = dev || (!preview && !build);
118
- const serverOptions = this.serverAdapter.getServerOptions({ enableHmr });
119
- const runtimeServerOptions = serverOptions;
116
+ const runtimeServerOptions = serverAdapter.getServerOptions({ enableHmr: dev });
117
+ const binding = resolveRuntimeBinding({
118
+ cliArgs: this.cliArgs,
119
+ serverOptions: this.serverOptions,
120
+ });
120
121
  startupTrace.beginServerListen();
121
- this.server = await this.runtimeHost.start({
122
- serveOptions: runtimeServerOptions,
123
- handleRequest: async () => new Response(null, { status: 500 }),
124
- onError: async () => { },
122
+ const bindingResult = await bindRuntimeServer(this.runtimeHost, {
123
+ startOptions: { serveOptions: runtimeServerOptions },
124
+ allowPortFallback: binding.allowPortFallback,
125
+ usePortManager: dev,
125
126
  });
126
- await this.serverAdapter.completeInitialization(this.server).catch((error) => {
127
+ this.server = bindingResult.server;
128
+ serverAdapter.applyBoundPort(bindingResult);
129
+ await serverAdapter.completeInitialization(this.server).catch((error) => {
127
130
  appLogger.error(`Failed to complete initialization: ${error}`);
128
131
  });
129
132
  if (!this.server) {
130
133
  throw new Error('Server failed to start');
131
134
  }
132
- const runtimeOrigin = this.runtimeHost.getOrigin(this.server, runtimeServerOptions);
133
- let previewOrigin;
134
- if (build || preview) {
135
- appLogger.debugTime('Building static pages');
136
- previewOrigin = await this.serverAdapter.buildStatic({ preview, force });
137
- const buildRuntimeServer = this.server;
138
- this.server = null;
139
- await this.runtimeHost.stop(buildRuntimeServer, { force: true });
140
- appLogger.debugTimeEnd('Building static pages');
141
- if (build) {
142
- process.exit(0);
143
- }
144
- }
145
- else {
146
- await this.notifyListening(runtimeOrigin);
147
- }
148
- if (preview && previewOrigin) {
149
- await this.notifyListening(previewOrigin);
150
- }
151
- return this.server ?? undefined;
135
+ await this.notifyListening(bindingResult.runtimeOrigin);
136
+ return this.server;
152
137
  }
153
138
  async stop(force = true) {
154
139
  if (this.stopped) {
@@ -17,7 +17,6 @@ export interface HmrManagerParams {
17
17
  * own explicit registration path.
18
18
  */
19
19
  export declare class HmrManager extends SharedHmrManager {
20
- private wsHandler;
21
20
  /**
22
21
  * Creates the Bun HMR manager around the shared HMR orchestration pipeline.
23
22
  *
@@ -10,7 +10,6 @@ import { SharedHmrManager } from '../shared/hmr/shared-hmr-manager.js';
10
10
  * own explicit registration path.
11
11
  */
12
12
  export class HmrManager extends SharedHmrManager {
13
- wsHandler;
14
13
  /**
15
14
  * Creates the Bun HMR manager around the shared HMR orchestration pipeline.
16
15
  *
@@ -51,10 +50,9 @@ export class HmrManager extends SharedHmrManager {
51
50
  bridge.unsubscribe(ws);
52
51
  appLogger.debug(`[HmrManager] Connection closed. Subscribers: ${bridge.subscriberCount}`);
53
52
  };
54
- this.wsHandler = { open, close };
55
53
  return {
56
- open: this.wsHandler.open,
57
- close: this.wsHandler.close,
54
+ open,
55
+ close,
58
56
  message: (_ws, message) => {
59
57
  appLogger.debug('[HMR] Received message from client:', message);
60
58
  },
@@ -1,10 +1,11 @@
1
1
  import type { Server as NodeHttpServer } from 'node:http';
2
2
  import type { Server, WebSocketHandler } from 'bun';
3
3
  import type { EcoPagesAppConfig } from '../../types/internal-types.js';
4
- import type { ApiHandler, ErrorHandler, StaticRoute, EcopagesWebSocketHandler } from '../../types/public-types.js';
4
+ import type { ApiHandler, ErrorHandler, StaticRoute, ErrorPageLoaders, EcopagesWebSocketHandler } from '../../types/public-types.js';
5
5
  import { SharedServerAdapter } from '../shared/runtime/server-adapter.js';
6
6
  import type { ServerAdapterResult } from '../abstract/server-adapter.js';
7
7
  import type { StaticPreviewHost } from '../shared/runtime/static-preview-host.js';
8
+ import { type WebSocketUpgradeOptions } from '../shared/ws/node-http-websocket-upgrades.js';
8
9
  import { ClientBridge } from './client-bridge.js';
9
10
  import { HmrManager } from './hmr-manager.js';
10
11
  type BunServerInstance = Server<unknown>;
@@ -32,6 +33,7 @@ export interface BunServerAdapterParams {
32
33
  serveOptions: BunServeAdapterServerOptions;
33
34
  apiHandlers?: ApiHandler<string, Request, BunServerInstance>[];
34
35
  staticRoutes?: StaticRoute[];
36
+ errorPageLoaders?: ErrorPageLoaders;
35
37
  errorHandler?: ErrorHandler;
36
38
  websocketHandlers?: Map<string, EcopagesWebSocketHandler<any, any>>;
37
39
  options?: {
@@ -40,6 +42,7 @@ export interface BunServerAdapterParams {
40
42
  hostOwnsDevClient?: boolean;
41
43
  deferRuntimeAssetSetup?: boolean;
42
44
  allowPortFallback?: boolean;
45
+ onDevelopmentRestart?: (changedFile: string) => Promise<void>;
43
46
  hmrManager?: HmrManager;
44
47
  bridge?: ClientBridge;
45
48
  previewHost?: StaticPreviewHost;
@@ -55,9 +58,7 @@ export interface BunServerAdapterResult extends ServerAdapterResult {
55
58
  servePreviewOnly: () => Promise<string | undefined>;
56
59
  completeInitialization: (server?: BunServerInstance | null) => Promise<void>;
57
60
  handleRequest: (request: Request) => Promise<Response>;
58
- attachUserWebSocketUpgrades: (server: NodeHttpServer, options?: {
59
- passthroughUnmatched?: boolean;
60
- }) => void;
61
+ attachUserWebSocketUpgrades: (server: NodeHttpServer, options?: WebSocketUpgradeOptions) => void;
61
62
  dispose: () => Promise<void>;
62
63
  }
63
64
  /**
@@ -76,6 +77,7 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
76
77
  serveOptions: BunServeAdapterServerOptions;
77
78
  protected apiHandlers: ApiHandler<string, Request, BunServerInstance>[];
78
79
  protected staticRoutes: StaticRoute[];
80
+ protected errorPageLoaders: ErrorPageLoaders;
79
81
  protected errorHandler?: ErrorHandler;
80
82
  private bridge;
81
83
  hmrManager: HmrManager;
@@ -86,6 +88,7 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
86
88
  private adapterDisposed;
87
89
  private readonly deferRuntimeAssetSetup;
88
90
  private readonly allowPortFallback;
91
+ private readonly onDevelopmentRestart?;
89
92
  private readonly previewHost;
90
93
  /**
91
94
  * Reference to the application-level WebSocket handlers map.
@@ -124,7 +127,7 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
124
127
  * is constructed, those collaborators are mandatory because the adapter cannot
125
128
  * initialize Bun HMR or preview flows without them.
126
129
  */
127
- constructor({ appConfig, runtimeOrigin, serveOptions, apiHandlers, staticRoutes, errorHandler, websocketHandlers, options, hostOwnsDevClient, deferRuntimeAssetSetup, allowPortFallback, hmrManager, bridge, previewHost, }: BunServerAdapterParams & {
130
+ constructor({ appConfig, runtimeOrigin, serveOptions, apiHandlers, staticRoutes, errorPageLoaders, errorHandler, websocketHandlers, options, hostOwnsDevClient, deferRuntimeAssetSetup, allowPortFallback, onDevelopmentRestart, hmrManager, bridge, previewHost, }: BunServerAdapterParams & {
128
131
  hmrManager: HmrManager;
129
132
  bridge: ClientBridge;
130
133
  previewHost: StaticPreviewHost;
@@ -132,9 +135,7 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
132
135
  /**
133
136
  * Wires user WebSocket routes onto a Node HTTP server used by host integrations.
134
137
  */
135
- attachUserWebSocketUpgrades(server: NodeHttpServer, options?: {
136
- passthroughUnmatched?: boolean;
137
- }): void;
138
+ attachUserWebSocketUpgrades(server: NodeHttpServer, options?: WebSocketUpgradeOptions): void;
138
139
  /**
139
140
  * Initializes the server adapter's core runtime components.
140
141
  */
@@ -189,9 +190,9 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
189
190
  * Composes the base Bun server settings that all runtime modes build from.
190
191
  *
191
192
  * @remarks
192
- * This method centralizes the Bun-specific error boundary. It preserves the
193
- * shared route pipeline while still allowing adapter-level custom error-handler
194
- * execution and `HttpError` passthrough.
193
+ * The `app.onError` boundary lives in {@link handleRequest}. Bun's `error`
194
+ * hook only fires if that boundary itself throws, so it answers with a plain
195
+ * 500 rather than rendering anything that could fail again.
195
196
  */
196
197
  private buildServerSettings;
197
198
  /**
@@ -241,8 +242,9 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
241
242
  *
242
243
  * @remarks
243
244
  * HMR HTML injection for API and page responses is owned by
244
- * `SharedServerAdapter.handleSharedRequest`. This method only maps the
245
- * request into the shared pipeline.
245
+ * `SharedServerAdapter.handleSharedRequest`. This method waits for
246
+ * initialization, maps the request into the shared pipeline, and sends any
247
+ * escaped error through the shared `app.onError` boundary.
246
248
  */
247
249
  handleRequest(request: Request): Promise<Response>;
248
250
  /**
@@ -250,14 +252,6 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
250
252
  * Prevents race conditions during startup.
251
253
  */
252
254
  private waitForInitialization;
253
- /**
254
- * Handles HTTP requests from the router adapter.
255
- */
256
- handleResponse(request: Request): Promise<Response>;
257
- /**
258
- * Handles requests that do not match any routes.
259
- */
260
- private handleNoMatch;
261
255
  }
262
256
  /**
263
257
  * Creates the Bun server adapter and fills in the runtime-specific collaborators
@@ -1,8 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from '../../config/constants.js';
3
3
  import { appLogger } from '../../global/app-logger.js';
4
- import { HttpError } from '../../errors/http-error.js';
5
- import { createRequire } from '../../utils/locals-utils.js';
4
+ import { entryWatcherOwnsConfig } from '../../dev/development-restart.js';
6
5
  import { findWebSocketRoute } from '../abstract/ws-pattern-matcher.js';
7
6
  import { fileSystem } from '@ecopages/file-system';
8
7
  import { setupAppRuntimePlugins } from '../../build/build-adapter.js';
@@ -10,9 +9,8 @@ import { installBuildRuntime } from '../../build/runtime/build-runtime.js';
10
9
  import { StaticSiteGenerator } from '../../static-site-generator/static-site-generator.js';
11
10
  import { ProjectWatcher } from '../../watchers/project-watcher.js';
12
11
  import { SharedServerAdapter } from '../shared/runtime/server-adapter.js';
13
- import { ApiResponseBuilder } from '../shared/http/api-response.js';
14
12
  import { ServerStaticBuilder } from '../shared/runtime/server-static-builder.js';
15
- import { attachNodeHttpWebSocketUpgrades } from '../shared/ws/node-http-websocket-upgrades.js';
13
+ import { attachNodeHttpWebSocketUpgrades, } from '../shared/ws/node-http-websocket-upgrades.js';
16
14
  import { createBunUserWebSocketLifecycle } from './bun-user-websocket-lifecycle.js';
17
15
  import { createEcopagesSocket } from '../shared/ws/websocket-lifecycle.js';
18
16
  import { resolveServeRuntimeOrigin } from '../shared/runtime/runtime-app-bootstrap.js';
@@ -35,6 +33,7 @@ import { BunStaticPreviewHost } from './static-preview-host.js';
35
33
  export class BunServerAdapter extends SharedServerAdapter {
36
34
  apiHandlers;
37
35
  staticRoutes;
36
+ errorPageLoaders;
38
37
  errorHandler;
39
38
  bridge;
40
39
  hmrManager;
@@ -44,6 +43,7 @@ export class BunServerAdapter extends SharedServerAdapter {
44
43
  adapterDisposed = false;
45
44
  deferRuntimeAssetSetup;
46
45
  allowPortFallback;
46
+ onDevelopmentRestart;
47
47
  previewHost;
48
48
  /**
49
49
  * Reference to the application-level WebSocket handlers map.
@@ -100,12 +100,14 @@ export class BunServerAdapter extends SharedServerAdapter {
100
100
  * is constructed, those collaborators are mandatory because the adapter cannot
101
101
  * initialize Bun HMR or preview flows without them.
102
102
  */
103
- constructor({ appConfig, runtimeOrigin, serveOptions, apiHandlers, staticRoutes, errorHandler, websocketHandlers, options, hostOwnsDevClient, deferRuntimeAssetSetup, allowPortFallback, hmrManager, bridge, previewHost, }) {
103
+ constructor({ appConfig, runtimeOrigin, serveOptions, apiHandlers, staticRoutes, errorPageLoaders, errorHandler, websocketHandlers, options, hostOwnsDevClient, deferRuntimeAssetSetup, allowPortFallback, onDevelopmentRestart, hmrManager, bridge, previewHost, }) {
104
104
  super({ appConfig, runtimeOrigin, serveOptions, options });
105
105
  this.deferRuntimeAssetSetup = deferRuntimeAssetSetup === true;
106
106
  this.allowPortFallback = allowPortFallback !== false;
107
+ this.onDevelopmentRestart = onDevelopmentRestart;
107
108
  this.apiHandlers = apiHandlers || [];
108
109
  this.staticRoutes = staticRoutes || [];
110
+ this.errorPageLoaders = errorPageLoaders ?? {};
109
111
  this.errorHandler = errorHandler;
110
112
  this.bridge = bridge;
111
113
  this.hmrManager = hmrManager;
@@ -190,6 +192,7 @@ export class BunServerAdapter extends SharedServerAdapter {
190
192
  }
191
193
  await this.createSharedWatchRefreshCallback({
192
194
  staticRoutes: this.staticRoutes,
195
+ errorPageLoaders: this.errorPageLoaders,
193
196
  hmrManager: this.hmrManager,
194
197
  onRoutesReady: () => {
195
198
  const options = this.getServerOptions({ enableHmr: true });
@@ -209,6 +212,8 @@ export class BunServerAdapter extends SharedServerAdapter {
209
212
  hmrManager: this.hmrManager,
210
213
  bridge: this.bridge,
211
214
  hostOwnsDevClient: this.hostOwnsDevClient,
215
+ onRestartRequest: this.onDevelopmentRestart,
216
+ entryWatcherOwnsConfig: entryWatcherOwnsConfig(),
212
217
  });
213
218
  this.projectWatcher = watcher;
214
219
  await watcher.createWatcherSubscription();
@@ -320,59 +325,22 @@ export class BunServerAdapter extends SharedServerAdapter {
320
325
  * Composes the base Bun server settings that all runtime modes build from.
321
326
  *
322
327
  * @remarks
323
- * This method centralizes the Bun-specific error boundary. It preserves the
324
- * shared route pipeline while still allowing adapter-level custom error-handler
325
- * execution and `HttpError` passthrough.
328
+ * The `app.onError` boundary lives in {@link handleRequest}. Bun's `error`
329
+ * hook only fires if that boundary itself throws, so it answers with a plain
330
+ * 500 rather than rendering anything that could fail again.
326
331
  */
327
332
  buildServerSettings() {
328
333
  const serverOptions = { ...this.serveOptions };
329
- const handleNoMatch = this.handleNoMatch.bind(this);
330
- const waitForInit = this.waitForInitialization.bind(this);
331
334
  const handleReq = this.handleRequest.bind(this);
332
- const errorHandler = this.errorHandler;
333
- const getCacheService = () => this.getCacheService();
334
- const getRenderContext = () => this.getRenderContext();
335
335
  appLogger.debug(`[BunServerAdapter] Building server settings`);
336
336
  const finalOptions = {
337
337
  ...serverOptions,
338
- async fetch(request, _server) {
339
- try {
340
- await waitForInit();
341
- return await handleReq(request);
342
- }
343
- catch (error) {
344
- if (error instanceof Response)
345
- return error;
346
- if (errorHandler) {
347
- try {
348
- const locals = {};
349
- const context = {
350
- request,
351
- params: {},
352
- response: new ApiResponseBuilder(),
353
- server: _server,
354
- locals,
355
- require: createRequire(() => locals),
356
- services: {
357
- cache: getCacheService(),
358
- },
359
- ...getRenderContext(),
360
- };
361
- return await errorHandler(error, context);
362
- }
363
- catch (handlerError) {
364
- appLogger.error(`[ecopages] Error in custom error handler: ${handlerError}`);
365
- }
366
- }
367
- if (error instanceof HttpError)
368
- return error.toResponse();
369
- appLogger.error(`[ecopages] Error handling request: ${error}`);
370
- return new Response('Internal Server Error', { status: 500 });
371
- }
338
+ async fetch(request) {
339
+ return await handleReq(request);
372
340
  },
373
341
  error(error) {
374
342
  appLogger.error(`[ecopages] Error handling request: ${error}`);
375
- return handleNoMatch(new Request('http://localhost'));
343
+ return new Response('Internal Server Error', { status: 500 });
376
344
  },
377
345
  };
378
346
  return finalOptions;
@@ -385,6 +353,7 @@ export class BunServerAdapter extends SharedServerAdapter {
385
353
  if (!this.fullyInitialized) {
386
354
  await this.initializeSharedRouteHandling({
387
355
  staticRoutes: this.staticRoutes,
356
+ errorPageLoaders: this.errorPageLoaders,
388
357
  hmrManager: this.hmrManager,
389
358
  });
390
359
  }
@@ -393,6 +362,7 @@ export class BunServerAdapter extends SharedServerAdapter {
393
362
  router: this.router,
394
363
  routeRendererFactory: this.routeRendererFactory,
395
364
  staticRoutes: this.staticRoutes,
365
+ errorPageLoaders: this.errorPageLoaders,
396
366
  });
397
367
  if (!options?.preview) {
398
368
  return undefined;
@@ -407,6 +377,7 @@ export class BunServerAdapter extends SharedServerAdapter {
407
377
  if (!this.fullyInitialized) {
408
378
  await this.initializeSharedRouteHandling({
409
379
  staticRoutes: this.staticRoutes,
380
+ errorPageLoaders: this.errorPageLoaders,
410
381
  hmrManager: this.hmrManager,
411
382
  });
412
383
  }
@@ -460,6 +431,7 @@ export class BunServerAdapter extends SharedServerAdapter {
460
431
  appLogger.debug('Completing server initialization with dynamic routes');
461
432
  await this.initializeSharedRouteHandling({
462
433
  staticRoutes: this.staticRoutes,
434
+ errorPageLoaders: this.errorPageLoaders,
463
435
  hmrManager: this.hmrManager,
464
436
  });
465
437
  if (this.options?.watch) {
@@ -492,6 +464,7 @@ export class BunServerAdapter extends SharedServerAdapter {
492
464
  completeInitialization: this.completeInitialization.bind(this),
493
465
  handleRequest: this.handleRequest.bind(this),
494
466
  attachUserWebSocketUpgrades: this.attachUserWebSocketUpgrades.bind(this),
467
+ applyBoundPort: this.applyBoundPort.bind(this),
495
468
  listStaticGenerationRoutes: (input) => this.router.listStaticGenerationRoutes(input),
496
469
  dispose: this.dispose.bind(this),
497
470
  };
@@ -522,17 +495,24 @@ export class BunServerAdapter extends SharedServerAdapter {
522
495
  *
523
496
  * @remarks
524
497
  * HMR HTML injection for API and page responses is owned by
525
- * `SharedServerAdapter.handleSharedRequest`. This method only maps the
526
- * request into the shared pipeline.
498
+ * `SharedServerAdapter.handleSharedRequest`. This method waits for
499
+ * initialization, maps the request into the shared pipeline, and sends any
500
+ * escaped error through the shared `app.onError` boundary.
527
501
  */
528
502
  async handleRequest(request) {
529
- const response = await this.handleSharedRequest(request, {
503
+ const context = {
530
504
  apiHandlers: this.apiHandlers,
531
505
  errorHandler: this.errorHandler,
532
506
  serverInstance: this.serverInstance,
533
507
  hmrManager: this.hmrManager,
534
- });
535
- return response;
508
+ };
509
+ try {
510
+ await this.waitForInitialization();
511
+ return await this.handleSharedRequest(request, context);
512
+ }
513
+ catch (error) {
514
+ return await this.handleUnexpectedRequestError(error, request, context);
515
+ }
536
516
  }
537
517
  /**
538
518
  * Ensures server initialization completes before request handling.
@@ -547,20 +527,6 @@ export class BunServerAdapter extends SharedServerAdapter {
547
527
  }
548
528
  throw new Error('Server not initialized. Call completeInitialization() first.');
549
529
  }
550
- /**
551
- * Handles HTTP requests from the router adapter.
552
- */
553
- async handleResponse(request) {
554
- await this.waitForInitialization();
555
- return this.routeHandler.handleResponse(request);
556
- }
557
- /**
558
- * Handles requests that do not match any routes.
559
- */
560
- async handleNoMatch(request) {
561
- await this.waitForInitialization();
562
- return this.routeHandler.handleNoMatch(request);
563
- }
564
530
  }
565
531
  /**
566
532
  * Creates the Bun server adapter and fills in the runtime-specific collaborators
@@ -11,6 +11,7 @@ type BunStaticPreviewServerFactory = {
11
11
  appConfig: EcoPagesAppConfig;
12
12
  options: {
13
13
  port: number;
14
+ hostname: string;
14
15
  };
15
16
  }): BunStaticPreviewServer;
16
17
  };
@@ -16,7 +16,7 @@ export class BunStaticPreviewHost {
16
16
  startOnPort: async (port) => {
17
17
  const candidate = this.previewServerFactory.createServer({
18
18
  appConfig: options.appConfig,
19
- options: { port },
19
+ options: { port, hostname: options.hostname },
20
20
  });
21
21
  const boundPort = candidate.server?.port ?? null;
22
22
  if (!boundPort) {
@@ -1,22 +1,77 @@
1
+ import type { EcoPagesUserConfig } from '../config/user-config-types.js';
1
2
  import type { EcoPagesAppConfig } from '../types/internal-types.js';
2
3
  import { AbstractApplicationAdapter } from './abstract/application-adapter.js';
3
4
  import type { ApplicationAdapterOptions } from './abstract/application-adapter.js';
4
- export type { OnAppStartCallback, AppStartInfo, StartCallback, ListenCallback, ApplicationListeningCallback, ApplicationListeningInfo, } from './abstract/application-adapter.js';
5
+ export type { OnAppStartCallback, AppStartInfo } from './abstract/application-adapter.js';
5
6
  export type EcopagesRuntimeAdapter = 'auto' | 'node' | 'bun';
6
- export interface EcopagesAppOptions extends ApplicationAdapterOptions {
7
+ type EcopagesAppConfigSource = {
7
8
  appConfig: EcoPagesAppConfig;
9
+ userConfig?: never;
10
+ configFile?: never;
11
+ } | {
12
+ appConfig?: never;
13
+ userConfig: EcoPagesUserConfig;
14
+ configFile?: never;
15
+ } | {
16
+ appConfig?: never;
17
+ userConfig?: never;
18
+ configFile?: string;
19
+ };
20
+ export type EcopagesAppOptions = Omit<ApplicationAdapterOptions, 'appConfig'> & EcopagesAppConfigSource & {
8
21
  /**
9
22
  * Selects the runtime adapter used by the universal `createApp()` entrypoint.
10
23
  *
11
24
  * @default 'auto'
12
25
  *
13
26
  * @remarks
14
- * This is separate from `runtime`, which configures embedded host behavior.
15
- * Use `auto` to select Bun when the current process exposes `globalThis.Bun`
27
+ * Use `'auto'` to select Bun when the current process exposes `globalThis.Bun`
16
28
  * and Node otherwise.
17
29
  */
18
30
  adapter?: EcopagesRuntimeAdapter;
19
- serverOptions?: Record<string, any>;
20
- }
21
- export type UniversalEcopagesApp = AbstractApplicationAdapter<EcopagesAppOptions, unknown, Request>;
22
- export declare function createApp<WebSocketData = undefined>(options: EcopagesAppOptions): Promise<UniversalEcopagesApp>;
31
+ /**
32
+ * Low-level server options passed to the underlying HTTP engine
33
+ * (e.g. Node `http.createServer` or Bun `Bun.serve`).
34
+ */
35
+ serverOptions?: Record<string, unknown>;
36
+ };
37
+ export type ResolvedEcopagesAppOptions = ApplicationAdapterOptions & {
38
+ adapter?: EcopagesRuntimeAdapter;
39
+ };
40
+ export type UniversalEcopagesApp = AbstractApplicationAdapter<ResolvedEcopagesAppOptions, unknown, Request>;
41
+ /**
42
+ * Creates and initializes an EcoPages universal application instance.
43
+ *
44
+ * @remarks
45
+ * In standard applications, `createApp()` is called with zero arguments. It automatically
46
+ * resolves and loads `eco.config.ts` from the project root (or via the `ECOPAGES_CONFIG_FILE`
47
+ * environment variable or explicit `configFile` option).
48
+ *
49
+ * In tests or fixture harness environments, you may pass `userConfig` (an unfinalized
50
+ * `EcoPagesUserConfig` object authored via `defineConfig()`) or `appConfig` (a pre-finalized
51
+ * `EcoPagesAppConfig`) to bypass file loading.
52
+ *
53
+ * @example Default usage in `app.ts`
54
+ * ```typescript
55
+ * import { createApp } from '@ecopages/core/create-app';
56
+ *
57
+ * const app = await createApp();
58
+ * app.get('/api/health', (req, res) => res.json({ status: 'ok' }));
59
+ * await app.start();
60
+ * ```
61
+ *
62
+ * @example With a custom config file path
63
+ * ```typescript
64
+ * const app = await createApp({ configFile: 'eco.custom.config.ts' });
65
+ * ```
66
+ *
67
+ * @example In tests with inline user config
68
+ * ```typescript
69
+ * const app = await createApp({
70
+ * userConfig: {
71
+ * rootDir: import.meta.dirname,
72
+ * integrations: [ecopagesJsxPlugin()],
73
+ * },
74
+ * });
75
+ * ```
76
+ */
77
+ export declare function createApp<WebSocketData = undefined>(options?: EcopagesAppOptions): Promise<UniversalEcopagesApp>;