@ecopages/core 0.2.0-rc.10 → 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 +0 -9
- package/package.json +3 -144
- package/src/adapters/README.md +8 -2
- package/src/adapters/abstract/application-adapter.d.ts +6 -32
- package/src/adapters/abstract/application-adapter.js +6 -45
- 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 +8 -12
- package/src/adapters/bun/create-app.js +13 -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 +9 -19
- package/src/adapters/bun/server-adapter.js +19 -66
- 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 +1 -1
- package/src/adapters/create-app.js +2 -1
- package/src/adapters/node/create-app.d.ts +4 -8
- package/src/adapters/node/create-app.js +7 -12
- package/src/adapters/node/runtime-host.d.ts +10 -10
- package/src/adapters/node/runtime-host.js +4 -4
- 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 +25 -31
- package/src/adapters/node/server-adapter.js +43 -64
- 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/fs-server-response-factory.d.ts +0 -1
- package/src/adapters/shared/http/fs-server-response-factory.js +0 -3
- 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/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 +13 -0
- package/src/adapters/shared/runtime/server-adapter.js +22 -0
- 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 +5 -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 +1 -2
- package/src/build/cache/server-entry-build-cache.js +4 -5
- 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/deduping-build-executor.d.ts +0 -1
- package/src/build/runtime/deduping-build-executor.js +0 -1
- 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 +3 -3
- package/src/config/apply-user-config.d.ts +3 -1
- package/src/config/apply-user-config.js +3 -2
- package/src/config/config-builder.d.ts +1 -0
- package/src/config/config-builder.js +2 -2
- package/src/config/constants.d.ts +0 -4
- package/src/config/constants.js +0 -4
- package/src/config/index.d.ts +1 -1
- package/src/config/index.js +1 -1
- package/src/config/load-eco-config.d.ts +1 -1
- package/src/config/load-eco-config.js +18 -11
- package/src/config/resolve-eco-config-path.d.ts +9 -0
- package/src/config/resolve-eco-config-path.js +11 -0
- package/src/config/server-config-bundle.js +2 -2
- package/src/config/user-config-types.d.ts +9 -3
- 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/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/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -4
- package/src/route-renderer/orchestration/integration-renderer.d.ts +0 -6
- package/src/route-renderer/orchestration/integration-renderer.js +1 -11
- 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/services/README.md +1 -1
- package/src/services/assets/browser-bundle.service.d.ts +1 -6
- package/src/services/error-pages/default-error-pages.d.ts +1 -6
- package/src/services/error-pages/default-error-pages.js +0 -8
- 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 +2 -19
- package/src/services/invalidation/development-invalidation.service.js +1 -39
- package/src/services/module-loading/README.md +1 -1
- 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 +0 -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 +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/server-module-transpiler.service.d.ts +1 -15
- package/src/services/module-loading/server-module-transpiler.service.js +0 -24
- 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/types/internal-types.d.ts +0 -38
- package/src/types/public-types.d.ts +0 -112
- package/src/watchers/project-watcher.d.ts +0 -15
- package/src/watchers/project-watcher.js +1 -27
- 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
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { appLogger } from '../../global/app-logger.js';
|
|
11
11
|
import { SharedApplicationAdapter } from '../shared/runtime/application-adapter.js';
|
|
12
|
-
import { resolveRuntimeBinding
|
|
12
|
+
import { resolveRuntimeBinding } from '../shared/runtime/runtime-app-bootstrap.js';
|
|
13
13
|
import { bindRuntimeServer } from '../shared/runtime/bind-runtime-server.js';
|
|
14
14
|
import { startupTrace } from '../../diagnostics/startup-trace.js';
|
|
15
15
|
import { createBunServerAdapter } from './server-adapter.js';
|
|
@@ -43,16 +43,6 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
|
|
|
43
43
|
}
|
|
44
44
|
this.serverAdapter.attachUserWebSocketUpgrades(httpServer, options);
|
|
45
45
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Complete the initialization of the server adapter by processing dynamic routes
|
|
48
|
-
* @param server The Bun server instance
|
|
49
|
-
*/
|
|
50
|
-
async completeInitialization(server) {
|
|
51
|
-
if (!this.serverAdapter) {
|
|
52
|
-
throw new Error('Server adapter not initialized. Call start() first.');
|
|
53
|
-
}
|
|
54
|
-
await this.serverAdapter.completeInitialization(server);
|
|
55
|
-
}
|
|
56
46
|
/**
|
|
57
47
|
* Initialize the Bun server adapter
|
|
58
48
|
*/
|
|
@@ -72,10 +62,7 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
|
|
|
72
62
|
options: { watch: binding.watch },
|
|
73
63
|
serveOptions: binding.serveOptions,
|
|
74
64
|
hostOwnsDevClient: hostOwnsDevClient(this.runtimeOptions),
|
|
75
|
-
deferRuntimeAssetSetup:
|
|
76
|
-
appConfig: this.appConfig,
|
|
77
|
-
cliArgs: this.cliArgs,
|
|
78
|
-
}).canBuildWithoutRuntimeServer,
|
|
65
|
+
deferRuntimeAssetSetup: this.cliArgs.build || this.cliArgs.preview,
|
|
79
66
|
allowPortFallback: binding.allowPortFallback,
|
|
80
67
|
onDevelopmentRestart: this.createDevelopmentRestartHandler(),
|
|
81
68
|
});
|
|
@@ -107,53 +94,33 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
|
|
|
107
94
|
process.exit(0);
|
|
108
95
|
}
|
|
109
96
|
}
|
|
110
|
-
async runStaticBuildOnRuntimeServer(serverAdapter, preview, build, force) {
|
|
111
|
-
appLogger.debugTime('Building static pages');
|
|
112
|
-
const previewOrigin = await serverAdapter.buildStatic({ preview, force });
|
|
113
|
-
const buildRuntimeServer = this.server;
|
|
114
|
-
this.server = null;
|
|
115
|
-
if (buildRuntimeServer) {
|
|
116
|
-
await this.runtimeHost.stop(buildRuntimeServer, { force: true });
|
|
117
|
-
}
|
|
118
|
-
appLogger.debugTimeEnd('Building static pages');
|
|
119
|
-
if (build) {
|
|
120
|
-
process.exit(0);
|
|
121
|
-
}
|
|
122
|
-
return previewOrigin;
|
|
123
|
-
}
|
|
124
97
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
98
|
+
* Starts the Bun application server, or runs the preview/build flow when the
|
|
99
|
+
* CLI requested one.
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* HMR endpoints and Bun's `development` serve mode follow the `dev` flag only,
|
|
103
|
+
* matching the options `completeInitialization()` reloads the server with.
|
|
128
104
|
*/
|
|
129
105
|
async bootServer() {
|
|
130
106
|
const serverAdapter = await this.ensureServerAdapterReady();
|
|
131
107
|
const { dev, preview, build, force, serveOnly } = this.cliArgs;
|
|
132
|
-
const staticRuntimeMode = resolveStaticRuntimeMode({
|
|
133
|
-
appConfig: this.appConfig,
|
|
134
|
-
cliArgs: this.cliArgs,
|
|
135
|
-
});
|
|
136
108
|
if (preview && serveOnly) {
|
|
137
109
|
await this.bootPreviewServeOnly(serverAdapter);
|
|
138
110
|
return;
|
|
139
111
|
}
|
|
140
|
-
if (
|
|
112
|
+
if (build || preview) {
|
|
141
113
|
await this.bootStaticWithoutRuntimeServer(serverAdapter, preview, build, force);
|
|
142
114
|
return;
|
|
143
115
|
}
|
|
144
|
-
const
|
|
145
|
-
const runtimeServerOptions = serverAdapter.getServerOptions({ enableHmr });
|
|
116
|
+
const runtimeServerOptions = serverAdapter.getServerOptions({ enableHmr: dev });
|
|
146
117
|
const binding = resolveRuntimeBinding({
|
|
147
118
|
cliArgs: this.cliArgs,
|
|
148
119
|
serverOptions: this.serverOptions,
|
|
149
120
|
});
|
|
150
121
|
startupTrace.beginServerListen();
|
|
151
122
|
const bindingResult = await bindRuntimeServer(this.runtimeHost, {
|
|
152
|
-
startOptions: {
|
|
153
|
-
serveOptions: runtimeServerOptions,
|
|
154
|
-
handleRequest: async () => new Response(null, { status: 500 }),
|
|
155
|
-
onError: async () => { },
|
|
156
|
-
},
|
|
123
|
+
startOptions: { serveOptions: runtimeServerOptions },
|
|
157
124
|
allowPortFallback: binding.allowPortFallback,
|
|
158
125
|
usePortManager: dev,
|
|
159
126
|
});
|
|
@@ -165,17 +132,8 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
|
|
|
165
132
|
if (!this.server) {
|
|
166
133
|
throw new Error('Server failed to start');
|
|
167
134
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
previewOrigin = await this.runStaticBuildOnRuntimeServer(serverAdapter, preview, build, force);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
await this.notifyListening(bindingResult.runtimeOrigin);
|
|
174
|
-
}
|
|
175
|
-
if (preview && previewOrigin) {
|
|
176
|
-
await this.notifyListening(previewOrigin);
|
|
177
|
-
}
|
|
178
|
-
return this.server ?? undefined;
|
|
135
|
+
await this.notifyListening(bindingResult.runtimeOrigin);
|
|
136
|
+
return this.server;
|
|
179
137
|
}
|
|
180
138
|
async stop(force = true) {
|
|
181
139
|
if (this.stopped) {
|
|
@@ -10,7 +10,6 @@ import { SharedHmrManager } from '../shared/hmr/shared-hmr-manager.js';
|
|
|
10
10
|
* own explicit registration path.
|
|
11
11
|
*/
|
|
12
12
|
export class HmrManager extends SharedHmrManager {
|
|
13
|
-
wsHandler;
|
|
14
13
|
/**
|
|
15
14
|
* Creates the Bun HMR manager around the shared HMR orchestration pipeline.
|
|
16
15
|
*
|
|
@@ -51,10 +50,9 @@ export class HmrManager extends SharedHmrManager {
|
|
|
51
50
|
bridge.unsubscribe(ws);
|
|
52
51
|
appLogger.debug(`[HmrManager] Connection closed. Subscribers: ${bridge.subscriberCount}`);
|
|
53
52
|
};
|
|
54
|
-
this.wsHandler = { open, close };
|
|
55
53
|
return {
|
|
56
|
-
open
|
|
57
|
-
close
|
|
54
|
+
open,
|
|
55
|
+
close,
|
|
58
56
|
message: (_ws, message) => {
|
|
59
57
|
appLogger.debug('[HMR] Received message from client:', message);
|
|
60
58
|
},
|
|
@@ -5,6 +5,7 @@ import type { ApiHandler, ErrorHandler, StaticRoute, ErrorPageLoaders, EcopagesW
|
|
|
5
5
|
import { SharedServerAdapter } from '../shared/runtime/server-adapter.js';
|
|
6
6
|
import type { ServerAdapterResult } from '../abstract/server-adapter.js';
|
|
7
7
|
import type { StaticPreviewHost } from '../shared/runtime/static-preview-host.js';
|
|
8
|
+
import { type WebSocketUpgradeOptions } from '../shared/ws/node-http-websocket-upgrades.js';
|
|
8
9
|
import { ClientBridge } from './client-bridge.js';
|
|
9
10
|
import { HmrManager } from './hmr-manager.js';
|
|
10
11
|
type BunServerInstance = Server<unknown>;
|
|
@@ -57,9 +58,7 @@ export interface BunServerAdapterResult extends ServerAdapterResult {
|
|
|
57
58
|
servePreviewOnly: () => Promise<string | undefined>;
|
|
58
59
|
completeInitialization: (server?: BunServerInstance | null) => Promise<void>;
|
|
59
60
|
handleRequest: (request: Request) => Promise<Response>;
|
|
60
|
-
attachUserWebSocketUpgrades: (server: NodeHttpServer, options?:
|
|
61
|
-
passthroughUnmatched?: boolean;
|
|
62
|
-
}) => void;
|
|
61
|
+
attachUserWebSocketUpgrades: (server: NodeHttpServer, options?: WebSocketUpgradeOptions) => void;
|
|
63
62
|
dispose: () => Promise<void>;
|
|
64
63
|
}
|
|
65
64
|
/**
|
|
@@ -136,9 +135,7 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
|
|
|
136
135
|
/**
|
|
137
136
|
* Wires user WebSocket routes onto a Node HTTP server used by host integrations.
|
|
138
137
|
*/
|
|
139
|
-
attachUserWebSocketUpgrades(server: NodeHttpServer, options?:
|
|
140
|
-
passthroughUnmatched?: boolean;
|
|
141
|
-
}): void;
|
|
138
|
+
attachUserWebSocketUpgrades(server: NodeHttpServer, options?: WebSocketUpgradeOptions): void;
|
|
142
139
|
/**
|
|
143
140
|
* Initializes the server adapter's core runtime components.
|
|
144
141
|
*/
|
|
@@ -193,9 +190,9 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
|
|
|
193
190
|
* Composes the base Bun server settings that all runtime modes build from.
|
|
194
191
|
*
|
|
195
192
|
* @remarks
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
193
|
+
* The `app.onError` boundary lives in {@link handleRequest}. Bun's `error`
|
|
194
|
+
* hook only fires if that boundary itself throws, so it answers with a plain
|
|
195
|
+
* 500 rather than rendering anything that could fail again.
|
|
199
196
|
*/
|
|
200
197
|
private buildServerSettings;
|
|
201
198
|
/**
|
|
@@ -245,8 +242,9 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
|
|
|
245
242
|
*
|
|
246
243
|
* @remarks
|
|
247
244
|
* HMR HTML injection for API and page responses is owned by
|
|
248
|
-
* `SharedServerAdapter.handleSharedRequest`. This method
|
|
249
|
-
* request into the shared pipeline
|
|
245
|
+
* `SharedServerAdapter.handleSharedRequest`. This method waits for
|
|
246
|
+
* initialization, maps the request into the shared pipeline, and sends any
|
|
247
|
+
* escaped error through the shared `app.onError` boundary.
|
|
250
248
|
*/
|
|
251
249
|
handleRequest(request: Request): Promise<Response>;
|
|
252
250
|
/**
|
|
@@ -254,14 +252,6 @@ export declare class BunServerAdapter extends SharedServerAdapter<BunServerAdapt
|
|
|
254
252
|
* Prevents race conditions during startup.
|
|
255
253
|
*/
|
|
256
254
|
private waitForInitialization;
|
|
257
|
-
/**
|
|
258
|
-
* Handles HTTP requests from the router adapter.
|
|
259
|
-
*/
|
|
260
|
-
handleResponse(request: Request): Promise<Response>;
|
|
261
|
-
/**
|
|
262
|
-
* Handles requests that do not match any routes.
|
|
263
|
-
*/
|
|
264
|
-
private handleNoMatch;
|
|
265
255
|
}
|
|
266
256
|
/**
|
|
267
257
|
* Creates the Bun server adapter and fills in the runtime-specific collaborators
|
|
@@ -2,8 +2,6 @@ import path from 'node:path';
|
|
|
2
2
|
import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from '../../config/constants.js';
|
|
3
3
|
import { appLogger } from '../../global/app-logger.js';
|
|
4
4
|
import { entryWatcherOwnsConfig } from '../../dev/development-restart.js';
|
|
5
|
-
import { HttpError } from '../../errors/http-error.js';
|
|
6
|
-
import { createRequire } from '../../utils/locals-utils.js';
|
|
7
5
|
import { findWebSocketRoute } from '../abstract/ws-pattern-matcher.js';
|
|
8
6
|
import { fileSystem } from '@ecopages/file-system';
|
|
9
7
|
import { setupAppRuntimePlugins } from '../../build/build-adapter.js';
|
|
@@ -11,9 +9,8 @@ import { installBuildRuntime } from '../../build/runtime/build-runtime.js';
|
|
|
11
9
|
import { StaticSiteGenerator } from '../../static-site-generator/static-site-generator.js';
|
|
12
10
|
import { ProjectWatcher } from '../../watchers/project-watcher.js';
|
|
13
11
|
import { SharedServerAdapter } from '../shared/runtime/server-adapter.js';
|
|
14
|
-
import { ApiResponseBuilder } from '../shared/http/api-response.js';
|
|
15
12
|
import { ServerStaticBuilder } from '../shared/runtime/server-static-builder.js';
|
|
16
|
-
import { attachNodeHttpWebSocketUpgrades } from '../shared/ws/node-http-websocket-upgrades.js';
|
|
13
|
+
import { attachNodeHttpWebSocketUpgrades, } from '../shared/ws/node-http-websocket-upgrades.js';
|
|
17
14
|
import { createBunUserWebSocketLifecycle } from './bun-user-websocket-lifecycle.js';
|
|
18
15
|
import { createEcopagesSocket } from '../shared/ws/websocket-lifecycle.js';
|
|
19
16
|
import { resolveServeRuntimeOrigin } from '../shared/runtime/runtime-app-bootstrap.js';
|
|
@@ -328,59 +325,22 @@ export class BunServerAdapter extends SharedServerAdapter {
|
|
|
328
325
|
* Composes the base Bun server settings that all runtime modes build from.
|
|
329
326
|
*
|
|
330
327
|
* @remarks
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
328
|
+
* The `app.onError` boundary lives in {@link handleRequest}. Bun's `error`
|
|
329
|
+
* hook only fires if that boundary itself throws, so it answers with a plain
|
|
330
|
+
* 500 rather than rendering anything that could fail again.
|
|
334
331
|
*/
|
|
335
332
|
buildServerSettings() {
|
|
336
333
|
const serverOptions = { ...this.serveOptions };
|
|
337
|
-
const handleNoMatch = this.handleNoMatch.bind(this);
|
|
338
|
-
const waitForInit = this.waitForInitialization.bind(this);
|
|
339
334
|
const handleReq = this.handleRequest.bind(this);
|
|
340
|
-
const errorHandler = this.errorHandler;
|
|
341
|
-
const getCacheService = () => this.getCacheService();
|
|
342
|
-
const getRenderContext = () => this.getRenderContext();
|
|
343
335
|
appLogger.debug(`[BunServerAdapter] Building server settings`);
|
|
344
336
|
const finalOptions = {
|
|
345
337
|
...serverOptions,
|
|
346
|
-
async fetch(request
|
|
347
|
-
|
|
348
|
-
await waitForInit();
|
|
349
|
-
return await handleReq(request);
|
|
350
|
-
}
|
|
351
|
-
catch (error) {
|
|
352
|
-
if (error instanceof Response)
|
|
353
|
-
return error;
|
|
354
|
-
if (errorHandler) {
|
|
355
|
-
try {
|
|
356
|
-
const locals = {};
|
|
357
|
-
const context = {
|
|
358
|
-
request,
|
|
359
|
-
params: {},
|
|
360
|
-
response: new ApiResponseBuilder(),
|
|
361
|
-
server: _server,
|
|
362
|
-
locals,
|
|
363
|
-
require: createRequire(() => locals),
|
|
364
|
-
services: {
|
|
365
|
-
cache: getCacheService(),
|
|
366
|
-
},
|
|
367
|
-
...getRenderContext(),
|
|
368
|
-
};
|
|
369
|
-
return await errorHandler(error, context);
|
|
370
|
-
}
|
|
371
|
-
catch (handlerError) {
|
|
372
|
-
appLogger.error(`[ecopages] Error in custom error handler: ${handlerError}`);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
if (error instanceof HttpError)
|
|
376
|
-
return error.toResponse();
|
|
377
|
-
appLogger.error(`[ecopages] Error handling request: ${error}`);
|
|
378
|
-
return new Response('Internal Server Error', { status: 500 });
|
|
379
|
-
}
|
|
338
|
+
async fetch(request) {
|
|
339
|
+
return await handleReq(request);
|
|
380
340
|
},
|
|
381
341
|
error(error) {
|
|
382
342
|
appLogger.error(`[ecopages] Error handling request: ${error}`);
|
|
383
|
-
return
|
|
343
|
+
return new Response('Internal Server Error', { status: 500 });
|
|
384
344
|
},
|
|
385
345
|
};
|
|
386
346
|
return finalOptions;
|
|
@@ -535,17 +495,24 @@ export class BunServerAdapter extends SharedServerAdapter {
|
|
|
535
495
|
*
|
|
536
496
|
* @remarks
|
|
537
497
|
* HMR HTML injection for API and page responses is owned by
|
|
538
|
-
* `SharedServerAdapter.handleSharedRequest`. This method
|
|
539
|
-
* request into the shared pipeline
|
|
498
|
+
* `SharedServerAdapter.handleSharedRequest`. This method waits for
|
|
499
|
+
* initialization, maps the request into the shared pipeline, and sends any
|
|
500
|
+
* escaped error through the shared `app.onError` boundary.
|
|
540
501
|
*/
|
|
541
502
|
async handleRequest(request) {
|
|
542
|
-
const
|
|
503
|
+
const context = {
|
|
543
504
|
apiHandlers: this.apiHandlers,
|
|
544
505
|
errorHandler: this.errorHandler,
|
|
545
506
|
serverInstance: this.serverInstance,
|
|
546
507
|
hmrManager: this.hmrManager,
|
|
547
|
-
}
|
|
548
|
-
|
|
508
|
+
};
|
|
509
|
+
try {
|
|
510
|
+
await this.waitForInitialization();
|
|
511
|
+
return await this.handleSharedRequest(request, context);
|
|
512
|
+
}
|
|
513
|
+
catch (error) {
|
|
514
|
+
return await this.handleUnexpectedRequestError(error, request, context);
|
|
515
|
+
}
|
|
549
516
|
}
|
|
550
517
|
/**
|
|
551
518
|
* Ensures server initialization completes before request handling.
|
|
@@ -560,20 +527,6 @@ export class BunServerAdapter extends SharedServerAdapter {
|
|
|
560
527
|
}
|
|
561
528
|
throw new Error('Server not initialized. Call completeInitialization() first.');
|
|
562
529
|
}
|
|
563
|
-
/**
|
|
564
|
-
* Handles HTTP requests from the router adapter.
|
|
565
|
-
*/
|
|
566
|
-
async handleResponse(request) {
|
|
567
|
-
await this.waitForInitialization();
|
|
568
|
-
return this.routeHandler.handleResponse(request);
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Handles requests that do not match any routes.
|
|
572
|
-
*/
|
|
573
|
-
async handleNoMatch(request) {
|
|
574
|
-
await this.waitForInitialization();
|
|
575
|
-
return this.routeHandler.handleNoMatch(request);
|
|
576
|
-
}
|
|
577
530
|
}
|
|
578
531
|
/**
|
|
579
532
|
* Creates the Bun server adapter and fills in the runtime-specific collaborators
|
|
@@ -16,7 +16,7 @@ export class BunStaticPreviewHost {
|
|
|
16
16
|
startOnPort: async (port) => {
|
|
17
17
|
const candidate = this.previewServerFactory.createServer({
|
|
18
18
|
appConfig: options.appConfig,
|
|
19
|
-
options: { port },
|
|
19
|
+
options: { port, hostname: options.hostname },
|
|
20
20
|
});
|
|
21
21
|
const boundPort = candidate.server?.port ?? null;
|
|
22
22
|
if (!boundPort) {
|
|
@@ -2,7 +2,7 @@ import type { EcoPagesUserConfig } from '../config/user-config-types.js';
|
|
|
2
2
|
import type { EcoPagesAppConfig } from '../types/internal-types.js';
|
|
3
3
|
import { AbstractApplicationAdapter } from './abstract/application-adapter.js';
|
|
4
4
|
import type { ApplicationAdapterOptions } from './abstract/application-adapter.js';
|
|
5
|
-
export type { OnAppStartCallback, AppStartInfo
|
|
5
|
+
export type { OnAppStartCallback, AppStartInfo } from './abstract/application-adapter.js';
|
|
6
6
|
export type EcopagesRuntimeAdapter = 'auto' | 'node' | 'bun';
|
|
7
7
|
type EcopagesAppConfigSource = {
|
|
8
8
|
appConfig: EcoPagesAppConfig;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { finalizeEcoPagesConfig, loadEcoPagesConfig } from '../config/load-eco-config.js';
|
|
3
|
+
import { DEFAULT_ECO_CONFIG_FILENAME, resolveUserConfigRootDir } from '../config/resolve-eco-config-path.js';
|
|
3
4
|
import { AbstractApplicationAdapter } from './abstract/application-adapter.js';
|
|
4
5
|
import { createApp as createBunApp } from './bun/create-app.js';
|
|
5
6
|
import { createNodeApp } from './node/create-app.js';
|
|
@@ -10,7 +11,7 @@ async function resolveAppConfig(options) {
|
|
|
10
11
|
if (options.userConfig) {
|
|
11
12
|
return await finalizeEcoPagesConfig({
|
|
12
13
|
config: options.userConfig,
|
|
13
|
-
configFilePath: path.join(
|
|
14
|
+
configFilePath: path.join(resolveUserConfigRootDir(options.userConfig.rootDir), DEFAULT_ECO_CONFIG_FILENAME),
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
return await loadEcoPagesConfig({ configFile: options.configFile });
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { SharedApplicationAdapter } from '../shared/runtime/application-adapter.js';
|
|
2
|
+
import type { WebSocketUpgradeOptions } from '../shared/ws/node-http-websocket-upgrades.js';
|
|
2
3
|
import type { RuntimeHost } from '../shared/runtime/runtime-host.js';
|
|
3
4
|
import type { ResolvedEcopagesAppOptions } from '../create-app.js';
|
|
4
5
|
import { type NodeServerAdapterResult, createNodeServerAdapter } from './server-adapter.js';
|
|
5
6
|
import type { NodeServerInstance } from './server-adapter.js';
|
|
7
|
+
import { type NodeRuntimeServeOptions } from './runtime-host.js';
|
|
6
8
|
export declare class NodeEcopagesApp extends SharedApplicationAdapter<ResolvedEcopagesAppOptions, NodeServerInstance, Request> {
|
|
7
9
|
serverAdapter: NodeServerAdapterResult | undefined;
|
|
8
10
|
private server;
|
|
@@ -10,10 +12,7 @@ export declare class NodeEcopagesApp extends SharedApplicationAdapter<ResolvedEc
|
|
|
10
12
|
private stopped;
|
|
11
13
|
private readonly runtimeHost;
|
|
12
14
|
constructor(options: ResolvedEcopagesAppOptions, dependencies: {
|
|
13
|
-
runtimeHost: RuntimeHost<NodeServerInstance,
|
|
14
|
-
port?: number;
|
|
15
|
-
hostname?: string;
|
|
16
|
-
}>;
|
|
15
|
+
runtimeHost: RuntimeHost<NodeServerInstance, NodeRuntimeServeOptions>;
|
|
17
16
|
});
|
|
18
17
|
protected createServerAdapter(params: Parameters<typeof createNodeServerAdapter>[0]): Promise<NodeServerAdapterResult>;
|
|
19
18
|
stop(force?: boolean): Promise<void>;
|
|
@@ -21,9 +20,6 @@ export declare class NodeEcopagesApp extends SharedApplicationAdapter<ResolvedEc
|
|
|
21
20
|
protected initializeServerAdapter(): Promise<NodeServerAdapterResult>;
|
|
22
21
|
protected bootServer(): Promise<NodeServerInstance | void>;
|
|
23
22
|
fetch(request: Request): Promise<Response>;
|
|
24
|
-
attachWebSocketUpgrades(httpServer: import('node:http').Server, options?:
|
|
25
|
-
passthroughUnmatched?: boolean;
|
|
26
|
-
}): Promise<void>;
|
|
23
|
+
attachWebSocketUpgrades(httpServer: import('node:http').Server, options?: WebSocketUpgradeOptions): Promise<void>;
|
|
27
24
|
}
|
|
28
25
|
export declare function createNodeApp(options: ResolvedEcopagesAppOptions): Promise<NodeEcopagesApp>;
|
|
29
|
-
export declare function createApp(options: ResolvedEcopagesAppOptions): Promise<NodeEcopagesApp>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appLogger } from '../../global/app-logger.js';
|
|
2
2
|
import { SharedApplicationAdapter } from '../shared/runtime/application-adapter.js';
|
|
3
|
-
import { resolveRuntimeBinding
|
|
3
|
+
import { resolveRuntimeBinding } from '../shared/runtime/runtime-app-bootstrap.js';
|
|
4
4
|
import { bindRuntimeServer } from '../shared/runtime/bind-runtime-server.js';
|
|
5
5
|
import { createNodeServerAdapter } from './server-adapter.js';
|
|
6
6
|
import { NodeHttpRequestBridge } from './http-request-bridge.js';
|
|
@@ -58,10 +58,7 @@ export class NodeEcopagesApp extends SharedApplicationAdapter {
|
|
|
58
58
|
options: { watch: binding.watch },
|
|
59
59
|
serveOptions: binding.serveOptions,
|
|
60
60
|
hostOwnsDevClient: hostOwnsDevClient(this.runtimeOptions),
|
|
61
|
-
deferRuntimeAssetSetup:
|
|
62
|
-
appConfig: this.appConfig,
|
|
63
|
-
cliArgs: this.cliArgs,
|
|
64
|
-
}).canBuildWithoutRuntimeServer,
|
|
61
|
+
deferRuntimeAssetSetup: this.cliArgs.build || this.cliArgs.preview,
|
|
65
62
|
allowPortFallback: binding.allowPortFallback,
|
|
66
63
|
onDevelopmentRestart: this.createDevelopmentRestartHandler(),
|
|
67
64
|
});
|
|
@@ -105,9 +102,10 @@ export class NodeEcopagesApp extends SharedApplicationAdapter {
|
|
|
105
102
|
startupTrace.beginServerListen();
|
|
106
103
|
const bindingResult = await bindRuntimeServer(this.runtimeHost, {
|
|
107
104
|
startOptions: {
|
|
108
|
-
serveOptions
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
serveOptions: {
|
|
106
|
+
...serveOptions,
|
|
107
|
+
handleRequest: async (request) => await this.serverAdapter.handleRequest(request),
|
|
108
|
+
},
|
|
111
109
|
},
|
|
112
110
|
allowPortFallback: binding.allowPortFallback,
|
|
113
111
|
usePortManager: this.cliArgs.dev,
|
|
@@ -131,7 +129,7 @@ export class NodeEcopagesApp extends SharedApplicationAdapter {
|
|
|
131
129
|
}
|
|
132
130
|
if (!this.server) {
|
|
133
131
|
this.server = httpServer;
|
|
134
|
-
await this.serverAdapter.completeInitialization(httpServer);
|
|
132
|
+
await this.serverAdapter.completeInitialization(httpServer, options);
|
|
135
133
|
return;
|
|
136
134
|
}
|
|
137
135
|
this.serverAdapter.attachUserWebSocketUpgrades(httpServer, options);
|
|
@@ -142,6 +140,3 @@ export async function createNodeApp(options) {
|
|
|
142
140
|
runtimeHost: new NodeRuntimeHost(new NodeHttpRequestBridge()),
|
|
143
141
|
});
|
|
144
142
|
}
|
|
145
|
-
export async function createApp(options) {
|
|
146
|
-
return createNodeApp(options);
|
|
147
|
-
}
|
|
@@ -2,6 +2,11 @@ import { createServer, type Server as NodeServerInstance } from 'node:http';
|
|
|
2
2
|
import type { RuntimeHost, RuntimeHostStartOptions } from '../shared/runtime/runtime-host.js';
|
|
3
3
|
import { NodeHttpRequestBridge } from './http-request-bridge.js';
|
|
4
4
|
type NodeServerFactory = typeof createServer;
|
|
5
|
+
export type NodeRuntimeServeOptions = {
|
|
6
|
+
port?: number;
|
|
7
|
+
hostname?: string;
|
|
8
|
+
handleRequest(request: Request): Promise<Response>;
|
|
9
|
+
};
|
|
5
10
|
/**
|
|
6
11
|
* Node runtime host that binds the shared Web-request pipeline onto a concrete
|
|
7
12
|
* Node HTTP server.
|
|
@@ -11,10 +16,7 @@ type NodeServerFactory = typeof createServer;
|
|
|
11
16
|
* requests through `NodeHttpRequestBridge`, and handling socket-level failures.
|
|
12
17
|
* Routing and rendering remain in the shared server adapter.
|
|
13
18
|
*/
|
|
14
|
-
export declare class NodeRuntimeHost implements RuntimeHost<NodeServerInstance, {
|
|
15
|
-
port?: number;
|
|
16
|
-
hostname?: string;
|
|
17
|
-
}> {
|
|
19
|
+
export declare class NodeRuntimeHost implements RuntimeHost<NodeServerInstance, NodeRuntimeServeOptions> {
|
|
18
20
|
private readonly requestBridge;
|
|
19
21
|
private readonly serverFactory;
|
|
20
22
|
/**
|
|
@@ -27,13 +29,11 @@ export declare class NodeRuntimeHost implements RuntimeHost<NodeServerInstance,
|
|
|
27
29
|
* request pipeline.
|
|
28
30
|
*
|
|
29
31
|
* @remarks
|
|
30
|
-
* Client disconnects are treated as normal aborts and
|
|
31
|
-
*
|
|
32
|
+
* Client disconnects are treated as normal aborts and are not logged. Other
|
|
33
|
+
* failures here (the response write, or an uninitialised adapter) are logged
|
|
34
|
+
* with their stack and answered with 500.
|
|
32
35
|
*/
|
|
33
|
-
start(options: RuntimeHostStartOptions<
|
|
34
|
-
port?: number;
|
|
35
|
-
hostname?: string;
|
|
36
|
-
}>): Promise<NodeServerInstance>;
|
|
36
|
+
start(options: RuntimeHostStartOptions<NodeRuntimeServeOptions>): Promise<NodeServerInstance>;
|
|
37
37
|
/**
|
|
38
38
|
* Stops the Node HTTP server and, by default, force-closes any remaining open
|
|
39
39
|
* connections.
|
|
@@ -28,8 +28,9 @@ export class NodeRuntimeHost {
|
|
|
28
28
|
* request pipeline.
|
|
29
29
|
*
|
|
30
30
|
* @remarks
|
|
31
|
-
* Client disconnects are treated as normal aborts and
|
|
32
|
-
*
|
|
31
|
+
* Client disconnects are treated as normal aborts and are not logged. Other
|
|
32
|
+
* failures here (the response write, or an uninitialised adapter) are logged
|
|
33
|
+
* with their stack and answered with 500.
|
|
33
34
|
*/
|
|
34
35
|
async start(options) {
|
|
35
36
|
const hostname = String(options.serveOptions.hostname ?? DEFAULT_ECOPAGES_HOSTNAME);
|
|
@@ -39,7 +40,7 @@ export class NodeRuntimeHost {
|
|
|
39
40
|
try {
|
|
40
41
|
const runtimeOrigin = this.getOrigin(server, options.serveOptions);
|
|
41
42
|
const webRequest = this.requestBridge.createWebRequest(req, runtimeOrigin);
|
|
42
|
-
const response = await options.handleRequest(webRequest);
|
|
43
|
+
const response = await options.serveOptions.handleRequest(webRequest);
|
|
43
44
|
await this.requestBridge.sendNodeResponse(res, response);
|
|
44
45
|
}
|
|
45
46
|
catch (error) {
|
|
@@ -49,7 +50,6 @@ export class NodeRuntimeHost {
|
|
|
49
50
|
appLogger.error('Node server adapter request failed', error);
|
|
50
51
|
res.statusCode = 500;
|
|
51
52
|
res.end('Internal Server Error');
|
|
52
|
-
await options.onError(error instanceof Error ? error : new Error(String(error)));
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
await new Promise((resolve, reject) => {
|
|
@@ -7,13 +7,5 @@ export interface NodeServerDevRuntime {
|
|
|
7
7
|
bridge: NodeClientBridge;
|
|
8
8
|
hmrManager: NodeHmrManager;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
appConfig: EcoPagesAppConfig;
|
|
13
|
-
}): NodeServerDevRuntime;
|
|
14
|
-
}
|
|
15
|
-
export declare class DefaultNodeServerDevRuntimeFactory implements NodeServerDevRuntimeFactory {
|
|
16
|
-
create(options: {
|
|
17
|
-
appConfig: EcoPagesAppConfig;
|
|
18
|
-
}): NodeServerDevRuntime;
|
|
19
|
-
}
|
|
10
|
+
/** Creates the dev WebSocket server, client bridge and HMR manager, and registers them for `appConfig`. */
|
|
11
|
+
export declare function createNodeServerDevRuntime(appConfig: EcoPagesAppConfig): NodeServerDevRuntime;
|
|
@@ -3,17 +3,12 @@ import { setAppDevClientBridge } from '../../dev/client-bridge-registry.js';
|
|
|
3
3
|
import { setAppHmrManager } from '../../dev/hmr-manager-registry.js';
|
|
4
4
|
import { NodeClientBridge } from './node-client-bridge.js';
|
|
5
5
|
import { NodeHmrManager } from './node-hmr-manager.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
websocketServer,
|
|
15
|
-
bridge,
|
|
16
|
-
hmrManager,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
6
|
+
/** Creates the dev WebSocket server, client bridge and HMR manager, and registers them for `appConfig`. */
|
|
7
|
+
export function createNodeServerDevRuntime(appConfig) {
|
|
8
|
+
const websocketServer = new WebSocketServer({ noServer: true });
|
|
9
|
+
const bridge = new NodeClientBridge();
|
|
10
|
+
const hmrManager = new NodeHmrManager({ appConfig, bridge });
|
|
11
|
+
setAppDevClientBridge(appConfig, bridge);
|
|
12
|
+
setAppHmrManager(appConfig, hmrManager);
|
|
13
|
+
return { websocketServer, bridge, hmrManager };
|
|
19
14
|
}
|