@ecopages/core 0.3.0 → 0.3.2
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.
- package/README.md +2 -2
- package/package.json +3 -3
- package/src/adapters/node/create-app.d.ts +40 -11
- package/src/adapters/node/create-app.js +95 -69
- package/src/adapters/node/dev-session.js +0 -1
- package/src/adapters/node/http-request-bridge.d.ts +4 -0
- package/src/adapters/node/http-request-bridge.js +9 -1
- package/src/adapters/node/runtime-host.d.ts +28 -6
- package/src/adapters/node/runtime-host.js +35 -9
- package/src/adapters/node/server-adapter.d.ts +10 -35
- package/src/adapters/node/server-adapter.js +21 -58
- package/src/adapters/shared/hmr/hmr-manager.d.ts +21 -7
- package/src/adapters/shared/hmr/hmr-manager.js +58 -70
- package/src/adapters/shared/http/api-request-pipeline.d.ts +3 -12
- package/src/adapters/shared/http/api-request-pipeline.js +7 -7
- package/src/adapters/shared/http/dist-file-handler.d.ts +16 -0
- package/src/adapters/shared/http/dist-file-handler.js +172 -0
- package/src/adapters/shared/http/explicit-static-route-matcher.js +2 -1
- package/src/adapters/shared/http/fs-server-response-matcher.js +3 -2
- package/src/adapters/shared/runtime/bind-runtime-server.d.ts +5 -7
- package/src/adapters/shared/runtime/bind-runtime-server.js +8 -12
- package/src/adapters/shared/runtime/copy-runtime-public-dir.js +10 -9
- package/src/adapters/shared/runtime/port-manager.d.ts +8 -11
- package/src/adapters/shared/runtime/port-manager.js +19 -30
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +6 -9
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +2 -5
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +1 -3
- package/src/adapters/shared/runtime/server-request-pipeline.js +1 -5
- package/src/adapters/shared/runtime/server-static-builder.d.ts +3 -3
- package/src/adapters/shared/runtime/server-static-builder.js +3 -3
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +2 -1
- package/src/adapters/shared/ws/websocket-lifecycle.d.ts +5 -6
- package/src/adapters/shared/ws/websocket-lifecycle.js +1 -2
- package/src/assets/app-browser-client-build.js +1 -2
- package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +8 -8
- package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +4 -4
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +12 -8
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +36 -16
- package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +11 -6
- package/src/assets/browser-asset-output.d.ts +19 -0
- package/src/assets/browser-asset-output.js +30 -0
- package/src/assets/hashed-browser-asset.d.ts +8 -6
- package/src/assets/hashed-browser-asset.js +8 -6
- package/src/build/build-adapter.d.ts +2 -19
- package/src/build/build-adapter.js +0 -21
- package/src/build/build-graph.js +2 -2
- package/src/build/cache/cache-keys.d.ts +0 -3
- package/src/build/cache/cache-keys.js +0 -14
- package/src/build/cache/pages-unified-graph-build.js +2 -17
- package/src/build/contracts/build-contracts.d.ts +0 -3
- package/src/build/preserve-import-meta-transform.js +2 -2
- package/src/build/rolldown/app-package-declarations.js +3 -3
- package/src/build/rolldown/rolldown-adapter-helpers.js +3 -3
- package/src/build/rolldown/rolldown-build-adapter.d.ts +0 -1
- package/src/build/rolldown/rolldown-build-adapter.js +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.d.ts +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.js +5 -12
- package/src/build/rolldown/server-side-css-shim-plugin.js +3 -3
- package/src/build/runtime/build-queue.d.ts +8 -13
- package/src/build/runtime/build-queue.js +6 -17
- package/src/build/server/app-module-loader.service.d.ts +1 -1
- package/src/build/server/app-module-loader.service.js +0 -2
- package/src/build/server/page-module-import.service.d.ts +2 -3
- package/src/build/server/page-module-import.service.js +3 -4
- package/src/build/server-bundle-deploy-manifest.d.ts +5 -0
- package/src/build/server-bundle-deploy-manifest.js +15 -1
- package/src/build/server-bundle-publication.js +4 -5
- package/src/build.d.ts +2 -2
- package/src/build.js +2 -2
- package/src/config/assembly/app-runtime.d.ts +2 -2
- package/src/config/assembly/app-runtime.js +2 -2
- package/src/config/assembly/finalize-config.d.ts +4 -4
- package/src/config/assembly/finalize-config.js +4 -5
- package/src/config/config-module-files.js +2 -3
- package/src/config/internal-types.d.ts +0 -7
- package/src/config/user-config-types.d.ts +0 -4
- package/src/diagnostics/request-pipeline-metrics.d.ts +3 -3
- package/src/diagnostics/request-pipeline-metrics.js +4 -4
- package/src/diagnostics/startup-trace.js +2 -5
- package/src/errors/http-error.d.ts +2 -2
- package/src/errors/http-error.js +4 -4
- package/src/hmr/client/hmr-runtime.js +16 -7
- package/src/hmr/client/module-update.d.ts +7 -0
- package/src/hmr/client/module-update.js +21 -4
- package/src/hmr/hmr-strategy.d.ts +0 -3
- package/src/hmr/hmr-strategy.js +0 -3
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -3
- package/src/hmr/strategies/js-hmr-strategy.js +3 -6
- package/src/html-pages/html-page-module-scripts.js +4 -3
- package/src/html-pages/html-page-renderer.js +2 -3
- package/src/plugins/alias-resolver-cache.d.ts +4 -3
- package/src/plugins/alias-resolver-cache.js +4 -3
- package/src/plugins/component-import-discovery.js +4 -4
- package/src/plugins/eco-component-meta-plugin.d.ts +10 -1
- package/src/plugins/eco-component-meta-plugin.js +66 -10
- package/src/plugins/foreign-jsx-override-plugin.js +4 -3
- package/src/plugins/tsconfig-import-resolver.js +12 -12
- package/src/route-renderer/error-pages/default-error-pages.js +2 -1
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -1
- package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +0 -1
- package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -5
- package/src/route-renderer/orchestration/integration-renderer.js +13 -14
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -23
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -29
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +2 -2
- package/src/route-renderer/page-loading/page-dependency-bundling.js +5 -5
- package/src/route-renderer/page-loading/page-module-loader.js +1 -1
- package/src/route-renderer/route-renderer.d.ts +2 -5
- package/src/route-renderer/route-renderer.js +2 -4
- package/src/router/client/link-navigation-policy.d.ts +4 -1
- package/src/router/client/link-navigation-policy.js +20 -6
- package/src/router/server/route-registry.d.ts +0 -1
- package/src/router/server/route-registry.js +3 -13
- package/src/router/server/segment-path-matcher.d.ts +12 -0
- package/src/router/server/segment-path-matcher.js +30 -0
- package/src/static-site-generator/static-site-generator.d.ts +0 -5
- package/src/static-site-generator/static-site-generator.js +2 -15
- package/src/types/contracts.d.ts +17 -27
- package/src/types/public-types.d.ts +1 -1
- package/src/utils/format-error-chain.d.ts +9 -0
- package/src/utils/format-error-chain.js +20 -0
- package/src/utils/invariant.d.ts +6 -1
- package/src/utils/invariant.js +7 -2
- package/src/watchers/project-watcher.d.ts +20 -1
- package/src/watchers/project-watcher.js +40 -9
- package/src/watchers/workspace-package-watch-roots.js +5 -5
- package/src/adapters/README.md +0 -58
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.d.ts +0 -28
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.js +0 -53
- package/src/adapters/shared/runtime/runtime-host.d.ts +0 -15
- package/src/adapters/shared/runtime/runtime-host.js +0 -1
- package/src/assets/README.md +0 -35
- package/src/build/README.md +0 -298
- package/src/build/server/README.md +0 -50
- package/src/cache/README.md +0 -5
- package/src/client/README.md +0 -5
- package/src/client/navigation-scripts/navigation-scripts.test.browser.d.ts +0 -1
- package/src/client/navigation-scripts/navigation-scripts.test.browser.js +0 -111
- package/src/client/scroll.test.browser.d.ts +0 -1
- package/src/client/scroll.test.browser.js +0 -31
- package/src/client/view-transitions.test.browser.d.ts +0 -1
- package/src/client/view-transitions.test.browser.js +0 -53
- package/src/config/README.md +0 -58
- package/src/config/constants.d.ts +0 -1
- package/src/config/constants.js +0 -1
- package/src/dev/README.md +0 -61
- package/src/dev/invalidation/README.md +0 -11
- package/src/dev-toolbar/README.md +0 -66
- package/src/diagnostics/README.md +0 -11
- package/src/eco/README.md +0 -776
- package/src/errors/README.md +0 -5
- package/src/global/README.md +0 -5
- package/src/hmr/README.md +0 -64
- package/src/hmr/client/build-error-overlay.test.browser.d.ts +0 -1
- package/src/hmr/client/build-error-overlay.test.browser.js +0 -48
- package/src/hmr/client/hmr-runtime.test.browser.d.ts +0 -1
- package/src/hmr/client/hmr-runtime.test.browser.js +0 -32
- package/src/hmr/entrypoint-dependency-graph.d.ts +0 -12
- package/src/hmr/entrypoint-dependency-graph.js +0 -27
- package/src/hmr/hmr-file-change-prep.d.ts +0 -9
- package/src/hmr/hmr-file-change-prep.js +0 -11
- package/src/html/README.md +0 -15
- package/src/html-pages/README.md +0 -104
- package/src/islands/README.md +0 -44
- package/src/page-cache/README.md +0 -17
- package/src/plugins/README.md +0 -53
- package/src/route-renderer/GRAPH.md +0 -142
- package/src/route-renderer/README.md +0 -160
- package/src/route-renderer/error-pages/README.md +0 -11
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +0 -15
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.d.ts +0 -39
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +0 -94
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.d.ts +0 -35
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.js +0 -69
- package/src/router/README.md +0 -160
- package/src/router/client/link-intent.test.browser.d.ts +0 -1
- package/src/router/client/link-intent.test.browser.js +0 -33
- package/src/router/client/link-navigation-policy.test.browser.d.ts +0 -1
- package/src/router/client/link-navigation-policy.test.browser.js +0 -142
- package/src/router/client/navigation-commit.test.browser.d.ts +0 -1
- package/src/router/client/navigation-commit.test.browser.js +0 -116
- package/src/router/client/navigation-document.test.browser.d.ts +0 -1
- package/src/router/client/navigation-document.test.browser.js +0 -77
- package/src/router/client/navigation-head.test.browser.d.ts +0 -1
- package/src/router/client/navigation-head.test.browser.js +0 -101
- package/src/router/client/navigation-lifecycle.test.browser.d.ts +0 -1
- package/src/router/client/navigation-lifecycle.test.browser.js +0 -97
- package/src/router/client/navigation-view-transition.test.browser.d.ts +0 -1
- package/src/router/client/navigation-view-transition.test.browser.js +0 -189
- package/src/router/client/staged-stylesheets.test-fixtures.d.ts +0 -18
- package/src/router/client/staged-stylesheets.test-fixtures.js +0 -31
- package/src/static-site-generator/README.md +0 -67
- package/src/static-site-generator/static-site-generator.test-utils.d.ts +0 -2
- package/src/static-site-generator/static-site-generator.test-utils.js +0 -41
- package/src/types/README.md +0 -5
- package/src/utils/README.md +0 -7
- package/src/validation/README.md +0 -9
- package/src/watchers/README.md +0 -15
- package/src/watchers/project-watcher.test-helpers.d.ts +0 -60
- 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 {
|
|
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 `
|
|
50
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
|
159
|
-
*
|
|
160
|
-
*
|
|
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 `
|
|
31
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
|
325
|
-
*
|
|
326
|
-
*
|
|
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.
|
|
355
|
+
configureResponseHandlers: () => this.requestPipeline.configureResponseHandlers({
|
|
386
356
|
staticRoutes: this.staticRoutes,
|
|
387
357
|
errorPageLoaders: this.errorPageLoaders,
|
|
388
358
|
}),
|
|
389
|
-
createWatchRefreshCallback: () => this.
|
|
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,27 @@ 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;
|
|
27
|
+
/**
|
|
28
|
+
* Error messages of changed files whose strategy or script-change handler threw, by file path.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* An entry stays until that file processes without error, because nothing records it again on a later
|
|
32
|
+
* request the way a dev-transform failure is.
|
|
33
|
+
*/
|
|
34
|
+
private readonly fileChangeErrors;
|
|
23
35
|
protected readonly entrypointRegistry: DevTransformEntrypointRegistry;
|
|
24
36
|
protected readonly browserBundleService: BrowserBundleService;
|
|
25
37
|
protected readonly invalidationService: DevelopmentInvalidationService;
|
|
26
|
-
|
|
38
|
+
private readonly buildInputIndex;
|
|
39
|
+
private readonly entrypointDependencyGraph;
|
|
27
40
|
private readonly hmrRuntime;
|
|
28
41
|
private readonly devToolbarRuntime;
|
|
29
42
|
private readonly runtimeBuilds;
|
|
@@ -61,8 +74,7 @@ export declare class HmrManager implements IHmrManager {
|
|
|
61
74
|
*/
|
|
62
75
|
injectDevClientRuntimes(response: Response): Promise<Response>;
|
|
63
76
|
broadcast(event: ClientBridgeEvent): void;
|
|
64
|
-
|
|
65
|
-
handleFileChanges(filePaths: string[], options?: HandleFileChangeOptions): Promise<void>;
|
|
77
|
+
handleFileChanges(filePaths: string[], options?: HmrFileChangeOptions): Promise<void>;
|
|
66
78
|
private processFileChange;
|
|
67
79
|
/**
|
|
68
80
|
* @remarks
|
|
@@ -94,11 +106,13 @@ export declare class HmrManager implements IHmrManager {
|
|
|
94
106
|
getWatchedFiles(): Map<string, string>;
|
|
95
107
|
getRegisteredEntrypoints(): ReadonlyMap<string, ResolvedHmrEntrypoint>;
|
|
96
108
|
/**
|
|
97
|
-
* Sends a browser that just connected the build errors of modules that still fail to transpile
|
|
109
|
+
* Sends a browser that just connected the build errors of modules that still fail to transpile, and of
|
|
110
|
+
* changed files whose last processing failed.
|
|
98
111
|
*
|
|
99
112
|
* @remarks
|
|
100
113
|
* A build error is broadcast while the failing module is served, which can happen before the page's HMR
|
|
101
|
-
* socket connects.
|
|
114
|
+
* socket connects. A change error can share its batch with a `reload`, which drops the error shown before
|
|
115
|
+
* it. Without this replay that browser would never show the error.
|
|
102
116
|
*/
|
|
103
117
|
sendPendingBuildErrors(client: {
|
|
104
118
|
send(payload: string): void;
|
|
@@ -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,37 @@ 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();
|
|
34
|
+
/**
|
|
35
|
+
* Error messages of changed files whose strategy or script-change handler threw, by file path.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* An entry stays until that file processes without error, because nothing records it again on a later
|
|
39
|
+
* request the way a dev-transform failure is.
|
|
40
|
+
*/
|
|
41
|
+
fileChangeErrors = new Map();
|
|
31
42
|
entrypointRegistry;
|
|
32
43
|
browserBundleService;
|
|
33
44
|
invalidationService;
|
|
34
|
-
|
|
45
|
+
buildInputIndex;
|
|
46
|
+
entrypointDependencyGraph = {
|
|
47
|
+
getDependencyEntrypoints: (filePath) => new Set(this.buildInputIndex.resolveKeys('entrypoint', filePath)),
|
|
48
|
+
};
|
|
35
49
|
hmrRuntime;
|
|
36
50
|
devToolbarRuntime;
|
|
37
51
|
runtimeBuilds = new Map();
|
|
@@ -54,11 +68,15 @@ export class HmrManager {
|
|
|
54
68
|
this.invalidationService = getDevelopmentInvalidationService(appConfig);
|
|
55
69
|
const runtime = requireAppRuntime(appConfig);
|
|
56
70
|
runtime.hmr = this;
|
|
57
|
-
this.
|
|
71
|
+
this.buildInputIndex = runtime.buildInputIndex;
|
|
58
72
|
this.devTransformServer = new DevTransformServer({
|
|
59
73
|
appConfig: this.appConfig,
|
|
60
74
|
onModuleDependencies: (modulePath, dependencies) => {
|
|
61
|
-
|
|
75
|
+
const entrypointPath = path.resolve(modulePath);
|
|
76
|
+
this.buildInputIndex.register({ consumer: 'entrypoint', key: entrypointPath }, [
|
|
77
|
+
entrypointPath,
|
|
78
|
+
...dependencies,
|
|
79
|
+
]);
|
|
62
80
|
},
|
|
63
81
|
onTransformError: (message) => this.broadcast({ type: 'error', message }),
|
|
64
82
|
});
|
|
@@ -115,13 +133,11 @@ export class HmrManager {
|
|
|
115
133
|
getTemplateExtensions: () => this.appConfig.templatesExt,
|
|
116
134
|
getEntrypointDependencyGraph: () => this.entrypointDependencyGraph,
|
|
117
135
|
shouldProcessEntrypoint: (entrypointPath) => this.shouldJsStrategyProcessEntrypoint(entrypointPath),
|
|
118
|
-
invalidateDevTransformSource: (sourcePath) => this.devTransformServer.invalidateSource(sourcePath),
|
|
119
136
|
consumeRegisteredScriptReloadRequired: (sourcePath) => this.consumeRegisteredScriptReloadRequired(sourcePath),
|
|
120
137
|
};
|
|
121
138
|
this.strategies = [
|
|
122
139
|
new JsHmrStrategy(jsContext),
|
|
123
140
|
new ServerRenderedTemplateHmrStrategy(this.invalidationService),
|
|
124
|
-
new DefaultHmrStrategy(),
|
|
125
141
|
];
|
|
126
142
|
}
|
|
127
143
|
registerStrategy(strategy) {
|
|
@@ -178,9 +194,6 @@ export class HmrManager {
|
|
|
178
194
|
appLogger.debug(`[HMR] Broadcasting ${event.type} event, path=${event.path || 'all'}, subscribers=${this.bridge.subscriberCount}`);
|
|
179
195
|
this.bridge.broadcast(event);
|
|
180
196
|
}
|
|
181
|
-
async handleFileChange(filePath, options = {}) {
|
|
182
|
-
await this.handleFileChanges([filePath], options);
|
|
183
|
-
}
|
|
184
197
|
async handleFileChanges(filePaths, options = {}) {
|
|
185
198
|
if (filePaths.length === 0) {
|
|
186
199
|
return;
|
|
@@ -189,20 +202,20 @@ export class HmrManager {
|
|
|
189
202
|
const events = [];
|
|
190
203
|
const uniqueFilePaths = [...new Set(filePaths.map((candidate) => path.resolve(candidate)))];
|
|
191
204
|
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
205
|
try {
|
|
196
|
-
events.push(...(await this.processFileChange(filePath
|
|
206
|
+
events.push(...(await this.processFileChange(filePath)));
|
|
207
|
+
this.fileChangeErrors.delete(filePath);
|
|
197
208
|
}
|
|
198
209
|
catch (error) {
|
|
199
210
|
appLogger.error(error instanceof Error ? error : new Error(String(error)));
|
|
200
|
-
|
|
211
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
212
|
+
this.fileChangeErrors.set(filePath, message);
|
|
213
|
+
events.push({ type: 'error', message });
|
|
201
214
|
}
|
|
202
215
|
}
|
|
203
216
|
this.broadcastBatchEvents(events, options, uniqueFilePaths);
|
|
204
217
|
}
|
|
205
|
-
async processFileChange(filePath
|
|
218
|
+
async processFileChange(filePath) {
|
|
206
219
|
const resolvedFilePath = path.resolve(filePath);
|
|
207
220
|
const isRegisteredDevTransformEdit = isRegisteredDevTransformEntrypoint(this.entrypointRegistry.getRegisteredEntrypoints(), resolvedFilePath);
|
|
208
221
|
if (!isRegisteredDevTransformEdit) {
|
|
@@ -215,18 +228,11 @@ export class HmrManager {
|
|
|
215
228
|
}
|
|
216
229
|
if (isRegisteredDevTransformEdit) {
|
|
217
230
|
await this.runRegisteredEntrypointChangeHandlers(resolvedFilePath);
|
|
218
|
-
|
|
219
|
-
if (registered && isDevTransformModuleUrl(registered.outputUrl)) {
|
|
220
|
-
this.devTransformServer.invalidateSource(resolvedFilePath);
|
|
221
|
-
}
|
|
231
|
+
this.devTransformServer.invalidateSource(resolvedFilePath);
|
|
222
232
|
}
|
|
223
233
|
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
234
|
appLogger.debug(`[${this.constructor.name}] Selected strategy: ${strategy.constructor.name}`);
|
|
229
|
-
return buildStrategyEvents(await strategy.process(filePath), !isRegisteredDevTransformEdit
|
|
235
|
+
return buildStrategyEvents(await strategy.process(filePath), !isRegisteredDevTransformEdit);
|
|
230
236
|
}
|
|
231
237
|
/**
|
|
232
238
|
* @remarks
|
|
@@ -250,13 +256,8 @@ export class HmrManager {
|
|
|
250
256
|
}
|
|
251
257
|
}
|
|
252
258
|
invalidateDevTransformDependents(changedFilePath) {
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
for (const entrypointPath of affectedEntrypoints) {
|
|
256
|
-
this.devTransformServer.invalidateSource(entrypointPath);
|
|
257
|
-
}
|
|
258
|
-
this.devTransformServer.invalidateSource(changedFilePath);
|
|
259
|
-
return;
|
|
259
|
+
for (const entrypointPath of this.entrypointDependencyGraph.getDependencyEntrypoints(changedFilePath)) {
|
|
260
|
+
this.devTransformServer.invalidateSource(entrypointPath);
|
|
260
261
|
}
|
|
261
262
|
this.devTransformServer.invalidateSource(changedFilePath);
|
|
262
263
|
}
|
|
@@ -270,7 +271,7 @@ export class HmrManager {
|
|
|
270
271
|
return [...this.strategies].sort((left, right) => right.priority - left.priority);
|
|
271
272
|
}
|
|
272
273
|
selectChangeStrategy(filePath) {
|
|
273
|
-
|
|
274
|
+
const strategy = this.getStrategiesByPriority().find((candidate) => {
|
|
274
275
|
try {
|
|
275
276
|
return candidate.matches(filePath);
|
|
276
277
|
}
|
|
@@ -279,6 +280,7 @@ export class HmrManager {
|
|
|
279
280
|
return false;
|
|
280
281
|
}
|
|
281
282
|
});
|
|
283
|
+
return strategy ?? this.fallbackStrategy;
|
|
282
284
|
}
|
|
283
285
|
/**
|
|
284
286
|
* @remarks
|
|
@@ -288,18 +290,8 @@ export class HmrManager {
|
|
|
288
290
|
*/
|
|
289
291
|
async runRegisteredEntrypointChangeHandlers(filePath) {
|
|
290
292
|
for (const handler of this.scriptEntrypointChangeHandlers) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (result === true) {
|
|
294
|
-
this.registeredScriptReloadRequired.add(path.resolve(filePath));
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
catch (error) {
|
|
298
|
-
const message = error instanceof Error
|
|
299
|
-
? error.message
|
|
300
|
-
: `Failed to handle registered script entrypoint change for ${filePath}: ${String(error)}`;
|
|
301
|
-
this.broadcast({ type: 'error', message });
|
|
302
|
-
throw error;
|
|
293
|
+
if ((await handler(filePath)) === true) {
|
|
294
|
+
this.registeredScriptReloadRequired.add(path.resolve(filePath));
|
|
303
295
|
}
|
|
304
296
|
}
|
|
305
297
|
}
|
|
@@ -325,14 +317,16 @@ export class HmrManager {
|
|
|
325
317
|
return this.entrypointRegistry.getRegisteredEntrypoints();
|
|
326
318
|
}
|
|
327
319
|
/**
|
|
328
|
-
* Sends a browser that just connected the build errors of modules that still fail to transpile
|
|
320
|
+
* Sends a browser that just connected the build errors of modules that still fail to transpile, and of
|
|
321
|
+
* changed files whose last processing failed.
|
|
329
322
|
*
|
|
330
323
|
* @remarks
|
|
331
324
|
* A build error is broadcast while the failing module is served, which can happen before the page's HMR
|
|
332
|
-
* socket connects.
|
|
325
|
+
* socket connects. A change error can share its batch with a `reload`, which drops the error shown before
|
|
326
|
+
* it. Without this replay that browser would never show the error.
|
|
333
327
|
*/
|
|
334
328
|
sendPendingBuildErrors(client) {
|
|
335
|
-
for (const message of this.devTransformServer.getFailureMessages()) {
|
|
329
|
+
for (const message of [...this.devTransformServer.getFailureMessages(), ...this.fileChangeErrors.values()]) {
|
|
336
330
|
client.send(JSON.stringify({ type: 'error', message }));
|
|
337
331
|
}
|
|
338
332
|
}
|
|
@@ -364,16 +358,17 @@ export class HmrManager {
|
|
|
364
358
|
this.readyRuntimes.clear();
|
|
365
359
|
this.scriptEntrypointChangeHandlers.length = 0;
|
|
366
360
|
this.registeredScriptReloadRequired.clear();
|
|
361
|
+
this.fileChangeErrors.clear();
|
|
367
362
|
this.entrypointRegistry.clearAll();
|
|
368
363
|
this.devTransformServer.reset();
|
|
369
|
-
this.
|
|
364
|
+
this.buildInputIndex.clearConsumer('entrypoint');
|
|
370
365
|
if (this.appConfig.appRuntime?.hmr === this) {
|
|
371
366
|
this.appConfig.appRuntime.hmr = null;
|
|
372
367
|
}
|
|
373
368
|
}
|
|
374
369
|
clearFailedEntrypointRegistration(entrypointPath) {
|
|
375
370
|
this.entrypointRegistry.clearRegistration(entrypointPath);
|
|
376
|
-
this.
|
|
371
|
+
this.buildInputIndex.unregister({ consumer: 'entrypoint', key: path.resolve(entrypointPath) });
|
|
377
372
|
}
|
|
378
373
|
async registerEntrypoint(entrypointPath) {
|
|
379
374
|
return this.registerDevTransformEntrypoint(entrypointPath, 'page').outputUrl;
|
|
@@ -400,38 +395,41 @@ export class HmrManager {
|
|
|
400
395
|
this.stop();
|
|
401
396
|
}
|
|
402
397
|
}
|
|
403
|
-
function buildStrategyEvents(action, fallbackReload
|
|
404
|
-
|
|
405
|
-
|
|
398
|
+
function buildStrategyEvents(action, fallbackReload) {
|
|
399
|
+
if (action.type === 'broadcast' && action.events) {
|
|
400
|
+
return action.events;
|
|
401
|
+
}
|
|
402
|
+
return fallbackReload ? [{ type: 'reload' }] : [];
|
|
406
403
|
}
|
|
407
404
|
/**
|
|
408
405
|
* @remarks
|
|
409
406
|
* A `reload` makes every other update redundant. Otherwise each distinct update is kept, so edits that touch several
|
|
410
407
|
* islands hot-update each of them, and several layout updates collapse into one soft refresh.
|
|
408
|
+
*
|
|
409
|
+
* Errors are placed after the updates. The client clears a shown build error whenever a non-error message arrives,
|
|
410
|
+
* so an error that precedes an update in the same batch would be wiped out by it.
|
|
411
411
|
*/
|
|
412
412
|
function coalesceBatchEvents(events) {
|
|
413
413
|
const errors = deduplicateEvents(events.filter((event) => event.type === 'error'));
|
|
414
414
|
const updates = deduplicateEvents(events.filter((event) => event.type !== 'error'));
|
|
415
415
|
if (updates.length <= 1) {
|
|
416
|
-
return [...
|
|
416
|
+
return [...updates, ...errors];
|
|
417
417
|
}
|
|
418
|
-
const graphIdentities = mergeGraphIdentities(updates);
|
|
419
418
|
if (updates.some((event) => event.type === 'reload')) {
|
|
420
|
-
return [
|
|
419
|
+
return [{ type: 'reload' }, ...errors];
|
|
421
420
|
}
|
|
422
421
|
const layoutUpdates = updates.filter((event) => event.type === 'layout-update');
|
|
423
422
|
const others = updates.filter((event) => event.type !== 'layout-update');
|
|
424
423
|
if (layoutUpdates.length <= 1) {
|
|
425
|
-
return [...
|
|
424
|
+
return [...others, ...layoutUpdates, ...errors];
|
|
426
425
|
}
|
|
427
426
|
return [
|
|
428
|
-
...errors,
|
|
429
427
|
...others,
|
|
430
428
|
{
|
|
431
429
|
type: 'layout-update',
|
|
432
430
|
timestamp: Math.max(...layoutUpdates.map((event) => event.timestamp ?? 0)),
|
|
433
|
-
...(graphIdentities ? { graphIdentities } : {}),
|
|
434
431
|
},
|
|
432
|
+
...errors,
|
|
435
433
|
];
|
|
436
434
|
}
|
|
437
435
|
function deduplicateEvents(events) {
|
|
@@ -440,13 +438,11 @@ function deduplicateEvents(events) {
|
|
|
440
438
|
const key = JSON.stringify([event.type, event.path, event.message]);
|
|
441
439
|
const existing = uniqueEvents.get(key);
|
|
442
440
|
if (existing) {
|
|
443
|
-
const graphIdentities = mergeGraphIdentities([existing, event]);
|
|
444
441
|
uniqueEvents.set(key, {
|
|
445
442
|
...existing,
|
|
446
443
|
...(existing.timestamp !== undefined || event.timestamp !== undefined
|
|
447
444
|
? { timestamp: Math.max(existing.timestamp ?? 0, event.timestamp ?? 0) }
|
|
448
445
|
: {}),
|
|
449
|
-
...(graphIdentities ? { graphIdentities } : {}),
|
|
450
446
|
});
|
|
451
447
|
continue;
|
|
452
448
|
}
|
|
@@ -454,11 +450,3 @@ function deduplicateEvents(events) {
|
|
|
454
450
|
}
|
|
455
451
|
return [...uniqueEvents.values()];
|
|
456
452
|
}
|
|
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
|
-
}
|