@ecopages/core 0.2.0-rc.0 → 0.2.0-rc.10
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 +52 -33
- package/package.json +58 -4
- package/src/adapters/README.md +3 -1
- package/src/adapters/abstract/application-adapter.d.ts +28 -6
- package/src/adapters/abstract/application-adapter.js +58 -5
- package/src/adapters/abstract/segment-path-matcher.js +56 -38
- package/src/adapters/abstract/server-adapter.d.ts +14 -0
- package/src/adapters/abstract/server-adapter.js +10 -0
- package/src/adapters/bun/create-app.d.ts +10 -6
- package/src/adapters/bun/create-app.js +64 -37
- package/src/adapters/bun/server-adapter.d.ts +6 -2
- package/src/adapters/bun/server-adapter.js +14 -1
- package/src/adapters/create-app.d.ts +62 -7
- package/src/adapters/create-app.js +61 -5
- package/src/adapters/node/create-app.d.ts +5 -5
- package/src/adapters/node/create-app.js +18 -5
- package/src/adapters/node/runtime-host.js +9 -4
- package/src/adapters/node/server-adapter.d.ts +5 -1
- package/src/adapters/node/server-adapter.js +16 -1
- package/src/adapters/shared/http/define-api-handler.d.ts +7 -49
- package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
- package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -8
- package/src/adapters/shared/http/fs-server-response-factory.js +5 -30
- 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/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/server-adapter.d.ts +14 -5
- package/src/adapters/shared/runtime/server-adapter.js +22 -30
- package/src/adapters/shared/runtime/server-route-handler.js +11 -3
- package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
- package/src/adapters/shared/runtime/server-static-builder.js +59 -37
- package/src/build/README.md +5 -1
- package/src/build/cache/server-entry-build-cache.d.ts +24 -1
- package/src/build/cache/server-entry-build-cache.js +125 -8
- package/src/build/contracts/content-virtual-modules.d.ts +3 -1
- package/src/build/contracts/content-virtual-modules.js +8 -0
- package/src/build/rolldown/rolldown-adapter-helpers.js +56 -31
- package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
- package/src/build/rolldown/runtime-build-output-normalizer.js +3 -29
- package/src/build/runtime/build-request-policy.js +1 -1
- package/src/build/server-bundle-publication.d.ts +14 -0
- package/src/build/server-bundle-publication.js +49 -0
- package/src/config/README.md +17 -2
- package/src/config/apply-user-config.d.ts +6 -0
- package/src/config/apply-user-config.js +67 -0
- package/src/config/config-builder.d.ts +10 -1
- package/src/config/config-builder.js +51 -10
- package/src/config/constants.d.ts +4 -0
- package/src/config/constants.js +4 -0
- 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 +100 -0
- package/src/config/resolve-eco-config-path.d.ts +23 -0
- package/src/config/resolve-eco-config-path.js +47 -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 +164 -0
- package/src/config/user-config-types.js +1 -0
- package/src/css-imports.d.ts +4 -0
- package/src/declarations.d.ts +11 -5
- package/src/dev/README.md +6 -0
- package/src/dev/development-restart-watch-paths.d.ts +13 -0
- package/src/dev/development-restart-watch-paths.js +37 -0
- package/src/dev/development-restart.d.ts +13 -0
- package/src/dev/development-restart.js +21 -0
- package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
- package/src/dev/transform-server/dev-transform-server.js +16 -5
- package/src/eco/README.md +73 -5
- package/src/eco/component-identity.d.ts +3 -2
- package/src/eco/component-identity.js +5 -2
- package/src/eco/discovered-dependencies.d.ts +45 -0
- package/src/eco/discovered-dependencies.js +87 -0
- package/src/eco/eco.js +6 -0
- package/src/eco/eco.types.d.ts +18 -2
- package/src/eco/lazy-injector-map.js +57 -41
- package/src/eco/page-dependency-contributions.d.ts +19 -0
- package/src/eco/page-dependency-contributions.js +52 -0
- package/src/errors/http-error-page-contract.d.ts +77 -0
- package/src/errors/http-error-page-contract.js +106 -0
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
- package/src/hmr/strategies/js-hmr-strategy.js +24 -16
- package/src/index.browser.d.ts +3 -0
- package/src/index.browser.js +3 -0
- package/src/index.d.ts +4 -1
- package/src/index.js +4 -1
- package/src/islands/README.md +5 -1
- package/src/plugins/README.md +10 -2
- package/src/plugins/component-import-discovery.d.ts +19 -0
- package/src/plugins/component-import-discovery.js +241 -0
- package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
- package/src/plugins/eco-component-meta-plugin.js +118 -16
- package/src/plugins/integration-plugin.d.ts +4 -9
- package/src/plugins/processor.d.ts +23 -2
- package/src/plugins/processor.js +25 -0
- package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
- package/src/plugins/tsconfig-import-resolver.js +4 -2
- package/src/route-renderer/GRAPH.md +1 -1
- package/src/route-renderer/README.md +16 -3
- package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +80 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +13 -1
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +15 -0
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
- package/src/route-renderer/orchestration/integration-renderer.d.ts +11 -5
- package/src/route-renderer/orchestration/integration-renderer.js +42 -29
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
- package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +8 -10
- package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
- package/src/route-renderer/orchestration/string-markup-renderer.js +10 -8
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
- package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
- package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
- package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
- package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
- package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
- package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
- package/src/route-renderer/route-renderer.d.ts +9 -0
- package/src/route-renderer/route-renderer.js +18 -0
- package/src/router/README.md +7 -1
- package/src/router/server/route-registry.d.ts +13 -0
- package/src/router/server/route-registry.js +46 -32
- package/src/services/README.md +5 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
- package/src/services/assets/asset-processing-service/page-package.js +42 -39
- package/src/services/error-pages/README.md +9 -0
- package/src/services/error-pages/default-error-pages.d.ts +44 -0
- package/src/services/error-pages/default-error-pages.js +207 -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/invalidation/development-invalidation.service.d.ts +7 -1
- package/src/services/invalidation/development-invalidation.service.js +35 -3
- package/src/services/module-loading/README.md +16 -13
- package/src/services/module-loading/app-server-module-transpiler.service.js +2 -0
- package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -0
- package/src/services/module-loading/collection-server-module-build.service.js +5 -2
- package/src/services/module-loading/page-module-import.service.d.ts +8 -0
- package/src/services/module-loading/page-module-import.service.js +62 -28
- package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
- 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/validation/schema-validation-service.d.ts +1 -0
- package/src/services/validation/schema-validation-service.js +23 -36
- package/src/static-site-generator/README.md +6 -1
- package/src/static-site-generator/static-site-generator.d.ts +7 -2
- package/src/static-site-generator/static-site-generator.js +90 -49
- package/src/types/internal-types.d.ts +6 -1
- package/src/types/public-types.d.ts +34 -24
- package/src/utils/parse-cli-args.js +29 -22
- package/src/watchers/project-watcher.d.ts +14 -1
- package/src/watchers/project-watcher.js +85 -34
- /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Stable class hooks exposed by the framework-owned error documents. */
|
|
2
|
+
export declare const DEFAULT_ERROR_PAGE_CLASS_NAMES: {
|
|
3
|
+
readonly root: "eco-error-page";
|
|
4
|
+
readonly notFoundModifier: "eco-error-page--not-found";
|
|
5
|
+
readonly serverErrorModifier: "eco-error-page--server-error";
|
|
6
|
+
readonly badRequestModifier: "eco-error-page--bad-request";
|
|
7
|
+
readonly unauthorizedModifier: "eco-error-page--unauthorized";
|
|
8
|
+
readonly forbiddenModifier: "eco-error-page--forbidden";
|
|
9
|
+
readonly conflictModifier: "eco-error-page--conflict";
|
|
10
|
+
readonly content: "eco-error-page__content";
|
|
11
|
+
readonly status: "eco-error-page__status";
|
|
12
|
+
readonly title: "eco-error-page__title";
|
|
13
|
+
readonly message: "eco-error-page__message";
|
|
14
|
+
readonly diagnostics: "eco-error-page__diagnostics";
|
|
15
|
+
readonly diagnosticsHeader: "eco-error-page__diagnostics-header";
|
|
16
|
+
readonly diagnosticsLabel: "eco-error-page__diagnostics-label";
|
|
17
|
+
readonly stack: "eco-error-page__stack";
|
|
18
|
+
readonly copyButton: "eco-error-page__copy";
|
|
19
|
+
readonly copyButtonCopied: "eco-error-page__copy--copied";
|
|
20
|
+
readonly copyButtonFailed: "eco-error-page__copy--failed";
|
|
21
|
+
readonly copyIcon: "eco-error-page__copy-icon";
|
|
22
|
+
readonly copyIconClipboard: "eco-error-page__copy-icon--clipboard";
|
|
23
|
+
readonly copyIconSuccess: "eco-error-page__copy-icon--success";
|
|
24
|
+
readonly copyLabel: "eco-error-page__copy-label";
|
|
25
|
+
};
|
|
26
|
+
export type DefaultErrorPageDetails = {
|
|
27
|
+
message?: string;
|
|
28
|
+
stack?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Self-contained HTML for a framework default error response.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Development 5xx pages may include escaped `message` / `stack` and a copy
|
|
35
|
+
* button. 4xx pages never serialize a stack.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildDefaultErrorHtml(status: number, details?: DefaultErrorPageDetails): string;
|
|
38
|
+
/** Self-contained HTML for the framework default not-found response. */
|
|
39
|
+
export declare function buildDefaultNotFoundHtml(): string;
|
|
40
|
+
export type DefaultServerErrorDetails = DefaultErrorPageDetails;
|
|
41
|
+
export declare function getDefaultServerErrorDetails(error: unknown): DefaultServerErrorDetails | undefined;
|
|
42
|
+
export declare function getPublicErrorMessage(error: unknown): string | undefined;
|
|
43
|
+
/** Self-contained HTML for the framework default server-error response. */
|
|
44
|
+
export declare function buildDefaultServerErrorHtml(details?: DefaultServerErrorDetails): string;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { isDevelopmentRuntime } from '../../utils/runtime.js';
|
|
2
|
+
import { ERROR_PAGE_COPY, isHttpErrorPageStatus, isHttpErrorStatus } from '../../errors/http-error-page-contract.js';
|
|
3
|
+
function escapeHtml(value) {
|
|
4
|
+
return value
|
|
5
|
+
.replaceAll('&', '&')
|
|
6
|
+
.replaceAll('<', '<')
|
|
7
|
+
.replaceAll('>', '>')
|
|
8
|
+
.replaceAll('"', '"')
|
|
9
|
+
.replaceAll("'", ''');
|
|
10
|
+
}
|
|
11
|
+
/** Stable class hooks exposed by the framework-owned error documents. */
|
|
12
|
+
export const DEFAULT_ERROR_PAGE_CLASS_NAMES = {
|
|
13
|
+
root: 'eco-error-page',
|
|
14
|
+
notFoundModifier: 'eco-error-page--not-found',
|
|
15
|
+
serverErrorModifier: 'eco-error-page--server-error',
|
|
16
|
+
badRequestModifier: 'eco-error-page--bad-request',
|
|
17
|
+
unauthorizedModifier: 'eco-error-page--unauthorized',
|
|
18
|
+
forbiddenModifier: 'eco-error-page--forbidden',
|
|
19
|
+
conflictModifier: 'eco-error-page--conflict',
|
|
20
|
+
content: 'eco-error-page__content',
|
|
21
|
+
status: 'eco-error-page__status',
|
|
22
|
+
title: 'eco-error-page__title',
|
|
23
|
+
message: 'eco-error-page__message',
|
|
24
|
+
diagnostics: 'eco-error-page__diagnostics',
|
|
25
|
+
diagnosticsHeader: 'eco-error-page__diagnostics-header',
|
|
26
|
+
diagnosticsLabel: 'eco-error-page__diagnostics-label',
|
|
27
|
+
stack: 'eco-error-page__stack',
|
|
28
|
+
copyButton: 'eco-error-page__copy',
|
|
29
|
+
copyButtonCopied: 'eco-error-page__copy--copied',
|
|
30
|
+
copyButtonFailed: 'eco-error-page__copy--failed',
|
|
31
|
+
copyIcon: 'eco-error-page__copy-icon',
|
|
32
|
+
copyIconClipboard: 'eco-error-page__copy-icon--clipboard',
|
|
33
|
+
copyIconSuccess: 'eco-error-page__copy-icon--success',
|
|
34
|
+
copyLabel: 'eco-error-page__copy-label',
|
|
35
|
+
};
|
|
36
|
+
const sharedStyles = `
|
|
37
|
+
.eco-error-page { box-sizing: border-box; display: grid; place-items: center; margin: 0; padding: 2rem; color: #18181b; background: radial-gradient(circle at top, #f4f4f5, #fff 42rem); font-family: ui-sans-serif, system-ui, sans-serif; line-height: 1.5; }
|
|
38
|
+
.eco-error-page__content { width: min(100%, 42rem); padding: clamp(2rem, 8vw, 4.5rem); border: 1px solid #e4e4e7; border-radius: 1rem; background: #fff; }
|
|
39
|
+
.eco-error-page__status { margin: 0 0 1rem; color: #71717a; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: .75rem; font-weight: 700; letter-spacing: .12em; }
|
|
40
|
+
.eco-error-page__title { margin: 0; font-size: clamp(2rem, 6vw, 3.5rem); font-weight: 650; letter-spacing: -.05em; line-height: 1.05; }
|
|
41
|
+
.eco-error-page__message { max-width: 36rem; margin: 1rem 0 0; color: #52525b; font-size: 1rem; }
|
|
42
|
+
.eco-error-page__diagnostics { margin-top: 2rem; border: 1px solid #e4e4e7; border-radius: .75rem; overflow: hidden; background: #fafafa; }
|
|
43
|
+
.eco-error-page__diagnostics-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3rem; padding: 0 .75rem 0 1rem; border-bottom: 1px solid #e4e4e7; background: #fff; }
|
|
44
|
+
.eco-error-page__diagnostics-label { color: #52525b; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: .75rem; font-weight: 650; }
|
|
45
|
+
.eco-error-page__stack { max-height: 22rem; overflow: auto; box-sizing: border-box; margin: 0; padding: 1rem; color: #3f3f46; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: .8125rem; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
|
|
46
|
+
.eco-error-page__copy { font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: .5rem; min-height: 2rem; padding: .375rem .625rem; border: 1px solid #d4d4d8; border-radius: .4375rem; color: #3f3f46; background: #fff; font-size: .8125rem; font-weight: 600; transition: border-color .15s ease, background-color .15s ease, color .15s ease; }
|
|
47
|
+
.eco-error-page__copy:hover { border-color: #a1a1aa; background: #fafafa; }
|
|
48
|
+
.eco-error-page__copy--copied { border-color: #86efac; background: #f0fdf4; color: #166534; }
|
|
49
|
+
.eco-error-page__copy--failed { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
|
|
50
|
+
.eco-error-page__copy-icon { display: inline-flex; flex-shrink: 0; width: 1rem; height: 1rem; }
|
|
51
|
+
.eco-error-page__copy-icon svg { display: block; width: 100%; height: 100%; }
|
|
52
|
+
.eco-error-page__copy-icon--success { display: none; }
|
|
53
|
+
.eco-error-page__copy--copied .eco-error-page__copy-icon--clipboard { display: none; }
|
|
54
|
+
.eco-error-page__copy--copied .eco-error-page__copy-icon--success { display: inline-flex; }
|
|
55
|
+
.eco-error-page__copy:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
|
|
56
|
+
@media (max-width: 40rem) { .eco-error-page { padding: 1rem; } .eco-error-page__content { padding: 2rem 1.5rem; border-radius: .75rem; } }
|
|
57
|
+
@media (prefers-color-scheme: dark) { .eco-error-page { color: #f4f4f5; background: radial-gradient(circle at top, #27272a, #09090b 42rem); } .eco-error-page__content { border-color: #3f3f46; background: #18181b; } .eco-error-page__status, .eco-error-page__message { color: #a1a1aa; } .eco-error-page__diagnostics { border-color: #3f3f46; background: #18181b; } .eco-error-page__diagnostics-header { border-color: #3f3f46; background: #27272a; } .eco-error-page__diagnostics-label, .eco-error-page__stack { color: #d4d4d8; } .eco-error-page__copy { border-color: #52525b; color: #e4e4e7; background: #27272a; } .eco-error-page__copy:hover { border-color: #a1a1aa; background: #3f3f46; } .eco-error-page__copy--copied { border-color: #166534; background: #052e16; color: #bbf7d0; } .eco-error-page__copy--failed { border-color: #991b1b; background: #450a0a; color: #fecaca; } }
|
|
58
|
+
`.trim();
|
|
59
|
+
const clipboardIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="8" height="4" x="8" y="2" rx="1" ry="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/></svg>';
|
|
60
|
+
const checkIconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>';
|
|
61
|
+
function buildDefaultCopyButtonMarkup(copyPayload) {
|
|
62
|
+
const names = DEFAULT_ERROR_PAGE_CLASS_NAMES;
|
|
63
|
+
return `<pre id="eco-copy-error-payload" hidden>${escapeHtml(copyPayload)}</pre>
|
|
64
|
+
<button type="button" class="${names.copyButton}" id="eco-copy-error" aria-label="Copy error details to clipboard">
|
|
65
|
+
<span class="${names.copyIcon} ${names.copyIconClipboard}" aria-hidden="true">${clipboardIconSvg}</span>
|
|
66
|
+
<span class="${names.copyIcon} ${names.copyIconSuccess}" aria-hidden="true">${checkIconSvg}</span>
|
|
67
|
+
<span class="${names.copyLabel}" aria-live="polite">Copy error</span>
|
|
68
|
+
</button>
|
|
69
|
+
<script>
|
|
70
|
+
(function () {
|
|
71
|
+
var button = document.getElementById('eco-copy-error');
|
|
72
|
+
var payload = document.getElementById('eco-copy-error-payload');
|
|
73
|
+
if (!button || !payload) return;
|
|
74
|
+
var label = button.querySelector('.${names.copyLabel}');
|
|
75
|
+
var text = payload.textContent || '';
|
|
76
|
+
var resetTimer;
|
|
77
|
+
function setState(state) {
|
|
78
|
+
button.classList.toggle('${names.copyButtonCopied}', state === 'copied');
|
|
79
|
+
button.classList.toggle('${names.copyButtonFailed}', state === 'failed');
|
|
80
|
+
if (label) label.textContent = state === 'copied' ? 'Copied' : state === 'failed' ? 'Copy failed' : 'Copy error';
|
|
81
|
+
button.setAttribute('aria-label', state === 'copied' ? 'Error details copied' : state === 'failed' ? 'Could not copy error details' : 'Copy error details to clipboard');
|
|
82
|
+
}
|
|
83
|
+
function fallbackCopy(value) {
|
|
84
|
+
var area = document.createElement('textarea');
|
|
85
|
+
area.value = value;
|
|
86
|
+
area.setAttribute('readonly', '');
|
|
87
|
+
area.style.position = 'absolute';
|
|
88
|
+
area.style.left = '-9999px';
|
|
89
|
+
document.body.appendChild(area);
|
|
90
|
+
area.select();
|
|
91
|
+
try {
|
|
92
|
+
if (!document.execCommand('copy')) throw new Error('Clipboard copy failed');
|
|
93
|
+
} finally { document.body.removeChild(area); }
|
|
94
|
+
}
|
|
95
|
+
function copyToClipboard(value) {
|
|
96
|
+
if (navigator.clipboard && navigator.clipboard.writeText) return navigator.clipboard.writeText(value);
|
|
97
|
+
return Promise.resolve().then(function () { fallbackCopy(value); });
|
|
98
|
+
}
|
|
99
|
+
button.addEventListener('click', function () {
|
|
100
|
+
copyToClipboard(text).then(function () {
|
|
101
|
+
setState('copied');
|
|
102
|
+
clearTimeout(resetTimer);
|
|
103
|
+
resetTimer = setTimeout(function () { setState('idle'); }, 2000);
|
|
104
|
+
}).catch(function () {
|
|
105
|
+
setState('failed');
|
|
106
|
+
clearTimeout(resetTimer);
|
|
107
|
+
resetTimer = setTimeout(function () { setState('idle'); }, 3000);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
})();
|
|
111
|
+
</script>`;
|
|
112
|
+
}
|
|
113
|
+
function copyForStatus(status) {
|
|
114
|
+
if (isHttpErrorPageStatus(status)) {
|
|
115
|
+
return ERROR_PAGE_COPY[status];
|
|
116
|
+
}
|
|
117
|
+
if (isHttpErrorStatus(status) && status >= 500) {
|
|
118
|
+
return ERROR_PAGE_COPY[500];
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
title: `Error ${status}`,
|
|
122
|
+
message: 'An error occurred while handling this request.',
|
|
123
|
+
modifier: `status-${status}`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function normalizeDetail(value) {
|
|
127
|
+
const trimmed = value?.trim();
|
|
128
|
+
return trimmed ? trimmed : undefined;
|
|
129
|
+
}
|
|
130
|
+
function formatDiagnosticsCopyPayload(message, stack) {
|
|
131
|
+
const parts = [];
|
|
132
|
+
if (message)
|
|
133
|
+
parts.push(`Message: ${message}`);
|
|
134
|
+
if (stack)
|
|
135
|
+
parts.push(`Stack:\n${stack}`);
|
|
136
|
+
return parts.join('\n\n');
|
|
137
|
+
}
|
|
138
|
+
function createDefaultErrorPageViewModel(status, details) {
|
|
139
|
+
const copy = copyForStatus(status);
|
|
140
|
+
const isServerError = status >= 500;
|
|
141
|
+
const stack = isServerError ? normalizeDetail(details?.stack) : undefined;
|
|
142
|
+
const showDiagnostics = isServerError && isDevelopmentRuntime() && Boolean(details?.message || stack);
|
|
143
|
+
const diagnosticMessage = showDiagnostics ? normalizeDetail(details?.message) : undefined;
|
|
144
|
+
return {
|
|
145
|
+
status,
|
|
146
|
+
title: copy.title,
|
|
147
|
+
modifierClass: `eco-error-page--${copy.modifier}`,
|
|
148
|
+
bodyMessage: isServerError ? copy.message : normalizeDetail(details?.message) || copy.message,
|
|
149
|
+
diagnostics: showDiagnostics
|
|
150
|
+
? {
|
|
151
|
+
message: diagnosticMessage,
|
|
152
|
+
stack,
|
|
153
|
+
copyPayload: formatDiagnosticsCopyPayload(diagnosticMessage, stack),
|
|
154
|
+
}
|
|
155
|
+
: undefined,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function renderDiagnosticsMarkup(diagnostics) {
|
|
159
|
+
const names = DEFAULT_ERROR_PAGE_CLASS_NAMES;
|
|
160
|
+
const copyMarkup = buildDefaultCopyButtonMarkup(diagnostics.copyPayload);
|
|
161
|
+
const messageMarkup = diagnostics.message
|
|
162
|
+
? `<p class="${names.message}" role="alert">${escapeHtml(diagnostics.message)}</p>`
|
|
163
|
+
: '';
|
|
164
|
+
if (!diagnostics.stack) {
|
|
165
|
+
return `${messageMarkup}${copyMarkup}`;
|
|
166
|
+
}
|
|
167
|
+
return `${messageMarkup}<section class="${names.diagnostics}" aria-label="Error stack trace"><div class="${names.diagnosticsHeader}"><span class="${names.diagnosticsLabel}">Stack trace</span>${copyMarkup}</div><pre class="${names.stack}">${escapeHtml(diagnostics.stack)}</pre></section>`;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Self-contained HTML for a framework default error response.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* Development 5xx pages may include escaped `message` / `stack` and a copy
|
|
174
|
+
* button. 4xx pages never serialize a stack.
|
|
175
|
+
*/
|
|
176
|
+
export function buildDefaultErrorHtml(status, details) {
|
|
177
|
+
const names = DEFAULT_ERROR_PAGE_CLASS_NAMES;
|
|
178
|
+
const view = createDefaultErrorPageViewModel(status, details);
|
|
179
|
+
const detailsBlock = view.diagnostics ? renderDiagnosticsMarkup(view.diagnostics) : '';
|
|
180
|
+
return `<!DOCTYPE html>
|
|
181
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(view.title)}</title><style>${sharedStyles}</style></head>
|
|
182
|
+
<body class="${names.root} ${view.modifierClass}"><main class="${names.content}"><p class="${names.status}" aria-hidden="true">ERROR ${view.status}</p><h1 class="${names.title}">${escapeHtml(view.title)}</h1><p class="${names.message}">${escapeHtml(view.bodyMessage)}</p>${detailsBlock}</main></body></html>`;
|
|
183
|
+
}
|
|
184
|
+
/** Self-contained HTML for the framework default not-found response. */
|
|
185
|
+
export function buildDefaultNotFoundHtml() {
|
|
186
|
+
return buildDefaultErrorHtml(404);
|
|
187
|
+
}
|
|
188
|
+
export function getDefaultServerErrorDetails(error) {
|
|
189
|
+
if (!isDevelopmentRuntime() || error === undefined) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
if (error instanceof Error) {
|
|
193
|
+
return { message: error.message, stack: error.stack };
|
|
194
|
+
}
|
|
195
|
+
return { message: String(error) };
|
|
196
|
+
}
|
|
197
|
+
export function getPublicErrorMessage(error) {
|
|
198
|
+
if (error instanceof Error) {
|
|
199
|
+
const message = error.message.trim();
|
|
200
|
+
return message.length > 0 ? message : undefined;
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
/** Self-contained HTML for the framework default server-error response. */
|
|
205
|
+
export function buildDefaultServerErrorHtml(details) {
|
|
206
|
+
return buildDefaultErrorHtml(500, details);
|
|
207
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../../types/internal-types.js';
|
|
2
|
+
import type { ErrorPageLoaders, RouteRendererBody } from '../../types/public-types.js';
|
|
3
|
+
import type { StaticGenerationRendererResolver } from '../../route-renderer/route-renderer.js';
|
|
4
|
+
import { type ErrorPageKind } from '../../errors/http-error-page-contract.js';
|
|
5
|
+
export type { ErrorPageKind };
|
|
6
|
+
export type ErrorPageRenderResult = {
|
|
7
|
+
body: RouteRendererBody;
|
|
8
|
+
sourceFile?: string;
|
|
9
|
+
};
|
|
10
|
+
export type ErrorPageRenderInput = {
|
|
11
|
+
kind?: ErrorPageKind;
|
|
12
|
+
status?: number;
|
|
13
|
+
error?: unknown;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Owns error-page source precedence and rendering for runtime and static paths.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Filesystem semantic pages win over explicitly registered views. A missing
|
|
20
|
+
* custom source is the only case that uses a framework default; rendering
|
|
21
|
+
* failures are intentionally propagated so callers can apply their own retry
|
|
22
|
+
* or fallback policy without hiding the original failure.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ErrorPageRenderer {
|
|
25
|
+
private readonly appConfig;
|
|
26
|
+
private readonly routeRendererFactory?;
|
|
27
|
+
private readonly loaders;
|
|
28
|
+
constructor({ appConfig, routeRendererFactory, errorPageLoaders, }: {
|
|
29
|
+
appConfig: EcoPagesAppConfig;
|
|
30
|
+
routeRendererFactory?: StaticGenerationRendererResolver;
|
|
31
|
+
errorPageLoaders?: ErrorPageLoaders;
|
|
32
|
+
});
|
|
33
|
+
render(input: ErrorPageRenderInput): Promise<ErrorPageRenderResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Renders the framework-owned document, ignoring custom filesystem pages and
|
|
36
|
+
* registered views.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Request-time callers use this after a custom 500 page itself fails so the
|
|
40
|
+
* fallback cannot re-enter the custom source.
|
|
41
|
+
*/
|
|
42
|
+
renderBuiltIn(input: ErrorPageRenderInput): ErrorPageRenderResult;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the source file used for incremental static-export reuse, without
|
|
45
|
+
* rendering the page.
|
|
46
|
+
*/
|
|
47
|
+
resolveSourceFile(kind: ErrorPageKind): Promise<string | undefined>;
|
|
48
|
+
private resolveCustomSource;
|
|
49
|
+
private renderFileSystemPage;
|
|
50
|
+
private renderRegisteredPage;
|
|
51
|
+
private getTemplatePath;
|
|
52
|
+
private getCustomPageProps;
|
|
53
|
+
private resolveViewSourceFile;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Logs a custom error-page failure without replacing the original request error.
|
|
57
|
+
*/
|
|
58
|
+
export declare function logErrorPageFailure(kind: ErrorPageKind | undefined, error: unknown): void;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
3
|
+
import { appLogger } from '../../global/app-logger.js';
|
|
4
|
+
import { prepareExplicitStaticRender } from '../../route-renderer/explicit-view-render-preparation.js';
|
|
5
|
+
import { ERROR_PAGE_STATUS_BY_KIND, kindForStatus } from '../../errors/http-error-page-contract.js';
|
|
6
|
+
import { buildDefaultErrorHtml, getDefaultServerErrorDetails, getPublicErrorMessage, } from './default-error-pages.js';
|
|
7
|
+
const ERROR_PAGE_RENDER_ERRORS = {
|
|
8
|
+
missingIntegration: (routePath) => `View at ${routePath} is missing component identity integration. Ensure it's defined with eco.page() and exported as default.`,
|
|
9
|
+
noRendererForIntegration: (integrationName) => `No renderer found for integration: ${integrationName}`,
|
|
10
|
+
};
|
|
11
|
+
function resolveRenderTarget(input) {
|
|
12
|
+
const status = input.status ?? (input.kind ? ERROR_PAGE_STATUS_BY_KIND[input.kind] : 500);
|
|
13
|
+
return {
|
|
14
|
+
status,
|
|
15
|
+
kind: input.kind ?? kindForStatus(status),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Owns error-page source precedence and rendering for runtime and static paths.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Filesystem semantic pages win over explicitly registered views. A missing
|
|
23
|
+
* custom source is the only case that uses a framework default; rendering
|
|
24
|
+
* failures are intentionally propagated so callers can apply their own retry
|
|
25
|
+
* or fallback policy without hiding the original failure.
|
|
26
|
+
*/
|
|
27
|
+
export class ErrorPageRenderer {
|
|
28
|
+
appConfig;
|
|
29
|
+
routeRendererFactory;
|
|
30
|
+
loaders;
|
|
31
|
+
constructor({ appConfig, routeRendererFactory, errorPageLoaders = {}, }) {
|
|
32
|
+
this.appConfig = appConfig;
|
|
33
|
+
this.routeRendererFactory = routeRendererFactory;
|
|
34
|
+
this.loaders = errorPageLoaders;
|
|
35
|
+
}
|
|
36
|
+
async render(input) {
|
|
37
|
+
const { status, kind } = resolveRenderTarget(input);
|
|
38
|
+
const source = kind ? this.resolveCustomSource(kind) : undefined;
|
|
39
|
+
const props = this.getCustomPageProps(status, input.error);
|
|
40
|
+
if (source?.kind === 'filesystem') {
|
|
41
|
+
return await this.renderFileSystemPage(source.templatePath, props);
|
|
42
|
+
}
|
|
43
|
+
if (source?.kind === 'loader') {
|
|
44
|
+
return await this.renderRegisteredPage(source.loader, status, props);
|
|
45
|
+
}
|
|
46
|
+
return this.renderBuiltIn(input);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Renders the framework-owned document, ignoring custom filesystem pages and
|
|
50
|
+
* registered views.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Request-time callers use this after a custom 500 page itself fails so the
|
|
54
|
+
* fallback cannot re-enter the custom source.
|
|
55
|
+
*/
|
|
56
|
+
renderBuiltIn(input) {
|
|
57
|
+
const { status } = resolveRenderTarget(input);
|
|
58
|
+
return {
|
|
59
|
+
body: buildDefaultErrorHtml(status, this.getCustomPageProps(status, input.error)),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns the source file used for incremental static-export reuse, without
|
|
64
|
+
* rendering the page.
|
|
65
|
+
*/
|
|
66
|
+
async resolveSourceFile(kind) {
|
|
67
|
+
const source = this.resolveCustomSource(kind);
|
|
68
|
+
if (source?.kind === 'filesystem') {
|
|
69
|
+
return source.templatePath;
|
|
70
|
+
}
|
|
71
|
+
if (source?.kind === 'loader') {
|
|
72
|
+
const view = (await source.loader()).default;
|
|
73
|
+
return this.resolveViewSourceFile(view.config?.identity?.file);
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
resolveCustomSource(kind) {
|
|
78
|
+
const templatePath = this.getTemplatePath(kind);
|
|
79
|
+
if (templatePath && fileSystem.exists(templatePath)) {
|
|
80
|
+
return { kind: 'filesystem', templatePath };
|
|
81
|
+
}
|
|
82
|
+
const loader = this.loaders[kind];
|
|
83
|
+
if (loader) {
|
|
84
|
+
return { kind: 'loader', loader };
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
async renderFileSystemPage(templatePath, props) {
|
|
89
|
+
if (!this.routeRendererFactory) {
|
|
90
|
+
throw new Error(`No route renderer available for ${templatePath}`);
|
|
91
|
+
}
|
|
92
|
+
const result = await this.routeRendererFactory.getPageRenderer(templatePath).execute({
|
|
93
|
+
file: templatePath,
|
|
94
|
+
props,
|
|
95
|
+
locals: {},
|
|
96
|
+
});
|
|
97
|
+
return { body: result.body, sourceFile: templatePath };
|
|
98
|
+
}
|
|
99
|
+
async renderRegisteredPage(loader, status, props) {
|
|
100
|
+
if (!this.routeRendererFactory) {
|
|
101
|
+
throw new Error(`No route renderer available for __error__/${status}`);
|
|
102
|
+
}
|
|
103
|
+
const view = (await loader()).default;
|
|
104
|
+
const { renderer, props: staticProps, view: renderableView, } = await prepareExplicitStaticRender({
|
|
105
|
+
routePath: `__error__/${status}`,
|
|
106
|
+
view,
|
|
107
|
+
params: {},
|
|
108
|
+
appConfig: this.appConfig,
|
|
109
|
+
runtimeOrigin: this.appConfig.baseUrl,
|
|
110
|
+
routeRendererFactory: this.routeRendererFactory,
|
|
111
|
+
errors: ERROR_PAGE_RENDER_ERRORS,
|
|
112
|
+
});
|
|
113
|
+
const response = await renderer.renderToResponse(renderableView, { ...staticProps, ...props }, { status });
|
|
114
|
+
return {
|
|
115
|
+
body: await response.text(),
|
|
116
|
+
sourceFile: this.resolveViewSourceFile(view.config?.identity?.file),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
getTemplatePath(kind) {
|
|
120
|
+
const status = ERROR_PAGE_STATUS_BY_KIND[kind];
|
|
121
|
+
return (this.appConfig.absolutePaths.errorPageTemplatePaths?.[status] ||
|
|
122
|
+
(kind === 'notFound' ? this.appConfig.absolutePaths.error404TemplatePath : '') ||
|
|
123
|
+
(kind === 'serverError' ? this.appConfig.absolutePaths.error500TemplatePath : '') ||
|
|
124
|
+
'');
|
|
125
|
+
}
|
|
126
|
+
getCustomPageProps(status, error) {
|
|
127
|
+
if (status >= 500) {
|
|
128
|
+
return { status, ...getDefaultServerErrorDetails(error) };
|
|
129
|
+
}
|
|
130
|
+
const message = getPublicErrorMessage(error);
|
|
131
|
+
return message ? { status, message } : { status };
|
|
132
|
+
}
|
|
133
|
+
resolveViewSourceFile(sourceFile) {
|
|
134
|
+
if (!sourceFile) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
return path.isAbsolute(sourceFile) ? sourceFile : path.join(this.appConfig.rootDir, sourceFile);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Logs a custom error-page failure without replacing the original request error.
|
|
142
|
+
*/
|
|
143
|
+
export function logErrorPageFailure(kind, error) {
|
|
144
|
+
const status = kind ? ERROR_PAGE_STATUS_BY_KIND[kind] : 500;
|
|
145
|
+
appLogger.error(`Custom ${status} page failed`, error);
|
|
146
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SEMANTIC_ERROR_PAGE_PATHNAMES } from '../../errors/http-error-page-contract.js';
|
|
2
|
+
import { ErrorPageRenderer } from './error-page-renderer.js';
|
|
3
|
+
type StaticArtifactWriter = (input: {
|
|
4
|
+
pathname: string;
|
|
5
|
+
sourceFile?: string;
|
|
6
|
+
createContents: () => Promise<string | Buffer>;
|
|
7
|
+
activeStaticPathnames: Set<string>;
|
|
8
|
+
}) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Emits semantic error-page artifacts using the same renderer as requests.
|
|
11
|
+
*/
|
|
12
|
+
export declare class SemanticErrorPageExporter {
|
|
13
|
+
private readonly errorPageRenderer;
|
|
14
|
+
private readonly writeArtifact;
|
|
15
|
+
constructor({ errorPageRenderer, writeArtifact, }: {
|
|
16
|
+
errorPageRenderer: ErrorPageRenderer;
|
|
17
|
+
writeArtifact: StaticArtifactWriter;
|
|
18
|
+
});
|
|
19
|
+
export(activeStaticPathnames: Set<string>): Promise<void>;
|
|
20
|
+
private exportOne;
|
|
21
|
+
private bodyToStaticContents;
|
|
22
|
+
}
|
|
23
|
+
export { SEMANTIC_ERROR_PAGE_PATHNAMES };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ERROR_PAGE_KIND_BY_STATUS, HTTP_ERROR_PAGE_STATUSES, SEMANTIC_ERROR_PAGE_PATHNAMES, } from '../../errors/http-error-page-contract.js';
|
|
2
|
+
import { ErrorPageRenderer } from './error-page-renderer.js';
|
|
3
|
+
/**
|
|
4
|
+
* Emits semantic error-page artifacts using the same renderer as requests.
|
|
5
|
+
*/
|
|
6
|
+
export class SemanticErrorPageExporter {
|
|
7
|
+
errorPageRenderer;
|
|
8
|
+
writeArtifact;
|
|
9
|
+
constructor({ errorPageRenderer, writeArtifact, }) {
|
|
10
|
+
this.errorPageRenderer = errorPageRenderer;
|
|
11
|
+
this.writeArtifact = writeArtifact;
|
|
12
|
+
}
|
|
13
|
+
async export(activeStaticPathnames) {
|
|
14
|
+
await Promise.all(HTTP_ERROR_PAGE_STATUSES.map((status) => this.exportOne(ERROR_PAGE_KIND_BY_STATUS[status], `/${status}`, activeStaticPathnames)));
|
|
15
|
+
}
|
|
16
|
+
async exportOne(kind, pathname, activeStaticPathnames) {
|
|
17
|
+
if (activeStaticPathnames.has(pathname)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const sourceFile = await this.errorPageRenderer.resolveSourceFile(kind);
|
|
21
|
+
await this.writeArtifact({
|
|
22
|
+
pathname,
|
|
23
|
+
sourceFile,
|
|
24
|
+
activeStaticPathnames,
|
|
25
|
+
createContents: async () => this.bodyToStaticContents((await this.errorPageRenderer.render({ kind })).body),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async bodyToStaticContents(body) {
|
|
29
|
+
if (typeof body === 'string' || Buffer.isBuffer(body)) {
|
|
30
|
+
return body;
|
|
31
|
+
}
|
|
32
|
+
return await new Response(body).text();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export { SEMANTIC_ERROR_PAGE_PATHNAMES };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EcoPagesAppConfig, RegisteredScriptEntrypointChangeHandler } from '../../types/internal-types.js';
|
|
2
2
|
export type { RegisteredScriptEntrypointChangeHandler };
|
|
3
|
-
export type DevelopmentInvalidationCategory = 'public-asset' | 'additional-watch' | 'include-source' | 'explicit-server-view' | 'route-source' | 'processor-owned-asset' | 'server-source' | 'other';
|
|
3
|
+
export type DevelopmentInvalidationCategory = 'public-asset' | 'additional-watch' | 'include-source' | 'explicit-server-view' | 'route-source' | 'processor-owned-asset' | 'server-source' | 'runtime-restart' | 'other';
|
|
4
4
|
/**
|
|
5
5
|
* Framework-owned invalidation plan for one changed file.
|
|
6
6
|
*
|
|
@@ -55,6 +55,12 @@ export declare class DevelopmentInvalidationService {
|
|
|
55
55
|
* Classifies one changed file into an explicit framework invalidation plan.
|
|
56
56
|
*/
|
|
57
57
|
planFileChange(filePath: string): DevelopmentInvalidationPlan;
|
|
58
|
+
/**
|
|
59
|
+
* Returns whether a config or dotenv edit should restart the development process.
|
|
60
|
+
*/
|
|
61
|
+
isRuntimeRestartFile(filePath: string): boolean;
|
|
62
|
+
/** Returns whether `filePath` is the resolved application config module. */
|
|
63
|
+
isConfigModuleFile(filePath: string): boolean;
|
|
58
64
|
/**
|
|
59
65
|
* Returns whether the file lives under the public directory.
|
|
60
66
|
*/
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { isDevEnvFilePath } from '../../dev/development-restart-watch-paths.js';
|
|
2
3
|
import { getAppServerInvalidationState } from '../runtime-state/server-invalidation-state.service.js';
|
|
3
4
|
import { appLogger } from '../../global/app-logger.js';
|
|
4
5
|
import { clearAppDevelopmentRouteModuleBuildCaches } from '../module-loading/route-module-build-cache-registry.js';
|
|
6
|
+
import { clearCollectionServerBuildArtifacts } from '../module-loading/collection-server-module-build.service.js';
|
|
5
7
|
/**
|
|
6
8
|
* Framework-owned development invalidation service.
|
|
7
9
|
*
|
|
@@ -31,6 +33,10 @@ export class DevelopmentInvalidationService {
|
|
|
31
33
|
getAppServerInvalidationState(this.appConfig).invalidateServerModules(changedFiles);
|
|
32
34
|
this.appConfig.runtime?.appModuleLoader?.invalidateDevelopmentGraph();
|
|
33
35
|
clearAppDevelopmentRouteModuleBuildCaches(this.appConfig);
|
|
36
|
+
clearCollectionServerBuildArtifacts(this.appConfig);
|
|
37
|
+
for (const processor of this.appConfig.processors.values()) {
|
|
38
|
+
processor.invalidateServerArtifacts?.();
|
|
39
|
+
}
|
|
34
40
|
}
|
|
35
41
|
/**
|
|
36
42
|
* Registers an integration-owned handler for registered script entrypoint edits.
|
|
@@ -67,6 +73,16 @@ export class DevelopmentInvalidationService {
|
|
|
67
73
|
* Classifies one changed file into an explicit framework invalidation plan.
|
|
68
74
|
*/
|
|
69
75
|
planFileChange(filePath) {
|
|
76
|
+
if (this.isRuntimeRestartFile(filePath)) {
|
|
77
|
+
return {
|
|
78
|
+
category: 'runtime-restart',
|
|
79
|
+
invalidateServerModules: false,
|
|
80
|
+
refreshRoutes: false,
|
|
81
|
+
reloadBrowser: false,
|
|
82
|
+
delegateToHmr: false,
|
|
83
|
+
processorHandledAsset: false,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
70
86
|
if (this.isPublicDirFile(filePath)) {
|
|
71
87
|
return {
|
|
72
88
|
category: 'public-asset',
|
|
@@ -80,7 +96,7 @@ export class DevelopmentInvalidationService {
|
|
|
80
96
|
if (this.matchesAdditionalWatchPaths(filePath)) {
|
|
81
97
|
return {
|
|
82
98
|
category: 'additional-watch',
|
|
83
|
-
invalidateServerModules:
|
|
99
|
+
invalidateServerModules: true,
|
|
84
100
|
refreshRoutes: false,
|
|
85
101
|
reloadBrowser: true,
|
|
86
102
|
delegateToHmr: false,
|
|
@@ -146,6 +162,20 @@ export class DevelopmentInvalidationService {
|
|
|
146
162
|
processorHandledAsset: false,
|
|
147
163
|
};
|
|
148
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns whether a config or dotenv edit should restart the development process.
|
|
167
|
+
*/
|
|
168
|
+
isRuntimeRestartFile(filePath) {
|
|
169
|
+
return this.isConfigModuleFile(filePath) || isDevEnvFilePath(filePath, this.appConfig.rootDir);
|
|
170
|
+
}
|
|
171
|
+
/** Returns whether `filePath` is the resolved application config module. */
|
|
172
|
+
isConfigModuleFile(filePath) {
|
|
173
|
+
const resolvedPath = path.resolve(filePath);
|
|
174
|
+
const configPath = this.appConfig.absolutePaths?.config
|
|
175
|
+
? path.resolve(this.appConfig.absolutePaths.config)
|
|
176
|
+
: undefined;
|
|
177
|
+
return configPath !== undefined && resolvedPath === configPath;
|
|
178
|
+
}
|
|
149
179
|
/**
|
|
150
180
|
* Returns whether the file lives under the public directory.
|
|
151
181
|
*/
|
|
@@ -162,11 +192,13 @@ export class DevelopmentInvalidationService {
|
|
|
162
192
|
return false;
|
|
163
193
|
for (const pattern of patterns) {
|
|
164
194
|
if (pattern.includes('*')) {
|
|
165
|
-
const ext = pattern.replace(
|
|
195
|
+
const ext = pattern.replace(/\*\*?\/\*|\*+/g, '');
|
|
166
196
|
if (normalizedPath.endsWith(ext))
|
|
167
197
|
return true;
|
|
198
|
+
continue;
|
|
168
199
|
}
|
|
169
|
-
|
|
200
|
+
const resolvedPattern = path.isAbsolute(pattern) ? pattern : path.resolve(this.appConfig.rootDir, pattern);
|
|
201
|
+
if (normalizedPath === resolvedPattern || normalizedPath.startsWith(`${resolvedPattern}${path.sep}`)) {
|
|
170
202
|
return true;
|
|
171
203
|
}
|
|
172
204
|
}
|