@ecopages/core 0.2.0-rc.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -38
- package/package.json +22 -152
- package/src/adapters/README.md +11 -3
- package/src/adapters/abstract/application-adapter.d.ts +32 -36
- package/src/adapters/abstract/application-adapter.js +61 -47
- package/src/adapters/abstract/server-adapter.d.ts +14 -0
- package/src/adapters/abstract/server-adapter.js +10 -0
- package/src/adapters/abstract/ws-pattern-matcher.d.ts +0 -5
- package/src/adapters/abstract/ws-pattern-matcher.js +0 -9
- package/src/adapters/bun/create-app.d.ts +12 -16
- package/src/adapters/bun/create-app.js +25 -55
- package/src/adapters/bun/hmr-manager.d.ts +0 -1
- package/src/adapters/bun/hmr-manager.js +2 -4
- package/src/adapters/bun/server-adapter.d.ts +15 -21
- package/src/adapters/bun/server-adapter.js +33 -67
- package/src/adapters/bun/static-preview-host.d.ts +1 -0
- package/src/adapters/bun/static-preview-host.js +1 -1
- package/src/adapters/create-app.d.ts +63 -8
- package/src/adapters/create-app.js +62 -5
- package/src/adapters/node/create-app.d.ts +8 -12
- package/src/adapters/node/create-app.js +22 -14
- package/src/adapters/node/runtime-host.d.ts +10 -10
- package/src/adapters/node/runtime-host.js +13 -8
- package/src/adapters/node/server-adapter-dependencies.d.ts +2 -10
- package/src/adapters/node/server-adapter-dependencies.js +8 -13
- package/src/adapters/node/server-adapter.d.ts +30 -32
- package/src/adapters/node/server-adapter.js +59 -65
- package/src/adapters/shared/hmr/shared-hmr-manager.d.ts +0 -4
- package/src/adapters/shared/hmr/shared-hmr-manager.js +0 -12
- package/src/adapters/shared/http/api-request-pipeline.d.ts +27 -1
- package/src/adapters/shared/http/api-request-pipeline.js +31 -16
- package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
- package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -9
- package/src/adapters/shared/http/fs-server-response-factory.js +5 -33
- package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
- package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
- package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
- package/src/adapters/shared/runtime/application-adapter.js +12 -0
- package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
- package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
- package/src/adapters/shared/runtime/collect-dev-prewarm-plan.d.ts +1 -3
- package/src/adapters/shared/runtime/collect-dev-prewarm-plan.js +1 -4
- package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
- package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
- package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
- package/src/adapters/shared/runtime/port-manager.js +14 -45
- package/src/adapters/shared/runtime/runtime-app-bootstrap.d.ts +0 -10
- package/src/adapters/shared/runtime/runtime-app-bootstrap.js +0 -7
- package/src/adapters/shared/runtime/runtime-host.d.ts +5 -2
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +1 -1
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +1 -1
- package/src/adapters/shared/runtime/server-adapter.d.ts +26 -5
- package/src/adapters/shared/runtime/server-adapter.js +35 -8
- package/src/adapters/shared/runtime/server-route-handler.js +11 -3
- package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
- package/src/adapters/shared/runtime/server-static-builder.js +59 -37
- package/src/adapters/shared/ws/node-http-websocket-upgrades.d.ts +9 -1
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +8 -2
- package/src/build/README.md +12 -8
- package/src/build/cache/cache-constants.d.ts +0 -2
- package/src/build/cache/cache-constants.js +0 -2
- package/src/build/cache/cache-keys.d.ts +0 -2
- package/src/build/cache/cache-keys.js +0 -2
- package/src/build/cache/output-imports.d.ts +35 -0
- package/src/build/cache/output-imports.js +87 -0
- package/src/build/cache/pages-unified-graph-build.d.ts +15 -1
- package/src/build/cache/pages-unified-graph-build.js +73 -22
- package/src/build/cache/production-build-cache.d.ts +2 -2
- package/src/build/cache/production-build-cache.js +2 -2
- package/src/build/cache/server-entry-build-cache.d.ts +25 -3
- package/src/build/cache/server-entry-build-cache.js +129 -13
- package/src/build/contracts/build-contracts.d.ts +1 -13
- package/src/build/rolldown/runtime-build-output-normalizer.js +3 -6
- package/src/build/runtime/build-request-identity.d.ts +2 -6
- package/src/build/runtime/build-request-identity.js +2 -8
- package/src/build/runtime/build-request-policy.js +1 -1
- package/src/build/runtime/deduping-build-executor.d.ts +0 -1
- package/src/build/runtime/deduping-build-executor.js +0 -1
- package/src/build/server-bundle-publication.d.ts +14 -0
- package/src/build/server-bundle-publication.js +49 -0
- package/src/cache/index.d.ts +1 -1
- package/src/cache/index.js +1 -1
- package/src/cache/module-parse-cache.d.ts +2 -29
- package/src/cache/module-parse-cache.js +6 -39
- package/src/config/README.md +17 -2
- package/src/config/apply-user-config.d.ts +8 -0
- package/src/config/apply-user-config.js +68 -0
- package/src/config/config-builder.d.ts +11 -1
- package/src/config/config-builder.js +53 -12
- package/src/config/constants.d.ts +4 -4
- package/src/config/constants.js +4 -4
- package/src/config/define-config.d.ts +9 -0
- package/src/config/define-config.js +10 -0
- package/src/config/index.d.ts +5 -0
- package/src/config/index.js +4 -0
- package/src/config/is-finalized-app-config.d.ts +6 -0
- package/src/config/is-finalized-app-config.js +11 -0
- package/src/config/load-eco-config.d.ts +21 -0
- package/src/config/load-eco-config.js +107 -0
- package/src/config/resolve-eco-config-path.d.ts +32 -0
- package/src/config/resolve-eco-config-path.js +58 -0
- package/src/config/server-config-bundle.d.ts +25 -0
- package/src/config/server-config-bundle.js +148 -0
- package/src/config/user-config-types.d.ts +170 -0
- package/src/config/user-config-types.js +1 -0
- package/src/dev/README.md +4 -0
- package/src/dev/development-restart-watch-paths.d.ts +13 -0
- package/src/dev/development-restart-watch-paths.js +37 -0
- package/src/dev/development-restart.d.ts +13 -0
- package/src/dev/development-restart.js +21 -0
- package/src/dev/host-runtime.d.ts +0 -1
- package/src/dev/host-runtime.js +0 -3
- package/src/dev/sc-server.d.ts +4 -1
- package/src/dev/sc-server.js +11 -20
- package/src/dev/transform-server/dev-transform-import-rewriter.js +2 -2
- package/src/eco/eco.js +4 -0
- package/src/errors/http-error-page-contract.d.ts +77 -0
- package/src/errors/http-error-page-contract.js +106 -0
- package/src/hmr/hmr-file-change-prep.d.ts +0 -1
- package/src/hmr/hmr-file-change-prep.js +2 -5
- package/src/hmr/hmr-strategy.d.ts +3 -8
- package/src/hmr/hmr-strategy.js +3 -8
- package/src/index.browser.d.ts +1 -2
- package/src/index.browser.js +1 -2
- package/src/index.d.ts +5 -6
- package/src/index.js +5 -6
- package/src/islands/island-host.d.ts +0 -9
- package/src/islands/island-host.js +1 -13
- package/src/plugins/component-import-discovery.js +2 -2
- package/src/plugins/eco-component-meta-plugin.js +5 -5
- package/src/plugins/integration-plugin.d.ts +0 -1
- package/src/plugins/integration-plugin.js +0 -4
- package/src/plugins/processor.d.ts +6 -2
- package/src/route-renderer/README.md +4 -0
- package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -4
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +25 -24
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +18 -20
- package/src/route-renderer/orchestration/integration-renderer.d.ts +24 -7
- package/src/route-renderer/orchestration/integration-renderer.js +44 -33
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +1 -1
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -1
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +1 -1
- package/src/route-renderer/route-renderer.d.ts +9 -0
- package/src/route-renderer/route-renderer.js +18 -0
- package/src/services/README.md +2 -1
- package/src/services/assets/browser-bundle.service.d.ts +1 -6
- package/src/services/error-pages/README.md +9 -0
- package/src/services/error-pages/default-error-pages.d.ts +39 -0
- package/src/services/error-pages/default-error-pages.js +199 -0
- package/src/services/error-pages/error-page-renderer.d.ts +58 -0
- package/src/services/error-pages/error-page-renderer.js +146 -0
- package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
- package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
- package/src/services/html/html-rewriter.d.ts +77 -0
- package/src/services/html/html-rewriter.js +751 -0
- package/src/services/html/html-rewriter.parity.test.bun.d.ts +1 -0
- package/src/services/html/html-rewriter.parity.test.bun.js +74 -0
- package/src/services/html/html-transformer.service.d.ts +29 -42
- package/src/services/html/html-transformer.service.js +85 -157
- package/src/services/invalidation/development-invalidation.service.d.ts +9 -20
- package/src/services/invalidation/development-invalidation.service.js +26 -39
- package/src/services/module-loading/README.md +20 -15
- package/src/services/module-loading/app-module-loader.service.d.ts +0 -2
- package/src/services/module-loading/app-server-module-transpiler.service.d.ts +1 -1
- package/src/services/module-loading/app-server-module-transpiler.service.js +2 -10
- package/src/services/module-loading/collection-server-module-build.service.d.ts +0 -1
- package/src/services/module-loading/collection-server-module-build.service.js +0 -3
- package/src/services/module-loading/host-module-loader-registry.d.ts +0 -1
- package/src/services/module-loading/host-module-loader-registry.js +0 -3
- package/src/services/module-loading/route-module-build-cache-registry.d.ts +0 -4
- package/src/services/module-loading/route-module-build-cache-registry.js +0 -4
- package/src/services/module-loading/route-module-build-cache.store.d.ts +8 -0
- package/src/services/module-loading/route-module-build-cache.store.js +25 -7
- package/src/services/module-loading/route-module-build-manifest.d.ts +12 -1
- package/src/services/module-loading/route-module-build-manifest.js +7 -3
- package/src/services/module-loading/route-module-dependency-hasher.d.ts +3 -2
- package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
- package/src/services/module-loading/server-module-transpiler.service.d.ts +1 -15
- package/src/services/module-loading/server-module-transpiler.service.js +0 -24
- package/src/services/module-loading/view-module-loader.d.ts +10 -0
- package/src/services/module-loading/view-module-loader.js +46 -0
- package/src/services/runtime-state/entrypoint-dependency-graph.service.js +0 -12
- package/src/services/runtime-state/server-invalidation-state.service.d.ts +4 -2
- package/src/services/runtime-state/server-invalidation-state.service.js +7 -14
- package/src/static-site-generator/README.md +12 -8
- package/src/static-site-generator/static-site-generator.d.ts +3 -2
- package/src/static-site-generator/static-site-generator.js +17 -3
- package/src/types/internal-types.d.ts +1 -38
- package/src/types/public-types.d.ts +28 -130
- package/src/watchers/project-watcher.d.ts +9 -16
- package/src/watchers/project-watcher.js +35 -28
- package/src/watchers/project-watcher.test-helpers.d.ts +10 -1
- package/src/watchers/project-watcher.test-helpers.js +12 -0
- package/src/adapters/abstract/router-adapter.d.ts +0 -26
- package/src/adapters/abstract/router-adapter.js +0 -13
- package/src/adapters/bun/index.d.ts +0 -2
- package/src/adapters/bun/index.js +0 -2
- package/src/adapters/index.d.ts +0 -2
- package/src/adapters/index.js +0 -2
- package/src/eco/eco.utils.d.ts +0 -1
- package/src/eco/eco.utils.js +0 -1
- package/src/services/cache/index.d.ts +0 -9
- package/src/services/cache/index.js +0 -8
- package/src/services/html/html-rewriter-provider.service.d.ts +0 -40
- package/src/services/html/html-rewriter-provider.service.js +0 -68
- package/src/services/module-loading/route-module-build-cache.d.ts +0 -4
- package/src/services/module-loading/route-module-build-cache.js +0 -3
- package/src/services/runtime-state/dev-graph.service.d.ts +0 -118
- package/src/services/runtime-state/dev-graph.service.js +0 -170
- /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { HtmlRewriter } from './html-rewriter.js';
|
|
3
|
+
/**
|
|
4
|
+
* Differential check against Bun's native `HTMLRewriter` (lol-html). Runs only in
|
|
5
|
+
* the `bun-adapter` Vitest project, i.e. when Vitest itself runs on Bun.
|
|
6
|
+
*/
|
|
7
|
+
const CORPUS = [
|
|
8
|
+
'<html><head><title>T</title></head><body><main>M</main></body></html>',
|
|
9
|
+
'<html><head><title>T</title><body><main>M</main>',
|
|
10
|
+
'<html><head><script>const s = "</head><body>";</script></head><body><!-- <body> --><textarea></body></textarea><main>M</main></body></html>',
|
|
11
|
+
'<head><title></head>fake</title><noscript></head></noscript></head>',
|
|
12
|
+
'<body><style>a{content:"</body>"}</style><iframe></body></iframe><xmp></body></xmp></body>',
|
|
13
|
+
'<body><script><!--<script>x</script>--></script></body>',
|
|
14
|
+
'<head><SCRIPT>x="</head>"</SCRIPT ></head >',
|
|
15
|
+
'<body><!--><head><!---></body>',
|
|
16
|
+
'<div id="a"><div id="b">x</div></div><body><body>inner</body></body>',
|
|
17
|
+
'<head><meta charset="x"><link rel="x"></head><svg><path d="m0"/></svg><br/><div/><p>x</p></div>',
|
|
18
|
+
`<html LANG=en data-x='1' hidden><body class="a b" data-y="a>b"></body></html>`,
|
|
19
|
+
'<!DOCTYPE html><?xml x?><HTML><HEAD></HEAD><BODY></BODY></HTML>',
|
|
20
|
+
'<template><body></body></template>',
|
|
21
|
+
'<body\n class="x"\n>y</body\n>',
|
|
22
|
+
'<body><svg><![CDATA[ a > </body> ]]></svg><![CDATA[ b > </body> ]]></body>',
|
|
23
|
+
'<body><svg><foreignObject><style>a</body>b</style></foreignObject><p><style>c</body>d</style></p></svg></body>',
|
|
24
|
+
'<body><svg><font color="r"><style>a</body>b</style></font></svg><math><mi><style>c</body></style></mi></math></body>',
|
|
25
|
+
'<body><!--a--!></body foo="</body>"><div a=/><div a="x"/ b="y"><br/></body>',
|
|
26
|
+
];
|
|
27
|
+
const TAGS = ['html', 'head', 'body', 'main', 'div', 'meta', 'link', 'path', 'br', 'script'];
|
|
28
|
+
function handlers(tag) {
|
|
29
|
+
return {
|
|
30
|
+
element(element) {
|
|
31
|
+
element.before(`[B:${tag}]`, { html: true });
|
|
32
|
+
element.prepend(`[P:${tag}]`, { html: true });
|
|
33
|
+
element.append(`[A:${tag}]`, { html: true });
|
|
34
|
+
element.after(`<F:${tag}>`);
|
|
35
|
+
if (tag === 'html')
|
|
36
|
+
element.setAttribute('data-eco', 'x"y');
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const SERIALIZE_CORPUS = [
|
|
41
|
+
'<div a="1"/>',
|
|
42
|
+
'<div\n a="1"\n b=\'2\'\n c\n>',
|
|
43
|
+
'<DIV A="1" b = 2/>',
|
|
44
|
+
'<div a=/>',
|
|
45
|
+
'<div a="x"/ b="y">',
|
|
46
|
+
'<br a="1"/>',
|
|
47
|
+
'<svg><path d="1" /></svg>',
|
|
48
|
+
];
|
|
49
|
+
const MUTATIONS = [
|
|
50
|
+
(element) => element.setAttribute('z', 'v"w'),
|
|
51
|
+
(element) => element.setAttribute('a', '2').prepend('[P]', { html: true }),
|
|
52
|
+
(element) => element.removeAttribute('a'),
|
|
53
|
+
];
|
|
54
|
+
describe('HtmlRewriter parity with Bun HTMLRewriter', () => {
|
|
55
|
+
it.each(CORPUS)('matches native output for %s', (html) => {
|
|
56
|
+
let native = new HTMLRewriter();
|
|
57
|
+
const ours = new HtmlRewriter();
|
|
58
|
+
for (const tag of TAGS) {
|
|
59
|
+
native = native.on(tag, handlers(tag));
|
|
60
|
+
ours.on(tag, handlers(tag));
|
|
61
|
+
}
|
|
62
|
+
expect(ours.transform(html)).toBe(native.transform(html));
|
|
63
|
+
});
|
|
64
|
+
it.each(SERIALIZE_CORPUS)('re-serialises changed tags like native for %s', (html) => {
|
|
65
|
+
for (const mutate of MUTATIONS) {
|
|
66
|
+
const tag = html.includes('<path') ? 'path' : html.toLowerCase().includes('<br') ? 'br' : 'div';
|
|
67
|
+
const native = new HTMLRewriter().on(tag, {
|
|
68
|
+
element: mutate,
|
|
69
|
+
});
|
|
70
|
+
const ours = new HtmlRewriter().on(tag, { element: mutate });
|
|
71
|
+
expect(ours.transform(html)).toBe(native.transform(html));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -1,42 +1,18 @@
|
|
|
1
1
|
import type { ProcessedAsset } from '../assets/asset-processing-service/assets.types.js';
|
|
2
2
|
import type { PagePackageResult } from '../../types/public-types.js';
|
|
3
|
-
import { type HtmlRewriterMode, type HtmlRewriterProvider } from './html-rewriter-provider.service.js';
|
|
4
3
|
export type HtmlDocumentContributionPlacement = 'head-prepend' | 'head-append' | 'body-prepend' | 'body-append';
|
|
5
4
|
export type HtmlDocumentContribution = {
|
|
6
5
|
placement: HtmlDocumentContributionPlacement;
|
|
7
6
|
html: string;
|
|
8
7
|
};
|
|
9
|
-
export interface HtmlTransformerServiceOptions {
|
|
10
|
-
htmlRewriterMode?: HtmlRewriterMode;
|
|
11
|
-
htmlRewriterProvider?: HtmlRewriterProvider;
|
|
12
|
-
}
|
|
13
8
|
export declare class HtmlTransformerService {
|
|
14
9
|
private processedDependencies;
|
|
15
10
|
private pagePackage?;
|
|
16
|
-
private htmlRewriterProvider;
|
|
17
|
-
constructor(options?: HtmlTransformerServiceOptions);
|
|
18
|
-
/**
|
|
19
|
-
* Overrides the HTML rewriter runtime selection.
|
|
20
|
-
*
|
|
21
|
-
* This is intended for internal/runtime tests that need deterministic
|
|
22
|
-
* selection between native, worker-tools, and string fallback behavior.
|
|
23
|
-
*
|
|
24
|
-
* @param mode Requested runtime selection strategy.
|
|
25
|
-
*/
|
|
26
|
-
setHtmlRewriterMode(mode: HtmlRewriterMode): void;
|
|
27
11
|
private formatAttributes;
|
|
28
12
|
private generateScriptTag;
|
|
29
13
|
private generateStylesheetTag;
|
|
30
|
-
private appendDependencies;
|
|
31
14
|
private buildDependencyTags;
|
|
32
|
-
private
|
|
33
|
-
/**
|
|
34
|
-
* Injects generated markup immediately before the closing HTML tag when it is
|
|
35
|
-
* present, or appends/prepends a fallback insertion otherwise.
|
|
36
|
-
*/
|
|
37
|
-
private injectBeforeClosingTag;
|
|
38
|
-
private injectAfterOpeningTag;
|
|
39
|
-
private groupContributionsByPlacement;
|
|
15
|
+
private joinContributions;
|
|
40
16
|
/**
|
|
41
17
|
* Replaces the current processed dependency set used during HTML finalization.
|
|
42
18
|
*/
|
|
@@ -54,18 +30,16 @@ export declare class HtmlTransformerService {
|
|
|
54
30
|
*/
|
|
55
31
|
getPagePackage(): PagePackageResult | undefined;
|
|
56
32
|
/**
|
|
57
|
-
*
|
|
33
|
+
* Sets attributes on the first `<html>` start tag.
|
|
58
34
|
*/
|
|
59
35
|
applyAttributesToHtmlElement(html: string, attributes: Record<string, string>): string;
|
|
60
36
|
/**
|
|
61
|
-
*
|
|
37
|
+
* Sets attributes on the element that directly follows the `<body>` start tag.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* Nothing is stamped when text or a comment comes first (whitespace aside).
|
|
62
41
|
*/
|
|
63
42
|
applyAttributesToFirstBodyElement(html: string, attributes: Record<string, string>): string;
|
|
64
|
-
/**
|
|
65
|
-
* Applies attributes to the first element in a fragment or full-document HTML
|
|
66
|
-
* string.
|
|
67
|
-
*/
|
|
68
|
-
applyAttributesToFirstElement(html: string, attributes: Record<string, string>): string;
|
|
69
43
|
/**
|
|
70
44
|
* Removes duplicate processed assets while preserving first-seen order.
|
|
71
45
|
*
|
|
@@ -76,21 +50,34 @@ export declare class HtmlTransformerService {
|
|
|
76
50
|
*/
|
|
77
51
|
dedupeProcessedAssets(assets: ProcessedAsset[]): ProcessedAsset[];
|
|
78
52
|
/**
|
|
79
|
-
* Injects the
|
|
80
|
-
*
|
|
53
|
+
* Injects the queued dependencies and document contributions into a streaming
|
|
54
|
+
* HTML response.
|
|
55
|
+
*/
|
|
56
|
+
transform(res: Response, contributions?: HtmlDocumentContribution[], pagePackage?: PagePackageResult): Response;
|
|
57
|
+
/**
|
|
58
|
+
* Injects the queued dependencies and document contributions into a complete
|
|
59
|
+
* HTML string.
|
|
60
|
+
*/
|
|
61
|
+
transformHtml(html: string, contributions?: HtmlDocumentContribution[], pagePackage?: PagePackageResult): string;
|
|
62
|
+
/**
|
|
81
63
|
* @remarks
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
64
|
+
* Each slot is inserted as one joined string, so contributions and assets keep
|
|
65
|
+
* their array order even though repeated `prepend` calls insert in reverse.
|
|
66
|
+
* Documents without a `<head>` or `<body>` element, or whose element never
|
|
67
|
+
* closes, skip the matching head or body injections (lol-html semantics).
|
|
85
68
|
*/
|
|
86
|
-
|
|
69
|
+
private createRewriter;
|
|
87
70
|
/**
|
|
88
71
|
* Splits processed assets into head and body injection groups.
|
|
89
72
|
*/
|
|
90
73
|
private groupDependenciesByPosition;
|
|
91
74
|
private resolvePagePackageHtmlDependencies;
|
|
92
|
-
/**
|
|
93
|
-
* Builds a serialized HTML attribute string from an attribute object.
|
|
94
|
-
*/
|
|
95
|
-
private buildAttributeString;
|
|
96
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Sets attributes on the element a fragment or document starts with.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* Nothing is stamped when text or a comment comes first (whitespace aside),
|
|
81
|
+
* so a Lit render that opens with `<!--lit-part-->` keeps its markup.
|
|
82
|
+
*/
|
|
83
|
+
export declare function applyAttributesToFirstElement(html: string, attributes: Record<string, string>): string;
|
|
@@ -1,26 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HtmlRewriter, rewriteFirstElement } from './html-rewriter.js';
|
|
2
2
|
import { buildProcessedAssetDedupeKey, dedupeProcessedAssets, } from '../../route-renderer/orchestration/page-browser-graph/processed-asset-dedupe.js';
|
|
3
3
|
export class HtmlTransformerService {
|
|
4
4
|
processedDependencies = [];
|
|
5
5
|
pagePackage;
|
|
6
|
-
htmlRewriterProvider;
|
|
7
|
-
constructor(options = {}) {
|
|
8
|
-
this.htmlRewriterProvider = options.htmlRewriterProvider ?? new DefaultHtmlRewriterProvider();
|
|
9
|
-
if (options.htmlRewriterMode) {
|
|
10
|
-
this.htmlRewriterProvider.setMode(options.htmlRewriterMode);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Overrides the HTML rewriter runtime selection.
|
|
15
|
-
*
|
|
16
|
-
* This is intended for internal/runtime tests that need deterministic
|
|
17
|
-
* selection between native, worker-tools, and string fallback behavior.
|
|
18
|
-
*
|
|
19
|
-
* @param mode Requested runtime selection strategy.
|
|
20
|
-
*/
|
|
21
|
-
setHtmlRewriterMode(mode) {
|
|
22
|
-
this.htmlRewriterProvider.setMode(mode);
|
|
23
|
-
}
|
|
24
6
|
formatAttributes(attrs) {
|
|
25
7
|
if (!attrs)
|
|
26
8
|
return '';
|
|
@@ -38,62 +20,16 @@ export class HtmlTransformerService {
|
|
|
38
20
|
? `<style${this.formatAttributes(dep.attributes)}>${dep.content}</style>`
|
|
39
21
|
: `<link rel="stylesheet" href="${dep.srcUrl}"${this.formatAttributes(dep.attributes)}>`;
|
|
40
22
|
}
|
|
41
|
-
appendDependencies(element, dependencies) {
|
|
42
|
-
for (const dep of dependencies) {
|
|
43
|
-
const tag = dep.kind === 'script' ? this.generateScriptTag(dep) : this.generateStylesheetTag(dep);
|
|
44
|
-
element.append(tag, { html: true });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
23
|
buildDependencyTags(dependencies) {
|
|
48
24
|
return dependencies
|
|
49
25
|
.map((dep) => dep.kind === 'script' ? this.generateScriptTag(dep) : this.generateStylesheetTag(dep))
|
|
50
26
|
.join('');
|
|
51
27
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Injects generated markup immediately before the closing HTML tag when it is
|
|
59
|
-
* present, or appends/prepends a fallback insertion otherwise.
|
|
60
|
-
*/
|
|
61
|
-
injectBeforeClosingTag(html, tag, content) {
|
|
62
|
-
if (!content) {
|
|
63
|
-
return html;
|
|
64
|
-
}
|
|
65
|
-
const closingTag = `</${tag}>`;
|
|
66
|
-
const lowerHtml = html.toLowerCase();
|
|
67
|
-
const closingTagIndex = lowerHtml.lastIndexOf(closingTag);
|
|
68
|
-
if (closingTagIndex !== -1) {
|
|
69
|
-
return `${html.slice(0, closingTagIndex)}${content}${html.slice(closingTagIndex)}`;
|
|
70
|
-
}
|
|
71
|
-
if (tag === 'head') {
|
|
72
|
-
return `${content}${html}`;
|
|
73
|
-
}
|
|
74
|
-
return `${html}${content}`;
|
|
75
|
-
}
|
|
76
|
-
injectAfterOpeningTag(html, tag, content) {
|
|
77
|
-
if (!content) {
|
|
78
|
-
return html;
|
|
79
|
-
}
|
|
80
|
-
const openingTag = new RegExp(`<${tag}\\b[^>]*>`, 'i');
|
|
81
|
-
const match = html.match(openingTag);
|
|
82
|
-
if (!match || match.index === undefined) {
|
|
83
|
-
return tag === 'head'
|
|
84
|
-
? `${content}${html}`
|
|
85
|
-
: html.replace(/<body\b[^>]*>/i, (value) => `${value}${content}`);
|
|
86
|
-
}
|
|
87
|
-
const insertAt = match.index + match[0].length;
|
|
88
|
-
return `${html.slice(0, insertAt)}${content}${html.slice(insertAt)}`;
|
|
89
|
-
}
|
|
90
|
-
groupContributionsByPlacement(contributions) {
|
|
91
|
-
return {
|
|
92
|
-
headPrepend: contributions.filter((item) => item.placement === 'head-prepend'),
|
|
93
|
-
headAppend: contributions.filter((item) => item.placement === 'head-append'),
|
|
94
|
-
bodyPrepend: contributions.filter((item) => item.placement === 'body-prepend'),
|
|
95
|
-
bodyAppend: contributions.filter((item) => item.placement === 'body-append'),
|
|
96
|
-
};
|
|
28
|
+
joinContributions(contributions, placement) {
|
|
29
|
+
return contributions
|
|
30
|
+
.filter((item) => item.placement === placement)
|
|
31
|
+
.map((item) => item.html)
|
|
32
|
+
.join('');
|
|
97
33
|
}
|
|
98
34
|
/**
|
|
99
35
|
* Replaces the current processed dependency set used during HTML finalization.
|
|
@@ -122,56 +58,25 @@ export class HtmlTransformerService {
|
|
|
122
58
|
return this.pagePackage;
|
|
123
59
|
}
|
|
124
60
|
/**
|
|
125
|
-
*
|
|
61
|
+
* Sets attributes on the first `<html>` start tag.
|
|
126
62
|
*/
|
|
127
63
|
applyAttributesToHtmlElement(html, attributes) {
|
|
128
|
-
|
|
129
|
-
if (!htmlTagMatch || htmlTagMatch.index === undefined) {
|
|
130
|
-
return html;
|
|
131
|
-
}
|
|
132
|
-
const attrs = this.buildAttributeString(attributes);
|
|
133
|
-
if (attrs.length === 0) {
|
|
134
|
-
return html;
|
|
135
|
-
}
|
|
136
|
-
const injectionOffset = htmlTagMatch.index + htmlTagMatch[0].length - 1;
|
|
137
|
-
return `${html.slice(0, injectionOffset)}${attrs}${html.slice(injectionOffset)}`;
|
|
64
|
+
return stampAttributes(html, attributes, (element) => element.tagName === 'html');
|
|
138
65
|
}
|
|
139
66
|
/**
|
|
140
|
-
*
|
|
67
|
+
* Sets attributes on the element that directly follows the `<body>` start tag.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Nothing is stamped when text or a comment comes first (whitespace aside).
|
|
141
71
|
*/
|
|
142
72
|
applyAttributesToFirstBodyElement(html, attributes) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (!firstTagMatch || firstTagMatch.index === undefined) {
|
|
151
|
-
return html;
|
|
152
|
-
}
|
|
153
|
-
const attrs = this.buildAttributeString(attributes);
|
|
154
|
-
if (attrs.length === 0) {
|
|
155
|
-
return html;
|
|
156
|
-
}
|
|
157
|
-
const injectionOffset = bodyOpenEnd + firstTagMatch[1].length + firstTagMatch[2].length;
|
|
158
|
-
return `${html.slice(0, injectionOffset)}${attrs}${html.slice(injectionOffset)}`;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Applies attributes to the first element in a fragment or full-document HTML
|
|
162
|
-
* string.
|
|
163
|
-
*/
|
|
164
|
-
applyAttributesToFirstElement(html, attributes) {
|
|
165
|
-
const firstTagMatch = html.match(/^(\s*<)([a-zA-Z][a-zA-Z0-9:-]*)(\b[^>]*>)/);
|
|
166
|
-
if (!firstTagMatch || firstTagMatch.index === undefined) {
|
|
167
|
-
return html;
|
|
168
|
-
}
|
|
169
|
-
const attrs = this.buildAttributeString(attributes);
|
|
170
|
-
if (attrs.length === 0) {
|
|
171
|
-
return html;
|
|
172
|
-
}
|
|
173
|
-
const injectionOffset = firstTagMatch[1].length + firstTagMatch[2].length;
|
|
174
|
-
return `${html.slice(0, injectionOffset)}${attrs}${html.slice(injectionOffset)}`;
|
|
73
|
+
let insideBody = false;
|
|
74
|
+
return stampAttributes(html, attributes, (element) => {
|
|
75
|
+
if (insideBody)
|
|
76
|
+
return true;
|
|
77
|
+
insideBody = element.tagName === 'body';
|
|
78
|
+
return false;
|
|
79
|
+
}, { leadingOnly: true });
|
|
175
80
|
}
|
|
176
81
|
/**
|
|
177
82
|
* Removes duplicate processed assets while preserving first-seen order.
|
|
@@ -185,46 +90,52 @@ export class HtmlTransformerService {
|
|
|
185
90
|
return dedupeProcessedAssets(assets);
|
|
186
91
|
}
|
|
187
92
|
/**
|
|
188
|
-
* Injects the
|
|
189
|
-
*
|
|
93
|
+
* Injects the queued dependencies and document contributions into a streaming
|
|
94
|
+
* HTML response.
|
|
95
|
+
*/
|
|
96
|
+
transform(res, contributions = [], pagePackage) {
|
|
97
|
+
return this.createRewriter(contributions, pagePackage).transform(res);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Injects the queued dependencies and document contributions into a complete
|
|
101
|
+
* HTML string.
|
|
102
|
+
*/
|
|
103
|
+
transformHtml(html, contributions = [], pagePackage) {
|
|
104
|
+
return this.createRewriter(contributions, pagePackage).transform(html);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
190
107
|
* @remarks
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
108
|
+
* Each slot is inserted as one joined string, so contributions and assets keep
|
|
109
|
+
* their array order even though repeated `prepend` calls insert in reverse.
|
|
110
|
+
* Documents without a `<head>` or `<body>` element, or whose element never
|
|
111
|
+
* closes, skip the matching head or body injections (lol-html semantics).
|
|
194
112
|
*/
|
|
195
|
-
|
|
113
|
+
createRewriter(contributions, pagePackage) {
|
|
196
114
|
const { head, body } = this.groupDependenciesByPosition(pagePackage);
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
115
|
+
const slots = {
|
|
116
|
+
head: {
|
|
117
|
+
prepend: this.joinContributions(contributions, 'head-prepend'),
|
|
118
|
+
append: `${this.buildDependencyTags(head)}${this.joinContributions(contributions, 'head-append')}`,
|
|
119
|
+
},
|
|
120
|
+
body: {
|
|
121
|
+
prepend: this.joinContributions(contributions, 'body-prepend'),
|
|
122
|
+
append: `${this.buildDependencyTags(body)}${this.joinContributions(contributions, 'body-append')}`,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const rewriter = new HtmlRewriter();
|
|
126
|
+
for (const [tagName, slot] of Object.entries(slots)) {
|
|
127
|
+
if (!slot.prepend && !slot.append)
|
|
128
|
+
continue;
|
|
129
|
+
rewriter.on(tagName, {
|
|
130
|
+
element(element) {
|
|
131
|
+
if (slot.prepend)
|
|
132
|
+
element.prepend(slot.prepend, { html: true });
|
|
133
|
+
if (slot.append)
|
|
134
|
+
element.append(slot.append, { html: true });
|
|
213
135
|
},
|
|
214
136
|
});
|
|
215
|
-
return htmlRewriter.transform(res);
|
|
216
137
|
}
|
|
217
|
-
|
|
218
|
-
const headers = new Headers(res.headers);
|
|
219
|
-
const withHeadPrependedContent = this.injectAfterOpeningTag(html, 'head', headPrepend.map((item) => item.html).join(''));
|
|
220
|
-
const withHeadDependencies = this.injectBeforeClosingTag(withHeadPrependedContent, 'head', `${this.buildDependencyTags(head)}${headAppend.map((item) => item.html).join('')}`);
|
|
221
|
-
const withBodyPrependedContent = this.injectAfterOpeningTag(withHeadDependencies, 'body', bodyPrepend.map((item) => item.html).join(''));
|
|
222
|
-
const transformedHtml = this.injectBeforeClosingTag(withBodyPrependedContent, 'body', `${this.buildDependencyTags(body)}${bodyAppend.map((item) => item.html).join('')}`);
|
|
223
|
-
return new Response(transformedHtml, {
|
|
224
|
-
headers,
|
|
225
|
-
status: res.status,
|
|
226
|
-
statusText: res.statusText,
|
|
227
|
-
});
|
|
138
|
+
return rewriter;
|
|
228
139
|
}
|
|
229
140
|
/**
|
|
230
141
|
* Splits processed assets into head and body injection groups.
|
|
@@ -258,13 +169,30 @@ export class HtmlTransformerService {
|
|
|
258
169
|
const entryHtmlAssets = pagePackage.pageBrowserGraph.entryAssets.filter((asset) => !chunkKeys.has(buildProcessedAssetDedupeKey(asset)));
|
|
259
170
|
return dedupeProcessedAssets([...nonGraphHtmlAssets, ...entryHtmlAssets]);
|
|
260
171
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Sets attributes on the element a fragment or document starts with.
|
|
175
|
+
*
|
|
176
|
+
* @remarks
|
|
177
|
+
* Nothing is stamped when text or a comment comes first (whitespace aside),
|
|
178
|
+
* so a Lit render that opens with `<!--lit-part-->` keeps its markup.
|
|
179
|
+
*/
|
|
180
|
+
export function applyAttributesToFirstElement(html, attributes) {
|
|
181
|
+
return stampAttributes(html, attributes, () => true, { leadingOnly: true });
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Sets `attributes` on the first element that `isTarget` accepts.
|
|
185
|
+
*
|
|
186
|
+
* @remarks
|
|
187
|
+
* Entries with an empty name or value are skipped, and an attribute the element
|
|
188
|
+
* already has is replaced rather than duplicated.
|
|
189
|
+
*/
|
|
190
|
+
function stampAttributes(html, attributes, isTarget, options) {
|
|
191
|
+
const entries = Object.entries(attributes).filter(([name, value]) => name.length > 0 && value.length > 0);
|
|
192
|
+
if (entries.length === 0)
|
|
193
|
+
return html;
|
|
194
|
+
return rewriteFirstElement(html, isTarget, (element) => {
|
|
195
|
+
for (const [name, value] of entries)
|
|
196
|
+
element.setAttribute(name, value);
|
|
197
|
+
}, options);
|
|
270
198
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { EcoPagesAppConfig
|
|
2
|
-
export type
|
|
3
|
-
export type DevelopmentInvalidationCategory = 'public-asset' | 'additional-watch' | 'include-source' | 'explicit-server-view' | 'route-source' | 'processor-owned-asset' | 'server-source' | 'other';
|
|
1
|
+
import type { EcoPagesAppConfig } from '../../types/internal-types.js';
|
|
2
|
+
export type DevelopmentInvalidationCategory = 'public-asset' | 'additional-watch' | 'include-source' | 'explicit-server-view' | 'route-source' | 'processor-owned-asset' | 'server-source' | 'runtime-restart' | 'other';
|
|
4
3
|
/**
|
|
5
4
|
* Framework-owned invalidation plan for one changed file.
|
|
6
5
|
*
|
|
@@ -23,7 +22,7 @@ export interface DevelopmentInvalidationPlan {
|
|
|
23
22
|
* @remarks
|
|
24
23
|
* This service centralizes two responsibilities:
|
|
25
24
|
* - file-change classification for watcher behavior
|
|
26
|
-
* - app-owned server-module invalidation
|
|
25
|
+
* - app-owned server-module invalidation
|
|
27
26
|
*
|
|
28
27
|
* Hosts and watchers should ask this service what a file change means instead
|
|
29
28
|
* of deciding invalidation semantics inline.
|
|
@@ -31,30 +30,20 @@ export interface DevelopmentInvalidationPlan {
|
|
|
31
30
|
export declare class DevelopmentInvalidationService {
|
|
32
31
|
private readonly appConfig;
|
|
33
32
|
constructor(appConfig: EcoPagesAppConfig);
|
|
34
|
-
/**
|
|
35
|
-
* Returns the current app-owned server-module invalidation version.
|
|
36
|
-
*/
|
|
37
|
-
getServerModuleInvalidationVersion(): number;
|
|
38
33
|
/**
|
|
39
34
|
* Invalidates the app-owned server-module graph.
|
|
40
35
|
*/
|
|
41
36
|
invalidateServerModules(changedFiles?: string[]): void;
|
|
42
|
-
/**
|
|
43
|
-
* Registers an integration-owned handler for registered script entrypoint edits.
|
|
44
|
-
*/
|
|
45
|
-
registerRegisteredScriptEntrypointChangeHandler(handler: RegisteredScriptEntrypointChangeHandler): void;
|
|
46
|
-
/**
|
|
47
|
-
* Notifies integration handlers that a registered script entrypoint changed.
|
|
48
|
-
*/
|
|
49
|
-
notifyRegisteredScriptEntrypointChange(filePath: string): Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Resets runtime-owned graph state and invalidates server modules.
|
|
52
|
-
*/
|
|
53
|
-
resetRuntimeState(changedFiles?: string[]): void;
|
|
54
37
|
/**
|
|
55
38
|
* Classifies one changed file into an explicit framework invalidation plan.
|
|
56
39
|
*/
|
|
57
40
|
planFileChange(filePath: string): DevelopmentInvalidationPlan;
|
|
41
|
+
/**
|
|
42
|
+
* Returns whether a config or dotenv edit should restart the development process.
|
|
43
|
+
*/
|
|
44
|
+
isRuntimeRestartFile(filePath: string): boolean;
|
|
45
|
+
/** Returns whether `filePath` is the resolved application config module. */
|
|
46
|
+
isConfigModuleFile(filePath: string): boolean;
|
|
58
47
|
/**
|
|
59
48
|
* Returns whether the file lives under the public directory.
|
|
60
49
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
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
|
-
import { appLogger } from '../../global/app-logger.js';
|
|
4
4
|
import { clearAppDevelopmentRouteModuleBuildCaches } from '../module-loading/route-module-build-cache-registry.js';
|
|
5
5
|
import { clearCollectionServerBuildArtifacts } from '../module-loading/collection-server-module-build.service.js';
|
|
6
6
|
/**
|
|
@@ -9,7 +9,7 @@ import { clearCollectionServerBuildArtifacts } from '../module-loading/collectio
|
|
|
9
9
|
* @remarks
|
|
10
10
|
* This service centralizes two responsibilities:
|
|
11
11
|
* - file-change classification for watcher behavior
|
|
12
|
-
* - app-owned server-module invalidation
|
|
12
|
+
* - app-owned server-module invalidation
|
|
13
13
|
*
|
|
14
14
|
* Hosts and watchers should ask this service what a file change means instead
|
|
15
15
|
* of deciding invalidation semantics inline.
|
|
@@ -19,12 +19,6 @@ export class DevelopmentInvalidationService {
|
|
|
19
19
|
constructor(appConfig) {
|
|
20
20
|
this.appConfig = appConfig;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Returns the current app-owned server-module invalidation version.
|
|
24
|
-
*/
|
|
25
|
-
getServerModuleInvalidationVersion() {
|
|
26
|
-
return getAppServerInvalidationState(this.appConfig).getServerInvalidationVersion();
|
|
27
|
-
}
|
|
28
22
|
/**
|
|
29
23
|
* Invalidates the app-owned server-module graph.
|
|
30
24
|
*/
|
|
@@ -37,41 +31,20 @@ export class DevelopmentInvalidationService {
|
|
|
37
31
|
processor.invalidateServerArtifacts?.();
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Registers an integration-owned handler for registered script entrypoint edits.
|
|
42
|
-
*/
|
|
43
|
-
registerRegisteredScriptEntrypointChangeHandler(handler) {
|
|
44
|
-
const runtime = this.appConfig.runtime ?? {};
|
|
45
|
-
this.appConfig.runtime = runtime;
|
|
46
|
-
runtime.registeredScriptEntrypointChangeHandlers ??= [];
|
|
47
|
-
runtime.registeredScriptEntrypointChangeHandlers.push(handler);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Notifies integration handlers that a registered script entrypoint changed.
|
|
51
|
-
*/
|
|
52
|
-
async notifyRegisteredScriptEntrypointChange(filePath) {
|
|
53
|
-
const handlers = this.appConfig.runtime?.registeredScriptEntrypointChangeHandlers ?? [];
|
|
54
|
-
for (const handler of handlers) {
|
|
55
|
-
try {
|
|
56
|
-
await handler(filePath);
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
appLogger.error(`Failed to handle registered script entrypoint change for ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Resets runtime-owned graph state and invalidates server modules.
|
|
65
|
-
*/
|
|
66
|
-
resetRuntimeState(changedFiles) {
|
|
67
|
-
this.invalidateServerModules(changedFiles);
|
|
68
|
-
const serverInvalidationState = getAppServerInvalidationState(this.appConfig);
|
|
69
|
-
serverInvalidationState.reset();
|
|
70
|
-
}
|
|
71
34
|
/**
|
|
72
35
|
* Classifies one changed file into an explicit framework invalidation plan.
|
|
73
36
|
*/
|
|
74
37
|
planFileChange(filePath) {
|
|
38
|
+
if (this.isRuntimeRestartFile(filePath)) {
|
|
39
|
+
return {
|
|
40
|
+
category: 'runtime-restart',
|
|
41
|
+
invalidateServerModules: false,
|
|
42
|
+
refreshRoutes: false,
|
|
43
|
+
reloadBrowser: false,
|
|
44
|
+
delegateToHmr: false,
|
|
45
|
+
processorHandledAsset: false,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
75
48
|
if (this.isPublicDirFile(filePath)) {
|
|
76
49
|
return {
|
|
77
50
|
category: 'public-asset',
|
|
@@ -151,6 +124,20 @@ export class DevelopmentInvalidationService {
|
|
|
151
124
|
processorHandledAsset: false,
|
|
152
125
|
};
|
|
153
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns whether a config or dotenv edit should restart the development process.
|
|
129
|
+
*/
|
|
130
|
+
isRuntimeRestartFile(filePath) {
|
|
131
|
+
return this.isConfigModuleFile(filePath) || isDevEnvFilePath(filePath, this.appConfig.rootDir);
|
|
132
|
+
}
|
|
133
|
+
/** Returns whether `filePath` is the resolved application config module. */
|
|
134
|
+
isConfigModuleFile(filePath) {
|
|
135
|
+
const resolvedPath = path.resolve(filePath);
|
|
136
|
+
const configPath = this.appConfig.absolutePaths?.config
|
|
137
|
+
? path.resolve(this.appConfig.absolutePaths.config)
|
|
138
|
+
: undefined;
|
|
139
|
+
return configPath !== undefined && resolvedPath === configPath;
|
|
140
|
+
}
|
|
154
141
|
/**
|
|
155
142
|
* Returns whether the file lives under the public directory.
|
|
156
143
|
*/
|