@ecopages/core 0.2.0-rc.1 → 0.2.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -41
- package/package.json +50 -145
- package/src/adapters/README.md +11 -3
- package/src/adapters/abstract/application-adapter.d.ts +32 -36
- package/src/adapters/abstract/application-adapter.js +61 -47
- package/src/adapters/abstract/segment-path-matcher.js +56 -38
- package/src/adapters/abstract/server-adapter.d.ts +14 -0
- package/src/adapters/abstract/server-adapter.js +10 -0
- package/src/adapters/abstract/ws-pattern-matcher.d.ts +0 -5
- package/src/adapters/abstract/ws-pattern-matcher.js +0 -9
- package/src/adapters/bun/create-app.d.ts +15 -15
- package/src/adapters/bun/create-app.js +52 -67
- package/src/adapters/bun/hmr-manager.d.ts +0 -1
- package/src/adapters/bun/hmr-manager.js +2 -4
- package/src/adapters/bun/server-adapter.d.ts +15 -21
- package/src/adapters/bun/server-adapter.js +33 -67
- package/src/adapters/bun/static-preview-host.d.ts +1 -0
- package/src/adapters/bun/static-preview-host.js +1 -1
- package/src/adapters/create-app.d.ts +63 -8
- package/src/adapters/create-app.js +62 -5
- package/src/adapters/node/create-app.d.ts +8 -12
- package/src/adapters/node/create-app.js +22 -14
- package/src/adapters/node/runtime-host.d.ts +10 -10
- package/src/adapters/node/runtime-host.js +13 -8
- package/src/adapters/node/server-adapter-dependencies.d.ts +2 -10
- package/src/adapters/node/server-adapter-dependencies.js +8 -13
- package/src/adapters/node/server-adapter.d.ts +30 -32
- package/src/adapters/node/server-adapter.js +59 -65
- package/src/adapters/shared/hmr/shared-hmr-manager.d.ts +0 -4
- package/src/adapters/shared/hmr/shared-hmr-manager.js +0 -12
- package/src/adapters/shared/http/api-request-pipeline.d.ts +27 -1
- package/src/adapters/shared/http/api-request-pipeline.js +31 -16
- package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
- package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -9
- package/src/adapters/shared/http/fs-server-response-factory.js +5 -33
- package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
- package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
- package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
- package/src/adapters/shared/runtime/application-adapter.js +12 -0
- package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
- package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
- package/src/adapters/shared/runtime/collect-dev-prewarm-plan.d.ts +1 -3
- package/src/adapters/shared/runtime/collect-dev-prewarm-plan.js +1 -4
- package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
- package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
- package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
- package/src/adapters/shared/runtime/port-manager.js +14 -45
- package/src/adapters/shared/runtime/runtime-app-bootstrap.d.ts +0 -10
- package/src/adapters/shared/runtime/runtime-app-bootstrap.js +0 -7
- package/src/adapters/shared/runtime/runtime-host.d.ts +5 -2
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +1 -1
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +1 -1
- package/src/adapters/shared/runtime/server-adapter.d.ts +27 -5
- package/src/adapters/shared/runtime/server-adapter.js +44 -30
- package/src/adapters/shared/runtime/server-route-handler.js +11 -3
- package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
- package/src/adapters/shared/runtime/server-static-builder.js +59 -37
- package/src/adapters/shared/ws/node-http-websocket-upgrades.d.ts +9 -1
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +8 -2
- package/src/build/README.md +9 -6
- package/src/build/cache/cache-constants.d.ts +0 -2
- package/src/build/cache/cache-constants.js +0 -2
- package/src/build/cache/cache-keys.d.ts +0 -2
- package/src/build/cache/cache-keys.js +0 -2
- package/src/build/cache/output-imports.d.ts +27 -0
- package/src/build/cache/output-imports.js +80 -0
- package/src/build/cache/pages-unified-graph-build.d.ts +6 -1
- package/src/build/cache/pages-unified-graph-build.js +42 -17
- package/src/build/cache/production-build-cache.d.ts +2 -2
- package/src/build/cache/production-build-cache.js +2 -2
- package/src/build/cache/server-entry-build-cache.d.ts +25 -3
- package/src/build/cache/server-entry-build-cache.js +129 -13
- package/src/build/contracts/build-contracts.d.ts +1 -13
- package/src/build/contracts/content-virtual-modules.d.ts +3 -1
- package/src/build/contracts/content-virtual-modules.js +8 -0
- package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
- package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
- package/src/build/rolldown/runtime-build-output-normalizer.js +3 -6
- package/src/build/runtime/build-request-identity.d.ts +2 -6
- package/src/build/runtime/build-request-identity.js +2 -8
- package/src/build/runtime/build-request-policy.js +1 -1
- package/src/build/runtime/deduping-build-executor.d.ts +0 -1
- package/src/build/runtime/deduping-build-executor.js +0 -1
- package/src/build/server-bundle-publication.d.ts +14 -0
- package/src/build/server-bundle-publication.js +49 -0
- package/src/cache/index.d.ts +1 -1
- package/src/cache/index.js +1 -1
- package/src/cache/module-parse-cache.d.ts +2 -29
- package/src/cache/module-parse-cache.js +6 -39
- package/src/config/README.md +17 -2
- package/src/config/apply-user-config.d.ts +8 -0
- package/src/config/apply-user-config.js +68 -0
- package/src/config/config-builder.d.ts +11 -1
- package/src/config/config-builder.js +53 -12
- package/src/config/constants.d.ts +4 -4
- package/src/config/constants.js +4 -4
- package/src/config/define-config.d.ts +9 -0
- package/src/config/define-config.js +10 -0
- package/src/config/index.d.ts +5 -0
- package/src/config/index.js +4 -0
- package/src/config/is-finalized-app-config.d.ts +6 -0
- package/src/config/is-finalized-app-config.js +11 -0
- package/src/config/load-eco-config.d.ts +21 -0
- package/src/config/load-eco-config.js +107 -0
- package/src/config/resolve-eco-config-path.d.ts +32 -0
- package/src/config/resolve-eco-config-path.js +58 -0
- package/src/config/server-config-bundle.d.ts +25 -0
- package/src/config/server-config-bundle.js +148 -0
- package/src/config/user-config-types.d.ts +170 -0
- package/src/config/user-config-types.js +1 -0
- package/src/css-imports.d.ts +4 -0
- package/src/declarations.d.ts +11 -5
- package/src/dev/README.md +6 -0
- package/src/dev/development-restart-watch-paths.d.ts +13 -0
- package/src/dev/development-restart-watch-paths.js +37 -0
- package/src/dev/development-restart.d.ts +13 -0
- package/src/dev/development-restart.js +21 -0
- package/src/dev/host-runtime.d.ts +0 -1
- package/src/dev/host-runtime.js +0 -3
- package/src/dev/sc-server.d.ts +4 -1
- package/src/dev/sc-server.js +11 -20
- package/src/dev/transform-server/dev-transform-import-rewriter.js +2 -2
- package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
- package/src/dev/transform-server/dev-transform-server.js +16 -5
- package/src/eco/README.md +73 -5
- package/src/eco/component-identity.d.ts +3 -2
- package/src/eco/component-identity.js +5 -2
- package/src/eco/discovered-dependencies.d.ts +45 -0
- package/src/eco/discovered-dependencies.js +87 -0
- package/src/eco/eco.js +6 -0
- package/src/eco/eco.types.d.ts +18 -2
- package/src/eco/lazy-injector-map.js +57 -41
- package/src/eco/page-dependency-contributions.d.ts +19 -0
- package/src/eco/page-dependency-contributions.js +52 -0
- package/src/errors/http-error-page-contract.d.ts +77 -0
- package/src/errors/http-error-page-contract.js +106 -0
- package/src/hmr/hmr-file-change-prep.d.ts +0 -1
- package/src/hmr/hmr-file-change-prep.js +2 -5
- package/src/hmr/hmr-strategy.d.ts +3 -8
- package/src/hmr/hmr-strategy.js +3 -8
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
- package/src/hmr/strategies/js-hmr-strategy.js +24 -16
- package/src/index.browser.d.ts +2 -0
- package/src/index.browser.js +2 -0
- package/src/index.d.ts +5 -3
- package/src/index.js +5 -3
- package/src/islands/README.md +5 -1
- package/src/islands/island-host.d.ts +0 -9
- package/src/islands/island-host.js +1 -13
- package/src/plugins/README.md +8 -1
- package/src/plugins/component-import-discovery.d.ts +19 -0
- package/src/plugins/component-import-discovery.js +241 -0
- package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
- package/src/plugins/eco-component-meta-plugin.js +120 -18
- package/src/plugins/integration-plugin.d.ts +0 -1
- package/src/plugins/integration-plugin.js +0 -4
- package/src/plugins/processor.d.ts +10 -2
- package/src/plugins/processor.js +4 -0
- package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
- package/src/plugins/tsconfig-import-resolver.js +4 -2
- package/src/route-renderer/GRAPH.md +1 -1
- package/src/route-renderer/README.md +15 -2
- package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +80 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +3 -4
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
- package/src/route-renderer/orchestration/integration-renderer.d.ts +9 -11
- package/src/route-renderer/orchestration/integration-renderer.js +43 -40
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +1 -1
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
- package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -1
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +1 -1
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +8 -10
- package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
- package/src/route-renderer/orchestration/string-markup-renderer.js +2 -1
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
- package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
- package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
- package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
- package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
- package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
- package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
- package/src/route-renderer/route-renderer.d.ts +9 -0
- package/src/route-renderer/route-renderer.js +18 -0
- package/src/router/README.md +7 -1
- package/src/router/server/route-registry.d.ts +13 -0
- package/src/router/server/route-registry.js +46 -32
- package/src/services/README.md +6 -1
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
- package/src/services/assets/asset-processing-service/page-package.js +42 -39
- package/src/services/assets/browser-bundle.service.d.ts +1 -6
- package/src/services/error-pages/README.md +9 -0
- package/src/services/error-pages/default-error-pages.d.ts +39 -0
- package/src/services/error-pages/default-error-pages.js +199 -0
- package/src/services/error-pages/error-page-renderer.d.ts +58 -0
- package/src/services/error-pages/error-page-renderer.js +146 -0
- package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
- package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
- package/src/services/html/html-rewriter.d.ts +77 -0
- package/src/services/html/html-rewriter.js +751 -0
- package/src/services/html/html-rewriter.parity.test.bun.d.ts +1 -0
- package/src/services/html/html-rewriter.parity.test.bun.js +74 -0
- package/src/services/html/html-transformer.service.d.ts +26 -39
- package/src/services/html/html-transformer.service.js +81 -153
- package/src/services/invalidation/development-invalidation.service.d.ts +9 -20
- package/src/services/invalidation/development-invalidation.service.js +35 -41
- package/src/services/module-loading/README.md +17 -14
- package/src/services/module-loading/app-module-loader.service.d.ts +0 -2
- package/src/services/module-loading/app-server-module-transpiler.service.d.ts +1 -1
- package/src/services/module-loading/app-server-module-transpiler.service.js +2 -10
- package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -1
- package/src/services/module-loading/collection-server-module-build.service.js +5 -5
- package/src/services/module-loading/host-module-loader-registry.d.ts +0 -1
- package/src/services/module-loading/host-module-loader-registry.js +0 -3
- package/src/services/module-loading/page-module-import.service.d.ts +8 -0
- package/src/services/module-loading/page-module-import.service.js +62 -28
- package/src/services/module-loading/route-module-build-cache-registry.d.ts +0 -4
- package/src/services/module-loading/route-module-build-cache-registry.js +0 -4
- package/src/services/module-loading/route-module-build-cache.store.d.ts +3 -0
- package/src/services/module-loading/route-module-build-cache.store.js +18 -5
- package/src/services/module-loading/route-module-build-manifest.d.ts +6 -1
- package/src/services/module-loading/route-module-build-manifest.js +1 -2
- package/src/services/module-loading/route-module-dependency-hasher.d.ts +3 -2
- package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
- package/src/services/module-loading/server-module-transpiler.service.d.ts +1 -15
- package/src/services/module-loading/server-module-transpiler.service.js +0 -24
- package/src/services/module-loading/view-module-loader.d.ts +10 -0
- package/src/services/module-loading/view-module-loader.js +46 -0
- package/src/services/runtime-state/entrypoint-dependency-graph.service.js +0 -12
- package/src/services/runtime-state/server-invalidation-state.service.d.ts +4 -2
- package/src/services/runtime-state/server-invalidation-state.service.js +7 -14
- package/src/services/validation/schema-validation-service.d.ts +1 -0
- package/src/services/validation/schema-validation-service.js +23 -36
- package/src/static-site-generator/README.md +6 -1
- package/src/static-site-generator/static-site-generator.d.ts +7 -2
- package/src/static-site-generator/static-site-generator.js +90 -49
- package/src/types/internal-types.d.ts +6 -39
- package/src/types/public-types.d.ts +29 -131
- package/src/utils/parse-cli-args.js +29 -22
- package/src/watchers/project-watcher.d.ts +14 -16
- package/src/watchers/project-watcher.js +86 -61
- package/src/watchers/project-watcher.test-helpers.d.ts +10 -1
- package/src/watchers/project-watcher.test-helpers.js +12 -0
- package/src/adapters/abstract/router-adapter.d.ts +0 -26
- package/src/adapters/abstract/router-adapter.js +0 -13
- package/src/adapters/bun/index.d.ts +0 -2
- package/src/adapters/bun/index.js +0 -2
- package/src/adapters/index.d.ts +0 -2
- package/src/adapters/index.js +0 -2
- package/src/eco/eco.utils.d.ts +0 -1
- package/src/eco/eco.utils.js +0 -1
- package/src/services/cache/index.d.ts +0 -9
- package/src/services/cache/index.js +0 -8
- package/src/services/html/html-rewriter-provider.service.d.ts +0 -40
- package/src/services/html/html-rewriter-provider.service.js +0 -68
- package/src/services/module-loading/route-module-build-cache.d.ts +0 -4
- package/src/services/module-loading/route-module-build-cache.js +0 -3
- package/src/services/runtime-state/dev-graph.service.d.ts +0 -118
- package/src/services/runtime-state/dev-graph.service.js +0 -170
- /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
|
@@ -8,7 +8,7 @@ import { ServerStaticBuilder } from './server-static-builder.js';
|
|
|
8
8
|
import { FileSystemResponseMatcher } from '../http/fs-server-response-matcher.js';
|
|
9
9
|
import { ServerRouteHandler } from './server-route-handler.js';
|
|
10
10
|
import { ApiRequestPipeline } from '../http/api-request-pipeline.js';
|
|
11
|
-
import type { ApiHandler, CacheInvalidator, ErrorHandler, IHmrManager, RenderContext, StaticRoute } from '../../../types/public-types.js';
|
|
11
|
+
import type { ApiHandler, CacheInvalidator, ErrorHandler, IHmrManager, RenderContext, StaticRoute, ErrorPageLoaders } from '../../../types/public-types.js';
|
|
12
12
|
type SharedHmrAssetManager = IHmrManager;
|
|
13
13
|
type SharedRequestContext<TServer = unknown> = {
|
|
14
14
|
apiHandlers: ApiHandler[];
|
|
@@ -28,17 +28,24 @@ export declare abstract class SharedServerAdapter<TOptions extends ServerAdapter
|
|
|
28
28
|
protected hostOwnsDevClient: boolean;
|
|
29
29
|
private devStaticRoutePrewarmStarted;
|
|
30
30
|
private sharedPageCacheService;
|
|
31
|
+
/** Propagates the actual listening port to every binding-dependent service. */
|
|
32
|
+
applyBoundPort(input: {
|
|
33
|
+
port: number;
|
|
34
|
+
runtimeOrigin: string;
|
|
35
|
+
}): void;
|
|
31
36
|
/**
|
|
32
37
|
* Warms declared static paths after the final watch-mode response pipeline exists.
|
|
33
38
|
*/
|
|
34
39
|
protected startDevStaticRoutePrewarmWhenReady(): Promise<void>;
|
|
35
40
|
protected initializeSharedRouteHandling(options: {
|
|
36
41
|
staticRoutes: StaticRoute[];
|
|
42
|
+
errorPageLoaders?: ErrorPageLoaders;
|
|
37
43
|
hmrManager?: SharedHmrAssetManager;
|
|
38
44
|
}): Promise<void>;
|
|
39
45
|
private ensureRouteRendererFactory;
|
|
40
46
|
protected createSharedWatchRefreshCallback(options: {
|
|
41
47
|
staticRoutes: StaticRoute[];
|
|
48
|
+
errorPageLoaders?: ErrorPageLoaders;
|
|
42
49
|
hmrManager?: SharedHmrAssetManager;
|
|
43
50
|
onRoutesReady?: () => Promise<void> | void;
|
|
44
51
|
onError?: (error: Error) => Promise<void> | void;
|
|
@@ -60,12 +67,14 @@ export declare abstract class SharedServerAdapter<TOptions extends ServerAdapter
|
|
|
60
67
|
* 1. How to render React/Lit pages via `RouteRendererFactory`
|
|
61
68
|
* 2. How to match logical routes to physical filesystem artifacts via `FileSystemResponseMatcher`
|
|
62
69
|
* 3. Whether to serve the response from the embedded `PageCacheService` or generate it fresh on the fly.
|
|
63
|
-
*
|
|
64
|
-
* @param staticRoutes - A map of explicitly served static assets.
|
|
65
|
-
* @param hmrManager - The runtime-specific Hot Module Replacement orchestrator (if watching).
|
|
66
70
|
*/
|
|
67
|
-
protected configureSharedResponseHandlers(
|
|
71
|
+
protected configureSharedResponseHandlers(options: {
|
|
72
|
+
staticRoutes: StaticRoute[];
|
|
73
|
+
hmrManager?: IHmrManager;
|
|
74
|
+
errorPageLoaders?: ErrorPageLoaders;
|
|
75
|
+
}): void;
|
|
68
76
|
private createSharedResponseHandlerDependencies;
|
|
77
|
+
private createSharedPageCacheServiceFromConfig;
|
|
69
78
|
private getOrCreateSharedPageCacheService;
|
|
70
79
|
protected getCacheService(): CacheInvalidator | null;
|
|
71
80
|
protected getRenderContext(): RenderContext;
|
|
@@ -73,6 +82,19 @@ export declare abstract class SharedServerAdapter<TOptions extends ServerAdapter
|
|
|
73
82
|
private tryHandleSharedHmrRequest;
|
|
74
83
|
private injectSharedHmrHtmlResponse;
|
|
75
84
|
private tryHandleSharedApiRequest;
|
|
85
|
+
/**
|
|
86
|
+
* Recognises a runtime-specific client disconnect so it answers 499.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* Only the Node adapter overrides it: its request bridge raises a dedicated
|
|
90
|
+
* error when the socket closes while the body is read.
|
|
91
|
+
*/
|
|
92
|
+
protected isClientAbortError(_error: unknown): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Resolves an error that escaped {@link handleSharedRequest} with the same
|
|
95
|
+
* precedence as API handler errors, so `app.onError` sees it on every runtime.
|
|
96
|
+
*/
|
|
97
|
+
protected handleUnexpectedRequestError(error: unknown, request: Request, context: SharedRequestContext): Promise<Response>;
|
|
76
98
|
/**
|
|
77
99
|
* Universally processes an incoming WinterCG Web standard Request.
|
|
78
100
|
*
|
|
@@ -33,10 +33,17 @@ export class SharedServerAdapter extends AbstractServerAdapter {
|
|
|
33
33
|
schemaValidator: this.schemaValidator,
|
|
34
34
|
getRenderContext: () => this.getRenderContext(),
|
|
35
35
|
getCacheService: () => this.getCacheService(),
|
|
36
|
+
isClientAbort: (error) => this.isClientAbortError(error),
|
|
36
37
|
});
|
|
37
38
|
hostOwnsDevClient = false;
|
|
38
39
|
devStaticRoutePrewarmStarted = false;
|
|
39
40
|
sharedPageCacheService;
|
|
41
|
+
/** Propagates the actual listening port to every binding-dependent service. */
|
|
42
|
+
applyBoundPort(input) {
|
|
43
|
+
super.applyBoundPort(input);
|
|
44
|
+
this.routeRendererFactory?.setRuntimeOrigin(input.runtimeOrigin);
|
|
45
|
+
this.staticBuilder?.setRuntimeBinding(input);
|
|
46
|
+
}
|
|
40
47
|
/**
|
|
41
48
|
* Warms declared static paths after the final watch-mode response pipeline exists.
|
|
42
49
|
*/
|
|
@@ -72,7 +79,7 @@ export class SharedServerAdapter extends AbstractServerAdapter {
|
|
|
72
79
|
async initializeSharedRouteHandling(options) {
|
|
73
80
|
this.ensureRouteRendererFactory();
|
|
74
81
|
await this.initSharedRouter();
|
|
75
|
-
this.configureSharedResponseHandlers(options
|
|
82
|
+
this.configureSharedResponseHandlers(options);
|
|
76
83
|
}
|
|
77
84
|
ensureRouteRendererFactory() {
|
|
78
85
|
if (this.routeRendererFactory) {
|
|
@@ -89,6 +96,7 @@ export class SharedServerAdapter extends AbstractServerAdapter {
|
|
|
89
96
|
try {
|
|
90
97
|
await this.initializeSharedRouteHandling({
|
|
91
98
|
staticRoutes: options.staticRoutes,
|
|
99
|
+
errorPageLoaders: options.errorPageLoaders,
|
|
92
100
|
hmrManager: options.hmrManager,
|
|
93
101
|
});
|
|
94
102
|
if (options.onRoutesReady) {
|
|
@@ -147,22 +155,19 @@ export class SharedServerAdapter extends AbstractServerAdapter {
|
|
|
147
155
|
* 1. How to render React/Lit pages via `RouteRendererFactory`
|
|
148
156
|
* 2. How to match logical routes to physical filesystem artifacts via `FileSystemResponseMatcher`
|
|
149
157
|
* 3. Whether to serve the response from the embedded `PageCacheService` or generate it fresh on the fly.
|
|
150
|
-
*
|
|
151
|
-
* @param staticRoutes - A map of explicitly served static assets.
|
|
152
|
-
* @param hmrManager - The runtime-specific Hot Module Replacement orchestrator (if watching).
|
|
153
158
|
*/
|
|
154
|
-
configureSharedResponseHandlers(
|
|
159
|
+
configureSharedResponseHandlers(options) {
|
|
155
160
|
this.ensureRouteRendererFactory();
|
|
156
|
-
const { fileSystemResponseMatcher, explicitStaticRouteMatcher } = this.createSharedResponseHandlerDependencies(staticRoutes);
|
|
161
|
+
const { fileSystemResponseMatcher, explicitStaticRouteMatcher } = this.createSharedResponseHandlerDependencies(options.staticRoutes, options.errorPageLoaders);
|
|
157
162
|
this.fileSystemResponseMatcher = fileSystemResponseMatcher;
|
|
158
163
|
this.routeHandler = new ServerRouteHandler({
|
|
159
164
|
router: this.router,
|
|
160
165
|
fileSystemResponseMatcher: this.fileSystemResponseMatcher,
|
|
161
166
|
explicitStaticRouteMatcher,
|
|
162
|
-
hmrManager,
|
|
167
|
+
hmrManager: options.hmrManager,
|
|
163
168
|
});
|
|
164
169
|
}
|
|
165
|
-
createSharedResponseHandlerDependencies(staticRoutes) {
|
|
170
|
+
createSharedResponseHandlerDependencies(staticRoutes, errorPageLoaders) {
|
|
166
171
|
const fileSystemResponseFactory = new FileSystemServerResponseFactory({
|
|
167
172
|
options: {
|
|
168
173
|
watchMode: !!this.options?.watch,
|
|
@@ -174,6 +179,7 @@ export class SharedServerAdapter extends AbstractServerAdapter {
|
|
|
174
179
|
assetPrefix: path.join(this.appConfig.rootDir, this.appConfig.distDir),
|
|
175
180
|
router: this.router,
|
|
176
181
|
routeRendererFactory: this.routeRendererFactory,
|
|
182
|
+
errorPageLoaders,
|
|
177
183
|
fileSystemResponseFactory,
|
|
178
184
|
cacheService,
|
|
179
185
|
defaultCacheStrategy: this.appConfig.cache?.defaultStrategy ?? 'static',
|
|
@@ -190,36 +196,23 @@ export class SharedServerAdapter extends AbstractServerAdapter {
|
|
|
190
196
|
: undefined,
|
|
191
197
|
};
|
|
192
198
|
}
|
|
193
|
-
|
|
194
|
-
if (this.sharedPageCacheService !== undefined) {
|
|
195
|
-
return this.sharedPageCacheService;
|
|
196
|
-
}
|
|
199
|
+
createSharedPageCacheServiceFromConfig() {
|
|
197
200
|
const cacheConfig = this.appConfig.cache;
|
|
198
201
|
const watch = Boolean(this.options?.watch);
|
|
199
|
-
|
|
200
|
-
if (cacheConfig?.enabled === false) {
|
|
201
|
-
this.sharedPageCacheService = null;
|
|
202
|
-
registerAppPageCacheService(this.appConfig, null);
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
const store = cacheConfig?.store === 'memory' || !cacheConfig?.store
|
|
206
|
-
? new MemoryCacheStore({ maxEntries: cacheConfig?.maxEntries })
|
|
207
|
-
: cacheConfig.store;
|
|
208
|
-
const service = new PageCacheService({ store, enabled: true });
|
|
209
|
-
this.sharedPageCacheService = service;
|
|
210
|
-
registerAppPageCacheService(this.appConfig, service);
|
|
211
|
-
return service;
|
|
212
|
-
}
|
|
213
|
-
const isCacheEnabled = cacheConfig?.enabled ?? true;
|
|
202
|
+
const isCacheEnabled = watch ? cacheConfig?.enabled !== false : (cacheConfig?.enabled ?? true);
|
|
214
203
|
if (!isCacheEnabled) {
|
|
215
|
-
this.sharedPageCacheService = null;
|
|
216
|
-
registerAppPageCacheService(this.appConfig, null);
|
|
217
204
|
return null;
|
|
218
205
|
}
|
|
219
206
|
const store = cacheConfig?.store === 'memory' || !cacheConfig?.store
|
|
220
207
|
? new MemoryCacheStore({ maxEntries: cacheConfig?.maxEntries })
|
|
221
208
|
: cacheConfig.store;
|
|
222
|
-
|
|
209
|
+
return new PageCacheService({ store, enabled: true });
|
|
210
|
+
}
|
|
211
|
+
getOrCreateSharedPageCacheService() {
|
|
212
|
+
if (this.sharedPageCacheService !== undefined) {
|
|
213
|
+
return this.sharedPageCacheService;
|
|
214
|
+
}
|
|
215
|
+
const service = this.createSharedPageCacheServiceFromConfig();
|
|
223
216
|
this.sharedPageCacheService = service;
|
|
224
217
|
registerAppPageCacheService(this.appConfig, service);
|
|
225
218
|
return service;
|
|
@@ -269,6 +262,27 @@ export class SharedServerAdapter extends AbstractServerAdapter {
|
|
|
269
262
|
async tryHandleSharedApiRequest(request, context) {
|
|
270
263
|
return await this.apiRequestPipeline.tryHandle(request, context.apiHandlers, context.serverInstance, context.errorHandler);
|
|
271
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Recognises a runtime-specific client disconnect so it answers 499.
|
|
267
|
+
*
|
|
268
|
+
* @remarks
|
|
269
|
+
* Only the Node adapter overrides it: its request bridge raises a dedicated
|
|
270
|
+
* error when the socket closes while the body is read.
|
|
271
|
+
*/
|
|
272
|
+
isClientAbortError(_error) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Resolves an error that escaped {@link handleSharedRequest} with the same
|
|
277
|
+
* precedence as API handler errors, so `app.onError` sees it on every runtime.
|
|
278
|
+
*/
|
|
279
|
+
async handleUnexpectedRequestError(error, request, context) {
|
|
280
|
+
return await this.apiRequestPipeline.handleError(error, {
|
|
281
|
+
request,
|
|
282
|
+
serverInstance: context.serverInstance,
|
|
283
|
+
errorHandler: context.errorHandler,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
272
286
|
/**
|
|
273
287
|
* Universally processes an incoming WinterCG Web standard Request.
|
|
274
288
|
*
|
|
@@ -40,7 +40,15 @@ export class ServerRouteHandler {
|
|
|
40
40
|
const pathname = new URL(request.url).pathname;
|
|
41
41
|
const explicitMatch = this.explicitStaticRouteMatcher?.match(request.url);
|
|
42
42
|
if (explicitMatch) {
|
|
43
|
-
|
|
43
|
+
try {
|
|
44
|
+
return await this.explicitStaticRouteMatcher.handleMatch(explicitMatch);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof Response) {
|
|
48
|
+
return error;
|
|
49
|
+
}
|
|
50
|
+
return await this.fileSystemResponseMatcher.renderServerError(pathname, error);
|
|
51
|
+
}
|
|
44
52
|
}
|
|
45
53
|
const fsMatch = !pathname.includes('.') && this.router.matchRequest(request.url);
|
|
46
54
|
return await (fsMatch
|
|
@@ -59,8 +67,8 @@ export class ServerRouteHandler {
|
|
|
59
67
|
* @throws HttpError for standard HTTP errors
|
|
60
68
|
*/
|
|
61
69
|
async handleNoMatch(request) {
|
|
70
|
+
const pathname = new URL(request.url).pathname;
|
|
62
71
|
try {
|
|
63
|
-
const pathname = new URL(request.url).pathname;
|
|
64
72
|
return await this.fileSystemResponseMatcher.handleNoMatch(pathname);
|
|
65
73
|
}
|
|
66
74
|
catch (error) {
|
|
@@ -71,7 +79,7 @@ export class ServerRouteHandler {
|
|
|
71
79
|
this.hmrManager?.broadcast({ type: 'error', message: error.message });
|
|
72
80
|
appLogger.error('Error handling no match:', error);
|
|
73
81
|
}
|
|
74
|
-
return
|
|
82
|
+
return await this.fileSystemResponseMatcher.renderServerError(pathname, error);
|
|
75
83
|
}
|
|
76
84
|
}
|
|
77
85
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EcoPagesAppConfig, IHmrManager } from '../../../types/internal-types.js';
|
|
2
2
|
import type { EcoBuildPlugin } from '../../../build/contracts/build-types.js';
|
|
3
|
-
import type { StaticRoute } from '../../../types/public-types.js';
|
|
3
|
+
import type { ErrorPageLoaders, StaticRoute } from '../../../types/public-types.js';
|
|
4
4
|
import type { RouteRegistry } from '../../../router/server/route-registry.js';
|
|
5
5
|
import type { StaticSiteGenerator } from '../../../static-site-generator/static-site-generator.js';
|
|
6
6
|
import type { StaticGenerationRendererResolver } from '../../../route-renderer/route-renderer.js';
|
|
@@ -43,14 +43,19 @@ export interface ServerStaticBuilderLogger {
|
|
|
43
43
|
export declare class ServerStaticBuilder {
|
|
44
44
|
private readonly appConfig;
|
|
45
45
|
private readonly staticSiteGenerator;
|
|
46
|
-
private
|
|
47
|
-
private
|
|
46
|
+
private serveOptions;
|
|
47
|
+
private runtimeOrigin;
|
|
48
48
|
private readonly needsServerBundle;
|
|
49
49
|
private readonly logger;
|
|
50
50
|
private readonly entryFile;
|
|
51
51
|
private readonly hmrManager?;
|
|
52
52
|
private readonly onRuntimePlugin?;
|
|
53
53
|
constructor({ appConfig, staticSiteGenerator, serveOptions, runtimeOrigin, needsServerBundle, logger, entryFile, hmrManager, onRuntimePlugin, }: ServerStaticBuilderParams);
|
|
54
|
+
/** Keeps build-time URLs aligned with the server's actual listening port. */
|
|
55
|
+
setRuntimeBinding(input: {
|
|
56
|
+
port: number;
|
|
57
|
+
runtimeOrigin: string;
|
|
58
|
+
}): void;
|
|
54
59
|
private prepareExportDirectory;
|
|
55
60
|
private refreshRuntimeAssets;
|
|
56
61
|
/**
|
|
@@ -82,5 +87,6 @@ export declare class ServerStaticBuilder {
|
|
|
82
87
|
router: RouteRegistry;
|
|
83
88
|
routeRendererFactory: StaticGenerationRendererResolver;
|
|
84
89
|
staticRoutes?: StaticRoute[];
|
|
90
|
+
errorPageLoaders?: ErrorPageLoaders;
|
|
85
91
|
}): Promise<void>;
|
|
86
92
|
}
|
|
@@ -2,12 +2,14 @@ import path from 'node:path';
|
|
|
2
2
|
import { fileSystem } from '@ecopages/file-system';
|
|
3
3
|
import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from '../../../config/constants.js';
|
|
4
4
|
import { appLogger } from '../../../global/app-logger.js';
|
|
5
|
-
import { build,
|
|
5
|
+
import { build, setupAppRuntimePlugins } from '../../../build/build-adapter.js';
|
|
6
|
+
import { createServerBundleStagingDirectory, publishServerBundleDirectory, removeServerBundleStagingDirectory, resolvePublishedServerBundlePaths, } from '../../../build/server-bundle-publication.js';
|
|
6
7
|
import { createServerBuildRequest } from '../../../build/runtime/build-request-policy.js';
|
|
7
8
|
import { requireBuildRuntime } from '../../../build/runtime/build-runtime.js';
|
|
8
9
|
import { attachHmrToIntegrations } from './runtime-server-lifecycle.js';
|
|
9
|
-
import { getServerBundleOutputPaths, lookupServerEntryBuildCache, recordServerEntryBuildCache, writeServerBundleDeployManifest, } from '../../../build/cache/server-entry-build-cache.js';
|
|
10
|
+
import { getServerBundleOutputPaths, lookupServerEntryBuildCache, recordServerEntryBuildCache, SERVER_BUNDLE_MANIFEST_FILENAME, writeServerBundleDeployManifest, } from '../../../build/cache/server-entry-build-cache.js';
|
|
10
11
|
import { clearProductionBuildCaches, shouldResetStaticExportDirectory, } from '../../../static-site-generator/static-build-invalidation.js';
|
|
12
|
+
import { assertCanBundleServerConfig, bundleEcoConfigModule, EMITTED_ECO_CONFIG_FILENAME, } from '../../../config/server-config-bundle.js';
|
|
11
13
|
import { resolveEntryFile, SERVER_BUNDLE_FILENAME } from '../../../utils/resolve-entry-file.js';
|
|
12
14
|
/**
|
|
13
15
|
* Handles static site generation.
|
|
@@ -33,6 +35,11 @@ export class ServerStaticBuilder {
|
|
|
33
35
|
this.hmrManager = hmrManager;
|
|
34
36
|
this.onRuntimePlugin = onRuntimePlugin;
|
|
35
37
|
}
|
|
38
|
+
/** Keeps build-time URLs aligned with the server's actual listening port. */
|
|
39
|
+
setRuntimeBinding(input) {
|
|
40
|
+
this.serveOptions = { ...this.serveOptions, port: input.port };
|
|
41
|
+
this.runtimeOrigin = input.runtimeOrigin;
|
|
42
|
+
}
|
|
36
43
|
prepareExportDirectory(force) {
|
|
37
44
|
if (force) {
|
|
38
45
|
clearProductionBuildCaches(this.appConfig);
|
|
@@ -87,56 +94,70 @@ export class ServerStaticBuilder {
|
|
|
87
94
|
* @throws If the build adapter is unavailable, is host-owned, or bundling fails.
|
|
88
95
|
*/
|
|
89
96
|
async bundleServerEntry(options) {
|
|
90
|
-
|
|
91
|
-
if (buildAdapter.ownership === 'vite-host') {
|
|
92
|
-
throw new Error('Cannot bundle the server entry file: build ownership is "vite-host". ' +
|
|
93
|
-
'The host runtime is expected to produce its own server bundle.');
|
|
94
|
-
}
|
|
97
|
+
assertCanBundleServerConfig(this.appConfig);
|
|
95
98
|
const entryPath = path.isAbsolute(this.entryFile)
|
|
96
99
|
? this.entryFile
|
|
97
100
|
: path.join(this.appConfig.rootDir, this.entryFile);
|
|
98
101
|
if (!fileSystem.exists(entryPath)) {
|
|
99
102
|
throw new Error(`Cannot bundle server entry: file "${this.entryFile}" not found in "${this.appConfig.rootDir}".`);
|
|
100
103
|
}
|
|
101
|
-
const { serverOutdir
|
|
104
|
+
const { serverOutdir } = getServerBundleOutputPaths(this.appConfig);
|
|
102
105
|
const cached = lookupServerEntryBuildCache({
|
|
103
106
|
appConfig: this.appConfig,
|
|
104
107
|
entryPath,
|
|
105
108
|
force: options?.force,
|
|
106
109
|
});
|
|
107
110
|
if (cached) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.logger.info('Reusing cached server entry bundle');
|
|
111
|
-
writeServerBundleDeployManifest(this.appConfig, serverEntryPath);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
111
|
+
this.logger.info('Reusing cached server entry bundle');
|
|
112
|
+
return;
|
|
114
113
|
}
|
|
115
114
|
this.logger.info('Bundling server entry file...');
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
const stagingDir = createServerBundleStagingDirectory(serverOutdir);
|
|
116
|
+
try {
|
|
117
|
+
const configBundle = await bundleEcoConfigModule(this.appConfig, {
|
|
118
|
+
outputDir: stagingDir,
|
|
119
|
+
runtimeDir: serverOutdir,
|
|
120
|
+
});
|
|
121
|
+
const stagedServerEntryPath = path.join(stagingDir, SERVER_BUNDLE_FILENAME);
|
|
122
|
+
const buildOptions = createServerBuildRequest(this.appConfig, {
|
|
123
|
+
profile: 'server-entry',
|
|
124
|
+
entrypoints: [entryPath],
|
|
125
|
+
outdir: stagingDir,
|
|
126
|
+
naming: SERVER_BUNDLE_FILENAME,
|
|
127
|
+
sourcemap: 'hidden',
|
|
128
|
+
});
|
|
129
|
+
const result = await build(buildOptions, requireBuildRuntime(this.appConfig).getProfile('server-entry'));
|
|
130
|
+
if (!result.success) {
|
|
131
|
+
const errorMessages = result.logs.map((log) => log.message).join('\n');
|
|
132
|
+
throw new Error(`Failed to bundle server entry file:\n${errorMessages}`);
|
|
133
|
+
}
|
|
134
|
+
writeServerBundleDeployManifest(this.appConfig, stagedServerEntryPath, {
|
|
135
|
+
sourceConfigPath: this.appConfig.absolutePaths.config,
|
|
136
|
+
emittedConfigModule: configBundle ? EMITTED_ECO_CONFIG_FILENAME : undefined,
|
|
137
|
+
outputDir: stagingDir,
|
|
138
|
+
});
|
|
139
|
+
const stagedOutputPaths = [
|
|
140
|
+
...(result.outputs.length > 0
|
|
141
|
+
? result.outputs.map((output) => output.path)
|
|
142
|
+
: fileSystem.exists(stagedServerEntryPath)
|
|
143
|
+
? [stagedServerEntryPath]
|
|
144
|
+
: []),
|
|
145
|
+
...(configBundle ? [configBundle.emittedConfigPath] : []),
|
|
146
|
+
path.join(stagingDir, SERVER_BUNDLE_MANIFEST_FILENAME),
|
|
147
|
+
];
|
|
148
|
+
const outputPaths = resolvePublishedServerBundlePaths(stagedOutputPaths, stagingDir, serverOutdir);
|
|
149
|
+
publishServerBundleDirectory(stagingDir, serverOutdir);
|
|
150
|
+
recordServerEntryBuildCache({
|
|
151
|
+
appConfig: this.appConfig,
|
|
152
|
+
entryPath,
|
|
153
|
+
buildResult: result,
|
|
154
|
+
configBuildResult: configBundle?.buildResult,
|
|
155
|
+
outputPaths,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
removeServerBundleStagingDirectory(stagingDir);
|
|
127
160
|
}
|
|
128
|
-
const outputPaths = result.outputs.length > 0
|
|
129
|
-
? result.outputs.map((output) => output.path)
|
|
130
|
-
: fileSystem.exists(serverEntryPath)
|
|
131
|
-
? [serverEntryPath]
|
|
132
|
-
: [];
|
|
133
|
-
recordServerEntryBuildCache({
|
|
134
|
-
appConfig: this.appConfig,
|
|
135
|
-
entryPath,
|
|
136
|
-
buildResult: result,
|
|
137
|
-
outputPaths,
|
|
138
|
-
});
|
|
139
|
-
writeServerBundleDeployManifest(this.appConfig, serverEntryPath);
|
|
140
161
|
this.logger.info('Server entry file bundled successfully');
|
|
141
162
|
}
|
|
142
163
|
/**
|
|
@@ -159,6 +180,7 @@ export class ServerStaticBuilder {
|
|
|
159
180
|
baseUrl,
|
|
160
181
|
routeRendererFactory: dependencies.routeRendererFactory,
|
|
161
182
|
staticRoutes: dependencies.staticRoutes,
|
|
183
|
+
errorPageLoaders: dependencies.errorPageLoaders,
|
|
162
184
|
force,
|
|
163
185
|
preserveExportDirectory,
|
|
164
186
|
});
|
|
@@ -12,10 +12,18 @@ export type AttachNodeHttpWebSocketUpgradesOptions = {
|
|
|
12
12
|
passthroughUnmatched?: boolean;
|
|
13
13
|
preflight?: NodeHttpWebSocketUpgradePreflight;
|
|
14
14
|
};
|
|
15
|
+
/** Upgrade options a host passes when it attaches Ecopages to a server it shares. */
|
|
16
|
+
export type WebSocketUpgradeOptions = Pick<AttachNodeHttpWebSocketUpgradesOptions, 'passthroughUnmatched'>;
|
|
15
17
|
/**
|
|
16
|
-
* Wires Ecopages
|
|
18
|
+
* Wires Ecopages WebSocket upgrades onto a Node HTTP server's `upgrade` event.
|
|
17
19
|
*
|
|
18
20
|
* Used by the Node adapter in standalone mode and by host integrations such as
|
|
19
21
|
* the Vite plugin that embed Ecopages behind a foreign HTTP server.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This is the single owner of the unmatched-upgrade policy: an upgrade claimed
|
|
25
|
+
* by `preflight` (for example `/_hmr`) or a user route is handled here, and
|
|
26
|
+
* anything else is destroyed unless `passthroughUnmatched` leaves it for other
|
|
27
|
+
* listeners on a shared server.
|
|
20
28
|
*/
|
|
21
29
|
export declare function attachNodeHttpWebSocketUpgrades(server: NodeHttpServer, options: AttachNodeHttpWebSocketUpgradesOptions): void;
|
|
@@ -71,13 +71,19 @@ async function setupNodeWebSocketConnection(ws, wsMatch, req, runtimeOrigin, sea
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* Wires Ecopages
|
|
74
|
+
* Wires Ecopages WebSocket upgrades onto a Node HTTP server's `upgrade` event.
|
|
75
75
|
*
|
|
76
76
|
* Used by the Node adapter in standalone mode and by host integrations such as
|
|
77
77
|
* the Vite plugin that embed Ecopages behind a foreign HTTP server.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* This is the single owner of the unmatched-upgrade policy: an upgrade claimed
|
|
81
|
+
* by `preflight` (for example `/_hmr`) or a user route is handled here, and
|
|
82
|
+
* anything else is destroyed unless `passthroughUnmatched` leaves it for other
|
|
83
|
+
* listeners on a shared server.
|
|
78
84
|
*/
|
|
79
85
|
export function attachNodeHttpWebSocketUpgrades(server, options) {
|
|
80
|
-
if (options.websocketHandlers.size === 0) {
|
|
86
|
+
if (options.websocketHandlers.size === 0 && !options.preflight) {
|
|
81
87
|
return;
|
|
82
88
|
}
|
|
83
89
|
if (attachedUpgradeServers.has(server)) {
|
package/src/build/README.md
CHANGED
|
@@ -45,6 +45,7 @@ build/
|
|
|
45
45
|
app-build-manifest-runtime.ts contributor collection at startup
|
|
46
46
|
contracts/ EcoBuildPlugin, BuildOptions, AppBuildManifest
|
|
47
47
|
runtime/ profiles, executors, request policy/identity
|
|
48
|
+
server-bundle-publication.ts staged server/config artifact publication
|
|
48
49
|
rolldown/ bundler adapter, plugin bridge, output normalization
|
|
49
50
|
cache/ persisted caches, fingerprints, unified pages graph
|
|
50
51
|
browser/ client runtime rewrites, JSX ownership, Lit worker guard
|
|
@@ -60,7 +61,9 @@ build/
|
|
|
60
61
|
- `rolldown/rolldown-plugin-bridge.ts`: `EcoBuildPlugin[]` → bundler-plugin translation.
|
|
61
62
|
- `runtime/serialized-build-executor.ts`: FIFO queue primitive.
|
|
62
63
|
- `cache/server-entry-build-cache.ts`: production server-entry bundle cache (`.eco/.server-entry/.build-cache.json` + `dist/.server/manifest.json`).
|
|
64
|
+
- `server-bundle-publication.ts`: stages the server entry, emitted config, and deploy manifest together, then publishes the complete directory with rollback.
|
|
63
65
|
- `cache/cache-constants.ts`: shared `.build-cache.json` filename for persisted production caches.
|
|
66
|
+
- `cache/output-imports.ts`: lists the local files reachable from a compiled module, including shared chunks, so a cached module is reused only while they exist.
|
|
64
67
|
- `*.test.ts`: regression coverage colocated with each module.
|
|
65
68
|
|
|
66
69
|
## Default Flow
|
|
@@ -137,13 +140,9 @@ App-manifest plugins keep canonical registration order and cannot be silently re
|
|
|
137
140
|
|
|
138
141
|
## BuildOptions Caveats
|
|
139
142
|
|
|
140
|
-
`BuildOptions` is modeled on the bundler's options shape. Most fields map cleanly. The
|
|
143
|
+
`BuildOptions` is modeled on the bundler's options shape. Most fields map cleanly. The exception:
|
|
141
144
|
|
|
142
145
|
- `splitting` — when `false` with a single entrypoint, maps to Rolldown `codeSplitting: false` so dynamic imports stay in one file. Multi-entrypoint builds ignore `splitting: false` because Rolldown cannot inline across multiple inputs.
|
|
143
|
-
- `bundle` — accepted but ignored. The bundler always bundles.
|
|
144
|
-
- `outbase` — accepted but ignored. The adapter derives the base from `options.root` directly.
|
|
145
|
-
|
|
146
|
-
These fields are kept in the type so existing call-sites compile. The proper fix is a more focused `BuildOptions` schema in a follow-up.
|
|
147
146
|
|
|
148
147
|
## Dev / watch path
|
|
149
148
|
|
|
@@ -176,6 +175,8 @@ Two persisted cache layers accelerate production builds. Both use `.build-cache.
|
|
|
176
175
|
|
|
177
176
|
`requireBuildRuntime(appConfig).getProfile('server-entry')` serves server-entry bundling. `clearProductionBuildCaches()` wipes both manifest trees, resets in-memory route-module state, and clears `buildRuntime`.
|
|
178
177
|
|
|
178
|
+
Server-entry cache hits require every recorded runtime artifact. Cache misses build the server entry and emitted config in a sibling staging directory; the deploy manifest joins that generation before the directory is published. A failed build therefore leaves the previous server generation intact.
|
|
179
|
+
|
|
179
180
|
The route-module registry (`route-module-build-cache-registry.ts`) shares one `RouteModuleBuildCache` per `(app, outdir)` pair. Legacy `.server-route-modules` outdirs are still read for migration but new writes go to `.server-modules`.
|
|
180
181
|
|
|
181
182
|
## Unified pages graph
|
|
@@ -187,7 +188,9 @@ Production static exports compile all template pages in one Rolldown invocation
|
|
|
187
188
|
| Graph manifest | `.eco/.server-pages-graph/.build-cache.json` |
|
|
188
189
|
| Chunk outputs | `.eco/.server-modules/` (shared with per-route cache) |
|
|
189
190
|
|
|
190
|
-
`StaticSiteGenerator` calls `ensurePagesUnifiedGraphBuilt()` before the export loop. `PageModuleImportService` imports prebuilt chunks via `importPagesUnifiedGraphModule()` and falls back to per-page Rolldown on miss.
|
|
191
|
+
`StaticSiteGenerator` calls `ensurePagesUnifiedGraphBuilt()` before the export loop. `PageModuleImportService` imports prebuilt chunks via `importPagesUnifiedGraphModule()` and falls back to per-page Rolldown on miss.
|
|
192
|
+
|
|
193
|
+
A persisted graph is reused only when it matches the core package version, the build inputs and the build key, and every local file reachable from its outputs still exists. `importPagesUnifiedGraphModule()` applies the same check, because pages can be imported before the export loop runs. This is separate from production Page Browser Graph prebuild (`production-page-browser-graph-prebuild.ts`), which warms browser assets in `page-browser-graph-session`.
|
|
191
194
|
|
|
192
195
|
`ECOPAGES_ROLLDOWN_BUILD_METRICS=1` enables `rolldown/rolldown-build-invocation-metrics.ts` counters used by bench and parity tests.
|
|
193
196
|
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
/** Filename written beside persisted production build artifacts that store incremental metadata. */
|
|
2
2
|
export declare const ROUTE_MODULE_BUILD_CACHE_FILENAME = ".build-cache.json";
|
|
3
|
-
/** @deprecated Use {@link ROUTE_MODULE_BUILD_CACHE_FILENAME}; server-entry caches share the same filename. */
|
|
4
|
-
export declare const SERVER_ENTRY_BUILD_CACHE_FILENAME = ".build-cache.json";
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
/** Filename written beside persisted production build artifacts that store incremental metadata. */
|
|
2
2
|
export const ROUTE_MODULE_BUILD_CACHE_FILENAME = '.build-cache.json';
|
|
3
|
-
/** @deprecated Use {@link ROUTE_MODULE_BUILD_CACHE_FILENAME}; server-entry caches share the same filename. */
|
|
4
|
-
export const SERVER_ENTRY_BUILD_CACHE_FILENAME = ROUTE_MODULE_BUILD_CACHE_FILENAME;
|
|
@@ -18,5 +18,3 @@ export declare function createSourceTransformCacheKey(sourceTransforms: BuildOpt
|
|
|
18
18
|
* agree within one install; not stable across minifiers or renames.
|
|
19
19
|
*/
|
|
20
20
|
export declare function hashFunctionIdentity(fn: (...args: never[]) => unknown): string;
|
|
21
|
-
/** @deprecated Use {@link hashFunctionIdentity}. */
|
|
22
|
-
export declare const hashPluginSetup: typeof hashFunctionIdentity;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lists the local files a compiled module imports: relative, absolute and
|
|
3
|
+
* `file:` specifiers in static imports, re-exports and literal dynamic imports.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Persisted build caches record these so a cached module is reused only while
|
|
7
|
+
* the shared chunks and generated modules it loads (for example
|
|
8
|
+
* `.server-collections`) still exist. Uses `parseSync` directly rather than the
|
|
9
|
+
* shared parse cache, so large compiled bundles are not retained in memory.
|
|
10
|
+
*/
|
|
11
|
+
export declare function collectLocalImports(code: string, modulePath: string): string[];
|
|
12
|
+
export type LocalImportFileAccess = {
|
|
13
|
+
exists: (filePath: string) => boolean;
|
|
14
|
+
readFile: (filePath: string) => string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Lists every local file reachable from `modulePath` through local imports.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Direct {@link collectLocalImports} misses shared chunks that a page output
|
|
21
|
+
* only reaches through another chunk. Persisted caches walk this graph so reuse
|
|
22
|
+
* fails when any reachable file is gone. `modulePath` itself is omitted; callers
|
|
23
|
+
* already check that the compiled output exists.
|
|
24
|
+
*/
|
|
25
|
+
export declare function collectReachableLocalImports(modulePath: string, fileAccess?: LocalImportFileAccess): string[];
|
|
26
|
+
/** Reads a compiled module from disk and lists its local imports. */
|
|
27
|
+
export declare function readLocalImports(modulePath: string): string[];
|