@ecopages/core 0.2.0-rc.6 → 0.2.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- 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/declarations.d.ts +10 -1
- 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/islands/README.md +5 -1
- 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 +3 -2
- 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 +68 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +183 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +9 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +22 -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/foreign-child/foreign-subtree-execution.service.d.ts +3 -2
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +1 -1
- package/src/route-renderer/orchestration/integration-renderer.d.ts +7 -3
- package/src/route-renderer/orchestration/integration-renderer.js +34 -20
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +1 -1
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -2
- 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 +3 -2
- package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
- package/src/route-renderer/orchestration/string-markup-renderer.js +2 -1
- 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 +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 +2 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +6 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +24 -5
- 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/types/internal-types.d.ts +5 -1
- 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
|
@@ -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,
|
|
@@ -88,11 +88,12 @@ export class RouteRenderOrchestrator {
|
|
|
88
88
|
dependencyInstanceKey,
|
|
89
89
|
});
|
|
90
90
|
const resolvedPageDependencyComponents = resolvedPageDependencies?.components ?? [];
|
|
91
|
+
const dependencyRoots = [...componentsToResolve, ...resolvedPageDependencyComponents];
|
|
91
92
|
const allDependencies = [
|
|
92
93
|
...resolvedDependencies,
|
|
93
|
-
...collectUsedIntegrationDependenciesFromGraph(this.appConfig,
|
|
94
|
+
...collectUsedIntegrationDependenciesFromGraph(this.appConfig, dependencyRoots, adapter.name),
|
|
94
95
|
];
|
|
95
|
-
const triggers = collectResolvedLazyTriggersFromGraph(
|
|
96
|
+
const triggers = collectResolvedLazyTriggersFromGraph(dependencyRoots, adapter.name);
|
|
96
97
|
const globalAssets = triggers.length > 0
|
|
97
98
|
? await buildGlobalInjectorAssets(this.appConfig, this.assetProcessingService, triggers, adapter.name)
|
|
98
99
|
: [];
|
|
@@ -9,6 +9,6 @@ import { IntegrationRenderer, type RenderToResponseContext } from './integration
|
|
|
9
9
|
*/
|
|
10
10
|
export declare abstract class StringMarkupRenderer extends IntegrationRenderer<EcoPagesElement> {
|
|
11
11
|
renderComponent(input: ComponentRenderInput): Promise<ComponentRenderResult>;
|
|
12
|
-
render({ params, query, props, locals, pageLocals, metadata, Page, Layout, layoutEntries, HtmlTemplate, pageProps, }: IntegrationRendererRenderOptions): Promise<RouteRendererBody>;
|
|
12
|
+
render({ params, query, props, locals, pageLocals, metadata, Page, Layout, layoutEntries, HtmlTemplate, pageProps, resolvedPageDependencyComponents, }: IntegrationRendererRenderOptions): Promise<RouteRendererBody>;
|
|
13
13
|
renderToResponse<P = Record<string, unknown>>(view: EcoComponent<P>, props: P, ctx: RenderToResponseContext): Promise<Response>;
|
|
14
14
|
}
|
|
@@ -14,7 +14,7 @@ export class StringMarkupRenderer extends IntegrationRenderer {
|
|
|
14
14
|
}
|
|
15
15
|
return this.renderStringComponentWithQueuedForeignSubtrees(input, input.component);
|
|
16
16
|
}
|
|
17
|
-
async render({ params, query, props, locals, pageLocals, metadata, Page, Layout, layoutEntries, HtmlTemplate, pageProps, }) {
|
|
17
|
+
async render({ params, query, props, locals, pageLocals, metadata, Page, Layout, layoutEntries, HtmlTemplate, pageProps, resolvedPageDependencyComponents, }) {
|
|
18
18
|
try {
|
|
19
19
|
return await this.renderPageWithDocumentShell({
|
|
20
20
|
page: {
|
|
@@ -31,6 +31,7 @@ export class StringMarkupRenderer extends IntegrationRenderer {
|
|
|
31
31
|
htmlTemplate: HtmlTemplate,
|
|
32
32
|
metadata,
|
|
33
33
|
pageProps: pageProps ?? props ?? {},
|
|
34
|
+
foreignChildRoots: resolvedPageDependencyComponents,
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
catch (error) {
|
|
@@ -30,6 +30,84 @@ function pushUniqueDependency(keys, key, dependencies, dependency) {
|
|
|
30
30
|
function resolveDependencyPath(componentDir, pathUrl) {
|
|
31
31
|
return path.isAbsolute(pathUrl) ? pathUrl : path.join(componentDir, pathUrl);
|
|
32
32
|
}
|
|
33
|
+
function createLazyScriptRegistrar(config, lazyScriptsByConfig) {
|
|
34
|
+
return ({ lazy, lazyKey, fallbackUrl }) => {
|
|
35
|
+
let grouped = lazyScriptsByConfig.get(config);
|
|
36
|
+
if (!grouped) {
|
|
37
|
+
grouped = new Map();
|
|
38
|
+
lazyScriptsByConfig.set(config, grouped);
|
|
39
|
+
}
|
|
40
|
+
const triggerKey = getLazyTriggerKey(lazy);
|
|
41
|
+
const existing = grouped.get(triggerKey) ?? { lazy, scripts: [] };
|
|
42
|
+
existing.scripts.push({ lazyKey, fallbackUrl });
|
|
43
|
+
grouped.set(triggerKey, existing);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function recordExplicitAndInferredStyles(config, dir, context) {
|
|
47
|
+
const dependenciesConfig = config.dependencies;
|
|
48
|
+
const explicitStyles = dependenciesConfig?.stylesheets ?? [];
|
|
49
|
+
for (const style of explicitStyles) {
|
|
50
|
+
const src = typeof style === 'string' ? style : style.src;
|
|
51
|
+
if (src)
|
|
52
|
+
context.explicitStylePaths.add(resolveDependencyPath(dir, src));
|
|
53
|
+
}
|
|
54
|
+
for (const src of getInferredStylesheets(config)) {
|
|
55
|
+
context.inferredStyles.push({ dir, src });
|
|
56
|
+
}
|
|
57
|
+
return explicitStyles;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Recursively visits one component config and its declared child dependencies.
|
|
61
|
+
*/
|
|
62
|
+
function collectComponentConfigDependencies(config, context) {
|
|
63
|
+
if (!config || context.visited.has(config))
|
|
64
|
+
return;
|
|
65
|
+
context.visited.add(config);
|
|
66
|
+
const file = getComponentIdentity(config)?.file;
|
|
67
|
+
if (!file)
|
|
68
|
+
return;
|
|
69
|
+
const dir = path.dirname(file);
|
|
70
|
+
const explicitStyles = recordExplicitAndInferredStyles(config, dir, context);
|
|
71
|
+
const dependenciesConfig = config.dependencies;
|
|
72
|
+
const registerLazyScript = createLazyScriptRegistrar(config, context.lazyScriptsByConfig);
|
|
73
|
+
collectDeclaredAssetEntries({
|
|
74
|
+
stylesheetEntries: explicitStyles,
|
|
75
|
+
scriptEntries: dependenciesConfig?.scripts ?? [],
|
|
76
|
+
componentDir: dir,
|
|
77
|
+
dependencies: context.dependencies,
|
|
78
|
+
stylesheetDependencyKeys: context.stylesheetDependencyKeys,
|
|
79
|
+
scriptDependencyKeys: context.scriptDependencyKeys,
|
|
80
|
+
resolveDependencyPath,
|
|
81
|
+
createModuleScriptAttributes,
|
|
82
|
+
pushUniqueDependency,
|
|
83
|
+
getInvalidStylesheetEntryMessage: () => context.errors.invalidStylesheetEntry,
|
|
84
|
+
getInvalidScriptEntryMessage: () => context.errors.invalidScriptEntry,
|
|
85
|
+
});
|
|
86
|
+
collectModuleDeclarations(context.modulesMap, dependenciesConfig?.modules, extractEcopagesVirtualImports(file));
|
|
87
|
+
collectLazyScriptEntries({
|
|
88
|
+
scriptEntries: dependenciesConfig?.scripts ?? [],
|
|
89
|
+
componentFile: file,
|
|
90
|
+
componentDir: dir,
|
|
91
|
+
integrationName: context.integrationName,
|
|
92
|
+
dependencies: context.dependencies,
|
|
93
|
+
lazyDependencyKeys: context.lazyDependencyKeys,
|
|
94
|
+
registerLazyScript,
|
|
95
|
+
resolveDependencyPath,
|
|
96
|
+
resolveLazyScripts: context.resolveLazyScripts,
|
|
97
|
+
createModuleScriptAttributes,
|
|
98
|
+
createEcopagesJsxLazyEntryName: context.createEcopagesJsxLazyEntryName,
|
|
99
|
+
pushUniqueDependency,
|
|
100
|
+
getLazyScriptMissingSrcMessage: () => context.errors.lazyScriptMissingSrc,
|
|
101
|
+
isEcopagesJsxIntegration: context.isEcopagesJsxIntegration,
|
|
102
|
+
});
|
|
103
|
+
for (const nestedComponent of dependenciesConfig?.components ?? []) {
|
|
104
|
+
if (!nestedComponent) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
assertEcoDeclaredComponent(nestedComponent, { parentComponentFile: file });
|
|
108
|
+
collectComponentConfigDependencies(nestedComponent.config, context);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
33
111
|
/**
|
|
34
112
|
* Walks component dependency trees and collects declared assets, module declarations,
|
|
35
113
|
* and lazy-script group metadata in one pass.
|
|
@@ -55,81 +133,24 @@ export function collectComponentDependencies(options) {
|
|
|
55
133
|
const componentFile = getComponentIdentity(component)?.file;
|
|
56
134
|
if (!componentFile)
|
|
57
135
|
continue;
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
visited
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const explicitStyles = dependenciesConfig?.stylesheets ?? [];
|
|
74
|
-
for (const style of explicitStyles) {
|
|
75
|
-
const src = typeof style === 'string' ? style : style.src;
|
|
76
|
-
if (src)
|
|
77
|
-
explicitStylePaths.add(resolveDependencyPath(dir, src));
|
|
78
|
-
}
|
|
79
|
-
for (const src of getInferredStylesheets(config))
|
|
80
|
-
inferredStyles.push({ dir, src });
|
|
81
|
-
const registerLazyScript = ({ lazy, lazyKey, fallbackUrl, }) => {
|
|
82
|
-
let grouped = lazyScriptsByConfig.get(config);
|
|
83
|
-
if (!grouped) {
|
|
84
|
-
grouped = new Map();
|
|
85
|
-
lazyScriptsByConfig.set(config, grouped);
|
|
86
|
-
}
|
|
87
|
-
const triggerKey = getLazyTriggerKey(lazy);
|
|
88
|
-
const existing = grouped.get(triggerKey) ?? { lazy, scripts: [] };
|
|
89
|
-
existing.scripts.push({ lazyKey, fallbackUrl });
|
|
90
|
-
grouped.set(triggerKey, existing);
|
|
91
|
-
};
|
|
92
|
-
collectDeclaredAssetEntries({
|
|
93
|
-
stylesheetEntries: explicitStyles,
|
|
94
|
-
scriptEntries: dependenciesConfig?.scripts ?? [],
|
|
95
|
-
componentDir: dir,
|
|
96
|
-
dependencies,
|
|
97
|
-
stylesheetDependencyKeys,
|
|
98
|
-
scriptDependencyKeys,
|
|
99
|
-
resolveDependencyPath,
|
|
100
|
-
createModuleScriptAttributes,
|
|
101
|
-
pushUniqueDependency,
|
|
102
|
-
getInvalidStylesheetEntryMessage: () => errors.invalidStylesheetEntry,
|
|
103
|
-
getInvalidScriptEntryMessage: () => errors.invalidScriptEntry,
|
|
104
|
-
});
|
|
105
|
-
collectModuleDeclarations(modulesMap, dependenciesConfig?.modules, extractEcopagesVirtualImports(file));
|
|
106
|
-
collectLazyScriptEntries({
|
|
107
|
-
scriptEntries: dependenciesConfig?.scripts ?? [],
|
|
108
|
-
componentFile: file,
|
|
109
|
-
componentDir: dir,
|
|
110
|
-
integrationName,
|
|
111
|
-
dependencies,
|
|
112
|
-
lazyDependencyKeys,
|
|
113
|
-
registerLazyScript,
|
|
114
|
-
resolveDependencyPath,
|
|
115
|
-
resolveLazyScripts,
|
|
116
|
-
createModuleScriptAttributes,
|
|
117
|
-
createEcopagesJsxLazyEntryName,
|
|
118
|
-
pushUniqueDependency,
|
|
119
|
-
getLazyScriptMissingSrcMessage: () => errors.lazyScriptMissingSrc,
|
|
120
|
-
isEcopagesJsxIntegration,
|
|
121
|
-
});
|
|
122
|
-
if (dependenciesConfig?.components) {
|
|
123
|
-
for (const nestedComponent of dependenciesConfig.components) {
|
|
124
|
-
if (!nestedComponent) {
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
assertEcoDeclaredComponent(nestedComponent, { parentComponentFile: file });
|
|
128
|
-
collect(nestedComponent.config);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
136
|
+
const collectionContext = {
|
|
137
|
+
integrationName,
|
|
138
|
+
resolveLazyScripts,
|
|
139
|
+
createEcopagesJsxLazyEntryName,
|
|
140
|
+
isEcopagesJsxIntegration,
|
|
141
|
+
errors,
|
|
142
|
+
dependencies,
|
|
143
|
+
lazyScriptsByConfig,
|
|
144
|
+
lazyDependencyKeys,
|
|
145
|
+
visited,
|
|
146
|
+
inferredStyles,
|
|
147
|
+
explicitStylePaths,
|
|
148
|
+
stylesheetDependencyKeys: new Set(),
|
|
149
|
+
scriptDependencyKeys: new Set(),
|
|
150
|
+
modulesMap: new Map(),
|
|
131
151
|
};
|
|
132
|
-
|
|
152
|
+
collectComponentConfigDependencies(component.config, collectionContext);
|
|
153
|
+
const { modulesMap } = collectionContext;
|
|
133
154
|
dependencies.push(...Array.from(modulesMap.entries()).map(([from, importsSet]) => {
|
|
134
155
|
const imports = importsSet ? Array.from(importsSet) : undefined;
|
|
135
156
|
return AssetFactory.createContentScript({
|
|
@@ -4,6 +4,46 @@ import { parseModuleSource } from '../../cache/module-parse-cache.js';
|
|
|
4
4
|
export function isBrowserEcopagesVirtualImport(specifier) {
|
|
5
5
|
return specifier.startsWith('ecopages:') && !isContentServerVirtualModule(specifier);
|
|
6
6
|
}
|
|
7
|
+
function getNamedImportFromSpecifier(spec) {
|
|
8
|
+
if (spec.type !== 'ImportSpecifier') {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
let importedName = spec.local?.name;
|
|
12
|
+
if (spec.imported?.type === 'Identifier') {
|
|
13
|
+
importedName = spec.imported.name;
|
|
14
|
+
}
|
|
15
|
+
else if (spec.imported?.type === 'Literal') {
|
|
16
|
+
importedName = spec.imported.value;
|
|
17
|
+
}
|
|
18
|
+
return importedName;
|
|
19
|
+
}
|
|
20
|
+
function collectNamedImportsFromDeclaration(node) {
|
|
21
|
+
const namedImports = [];
|
|
22
|
+
for (const spec of node.specifiers ?? []) {
|
|
23
|
+
const importedName = getNamedImportFromSpecifier(spec);
|
|
24
|
+
if (importedName) {
|
|
25
|
+
namedImports.push(importedName);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return namedImports;
|
|
29
|
+
}
|
|
30
|
+
function recordVirtualImport(found, specifier, namedImports) {
|
|
31
|
+
if (found.get(specifier) === null) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (namedImports.length === 0) {
|
|
35
|
+
found.set(specifier, null);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const existing = found.get(specifier);
|
|
39
|
+
if (!existing) {
|
|
40
|
+
found.set(specifier, new Set(namedImports));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
for (const imported of namedImports) {
|
|
44
|
+
existing.add(imported);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
7
47
|
/**
|
|
8
48
|
* Extracts runtime `ecopages:` virtual-module imports from a component source file.
|
|
9
49
|
*
|
|
@@ -34,34 +74,7 @@ export function extractEcopagesVirtualImports(file) {
|
|
|
34
74
|
const specifier = node.source?.value ?? '';
|
|
35
75
|
if (!isBrowserEcopagesVirtualImport(specifier))
|
|
36
76
|
continue;
|
|
37
|
-
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const namedImports = [];
|
|
41
|
-
for (const spec of node.specifiers ?? []) {
|
|
42
|
-
if (spec.type === 'ImportSpecifier') {
|
|
43
|
-
let importedName = spec.local?.name;
|
|
44
|
-
if (spec.imported?.type === 'Identifier') {
|
|
45
|
-
importedName = spec.imported.name;
|
|
46
|
-
}
|
|
47
|
-
else if (spec.imported?.type === 'Literal') {
|
|
48
|
-
importedName = spec.imported.value;
|
|
49
|
-
}
|
|
50
|
-
namedImports.push(importedName);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (namedImports.length === 0) {
|
|
54
|
-
found.set(specifier, null);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
const existing = found.get(specifier);
|
|
58
|
-
if (!existing) {
|
|
59
|
-
found.set(specifier, new Set(namedImports));
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
for (const imported of namedImports) {
|
|
63
|
-
existing.add(imported);
|
|
64
|
-
}
|
|
77
|
+
recordVirtualImport(found, specifier, collectNamedImportsFromDeclaration(node));
|
|
65
78
|
}
|
|
66
79
|
return Array.from(found.entries()).map(([from, importsSet]) => ({
|
|
67
80
|
from,
|
|
@@ -34,9 +34,6 @@ export type CollectComponentConfigFilePathsOptions = {
|
|
|
34
34
|
includeLayouts?: boolean;
|
|
35
35
|
includeStylesheets?: boolean;
|
|
36
36
|
};
|
|
37
|
-
/**
|
|
38
|
-
* Walks component configs and collects identity files, stylesheets, and discovered barrel hops.
|
|
39
|
-
*/
|
|
40
37
|
export declare function collectComponentConfigFilePaths(components: ReadonlyArray<EcoComponent | Partial<EcoComponent> | undefined>, options?: CollectComponentConfigFilePathsOptions): Set<string>;
|
|
41
38
|
/**
|
|
42
39
|
* Collects source files that should invalidate a per-instance browser graph entry.
|
|
@@ -62,6 +62,42 @@ export function collectPageDependencyComponents(options) {
|
|
|
62
62
|
/**
|
|
63
63
|
* Walks component configs and collects identity files, stylesheets, and discovered barrel hops.
|
|
64
64
|
*/
|
|
65
|
+
function collectStylesheetPathsForConfig(config, resolvedOwnerFile, files) {
|
|
66
|
+
for (const style of config.dependencies?.stylesheets ?? []) {
|
|
67
|
+
const src = typeof style === 'string' ? style : style.src;
|
|
68
|
+
if (src)
|
|
69
|
+
files.add(path.resolve(path.dirname(resolvedOwnerFile), src));
|
|
70
|
+
}
|
|
71
|
+
for (const src of getInferredStylesheets(config)) {
|
|
72
|
+
files.add(path.resolve(path.dirname(resolvedOwnerFile), src));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function visitNestedComponentConfigFilePaths(config, options, visit) {
|
|
76
|
+
for (const dependency of config.dependencies?.components ?? []) {
|
|
77
|
+
visit(dependency?.config);
|
|
78
|
+
}
|
|
79
|
+
if (!options?.includeLayouts) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const layout of config.layouts ?? []) {
|
|
83
|
+
visit(layout?.config);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function visitComponentConfigFilePaths(config, options, files, visited, visit) {
|
|
87
|
+
const file = getComponentIdentity(config)?.file;
|
|
88
|
+
if (!file || !config || visited.has(config)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
visited.add(config);
|
|
92
|
+
files.add(path.resolve(file));
|
|
93
|
+
if (options?.includeStylesheets) {
|
|
94
|
+
collectStylesheetPathsForConfig(config, path.resolve(file), files);
|
|
95
|
+
}
|
|
96
|
+
for (const watchFile of getDiscoveredWatchFiles(config)) {
|
|
97
|
+
files.add(path.resolve(watchFile));
|
|
98
|
+
}
|
|
99
|
+
visitNestedComponentConfigFilePaths(config, options, visit);
|
|
100
|
+
}
|
|
65
101
|
export function collectComponentConfigFilePaths(components, options) {
|
|
66
102
|
const files = new Set();
|
|
67
103
|
const visited = new Set();
|
|
@@ -69,40 +105,7 @@ export function collectComponentConfigFilePaths(components, options) {
|
|
|
69
105
|
files.add(path.resolve(additionalPath));
|
|
70
106
|
}
|
|
71
107
|
const visit = (config) => {
|
|
72
|
-
|
|
73
|
-
if (!file) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (!config) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const resolved = path.resolve(file);
|
|
80
|
-
if (visited.has(config)) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
visited.add(config);
|
|
84
|
-
files.add(resolved);
|
|
85
|
-
for (const style of options?.includeStylesheets ? (config.dependencies?.stylesheets ?? []) : []) {
|
|
86
|
-
const src = typeof style === 'string' ? style : style.src;
|
|
87
|
-
if (src)
|
|
88
|
-
files.add(path.resolve(path.dirname(resolved), src));
|
|
89
|
-
}
|
|
90
|
-
if (options?.includeStylesheets) {
|
|
91
|
-
for (const src of getInferredStylesheets(config)) {
|
|
92
|
-
files.add(path.resolve(path.dirname(resolved), src));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
for (const watchFile of getDiscoveredWatchFiles(config)) {
|
|
96
|
-
files.add(path.resolve(watchFile));
|
|
97
|
-
}
|
|
98
|
-
for (const dependency of config.dependencies?.components ?? []) {
|
|
99
|
-
visit(dependency?.config);
|
|
100
|
-
}
|
|
101
|
-
if (options?.includeLayouts) {
|
|
102
|
-
for (const layout of config.layouts ?? []) {
|
|
103
|
-
visit(layout?.config);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
108
|
+
visitComponentConfigFilePaths(config, options, files, visited, visit);
|
|
106
109
|
};
|
|
107
110
|
for (const component of components) {
|
|
108
111
|
visit(component?.config);
|