@ecopages/core 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +2 -2
  2. package/package.json +3 -3
  3. package/src/adapters/node/create-app.d.ts +29 -11
  4. package/src/adapters/node/create-app.js +78 -67
  5. package/src/adapters/node/dev-session.js +0 -1
  6. package/src/adapters/node/http-request-bridge.d.ts +4 -0
  7. package/src/adapters/node/http-request-bridge.js +9 -1
  8. package/src/adapters/node/runtime-host.d.ts +23 -6
  9. package/src/adapters/node/runtime-host.js +27 -8
  10. package/src/adapters/node/server-adapter.d.ts +10 -35
  11. package/src/adapters/node/server-adapter.js +21 -58
  12. package/src/adapters/shared/hmr/hmr-manager.d.ts +9 -5
  13. package/src/adapters/shared/hmr/hmr-manager.js +38 -54
  14. package/src/adapters/shared/http/api-request-pipeline.d.ts +3 -12
  15. package/src/adapters/shared/http/api-request-pipeline.js +7 -7
  16. package/src/adapters/shared/http/dist-file-handler.d.ts +16 -0
  17. package/src/adapters/shared/http/dist-file-handler.js +172 -0
  18. package/src/adapters/shared/http/explicit-static-route-matcher.js +2 -1
  19. package/src/adapters/shared/http/fs-server-response-matcher.js +3 -2
  20. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +5 -7
  21. package/src/adapters/shared/runtime/bind-runtime-server.js +5 -11
  22. package/src/adapters/shared/runtime/port-manager.d.ts +2 -11
  23. package/src/adapters/shared/runtime/port-manager.js +3 -28
  24. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +6 -9
  25. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +2 -5
  26. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +1 -3
  27. package/src/adapters/shared/runtime/server-request-pipeline.js +1 -5
  28. package/src/adapters/shared/runtime/server-static-builder.d.ts +3 -3
  29. package/src/adapters/shared/runtime/server-static-builder.js +3 -3
  30. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +2 -1
  31. package/src/adapters/shared/ws/websocket-lifecycle.d.ts +5 -6
  32. package/src/adapters/shared/ws/websocket-lifecycle.js +1 -2
  33. package/src/build/build-adapter.d.ts +2 -19
  34. package/src/build/build-adapter.js +0 -21
  35. package/src/build/cache/cache-keys.d.ts +0 -3
  36. package/src/build/cache/cache-keys.js +0 -14
  37. package/src/build/cache/pages-unified-graph-build.js +2 -17
  38. package/src/build/contracts/build-contracts.d.ts +0 -3
  39. package/src/build/rolldown/rolldown-build-adapter.d.ts +0 -1
  40. package/src/build/rolldown/rolldown-build-adapter.js +1 -2
  41. package/src/build/rolldown/rolldown-build-invocation-metrics.d.ts +1 -2
  42. package/src/build/rolldown/rolldown-build-invocation-metrics.js +5 -12
  43. package/src/build/runtime/build-queue.d.ts +8 -13
  44. package/src/build/runtime/build-queue.js +6 -17
  45. package/src/build/server/app-module-loader.service.d.ts +1 -1
  46. package/src/build/server/app-module-loader.service.js +0 -2
  47. package/src/build/server/page-module-import.service.d.ts +2 -3
  48. package/src/build/server/page-module-import.service.js +3 -4
  49. package/src/build/server-bundle-deploy-manifest.d.ts +5 -0
  50. package/src/build/server-bundle-deploy-manifest.js +15 -1
  51. package/src/build.d.ts +2 -2
  52. package/src/build.js +2 -2
  53. package/src/config/assembly/app-runtime.d.ts +2 -2
  54. package/src/config/assembly/app-runtime.js +2 -2
  55. package/src/config/assembly/finalize-config.d.ts +4 -4
  56. package/src/config/assembly/finalize-config.js +4 -5
  57. package/src/config/internal-types.d.ts +0 -7
  58. package/src/config/user-config-types.d.ts +0 -4
  59. package/src/diagnostics/request-pipeline-metrics.d.ts +3 -3
  60. package/src/diagnostics/request-pipeline-metrics.js +4 -4
  61. package/src/errors/http-error.d.ts +2 -2
  62. package/src/errors/http-error.js +4 -4
  63. package/src/hmr/client/hmr-runtime.js +16 -7
  64. package/src/hmr/client/module-update.d.ts +7 -0
  65. package/src/hmr/client/module-update.js +21 -4
  66. package/src/hmr/hmr-strategy.d.ts +0 -3
  67. package/src/hmr/hmr-strategy.js +0 -3
  68. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -3
  69. package/src/hmr/strategies/js-hmr-strategy.js +3 -6
  70. package/src/plugins/alias-resolver-cache.d.ts +4 -3
  71. package/src/plugins/alias-resolver-cache.js +4 -3
  72. package/src/plugins/eco-component-meta-plugin.d.ts +10 -1
  73. package/src/plugins/eco-component-meta-plugin.js +66 -10
  74. package/src/plugins/foreign-jsx-override-plugin.js +2 -1
  75. package/src/route-renderer/error-pages/default-error-pages.js +2 -1
  76. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -1
  77. package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +0 -1
  78. package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -5
  79. package/src/route-renderer/orchestration/integration-renderer.js +13 -14
  80. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -6
  81. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -6
  82. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
  83. package/src/route-renderer/page-loading/page-module-loader.js +1 -1
  84. package/src/route-renderer/route-renderer.d.ts +2 -5
  85. package/src/route-renderer/route-renderer.js +2 -4
  86. package/src/router/client/link-navigation-policy.d.ts +4 -1
  87. package/src/router/client/link-navigation-policy.js +20 -6
  88. package/src/router/server/route-registry.d.ts +0 -1
  89. package/src/router/server/route-registry.js +2 -11
  90. package/src/router/server/segment-path-matcher.d.ts +12 -0
  91. package/src/router/server/segment-path-matcher.js +30 -0
  92. package/src/static-site-generator/static-site-generator.d.ts +0 -5
  93. package/src/static-site-generator/static-site-generator.js +2 -15
  94. package/src/types/contracts.d.ts +17 -27
  95. package/src/types/public-types.d.ts +1 -1
  96. package/src/utils/format-error-chain.d.ts +9 -0
  97. package/src/utils/format-error-chain.js +20 -0
  98. package/src/utils/invariant.d.ts +6 -1
  99. package/src/utils/invariant.js +7 -2
  100. package/src/watchers/project-watcher.d.ts +20 -1
  101. package/src/watchers/project-watcher.js +40 -9
  102. package/src/watchers/workspace-package-watch-roots.js +5 -5
  103. package/src/adapters/README.md +0 -58
  104. package/src/adapters/shared/hmr/hmr-manager.test-helpers.d.ts +0 -28
  105. package/src/adapters/shared/hmr/hmr-manager.test-helpers.js +0 -53
  106. package/src/adapters/shared/runtime/runtime-host.d.ts +0 -15
  107. package/src/adapters/shared/runtime/runtime-host.js +0 -1
  108. package/src/assets/README.md +0 -35
  109. package/src/build/README.md +0 -298
  110. package/src/build/server/README.md +0 -50
  111. package/src/cache/README.md +0 -5
  112. package/src/client/README.md +0 -5
  113. package/src/client/navigation-scripts/navigation-scripts.test.browser.d.ts +0 -1
  114. package/src/client/navigation-scripts/navigation-scripts.test.browser.js +0 -111
  115. package/src/client/scroll.test.browser.d.ts +0 -1
  116. package/src/client/scroll.test.browser.js +0 -31
  117. package/src/client/view-transitions.test.browser.d.ts +0 -1
  118. package/src/client/view-transitions.test.browser.js +0 -53
  119. package/src/config/README.md +0 -58
  120. package/src/config/constants.d.ts +0 -1
  121. package/src/config/constants.js +0 -1
  122. package/src/dev/README.md +0 -61
  123. package/src/dev/invalidation/README.md +0 -11
  124. package/src/dev-toolbar/README.md +0 -66
  125. package/src/diagnostics/README.md +0 -11
  126. package/src/eco/README.md +0 -776
  127. package/src/errors/README.md +0 -5
  128. package/src/global/README.md +0 -5
  129. package/src/hmr/README.md +0 -64
  130. package/src/hmr/client/build-error-overlay.test.browser.d.ts +0 -1
  131. package/src/hmr/client/build-error-overlay.test.browser.js +0 -48
  132. package/src/hmr/client/hmr-runtime.test.browser.d.ts +0 -1
  133. package/src/hmr/client/hmr-runtime.test.browser.js +0 -32
  134. package/src/hmr/entrypoint-dependency-graph.d.ts +0 -12
  135. package/src/hmr/entrypoint-dependency-graph.js +0 -27
  136. package/src/hmr/hmr-file-change-prep.d.ts +0 -9
  137. package/src/hmr/hmr-file-change-prep.js +0 -11
  138. package/src/html/README.md +0 -15
  139. package/src/html-pages/README.md +0 -104
  140. package/src/islands/README.md +0 -44
  141. package/src/page-cache/README.md +0 -17
  142. package/src/plugins/README.md +0 -53
  143. package/src/route-renderer/GRAPH.md +0 -142
  144. package/src/route-renderer/README.md +0 -160
  145. package/src/route-renderer/error-pages/README.md +0 -11
  146. package/src/route-renderer/orchestration/custom-element-scripts/README.md +0 -15
  147. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.d.ts +0 -39
  148. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +0 -94
  149. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.d.ts +0 -35
  150. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.js +0 -69
  151. package/src/router/README.md +0 -160
  152. package/src/router/client/link-intent.test.browser.d.ts +0 -1
  153. package/src/router/client/link-intent.test.browser.js +0 -33
  154. package/src/router/client/link-navigation-policy.test.browser.d.ts +0 -1
  155. package/src/router/client/link-navigation-policy.test.browser.js +0 -142
  156. package/src/router/client/navigation-commit.test.browser.d.ts +0 -1
  157. package/src/router/client/navigation-commit.test.browser.js +0 -116
  158. package/src/router/client/navigation-document.test.browser.d.ts +0 -1
  159. package/src/router/client/navigation-document.test.browser.js +0 -77
  160. package/src/router/client/navigation-head.test.browser.d.ts +0 -1
  161. package/src/router/client/navigation-head.test.browser.js +0 -101
  162. package/src/router/client/navigation-lifecycle.test.browser.d.ts +0 -1
  163. package/src/router/client/navigation-lifecycle.test.browser.js +0 -97
  164. package/src/router/client/navigation-view-transition.test.browser.d.ts +0 -1
  165. package/src/router/client/navigation-view-transition.test.browser.js +0 -189
  166. package/src/router/client/staged-stylesheets.test-fixtures.d.ts +0 -18
  167. package/src/router/client/staged-stylesheets.test-fixtures.js +0 -31
  168. package/src/static-site-generator/README.md +0 -67
  169. package/src/static-site-generator/static-site-generator.test-utils.d.ts +0 -2
  170. package/src/static-site-generator/static-site-generator.test-utils.js +0 -41
  171. package/src/types/README.md +0 -5
  172. package/src/utils/README.md +0 -7
  173. package/src/validation/README.md +0 -9
  174. package/src/watchers/README.md +0 -15
  175. package/src/watchers/project-watcher.test-helpers.d.ts +0 -60
  176. package/src/watchers/project-watcher.test-helpers.js +0 -108
@@ -1,9 +1,7 @@
1
1
  import { type Server as NodeHttpServer } from 'node:http';
2
2
  import type { EcoPagesAppConfig } from '../../config/internal-types.js';
3
3
  import type { ApiHandler, ErrorHandler, StaticRoute, ErrorPageLoaders, EcopagesWebSocketHandler } from '../../types/contracts.js';
4
- import { type ServerRequestContext } from '../shared/runtime/server-request-pipeline.js';
5
- import type { RuntimeHost } from '../shared/runtime/runtime-host.js';
6
- import type { NodeRuntimeServeOptions } from './runtime-host.js';
4
+ import type { RuntimeHost } from './runtime-host.js';
7
5
  import type { AppRuntime } from '../../config/assembly/app-runtime.js';
8
6
  export type NodeServerInstance = NodeHttpServer;
9
7
  export type NodeServeAdapterServerOptions = {
@@ -13,6 +11,7 @@ export type NodeServeAdapterServerOptions = {
13
11
  export interface NodeServerAdapterParams {
14
12
  appConfig: EcoPagesAppConfig;
15
13
  runtime: AppRuntime;
14
+ runtimeHost: RuntimeHost;
16
15
  serveOptions: NodeServeAdapterServerOptions;
17
16
  apiHandlers?: ApiHandler[];
18
17
  staticRoutes?: StaticRoute[];
@@ -46,8 +45,8 @@ export interface NodeServerAdapterParams {
46
45
  * 2. `completeInitialization(server)` — called once the HTTP server is listening.
47
46
  * Conditionally wires HMR, WebSocket upgrades, and the file watcher when
48
47
  * `options.watch` is `true`.
49
- * 3. `handleRequest(request)` — delegates to `handleSharedRequest` for routing;
50
- * intercepts `ClientAbortError` to return 499 instead of 500 and sends every
48
+ * 3. `handleRequest(request)` — delegates routing to `ServerRequestPipeline`;
49
+ * answers a client disconnect with 499 instead of 500 and sends every
51
50
  * other escaped error through the shared `app.onError` boundary.
52
51
  * 4. `buildStatic()` — generates static pages in-process through the shared
53
52
  * static builder (no runtime server), then optionally starts the preview server.
@@ -80,17 +79,11 @@ export declare class NodeServerAdapter {
80
79
  private resolveRequestReadiness;
81
80
  private rejectRequestReadiness;
82
81
  /**
83
- * Reference to the application-level WebSocket handlers map.
84
- *
85
82
  * @remarks
86
- * This is a reference to the map owned by `EcopagesApp`,
87
- * passed in via the constructor. The Node adapter reads from it to wire
88
- * WebSocket upgrades for user-registered patterns.
83
+ * The map owned by `EcopagesApp`, so WebSocket upgrades see every user-registered pattern.
89
84
  */
90
- protected websocketHandlers: Map<string, EcopagesWebSocketHandler<unknown, Record<string, string>>>;
91
- constructor(options: NodeServerAdapterParams & {
92
- runtimeHost: RuntimeHost<NodeHttpServer, NodeRuntimeServeOptions>;
93
- });
85
+ private readonly websocketHandlers;
86
+ constructor(options: NodeServerAdapterParams);
94
87
  /**
95
88
  * Prepares the adapter for use.
96
89
  *
@@ -137,28 +130,12 @@ export declare class NodeServerAdapter {
137
130
  dispose(): Promise<void>;
138
131
  private disposeResources;
139
132
  private disposeRuntimeResources;
140
- protected configureSharedResponseHandlers(options: {
141
- staticRoutes: StaticRoute[];
142
- errorPageLoaders?: ErrorPageLoaders;
143
- }): void;
144
- protected initializeSharedRouteHandling(options: {
145
- staticRoutes: StaticRoute[];
146
- errorPageLoaders?: ErrorPageLoaders;
147
- }): Promise<void>;
148
- protected createSharedWatchRefreshCallback(options: {
149
- staticRoutes: StaticRoute[];
150
- errorPageLoaders?: ErrorPageLoaders;
151
- onRoutesReady?: () => Promise<void> | void;
152
- onError?: (error: Error) => Promise<void> | void;
153
- }): () => Promise<void>;
154
- handleSharedRequest(request: Request, context: ServerRequestContext): Promise<Response>;
155
133
  /**
156
134
  * Handles a Web `Request` directly through the shared pipeline and returns a Web `Response`.
157
135
  *
158
- * Delegates to `handleSharedRequest` for all routing, caching, and response
159
- * handler logic. Escaped errors go through the shared `app.onError`
160
- * boundary, which answers client aborts (see {@link isClientAbortError}) with 499. This path supports
161
- * request-only `app.fetch()` use without a bound listener.
136
+ * Delegates all routing, caching, and response handler logic to `ServerRequestPipeline`. Escaped
137
+ * errors go through the shared `app.onError` boundary, which answers client aborts with 499. This
138
+ * path supports request-only `app.fetch()` use without a bound listener.
162
139
  */
163
140
  handleRequest(request: Request): Promise<Response>;
164
141
  /**
@@ -187,5 +164,3 @@ export declare class NodeServerAdapter {
187
164
  */
188
165
  completeInitialization(server: NodeServerInstance): Promise<void>;
189
166
  }
190
- /** Creates the concrete Node server owned by `EcopagesApp`. */
191
- export declare function createNodeServerAdapter(params: NodeServerAdapterParams, runtimeHost: RuntimeHost<NodeHttpServer, NodeRuntimeServeOptions>): NodeServerAdapter;
@@ -2,7 +2,6 @@ import {} from 'node:http';
2
2
  import path from 'node:path';
3
3
  import { fileSystem } from '@ecopages/file-system';
4
4
  import { setupAppRuntimeIntegrations, setupAppRuntimePlugins } from '../../build/build-adapter.js';
5
- import { installBuildQueue } from '../../build/runtime/build-queue.js';
6
5
  import { appLogger } from '../../global/app-logger.js';
7
6
  import { attachNodeHttpWebSocketUpgrades } from '../shared/ws/node-http-websocket-upgrades.js';
8
7
  import { StaticSiteGenerator } from '../../static-site-generator/static-site-generator.js';
@@ -12,7 +11,6 @@ import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from '../../constant
12
11
  import { disposeDevResources, prepareRuntimePublicDir } from '../shared/runtime/runtime-server-lifecycle.js';
13
12
  import { resolveServeRuntimeOrigin } from '../shared/runtime/runtime-app-bootstrap.js';
14
13
  import { bindRuntimeServer } from '../shared/runtime/bind-runtime-server.js';
15
- import { isNodeClientAbortError } from './http-request-bridge.js';
16
14
  import { serveDistFile } from '../shared/http/dist-file-handler.js';
17
15
  import { DevSession } from './dev-session.js';
18
16
  import { prebuildProductionPageBrowserGraphsFromManifest } from '../../static-site-generator/production-page-browser-graph-prebuild.js';
@@ -27,8 +25,8 @@ import { prebuildProductionPageBrowserGraphsFromManifest } from '../../static-si
27
25
  * 2. `completeInitialization(server)` — called once the HTTP server is listening.
28
26
  * Conditionally wires HMR, WebSocket upgrades, and the file watcher when
29
27
  * `options.watch` is `true`.
30
- * 3. `handleRequest(request)` — delegates to `handleSharedRequest` for routing;
31
- * intercepts `ClientAbortError` to return 499 instead of 500 and sends every
28
+ * 3. `handleRequest(request)` — delegates routing to `ServerRequestPipeline`;
29
+ * answers a client disconnect with 499 instead of 500 and sends every
32
30
  * other escaped error through the shared `app.onError` boundary.
33
31
  * 4. `buildStatic()` — generates static pages in-process through the shared
34
32
  * static builder (no runtime server), then optionally starts the preview server.
@@ -61,14 +59,10 @@ export class NodeServerAdapter {
61
59
  resolveRequestReadiness = () => { };
62
60
  rejectRequestReadiness = () => { };
63
61
  /**
64
- * Reference to the application-level WebSocket handlers map.
65
- *
66
62
  * @remarks
67
- * This is a reference to the map owned by `EcopagesApp`,
68
- * passed in via the constructor. The Node adapter reads from it to wire
69
- * WebSocket upgrades for user-registered patterns.
63
+ * The map owned by `EcopagesApp`, so WebSocket upgrades see every user-registered pattern.
70
64
  */
71
- websocketHandlers = new Map();
65
+ websocketHandlers;
72
66
  constructor(options) {
73
67
  this.appConfig = options.appConfig;
74
68
  this.runtime = options.runtime;
@@ -83,7 +77,6 @@ export class NodeServerAdapter {
83
77
  appConfig: this.appConfig,
84
78
  runtime: this.runtime,
85
79
  watch: this.options.watch,
86
- isClientAbortError: isNodeClientAbortError,
87
80
  });
88
81
  this.runtimeAssetSetup = options.runtimeAssetSetup ?? 'start';
89
82
  this.allowPortFallback = options.allowPortFallback !== false;
@@ -93,9 +86,7 @@ export class NodeServerAdapter {
93
86
  this.errorPageLoaders = options.errorPageLoaders ?? {};
94
87
  this.errorHandler = options.errorHandler;
95
88
  this.runtimeHost = options.runtimeHost;
96
- if (options.websocketHandlers) {
97
- this.websocketHandlers = options.websocketHandlers;
98
- }
89
+ this.websocketHandlers = options.websocketHandlers ?? new Map();
99
90
  }
100
91
  /**
101
92
  * Prepares the adapter for use.
@@ -136,7 +127,6 @@ export class NodeServerAdapter {
136
127
  return this.ready;
137
128
  }
138
129
  async initializeResources() {
139
- installBuildQueue(this.appConfig);
140
130
  if (this.runtimeAssetSetup !== 'export') {
141
131
  prepareRuntimePublicDir(this.appConfig);
142
132
  }
@@ -156,7 +146,7 @@ export class NodeServerAdapter {
156
146
  appConfig: this.appConfig,
157
147
  });
158
148
  }
159
- await this.initializeSharedRouteHandling({
149
+ await this.requestPipeline.initializeRouteHandling({
160
150
  staticRoutes: this.staticRoutes,
161
151
  errorPageLoaders: this.errorPageLoaders,
162
152
  });
@@ -207,16 +197,14 @@ export class NodeServerAdapter {
207
197
  await this.stopPreviewServerNow();
208
198
  this.ensurePreviewCanStart();
209
199
  const binding = await bindRuntimeServer(this.runtimeHost, {
210
- startOptions: {
211
- serveOptions: {
212
- hostname: String(this.serveOptions.hostname || DEFAULT_ECOPAGES_HOSTNAME),
213
- port: Number(this.serveOptions.port ?? DEFAULT_ECOPAGES_PORT),
214
- handleRequest: (request) => serveDistFile(request, {
215
- distDir: this.appConfig.absolutePaths.distDir,
216
- watchMode: false,
217
- resolveExportedPages: true,
218
- }),
219
- },
200
+ serveOptions: {
201
+ hostname: String(this.serveOptions.hostname || DEFAULT_ECOPAGES_HOSTNAME),
202
+ port: Number(this.serveOptions.port ?? DEFAULT_ECOPAGES_PORT),
203
+ handleRequest: (request) => serveDistFile(request, {
204
+ distDir: this.appConfig.absolutePaths.distDir,
205
+ watchMode: false,
206
+ resolveExportedPages: true,
207
+ }),
220
208
  },
221
209
  allowPortFallback: this.allowPortFallback,
222
210
  usePortManager: true,
@@ -283,12 +271,7 @@ export class NodeServerAdapter {
283
271
  await session.dispose();
284
272
  }
285
273
  else {
286
- await disposeDevResources({
287
- projectWatcher: undefined,
288
- appConfig: this.appConfig,
289
- bridge: undefined,
290
- stopPreviewServer: async () => { },
291
- });
274
+ await disposeDevResources({ appConfig: this.appConfig });
292
275
  }
293
276
  }
294
277
  catch (error) {
@@ -306,25 +289,12 @@ export class NodeServerAdapter {
306
289
  if (errors.length > 1)
307
290
  throw new AggregateError(errors, 'Failed to release server adapter resources');
308
291
  }
309
- configureSharedResponseHandlers(options) {
310
- this.requestPipeline.configureResponseHandlers(options);
311
- }
312
- initializeSharedRouteHandling(options) {
313
- return this.requestPipeline.initializeRouteHandling(options);
314
- }
315
- createSharedWatchRefreshCallback(options) {
316
- return this.requestPipeline.createWatchRefreshCallback(options);
317
- }
318
- async handleSharedRequest(request, context) {
319
- return await this.requestPipeline.handleSharedRequest(request, context);
320
- }
321
292
  /**
322
293
  * Handles a Web `Request` directly through the shared pipeline and returns a Web `Response`.
323
294
  *
324
- * Delegates to `handleSharedRequest` for all routing, caching, and response
325
- * handler logic. Escaped errors go through the shared `app.onError`
326
- * boundary, which answers client aborts (see {@link isClientAbortError}) with 499. This path supports
327
- * request-only `app.fetch()` use without a bound listener.
295
+ * Delegates all routing, caching, and response handler logic to `ServerRequestPipeline`. Escaped
296
+ * errors go through the shared `app.onError` boundary, which answers client aborts with 499. This
297
+ * path supports request-only `app.fetch()` use without a bound listener.
328
298
  */
329
299
  async handleRequest(request) {
330
300
  return await this.handleRequestInternal(request, false);
@@ -349,7 +319,7 @@ export class NodeServerAdapter {
349
319
  if (waitForReadiness) {
350
320
  await this.requestReadiness;
351
321
  }
352
- return await this.handleSharedRequest(request, context);
322
+ return await this.requestPipeline.handleSharedRequest(request, context);
353
323
  }
354
324
  catch (error) {
355
325
  return await this.requestPipeline.handleUnexpectedRequestError(error, request, context);
@@ -382,11 +352,11 @@ export class NodeServerAdapter {
382
352
  requestPipeline: this.requestPipeline,
383
353
  websocketHandlers: this.websocketHandlers,
384
354
  onDevelopmentRestart: this.onDevelopmentRestart,
385
- configureResponseHandlers: () => this.configureSharedResponseHandlers({
355
+ configureResponseHandlers: () => this.requestPipeline.configureResponseHandlers({
386
356
  staticRoutes: this.staticRoutes,
387
357
  errorPageLoaders: this.errorPageLoaders,
388
358
  }),
389
- createWatchRefreshCallback: () => this.createSharedWatchRefreshCallback({
359
+ createWatchRefreshCallback: () => this.requestPipeline.createWatchRefreshCallback({
390
360
  staticRoutes: this.staticRoutes,
391
361
  errorPageLoaders: this.errorPageLoaders,
392
362
  }),
@@ -418,10 +388,3 @@ export class NodeServerAdapter {
418
388
  });
419
389
  }
420
390
  }
421
- /** Creates the concrete Node server owned by `EcopagesApp`. */
422
- export function createNodeServerAdapter(params, runtimeHost) {
423
- return new NodeServerAdapter({
424
- ...params,
425
- runtimeHost,
426
- });
427
- }
@@ -4,10 +4,8 @@ import { type DevelopmentInvalidationService } from '../../../dev/invalidation/d
4
4
  import type { ClientBridgeEvent, HmrFileChangeOptions, RegisteredScriptEntrypointChangeHandler, ResolvedHmrEntrypoint } from '../../../types/contracts.js';
5
5
  import { DevTransformEntrypointRegistry } from './dev-transform-entrypoint-registry.js';
6
6
  import { BrowserBundleService } from '../../../assets/browser-bundle.service.js';
7
- import { InMemoryEntrypointDependencyGraph } from '../../../hmr/entrypoint-dependency-graph.js';
8
7
  import { DevTransformServer } from '../../../dev/transform-server/dev-transform-server.js';
9
8
  import type { DevTransformBundleContributor } from '../../../dev/transform-server/types.js';
10
- type HandleFileChangeOptions = HmrFileChangeOptions;
11
9
  type HmrManagerParams = {
12
10
  appConfig: EcoPagesAppConfig;
13
11
  bridge: IClientBridge;
@@ -18,12 +16,19 @@ export declare class HmrManager implements IHmrManager {
18
16
  protected runtimeWorkDir: string;
19
17
  protected enabled: boolean;
20
18
  protected strategies: HmrStrategy[];
19
+ /**
20
+ * @remarks
21
+ * Kept out of `strategies` because it matches every path: it reloads the page when no other strategy claims
22
+ * the change.
23
+ */
24
+ private readonly fallbackStrategy;
21
25
  private readonly scriptEntrypointChangeHandlers;
22
26
  private readonly registeredScriptReloadRequired;
23
27
  protected readonly entrypointRegistry: DevTransformEntrypointRegistry;
24
28
  protected readonly browserBundleService: BrowserBundleService;
25
29
  protected readonly invalidationService: DevelopmentInvalidationService;
26
- protected readonly entrypointDependencyGraph: InMemoryEntrypointDependencyGraph;
30
+ private readonly buildInputIndex;
31
+ private readonly entrypointDependencyGraph;
27
32
  private readonly hmrRuntime;
28
33
  private readonly devToolbarRuntime;
29
34
  private readonly runtimeBuilds;
@@ -61,8 +66,7 @@ export declare class HmrManager implements IHmrManager {
61
66
  */
62
67
  injectDevClientRuntimes(response: Response): Promise<Response>;
63
68
  broadcast(event: ClientBridgeEvent): void;
64
- handleFileChange(filePath: string, options?: HandleFileChangeOptions): Promise<void>;
65
- handleFileChanges(filePaths: string[], options?: HandleFileChangeOptions): Promise<void>;
69
+ handleFileChanges(filePaths: string[], options?: HmrFileChangeOptions): Promise<void>;
66
70
  private processFileChange;
67
71
  /**
68
72
  * @remarks
@@ -4,7 +4,6 @@ import { HMR_RUNTIME_SCRIPT_URL, resolveHmrRuntimeWorkDir } from '../../../hmr/h
4
4
  import { bundleDevClientRuntime, injectDevClientRuntimes, readDevClientRuntime, } from '../../../hmr/dev-client-runtime.js';
5
5
  import { isDevToolbarEnabled } from '../../../dev-toolbar/dev-toolbar-config.js';
6
6
  import { createDevToolbarClientRuntime } from '../../../dev-toolbar/dev-toolbar-runtime.js';
7
- import { isDevTransformModuleUrl } from '../../../hmr/hmr-asset-paths.js';
8
7
  import { isRegisteredDevTransformEntrypoint } from '../../../hmr/hmr-entrypoint-output.js';
9
8
  import { fileSystem } from '@ecopages/file-system';
10
9
  import { HmrStrategyType } from '../../../hmr/hmr-strategy.js';
@@ -16,22 +15,29 @@ import { appLogger } from '../../../global/app-logger.js';
16
15
  import { DevTransformEntrypointRegistry } from './dev-transform-entrypoint-registry.js';
17
16
  import { BrowserBundleService } from '../../../assets/browser-bundle.service.js';
18
17
  import { requireAppRuntime } from '../../../utils/app-runtime.js';
19
- import { InMemoryEntrypointDependencyGraph } from '../../../hmr/entrypoint-dependency-graph.js';
20
18
  import { resolveInternalExecutionDir, resolveInternalWorkDir } from '../../../utils/resolve-work-dir.js';
21
19
  import { DevTransformServer } from '../../../dev/transform-server/dev-transform-server.js';
22
- import { prepareHmrFileChange } from '../../../hmr/hmr-file-change-prep.js';
23
20
  export class HmrManager {
24
21
  appConfig;
25
22
  bridge;
26
23
  runtimeWorkDir;
27
24
  enabled = false;
28
25
  strategies = [];
26
+ /**
27
+ * @remarks
28
+ * Kept out of `strategies` because it matches every path: it reloads the page when no other strategy claims
29
+ * the change.
30
+ */
31
+ fallbackStrategy = new DefaultHmrStrategy();
29
32
  scriptEntrypointChangeHandlers = [];
30
33
  registeredScriptReloadRequired = new Set();
31
34
  entrypointRegistry;
32
35
  browserBundleService;
33
36
  invalidationService;
34
- entrypointDependencyGraph;
37
+ buildInputIndex;
38
+ entrypointDependencyGraph = {
39
+ getDependencyEntrypoints: (filePath) => new Set(this.buildInputIndex.resolveKeys('entrypoint', filePath)),
40
+ };
35
41
  hmrRuntime;
36
42
  devToolbarRuntime;
37
43
  runtimeBuilds = new Map();
@@ -54,11 +60,15 @@ export class HmrManager {
54
60
  this.invalidationService = getDevelopmentInvalidationService(appConfig);
55
61
  const runtime = requireAppRuntime(appConfig);
56
62
  runtime.hmr = this;
57
- this.entrypointDependencyGraph = new InMemoryEntrypointDependencyGraph(runtime.buildInputIndex);
63
+ this.buildInputIndex = runtime.buildInputIndex;
58
64
  this.devTransformServer = new DevTransformServer({
59
65
  appConfig: this.appConfig,
60
66
  onModuleDependencies: (modulePath, dependencies) => {
61
- this.entrypointDependencyGraph.setEntrypointDependencies(modulePath, dependencies);
67
+ const entrypointPath = path.resolve(modulePath);
68
+ this.buildInputIndex.register({ consumer: 'entrypoint', key: entrypointPath }, [
69
+ entrypointPath,
70
+ ...dependencies,
71
+ ]);
62
72
  },
63
73
  onTransformError: (message) => this.broadcast({ type: 'error', message }),
64
74
  });
@@ -115,13 +125,11 @@ export class HmrManager {
115
125
  getTemplateExtensions: () => this.appConfig.templatesExt,
116
126
  getEntrypointDependencyGraph: () => this.entrypointDependencyGraph,
117
127
  shouldProcessEntrypoint: (entrypointPath) => this.shouldJsStrategyProcessEntrypoint(entrypointPath),
118
- invalidateDevTransformSource: (sourcePath) => this.devTransformServer.invalidateSource(sourcePath),
119
128
  consumeRegisteredScriptReloadRequired: (sourcePath) => this.consumeRegisteredScriptReloadRequired(sourcePath),
120
129
  };
121
130
  this.strategies = [
122
131
  new JsHmrStrategy(jsContext),
123
132
  new ServerRenderedTemplateHmrStrategy(this.invalidationService),
124
- new DefaultHmrStrategy(),
125
133
  ];
126
134
  }
127
135
  registerStrategy(strategy) {
@@ -178,9 +186,6 @@ export class HmrManager {
178
186
  appLogger.debug(`[HMR] Broadcasting ${event.type} event, path=${event.path || 'all'}, subscribers=${this.bridge.subscriberCount}`);
179
187
  this.bridge.broadcast(event);
180
188
  }
181
- async handleFileChange(filePath, options = {}) {
182
- await this.handleFileChanges([filePath], options);
183
- }
184
189
  async handleFileChanges(filePaths, options = {}) {
185
190
  if (filePaths.length === 0) {
186
191
  return;
@@ -189,11 +194,8 @@ export class HmrManager {
189
194
  const events = [];
190
195
  const uniqueFilePaths = [...new Set(filePaths.map((candidate) => path.resolve(candidate)))];
191
196
  for (const filePath of uniqueFilePaths) {
192
- const affectedGraphIdentities = options.graphIdentities ??
193
- (this.isEnabled() ? prepareHmrFileChange(this.appConfig, filePath).affectedGraphIdentities : undefined);
194
- const graphIdentities = affectedGraphIdentities?.length ? affectedGraphIdentities : undefined;
195
197
  try {
196
- events.push(...(await this.processFileChange(filePath, graphIdentities)));
198
+ events.push(...(await this.processFileChange(filePath)));
197
199
  }
198
200
  catch (error) {
199
201
  appLogger.error(error instanceof Error ? error : new Error(String(error)));
@@ -202,7 +204,7 @@ export class HmrManager {
202
204
  }
203
205
  this.broadcastBatchEvents(events, options, uniqueFilePaths);
204
206
  }
205
- async processFileChange(filePath, graphIdentities) {
207
+ async processFileChange(filePath) {
206
208
  const resolvedFilePath = path.resolve(filePath);
207
209
  const isRegisteredDevTransformEdit = isRegisteredDevTransformEntrypoint(this.entrypointRegistry.getRegisteredEntrypoints(), resolvedFilePath);
208
210
  if (!isRegisteredDevTransformEdit) {
@@ -215,18 +217,11 @@ export class HmrManager {
215
217
  }
216
218
  if (isRegisteredDevTransformEdit) {
217
219
  await this.runRegisteredEntrypointChangeHandlers(resolvedFilePath);
218
- const registered = this.entrypointRegistry.getRegisteredEntrypoints().get(resolvedFilePath);
219
- if (registered && isDevTransformModuleUrl(registered.outputUrl)) {
220
- this.devTransformServer.invalidateSource(resolvedFilePath);
221
- }
220
+ this.devTransformServer.invalidateSource(resolvedFilePath);
222
221
  }
223
222
  const strategy = this.selectChangeStrategy(filePath);
224
- if (!strategy) {
225
- appLogger.warn(`[HMR] No strategy found for ${filePath}`);
226
- return buildStrategyEvents({ type: 'none' }, !isRegisteredDevTransformEdit, graphIdentities);
227
- }
228
223
  appLogger.debug(`[${this.constructor.name}] Selected strategy: ${strategy.constructor.name}`);
229
- return buildStrategyEvents(await strategy.process(filePath), !isRegisteredDevTransformEdit, graphIdentities);
224
+ return buildStrategyEvents(await strategy.process(filePath), !isRegisteredDevTransformEdit);
230
225
  }
231
226
  /**
232
227
  * @remarks
@@ -250,13 +245,8 @@ export class HmrManager {
250
245
  }
251
246
  }
252
247
  invalidateDevTransformDependents(changedFilePath) {
253
- const affectedEntrypoints = this.entrypointDependencyGraph.getDependencyEntrypoints(changedFilePath);
254
- if (affectedEntrypoints.size > 0) {
255
- for (const entrypointPath of affectedEntrypoints) {
256
- this.devTransformServer.invalidateSource(entrypointPath);
257
- }
258
- this.devTransformServer.invalidateSource(changedFilePath);
259
- return;
248
+ for (const entrypointPath of this.entrypointDependencyGraph.getDependencyEntrypoints(changedFilePath)) {
249
+ this.devTransformServer.invalidateSource(entrypointPath);
260
250
  }
261
251
  this.devTransformServer.invalidateSource(changedFilePath);
262
252
  }
@@ -270,7 +260,7 @@ export class HmrManager {
270
260
  return [...this.strategies].sort((left, right) => right.priority - left.priority);
271
261
  }
272
262
  selectChangeStrategy(filePath) {
273
- return this.getStrategiesByPriority().find((candidate) => {
263
+ const strategy = this.getStrategiesByPriority().find((candidate) => {
274
264
  try {
275
265
  return candidate.matches(filePath);
276
266
  }
@@ -279,6 +269,7 @@ export class HmrManager {
279
269
  return false;
280
270
  }
281
271
  });
272
+ return strategy ?? this.fallbackStrategy;
282
273
  }
283
274
  /**
284
275
  * @remarks
@@ -366,14 +357,14 @@ export class HmrManager {
366
357
  this.registeredScriptReloadRequired.clear();
367
358
  this.entrypointRegistry.clearAll();
368
359
  this.devTransformServer.reset();
369
- this.entrypointDependencyGraph.reset();
360
+ this.buildInputIndex.clearConsumer('entrypoint');
370
361
  if (this.appConfig.appRuntime?.hmr === this) {
371
362
  this.appConfig.appRuntime.hmr = null;
372
363
  }
373
364
  }
374
365
  clearFailedEntrypointRegistration(entrypointPath) {
375
366
  this.entrypointRegistry.clearRegistration(entrypointPath);
376
- this.entrypointDependencyGraph.clearEntrypointDependencies(entrypointPath);
367
+ this.buildInputIndex.unregister({ consumer: 'entrypoint', key: path.resolve(entrypointPath) });
377
368
  }
378
369
  async registerEntrypoint(entrypointPath) {
379
370
  return this.registerDevTransformEntrypoint(entrypointPath, 'page').outputUrl;
@@ -400,38 +391,41 @@ export class HmrManager {
400
391
  this.stop();
401
392
  }
402
393
  }
403
- function buildStrategyEvents(action, fallbackReload, graphIdentities) {
404
- const events = action.type === 'broadcast' && action.events ? action.events : fallbackReload ? [{ type: 'reload' }] : [];
405
- return events.map((event) => event.graphIdentities === undefined && graphIdentities !== undefined ? { ...event, graphIdentities } : event);
394
+ function buildStrategyEvents(action, fallbackReload) {
395
+ if (action.type === 'broadcast' && action.events) {
396
+ return action.events;
397
+ }
398
+ return fallbackReload ? [{ type: 'reload' }] : [];
406
399
  }
407
400
  /**
408
401
  * @remarks
409
402
  * A `reload` makes every other update redundant. Otherwise each distinct update is kept, so edits that touch several
410
403
  * islands hot-update each of them, and several layout updates collapse into one soft refresh.
404
+ *
405
+ * Errors are placed after the updates. The client clears a shown build error whenever a non-error message arrives,
406
+ * so an error that precedes an update in the same batch would be wiped out by it.
411
407
  */
412
408
  function coalesceBatchEvents(events) {
413
409
  const errors = deduplicateEvents(events.filter((event) => event.type === 'error'));
414
410
  const updates = deduplicateEvents(events.filter((event) => event.type !== 'error'));
415
411
  if (updates.length <= 1) {
416
- return [...errors, ...updates];
412
+ return [...updates, ...errors];
417
413
  }
418
- const graphIdentities = mergeGraphIdentities(updates);
419
414
  if (updates.some((event) => event.type === 'reload')) {
420
- return [...errors, { type: 'reload', ...(graphIdentities ? { graphIdentities } : {}) }];
415
+ return [{ type: 'reload' }, ...errors];
421
416
  }
422
417
  const layoutUpdates = updates.filter((event) => event.type === 'layout-update');
423
418
  const others = updates.filter((event) => event.type !== 'layout-update');
424
419
  if (layoutUpdates.length <= 1) {
425
- return [...errors, ...others, ...layoutUpdates];
420
+ return [...others, ...layoutUpdates, ...errors];
426
421
  }
427
422
  return [
428
- ...errors,
429
423
  ...others,
430
424
  {
431
425
  type: 'layout-update',
432
426
  timestamp: Math.max(...layoutUpdates.map((event) => event.timestamp ?? 0)),
433
- ...(graphIdentities ? { graphIdentities } : {}),
434
427
  },
428
+ ...errors,
435
429
  ];
436
430
  }
437
431
  function deduplicateEvents(events) {
@@ -440,13 +434,11 @@ function deduplicateEvents(events) {
440
434
  const key = JSON.stringify([event.type, event.path, event.message]);
441
435
  const existing = uniqueEvents.get(key);
442
436
  if (existing) {
443
- const graphIdentities = mergeGraphIdentities([existing, event]);
444
437
  uniqueEvents.set(key, {
445
438
  ...existing,
446
439
  ...(existing.timestamp !== undefined || event.timestamp !== undefined
447
440
  ? { timestamp: Math.max(existing.timestamp ?? 0, event.timestamp ?? 0) }
448
441
  : {}),
449
- ...(graphIdentities ? { graphIdentities } : {}),
450
442
  });
451
443
  continue;
452
444
  }
@@ -454,11 +446,3 @@ function deduplicateEvents(events) {
454
446
  }
455
447
  return [...uniqueEvents.values()];
456
448
  }
457
- function mergeGraphIdentities(events) {
458
- const identities = events.flatMap((event) => event.graphIdentities ?? []);
459
- if (identities.length === 0) {
460
- return undefined;
461
- }
462
- const unique = new Map(identities.map((identity) => [JSON.stringify(identity), identity]));
463
- return [...unique.values()];
464
- }
@@ -3,20 +3,10 @@ import type { ApiHandler, ApiHandlerContext, CacheInvalidator, ErrorHandler, Pag
3
3
  export type ApiRequestPipelineOptions = {
4
4
  getRenderContext: () => RenderContext;
5
5
  getCacheService: () => CacheInvalidator | null;
6
- /**
7
- * Recognises a client that disconnected mid-request.
8
- *
9
- * @remarks
10
- * Such errors are a normal browser behaviour, not a server fault, so
11
- * {@link ApiRequestPipeline.handleError} answers them with 499 without logging or
12
- * calling `app.onError`. Only the Node adapter supplies it.
13
- */
14
- isClientAbort?: (error: unknown) => boolean;
15
6
  };
16
7
  export declare class ApiRequestPipeline<TRequest extends Request = Request, TServer = unknown> {
17
8
  private readonly getRenderContext;
18
9
  private readonly getCacheService;
19
- private readonly isClientAbort;
20
10
  constructor(options: ApiRequestPipelineOptions);
21
11
  match(request: TRequest, apiHandlers: ApiHandler<string, TRequest, TServer>[], parsedPathSegments?: ParsedSegmentPath): {
22
12
  routeConfig: ApiHandler<string, TRequest, TServer>;
@@ -30,8 +20,9 @@ export declare class ApiRequestPipeline<TRequest extends Request = Request, TSer
30
20
  * @remarks
31
21
  * Precedence is a thrown `Response`, then a client abort (499), then the app
32
22
  * `onError` handler, then `HttpError.toResponse()`, then a logged plain 500.
33
- * Runtime adapters reuse this for errors that escape the whole request
34
- * pipeline so `app.onError` behaves the same on Bun and Node.
23
+ * A client abort is a browser leaving mid-request, not a server fault, so it
24
+ * is neither logged nor passed to `onError`. Runtime adapters reuse this for errors that escape the whole request
25
+ * pipeline so `app.onError` also covers them.
35
26
  */
36
27
  handleError(error: unknown, options: {
37
28
  request: TRequest;
@@ -4,16 +4,15 @@ import { ApiResponseBuilder } from './api-response.js';
4
4
  import { runMiddlewareChain } from './run-middleware-chain.js';
5
5
  import { matchParsedSegmentPath, parseSegmentPath, scoreSegmentPathPattern, } from '../../../router/server/segment-path-matcher.js';
6
6
  import { appLogger } from '../../../global/app-logger.js';
7
+ import { isNodeClientAbortError } from '../../node/http-request-bridge.js';
7
8
  import { validateRequest } from '../../../validation/validate-request.js';
8
9
  import { parseSearchParams } from '../../../router/server/parse-search-params.js';
9
10
  export class ApiRequestPipeline {
10
11
  getRenderContext;
11
12
  getCacheService;
12
- isClientAbort;
13
13
  constructor(options) {
14
14
  this.getRenderContext = options.getRenderContext;
15
15
  this.getCacheService = options.getCacheService;
16
- this.isClientAbort = options.isClientAbort ?? (() => false);
17
16
  }
18
17
  match(request, apiHandlers, parsedPathSegments) {
19
18
  const pathname = new URL(request.url).pathname;
@@ -67,13 +66,14 @@ export class ApiRequestPipeline {
67
66
  * @remarks
68
67
  * Precedence is a thrown `Response`, then a client abort (499), then the app
69
68
  * `onError` handler, then `HttpError.toResponse()`, then a logged plain 500.
70
- * Runtime adapters reuse this for errors that escape the whole request
71
- * pipeline so `app.onError` behaves the same on Bun and Node.
69
+ * A client abort is a browser leaving mid-request, not a server fault, so it
70
+ * is neither logged nor passed to `onError`. Runtime adapters reuse this for errors that escape the whole request
71
+ * pipeline so `app.onError` also covers them.
72
72
  */
73
73
  async handleError(error, options) {
74
74
  if (error instanceof Response)
75
75
  return error;
76
- if (this.isClientAbort(error))
76
+ if (isNodeClientAbortError(error))
77
77
  return new Response(null, { status: 499 });
78
78
  if (options.errorHandler) {
79
79
  try {
@@ -155,7 +155,7 @@ export class ApiRequestPipeline {
155
155
  return { value };
156
156
  }
157
157
  catch (error) {
158
- if (this.isClientAbort(error))
158
+ if (isNodeClientAbortError(error))
159
159
  throw error;
160
160
  return { response: responseBuilder.status(400).json({ error: 'Invalid request body' }) };
161
161
  }
@@ -168,7 +168,7 @@ export class ApiRequestPipeline {
168
168
  : { value: undefined };
169
169
  }
170
170
  catch (error) {
171
- if (this.isClientAbort(error))
171
+ if (isNodeClientAbortError(error))
172
172
  throw error;
173
173
  return { response: responseBuilder.status(400).json({ error: 'Invalid request body' }) };
174
174
  }