@ecopages/core 0.2.0-rc.8 → 0.2.0
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 +39 -38
- package/package.json +22 -152
- 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/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 +12 -16
- package/src/adapters/bun/create-app.js +25 -55
- 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 +26 -5
- package/src/adapters/shared/runtime/server-adapter.js +35 -8
- 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 +12 -8
- 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 +35 -0
- package/src/build/cache/output-imports.js +87 -0
- package/src/build/cache/pages-unified-graph-build.d.ts +15 -1
- package/src/build/cache/pages-unified-graph-build.js +73 -22
- 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/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/dev/README.md +4 -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/eco/eco.js +4 -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/index.browser.d.ts +1 -2
- package/src/index.browser.js +1 -2
- package/src/index.d.ts +5 -6
- package/src/index.js +5 -6
- package/src/islands/island-host.d.ts +0 -9
- package/src/islands/island-host.js +1 -13
- package/src/plugins/component-import-discovery.js +2 -2
- package/src/plugins/eco-component-meta-plugin.js +5 -5
- package/src/plugins/integration-plugin.d.ts +0 -1
- package/src/plugins/integration-plugin.js +0 -4
- package/src/plugins/processor.d.ts +6 -2
- package/src/route-renderer/README.md +4 -0
- 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 +2 -2
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +14 -2
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +12 -5
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +8 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +19 -0
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -4
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +25 -24
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +18 -20
- package/src/route-renderer/orchestration/integration-renderer.d.ts +24 -7
- package/src/route-renderer/orchestration/integration-renderer.js +44 -33
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +1 -1
- 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/route-renderer.d.ts +9 -0
- package/src/route-renderer/route-renderer.js +18 -0
- package/src/services/README.md +2 -1
- 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 +29 -42
- package/src/services/html/html-transformer.service.js +85 -157
- package/src/services/invalidation/development-invalidation.service.d.ts +9 -20
- package/src/services/invalidation/development-invalidation.service.js +26 -39
- package/src/services/module-loading/README.md +20 -15
- 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 +0 -1
- package/src/services/module-loading/collection-server-module-build.service.js +0 -3
- 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/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 +8 -0
- package/src/services/module-loading/route-module-build-cache.store.js +25 -7
- package/src/services/module-loading/route-module-build-manifest.d.ts +12 -1
- package/src/services/module-loading/route-module-build-manifest.js +7 -3
- 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/static-site-generator/README.md +12 -8
- package/src/static-site-generator/static-site-generator.d.ts +3 -2
- package/src/static-site-generator/static-site-generator.js +17 -3
- package/src/types/internal-types.d.ts +1 -38
- package/src/types/public-types.d.ts +28 -130
- package/src/watchers/project-watcher.d.ts +9 -16
- package/src/watchers/project-watcher.js +35 -28
- 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
|
@@ -39,7 +39,7 @@ export interface PortManagerOptions {
|
|
|
39
39
|
warn?: (message: string) => void;
|
|
40
40
|
/** Infers a free port to display in the prompt. Defaults to {@link isPortAvailable}. */
|
|
41
41
|
probePort?: (port: number) => Promise<boolean>;
|
|
42
|
-
/** Custom prompter. Defaults to a
|
|
42
|
+
/** Custom prompter. Defaults to a Clack confirm on interactive stdio. */
|
|
43
43
|
prompt?: PromptFunction;
|
|
44
44
|
/** Enables the prompt flow at all. Defaults to `process.stdin.isTTY && process.stdout.isTTY`. */
|
|
45
45
|
interactive?: boolean;
|
|
@@ -64,7 +64,7 @@ export interface BindPortOptions {
|
|
|
64
64
|
allowPortFallback: boolean;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* Owns
|
|
67
|
+
* Owns server-port assignment: probing, race-release retries, fallback, and
|
|
68
68
|
* an optional interactive auto-approve prompt.
|
|
69
69
|
*
|
|
70
70
|
* @remarks
|
|
@@ -83,7 +83,7 @@ export declare class PortManager {
|
|
|
83
83
|
private readonly releaseRaceDelayMs;
|
|
84
84
|
constructor(options: PortManagerOptions);
|
|
85
85
|
/**
|
|
86
|
-
* Binds
|
|
86
|
+
* Binds a server to the preferred port.
|
|
87
87
|
*
|
|
88
88
|
* @remarks
|
|
89
89
|
* When the preferred port is free, binds it directly — no prompt, no
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createServer as createNetServer } from 'node:net';
|
|
2
|
-
import {
|
|
2
|
+
import { createClackDefaultPrompt } from './port-manager-default-prompt.js';
|
|
3
3
|
/**
|
|
4
4
|
* Detects whether a thrown error indicates the requested port is already in
|
|
5
5
|
* use.
|
|
@@ -53,42 +53,12 @@ export function isPortAvailable(port, hostname = '127.0.0.1') {
|
|
|
53
53
|
tester.listen(port, hostname);
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const rl = createInterface({ input: stdin, output: undefined, terminal: false });
|
|
61
|
-
let settled = false;
|
|
62
|
-
const finish = (value) => {
|
|
63
|
-
if (settled) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
settled = true;
|
|
67
|
-
clearTimeout(timer);
|
|
68
|
-
rl.close();
|
|
69
|
-
stdout.write('\n');
|
|
70
|
-
resolve(value);
|
|
71
|
-
};
|
|
72
|
-
const timer = setTimeout(() => finish(true), timeoutMs);
|
|
73
|
-
rl.once('line', (line) => {
|
|
74
|
-
const answer = line.trim().toLowerCase();
|
|
75
|
-
if (answer === '' || answer === 'y' || answer === 'yes') {
|
|
76
|
-
finish(true);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
finish(false);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
rl.once('close', () => finish(true));
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
const PREVIEW_PORT_RELEASE_RACE_RETRIES = 2;
|
|
87
|
-
const PREVIEW_PORT_FALLBACK_ATTEMPTS = 20;
|
|
88
|
-
const PREVIEW_PORT_RELEASE_RACE_DELAY_MS = 100;
|
|
89
|
-
const PREVIEW_PORT_AUTO_APPROVE_MS = 10_000;
|
|
56
|
+
const PORT_RELEASE_RACE_RETRIES = 2;
|
|
57
|
+
const PORT_FALLBACK_ATTEMPTS = 20;
|
|
58
|
+
const PORT_RELEASE_RACE_DELAY_MS = 100;
|
|
59
|
+
const PORT_AUTO_APPROVE_MS = 10_000;
|
|
90
60
|
/**
|
|
91
|
-
* Owns
|
|
61
|
+
* Owns server-port assignment: probing, race-release retries, fallback, and
|
|
92
62
|
* an optional interactive auto-approve prompt.
|
|
93
63
|
*
|
|
94
64
|
* @remarks
|
|
@@ -109,10 +79,10 @@ export class PortManager {
|
|
|
109
79
|
this.startOnPort = options.startOnPort;
|
|
110
80
|
this.warn = options.warn;
|
|
111
81
|
this.probePort = options.probePort ?? isPortAvailable;
|
|
112
|
-
this.maxPortOffset = options.maxPortOffset ??
|
|
113
|
-
this.releaseRaceRetries = options.releaseRaceRetries ??
|
|
114
|
-
this.releaseRaceDelayMs = options.releaseRaceDelayMs ??
|
|
115
|
-
this.autoApproveMs = options.autoApproveMs ??
|
|
82
|
+
this.maxPortOffset = options.maxPortOffset ?? PORT_FALLBACK_ATTEMPTS - 1;
|
|
83
|
+
this.releaseRaceRetries = options.releaseRaceRetries ?? PORT_RELEASE_RACE_RETRIES;
|
|
84
|
+
this.releaseRaceDelayMs = options.releaseRaceDelayMs ?? PORT_RELEASE_RACE_DELAY_MS;
|
|
85
|
+
this.autoApproveMs = options.autoApproveMs ?? PORT_AUTO_APPROVE_MS;
|
|
116
86
|
this.interactive =
|
|
117
87
|
typeof options.interactive === 'boolean'
|
|
118
88
|
? options.interactive
|
|
@@ -121,14 +91,14 @@ export class PortManager {
|
|
|
121
91
|
this.prompt = options.prompt;
|
|
122
92
|
}
|
|
123
93
|
else if (this.interactive) {
|
|
124
|
-
this.prompt =
|
|
94
|
+
this.prompt = createClackDefaultPrompt();
|
|
125
95
|
}
|
|
126
96
|
else {
|
|
127
97
|
this.prompt = undefined;
|
|
128
98
|
}
|
|
129
99
|
}
|
|
130
100
|
/**
|
|
131
|
-
* Binds
|
|
101
|
+
* Binds a server to the preferred port.
|
|
132
102
|
*
|
|
133
103
|
* @remarks
|
|
134
104
|
* When the preferred port is free, binds it directly — no prompt, no
|
|
@@ -149,7 +119,6 @@ export class PortManager {
|
|
|
149
119
|
if (firstAttempt.status === 'factory-refused') {
|
|
150
120
|
return null;
|
|
151
121
|
}
|
|
152
|
-
// firstAttempt.status === 'port-in-use'
|
|
153
122
|
await this.shouldFallback(preferredPort, options.allowPortFallback, firstAttempt.error);
|
|
154
123
|
return await this.fallForward(preferredPort);
|
|
155
124
|
}
|
|
@@ -158,7 +127,7 @@ export class PortManager {
|
|
|
158
127
|
const nextFree = await this.findNextFreePort(preferredPort);
|
|
159
128
|
const nextFreeSuffix = typeof nextFree === 'number' ? ` (next free: ${nextFree})` : '';
|
|
160
129
|
const autoApproveHint = `auto-yes in ${Math.round(this.autoApproveMs / 1000)}s`;
|
|
161
|
-
const message = `
|
|
130
|
+
const message = `Port ${preferredPort} is already in use${nextFreeSuffix}. Bind to the next free port instead? (${autoApproveHint})`;
|
|
162
131
|
const accepted = await this.prompt(message, this.autoApproveMs);
|
|
163
132
|
if (!accepted) {
|
|
164
133
|
throw error;
|
|
@@ -174,7 +143,7 @@ export class PortManager {
|
|
|
174
143
|
const candidatePort = preferredPort + offset;
|
|
175
144
|
const attempt = await this.tryPort(candidatePort);
|
|
176
145
|
if (attempt.status === 'bound') {
|
|
177
|
-
this.warn?.(`Port ${preferredPort} is in use;
|
|
146
|
+
this.warn?.(`Port ${preferredPort} is in use; serving on port ${attempt.boundPort} instead. Pin the port with --port or ECOPAGES_PORT when a fixed binding is required.`);
|
|
178
147
|
return attempt.boundPort;
|
|
179
148
|
}
|
|
180
149
|
}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import type { ReturnParseCliArgs } from '../../../utils/parse-cli-args.js';
|
|
2
|
-
import type { EcoPagesAppConfig } from '../../../types/internal-types.js';
|
|
3
2
|
export type RuntimeBinding = {
|
|
4
|
-
preferredPort: number;
|
|
5
|
-
preferredHostname: string;
|
|
6
3
|
runtimeOrigin: string;
|
|
7
4
|
serveOptions: Record<string, unknown>;
|
|
8
5
|
watch: boolean;
|
|
9
6
|
/** Whether preview may bind to the next free port when the preferred port is busy. */
|
|
10
7
|
allowPortFallback: boolean;
|
|
11
8
|
};
|
|
12
|
-
export type StaticRuntimeMode = {
|
|
13
|
-
canBuildWithoutRuntimeServer: boolean;
|
|
14
|
-
};
|
|
15
9
|
export declare function resolveServeRuntimeOrigin(serveOptions: {
|
|
16
10
|
hostname?: string;
|
|
17
11
|
port?: number | string;
|
|
@@ -21,7 +15,3 @@ export declare function resolveRuntimeBinding(options: {
|
|
|
21
15
|
serverOptions?: Record<string, unknown>;
|
|
22
16
|
env?: NodeJS.ProcessEnv;
|
|
23
17
|
}): RuntimeBinding;
|
|
24
|
-
export declare function resolveStaticRuntimeMode(options: {
|
|
25
|
-
appConfig: EcoPagesAppConfig;
|
|
26
|
-
cliArgs: ReturnParseCliArgs;
|
|
27
|
-
}): StaticRuntimeMode;
|
|
@@ -16,8 +16,6 @@ export function resolveRuntimeBinding(options) {
|
|
|
16
16
|
const preferredPort = options.cliArgs.port ?? (env.ECOPAGES_PORT ? Number(env.ECOPAGES_PORT) : undefined) ?? DEFAULT_ECOPAGES_PORT;
|
|
17
17
|
const preferredHostname = options.cliArgs.hostname ?? env.ECOPAGES_HOSTNAME ?? DEFAULT_ECOPAGES_HOSTNAME;
|
|
18
18
|
return {
|
|
19
|
-
preferredPort,
|
|
20
|
-
preferredHostname,
|
|
21
19
|
allowPortFallback: !portExplicitlyConfigured,
|
|
22
20
|
runtimeOrigin: resolveServeRuntimeOrigin({
|
|
23
21
|
hostname: preferredHostname,
|
|
@@ -31,8 +29,3 @@ export function resolveRuntimeBinding(options) {
|
|
|
31
29
|
watch: options.cliArgs.dev,
|
|
32
30
|
};
|
|
33
31
|
}
|
|
34
|
-
export function resolveStaticRuntimeMode(options) {
|
|
35
|
-
return {
|
|
36
|
-
canBuildWithoutRuntimeServer: options.cliArgs.build || options.cliArgs.preview,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
@@ -5,8 +5,11 @@ export interface RuntimeHost<TServer, TServeOptions> {
|
|
|
5
5
|
}): Promise<void>;
|
|
6
6
|
getOrigin(server: TServer, fallbackServeOptions: TServeOptions): string;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* @remarks
|
|
10
|
+
* Request handling travels inside `serveOptions`, as Bun's `fetch` does, so each
|
|
11
|
+
* runtime host receives only the callbacks it actually calls.
|
|
12
|
+
*/
|
|
8
13
|
export interface RuntimeHostStartOptions<TServeOptions> {
|
|
9
14
|
serveOptions: TServeOptions;
|
|
10
|
-
handleRequest(request: Request): Promise<Response>;
|
|
11
|
-
onError(error: Error): Promise<void> | void;
|
|
12
15
|
}
|
|
@@ -28,7 +28,7 @@ export declare function startDevWarmup(options: {
|
|
|
28
28
|
* Releases shared dev resources in a consistent order across server adapters.
|
|
29
29
|
*
|
|
30
30
|
* @remarks
|
|
31
|
-
* Bun calls `
|
|
31
|
+
* Bun calls `ensureRuntimeReady()` during `initialize()` when watch is enabled; Node defers
|
|
32
32
|
* runtime creation to `completeInitialization()`. Transport-specific setup stays in
|
|
33
33
|
* each adapter — only shared teardown lives here.
|
|
34
34
|
*/
|
|
@@ -56,7 +56,7 @@ export function startDevWarmup(options) {
|
|
|
56
56
|
* Releases shared dev resources in a consistent order across server adapters.
|
|
57
57
|
*
|
|
58
58
|
* @remarks
|
|
59
|
-
* Bun calls `
|
|
59
|
+
* Bun calls `ensureRuntimeReady()` during `initialize()` when watch is enabled; Node defers
|
|
60
60
|
* runtime creation to `completeInitialization()`. Transport-specific setup stays in
|
|
61
61
|
* each adapter — only shared teardown lives here.
|
|
62
62
|
*/
|
|
@@ -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,11 +67,12 @@ 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;
|
|
69
77
|
private createSharedPageCacheServiceFromConfig;
|
|
70
78
|
private getOrCreateSharedPageCacheService;
|
|
@@ -74,6 +82,19 @@ export declare abstract class SharedServerAdapter<TOptions extends ServerAdapter
|
|
|
74
82
|
private tryHandleSharedHmrRequest;
|
|
75
83
|
private injectSharedHmrHtmlResponse;
|
|
76
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>;
|
|
77
98
|
/**
|
|
78
99
|
* Universally processes an incoming WinterCG Web standard Request.
|
|
79
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',
|
|
@@ -256,6 +262,27 @@ export class SharedServerAdapter extends AbstractServerAdapter {
|
|
|
256
262
|
async tryHandleSharedApiRequest(request, context) {
|
|
257
263
|
return await this.apiRequestPipeline.tryHandle(request, context.apiHandlers, context.serverInstance, context.errorHandler);
|
|
258
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
|
+
}
|
|
259
286
|
/**
|
|
260
287
|
* Universally processes an incoming WinterCG Web standard Request.
|
|
261
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)) {
|