@ecopages/core 0.3.2 → 0.5.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 +19 -3
- package/package.json +3 -3
- package/src/adapters/node/create-app.d.ts +19 -19
- package/src/adapters/node/create-app.js +26 -40
- package/src/adapters/node/dev-session.d.ts +3 -1
- package/src/adapters/node/dev-session.js +4 -1
- package/src/adapters/node/server-adapter.js +5 -1
- package/src/adapters/shared/http/api-request-pipeline.js +2 -2
- package/src/adapters/shared/http/define-api-handler.d.ts +41 -26
- package/src/adapters/shared/http/define-api-handler.js +15 -1
- package/src/adapters/shared/http/endpoint-route-handler.d.ts +46 -0
- package/src/adapters/shared/http/endpoint-route-handler.js +96 -0
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +20 -3
- package/src/adapters/shared/runtime/server-request-pipeline.js +46 -12
- package/src/adapters/shared/runtime/server-route-handler.d.ts +8 -3
- package/src/adapters/shared/runtime/server-route-handler.js +16 -10
- package/src/adapters/shared/runtime/server-static-builder.d.ts +14 -1
- package/src/adapters/shared/runtime/server-static-builder.js +13 -2
- package/src/assets/app-browser-client-build.js +8 -21
- package/src/assets/app-browser-client-manifest.d.ts +0 -1
- package/src/assets/app-browser-client-manifest.js +1 -20
- package/src/build/contracts/content-virtual-modules.d.ts +9 -3
- package/src/build/contracts/content-virtual-modules.js +11 -5
- package/src/build/contracts.d.ts +1 -1
- package/src/build/contracts.js +1 -1
- package/src/build/rolldown/rolldown-plugin-bridge.js +2 -2
- package/src/build/server-bundle-deploy-manifest.d.ts +1 -1
- package/src/build/server-bundle-deploy-manifest.js +1 -1
- package/src/build.d.ts +1 -1
- package/src/build.js +1 -1
- package/src/config/assembly/finalize-config.js +5 -0
- package/src/dev/transform-server/dev-transform-server.js +1 -1
- package/src/dev/transform-server/dev-transform-vendor-registry.d.ts +29 -6
- package/src/dev/transform-server/dev-transform-vendor-registry.js +101 -53
- package/src/errors/http-error.d.ts +9 -0
- package/src/errors/http-error.js +11 -0
- package/src/html/html-transformer.service.d.ts +0 -21
- package/src/html/html-transformer.service.js +0 -32
- package/src/html-pages/html-page-renderer.d.ts +2 -1
- package/src/html-pages/html-page-renderer.js +5 -3
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/integration.d.ts +1 -2
- package/src/integration.js +0 -1
- package/src/islands/island-host.d.ts +1 -2
- package/src/islands/island-host.js +1 -2
- package/src/plugins/integration-plugin.d.ts +1 -1
- package/src/plugins/processor.d.ts +1 -1
- package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
- package/src/plugins/tsconfig-import-resolver.js +4 -2
- package/src/processor.d.ts +1 -1
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +2 -44
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +14 -89
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +4 -16
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +2 -10
- package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +3 -5
- package/src/route-renderer/orchestration/integration-renderer.d.ts +20 -44
- package/src/route-renderer/orchestration/integration-renderer.js +52 -115
- package/src/route-renderer/orchestration/ownership-graph/page-client-browser-assets.d.ts +3 -4
- package/src/route-renderer/orchestration/ownership-graph/page-client-browser-assets.js +4 -15
- package/src/route-renderer/orchestration/ownership-graph/prepared-graph-membership.d.ts +22 -0
- package/src/route-renderer/orchestration/ownership-graph/prepared-graph-membership.js +45 -0
- package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.d.ts +0 -1
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +4 -3
- package/src/router/server/route-registry.d.ts +20 -9
- package/src/router/server/route-registry.js +52 -30
- package/src/router/server/segment-path-matcher.d.ts +8 -0
- package/src/router/server/segment-path-matcher.js +15 -0
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +0 -4
- package/src/static-site-generator/static-site-generator.js +1 -1
- package/src/types/build-types.d.ts +6 -0
- package/src/types/contracts.d.ts +93 -65
- package/src/types/contracts.js +4 -1
- package/src/types/eco-api-types.d.ts +1 -1
- package/src/types/public-types.d.ts +1 -1
- package/src/utils/endpoint-file-extensions.d.ts +11 -0
- package/src/utils/endpoint-file-extensions.js +13 -0
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.d.ts +0 -12
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.js +0 -32
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Every integration renderer should extend this class
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import {} from '../../assets/asset-processing-service/index.js';
|
|
7
7
|
import { resolveAssetProcessingIntegration } from '../../assets/asset-processing-service/asset-processing-integration.js';
|
|
8
8
|
import { createAppBrowserClientEntryKey } from '../../assets/app-browser-client-build.js';
|
|
9
9
|
import { HtmlTransformerService } from '../../html/html-transformer.service.js';
|
|
@@ -15,6 +15,7 @@ import { getComponentIdentity } from '../../eco/component-identity.js';
|
|
|
15
15
|
import { OwnershipValidationService } from './ownership-graph/ownership-validation.service.js';
|
|
16
16
|
import {} from './ownership-graph/component-graph.js';
|
|
17
17
|
import { collectComponentGraphWatchPaths } from './ownership-graph/component-graph-collectors.js';
|
|
18
|
+
import { assertComponentInPreparedGraph } from './ownership-graph/prepared-graph-membership.js';
|
|
18
19
|
import { collectPageClientPlan, collectPageClientPlanFromGraph, planCoversComponents, planHasForeignChildDescendants, uniqueIslandIntegrationNames, } from './ownership-graph/page-client-plan.js';
|
|
19
20
|
import { buildPageClientBrowserAssets } from './ownership-graph/page-client-browser-assets.js';
|
|
20
21
|
import { finalizeComponentRender, getComponentRenderContext, runWithComponentRenderContext, } from '../../eco/component-render-context.js';
|
|
@@ -193,7 +194,6 @@ export class IntegrationRenderer {
|
|
|
193
194
|
pageClientBuildEntries,
|
|
194
195
|
prebuiltPageClientBrowserAssets: {
|
|
195
196
|
processedAssets: [],
|
|
196
|
-
islandRenderAssetsByFile: new Map(),
|
|
197
197
|
fallbackDependencies: [],
|
|
198
198
|
},
|
|
199
199
|
};
|
|
@@ -331,36 +331,6 @@ export class IntegrationRenderer {
|
|
|
331
331
|
collectContribution: async () => mergePageBrowserGraphContributions(await this.collectPageBrowserGraphContribution(graphContext), resolvedPageDependencies?.contribution),
|
|
332
332
|
});
|
|
333
333
|
}
|
|
334
|
-
/**
|
|
335
|
-
* Merges component-scoped assets into the active render's page package.
|
|
336
|
-
*
|
|
337
|
-
* Explicit page, layout, and document shell composition can produce assets at
|
|
338
|
-
* each foreign subtree. This helper deduplicates those groups and adds them to the
|
|
339
|
-
* render session so downstream HTML finalization sees one canonical asset set.
|
|
340
|
-
*
|
|
341
|
-
* @param assetGroups - Optional groups of processed assets to merge.
|
|
342
|
-
* @returns The deduplicated asset subset contributed by this merge operation.
|
|
343
|
-
*/
|
|
344
|
-
appendProcessedDependencies(...assetGroups) {
|
|
345
|
-
const nextDependencies = this.htmlTransformer.dedupeProcessedAssets(assetGroups.flatMap((assets) => assets ?? []));
|
|
346
|
-
if (nextDependencies.length === 0) {
|
|
347
|
-
return nextDependencies;
|
|
348
|
-
}
|
|
349
|
-
const session = getComponentRenderContext()?.renderState?.session;
|
|
350
|
-
const existingPackage = session?.pagePackage;
|
|
351
|
-
const existingDependencies = existingPackage?.assets ?? [];
|
|
352
|
-
const mergedDependencies = this.htmlTransformer.dedupeProcessedAssets([
|
|
353
|
-
...existingDependencies,
|
|
354
|
-
...nextDependencies,
|
|
355
|
-
]);
|
|
356
|
-
const pagePackage = createPagePackage(mergedDependencies, {
|
|
357
|
-
pageBrowserGraph: existingPackage?.pageBrowserGraph,
|
|
358
|
-
});
|
|
359
|
-
if (session) {
|
|
360
|
-
session.pagePackage = pagePackage;
|
|
361
|
-
}
|
|
362
|
-
return nextDependencies;
|
|
363
|
-
}
|
|
364
334
|
/**
|
|
365
335
|
* Renders a route page through optional layout and document shells.
|
|
366
336
|
*
|
|
@@ -382,8 +352,7 @@ export class IntegrationRenderer {
|
|
|
382
352
|
});
|
|
383
353
|
return renderPageDocumentShell({
|
|
384
354
|
renderComponentWithForeignChildren: (renderInput) => this.renderComponentWithForeignChildren(renderInput),
|
|
385
|
-
|
|
386
|
-
}, { ...input, layouts, composeChildren, inheritedOwner: this.name }, this.DOC_TYPE);
|
|
355
|
+
}, { ...input, layouts, composeChildren }, this.DOC_TYPE);
|
|
387
356
|
}
|
|
388
357
|
serializeStringRenderChildren(children) {
|
|
389
358
|
if (children === undefined) {
|
|
@@ -419,15 +388,10 @@ export class IntegrationRenderer {
|
|
|
419
388
|
const props = serializedChildren === undefined ? input.props : { ...input.props, children: serializedChildren };
|
|
420
389
|
const content = await component(props);
|
|
421
390
|
this.assertStringRenderContent(input, content);
|
|
422
|
-
const html = content;
|
|
423
|
-
const assets = input.component.config?.dependencies
|
|
424
|
-
? await this.processComponentDependencies([input.component])
|
|
425
|
-
: undefined;
|
|
426
391
|
return {
|
|
427
|
-
html,
|
|
392
|
+
html: content,
|
|
428
393
|
canAttachAttributes: true,
|
|
429
394
|
integrationName: this.name,
|
|
430
|
-
assets,
|
|
431
395
|
};
|
|
432
396
|
}
|
|
433
397
|
/**
|
|
@@ -446,21 +410,13 @@ export class IntegrationRenderer {
|
|
|
446
410
|
runtimeContext: this.getQueuedForeignSubtreeContext(input),
|
|
447
411
|
getOwningRenderer: (integrationName, rendererCache) => this.resolveOwningRenderer(integrationName, rendererCache),
|
|
448
412
|
};
|
|
449
|
-
const
|
|
413
|
+
const html = this.integrationHooks.renderQueuedChildren
|
|
450
414
|
? await resolveQueuedHtml({
|
|
451
415
|
...queuedOptions,
|
|
452
416
|
renderQueuedChildren: this.integrationHooks.renderQueuedChildren,
|
|
453
417
|
})
|
|
454
418
|
: await resolveStringQueuedHtml(queuedOptions);
|
|
455
|
-
|
|
456
|
-
...(componentRender.assets ?? []),
|
|
457
|
-
...queuedForeignSubtreeResolution.assets,
|
|
458
|
-
]);
|
|
459
|
-
return {
|
|
460
|
-
...componentRender,
|
|
461
|
-
html: queuedForeignSubtreeResolution.html,
|
|
462
|
-
assets: mergedAssets.length > 0 ? mergedAssets : undefined,
|
|
463
|
-
};
|
|
419
|
+
return { ...componentRender, html };
|
|
464
420
|
}
|
|
465
421
|
constructor({ appConfig, assetProcessingService, assetProcessingIntegration, resolvedIntegrationDependencies, hooks, }) {
|
|
466
422
|
this.appConfig = appConfig;
|
|
@@ -483,7 +439,6 @@ export class IntegrationRenderer {
|
|
|
483
439
|
resolvedIntegrationDependencies,
|
|
484
440
|
hooks: {},
|
|
485
441
|
resolveDependencies: (components, options) => this.resolveDependencies(components, options),
|
|
486
|
-
resolveComponentDependencies: (components, options) => this.processComponentDependencies(components, options),
|
|
487
442
|
resolveDependencyPath: (componentDir, pathUrl) => this.resolveDependencyPath(componentDir, pathUrl),
|
|
488
443
|
applyPendingLazyTriggers: (assets, configs) => this.dependencyResolverService.applyPendingLazyTriggers(assets, configs),
|
|
489
444
|
})
|
|
@@ -570,11 +525,10 @@ export class IntegrationRenderer {
|
|
|
570
525
|
applyAttributesToHtmlElement: (html, attributes) => this.applyAttributesToHtmlElement(html, attributes),
|
|
571
526
|
});
|
|
572
527
|
}
|
|
573
|
-
async transformRouteResponse(response, htmlContributions,
|
|
574
|
-
const resolvedPagePackage = getComponentRenderContext()?.renderState?.session?.pagePackage ?? pagePackage;
|
|
528
|
+
async transformRouteResponse(response, htmlContributions, renderOptions) {
|
|
575
529
|
const transformedResponse = this.htmlTransformer.transform(response, {
|
|
576
530
|
contributions: htmlContributions,
|
|
577
|
-
pagePackage:
|
|
531
|
+
pagePackage: renderOptions.pagePackage,
|
|
578
532
|
});
|
|
579
533
|
const body = (transformedResponse.body ?? (await transformedResponse.text()));
|
|
580
534
|
return this.finalizeDocument(body, renderOptions);
|
|
@@ -738,9 +692,8 @@ export class IntegrationRenderer {
|
|
|
738
692
|
const renderState = getComponentRenderContext()?.renderState;
|
|
739
693
|
if (renderState) {
|
|
740
694
|
renderState.pageClientPlan = renderOptions.pageClientPlan;
|
|
741
|
-
renderState.
|
|
695
|
+
renderState.preparedGraphComponents = renderOptions.preparedGraphComponents;
|
|
742
696
|
}
|
|
743
|
-
session.pagePackage = renderOptions.pagePackage;
|
|
744
697
|
return this.routeRenderOrchestrator.executePrepared(renderOptions, this);
|
|
745
698
|
});
|
|
746
699
|
return value;
|
|
@@ -830,39 +783,11 @@ export class IntegrationRenderer {
|
|
|
830
783
|
return this.integrationHooks.documentContributions?.(context);
|
|
831
784
|
}
|
|
832
785
|
/**
|
|
833
|
-
* Renders the route
|
|
786
|
+
* Renders the route, wrapping whatever it throws as `Error rendering page`.
|
|
834
787
|
* Integrations can add preparation and final HTML hooks around core composition.
|
|
835
788
|
*/
|
|
836
789
|
async render(options) {
|
|
837
|
-
const
|
|
838
|
-
const renderRoute = async () => {
|
|
839
|
-
await this.beforeRender(options);
|
|
840
|
-
const documentShellProps = this.integrationHooks.documentShellProps?.(options);
|
|
841
|
-
return await this.renderPageWithDocumentShell({
|
|
842
|
-
page: {
|
|
843
|
-
component: options.Page,
|
|
844
|
-
props: {
|
|
845
|
-
...options.props,
|
|
846
|
-
params: options.params ?? {},
|
|
847
|
-
query: options.query ?? {},
|
|
848
|
-
locals: options.pageLocals,
|
|
849
|
-
},
|
|
850
|
-
},
|
|
851
|
-
layouts: resolveDocumentShellLayouts({
|
|
852
|
-
layout: options.Layout,
|
|
853
|
-
layoutEntries: options.layoutEntries,
|
|
854
|
-
params: options.params,
|
|
855
|
-
query: options.query,
|
|
856
|
-
locals: options.locals,
|
|
857
|
-
}),
|
|
858
|
-
htmlTemplate: options.HtmlTemplate,
|
|
859
|
-
metadata: options.metadata,
|
|
860
|
-
pageProps: documentShellProps?.pageProps ?? options.pageProps ?? options.props ?? {},
|
|
861
|
-
documentProps: documentShellProps?.documentProps,
|
|
862
|
-
foreignChildRoots: internalOptions.pageDependencyComponents,
|
|
863
|
-
transformDocumentHtml: (html) => this.transformDocumentHtml(html),
|
|
864
|
-
});
|
|
865
|
-
};
|
|
790
|
+
const renderRoute = () => this.renderRouteDocument(options);
|
|
866
791
|
try {
|
|
867
792
|
return await (this.integrationHooks.renderRoute?.(options, renderRoute) ?? renderRoute());
|
|
868
793
|
}
|
|
@@ -870,6 +795,42 @@ export class IntegrationRenderer {
|
|
|
870
795
|
throw this.createRenderError('Error rendering page', error);
|
|
871
796
|
}
|
|
872
797
|
}
|
|
798
|
+
/**
|
|
799
|
+
* Renders the route document through the shared document shell.
|
|
800
|
+
*
|
|
801
|
+
* @remarks
|
|
802
|
+
* A subclass with its own document model overrides this rather than `render()`,
|
|
803
|
+
* so its errors still go through core's wrap.
|
|
804
|
+
*/
|
|
805
|
+
async renderRouteDocument(options) {
|
|
806
|
+
const internalOptions = options;
|
|
807
|
+
await this.beforeRender(options);
|
|
808
|
+
const documentShellProps = this.integrationHooks.documentShellProps?.(options);
|
|
809
|
+
return await this.renderPageWithDocumentShell({
|
|
810
|
+
page: {
|
|
811
|
+
component: options.Page,
|
|
812
|
+
props: {
|
|
813
|
+
...options.props,
|
|
814
|
+
params: options.params ?? {},
|
|
815
|
+
query: options.query ?? {},
|
|
816
|
+
locals: options.pageLocals,
|
|
817
|
+
},
|
|
818
|
+
},
|
|
819
|
+
layouts: resolveDocumentShellLayouts({
|
|
820
|
+
layout: options.Layout,
|
|
821
|
+
layoutEntries: options.layoutEntries,
|
|
822
|
+
params: options.params,
|
|
823
|
+
query: options.query,
|
|
824
|
+
locals: options.locals,
|
|
825
|
+
}),
|
|
826
|
+
htmlTemplate: options.HtmlTemplate,
|
|
827
|
+
metadata: options.metadata,
|
|
828
|
+
pageProps: documentShellProps?.pageProps ?? options.pageProps ?? options.props ?? {},
|
|
829
|
+
documentProps: documentShellProps?.documentProps,
|
|
830
|
+
foreignChildRoots: internalOptions.pageDependencyComponents,
|
|
831
|
+
transformDocumentHtml: (html) => this.transformDocumentHtml(html),
|
|
832
|
+
});
|
|
833
|
+
}
|
|
873
834
|
async beforeRender(options) {
|
|
874
835
|
await this.integrationHooks.beforeRender?.(options);
|
|
875
836
|
}
|
|
@@ -885,6 +846,7 @@ export class IntegrationRenderer {
|
|
|
885
846
|
* renderer's nested foreign-child handoff.
|
|
886
847
|
*/
|
|
887
848
|
async renderComponentWithForeignChildren(input) {
|
|
849
|
+
assertComponentInPreparedGraph(input.component, getComponentRenderContext()?.renderState?.preparedGraphComponents);
|
|
888
850
|
return await executeComponentRender({
|
|
889
851
|
currentIntegrationName: this.name,
|
|
890
852
|
input,
|
|
@@ -924,8 +886,7 @@ export class IntegrationRenderer {
|
|
|
924
886
|
*
|
|
925
887
|
* @remarks
|
|
926
888
|
* `renderQueuedChildren` renders a subtree's children inside this renderer
|
|
927
|
-
* before the owning renderer renders the subtree around them.
|
|
928
|
-
* assets are the owning renderers' assets, deduplicated.
|
|
889
|
+
* before the owning renderer renders the subtree around them.
|
|
929
890
|
*/
|
|
930
891
|
resolveQueuedForeignSubtrees(html, runtimeContext, renderQueuedChildren) {
|
|
931
892
|
return resolveQueuedHtml({
|
|
@@ -939,9 +900,8 @@ export class IntegrationRenderer {
|
|
|
939
900
|
/**
|
|
940
901
|
* Stamps `result` as an Island Host when the component itself declares a client script.
|
|
941
902
|
*
|
|
942
|
-
* @remarks Reads the component's own declarations, excluding Foreign Children
|
|
943
|
-
*
|
|
944
|
-
* `dependencies` emit no assets of their own, so they are never stamped.
|
|
903
|
+
* @remarks Reads the component's own declarations, excluding Foreign Children: a component without
|
|
904
|
+
* scripts that wraps an island is not an island itself. Components without `dependencies` are never stamped.
|
|
945
905
|
*/
|
|
946
906
|
finalizeIslandComponentRender(input, result) {
|
|
947
907
|
const ownAssets = input.component.config?.dependencies
|
|
@@ -964,15 +924,6 @@ export class IntegrationRenderer {
|
|
|
964
924
|
normalizeUnresolvedMarkerArtifactHtml(html) {
|
|
965
925
|
return normalizeUnresolvedMarkerArtifactHtml(html);
|
|
966
926
|
}
|
|
967
|
-
/**
|
|
968
|
-
* Island assets for the active render.
|
|
969
|
-
*
|
|
970
|
-
* @remarks
|
|
971
|
-
* The render context owns the map; outside a render there are none.
|
|
972
|
-
*/
|
|
973
|
-
getActiveIslandRenderAssets() {
|
|
974
|
-
return getComponentRenderContext()?.renderState?.islandRenderAssetsByFile ?? new Map();
|
|
975
|
-
}
|
|
976
927
|
/**
|
|
977
928
|
* @remarks
|
|
978
929
|
* The active plan is the page owner's, but it answers for any renderer: a nested renderer of
|
|
@@ -987,17 +938,6 @@ export class IntegrationRenderer {
|
|
|
987
938
|
const plan = collectPageClientPlan([component, ...(foreignChildRoots ?? [])].map((root) => ({ component: root })), this.name);
|
|
988
939
|
return planHasForeignChildDescendants(plan, component, this.name, foreignChildRoots);
|
|
989
940
|
}
|
|
990
|
-
/**
|
|
991
|
-
* Builds island client assets from the page client plan before SSR.
|
|
992
|
-
*
|
|
993
|
-
* @remarks
|
|
994
|
-
* Default is none. Integrations that hydrate islands override this so
|
|
995
|
-
* {@link IntegrationRenderer.execute} never starts a browser build during SSR.
|
|
996
|
-
* Page owners also call this on other hydrating integrations listed in the plan.
|
|
997
|
-
*/
|
|
998
|
-
async collectIslandRenderAssets(_plan) {
|
|
999
|
-
return new Map();
|
|
1000
|
-
}
|
|
1001
941
|
/**
|
|
1002
942
|
* Returns whether this renderer builds island and lazy-entry scripts in the
|
|
1003
943
|
* app-wide grouped browser build that other page owners should run for the plan.
|
|
@@ -1010,8 +950,7 @@ export class IntegrationRenderer {
|
|
|
1010
950
|
*
|
|
1011
951
|
* @remarks
|
|
1012
952
|
* The planning and merging live in `ownership-graph/page-client-browser-assets.ts`; this method
|
|
1013
|
-
* supplies what only the renderer has:
|
|
1014
|
-
* Integrations, and its asset service.
|
|
953
|
+
* supplies what only the renderer has: the owning renderers of other Integrations and its asset service.
|
|
1015
954
|
*/
|
|
1016
955
|
async buildPageClientBrowserAssets(plan, route) {
|
|
1017
956
|
const prebuilt = route ? await this.buildPrebuiltPageClientBrowserAssets(plan, route) : undefined;
|
|
@@ -1026,7 +965,6 @@ export class IntegrationRenderer {
|
|
|
1026
965
|
return buildPageClientBrowserAssets({
|
|
1027
966
|
plan,
|
|
1028
967
|
integrationName: this.name,
|
|
1029
|
-
collectOwnIslandAssets: (ownPlan) => this.collectIslandRenderAssets(ownPlan),
|
|
1030
968
|
resolveContributor: async (integrationName) => {
|
|
1031
969
|
const owning = await this.resolveOwningRenderer(integrationName, rendererCache);
|
|
1032
970
|
return owning instanceof IntegrationRenderer
|
|
@@ -1065,7 +1003,6 @@ export class IntegrationRenderer {
|
|
|
1065
1003
|
const processedAssets = [...prebuilt.processedAssets, ...fallbackAssets];
|
|
1066
1004
|
return {
|
|
1067
1005
|
processedAssets,
|
|
1068
|
-
islandRenderAssetsByFile: prebuilt.islandRenderAssetsByFile,
|
|
1069
1006
|
lazyTriggers: this.dependencyResolverService.applyPendingLazyTriggers(processedAssets, plan.lazyConfigs),
|
|
1070
1007
|
};
|
|
1071
1008
|
}
|
|
@@ -12,7 +12,6 @@ export type BuildPageClientBrowserAssetsInput = {
|
|
|
12
12
|
plan: PageClientPlan;
|
|
13
13
|
/** Name of the Integration building for the plan. */
|
|
14
14
|
integrationName: string;
|
|
15
|
-
collectOwnIslandAssets(plan: PageClientPlan): Promise<Map<string, ProcessedAsset[]>>;
|
|
16
15
|
resolveContributor(integrationName: string): Promise<PageClientAssetsContributor | undefined>;
|
|
17
16
|
processLazyEntries(entries: AssetDefinition[]): Promise<ProcessedAsset[]>;
|
|
18
17
|
applyPendingLazyTriggers(assets: ProcessedAsset[], configs: EcoComponentConfig[]): ResolvedLazyTrigger[];
|
|
@@ -21,8 +20,8 @@ export type BuildPageClientBrowserAssetsInput = {
|
|
|
21
20
|
* Builds island and lazy-entry browser assets from a page client plan.
|
|
22
21
|
*
|
|
23
22
|
* @remarks
|
|
24
|
-
* The page owner
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* The page owner asks every other island-hydrating Integration on the plan to contribute its grouped
|
|
24
|
+
* client build. Lazy entries join that grouped build when an Integration includes them; otherwise they
|
|
25
|
+
* are processed here as one grouped batch.
|
|
27
26
|
*/
|
|
28
27
|
export declare function buildPageClientBrowserAssets(input: BuildPageClientBrowserAssetsInput): Promise<PageClientBrowserAssets>;
|
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
import { uniqueIslandIntegrationNames } from './page-client-plan.js';
|
|
2
|
-
function mergeIslandRenderAssetMaps(target, source) {
|
|
3
|
-
for (const [file, assets] of source) {
|
|
4
|
-
const existing = target.get(file);
|
|
5
|
-
target.set(file, existing ? [...existing, ...assets] : assets);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
2
|
/**
|
|
9
3
|
* Builds island and lazy-entry browser assets from a page client plan.
|
|
10
4
|
*
|
|
11
5
|
* @remarks
|
|
12
|
-
* The page owner
|
|
13
|
-
*
|
|
14
|
-
*
|
|
6
|
+
* The page owner asks every other island-hydrating Integration on the plan to contribute its grouped
|
|
7
|
+
* client build. Lazy entries join that grouped build when an Integration includes them; otherwise they
|
|
8
|
+
* are processed here as one grouped batch.
|
|
15
9
|
*/
|
|
16
10
|
export async function buildPageClientBrowserAssets(input) {
|
|
17
11
|
const { plan } = input;
|
|
18
|
-
const
|
|
19
|
-
const islandRenderAssetsByFile = new Map();
|
|
20
|
-
mergeIslandRenderAssetMaps(islandRenderAssetsByFile, ownIslands);
|
|
21
|
-
const combined = [...ownIslands.values()].flat();
|
|
12
|
+
const combined = [];
|
|
22
13
|
for (const integrationName of uniqueIslandIntegrationNames(plan)) {
|
|
23
14
|
if (integrationName === input.integrationName) {
|
|
24
15
|
continue;
|
|
@@ -28,7 +19,6 @@ export async function buildPageClientBrowserAssets(input) {
|
|
|
28
19
|
continue;
|
|
29
20
|
}
|
|
30
21
|
const contributed = await contributor.buildPageClientBrowserAssets(plan);
|
|
31
|
-
mergeIslandRenderAssetMaps(islandRenderAssetsByFile, contributed.islandRenderAssetsByFile);
|
|
32
22
|
combined.push(...contributed.processedAssets);
|
|
33
23
|
}
|
|
34
24
|
const lazyAlreadyProcessed = combined.some((asset) => Boolean(asset.attributes?.['data-eco-lazy-key']));
|
|
@@ -38,7 +28,6 @@ export async function buildPageClientBrowserAssets(input) {
|
|
|
38
28
|
const processedAssets = [...combined, ...processedLazy];
|
|
39
29
|
return {
|
|
40
30
|
processedAssets,
|
|
41
|
-
islandRenderAssetsByFile,
|
|
42
31
|
lazyTriggers: input.applyPendingLazyTriggers(processedAssets, plan.lazyConfigs),
|
|
43
32
|
};
|
|
44
33
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EcoComponent } from '../../../types/contracts.js';
|
|
2
|
+
import type { PreparedComponentGraph } from './component-graph.js';
|
|
3
|
+
/**
|
|
4
|
+
* Maps each prepared component's identity id to whether route preparation collects its assets,
|
|
5
|
+
* or returns `undefined` outside development.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Only development renders are checked, so no map is built elsewhere. Assets are collected when
|
|
9
|
+
* the component has an identity file and so does every parent along some path to a root.
|
|
10
|
+
* Components are compared by identity id, because one file can declare several.
|
|
11
|
+
*/
|
|
12
|
+
export declare function collectPreparedGraphComponents(graph: PreparedComponentGraph): ReadonlyMap<string, boolean> | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Fails a render that reaches a component whose assets route preparation did not collect.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Without a map (production, or a partial view that prepares no graph) nothing is checked.
|
|
18
|
+
* A component without an identity file or a `dependencies` config has no assets to collect.
|
|
19
|
+
* A component that is declared but sits only under parents without an identity file gets its own
|
|
20
|
+
* message, because declaring it again would not help.
|
|
21
|
+
*/
|
|
22
|
+
export declare function assertComponentInPreparedGraph(component: EcoComponent, preparedGraphComponents: ReadonlyMap<string, boolean> | undefined): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { getComponentIdentity } from '../../../eco/component-identity.js';
|
|
2
|
+
import { isDevelopmentRuntime } from '../../../utils/runtime.js';
|
|
3
|
+
/**
|
|
4
|
+
* Maps each prepared component's identity id to whether route preparation collects its assets,
|
|
5
|
+
* or returns `undefined` outside development.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Only development renders are checked, so no map is built elsewhere. Assets are collected when
|
|
9
|
+
* the component has an identity file and so does every parent along some path to a root.
|
|
10
|
+
* Components are compared by identity id, because one file can declare several.
|
|
11
|
+
*/
|
|
12
|
+
export function collectPreparedGraphComponents(graph) {
|
|
13
|
+
if (!isDevelopmentRuntime()) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const components = new Map();
|
|
17
|
+
for (const node of graph.nodes) {
|
|
18
|
+
components.set(node.componentId, node.dependencyCollectionVisible || components.get(node.componentId) === true);
|
|
19
|
+
}
|
|
20
|
+
return components;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Fails a render that reaches a component whose assets route preparation did not collect.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Without a map (production, or a partial view that prepares no graph) nothing is checked.
|
|
27
|
+
* A component without an identity file or a `dependencies` config has no assets to collect.
|
|
28
|
+
* A component that is declared but sits only under parents without an identity file gets its own
|
|
29
|
+
* message, because declaring it again would not help.
|
|
30
|
+
*/
|
|
31
|
+
export function assertComponentInPreparedGraph(component, preparedGraphComponents) {
|
|
32
|
+
if (!preparedGraphComponents || !component.config?.dependencies) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const identity = getComponentIdentity(component);
|
|
36
|
+
const collected = identity?.file ? preparedGraphComponents.get(identity.id) : undefined;
|
|
37
|
+
if (!identity?.file || collected) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const notCollected = `[ecopages] Component "${identity.file}" was rendered but route preparation did not collect it, so its stylesheets and scripts are not part of the page assets.`;
|
|
41
|
+
if (collected === false) {
|
|
42
|
+
throw new Error(`${notCollected} It is declared, but only under a parent without an identity file, and preparation collects nothing below such a parent. Declare that parent with eco.component() in its own module, or list the component from a parent that has one.`);
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`${notCollected} Import it statically from the module that declares it with eco.component() (a named re-export works, \`export *\` does not), list it in the parent's dependencies.components, or return it in components from the Page's dependencies.`);
|
|
45
|
+
}
|
|
@@ -6,7 +6,6 @@ export type PlannedPageClientBuildEntry = PageClientBuildEntry & {
|
|
|
6
6
|
};
|
|
7
7
|
export type PrebuiltPageClientBrowserAssets = {
|
|
8
8
|
processedAssets: ProcessedAsset[];
|
|
9
|
-
islandRenderAssetsByFile: Map<string, ProcessedAsset[]>;
|
|
10
9
|
fallbackDependencies: Array<{
|
|
11
10
|
dependency: PageClientBuildEntry['dependency'];
|
|
12
11
|
integrationName: string;
|
|
@@ -7,6 +7,7 @@ import { createPreparedComponentGraphBuilder, } from '../ownership-graph/compone
|
|
|
7
7
|
import { OwnershipValidationService, throwIfOwnershipInvalid, } from '../ownership-graph/ownership-validation.service.js';
|
|
8
8
|
import { collectComponentGraphWatchPaths, collectUsedIntegrationDependenciesFromNames, } from '../ownership-graph/component-graph-collectors.js';
|
|
9
9
|
import { collectPageClientPlanFromGraph } from '../ownership-graph/page-client-plan.js';
|
|
10
|
+
import { collectPreparedGraphComponents } from '../ownership-graph/prepared-graph-membership.js';
|
|
10
11
|
import { buildGlobalInjectorAssets } from '../page-browser-graph/global-injector-assets.service.js';
|
|
11
12
|
import { mergePageBrowserGraphContributions } from '../page-browser-graph/page-browser-graph-contribution.merge.js';
|
|
12
13
|
import { PageBrowserGraphService } from '../page-browser-graph/page-browser-graph.service.js';
|
|
@@ -210,7 +211,7 @@ export class RouteRenderOrchestrator {
|
|
|
210
211
|
}),
|
|
211
212
|
sourceDependencyPaths,
|
|
212
213
|
pageClientPlan: clientPlan,
|
|
213
|
-
|
|
214
|
+
preparedGraphComponents: collectPreparedGraphComponents(preparedGraph),
|
|
214
215
|
};
|
|
215
216
|
}
|
|
216
217
|
async resolveDeclaredPageBrowserGraph(input) {
|
|
@@ -253,7 +254,7 @@ export class RouteRenderOrchestrator {
|
|
|
253
254
|
headers: {
|
|
254
255
|
'Content-Type': 'text/html',
|
|
255
256
|
},
|
|
256
|
-
}), htmlFinalization.htmlContributions, renderOptions
|
|
257
|
+
}), htmlFinalization.htmlContributions, renderOptions));
|
|
257
258
|
return {
|
|
258
259
|
body,
|
|
259
260
|
cacheStrategy: renderOptions.cacheStrategy,
|
|
@@ -268,7 +269,7 @@ export class RouteRenderOrchestrator {
|
|
|
268
269
|
headers: {
|
|
269
270
|
'Content-Type': 'text/html',
|
|
270
271
|
},
|
|
271
|
-
}), htmlFinalization.htmlContributions, renderOptions
|
|
272
|
+
}), htmlFinalization.htmlContributions, renderOptions));
|
|
272
273
|
return {
|
|
273
274
|
body,
|
|
274
275
|
cacheStrategy: renderOptions.cacheStrategy,
|
|
@@ -2,17 +2,23 @@ import type { EcoPagesAppConfig } from '../../config/internal-types.js';
|
|
|
2
2
|
import type { PageParams, PageQuery } from '../../types/contracts.js';
|
|
3
3
|
import { type ParsedSegmentPath } from './segment-path-matcher.js';
|
|
4
4
|
export type RouteKind = 'exact' | 'catch-all' | 'dynamic';
|
|
5
|
+
/**
|
|
6
|
+
* What a Template Route file declares: a Page rendered to HTML, or an endpoint file whose method
|
|
7
|
+
* handler exports answer its requests. Only `page` routes take part in static generation.
|
|
8
|
+
*/
|
|
9
|
+
export type RouteRole = 'page' | 'endpoint';
|
|
5
10
|
export type RouteParams = PageParams;
|
|
6
11
|
export type RouteQuery = PageQuery;
|
|
7
12
|
export type TemplateRoute = {
|
|
8
13
|
readonly pathname: string;
|
|
9
14
|
readonly kind: RouteKind;
|
|
15
|
+
readonly role: RouteRole;
|
|
10
16
|
readonly filePath: string;
|
|
11
17
|
readonly paramNames: readonly string[];
|
|
12
18
|
};
|
|
13
19
|
export type RouteMatch = {
|
|
14
20
|
readonly requestedPathname: string;
|
|
15
|
-
readonly templateRoute: Pick<TemplateRoute, 'pathname' | 'kind' | 'filePath'> & Partial<Pick<TemplateRoute, 'paramNames'>>;
|
|
21
|
+
readonly templateRoute: Pick<TemplateRoute, 'pathname' | 'kind' | 'role' | 'filePath'> & Partial<Pick<TemplateRoute, 'paramNames'>>;
|
|
16
22
|
readonly params: RouteParams;
|
|
17
23
|
readonly query: RouteQuery;
|
|
18
24
|
};
|
|
@@ -38,6 +44,8 @@ export type RouteRegistryPageModule = {
|
|
|
38
44
|
}>;
|
|
39
45
|
}>;
|
|
40
46
|
readonly staticProps?: unknown;
|
|
47
|
+
/** The Page's Cache Strategy; `'dynamic'` Pages render per request and are never expanded. */
|
|
48
|
+
readonly cache?: unknown;
|
|
41
49
|
};
|
|
42
50
|
export interface RouteRegistryPageModuleAdapter {
|
|
43
51
|
loadPageModule(filePath: string): Promise<RouteRegistryPageModule>;
|
|
@@ -62,22 +70,23 @@ export declare class RouteRegistry {
|
|
|
62
70
|
constructor(options: RouteRegistryOptions);
|
|
63
71
|
get origin(): string;
|
|
64
72
|
get templateRoutes(): readonly TemplateRoute[];
|
|
73
|
+
private get pageRoutes();
|
|
65
74
|
init(): Promise<void>;
|
|
66
75
|
reload(): Promise<void>;
|
|
67
76
|
onReload(listener: () => void): () => void;
|
|
68
77
|
matchRequest(requestUrl: string, parsedPathSegments?: ParsedSegmentPath): RouteMatch | null;
|
|
69
78
|
/**
|
|
70
|
-
* Orders
|
|
79
|
+
* Orders two dynamic or two catch-all routes by the specificity of their
|
|
80
|
+
* pattern segments, the catch-all segment itself left out.
|
|
71
81
|
*
|
|
72
82
|
* @remarks
|
|
73
|
-
*
|
|
83
|
+
* Segments are compared from left to right because an earlier literal
|
|
74
84
|
* segment constrains a request more strongly than a later one. A longer
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* order.
|
|
85
|
+
* pattern wins only after the shared segments tie. The pathname tie breaker
|
|
86
|
+
* keeps equal patterns deterministic without depending on discovery order.
|
|
78
87
|
*/
|
|
79
|
-
private
|
|
80
|
-
private
|
|
88
|
+
private compareSpecificity;
|
|
89
|
+
private getSpecificitySegments;
|
|
81
90
|
private isDynamicRouteSegment;
|
|
82
91
|
listStaticPathExpansions(input: {
|
|
83
92
|
runtimeOrigin: string;
|
|
@@ -89,7 +98,9 @@ export declare class RouteRegistry {
|
|
|
89
98
|
/**
|
|
90
99
|
* @remarks
|
|
91
100
|
* Strips the longest template extension the file ends with, so `about.kita.tsx` keeps no
|
|
92
|
-
* `.kita` part when `.tsx` is also registered, and `my.html-tips.html` keeps its name.
|
|
101
|
+
* `.kita` part when `.tsx` is also registered, and `my.html-tips.html` keeps its name. An
|
|
102
|
+
* endpoint strips its whole marker, so `users.api.tsx` is `/users` even when `.tsx` is a
|
|
103
|
+
* template extension.
|
|
93
104
|
*/
|
|
94
105
|
private getRoutePath;
|
|
95
106
|
/**
|