@ecopages/core 0.2.0-rc.7 → 0.2.0-rc.9
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/package.json +27 -3
- package/src/adapters/abstract/segment-path-matcher.js +56 -38
- package/src/adapters/bun/create-app.d.ts +4 -0
- package/src/adapters/bun/create-app.js +46 -31
- package/src/adapters/shared/runtime/server-adapter.d.ts +1 -0
- package/src/adapters/shared/runtime/server-adapter.js +9 -22
- package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
- package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
- package/src/eco/README.md +3 -1
- package/src/eco/lazy-injector-map.js +57 -41
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
- package/src/hmr/strategies/js-hmr-strategy.js +24 -16
- package/src/plugins/component-import-discovery.js +115 -77
- package/src/plugins/eco-component-meta-plugin.js +47 -30
- package/src/route-renderer/README.md +1 -0
- 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/integration-renderer.d.ts +3 -0
- package/src/route-renderer/orchestration/integration-renderer.js +31 -17
- 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/page-loading/component-dependency-collection.js +95 -74
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
- package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +0 -3
- package/src/route-renderer/page-loading/file-scoped-dependency-components.js +37 -34
- package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
- package/src/router/README.md +2 -0
- package/src/services/assets/asset-processing-service/page-package.js +42 -39
- package/src/services/module-loading/page-module-import.service.d.ts +6 -0
- package/src/services/module-loading/page-module-import.service.js +60 -27
- 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/static-site-generator.d.ts +4 -0
- package/src/static-site-generator/static-site-generator.js +75 -48
- package/src/utils/parse-cli-args.js +29 -22
- package/src/watchers/project-watcher.d.ts +5 -0
- package/src/watchers/project-watcher.js +46 -32
package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { getComponentIdentity } from '../../../eco/component-identity.js';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { getCustomElementScriptPreloadScopeState, invalidateCustomElementScriptPreload, } from './custom-element-script-preload-invalidation.js';
|
|
6
|
+
export { invalidateCustomElementScriptPreload };
|
|
7
|
+
const registryKeys = new WeakMap();
|
|
8
|
+
export const CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES = {
|
|
9
|
+
lit: 'lit',
|
|
10
|
+
ecopagesJsx: 'ecopages-jsx',
|
|
11
|
+
};
|
|
12
|
+
function getRegistryKey(registry) {
|
|
13
|
+
let key = registryKeys.get(registry);
|
|
14
|
+
if (!key) {
|
|
15
|
+
key = randomUUID();
|
|
16
|
+
registryKeys.set(registry, key);
|
|
17
|
+
}
|
|
18
|
+
return key;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Detects preload failures that are expected for browser-only modules.
|
|
22
|
+
*/
|
|
23
|
+
export function isExpectedCustomElementSsrPreloadError(error) {
|
|
24
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
25
|
+
return (errorMessage.includes(`reading 'Element'`) ||
|
|
26
|
+
errorMessage.includes('window is not defined') ||
|
|
27
|
+
errorMessage.includes('document is not defined') ||
|
|
28
|
+
errorMessage.includes('navigator is not defined'));
|
|
29
|
+
}
|
|
30
|
+
function collectSsrScriptsFromConfig(config, scriptPaths, resolveDependencyPath, componentFile, requireLazyScriptEntry = false) {
|
|
31
|
+
if (!componentFile) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const componentDir = path.dirname(componentFile);
|
|
35
|
+
for (const script of config.dependencies?.scripts ?? []) {
|
|
36
|
+
if (typeof script === 'string' || script.ssr !== true || !script.src) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (requireLazyScriptEntry && !script.lazy) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
scriptPaths.add(resolveDependencyPath(componentDir, script.src));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Collects `dependencies.scripts` paths marked `ssr: true` from a component tree.
|
|
47
|
+
*/
|
|
48
|
+
export function collectCustomElementSsrPreloadScripts(components, resolveDependencyPath, requireLazyScriptEntry = false, collectForIntegration) {
|
|
49
|
+
const scriptPaths = new Set();
|
|
50
|
+
const visitedConfigs = new Set();
|
|
51
|
+
const collect = (component) => {
|
|
52
|
+
const config = component?.config;
|
|
53
|
+
if (!config || visitedConfigs.has(config)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
visitedConfigs.add(config);
|
|
57
|
+
const identity = getComponentIdentity(config);
|
|
58
|
+
const integration = config.integration ?? identity?.integration;
|
|
59
|
+
const ownsScripts = !collectForIntegration || integration === collectForIntegration;
|
|
60
|
+
const componentFile = ownsScripts ? identity?.file : undefined;
|
|
61
|
+
if (ownsScripts) {
|
|
62
|
+
collectSsrScriptsFromConfig(config, scriptPaths, resolveDependencyPath, componentFile, requireLazyScriptEntry);
|
|
63
|
+
}
|
|
64
|
+
for (const layout of config.layouts ?? []) {
|
|
65
|
+
collect(layout);
|
|
66
|
+
}
|
|
67
|
+
for (const nestedComponent of config.dependencies?.components || []) {
|
|
68
|
+
collect(nestedComponent);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
for (const component of components) {
|
|
72
|
+
collect(component);
|
|
73
|
+
}
|
|
74
|
+
return Array.from(scriptPaths);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Preloads `dependencies.scripts` entries marked `ssr: true` before SSR.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* `lazy` controls browser delivery only; `ssr: true` opts into server evaluation
|
|
81
|
+
* for both eager and lazy script entries. State is keyed by `cacheScope` so
|
|
82
|
+
* concurrent renders and dev invalidation share one deduplicated import cache.
|
|
83
|
+
*/
|
|
84
|
+
export class CustomElementScriptPreloader {
|
|
85
|
+
cacheScope;
|
|
86
|
+
enabled;
|
|
87
|
+
requireLazyScriptEntry;
|
|
88
|
+
resolveDependencyPath;
|
|
89
|
+
preferSourceImports;
|
|
90
|
+
resolvePreloadEntrypoint;
|
|
91
|
+
importServerModule;
|
|
92
|
+
collectForIntegration;
|
|
93
|
+
logLabel;
|
|
94
|
+
constructor({ cacheScope, enabled = true, requireLazyScriptEntry = false, resolveDependencyPath, preferSourceImports, resolvePreloadEntrypoint, importServerModule, collectForIntegration, logLabel = 'ecopages', }) {
|
|
95
|
+
this.cacheScope = cacheScope;
|
|
96
|
+
this.enabled = enabled;
|
|
97
|
+
this.requireLazyScriptEntry = requireLazyScriptEntry;
|
|
98
|
+
this.resolveDependencyPath = resolveDependencyPath;
|
|
99
|
+
this.preferSourceImports = preferSourceImports ?? typeof Bun !== 'undefined';
|
|
100
|
+
this.resolvePreloadEntrypoint = resolvePreloadEntrypoint;
|
|
101
|
+
this.importServerModule = importServerModule;
|
|
102
|
+
this.collectForIntegration = collectForIntegration;
|
|
103
|
+
this.logLabel = logLabel;
|
|
104
|
+
}
|
|
105
|
+
invalidateScript(scriptPath) {
|
|
106
|
+
invalidateCustomElementScriptPreload(scriptPath, this.cacheScope);
|
|
107
|
+
}
|
|
108
|
+
isExpectedSsrPreloadError(error) {
|
|
109
|
+
return isExpectedCustomElementSsrPreloadError(error);
|
|
110
|
+
}
|
|
111
|
+
collectSsrPreloadScripts(components) {
|
|
112
|
+
return collectCustomElementSsrPreloadScripts(components, this.resolveDependencyPath, this.requireLazyScriptEntry, this.collectForIntegration);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Preloads SSR-eligible scripts to register custom elements before render.
|
|
116
|
+
*/
|
|
117
|
+
async preloadSsrScripts(components) {
|
|
118
|
+
if (!this.enabled) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const scopeState = getCustomElementScriptPreloadScopeState(this.cacheScope);
|
|
122
|
+
const registry = globalThis.customElements;
|
|
123
|
+
if (scopeState.activeRegistry !== registry) {
|
|
124
|
+
scopeState.preloadedScripts.clear();
|
|
125
|
+
scopeState.preloadFailedScripts.clear();
|
|
126
|
+
scopeState.inFlightImports.clear();
|
|
127
|
+
scopeState.activeRegistry = registry;
|
|
128
|
+
}
|
|
129
|
+
const scripts = this.collectSsrPreloadScripts(components);
|
|
130
|
+
if (scripts.length === 0) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
await Promise.all(scripts.map((scriptPath) => this.preloadOneScript(scriptPath, scopeState, registry)));
|
|
134
|
+
}
|
|
135
|
+
async preloadOneScript(scriptPath, scopeState, registry) {
|
|
136
|
+
if (scopeState.preloadedScripts.has(scriptPath) || scopeState.preloadFailedScripts.has(scriptPath)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
let inFlight = scopeState.inFlightImports.get(scriptPath);
|
|
140
|
+
if (inFlight) {
|
|
141
|
+
await inFlight;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
inFlight = (async () => {
|
|
145
|
+
try {
|
|
146
|
+
await this.importScriptForPreload(scriptPath, registry);
|
|
147
|
+
scopeState.preloadedScripts.add(scriptPath);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
scopeState.preloadFailedScripts.add(scriptPath);
|
|
151
|
+
if (this.isExpectedSsrPreloadError(error)) {
|
|
152
|
+
if (process.env.ECOPAGES_DEBUG === 'true') {
|
|
153
|
+
console.warn(`[ecopages][${this.logLabel}] Skipping SSR preload for browser-only script: ${scriptPath}`);
|
|
154
|
+
}
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
console.warn(`[ecopages][${this.logLabel}] Failed to preload SSR script: ${scriptPath}`, error);
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
scopeState.inFlightImports.delete(scriptPath);
|
|
161
|
+
}
|
|
162
|
+
})();
|
|
163
|
+
scopeState.inFlightImports.set(scriptPath, inFlight);
|
|
164
|
+
await inFlight;
|
|
165
|
+
}
|
|
166
|
+
async importScriptForPreload(scriptPath, registry) {
|
|
167
|
+
const registryKey = registry ? getRegistryKey(registry) : 'default';
|
|
168
|
+
if (this.resolvePreloadEntrypoint) {
|
|
169
|
+
const preloadEntrypoint = await this.resolvePreloadEntrypoint(scriptPath);
|
|
170
|
+
const importUrl = pathToFileURL(preloadEntrypoint);
|
|
171
|
+
if (registry && typeof Bun === 'undefined') {
|
|
172
|
+
importUrl.searchParams.set('eco-ssr-registry', registryKey);
|
|
173
|
+
}
|
|
174
|
+
await import(/* @vite-ignore */ importUrl.href);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (this.importServerModule) {
|
|
178
|
+
await this.importServerModule(scriptPath, registryKey);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!this.preferSourceImports) {
|
|
182
|
+
throw new Error(`Cannot preload SSR script ${scriptPath}: configure appConfig.runtime.appModuleLoader or enable source imports (Bun)`);
|
|
183
|
+
}
|
|
184
|
+
const importUrl = pathToFileURL(scriptPath);
|
|
185
|
+
if (registry && typeof Bun === 'undefined') {
|
|
186
|
+
importUrl.searchParams.set('eco-ssr-registry', registryKey);
|
|
187
|
+
}
|
|
188
|
+
await import(/* @vite-ignore */ importUrl.href);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EcoPagesAppConfig } from '../../../types/internal-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Imports one registered script through the app server module loader for SSR.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Uses an isolated outdir per custom-element registry so concurrent renders do
|
|
7
|
+
* not share mutable module evaluation state.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createCustomElementServerModuleImporter(appConfig: EcoPagesAppConfig, outdirSegment: string): (filePath: string, registryKey: string) => Promise<unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Imports an `ssr: true` script through the same server-module graph as pages.
|
|
12
|
+
*
|
|
13
|
+
* @remarks A per-registry outdir with `forceBuild` compiles a second copy of
|
|
14
|
+
* Radiant and breaks host SSR. This outdir matches page imports and keeps
|
|
15
|
+
* package specifiers external.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSharedServerModuleImporter(appConfig: EcoPagesAppConfig): (filePath: string) => Promise<unknown>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { getAppModuleLoader } from '../../../services/module-loading/app-server-module-transpiler.service.js';
|
|
3
|
+
import { resolveInternalExecutionDir } from '../../../utils/resolve-work-dir.js';
|
|
4
|
+
/**
|
|
5
|
+
* Imports one registered script through the app server module loader for SSR.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Uses an isolated outdir per custom-element registry so concurrent renders do
|
|
9
|
+
* not share mutable module evaluation state.
|
|
10
|
+
*/
|
|
11
|
+
export function createCustomElementServerModuleImporter(appConfig, outdirSegment) {
|
|
12
|
+
return async (filePath, registryKey) => {
|
|
13
|
+
const loader = appConfig.runtime?.appModuleLoader;
|
|
14
|
+
if (!loader) {
|
|
15
|
+
throw new Error('Custom element SSR script preload requires the app server module loader');
|
|
16
|
+
}
|
|
17
|
+
return loader.importModule({
|
|
18
|
+
filePath,
|
|
19
|
+
rootDir: appConfig.rootDir,
|
|
20
|
+
outdir: path.join(appConfig.absolutePaths.workDir, outdirSegment, registryKey),
|
|
21
|
+
forceBuild: true,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Imports an `ssr: true` script through the same server-module graph as pages.
|
|
27
|
+
*
|
|
28
|
+
* @remarks A per-registry outdir with `forceBuild` compiles a second copy of
|
|
29
|
+
* Radiant and breaks host SSR. This outdir matches page imports and keeps
|
|
30
|
+
* package specifiers external.
|
|
31
|
+
*/
|
|
32
|
+
export function createSharedServerModuleImporter(appConfig) {
|
|
33
|
+
return async (filePath) => {
|
|
34
|
+
return getAppModuleLoader(appConfig).importModule({
|
|
35
|
+
filePath,
|
|
36
|
+
rootDir: appConfig.rootDir,
|
|
37
|
+
outdir: `${resolveInternalExecutionDir(appConfig)}/.server-modules`,
|
|
38
|
+
externalPackages: true,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type AssetDefinition, type ProcessedAsset } from '../../../services/assets/asset-processing-service/index.js';
|
|
2
|
+
export type CustomElementSsrPreloadEntrypointResolverOptions = {
|
|
3
|
+
preferSourceImports: boolean;
|
|
4
|
+
processDependencies?: (dependencies: AssetDefinition[], integrationName: string) => Promise<ProcessedAsset[]>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Resolves SSR script paths through the asset pipeline so preload imports share
|
|
8
|
+
* the renderer dependency graph instead of an isolated app-module bundle.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createCustomElementSsrPreloadEntrypointResolver({ preferSourceImports, processDependencies, }: CustomElementSsrPreloadEntrypointResolverOptions): (scriptPath: string) => Promise<string>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AssetFactory, } from '../../../services/assets/asset-processing-service/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves SSR script paths through the asset pipeline so preload imports share
|
|
4
|
+
* the renderer dependency graph instead of an isolated app-module bundle.
|
|
5
|
+
*/
|
|
6
|
+
export function createCustomElementSsrPreloadEntrypointResolver({ preferSourceImports, processDependencies, }) {
|
|
7
|
+
const entrypointCache = new Map();
|
|
8
|
+
return async (scriptPath) => {
|
|
9
|
+
const cachedEntrypoint = entrypointCache.get(scriptPath);
|
|
10
|
+
if (cachedEntrypoint) {
|
|
11
|
+
return cachedEntrypoint;
|
|
12
|
+
}
|
|
13
|
+
if (preferSourceImports) {
|
|
14
|
+
entrypointCache.set(scriptPath, scriptPath);
|
|
15
|
+
return scriptPath;
|
|
16
|
+
}
|
|
17
|
+
if (!processDependencies) {
|
|
18
|
+
entrypointCache.set(scriptPath, scriptPath);
|
|
19
|
+
return scriptPath;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const processed = await processDependencies([
|
|
23
|
+
AssetFactory.createInlineFileScript({
|
|
24
|
+
filepath: scriptPath,
|
|
25
|
+
excludeFromHtml: true,
|
|
26
|
+
position: 'head',
|
|
27
|
+
bundle: true,
|
|
28
|
+
attributes: {
|
|
29
|
+
type: 'module',
|
|
30
|
+
defer: '',
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
], `custom-element-ssr-preload:${scriptPath}`);
|
|
34
|
+
const entrypoint = processed[0]?.filepath ?? scriptPath;
|
|
35
|
+
entrypointCache.set(scriptPath, entrypoint);
|
|
36
|
+
return entrypoint;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (process.env.ECOPAGES_DEBUG === 'true') {
|
|
40
|
+
console.warn(`[ecopages] Failed to resolve custom-element SSR preload entrypoint for: ${scriptPath}`, error);
|
|
41
|
+
}
|
|
42
|
+
entrypointCache.set(scriptPath, scriptPath);
|
|
43
|
+
return scriptPath;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -219,6 +219,9 @@ export declare abstract class IntegrationRenderer<C = EcoPagesElement> {
|
|
|
219
219
|
transformDocumentHtml?: (html: string) => string;
|
|
220
220
|
foreignChildRoots?: ReadonlyArray<EcoComponent | Partial<EcoComponent>>;
|
|
221
221
|
}): Promise<string>;
|
|
222
|
+
private serializeStringRenderChildren;
|
|
223
|
+
private assertStringRenderChildren;
|
|
224
|
+
private assertStringRenderContent;
|
|
222
225
|
protected renderStringComponentWithSerializedChildren(input: ComponentRenderInput, component: (props: Record<string, unknown>) => Promise<EcoPagesElement> | EcoPagesElement): Promise<ComponentRenderResult>;
|
|
223
226
|
/**
|
|
224
227
|
* Renders a string-first component, then resolves any queued foreign
|
|
@@ -366,26 +366,40 @@ export class IntegrationRenderer {
|
|
|
366
366
|
appendProcessedDependencies: (...assetGroups) => this.appendProcessedDependencies(...assetGroups),
|
|
367
367
|
}, input, this.DOC_TYPE);
|
|
368
368
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
369
|
+
serializeStringRenderChildren(children) {
|
|
370
|
+
if (children === undefined) {
|
|
371
|
+
return undefined;
|
|
372
|
+
}
|
|
373
|
+
if (typeof children === 'string') {
|
|
374
|
+
return children;
|
|
375
|
+
}
|
|
376
|
+
if (isMarkupNodeLike(children) && typeof children.outerHTML === 'string') {
|
|
377
|
+
return children.outerHTML;
|
|
378
|
+
}
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
assertStringRenderChildren(input, serializedChildren) {
|
|
382
|
+
if (input.children === undefined || serializedChildren !== undefined) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const componentFile = input.component.config?.identity?.file ?? 'unknown component';
|
|
386
|
+
const childTag = Object.prototype.toString.call(input.children);
|
|
387
|
+
throw new TypeError(`[ecopages] ${this.name} renderer expected serialized children for ${componentFile}, received ${childTag}.`);
|
|
388
|
+
}
|
|
389
|
+
assertStringRenderContent(input, content) {
|
|
390
|
+
if (typeof content === 'string') {
|
|
391
|
+
return;
|
|
381
392
|
}
|
|
393
|
+
const componentFile = input.component.config?.identity?.file ?? 'unknown component';
|
|
394
|
+
const contentTag = Object.prototype.toString.call(content);
|
|
395
|
+
throw new TypeError(`[ecopages] ${this.name} renderer expected a string render result for ${componentFile}, received ${contentTag}.`);
|
|
396
|
+
}
|
|
397
|
+
async renderStringComponentWithSerializedChildren(input, component) {
|
|
398
|
+
const serializedChildren = this.serializeStringRenderChildren(input.children);
|
|
399
|
+
this.assertStringRenderChildren(input, serializedChildren);
|
|
382
400
|
const props = serializedChildren === undefined ? input.props : { ...input.props, children: serializedChildren };
|
|
383
401
|
const content = await component(props);
|
|
384
|
-
|
|
385
|
-
const componentFile = input.component.config?.identity?.file ?? 'unknown component';
|
|
386
|
-
const contentTag = Object.prototype.toString.call(content);
|
|
387
|
-
throw new TypeError(`[ecopages] ${this.name} renderer expected a string render result for ${componentFile}, received ${contentTag}.`);
|
|
388
|
-
}
|
|
402
|
+
this.assertStringRenderContent(input, content);
|
|
389
403
|
const html = content;
|
|
390
404
|
const assets = input.component.config?.dependencies &&
|
|
391
405
|
typeof this.assetProcessingService?.processDependencies === 'function'
|
|
@@ -1,24 +1,57 @@
|
|
|
1
1
|
import { getComponentIdentity } from '../../../eco/component-identity.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
function visitComponentGraphConfig(config, parentIntegrationName, state, visitComponent) {
|
|
3
|
+
if (!config || state.seenConfigs.has(config)) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
state.seenConfigs.add(config);
|
|
7
|
+
if (state.onConfig) {
|
|
8
|
+
state.onConfig(config);
|
|
9
|
+
}
|
|
10
|
+
if (state.visitLayout) {
|
|
11
|
+
for (const layout of config.layouts ?? []) {
|
|
12
|
+
if (layout?.config) {
|
|
13
|
+
visitComponentGraphConfig(layout.config, parentIntegrationName, state, visitComponent);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
for (const child of config.dependencies?.components ?? []) {
|
|
18
|
+
visitComponent(child, parentIntegrationName, 'dependency');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function notifyComponentGraphConfig(config, state) {
|
|
22
|
+
if (!state.onConfig || !config || state.seenConfigs.has(config)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
state.seenConfigs.add(config);
|
|
26
|
+
state.onConfig(config);
|
|
27
|
+
}
|
|
28
|
+
function visitComponentGraphChildren(ecoComponent, integrationName, state, visitComponent) {
|
|
29
|
+
if (state.visitLayout) {
|
|
30
|
+
for (const layout of ecoComponent.config?.layouts ?? []) {
|
|
31
|
+
if (layout?.config) {
|
|
32
|
+
visitComponentGraphConfig(layout.config, integrationName, state, visitComponent);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
for (const child of ecoComponent.config?.dependencies?.components ?? []) {
|
|
37
|
+
visitComponent(child, integrationName, 'dependency');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function createComponentGraphVisitor(state) {
|
|
5
41
|
const visitComponent = (component, parentIntegrationName, source) => {
|
|
6
42
|
if (!component) {
|
|
7
43
|
return;
|
|
8
44
|
}
|
|
9
45
|
const ecoComponent = component;
|
|
10
|
-
if (seenComponents.has(ecoComponent)) {
|
|
46
|
+
if (state.seenComponents.has(ecoComponent)) {
|
|
11
47
|
return;
|
|
12
48
|
}
|
|
13
|
-
seenComponents.add(ecoComponent);
|
|
49
|
+
state.seenComponents.add(ecoComponent);
|
|
14
50
|
const identity = getComponentIdentity(ecoComponent);
|
|
15
51
|
const integrationName = ecoComponent.config?.integration ?? identity?.integration ?? parentIntegrationName;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
if (input.onComponent) {
|
|
21
|
-
const shouldContinue = input.onComponent({
|
|
52
|
+
notifyComponentGraphConfig(ecoComponent.config, state);
|
|
53
|
+
if (state.onComponent) {
|
|
54
|
+
const shouldContinue = state.onComponent({
|
|
22
55
|
component: ecoComponent,
|
|
23
56
|
parentIntegrationName,
|
|
24
57
|
source,
|
|
@@ -27,36 +60,19 @@ export function walkComponentGraph(input) {
|
|
|
27
60
|
return;
|
|
28
61
|
}
|
|
29
62
|
}
|
|
30
|
-
|
|
31
|
-
for (const layout of ecoComponent.config?.layouts ?? []) {
|
|
32
|
-
if (layout?.config) {
|
|
33
|
-
visitConfig(layout.config, integrationName);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
for (const child of ecoComponent.config?.dependencies?.components ?? []) {
|
|
38
|
-
visitComponent(child, integrationName, 'dependency');
|
|
39
|
-
}
|
|
63
|
+
visitComponentGraphChildren(ecoComponent, integrationName, state, visitComponent);
|
|
40
64
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (const layout of config.layouts ?? []) {
|
|
51
|
-
if (layout?.config) {
|
|
52
|
-
visitConfig(layout.config, parentIntegrationName);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
for (const child of config.dependencies?.components ?? []) {
|
|
57
|
-
visitComponent(child, parentIntegrationName, 'dependency');
|
|
58
|
-
}
|
|
65
|
+
return visitComponent;
|
|
66
|
+
}
|
|
67
|
+
export function walkComponentGraph(input) {
|
|
68
|
+
const state = {
|
|
69
|
+
seenComponents: new Set(),
|
|
70
|
+
seenConfigs: new Set(),
|
|
71
|
+
visitLayout: input.visitLayout,
|
|
72
|
+
onComponent: input.onComponent,
|
|
73
|
+
onConfig: input.onConfig,
|
|
59
74
|
};
|
|
75
|
+
const visitComponent = createComponentGraphVisitor(state);
|
|
60
76
|
for (const root of input.roots) {
|
|
61
77
|
visitComponent(root.component, input.currentIntegrationName, root.source);
|
|
62
78
|
}
|
|
@@ -42,6 +42,12 @@ export declare class PageBrowserGraphService {
|
|
|
42
42
|
private buildPageBrowserGraphRecord;
|
|
43
43
|
private materializePageBrowserGraph;
|
|
44
44
|
private resolveGroupedPageBrowserAssets;
|
|
45
|
+
private collectGroupedBuildPlanContributions;
|
|
46
|
+
private registerRouteGroupedDependencies;
|
|
47
|
+
private mergePeerGroupedContributions;
|
|
48
|
+
private addGroupedDependencyFilePaths;
|
|
49
|
+
private matchGroupedAssetsByRoute;
|
|
50
|
+
private addProcessedGroupedAssetDependencyPaths;
|
|
45
51
|
private buildGroupedPageBrowserAssets;
|
|
46
52
|
private partitionPageBrowserGraphAssets;
|
|
47
53
|
}
|
|
@@ -147,29 +147,36 @@ export class PageBrowserGraphService {
|
|
|
147
147
|
cacheable: groupedCacheable,
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
collectGroupedBuildPlanContributions(input) {
|
|
151
|
+
if (!input.groupedBuildPlan) {
|
|
152
|
+
return { contributions: [], hasCollectionFailures: false };
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
contributions: input.groupedBuildPlan.instances.map((instance) => ({
|
|
156
|
+
routeFile: instance.routeFile,
|
|
157
|
+
dependencyInstanceKey: instance.dependencyInstanceKey,
|
|
158
|
+
contribution: instance.contribution,
|
|
159
|
+
})),
|
|
160
|
+
hasCollectionFailures: false,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
registerRouteGroupedDependencies(routeLookupKey, routeFile, routeGroupedDependencies, groupedDependencies, groupedAssetKeysByRoute, routeDisplayPaths, dependencyPaths) {
|
|
164
|
+
if (routeGroupedDependencies.length === 0) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
groupedDependencies.push(...routeGroupedDependencies);
|
|
168
|
+
groupedAssetKeysByRoute.set(routeLookupKey, new Set(routeGroupedDependencies.map((dep) => getGroupedBundleAssetKey(dep.groupedBundle))));
|
|
169
|
+
routeDisplayPaths.set(routeLookupKey, routeFile);
|
|
170
|
+
dependencyPaths.add(path.resolve(routeFile));
|
|
171
|
+
}
|
|
172
|
+
mergePeerGroupedContributions(input, currentContribution, groupedContributions, hasCollectionFailures) {
|
|
151
173
|
const dependencyInstanceKey = input.dependencyInstanceKey ?? '';
|
|
152
174
|
const currentRouteLookupKey = createRouteGraphLookupKey(input.routeFile, dependencyInstanceKey);
|
|
153
|
-
const groupedCollection = input.groupedBuildPlan
|
|
154
|
-
? {
|
|
155
|
-
contributions: input.groupedBuildPlan.instances.map((instance) => ({
|
|
156
|
-
routeFile: instance.routeFile,
|
|
157
|
-
dependencyInstanceKey: instance.dependencyInstanceKey,
|
|
158
|
-
contribution: instance.contribution,
|
|
159
|
-
})),
|
|
160
|
-
hasCollectionFailures: false,
|
|
161
|
-
}
|
|
162
|
-
: {
|
|
163
|
-
contributions: [],
|
|
164
|
-
hasCollectionFailures: false,
|
|
165
|
-
};
|
|
166
|
-
const groupedContributions = groupedCollection.contributions;
|
|
167
175
|
const currentRouteGroupedDependencies = (currentContribution.dependencies ?? []).filter((dep) => isGroupedContentScriptAsset(dep));
|
|
168
176
|
const groupedDependencies = [...currentRouteGroupedDependencies];
|
|
169
177
|
const groupedAssetKeysByRoute = new Map();
|
|
170
178
|
const routeDisplayPaths = new Map();
|
|
171
179
|
const dependencyPaths = new Set([path.resolve(input.routeFile)]);
|
|
172
|
-
let hasCollectionFailures = groupedCollection.hasCollectionFailures;
|
|
173
180
|
if (currentRouteGroupedDependencies.length > 0) {
|
|
174
181
|
groupedAssetKeysByRoute.set(currentRouteLookupKey, new Set(currentRouteGroupedDependencies.map((dep) => getGroupedBundleAssetKey(dep.groupedBundle))));
|
|
175
182
|
routeDisplayPaths.set(currentRouteLookupKey, input.routeFile);
|
|
@@ -184,40 +191,38 @@ export class PageBrowserGraphService {
|
|
|
184
191
|
continue;
|
|
185
192
|
}
|
|
186
193
|
const routeGroupedDependencies = contribution.dependencies.filter((dep) => isGroupedContentScriptAsset(dep));
|
|
187
|
-
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
groupedDependencies.push(...routeGroupedDependencies);
|
|
191
|
-
groupedAssetKeysByRoute.set(createRouteGraphLookupKey(routeFile, groupedContribution.dependencyInstanceKey), new Set(routeGroupedDependencies.map((dep) => getGroupedBundleAssetKey(dep.groupedBundle))));
|
|
192
|
-
routeDisplayPaths.set(createRouteGraphLookupKey(routeFile, groupedContribution.dependencyInstanceKey), routeFile);
|
|
193
|
-
dependencyPaths.add(path.resolve(routeFile));
|
|
194
|
-
}
|
|
195
|
-
if (groupedDependencies.length === 0) {
|
|
196
|
-
return {
|
|
197
|
-
assetsByRoute: new Map(),
|
|
198
|
-
dependencyPaths,
|
|
199
|
-
hasCollectionFailures,
|
|
200
|
-
cacheable: Boolean(input.groupedBuildPlan) && !hasCollectionFailures,
|
|
201
|
-
};
|
|
194
|
+
this.registerRouteGroupedDependencies(createRouteGraphLookupKey(routeFile, groupedContribution.dependencyInstanceKey), routeFile, routeGroupedDependencies, groupedDependencies, groupedAssetKeysByRoute, routeDisplayPaths, dependencyPaths);
|
|
202
195
|
}
|
|
196
|
+
return {
|
|
197
|
+
groupedDependencies,
|
|
198
|
+
groupedAssetKeysByRoute,
|
|
199
|
+
routeDisplayPaths,
|
|
200
|
+
dependencyPaths,
|
|
201
|
+
hasCollectionFailures,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
addGroupedDependencyFilePaths(groupedDependencies, dependencyPaths) {
|
|
203
205
|
for (const dependency of groupedDependencies) {
|
|
204
206
|
if (dependency.source === 'file') {
|
|
205
207
|
dependencyPaths.add(path.resolve(dependency.filepath));
|
|
206
208
|
}
|
|
207
209
|
}
|
|
208
|
-
|
|
210
|
+
}
|
|
211
|
+
matchGroupedAssetsByRoute(groupedAssetKeysByRoute, routeDisplayPaths, groupedAssetsByBundleKey) {
|
|
209
212
|
const groupedAssetsByRoute = new Map();
|
|
210
|
-
const
|
|
211
|
-
for (const [routeFile, groupedAssetKeys] of groupedAssetKeysByRoute) {
|
|
213
|
+
for (const [routeLookupKey, groupedAssetKeys] of groupedAssetKeysByRoute) {
|
|
212
214
|
const matchedAssets = [...groupedAssetKeys]
|
|
213
215
|
.flatMap((assetKey) => groupedAssetsByBundleKey.get(assetKey) ?? [])
|
|
214
216
|
.sort((left, right) => left.index - right.index)
|
|
215
217
|
.map(({ asset }) => asset);
|
|
216
218
|
if (groupedAssetKeys.size > 0 && matchedAssets.length === 0) {
|
|
217
|
-
appLogger.warn(`Grouped page-browser assets for ${routeDisplayPaths.get(
|
|
219
|
+
appLogger.warn(`Grouped page-browser assets for ${routeDisplayPaths.get(routeLookupKey) ?? routeLookupKey} are missing groupedBundle metadata after processing. Hydration scripts may be omitted from HTML.`);
|
|
218
220
|
}
|
|
219
|
-
groupedAssetsByRoute.set(
|
|
221
|
+
groupedAssetsByRoute.set(routeLookupKey, matchedAssets);
|
|
220
222
|
}
|
|
223
|
+
return groupedAssetsByRoute;
|
|
224
|
+
}
|
|
225
|
+
addProcessedGroupedAssetDependencyPaths(processedGroupedDependencies, dependencyPaths) {
|
|
221
226
|
for (const asset of processedGroupedDependencies) {
|
|
222
227
|
if (asset.sourceFilepath) {
|
|
223
228
|
dependencyPaths.add(path.resolve(asset.sourceFilepath));
|
|
@@ -226,6 +231,24 @@ export class PageBrowserGraphService {
|
|
|
226
231
|
dependencyPaths.add(path.resolve(bundledSourceFilepath));
|
|
227
232
|
}
|
|
228
233
|
}
|
|
234
|
+
}
|
|
235
|
+
async buildGroupedPageBrowserAssets(input, currentContribution) {
|
|
236
|
+
const groupedCollection = this.collectGroupedBuildPlanContributions(input);
|
|
237
|
+
const merged = this.mergePeerGroupedContributions(input, currentContribution, groupedCollection.contributions, groupedCollection.hasCollectionFailures);
|
|
238
|
+
const { groupedDependencies, groupedAssetKeysByRoute, routeDisplayPaths, dependencyPaths, hasCollectionFailures, } = merged;
|
|
239
|
+
if (groupedDependencies.length === 0) {
|
|
240
|
+
return {
|
|
241
|
+
assetsByRoute: new Map(),
|
|
242
|
+
dependencyPaths,
|
|
243
|
+
hasCollectionFailures,
|
|
244
|
+
cacheable: Boolean(input.groupedBuildPlan) && !hasCollectionFailures,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
this.addGroupedDependencyFilePaths(groupedDependencies, dependencyPaths);
|
|
248
|
+
const processedGroupedDependencies = await this.assetProcessingService.processDependencies(groupedDependencies, `${input.integrationName}:grouped-page-browser-graph`);
|
|
249
|
+
const groupedAssetsByBundleKey = indexGroupedAssetsByBundleKey(processedGroupedDependencies);
|
|
250
|
+
const groupedAssetsByRoute = this.matchGroupedAssetsByRoute(groupedAssetKeysByRoute, routeDisplayPaths, groupedAssetsByBundleKey);
|
|
251
|
+
this.addProcessedGroupedAssetDependencyPaths(processedGroupedDependencies, dependencyPaths);
|
|
229
252
|
return {
|
|
230
253
|
assetsByRoute: groupedAssetsByRoute,
|
|
231
254
|
dependencyPaths,
|