@ecopages/core 0.2.0-beta.1 → 0.2.0-beta.10

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 (216) hide show
  1. package/package.json +107 -3
  2. package/src/adapters/abstract/application-adapter.d.ts +73 -1
  3. package/src/adapters/abstract/application-adapter.js +89 -0
  4. package/src/adapters/abstract/server-adapter.d.ts +3 -0
  5. package/src/adapters/abstract/ws-pattern-matcher.d.ts +60 -0
  6. package/src/adapters/abstract/ws-pattern-matcher.js +61 -0
  7. package/src/adapters/bun/client-bridge.d.ts +1 -0
  8. package/src/adapters/bun/client-bridge.js +3 -0
  9. package/src/adapters/bun/create-app.d.ts +5 -3
  10. package/src/adapters/bun/create-app.js +44 -39
  11. package/src/adapters/bun/hmr-manager.d.ts +2 -1
  12. package/src/adapters/bun/hmr-manager.js +2 -2
  13. package/src/adapters/bun/server-adapter.d.ts +81 -20
  14. package/src/adapters/bun/server-adapter.js +220 -78
  15. package/src/adapters/bun/static-preview-host.js +25 -20
  16. package/src/adapters/create-app.d.ts +13 -0
  17. package/src/adapters/create-app.js +10 -1
  18. package/src/adapters/node/create-app.d.ts +4 -0
  19. package/src/adapters/node/create-app.js +38 -9
  20. package/src/adapters/node/node-client-bridge.d.ts +1 -0
  21. package/src/adapters/node/node-client-bridge.js +3 -0
  22. package/src/adapters/node/node-hmr-manager.d.ts +2 -1
  23. package/src/adapters/node/node-hmr-manager.js +2 -2
  24. package/src/adapters/node/server-adapter-dependencies.js +2 -0
  25. package/src/adapters/node/server-adapter.d.ts +55 -19
  26. package/src/adapters/node/server-adapter.js +140 -132
  27. package/src/adapters/node/static-content-server.d.ts +1 -0
  28. package/src/adapters/node/static-content-server.js +10 -2
  29. package/src/adapters/node/static-preview-host.js +27 -12
  30. package/src/adapters/shared/bun-user-websocket-lifecycle.d.ts +22 -0
  31. package/src/adapters/shared/bun-user-websocket-lifecycle.js +96 -0
  32. package/src/adapters/shared/copy-runtime-public-dir.d.ts +6 -0
  33. package/src/adapters/shared/copy-runtime-public-dir.js +24 -0
  34. package/src/adapters/shared/hmr-html-response.d.ts +1 -1
  35. package/src/adapters/shared/hmr-html-response.js +4 -1
  36. package/src/adapters/shared/node-http-websocket-upgrades.d.ts +21 -0
  37. package/src/adapters/shared/node-http-websocket-upgrades.js +100 -0
  38. package/src/adapters/shared/port-manager.d.ts +116 -0
  39. package/src/adapters/shared/port-manager.js +196 -0
  40. package/src/adapters/shared/runtime-app-bootstrap.d.ts +2 -1
  41. package/src/adapters/shared/runtime-app-bootstrap.js +3 -6
  42. package/src/adapters/shared/runtime-server-lifecycle.d.ts +38 -0
  43. package/src/adapters/shared/runtime-server-lifecycle.js +39 -0
  44. package/src/adapters/shared/server-adapter.d.ts +2 -1
  45. package/src/adapters/shared/server-adapter.js +12 -4
  46. package/src/adapters/shared/server-route-handler.d.ts +4 -1
  47. package/src/adapters/shared/server-route-handler.js +5 -2
  48. package/src/adapters/shared/server-static-builder.d.ts +14 -29
  49. package/src/adapters/shared/server-static-builder.js +91 -70
  50. package/src/adapters/shared/shared-hmr-manager.d.ts +12 -0
  51. package/src/adapters/shared/shared-hmr-manager.js +64 -7
  52. package/src/adapters/shared/static-preview-host.d.ts +5 -0
  53. package/src/adapters/shared/websocket-lifecycle.d.ts +24 -0
  54. package/src/adapters/shared/websocket-lifecycle.js +55 -0
  55. package/src/build/README.md +77 -14
  56. package/src/build/app-build-manifest-runtime.d.ts +10 -0
  57. package/src/build/app-build-manifest-runtime.js +90 -0
  58. package/src/build/build-adapter.d.ts +17 -319
  59. package/src/build/build-adapter.js +28 -94
  60. package/src/build/build-contracts.d.ts +97 -0
  61. package/src/build/build-contracts.js +0 -0
  62. package/src/build/build-input-fingerprint.d.ts +28 -0
  63. package/src/build/build-input-fingerprint.js +31 -0
  64. package/src/build/build-profile-options.d.ts +7 -0
  65. package/src/build/build-profile-options.js +37 -0
  66. package/src/build/build-runtime.d.ts +24 -0
  67. package/src/build/build-runtime.js +65 -0
  68. package/src/build/deduping-build-executor.d.ts +28 -0
  69. package/src/build/deduping-build-executor.js +56 -0
  70. package/src/build/jsx-ownership-plugins.d.ts +24 -0
  71. package/src/build/jsx-ownership-plugins.js +41 -0
  72. package/src/build/pages-unified-graph-build.d.ts +31 -0
  73. package/src/build/pages-unified-graph-build.js +206 -0
  74. package/src/build/parallel-build-executor.d.ts +21 -0
  75. package/src/build/parallel-build-executor.js +52 -0
  76. package/src/build/production-build-cache.d.ts +20 -0
  77. package/src/build/production-build-cache.js +63 -0
  78. package/src/build/rolldown-adapter-helpers.d.ts +3 -6
  79. package/src/build/rolldown-adapter-helpers.js +71 -6
  80. package/src/build/rolldown-build-adapter.d.ts +2 -6
  81. package/src/build/rolldown-build-adapter.js +3 -3
  82. package/src/build/rolldown-build-invocation-metrics.d.ts +12 -0
  83. package/src/build/rolldown-build-invocation-metrics.js +43 -0
  84. package/src/build/rolldown-plugin-bridge.d.ts +15 -1
  85. package/src/build/rolldown-plugin-bridge.js +20 -5
  86. package/src/build/rolldown-source-transform-pass.d.ts +15 -0
  87. package/src/build/rolldown-source-transform-pass.js +58 -0
  88. package/src/build/runtime-build-executor.d.ts +8 -15
  89. package/src/build/runtime-build-executor.js +12 -15
  90. package/src/build/runtime-build-output-normalizer.d.ts +7 -0
  91. package/src/build/runtime-build-output-normalizer.js +94 -2
  92. package/src/build/server-entry-build-cache.d.ts +44 -0
  93. package/src/build/server-entry-build-cache.js +161 -0
  94. package/src/config/config-builder.d.ts +12 -7
  95. package/src/config/config-builder.js +12 -9
  96. package/src/dev/client-bridge-registry.d.ts +5 -0
  97. package/src/dev/client-bridge-registry.js +15 -0
  98. package/src/dev/dev-client-ownership.d.ts +7 -0
  99. package/src/dev/dev-client-ownership.js +6 -0
  100. package/src/dev/host-runtime.d.ts +3 -0
  101. package/src/dev/host-runtime.js +7 -0
  102. package/src/hmr/client/hmr-runtime.js +5 -2
  103. package/src/hmr/strategies/server-rendered-template-hmr-strategy.d.ts +17 -0
  104. package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +29 -0
  105. package/src/integrations/ghtml/ghtml-renderer.d.ts +2 -6
  106. package/src/integrations/ghtml/ghtml-renderer.js +2 -51
  107. package/src/integrations/ghtml/ghtml.plugin.d.ts +3 -16
  108. package/src/integrations/ghtml/ghtml.plugin.js +7 -14
  109. package/src/plugins/define-integration.d.ts +26 -0
  110. package/src/plugins/define-integration.js +19 -0
  111. package/src/plugins/eco-component-meta-plugin.js +5 -8
  112. package/src/plugins/foreign-jsx-override-plugin.js +4 -6
  113. package/src/plugins/integration-plugin.d.ts +19 -9
  114. package/src/plugins/integration-plugin.js +7 -4
  115. package/src/plugins/jsx-import-source.utils.d.ts +8 -0
  116. package/src/plugins/jsx-import-source.utils.js +26 -0
  117. package/src/plugins/processor.d.ts +19 -4
  118. package/src/plugins/processor.js +22 -4
  119. package/src/plugins/source-transform.d.ts +31 -0
  120. package/src/plugins/source-transform.js +23 -1
  121. package/src/route-renderer/GRAPH.md +8 -8
  122. package/src/route-renderer/README.md +30 -28
  123. package/src/route-renderer/orchestration/component-graph-collectors.d.ts +10 -0
  124. package/src/route-renderer/orchestration/component-graph-collectors.js +143 -0
  125. package/src/route-renderer/orchestration/component-graph.d.ts +36 -0
  126. package/src/route-renderer/orchestration/component-graph.js +90 -0
  127. package/src/route-renderer/orchestration/component-render-context.d.ts +3 -10
  128. package/src/route-renderer/orchestration/component-render-context.js +3 -1
  129. package/src/route-renderer/orchestration/declared-ownership-graph.d.ts +1 -18
  130. package/src/route-renderer/orchestration/declared-ownership-graph.js +5 -31
  131. package/src/route-renderer/orchestration/document-shell-render.service.d.ts +54 -0
  132. package/src/route-renderer/orchestration/document-shell-render.service.js +54 -0
  133. package/src/route-renderer/orchestration/foreign-subtree-execution.service.d.ts +59 -29
  134. package/src/route-renderer/orchestration/foreign-subtree-execution.service.js +164 -35
  135. package/src/route-renderer/orchestration/global-injector-assets.service.d.ts +7 -0
  136. package/src/route-renderer/orchestration/global-injector-assets.service.js +32 -0
  137. package/src/route-renderer/orchestration/integration-renderer.d.ts +18 -54
  138. package/src/route-renderer/orchestration/integration-renderer.js +108 -194
  139. package/src/route-renderer/orchestration/integration-route-render-adapter.d.ts +38 -0
  140. package/src/route-renderer/orchestration/integration-route-render-adapter.js +27 -0
  141. package/src/route-renderer/orchestration/ownership-validation.service.d.ts +4 -0
  142. package/src/route-renderer/orchestration/ownership-validation.service.js +11 -1
  143. package/src/route-renderer/orchestration/page-browser-graph-contribution.loader.d.ts +9 -0
  144. package/src/route-renderer/orchestration/page-browser-graph-contribution.loader.js +7 -0
  145. package/src/route-renderer/orchestration/page-browser-graph.service.d.ts +25 -0
  146. package/src/route-renderer/orchestration/page-browser-graph.service.js +174 -0
  147. package/src/route-renderer/orchestration/render-output.utils.d.ts +2 -0
  148. package/src/route-renderer/orchestration/render-output.utils.js +4 -0
  149. package/src/route-renderer/orchestration/route-html-finalization.service.d.ts +17 -0
  150. package/src/route-renderer/orchestration/route-html-finalization.service.js +26 -0
  151. package/src/route-renderer/orchestration/route-prepared-options.builder.d.ts +24 -0
  152. package/src/route-renderer/orchestration/route-prepared-options.builder.js +52 -0
  153. package/src/route-renderer/orchestration/route-prepared-options.utils.d.ts +4 -0
  154. package/src/route-renderer/orchestration/route-prepared-options.utils.js +33 -0
  155. package/src/route-renderer/orchestration/route-render-orchestrator.d.ts +5 -38
  156. package/src/route-renderer/orchestration/route-render-orchestrator.js +51 -459
  157. package/src/route-renderer/orchestration/string-markup-renderer.d.ts +14 -0
  158. package/src/route-renderer/orchestration/string-markup-renderer.js +54 -0
  159. package/src/router/client/navigation-coordinator.d.ts +1 -1
  160. package/src/router/client/navigation-coordinator.js +12 -2
  161. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +1 -0
  162. package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.js +1 -0
  163. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +4 -2
  164. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +27 -7
  165. package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +32 -14
  166. package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +17 -3
  167. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +0 -3
  168. package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +2 -31
  169. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +0 -3
  170. package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +2 -30
  171. package/src/services/assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.d.ts +2 -0
  172. package/src/services/assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.js +43 -0
  173. package/src/services/assets/browser-bundle.service.d.ts +3 -1
  174. package/src/services/assets/browser-bundle.service.js +17 -5
  175. package/src/services/html/html-transformer.service.d.ts +1 -1
  176. package/src/services/html/html-transformer.service.js +4 -4
  177. package/src/services/invalidation/development-invalidation.service.d.ts +10 -1
  178. package/src/services/invalidation/development-invalidation.service.js +31 -2
  179. package/src/services/module-loading/README.md +49 -0
  180. package/src/services/module-loading/app-server-module-transpiler.service.js +5 -17
  181. package/src/services/module-loading/page-module-import.service.d.ts +4 -1
  182. package/src/services/module-loading/page-module-import.service.js +61 -41
  183. package/src/services/module-loading/route-module-build-cache-registry.d.ts +24 -0
  184. package/src/services/module-loading/route-module-build-cache-registry.js +37 -0
  185. package/src/services/module-loading/route-module-build-cache.d.ts +4 -0
  186. package/src/services/module-loading/route-module-build-cache.js +38 -0
  187. package/src/services/module-loading/route-module-build-cache.store.d.ts +57 -0
  188. package/src/services/module-loading/route-module-build-cache.store.js +207 -0
  189. package/src/services/module-loading/route-module-build-manifest.d.ts +61 -0
  190. package/src/services/module-loading/route-module-build-manifest.js +116 -0
  191. package/src/services/module-loading/route-module-dependency-hasher.d.ts +81 -0
  192. package/src/services/module-loading/route-module-dependency-hasher.js +121 -0
  193. package/src/services/module-loading/server-module-transpiler.service.js +1 -1
  194. package/src/static-site-generator/README.md +33 -0
  195. package/src/static-site-generator/static-build-invalidation.d.ts +10 -0
  196. package/src/static-site-generator/static-build-invalidation.js +59 -0
  197. package/src/static-site-generator/static-export-context.d.ts +22 -0
  198. package/src/static-site-generator/static-export-context.js +0 -0
  199. package/src/static-site-generator/static-site-generator.d.ts +17 -20
  200. package/src/static-site-generator/static-site-generator.js +188 -85
  201. package/src/types/internal-types.d.ts +12 -9
  202. package/src/types/public-types.d.ts +87 -22
  203. package/src/utils/parse-cli-args.d.ts +1 -0
  204. package/src/utils/parse-cli-args.js +3 -0
  205. package/src/watchers/project-watcher.d.ts +14 -2
  206. package/src/watchers/project-watcher.js +50 -20
  207. package/src/build/rolldown-dev-build-adapter.d.ts +0 -82
  208. package/src/build/rolldown-dev-build-adapter.js +0 -166
  209. package/src/hmr/hmr.postcss.test.e2e.d.ts +0 -1
  210. package/src/hmr/hmr.postcss.test.e2e.js +0 -31
  211. package/src/hmr/hmr.test.e2e.d.ts +0 -1
  212. package/src/hmr/hmr.test.e2e.js +0 -43
  213. package/src/route-renderer/orchestration/ownership-planning.service.d.ts +0 -24
  214. package/src/route-renderer/orchestration/ownership-planning.service.js +0 -63
  215. package/src/route-renderer/orchestration/queued-foreign-subtree-resolution.service.d.ts +0 -91
  216. package/src/route-renderer/orchestration/queued-foreign-subtree-resolution.service.js +0 -170
@@ -1,19 +1,17 @@
1
- import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from "../../config/constants.js";
2
1
  import { appLogger } from "../../global/app-logger.js";
3
2
  import { SharedApplicationAdapter } from "../shared/application-adapter.js";
4
3
  import { resolveRuntimeBinding, resolveStaticRuntimeMode } from "../shared/runtime-app-bootstrap.js";
5
4
  import { createBunServerAdapter } from "./server-adapter.js";
6
- import { BunStaticPreviewHost } from "./static-preview-host.js";
7
5
  import { BunRuntimeHost } from "./runtime-host.js";
6
+ import { hostOwnsDevClient } from "../../dev/dev-client-ownership.js";
8
7
  class BunEcopagesApp extends SharedApplicationAdapter {
9
8
  serverAdapter;
10
9
  server = null;
10
+ stopped = false;
11
11
  runtimeHost;
12
- previewHost;
13
12
  constructor(options, dependencies) {
14
13
  super(options);
15
14
  this.runtimeHost = dependencies.runtimeHost;
16
- this.previewHost = dependencies.previewHost;
17
15
  }
18
16
  async fetch(request) {
19
17
  if (!this.serverAdapter) {
@@ -22,6 +20,12 @@ class BunEcopagesApp extends SharedApplicationAdapter {
22
20
  await this.serverAdapter.completeInitialization(this.server);
23
21
  return this.serverAdapter.handleRequest(request);
24
22
  }
23
+ async attachWebSocketUpgrades(httpServer, options) {
24
+ if (!this.serverAdapter) {
25
+ this.serverAdapter = await this.initializeServerAdapter();
26
+ }
27
+ this.serverAdapter.attachUserWebSocketUpgrades(httpServer, options);
28
+ }
25
29
  /**
26
30
  * Complete the initialization of the server adapter by processing dynamic routes
27
31
  * @param server The Bun server instance
@@ -40,24 +44,21 @@ class BunEcopagesApp extends SharedApplicationAdapter {
40
44
  cliArgs: this.cliArgs,
41
45
  serverOptions: this.serverOptions
42
46
  });
43
- appLogger.debug("initializeServerAdapter", {
44
- dev: this.cliArgs.dev,
45
- cliPort: this.cliArgs.port,
46
- cliHostname: this.cliArgs.hostname,
47
- envPort: process.env.ECOPAGES_PORT,
48
- envHostname: process.env.ECOPAGES_HOSTNAME,
49
- preferredPort: binding.preferredPort,
50
- preferredHostname: binding.preferredHostname,
51
- composedUrl: binding.runtimeOrigin
52
- });
53
- return await createBunServerAdapter({
47
+ return createBunServerAdapter({
54
48
  runtimeOrigin: binding.runtimeOrigin,
55
49
  appConfig: this.appConfig,
56
50
  apiHandlers: this.apiHandlers,
57
51
  staticRoutes: this.staticRoutes,
58
52
  errorHandler: this.errorHandler,
53
+ websocketHandlers: this.websocketHandlers.size > 0 ? this.websocketHandlers : void 0,
59
54
  options: { watch: binding.watch },
60
- serveOptions: binding.serveOptions
55
+ serveOptions: binding.serveOptions,
56
+ hostOwnsDevClient: hostOwnsDevClient(this.runtimeOptions),
57
+ deferRuntimeAssetSetup: resolveStaticRuntimeMode({
58
+ appConfig: this.appConfig,
59
+ cliArgs: this.cliArgs
60
+ }).canBuildWithoutRuntimeServer,
61
+ allowPortFallback: binding.allowPortFallback
61
62
  });
62
63
  }
63
64
  /**
@@ -66,17 +67,21 @@ class BunEcopagesApp extends SharedApplicationAdapter {
66
67
  * @param options.autoCompleteInitialization Whether to automatically complete initialization with dynamic routes after server start (defaults to true)
67
68
  */
68
69
  async start() {
70
+ if (this.stopped) {
71
+ this.serverAdapter = void 0;
72
+ this.stopped = false;
73
+ }
69
74
  if (!this.serverAdapter) {
70
75
  this.serverAdapter = await this.initializeServerAdapter();
71
76
  }
72
- const { dev, preview, build } = this.cliArgs;
77
+ const { dev, preview, build, force } = this.cliArgs;
73
78
  const staticRuntimeMode = resolveStaticRuntimeMode({
74
79
  appConfig: this.appConfig,
75
80
  cliArgs: this.cliArgs
76
81
  });
77
82
  if (staticRuntimeMode.canBuildWithoutRuntimeServer) {
78
83
  appLogger.debugTime("Building static pages");
79
- await this.serverAdapter.buildStatic({ preview });
84
+ await this.serverAdapter.buildStatic({ preview, force });
80
85
  appLogger.debugTimeEnd("Building static pages");
81
86
  if (build) {
82
87
  process.exit(0);
@@ -85,12 +90,7 @@ class BunEcopagesApp extends SharedApplicationAdapter {
85
90
  }
86
91
  const enableHmr = dev || !preview && !build;
87
92
  const serverOptions = this.serverAdapter.getServerOptions({ enableHmr });
88
- const configuredHostname = String(serverOptions.hostname ?? DEFAULT_ECOPAGES_HOSTNAME);
89
- const configuredPort = Number(serverOptions.port ?? DEFAULT_ECOPAGES_PORT);
90
- const runtimeServerOptions = (preview || build) && staticRuntimeMode.requiresFetchRuntime ? {
91
- ...serverOptions,
92
- port: 0
93
- } : serverOptions;
93
+ const runtimeServerOptions = serverOptions;
94
94
  this.server = await this.runtimeHost.start({
95
95
  serveOptions: runtimeServerOptions,
96
96
  handleRequest: async () => new Response(null, { status: 500 }),
@@ -108,30 +108,35 @@ class BunEcopagesApp extends SharedApplicationAdapter {
108
108
  );
109
109
  if (build || preview) {
110
110
  appLogger.debugTime("Building static pages");
111
- await this.serverAdapter.buildStatic({ preview: false });
112
- await this.runtimeHost.stop(this.server, { force: true });
113
- if (preview) {
114
- const previewPort = await this.previewHost.start({
115
- appConfig: this.appConfig,
116
- hostname: configuredHostname,
117
- port: configuredPort
118
- });
119
- if (previewPort) {
120
- appLogger.info(`Preview running at http://${configuredHostname}:${previewPort}`);
121
- }
122
- }
111
+ await this.serverAdapter.buildStatic({ preview, force });
112
+ const buildRuntimeServer = this.server;
113
+ this.server = null;
114
+ await this.runtimeHost.stop(buildRuntimeServer, { force: true });
123
115
  appLogger.debugTimeEnd("Building static pages");
124
116
  if (build) {
125
117
  process.exit(0);
126
118
  }
127
119
  }
128
- return this.server;
120
+ return this.server ?? void 0;
121
+ }
122
+ async stop(force = true) {
123
+ if (this.stopped) {
124
+ return;
125
+ }
126
+ if (this.server) {
127
+ const activeServer = this.server;
128
+ this.server = null;
129
+ await this.runtimeHost.stop(activeServer, { force });
130
+ }
131
+ if (this.serverAdapter) {
132
+ await this.serverAdapter.dispose();
133
+ }
134
+ this.stopped = true;
129
135
  }
130
136
  }
131
137
  async function createApp(options) {
132
138
  return new BunEcopagesApp(options, {
133
- runtimeHost: new BunRuntimeHost(),
134
- previewHost: new BunStaticPreviewHost()
139
+ runtimeHost: new BunRuntimeHost()
135
140
  });
136
141
  }
137
142
  export {
@@ -7,6 +7,7 @@ type BunSocketHandler = WebSocketHandler<unknown>;
7
7
  export interface HmrManagerParams {
8
8
  appConfig: EcoPagesAppConfig;
9
9
  bridge: ClientBridge;
10
+ registrationTimeoutMs?: number;
10
11
  }
11
12
  /**
12
13
  * Bun development HMR manager.
@@ -26,7 +27,7 @@ export declare class HmrManager extends SharedHmrManager {
26
27
  * generation to `SharedHmrManager`. The Bun subclass only supplies the
27
28
  * transport-specific dependency graph policy and websocket hook surface.
28
29
  */
29
- constructor({ appConfig, bridge }: HmrManagerParams);
30
+ constructor({ appConfig, bridge, registrationTimeoutMs }: HmrManagerParams);
30
31
  /**
31
32
  * Reuses the shared in-memory dependency graph when possible and otherwise
32
33
  * creates the Bun-compatible default graph implementation.
@@ -13,8 +13,8 @@ class HmrManager extends SharedHmrManager {
13
13
  * generation to `SharedHmrManager`. The Bun subclass only supplies the
14
14
  * transport-specific dependency graph policy and websocket hook surface.
15
15
  */
16
- constructor({ appConfig, bridge }) {
17
- super({ appConfig, bridge });
16
+ constructor({ appConfig, bridge, registrationTimeoutMs }) {
17
+ super({ appConfig, bridge, registrationTimeoutMs });
18
18
  }
19
19
  /**
20
20
  * Reuses the shared in-memory dependency graph when possible and otherwise
@@ -1,6 +1,7 @@
1
+ import type { Server as NodeHttpServer } from 'node:http';
1
2
  import type { Server, WebSocketHandler } from 'bun';
2
3
  import type { EcoPagesAppConfig } from '../../types/internal-types.js';
3
- import type { ApiHandler, ErrorHandler, StaticRoute } from '../../types/public-types.js';
4
+ import type { ApiHandler, ErrorHandler, StaticRoute, EcopagesWebSocketHandler } from '../../types/public-types.js';
4
5
  import { SharedServerAdapter } from '../shared/server-adapter.js';
5
6
  import type { ServerAdapterResult } from '../abstract/server-adapter.js';
6
7
  import type { StaticPreviewHost } from '../shared/static-preview-host.js';
@@ -32,9 +33,14 @@ export interface BunServerAdapterParams {
32
33
  apiHandlers?: ApiHandler<string, Request, BunServerInstance>[];
33
34
  staticRoutes?: StaticRoute[];
34
35
  errorHandler?: ErrorHandler;
36
+ websocketHandlers?: Map<string, EcopagesWebSocketHandler<any, any>>;
35
37
  options?: {
36
38
  watch?: boolean;
37
39
  };
40
+ delegateBrowserReloadToHost?: boolean;
41
+ hostOwnsDevClient?: boolean;
42
+ deferRuntimeAssetSetup?: boolean;
43
+ allowPortFallback?: boolean;
38
44
  hmrManager?: HmrManager;
39
45
  bridge?: ClientBridge;
40
46
  previewHost?: StaticPreviewHost;
@@ -45,9 +51,14 @@ export interface BunServerAdapterResult extends ServerAdapterResult {
45
51
  }) => BunServeOptions;
46
52
  buildStatic: (options?: {
47
53
  preview?: boolean;
54
+ force?: boolean;
48
55
  }) => Promise<void>;
49
56
  completeInitialization: (server?: BunServerInstance | null) => Promise<void>;
50
57
  handleRequest: (request: Request) => Promise<Response>;
58
+ attachUserWebSocketUpgrades: (server: NodeHttpServer, options?: {
59
+ passthroughUnmatched?: boolean;
60
+ }) => void;
61
+ dispose: () => Promise<void>;
51
62
  }
52
63
  /**
53
64
  * Bun transport adapter that wires shared Ecopages request handling onto a live
@@ -71,7 +82,39 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
71
82
  private initializationPromise;
72
83
  private fullyInitialized;
73
84
  serverInstance: BunServerInstance | null;
85
+ private projectWatcher;
86
+ private adapterDisposed;
87
+ private readonly deferRuntimeAssetSetup;
88
+ private readonly allowPortFallback;
74
89
  private readonly previewHost;
90
+ /**
91
+ * Reference to the application-level WebSocket handlers map.
92
+ *
93
+ * @remarks
94
+ * This is a reference to the map owned by `AbstractApplicationAdapter`,
95
+ * passed in via the constructor. The Bun adapter reads from it to wire
96
+ * WebSocket upgrades for user-registered patterns.
97
+ */
98
+ protected websocketHandlers: Map<string, EcopagesWebSocketHandler<any, any>>;
99
+ private registerBunRuntimePlugin;
100
+ private adaptBunWebSocket;
101
+ /**
102
+ * Resolves the per-connection context for a Bun user connection.
103
+ *
104
+ * @remarks
105
+ * `context()` is invoked exactly once per accepted connection. Its
106
+ * resolved value is shared by all subsequent lifecycle hooks. If
107
+ * `context()` throws, the connection is closed immediately with code
108
+ * 1011 (server error) and the error is logged.
109
+ *
110
+ * @param request - The original upgrade request (best-effort reconstructed)
111
+ * @param handler - The registered handler
112
+ * @param kind - The registered route pattern
113
+ * @param params - Dynamic path parameters
114
+ * @param search - Query string parameters
115
+ * @returns The resolved per-connection context
116
+ */
117
+ private resolveBunContext;
75
118
  /**
76
119
  * Creates a Bun server adapter with already-resolved runtime collaborators.
77
120
  *
@@ -81,11 +124,17 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
81
124
  * is constructed, those collaborators are mandatory because the adapter cannot
82
125
  * initialize Bun HMR or preview flows without them.
83
126
  */
84
- constructor({ appConfig, runtimeOrigin, serveOptions, apiHandlers, staticRoutes, errorHandler, options, hmrManager, bridge, previewHost, }: BunServerAdapterParams & {
127
+ constructor({ appConfig, runtimeOrigin, serveOptions, apiHandlers, staticRoutes, errorHandler, websocketHandlers, options, hostOwnsDevClient, deferRuntimeAssetSetup, allowPortFallback, hmrManager, bridge, previewHost, }: BunServerAdapterParams & {
85
128
  hmrManager: HmrManager;
86
129
  bridge: ClientBridge;
87
130
  previewHost: StaticPreviewHost;
88
131
  });
132
+ /**
133
+ * Wires user WebSocket routes onto a Node HTTP server used by host integrations.
134
+ */
135
+ attachUserWebSocketUpgrades(server: NodeHttpServer, options?: {
136
+ passthroughUnmatched?: boolean;
137
+ }): void;
89
138
  /**
90
139
  * Returns whether adapter-level HTML responses still need HMR runtime injection.
91
140
  *
@@ -94,26 +143,11 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
94
143
  * adapter-level check exists for explicit API handlers that return HTML and
95
144
  * would otherwise bypass the route wrapper entirely.
96
145
  */
97
- private shouldInjectHmrScript;
98
- /**
99
- * Delegates the HTML-response test to the shared response helper used by both
100
- * adapters.
101
- */
102
- private isHtmlResponse;
103
- /**
104
- * Injects HMR script into HTML responses in development mode.
105
- * Ensures explicit API handlers that return HTML get auto-reload capability.
106
- */
107
146
  private maybeInjectHmrScript;
108
147
  /**
109
148
  * Initializes the server adapter's core runtime components.
110
149
  */
111
150
  initialize(): Promise<void>;
112
- /**
113
- * Copies the source `public` directory into the runtime output and ensures the
114
- * HMR assets directory exists before any runtime bundles are emitted.
115
- */
116
- private prepareRuntimePublicDir;
117
151
  /**
118
152
  * Registers runtime plugins and propagates the final HMR manager into each
119
153
  * integration.
@@ -134,13 +168,31 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
134
168
  * Builds the `Bun.serve()` options for the current adapter state.
135
169
  *
136
170
  * @remarks
137
- * The HMR-enabled variant wraps the base fetch handler so one Bun server can
138
- * serve normal requests, accept HMR websocket upgrades, and expose the HMR
139
- * runtime asset without splitting responsibility across separate listeners.
171
+ * When HMR is enabled the websocket dispatcher merges HMR and user handlers,
172
+ * routing by the `kind` field embedded in socket data at upgrade time.
173
+ * This prevents user-registered websocket handlers from being silently overwritten
174
+ * by the HMR handler in development mode.
175
+ *
176
+ * User WebSocket paths are intercepted in the fetch handler via the pattern matcher.
177
+ * The upgrade happens implicitly — no manual GET route registration needed.
140
178
  */
141
179
  getServerOptions({ enableHmr }?: {
142
180
  enableHmr?: boolean | undefined;
143
181
  }): BunServeOptions;
182
+ private createBunUserLifecycle;
183
+ /**
184
+ * @remarks
185
+ * HMR and user sockets share one Bun `websocket` handler. Upgrade tags HMR
186
+ * connections with `kind: '__hmr__'`; everything else routes to the user lifecycle.
187
+ */
188
+ private createHmrAwareWebSocketHandler;
189
+ /**
190
+ * @remarks
191
+ * When `serveHmrEndpoints` is set, `/_hmr` and `/_hmr_runtime.js` are checked
192
+ * before user websocket patterns so HMR upgrades are never captured by app routes.
193
+ * Production mode with only user handlers skips the HMR branch entirely.
194
+ */
195
+ private wrapFetchWithWebSocketUpgrades;
144
196
  /**
145
197
  * Helper method to retrieve and parse the request body.
146
198
  * Handles JSON and plain text content types.
@@ -163,6 +215,7 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
163
215
  */
164
216
  buildStatic(options?: {
165
217
  preview?: boolean;
218
+ force?: boolean;
166
219
  }): Promise<void>;
167
220
  /**
168
221
  * Initializes the server with dynamic routes after server creation.
@@ -184,6 +237,14 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
184
237
  * @returns Configured adapter with server methods
185
238
  */
186
239
  createAdapter(): Promise<BunServerAdapterResult>;
240
+ /**
241
+ * Releases dev-time resources owned by the adapter.
242
+ *
243
+ * @remarks
244
+ * Safe to call multiple times. Does not stop the bound Bun server — callers
245
+ * should shut down transport through the runtime host before disposing.
246
+ */
247
+ dispose(): Promise<void>;
187
248
  /**
188
249
  * Handles HTTP requests by passing them securely to the shared core router adapter.
189
250
  *