@ecopages/core 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +3 -3
- package/src/adapters/node/create-app.d.ts +40 -11
- package/src/adapters/node/create-app.js +95 -69
- package/src/adapters/node/dev-session.js +0 -1
- package/src/adapters/node/http-request-bridge.d.ts +4 -0
- package/src/adapters/node/http-request-bridge.js +9 -1
- package/src/adapters/node/runtime-host.d.ts +28 -6
- package/src/adapters/node/runtime-host.js +35 -9
- package/src/adapters/node/server-adapter.d.ts +10 -35
- package/src/adapters/node/server-adapter.js +21 -58
- package/src/adapters/shared/hmr/hmr-manager.d.ts +21 -7
- package/src/adapters/shared/hmr/hmr-manager.js +58 -70
- package/src/adapters/shared/http/api-request-pipeline.d.ts +3 -12
- package/src/adapters/shared/http/api-request-pipeline.js +7 -7
- package/src/adapters/shared/http/dist-file-handler.d.ts +16 -0
- package/src/adapters/shared/http/dist-file-handler.js +172 -0
- package/src/adapters/shared/http/explicit-static-route-matcher.js +2 -1
- package/src/adapters/shared/http/fs-server-response-matcher.js +3 -2
- package/src/adapters/shared/runtime/bind-runtime-server.d.ts +5 -7
- package/src/adapters/shared/runtime/bind-runtime-server.js +8 -12
- package/src/adapters/shared/runtime/copy-runtime-public-dir.js +10 -9
- package/src/adapters/shared/runtime/port-manager.d.ts +8 -11
- package/src/adapters/shared/runtime/port-manager.js +19 -30
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +6 -9
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +2 -5
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +1 -3
- package/src/adapters/shared/runtime/server-request-pipeline.js +1 -5
- package/src/adapters/shared/runtime/server-static-builder.d.ts +3 -3
- package/src/adapters/shared/runtime/server-static-builder.js +3 -3
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +2 -1
- package/src/adapters/shared/ws/websocket-lifecycle.d.ts +5 -6
- package/src/adapters/shared/ws/websocket-lifecycle.js +1 -2
- package/src/assets/app-browser-client-build.js +1 -2
- package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +8 -8
- package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +4 -4
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +12 -8
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +36 -16
- package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +11 -6
- package/src/assets/browser-asset-output.d.ts +19 -0
- package/src/assets/browser-asset-output.js +30 -0
- package/src/assets/hashed-browser-asset.d.ts +8 -6
- package/src/assets/hashed-browser-asset.js +8 -6
- package/src/build/build-adapter.d.ts +2 -19
- package/src/build/build-adapter.js +0 -21
- package/src/build/build-graph.js +2 -2
- package/src/build/cache/cache-keys.d.ts +0 -3
- package/src/build/cache/cache-keys.js +0 -14
- package/src/build/cache/pages-unified-graph-build.js +2 -17
- package/src/build/contracts/build-contracts.d.ts +0 -3
- package/src/build/preserve-import-meta-transform.js +2 -2
- package/src/build/rolldown/app-package-declarations.js +3 -3
- package/src/build/rolldown/rolldown-adapter-helpers.js +3 -3
- package/src/build/rolldown/rolldown-build-adapter.d.ts +0 -1
- package/src/build/rolldown/rolldown-build-adapter.js +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.d.ts +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.js +5 -12
- package/src/build/rolldown/server-side-css-shim-plugin.js +3 -3
- package/src/build/runtime/build-queue.d.ts +8 -13
- package/src/build/runtime/build-queue.js +6 -17
- package/src/build/server/app-module-loader.service.d.ts +1 -1
- package/src/build/server/app-module-loader.service.js +0 -2
- package/src/build/server/page-module-import.service.d.ts +2 -3
- package/src/build/server/page-module-import.service.js +3 -4
- package/src/build/server-bundle-deploy-manifest.d.ts +5 -0
- package/src/build/server-bundle-deploy-manifest.js +15 -1
- package/src/build/server-bundle-publication.js +4 -5
- package/src/build.d.ts +2 -2
- package/src/build.js +2 -2
- package/src/config/assembly/app-runtime.d.ts +2 -2
- package/src/config/assembly/app-runtime.js +2 -2
- package/src/config/assembly/finalize-config.d.ts +4 -4
- package/src/config/assembly/finalize-config.js +4 -5
- package/src/config/config-module-files.js +2 -3
- package/src/config/internal-types.d.ts +0 -7
- package/src/config/user-config-types.d.ts +0 -4
- package/src/diagnostics/request-pipeline-metrics.d.ts +3 -3
- package/src/diagnostics/request-pipeline-metrics.js +4 -4
- package/src/diagnostics/startup-trace.js +2 -5
- package/src/errors/http-error.d.ts +2 -2
- package/src/errors/http-error.js +4 -4
- package/src/hmr/client/hmr-runtime.js +16 -7
- package/src/hmr/client/module-update.d.ts +7 -0
- package/src/hmr/client/module-update.js +21 -4
- package/src/hmr/hmr-strategy.d.ts +0 -3
- package/src/hmr/hmr-strategy.js +0 -3
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -3
- package/src/hmr/strategies/js-hmr-strategy.js +3 -6
- package/src/html-pages/html-page-module-scripts.js +4 -3
- package/src/html-pages/html-page-renderer.js +2 -3
- package/src/plugins/alias-resolver-cache.d.ts +4 -3
- package/src/plugins/alias-resolver-cache.js +4 -3
- package/src/plugins/component-import-discovery.js +4 -4
- package/src/plugins/eco-component-meta-plugin.d.ts +10 -1
- package/src/plugins/eco-component-meta-plugin.js +66 -10
- package/src/plugins/foreign-jsx-override-plugin.js +4 -3
- package/src/plugins/tsconfig-import-resolver.js +12 -12
- package/src/route-renderer/error-pages/default-error-pages.js +2 -1
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -1
- package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +0 -1
- package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -5
- package/src/route-renderer/orchestration/integration-renderer.js +13 -14
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -23
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -29
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +2 -2
- package/src/route-renderer/page-loading/page-dependency-bundling.js +5 -5
- package/src/route-renderer/page-loading/page-module-loader.js +1 -1
- package/src/route-renderer/route-renderer.d.ts +2 -5
- package/src/route-renderer/route-renderer.js +2 -4
- package/src/router/client/link-navigation-policy.d.ts +4 -1
- package/src/router/client/link-navigation-policy.js +20 -6
- package/src/router/server/route-registry.d.ts +0 -1
- package/src/router/server/route-registry.js +3 -13
- package/src/router/server/segment-path-matcher.d.ts +12 -0
- package/src/router/server/segment-path-matcher.js +30 -0
- package/src/static-site-generator/static-site-generator.d.ts +0 -5
- package/src/static-site-generator/static-site-generator.js +2 -15
- package/src/types/contracts.d.ts +17 -27
- package/src/types/public-types.d.ts +1 -1
- package/src/utils/format-error-chain.d.ts +9 -0
- package/src/utils/format-error-chain.js +20 -0
- package/src/utils/invariant.d.ts +6 -1
- package/src/utils/invariant.js +7 -2
- package/src/watchers/project-watcher.d.ts +20 -1
- package/src/watchers/project-watcher.js +40 -9
- package/src/watchers/workspace-package-watch-roots.js +5 -5
- package/src/adapters/README.md +0 -58
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.d.ts +0 -28
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.js +0 -53
- package/src/adapters/shared/runtime/runtime-host.d.ts +0 -15
- package/src/adapters/shared/runtime/runtime-host.js +0 -1
- package/src/assets/README.md +0 -35
- package/src/build/README.md +0 -298
- package/src/build/server/README.md +0 -50
- package/src/cache/README.md +0 -5
- package/src/client/README.md +0 -5
- package/src/client/navigation-scripts/navigation-scripts.test.browser.d.ts +0 -1
- package/src/client/navigation-scripts/navigation-scripts.test.browser.js +0 -111
- package/src/client/scroll.test.browser.d.ts +0 -1
- package/src/client/scroll.test.browser.js +0 -31
- package/src/client/view-transitions.test.browser.d.ts +0 -1
- package/src/client/view-transitions.test.browser.js +0 -53
- package/src/config/README.md +0 -58
- package/src/config/constants.d.ts +0 -1
- package/src/config/constants.js +0 -1
- package/src/dev/README.md +0 -61
- package/src/dev/invalidation/README.md +0 -11
- package/src/dev-toolbar/README.md +0 -66
- package/src/diagnostics/README.md +0 -11
- package/src/eco/README.md +0 -776
- package/src/errors/README.md +0 -5
- package/src/global/README.md +0 -5
- package/src/hmr/README.md +0 -64
- package/src/hmr/client/build-error-overlay.test.browser.d.ts +0 -1
- package/src/hmr/client/build-error-overlay.test.browser.js +0 -48
- package/src/hmr/client/hmr-runtime.test.browser.d.ts +0 -1
- package/src/hmr/client/hmr-runtime.test.browser.js +0 -32
- package/src/hmr/entrypoint-dependency-graph.d.ts +0 -12
- package/src/hmr/entrypoint-dependency-graph.js +0 -27
- package/src/hmr/hmr-file-change-prep.d.ts +0 -9
- package/src/hmr/hmr-file-change-prep.js +0 -11
- package/src/html/README.md +0 -15
- package/src/html-pages/README.md +0 -104
- package/src/islands/README.md +0 -44
- package/src/page-cache/README.md +0 -17
- package/src/plugins/README.md +0 -53
- package/src/route-renderer/GRAPH.md +0 -142
- package/src/route-renderer/README.md +0 -160
- package/src/route-renderer/error-pages/README.md +0 -11
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +0 -15
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.d.ts +0 -39
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +0 -94
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.d.ts +0 -35
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.js +0 -69
- package/src/router/README.md +0 -160
- package/src/router/client/link-intent.test.browser.d.ts +0 -1
- package/src/router/client/link-intent.test.browser.js +0 -33
- package/src/router/client/link-navigation-policy.test.browser.d.ts +0 -1
- package/src/router/client/link-navigation-policy.test.browser.js +0 -142
- package/src/router/client/navigation-commit.test.browser.d.ts +0 -1
- package/src/router/client/navigation-commit.test.browser.js +0 -116
- package/src/router/client/navigation-document.test.browser.d.ts +0 -1
- package/src/router/client/navigation-document.test.browser.js +0 -77
- package/src/router/client/navigation-head.test.browser.d.ts +0 -1
- package/src/router/client/navigation-head.test.browser.js +0 -101
- package/src/router/client/navigation-lifecycle.test.browser.d.ts +0 -1
- package/src/router/client/navigation-lifecycle.test.browser.js +0 -97
- package/src/router/client/navigation-view-transition.test.browser.d.ts +0 -1
- package/src/router/client/navigation-view-transition.test.browser.js +0 -189
- package/src/router/client/staged-stylesheets.test-fixtures.d.ts +0 -18
- package/src/router/client/staged-stylesheets.test-fixtures.js +0 -31
- package/src/static-site-generator/README.md +0 -67
- package/src/static-site-generator/static-site-generator.test-utils.d.ts +0 -2
- package/src/static-site-generator/static-site-generator.test-utils.js +0 -41
- package/src/types/README.md +0 -5
- package/src/utils/README.md +0 -7
- package/src/validation/README.md +0 -9
- package/src/watchers/README.md +0 -15
- package/src/watchers/project-watcher.test-helpers.d.ts +0 -60
- package/src/watchers/project-watcher.test-helpers.js +0 -108
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
2
|
import { fileSystem } from '@ecopages/file-system';
|
|
4
3
|
import { appLogger } from '../../global/app-logger.js';
|
|
5
4
|
import { invariant } from '../../utils/invariant.js';
|
|
6
5
|
import { normalizePathname } from '../../utils/path-pattern.js';
|
|
7
6
|
import { parseSearchParams } from './parse-search-params.js';
|
|
8
7
|
import { findIntegrationForFile, findLongestExtension } from '../../plugins/find-integration-for-file.js';
|
|
9
|
-
import { matchParsedSegmentPath, parseSegmentPath } from './segment-path-matcher.js';
|
|
8
|
+
import { buildSegmentPath, matchParsedSegmentPath, parseSegmentPath, } from './segment-path-matcher.js';
|
|
10
9
|
const ROUTE_PRIORITY = {
|
|
11
10
|
exact: 0,
|
|
12
11
|
dynamic: 1,
|
|
@@ -122,7 +121,7 @@ export class RouteRegistry {
|
|
|
122
121
|
});
|
|
123
122
|
for (const { params } of result.paths) {
|
|
124
123
|
expansions.push({
|
|
125
|
-
pathname:
|
|
124
|
+
pathname: buildSegmentPath(route.pathname, params, 'filesystem'),
|
|
126
125
|
templateRoute: route,
|
|
127
126
|
params,
|
|
128
127
|
});
|
|
@@ -150,7 +149,7 @@ export class RouteRegistry {
|
|
|
150
149
|
];
|
|
151
150
|
}
|
|
152
151
|
async scanTemplateRoutes() {
|
|
153
|
-
if (!
|
|
152
|
+
if (!fileSystem.exists(this.pagesDir)) {
|
|
154
153
|
return [];
|
|
155
154
|
}
|
|
156
155
|
const scannedFiles = await fileSystem.glob(this.templatesExt.map((ext) => `**/*${ext}`), {
|
|
@@ -227,13 +226,4 @@ export class RouteRegistry {
|
|
|
227
226
|
getSearchParams(url) {
|
|
228
227
|
return parseSearchParams(url.searchParams);
|
|
229
228
|
}
|
|
230
|
-
resolveTemplatePath(pathname, params) {
|
|
231
|
-
let resolvedPath = pathname;
|
|
232
|
-
for (const [key, value] of Object.entries(params)) {
|
|
233
|
-
const serializedValue = Array.isArray(value) ? value.join('/') : value;
|
|
234
|
-
resolvedPath = resolvedPath.replace(`[...${key}]`, serializedValue);
|
|
235
|
-
resolvedPath = resolvedPath.replace(`[${key}]`, serializedValue);
|
|
236
|
-
}
|
|
237
|
-
return normalizePathname(resolvedPath);
|
|
238
|
-
}
|
|
239
229
|
}
|
|
@@ -23,5 +23,17 @@ export declare function matchParsedSegmentPath(pattern: string, pathSegments: Pa
|
|
|
23
23
|
export declare function matchSegmentPath(pattern: string, pathname: string, syntax: 'filesystem' | 'api'): SegmentPathParams | null;
|
|
24
24
|
export declare function matchSegmentPath(pattern: string, pathname: string, syntax: 'explicit' | 'websocket'): Record<string, string> | null;
|
|
25
25
|
export declare function matchSegmentPath(pattern: string, pathname: string, syntax: SegmentPathSyntax): SegmentPathParams | null;
|
|
26
|
+
/**
|
|
27
|
+
* Builds a concrete pathname from a route pattern and its params.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* The inverse of {@link matchSegmentPath}: it reads the pattern with the same
|
|
31
|
+
* segment grammar, so `:id` never touches `:idx`, and a catch-all segment
|
|
32
|
+
* (`[...name]` or, for explicit routes, `:...name`) expands to every value of
|
|
33
|
+
* an array param or to a joined string. Values are inserted as given, without
|
|
34
|
+
* percent-encoding. A segment whose param is missing is kept verbatim, and a
|
|
35
|
+
* catch-all with no values disappears from the pathname.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildSegmentPath(pattern: string, params: SegmentPathParams, syntax: SegmentPathSyntax): string;
|
|
26
38
|
export declare function scoreSegmentPathPattern(pattern: string, syntax: 'api'): number;
|
|
27
39
|
export declare function scoreSegmentPathPattern(pattern: string, syntax: 'websocket'): number;
|
|
@@ -132,6 +132,36 @@ export function matchParsedSegmentPath(pattern, pathSegments, syntax) {
|
|
|
132
132
|
export function matchSegmentPath(pattern, pathname, syntax) {
|
|
133
133
|
return matchParsedSegmentPath(pattern, parseSegmentPath(pathname), syntax);
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Builds a concrete pathname from a route pattern and its params.
|
|
137
|
+
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* The inverse of {@link matchSegmentPath}: it reads the pattern with the same
|
|
140
|
+
* segment grammar, so `:id` never touches `:idx`, and a catch-all segment
|
|
141
|
+
* (`[...name]` or, for explicit routes, `:...name`) expands to every value of
|
|
142
|
+
* an array param or to a joined string. Values are inserted as given, without
|
|
143
|
+
* percent-encoding. A segment whose param is missing is kept verbatim, and a
|
|
144
|
+
* catch-all with no values disappears from the pathname.
|
|
145
|
+
*/
|
|
146
|
+
export function buildSegmentPath(pattern, params, syntax) {
|
|
147
|
+
const options = syntaxOptions[syntax];
|
|
148
|
+
const segments = normalizePathname(pattern)
|
|
149
|
+
.split('/')
|
|
150
|
+
.filter(Boolean)
|
|
151
|
+
.flatMap((segment) => {
|
|
152
|
+
const patternSegment = parsePatternSegment(segment, options);
|
|
153
|
+
if (patternSegment.kind !== 'parameter' && patternSegment.kind !== 'catch-all') {
|
|
154
|
+
return [segment];
|
|
155
|
+
}
|
|
156
|
+
const value = params[patternSegment.name];
|
|
157
|
+
if (value === undefined) {
|
|
158
|
+
return [segment];
|
|
159
|
+
}
|
|
160
|
+
return Array.isArray(value) ? value : [value];
|
|
161
|
+
})
|
|
162
|
+
.filter((segment) => segment !== '');
|
|
163
|
+
return normalizePathname(segments.join('/'));
|
|
164
|
+
}
|
|
135
165
|
export function scoreSegmentPathPattern(pattern, syntax) {
|
|
136
166
|
const segments = parsePattern(pattern, syntax);
|
|
137
167
|
if (syntax === 'websocket') {
|
|
@@ -101,11 +101,6 @@ export declare class StaticSiteGenerator {
|
|
|
101
101
|
private planExplicitStaticRoute;
|
|
102
102
|
private createExplicitStaticContents;
|
|
103
103
|
private listExplicitStaticRouteEntries;
|
|
104
|
-
/**
|
|
105
|
-
* Resolve a route path template with actual params.
|
|
106
|
-
* Supports both :param and [param] syntax.
|
|
107
|
-
*/
|
|
108
|
-
private resolveRoutePath;
|
|
109
104
|
/**
|
|
110
105
|
* Get the output file path for a given route.
|
|
111
106
|
*/
|
|
@@ -10,6 +10,7 @@ import { clearProductionPageBrowserGraphSession, prebuildProductionPageBrowserGr
|
|
|
10
10
|
import { renderSitemap } from './sitemap.js';
|
|
11
11
|
import { resolveSitemapLocations } from './sitemap-routes.js';
|
|
12
12
|
import { toEcopagesRouteInfo } from '../utils/ecopages-route-info.js';
|
|
13
|
+
import { buildSegmentPath } from '../router/server/segment-path-matcher.js';
|
|
13
14
|
import { normalizePathname } from '../utils/path-pattern.js';
|
|
14
15
|
import { ErrorPageRenderer } from '../route-renderer/error-pages/error-page-renderer.js';
|
|
15
16
|
import { SemanticErrorPageExporter, SEMANTIC_ERROR_PAGE_PATHNAMES, } from '../route-renderer/error-pages/semantic-error-page-exporter.js';
|
|
@@ -537,24 +538,10 @@ export class StaticSiteGenerator {
|
|
|
537
538
|
runtimeOrigin: this.appConfig.baseUrl,
|
|
538
539
|
});
|
|
539
540
|
return paths.map(({ params }) => ({
|
|
540
|
-
pathname:
|
|
541
|
+
pathname: buildSegmentPath(routePath, params, 'explicit'),
|
|
541
542
|
params,
|
|
542
543
|
}));
|
|
543
544
|
}
|
|
544
|
-
/**
|
|
545
|
-
* Resolve a route path template with actual params.
|
|
546
|
-
* Supports both :param and [param] syntax.
|
|
547
|
-
*/
|
|
548
|
-
resolveRoutePath(routePath, params) {
|
|
549
|
-
let resolved = routePath;
|
|
550
|
-
for (const [key, value] of Object.entries(params)) {
|
|
551
|
-
const paramValue = Array.isArray(value) ? value.join('/') : value;
|
|
552
|
-
resolved = resolved.replace(`:${key}`, paramValue);
|
|
553
|
-
resolved = resolved.replace(`[${key}]`, paramValue);
|
|
554
|
-
resolved = resolved.replace(`[...${key}]`, paramValue);
|
|
555
|
-
}
|
|
556
|
-
return resolved;
|
|
557
|
-
}
|
|
558
545
|
/**
|
|
559
546
|
* Get the output file path for a given route.
|
|
560
547
|
*/
|
package/src/types/contracts.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ export type PageDependenciesInput<T = Record<string, unknown>> = EcoComponentDep
|
|
|
35
35
|
/**
|
|
36
36
|
* Runtime-agnostic incoming WebSocket frame.
|
|
37
37
|
*
|
|
38
|
-
*
|
|
39
|
-
* union lets handlers deal with both without
|
|
38
|
+
* Node `ws` delivers text and binary frames; this discriminated
|
|
39
|
+
* union lets handlers deal with both without casts.
|
|
40
40
|
*/
|
|
41
41
|
export type IncomingWebSocketMessage = {
|
|
42
42
|
readonly kind: 'text';
|
|
@@ -71,7 +71,7 @@ interface WebSocketContextFactoryInput<TParams extends Record<string, string> =
|
|
|
71
71
|
readonly request: Request;
|
|
72
72
|
readonly kind: string;
|
|
73
73
|
readonly params: TParams;
|
|
74
|
-
readonly search: Readonly<
|
|
74
|
+
readonly search: Readonly<PageQuery>;
|
|
75
75
|
readonly locals?: RequestLocals;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
@@ -80,7 +80,7 @@ interface WebSocketContextFactoryInput<TParams extends Record<string, string> =
|
|
|
80
80
|
* Framework-owned fields:
|
|
81
81
|
* - `kind`: the registered route pattern (e.g. '/ws/chat/:roomId')
|
|
82
82
|
* - `params`: dynamic segments captured at match time
|
|
83
|
-
* - `search`: query string,
|
|
83
|
+
* - `search`: query string parameters, shaped like {@link PageQuery}: a repeated key is an array
|
|
84
84
|
*
|
|
85
85
|
* App-owned field:
|
|
86
86
|
* - `context`: returned by the handler's `context()` factory
|
|
@@ -88,7 +88,7 @@ interface WebSocketContextFactoryInput<TParams extends Record<string, string> =
|
|
|
88
88
|
export interface EcopagesSocket<TContext = unknown, TParams extends Record<string, string> = Record<string, string>> {
|
|
89
89
|
readonly kind: string;
|
|
90
90
|
readonly params: TParams;
|
|
91
|
-
readonly search: Readonly<
|
|
91
|
+
readonly search: Readonly<PageQuery>;
|
|
92
92
|
readonly context: TContext;
|
|
93
93
|
send(message: OutgoingWebSocketMessage): void;
|
|
94
94
|
sendStream(stream: ReadableStream<Uint8Array>): Promise<void>;
|
|
@@ -229,15 +229,6 @@ export type ClientBridgeEvent = {
|
|
|
229
229
|
* Timestamp for cache busting
|
|
230
230
|
*/
|
|
231
231
|
timestamp?: number;
|
|
232
|
-
/**
|
|
233
|
-
* Page Browser Graph identities invalidated by the originating file change.
|
|
234
|
-
*/
|
|
235
|
-
graphIdentities?: Array<{
|
|
236
|
-
integrationName: string;
|
|
237
|
-
routeFile: string;
|
|
238
|
-
policy: 'development' | 'production';
|
|
239
|
-
entryFingerprint: string;
|
|
240
|
-
}>;
|
|
241
232
|
};
|
|
242
233
|
export interface HmrAction {
|
|
243
234
|
type: 'broadcast' | 'none';
|
|
@@ -248,7 +239,6 @@ export interface HmrAction {
|
|
|
248
239
|
*/
|
|
249
240
|
export type HmrFileChangeOptions = {
|
|
250
241
|
broadcast?: boolean;
|
|
251
|
-
graphIdentities?: ClientBridgeEvent['graphIdentities'];
|
|
252
242
|
};
|
|
253
243
|
/**
|
|
254
244
|
* Integration callback for registered `dependencies.scripts` entrypoint changes in development.
|
|
@@ -259,7 +249,7 @@ export type HmrFileChangeOptions = {
|
|
|
259
249
|
export type RegisteredScriptEntrypointChangeHandler = (filePath: string) => void | boolean | Promise<void | boolean>;
|
|
260
250
|
/**
|
|
261
251
|
* Adapter-agnostic interface for broadcasting development events to connected clients.
|
|
262
|
-
* Implemented by
|
|
252
|
+
* Implemented by the Node client bridge.
|
|
263
253
|
*/
|
|
264
254
|
export interface IClientBridge {
|
|
265
255
|
broadcast(event: ClientBridgeEvent): void;
|
|
@@ -350,10 +340,6 @@ export interface IHmrManager {
|
|
|
350
340
|
* Gets the default HMR context.
|
|
351
341
|
*/
|
|
352
342
|
getDefaultContext(): DefaultHmrContext;
|
|
353
|
-
/**
|
|
354
|
-
* Handles a file change event.
|
|
355
|
-
*/
|
|
356
|
-
handleFileChange(path: string, options?: HmrFileChangeOptions): Promise<void>;
|
|
357
343
|
/**
|
|
358
344
|
* Handles all file changes from one watcher batch and coalesces their client update.
|
|
359
345
|
*/
|
|
@@ -690,8 +676,15 @@ export interface ErrorPageTemplateProps extends Omit<HtmlTemplateProps, 'childre
|
|
|
690
676
|
*/
|
|
691
677
|
export type PageParams = Record<string, string | string[]>;
|
|
692
678
|
/**
|
|
693
|
-
*
|
|
694
|
-
*
|
|
679
|
+
* Query parameters parsed from the URL.
|
|
680
|
+
*
|
|
681
|
+
* @remarks
|
|
682
|
+
* A key that appears once is a string. A key repeated in the URL (`?tag=a&tag=b`)
|
|
683
|
+
* is an array of its values in URL order, never just its last value. Page props,
|
|
684
|
+
* API handlers (`ctx.query` and the value a query schema validates) and WebSocket
|
|
685
|
+
* `search` all share this shape, so a schema that expects a plain string rejects
|
|
686
|
+
* a repeated key with HTTP 400. Accept both with
|
|
687
|
+
* `z.union([z.string(), z.array(z.string())])`.
|
|
695
688
|
*/
|
|
696
689
|
export type PageQuery = Record<string, string | string[]>;
|
|
697
690
|
/**
|
|
@@ -781,9 +774,6 @@ export type EcoPagesAppConfig = {
|
|
|
781
774
|
enabled?: boolean;
|
|
782
775
|
package?: string;
|
|
783
776
|
};
|
|
784
|
-
experimental?: {
|
|
785
|
-
unsafe?: Record<string, unknown>;
|
|
786
|
-
};
|
|
787
777
|
};
|
|
788
778
|
export type PagePropsFor<T> = T extends GetStaticProps<infer P> ? P & {
|
|
789
779
|
params?: PageParams;
|
|
@@ -1316,7 +1306,7 @@ type MiddlewareNext = () => Promise<Response>;
|
|
|
1316
1306
|
*
|
|
1317
1307
|
* @example Middleware with extended context (use EcoMiddleware helper)
|
|
1318
1308
|
* ```typescript
|
|
1319
|
-
* type AuthContext = ApiHandlerContext<
|
|
1309
|
+
* type AuthContext = ApiHandlerContext<Request, unknown> & { user: User };
|
|
1320
1310
|
*
|
|
1321
1311
|
* const authMiddleware: EcoMiddleware<AuthContext> = async (ctx, next) => {
|
|
1322
1312
|
* const user = await authenticate(ctx.request);
|
|
@@ -1339,7 +1329,7 @@ export type FileRouteMiddleware<TRequest extends Request = Request, TServer = an
|
|
|
1339
1329
|
*
|
|
1340
1330
|
* @example
|
|
1341
1331
|
* ```typescript
|
|
1342
|
-
* type AuthContext = ApiHandlerContext<
|
|
1332
|
+
* type AuthContext = ApiHandlerContext<Request, unknown> & {
|
|
1343
1333
|
* session: { user: User };
|
|
1344
1334
|
* };
|
|
1345
1335
|
*
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { ApiHandler, ApiHandlerContext, EcoComponent, EcoComponentConfig, EcoComponentDependencies, DependencyAttributes, EcoChildren, EcoFunctionComponent, EcoPageComponent, EcoPageFile, EcoPagesAppConfig, EcoPagesElement, EcoPageLayoutEntry, EcoPageLayoutSpec, EcoPageLayouts, EcoHtmlComponent, EcoLayoutComponent, ErrorHandler, ErrorPageTemplateProps, EcopagesRouteInfo, EcopagesSocket, EcopagesWebSocketHandler, FileRouteMiddleware, FileRouteMiddlewareContext, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, GetMetadata, GetMetadataContext, GetStaticPaths, GetStaticProps, HtmlTemplateProps, LayoutProps, LayoutPropsContext, Middleware, OutgoingWebSocketMessage, IncomingWebSocketMessage, PageHeadProps, PageMetadataProps, PageParams, PageQuery, PageDependenciesInput, PageDependenciesResult, PageProps, PagePropsFor, PageRequires, PageRobotsMetadata, RequestLocals, RequestPageContext, RenderContext, RenderOptions, RouteGroupBuilder, RouteOptions, RouteSchema, SitemapConfig, StandardSchema, StandardSchemaFailureResult, StandardSchemaIssue, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaV1, StaticPageContext, StaticPath, TypedGroupHandlerContext, WebSocketCloseInfo, WithLocals, } from './contracts.js';
|
|
1
|
+
export type { ApiHandler, ApiHandlerContext, EcoComponent, EcoComponentConfig, EcoComponentDependencies, DependencyAttributes, EcoChildren, EcoFunctionComponent, EcoPageComponent, EcoPageFile, EcoPagesAppConfig, EcoPagesElement, EcoPageLayoutEntry, EcoPageLayoutSpec, EcoPageLayouts, EcoHtmlComponent, EcoLayoutComponent, EcoMiddleware, ErrorHandler, ErrorPageTemplateProps, EcopagesRouteInfo, EcopagesSocket, EcopagesWebSocketHandler, FileRouteMiddleware, FileRouteMiddlewareContext, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, GetMetadata, GetMetadataContext, GetStaticPaths, GetStaticProps, HtmlTemplateProps, LayoutProps, LayoutPropsContext, Middleware, OutgoingWebSocketMessage, IncomingWebSocketMessage, PageHeadProps, PageMetadataProps, PageParams, PageQuery, PageDependenciesInput, PageDependenciesResult, PageProps, PagePropsFor, PageRequires, PageRobotsMetadata, RequestLocals, RequestPageContext, RenderContext, RenderOptions, RouteGroupBuilder, RouteOptions, RouteSchema, SitemapConfig, StandardSchema, StandardSchemaFailureResult, StandardSchemaIssue, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaV1, StaticPageContext, StaticPath, TypedGroupHandlerContext, WebSocketCloseInfo, WithLocals, } from './contracts.js';
|
|
2
2
|
export type { CacheConfig, CacheStrategy } from './cache-types.js';
|
|
3
3
|
export type { CallableComponentOf, ChildrenOf, ComponentOptions, Eco, EcoEmbedProps, EmbedPropsOf, HtmlOptions, LayoutOptions, LazyTrigger, PageOptions, PageOptionsBase, PagePropsForWithLocals, PropsOf, ResultOf, } from './eco-api-types.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats an error and its `cause` chain as one multi-line string.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* `Error.prototype.stack` never includes `cause`, and the app logger prints only `stack`, so a wrapper error such
|
|
6
|
+
* as a render failure would otherwise hide the stack and code frame of the error it wraps. An error without a
|
|
7
|
+
* cause formats to its own stack unchanged. Circular cause chains stop at the first repeated error.
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatErrorChain(error: unknown): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats an error and its `cause` chain as one multi-line string.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* `Error.prototype.stack` never includes `cause`, and the app logger prints only `stack`, so a wrapper error such
|
|
6
|
+
* as a render failure would otherwise hide the stack and code frame of the error it wraps. An error without a
|
|
7
|
+
* cause formats to its own stack unchanged. Circular cause chains stop at the first repeated error.
|
|
8
|
+
*/
|
|
9
|
+
export function formatErrorChain(error) {
|
|
10
|
+
const seen = new Set();
|
|
11
|
+
const lines = [];
|
|
12
|
+
let current = error;
|
|
13
|
+
while (current !== undefined && !seen.has(current)) {
|
|
14
|
+
seen.add(current);
|
|
15
|
+
const text = current instanceof Error ? (current.stack ?? `${current.name}: ${current.message}`) : String(current);
|
|
16
|
+
lines.push(lines.length === 0 ? text : `Caused by: ${text}`);
|
|
17
|
+
current = current instanceof Error ? current.cause : undefined;
|
|
18
|
+
}
|
|
19
|
+
return lines.join('\n');
|
|
20
|
+
}
|
package/src/utils/invariant.d.ts
CHANGED
|
@@ -2,4 +2,9 @@
|
|
|
2
2
|
* This module contains a simple utility invariant function that throws an error if the condition is not met
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Throws a prefixed error when the condition is false.
|
|
7
|
+
*
|
|
8
|
+
* @param options Forwarded to the thrown error so callers can keep the original failure as `cause`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function invariant(condition: boolean, message?: string, options?: ErrorOptions): asserts condition;
|
package/src/utils/invariant.js
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
const prefix = '[ecopages]';
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Throws a prefixed error when the condition is false.
|
|
8
|
+
*
|
|
9
|
+
* @param options Forwarded to the thrown error so callers can keep the original failure as `cause`.
|
|
10
|
+
*/
|
|
11
|
+
export function invariant(condition, message, options) {
|
|
7
12
|
if (condition) {
|
|
8
13
|
return;
|
|
9
14
|
}
|
|
10
15
|
const value = message ? `${prefix} ${message}` : `${prefix} An error occurred`;
|
|
11
|
-
throw new Error(value);
|
|
16
|
+
throw new Error(value, options);
|
|
12
17
|
}
|
|
@@ -63,9 +63,24 @@ export declare class ProjectWatcher {
|
|
|
63
63
|
private pendingFlushResolvers;
|
|
64
64
|
private changeQueue;
|
|
65
65
|
private closePromise;
|
|
66
|
+
/**
|
|
67
|
+
* Reads `ECOPAGES_WATCH_CHANGE_DEBOUNCE_MS`.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* A value that is not a non-negative number would otherwise become `NaN` or a negative delay, which timers
|
|
71
|
+
* treat as about 1 ms and so silently turn debouncing off. It is ignored with a warning instead, so the
|
|
72
|
+
* default window applies.
|
|
73
|
+
*/
|
|
74
|
+
private static resolveEnvDebounceMs;
|
|
66
75
|
constructor({ config, refreshRouterRoutesCallback, hmrManager, bridge, changeDebounceMs, onRestartRequest, entryWatcherOwnsConfig, }: ProjectWatcherConfig);
|
|
67
76
|
private requestBrowserReload;
|
|
68
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Mirrors one public file change into dist.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* A deleted source is removed from dist, otherwise the stale copy keeps being served by the dev server.
|
|
82
|
+
*/
|
|
83
|
+
private syncPublicDirFile;
|
|
69
84
|
/**
|
|
70
85
|
* Serializes file change handling so that concurrent chokidar events are
|
|
71
86
|
* processed one at a time, preventing overlapping builds and race conditions.
|
|
@@ -105,6 +120,10 @@ export declare class ProjectWatcher {
|
|
|
105
120
|
* @param {unknown} error - The error to handle
|
|
106
121
|
*/
|
|
107
122
|
handleError(error: unknown): void;
|
|
123
|
+
/**
|
|
124
|
+
* Logs an error and shows it in the browser error overlay.
|
|
125
|
+
*/
|
|
126
|
+
private reportError;
|
|
108
127
|
/**
|
|
109
128
|
* @remarks
|
|
110
129
|
* The subscription watches `srcDir` recursively alongside external recorded
|
|
@@ -53,16 +53,31 @@ export class ProjectWatcher {
|
|
|
53
53
|
pendingFlushResolvers = [];
|
|
54
54
|
changeQueue = Promise.resolve();
|
|
55
55
|
closePromise;
|
|
56
|
+
/**
|
|
57
|
+
* Reads `ECOPAGES_WATCH_CHANGE_DEBOUNCE_MS`.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* A value that is not a non-negative number would otherwise become `NaN` or a negative delay, which timers
|
|
61
|
+
* treat as about 1 ms and so silently turn debouncing off. It is ignored with a warning instead, so the
|
|
62
|
+
* default window applies.
|
|
63
|
+
*/
|
|
64
|
+
static resolveEnvDebounceMs() {
|
|
65
|
+
const raw = getEcopagesEnv('ECOPAGES_WATCH_CHANGE_DEBOUNCE_MS');
|
|
66
|
+
if (raw === undefined || raw.trim() === '')
|
|
67
|
+
return undefined;
|
|
68
|
+
const parsed = Number(raw);
|
|
69
|
+
if (Number.isFinite(parsed) && parsed >= 0)
|
|
70
|
+
return parsed;
|
|
71
|
+
appLogger.warn(`Ignoring ECOPAGES_WATCH_CHANGE_DEBOUNCE_MS="${raw}": expected a non-negative number of milliseconds. Using ${ProjectWatcher.duplicateChangeWindowMs} ms.`);
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
56
74
|
constructor({ config, refreshRouterRoutesCallback, hmrManager, bridge, changeDebounceMs, onRestartRequest, entryWatcherOwnsConfig, }) {
|
|
57
75
|
this.appConfig = config;
|
|
58
76
|
this.refreshRouterRoutesCallback = refreshRouterRoutesCallback;
|
|
59
77
|
this.hmrManager = hmrManager;
|
|
60
78
|
this.bridge = bridge;
|
|
61
|
-
const envDebounceMs = getEcopagesEnv('ECOPAGES_WATCH_CHANGE_DEBOUNCE_MS');
|
|
62
79
|
this.changeDebounceMs =
|
|
63
|
-
changeDebounceMs ??
|
|
64
|
-
(envDebounceMs !== undefined && envDebounceMs !== '' ? Number(envDebounceMs) : undefined) ??
|
|
65
|
-
ProjectWatcher.duplicateChangeWindowMs;
|
|
80
|
+
changeDebounceMs ?? ProjectWatcher.resolveEnvDebounceMs() ?? ProjectWatcher.duplicateChangeWindowMs;
|
|
66
81
|
this.onRestartRequest = onRestartRequest;
|
|
67
82
|
this.entryWatcherOwnsConfig = entryWatcherOwnsConfig === true;
|
|
68
83
|
this.invalidationService = getDevelopmentInvalidationService(config);
|
|
@@ -72,14 +87,24 @@ export class ProjectWatcher {
|
|
|
72
87
|
requestBrowserReload() {
|
|
73
88
|
this.bridge.reload();
|
|
74
89
|
}
|
|
75
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Mirrors one public file change into dist.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* A deleted source is removed from dist, otherwise the stale copy keeps being served by the dev server.
|
|
95
|
+
*/
|
|
96
|
+
async syncPublicDirFile(filePath, kind) {
|
|
76
97
|
try {
|
|
77
98
|
const relativePath = path.relative(this.appConfig.absolutePaths.publicDir, filePath);
|
|
78
99
|
const destPath = path.join(this.appConfig.absolutePaths.distDir, relativePath);
|
|
100
|
+
if (kind === 'deleted') {
|
|
101
|
+
await fileSystem.removeAsync(destPath);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
79
104
|
await copyRuntimePublicFile(filePath, destPath);
|
|
80
105
|
}
|
|
81
106
|
catch (error) {
|
|
82
|
-
appLogger.error(`Failed to
|
|
107
|
+
appLogger.error(`Failed to sync public file: ${formatErrorWithStack(error)}`);
|
|
83
108
|
}
|
|
84
109
|
}
|
|
85
110
|
/**
|
|
@@ -256,7 +281,7 @@ export class ProjectWatcher {
|
|
|
256
281
|
async copyPublicAssets(files) {
|
|
257
282
|
for (const file of files) {
|
|
258
283
|
if (file.plan.category === 'public-asset') {
|
|
259
|
-
await this.
|
|
284
|
+
await this.syncPublicDirFile(file.filePath, file.kind);
|
|
260
285
|
}
|
|
261
286
|
}
|
|
262
287
|
}
|
|
@@ -284,7 +309,7 @@ export class ProjectWatcher {
|
|
|
284
309
|
await watchConfig.onChanges(changes);
|
|
285
310
|
}
|
|
286
311
|
catch (error) {
|
|
287
|
-
|
|
312
|
+
this.reportError(`Processor ${processor.name} failed to handle file changes`, error);
|
|
288
313
|
}
|
|
289
314
|
}
|
|
290
315
|
}
|
|
@@ -312,10 +337,16 @@ export class ProjectWatcher {
|
|
|
312
337
|
* @param {unknown} error - The error to handle
|
|
313
338
|
*/
|
|
314
339
|
handleError(error) {
|
|
340
|
+
this.reportError('Watcher error', error);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Logs an error and shows it in the browser error overlay.
|
|
344
|
+
*/
|
|
345
|
+
reportError(context, error) {
|
|
315
346
|
if (error instanceof Error) {
|
|
316
347
|
this.hmrManager.broadcast({ type: 'error', message: error.message });
|
|
317
348
|
}
|
|
318
|
-
appLogger.error(
|
|
349
|
+
appLogger.error(`${context}: ${formatErrorWithStack(error)}`);
|
|
319
350
|
}
|
|
320
351
|
/**
|
|
321
352
|
* @remarks
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
2
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
3
3
|
import { isPathStrictlyInside } from '../utils/path-containment.js';
|
|
4
4
|
/**
|
|
5
5
|
* @remarks
|
|
@@ -10,9 +10,9 @@ import { isPathStrictlyInside } from '../utils/path-containment.js';
|
|
|
10
10
|
*/
|
|
11
11
|
export function resolveWorkspacePackageWatchRoots(rootDir) {
|
|
12
12
|
const manifestPath = path.join(rootDir, 'package.json');
|
|
13
|
-
if (!
|
|
13
|
+
if (!fileSystem.exists(manifestPath))
|
|
14
14
|
return [];
|
|
15
|
-
const manifest = JSON.parse(readFileSync(manifestPath
|
|
15
|
+
const manifest = JSON.parse(fileSystem.readFileSync(manifestPath));
|
|
16
16
|
const names = new Set([
|
|
17
17
|
...Object.keys(manifest.dependencies ?? {}),
|
|
18
18
|
...Object.keys(manifest.devDependencies ?? {}),
|
|
@@ -25,8 +25,8 @@ export function resolveWorkspacePackageWatchRoots(rootDir) {
|
|
|
25
25
|
let directory = path.resolve(rootDir);
|
|
26
26
|
while (true) {
|
|
27
27
|
const installed = path.join(directory, 'node_modules', name);
|
|
28
|
-
if (
|
|
29
|
-
const realRoot =
|
|
28
|
+
if (fileSystem.exists(path.join(installed, 'package.json'))) {
|
|
29
|
+
const realRoot = fileSystem.realpath(installed);
|
|
30
30
|
if (!realRoot.split(path.sep).includes('node_modules'))
|
|
31
31
|
roots.add(realRoot);
|
|
32
32
|
break;
|
package/src/adapters/README.md
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# Runtime Adapters
|
|
2
|
-
|
|
3
|
-
**Layer:** Application assembly.
|
|
4
|
-
|
|
5
|
-
This directory contains the runtime-host integration layer for Ecopages.
|
|
6
|
-
|
|
7
|
-
## Purpose
|
|
8
|
-
|
|
9
|
-
`createApp()` resolves the config and command-line mode once, then returns the concrete `EcopagesApp`. The app owns route registration and moves through `idle`, `starting`, `ready`, `stopping`, and `stopped` phases. Concurrent `start()` and `fetch()` calls share the app's readiness promise. After `stop()`, a later `start()` or `fetch()` creates a fresh server adapter. The app owns one `NodeServerAdapter`, which binds the Node HTTP host and composes `ServerRequestPipeline` for route handling.
|
|
10
|
-
|
|
11
|
-
Watch mode creates a `DevSession` after the Node server binds. That session owns the Project Watcher, `HmrManager`, client bridge, background Page prewarm, and the Dev Toolbar runtime. Its single `dispose()` stops those resources before Integration teardown. Production and request-only use do not create a DevSession.
|
|
12
|
-
|
|
13
|
-
They are responsible for:
|
|
14
|
-
|
|
15
|
-
- binding and stopping the Node HTTP server
|
|
16
|
-
- delegating startup into framework-owned loaders and services
|
|
17
|
-
- bridging runtime-specific request/response or HMR transport details
|
|
18
|
-
- keeping host/runtime transport details out of generic core orchestration
|
|
19
|
-
|
|
20
|
-
Shutdown cancels queued Page prewarming, waits for active prewarm renders and for Integration `setup()` calls still in flight, then calls `teardown()` for activated Integrations and clears their activation state. Cleanup attempts each resource even when an earlier step fails, then reports the errors. This releases runtime resources such as Lit workers after background renders finish using them.
|
|
21
|
-
|
|
22
|
-
If shutdown rejects while a standalone development restart is stopping the server, the adapter logs the rejection details, including nested cleanup errors and their causes, and still exits with the restart code: the process ends either way, and the CLI starts a fresh server.
|
|
23
|
-
|
|
24
|
-
They are not responsible for:
|
|
25
|
-
|
|
26
|
-
- deciding plugin lifecycle ordering
|
|
27
|
-
- owning server-module semantics
|
|
28
|
-
- owning browser bundling policy
|
|
29
|
-
- owning route rendering semantics
|
|
30
|
-
|
|
31
|
-
## Main Areas
|
|
32
|
-
|
|
33
|
-
- `node/`: `EcopagesApp`, concrete `NodeServerAdapter`, watch-only `DevSession`, HTTP request bridge, and HMR transport
|
|
34
|
-
- `shared/`: runtime-neutral adapter helpers, clustered by concern:
|
|
35
|
-
- `shared/http/` — API response builders, the shared `serveDistFile()` request handler, middleware runner, define-api helpers, explicit-static and filesystem matchers. The dist handler owns file lookup, path validation, HEAD and 405 behavior, ETags, conditional 304, gzip negotiation, and `Cache-Control` for both the runtime fallback and preview. In watch mode stable non-HTML files use `no-cache`; in production only recorded content-hashed outputs are `immutable`, and `.html` and every other file is revalidated (`public, max-age=0, must-revalidate`). A `.gz` variant is sent only to a client that accepts gzip, and any gzip-eligible file that has one carries `Vary: Accept-Encoding`. `FileSystemServerResponseFactory` only wraps rendered route and error-page bodies.
|
|
36
|
-
- `shared/hmr/` — HMR HTML inject helpers, concrete `HmrManager`, and entrypoint registrar. `HmrManager` assigns `appRuntime.hmr` for the dev session, owns per-session script entrypoint change handlers (`onScriptEntrypointChanged`), and clears both on `stop()`. Missing-file events are skipped and their entrypoint registrations are cleared. In watch mode every HTML response is marked `no-store`
|
|
37
|
-
- `shared/runtime/` — `ServerRequestPipeline`, route handler, static builder, port/bootstrap utilities (`PortManager` on dev and preview bind, Clack confirm on TTY port collisions), and the public asset copy helper used at startup, during static export, and by the watcher. Preview binds `serveDistFile()` through the same `RuntimeHost` transport used by the app server. Before `EcopagesApp.start()` reports readiness, watch mode waits for best-effort Integration warmup attempts and the watcher's initial filesystem subscription; all warmup attempts settle before failures are logged. Non-watch network startup activates Integrations before releasing request readiness. In production, startup also restores listed route browser graphs from the production build manifest and verifies their source files and outputs. Request-only `app.fetch()` activates only Integrations used by the request. Declared prewarm paths (`devPrewarmPaths`, including those Processors append in `setup()`) are de-duplicated and rendered in the background without delaying readiness; a path that fails to render is skipped and logged at debug level.
|
|
38
|
-
- `shared/ws/` — WinterCG WebSocket lifecycle helpers and Node HTTP upgrade bridge
|
|
39
|
-
|
|
40
|
-
## Ownership Boundary
|
|
41
|
-
|
|
42
|
-
The adapter layer is transport-oriented.
|
|
43
|
-
|
|
44
|
-
Core-owned modules still own:
|
|
45
|
-
|
|
46
|
-
- config finalization
|
|
47
|
-
- build-manifest assembly
|
|
48
|
-
- server loading
|
|
49
|
-
- invalidation classification
|
|
50
|
-
- route rendering orchestration
|
|
51
|
-
|
|
52
|
-
The error-pages module owns semantic error-page source selection and rendering. The filesystem response matcher classifies page failures, logs rendering failures, coordinates built-in fallback, and wraps the final body in an HTTP response.
|
|
53
|
-
|
|
54
|
-
## Shared Request Contracts
|
|
55
|
-
|
|
56
|
-
- API handler errors and errors that escape `ServerRequestPipeline.handleSharedRequest` resolve through `ApiRequestPipeline.handleError`: a thrown `Response`, then a client abort (499), then `app.onError`, then `HttpError`, then a 500 logged with its stack. `app.fetch()` therefore always resolves with a `Response`. Page render failures render the error page instead and do not reach `app.onError`.
|
|
57
|
-
- On Node, `attachNodeHttpWebSocketUpgrades` owns the unmatched-upgrade policy. `/_hmr` (dev only) and user routes are handled; anything else is destroyed.
|
|
58
|
-
- HMR endpoints follow the `dev` flag only.
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { EcoPagesAppConfig } from '../../../config/internal-types.js';
|
|
2
|
-
import type { ClientBridgeEvent } from '../../../types/contracts.js';
|
|
3
|
-
import { HmrManager } from './hmr-manager.js';
|
|
4
|
-
/**
|
|
5
|
-
* Creates a directory under `os.tmpdir()` that is removed when the test finishes.
|
|
6
|
-
*/
|
|
7
|
-
export declare function createTempRoot(prefix: string): string;
|
|
8
|
-
/**
|
|
9
|
-
* Writes a source file, creating its directories, and returns its path.
|
|
10
|
-
*/
|
|
11
|
-
export declare function writeSourceFile(rootDir: string, relativePath: string, source: string): string;
|
|
12
|
-
/**
|
|
13
|
-
* Starts a Node HMR manager over `config` with a bridge that records what it broadcasts.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* `subscriberCount` is what the bridge reports as connected browsers. The manager stops when the test finishes.
|
|
17
|
-
*/
|
|
18
|
-
export declare function startHmrManager(config: EcoPagesAppConfig, subscriberCount?: number): {
|
|
19
|
-
manager: HmrManager;
|
|
20
|
-
broadcasts: ClientBridgeEvent[];
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Starts a Node HMR manager over a default app config rooted at `rootDir`.
|
|
24
|
-
*/
|
|
25
|
-
export declare function startHmrManagerAt(rootDir: string, subscriberCount?: number): Promise<{
|
|
26
|
-
manager: HmrManager;
|
|
27
|
-
broadcasts: ClientBridgeEvent[];
|
|
28
|
-
}>;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { onTestFinished } from 'vitest';
|
|
5
|
-
import { finalizeEcoPagesConfig } from '../../../config/assembly/finalize-config.js';
|
|
6
|
-
import { HmrManager } from './hmr-manager.js';
|
|
7
|
-
/**
|
|
8
|
-
* Creates a directory under `os.tmpdir()` that is removed when the test finishes.
|
|
9
|
-
*/
|
|
10
|
-
export function createTempRoot(prefix) {
|
|
11
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), `${prefix}-`));
|
|
12
|
-
onTestFinished(() => {
|
|
13
|
-
fs.rmSync(root, { recursive: true, force: true });
|
|
14
|
-
});
|
|
15
|
-
return root;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Writes a source file, creating its directories, and returns its path.
|
|
19
|
-
*/
|
|
20
|
-
export function writeSourceFile(rootDir, relativePath, source) {
|
|
21
|
-
const filePath = path.join(rootDir, relativePath);
|
|
22
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
23
|
-
fs.writeFileSync(filePath, source, 'utf8');
|
|
24
|
-
return filePath;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Starts a Node HMR manager over `config` with a bridge that records what it broadcasts.
|
|
28
|
-
*
|
|
29
|
-
* @remarks
|
|
30
|
-
* `subscriberCount` is what the bridge reports as connected browsers. The manager stops when the test finishes.
|
|
31
|
-
*/
|
|
32
|
-
export function startHmrManager(config, subscriberCount = 0) {
|
|
33
|
-
const broadcasts = [];
|
|
34
|
-
const bridge = {
|
|
35
|
-
subscriberCount,
|
|
36
|
-
broadcast: (event) => {
|
|
37
|
-
broadcasts.push(event);
|
|
38
|
-
},
|
|
39
|
-
reload: () => { },
|
|
40
|
-
cssUpdate: () => { },
|
|
41
|
-
update: () => { },
|
|
42
|
-
error: () => { },
|
|
43
|
-
};
|
|
44
|
-
const manager = new HmrManager({ appConfig: config, bridge });
|
|
45
|
-
onTestFinished(() => manager.stop());
|
|
46
|
-
return { manager, broadcasts };
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Starts a Node HMR manager over a default app config rooted at `rootDir`.
|
|
50
|
-
*/
|
|
51
|
-
export async function startHmrManagerAt(rootDir, subscriberCount = 0) {
|
|
52
|
-
return startHmrManager(await finalizeEcoPagesConfig({ rootDir }), subscriberCount);
|
|
53
|
-
}
|