@ecopages/core 0.8.0 → 0.10.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 +2 -2
- package/package.json +14 -4
- package/src/adapters/node/create-app.d.ts +5 -5
- package/src/adapters/node/create-app.js +1 -1
- package/src/adapters/node/server-adapter.d.ts +1 -0
- package/src/adapters/node/server-adapter.js +4 -1
- package/src/adapters/shared/hmr/hmr-manager.d.ts +2 -0
- package/src/adapters/shared/hmr/hmr-manager.js +8 -4
- package/src/adapters/shared/http/api-request-pipeline.d.ts +16 -3
- package/src/adapters/shared/http/api-request-pipeline.js +23 -16
- package/src/adapters/shared/http/define-api-handler.d.ts +8 -8
- package/src/adapters/shared/http/explicit-static-route-matcher.js +8 -4
- package/src/adapters/shared/http/file-route-middleware-pipeline.d.ts +10 -11
- package/src/adapters/shared/http/file-route-middleware-pipeline.js +5 -6
- package/src/adapters/shared/http/fs-server-response-matcher.js +12 -4
- package/src/adapters/shared/http/run-middleware-chain.d.ts +29 -2
- package/src/adapters/shared/http/run-middleware-chain.js +108 -10
- package/src/adapters/shared/runtime/render-context.d.ts +2 -0
- package/src/adapters/shared/runtime/render-context.js +6 -21
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +2 -2
- package/src/adapters/shared/runtime/server-request-pipeline.js +4 -3
- package/src/adapters/shared/runtime/server-static-builder.js +4 -1
- package/src/adapters/shared/runtime/unattached-scripts.d.ts +17 -0
- package/src/adapters/shared/runtime/unattached-scripts.js +57 -0
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +3 -2
- package/src/adapters/shared/ws/ws-pattern-matcher.d.ts +14 -1
- package/src/adapters/shared/ws/ws-pattern-matcher.js +14 -13
- package/src/assets/app-browser-client-build.js +3 -0
- package/src/assets/asset-processing-service/asset-processing.service.d.ts +9 -0
- package/src/assets/asset-processing-service/asset-processing.service.js +19 -0
- package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +16 -2
- package/src/assets/asset-processing-service/processed-asset-ledger.js +31 -3
- package/src/build/build-graph.d.ts +19 -2
- package/src/build/build-graph.js +19 -18
- package/src/build/cache/pages-unified-graph-build.d.ts +4 -6
- package/src/build/cache/pages-unified-graph-build.js +14 -51
- package/src/build/cache/server-module-entries.d.ts +5 -9
- package/src/build/cache/server-module-entries.js +5 -58
- package/src/build/contracts/build-contracts.d.ts +15 -0
- package/src/build/contracts.d.ts +1 -1
- package/src/build/contracts.js +1 -1
- package/src/build/production-asset-ledger.d.ts +1 -1
- package/src/build/production-asset-ledger.js +4 -2
- package/src/build/rolldown/file-role-grammar-plugin.d.ts +11 -0
- package/src/build/rolldown/file-role-grammar-plugin.js +32 -0
- package/src/build/rolldown/rolldown-adapter-helpers.d.ts +11 -0
- package/src/build/rolldown/rolldown-adapter-helpers.js +79 -10
- package/src/build/rolldown/ssr-script-entries-plugin.d.ts +31 -0
- package/src/build/rolldown/ssr-script-entries-plugin.js +104 -0
- package/src/build/runtime/build-request-policy.js +4 -1
- package/src/build/server/server-modules-manifest.d.ts +6 -1
- package/src/build/server/server-modules-manifest.js +10 -1
- package/src/build/server/view-reference.d.ts +9 -0
- package/src/build/server/view-reference.js +11 -0
- package/src/build.d.ts +3 -1
- package/src/build.js +3 -1
- package/src/cli.d.ts +14 -0
- package/src/cli.js +14 -0
- package/src/config/assembly/app-runtime.d.ts +13 -0
- package/src/config/assembly/app-runtime.js +2 -0
- package/src/config/assembly/finalize-config.js +13 -8
- package/src/config/internal-types.d.ts +0 -12
- package/src/config/resolve-eco-config-path.d.ts +2 -0
- package/src/config/resolve-eco-config-path.js +2 -1
- package/src/config/server-config-bundle.d.ts +0 -1
- package/src/config/server-config-bundle.js +1 -1
- package/src/config/user-config-types.d.ts +0 -12
- package/src/declarations.d.ts +2 -0
- package/src/dev/invalidation/development-invalidation.service.d.ts +0 -2
- package/src/dev/invalidation/development-invalidation.service.js +1 -11
- package/src/dev/transform-server/dev-transform-vendor-registry.js +33 -19
- package/src/eco/discovered-dependencies.d.ts +5 -0
- package/src/eco/discovered-dependencies.js +9 -0
- package/src/eco/eco.browser.js +6 -26
- package/src/eco/eco.js +24 -16
- package/src/eco/migration-docs.d.ts +7 -0
- package/src/eco/migration-docs.js +7 -0
- package/src/eco/page-data-hooks.d.ts +27 -0
- package/src/eco/page-data-hooks.js +64 -0
- package/src/eco/page-layout-normalization.d.ts +2 -2
- package/src/hmr/client/hmr-runtime.js +1 -1
- package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -2
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.d.ts +2 -1
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +4 -3
- package/src/html/html-rewriter.d.ts +9 -7
- package/src/html/html-rewriter.js +26 -41
- package/src/html/html-transformer.service.d.ts +2 -2
- package/src/html/html-transformer.service.js +21 -15
- package/src/html-pages/html-page-module-scripts.js +2 -1
- package/src/html-pages/html-pages.plugin.d.ts +1 -1
- package/src/html-pages/html-pages.plugin.js +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/integration.d.ts +2 -2
- package/src/integration.js +2 -2
- package/src/islands/island-host.d.ts +16 -5
- package/src/islands/island-host.js +8 -1
- package/src/middleware/create-middleware.d.ts +41 -0
- package/src/middleware/create-middleware.js +72 -0
- package/src/plugins/component-import-discovery.d.ts +14 -1
- package/src/plugins/component-import-discovery.js +36 -16
- package/src/plugins/eco-component-meta-plugin.d.ts +38 -0
- package/src/plugins/eco-component-meta-plugin.js +208 -44
- package/src/plugins/ecopages-virtual-imports.d.ts +15 -0
- package/src/plugins/ecopages-virtual-imports.js +25 -0
- package/src/plugins/integration-plugin.d.ts +1 -1
- package/src/plugins/integration-plugin.js +1 -1
- package/src/plugins/tsconfig-import-resolver.d.ts +2 -0
- package/src/plugins/tsconfig-import-resolver.js +7 -5
- package/src/route-renderer/error-pages/error-page-renderer.js +32 -3
- package/src/route-renderer/explicit-view-render-preparation.d.ts +28 -3
- package/src/route-renderer/explicit-view-render-preparation.js +63 -11
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +15 -5
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +27 -15
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +24 -9
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +73 -50
- package/src/route-renderer/orchestration/integration-renderer.d.ts +42 -11
- package/src/route-renderer/orchestration/integration-renderer.js +83 -43
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.builder.js +0 -3
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +36 -11
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +74 -62
- package/src/route-renderer/page-declaration.d.ts +25 -0
- package/src/route-renderer/page-declaration.js +39 -0
- package/src/route-renderer/page-loading/component-declarations.d.ts +65 -0
- package/src/route-renderer/page-loading/component-declarations.js +77 -0
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -16
- package/src/route-renderer/page-loading/component-dependency-collection.js +36 -105
- package/src/route-renderer/page-loading/declared-asset-collection.d.ts +19 -14
- package/src/route-renderer/page-loading/declared-asset-collection.js +66 -67
- package/src/route-renderer/page-loading/dependency-resolver.d.ts +18 -10
- package/src/route-renderer/page-loading/dependency-resolver.js +58 -99
- package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +19 -26
- package/src/route-renderer/page-loading/lazy-entry-collection.js +53 -64
- package/src/route-renderer/page-loading/module-declaration-aggregation.d.ts +17 -3
- package/src/route-renderer/page-loading/module-declaration-aggregation.js +14 -13
- package/src/route-renderer/page-loading/page-module-loader.d.ts +31 -12
- package/src/route-renderer/page-loading/page-module-loader.js +66 -35
- package/src/route-renderer/page-loading/resolved-page-dependencies.js +14 -9
- package/src/router/server/pages-dir.d.ts +7 -0
- package/src/router/server/pages-dir.js +7 -0
- package/src/router/server/route-registry.d.ts +22 -10
- package/src/router/server/route-registry.js +54 -23
- package/src/router/server/segment-path-matcher.d.ts +29 -5
- package/src/router/server/segment-path-matcher.js +22 -19
- package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +2 -2
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +5 -5
- package/src/static-site-generator/static-site-generator.d.ts +17 -2
- package/src/static-site-generator/static-site-generator.js +52 -18
- package/src/types/contracts.d.ts +216 -160
- package/src/types/eco-api-types.d.ts +86 -51
- package/src/types/locals-brand.d.ts +9 -0
- package/src/types/locals-brand.js +9 -0
- package/src/types/middleware-types.d.ts +143 -0
- package/src/types/middleware-types.js +1 -0
- package/src/types/public-types.d.ts +3 -2
- package/src/utils/file-roles.d.ts +48 -0
- package/src/utils/file-roles.js +85 -0
- package/src/utils/node-builtin.d.ts +10 -0
- package/src/utils/node-builtin.js +13 -0
- package/src/watchers/project-watcher.js +2 -2
- package/src/build/contracts/server-only-specifier.d.ts +0 -8
- package/src/build/contracts/server-only-specifier.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.d.ts +0 -5
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.d.ts +0 -4
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.js +0 -30
- package/src/route-renderer/page-loading/ecopages-virtual-imports.d.ts +0 -12
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +0 -100
- package/src/utils/endpoint-file-extensions.d.ts +0 -11
- package/src/utils/endpoint-file-extensions.js +0 -13
- package/src/utils/locals-utils.d.ts +0 -15
- package/src/utils/locals-utils.js +0 -34
|
@@ -9,13 +9,16 @@ import { resolveAssetProcessingIntegration } from '../../assets/asset-processing
|
|
|
9
9
|
import { getAssetDependencyKey } from '../../assets/asset-processing-service/asset-dependency-keys.js';
|
|
10
10
|
import { HtmlTransformerService } from '../../html/html-transformer.service.js';
|
|
11
11
|
import { fileSystem } from '@ecopages/file-system';
|
|
12
|
-
import { hasProductionServerModule } from '../../build/server/server-modules-manifest.js';
|
|
12
|
+
import { hasProductionServerModule, MissingProductionServerModuleError, } from '../../build/server/server-modules-manifest.js';
|
|
13
13
|
import { invariant } from '../../utils/invariant.js';
|
|
14
14
|
import { toRootRelativePath } from '../../utils/root-relative-path.js';
|
|
15
15
|
import { HttpError } from '../../errors/http-error.js';
|
|
16
16
|
import { DependencyResolverService } from '../page-loading/dependency-resolver.js';
|
|
17
17
|
import { PageModuleLoaderService } from '../page-loading/page-module-loader.js';
|
|
18
18
|
import { getComponentIdentity } from '../../eco/component-identity.js';
|
|
19
|
+
import { isDynamicPage } from '../../eco/page-data-hooks.js';
|
|
20
|
+
import { isPathInside } from '../../utils/path-containment.js';
|
|
21
|
+
import { createLiteralPageDeclarationError, isPageDeclaredIn, isUnattributedPage } from '../page-declaration.js';
|
|
19
22
|
import { OwnershipValidationService } from './ownership-graph/ownership-validation.service.js';
|
|
20
23
|
import {} from './ownership-graph/component-graph.js';
|
|
21
24
|
import { collectComponentGraphWatchPaths } from './ownership-graph/component-graph-collectors.js';
|
|
@@ -27,16 +30,15 @@ import { createRenderSession } from './foreign-child/render-session.js';
|
|
|
27
30
|
import { RouteRenderOrchestrator, } from './route-pipeline/route-render-orchestrator.js';
|
|
28
31
|
import { buildRouteHtmlFinalization } from './route-pipeline/route-html-finalization.service.js';
|
|
29
32
|
import { resolvePageDependenciesFromContext, } from '../page-loading/resolved-page-dependencies.js';
|
|
30
|
-
import { normalizeUnresolvedMarkerArtifactHtml } from './route-pipeline/marker-artifact.utils.js';
|
|
31
33
|
import { isMarkupNodeLike } from '../../eco/component-render-output.js';
|
|
32
|
-
import { getForeignSubtreeResolutionContextKey,
|
|
34
|
+
import { getForeignSubtreeResolutionContextKey, resolveOwningIntegrationRenderer, } from './foreign-child/owning-renderer-resolution.js';
|
|
33
35
|
import { keepsLastGoodOutput, showAssetFailure } from '../../assets/asset-processing-service/last-good-output.js';
|
|
34
36
|
import { ensureIntegrationRuntimeReady } from '../../build/app-build-manifest-runtime.js';
|
|
35
37
|
import { assignSsrPreloadScripts, CustomElementScriptPreloader, } from './custom-element-scripts/custom-element-script-preloader.js';
|
|
36
38
|
import { createQueuedRuntime, executeComponentRender, getQueuedRuntimeContext, resolveQueuedHtml, resolveStringQueuedHtml, } from './foreign-child/foreign-subtree-execution.service.js';
|
|
37
39
|
import { renderPageDocumentShell, } from './document-shell/document-shell-render.service.js';
|
|
38
|
-
import { resolveInnermostPageLayout, resolvePageLayoutComponents,
|
|
39
|
-
import {
|
|
40
|
+
import { resolveInnermostPageLayout, resolvePageLayoutComponents, resolveRenderLayouts, } from './document-shell/layout-shell-props.service.js';
|
|
41
|
+
import { stampIslandHost } from '../../islands/island-host.js';
|
|
40
42
|
import { requireAppRuntime } from '../../utils/app-runtime.js';
|
|
41
43
|
import { prepareAssetDependencies } from '../../assets/asset-processing-service/asset-processing.service.js';
|
|
42
44
|
import { isBundleableScript } from '../../assets/asset-processing-service/bundleable-script.js';
|
|
@@ -148,17 +150,21 @@ export class IntegrationRenderer {
|
|
|
148
150
|
* @remarks
|
|
149
151
|
* The scripts the route's render would bundle, from the shell, the page Dependencies, the Page Browser Graph
|
|
150
152
|
* dependencies and the components and scripts its contribution names, go to `bundledScripts`, prepared as asset
|
|
151
|
-
* processing prepares them.
|
|
153
|
+
* processing prepares them. A Dynamic Page is planned without its `props` hook, which is its request handler: the
|
|
154
|
+
* build has no request to give it. A plan without the `props` hook also skips `metadata`, which would read props
|
|
155
|
+
* that were never resolved. Planning does not read metadata, and static export never renders from such a plan.
|
|
152
156
|
*/
|
|
153
157
|
async planRouteInstance(routeInstance) {
|
|
158
|
+
const pageModule = await this.loadPageModule(routeInstance.routeFile);
|
|
159
|
+
const skipPropsHook = routeInstance.skipPropsHook || isDynamicPage(pageModule.default);
|
|
154
160
|
const routeOptions = {
|
|
155
161
|
file: routeInstance.routeFile,
|
|
156
162
|
params: routeInstance.params,
|
|
157
163
|
query: routeInstance.query,
|
|
158
|
-
|
|
164
|
+
skipPropsHook,
|
|
159
165
|
};
|
|
160
166
|
const resolvedInputs = await this.resolveRouteRenderInputs(routeOptions, {
|
|
161
|
-
skipMetadata: routeInstance.isRouteTemplate,
|
|
167
|
+
skipMetadata: routeInstance.isRouteTemplate || skipPropsHook,
|
|
162
168
|
});
|
|
163
169
|
const graphContext = await this.routeRenderOrchestrator.prepareRouteGraphContext({
|
|
164
170
|
routeOptions,
|
|
@@ -203,10 +209,42 @@ export class IntegrationRenderer {
|
|
|
203
209
|
* `getStaticPaths` or `getMetadata` fails here with an error that points to the codemod.
|
|
204
210
|
*/
|
|
205
211
|
async loadPageModule(file, options) {
|
|
212
|
+
return this.importRouteModule(file, options);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Imports a route module and fails unless it is a Page this Integration accepts.
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* The legacy-export check runs first, so a module that still exports `getStaticProps` gets the codemod message.
|
|
219
|
+
*/
|
|
220
|
+
async importRouteModule(file, options) {
|
|
206
221
|
const pageModule = await this.importPageFile(file, options);
|
|
207
222
|
this.pageModuleLoaderService.assertNoLegacyPageExports(file, pageModule);
|
|
223
|
+
this.assertPageModule(file, pageModule);
|
|
208
224
|
return pageModule;
|
|
209
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Fails when the default export of a route module is not a Page that the file itself declares.
|
|
228
|
+
*
|
|
229
|
+
* @remarks
|
|
230
|
+
* A Page is a declared component whose build-time identity names this route file: an `eco.page()` result
|
|
231
|
+
* (also an HTML Page or an MDX module, which the Integration stamps the same way). The identity transform
|
|
232
|
+
* stamps the file that holds the literal `eco.page(...)` call, so a Page made by a wrapper in another file,
|
|
233
|
+
* or re-exported from one, names that other file and fails here. A function with a `config` that fails the
|
|
234
|
+
* check gets the literal-call message; anything else gets the not-a-Page message with the fixes.
|
|
235
|
+
* @throws When the module has no default export that is a Page declared in `file`.
|
|
236
|
+
*/
|
|
237
|
+
assertPageModule(file, module) {
|
|
238
|
+
const page = module.default;
|
|
239
|
+
if (isPageDeclaredIn(file, page, this.appConfig.rootDir))
|
|
240
|
+
return;
|
|
241
|
+
if (isUnattributedPage(page))
|
|
242
|
+
throw createLiteralPageDeclarationError(file);
|
|
243
|
+
const fixes = isPathInside(path.resolve(file), this.appConfig.absolutePaths.pagesDir)
|
|
244
|
+
? ' If the file is not a Page, prefix its name with "_", give it a role suffix such as .server.ts or .script.ts, or move it out of the pages directory.'
|
|
245
|
+
: '';
|
|
246
|
+
throw new Error(`[ecopages] ${file} does not default-export a Page the ${this.name} Integration renders (an eco.page() result).${fixes}`);
|
|
247
|
+
}
|
|
210
248
|
setHmrManager(hmrManager) {
|
|
211
249
|
this.hmrManager = hmrManager;
|
|
212
250
|
if (this.assetProcessingService) {
|
|
@@ -349,11 +387,12 @@ export class IntegrationRenderer {
|
|
|
349
387
|
this.assetProcessingIntegration = assetProcessingIntegration;
|
|
350
388
|
this.htmlTransformer = new HtmlTransformerService();
|
|
351
389
|
this.resolvedIntegrationDependencies = resolvedIntegrationDependencies || [];
|
|
352
|
-
this.dependencyResolverService = new DependencyResolverService(appConfig, assetProcessingService,
|
|
390
|
+
this.dependencyResolverService = new DependencyResolverService(appConfig, assetProcessingService, assetProcessingIntegration);
|
|
353
391
|
this.pageModuleLoaderService = new PageModuleLoaderService(appConfig);
|
|
354
392
|
this.routeRenderOrchestrator = new RouteRenderOrchestrator(appConfig, assetProcessingService, {
|
|
355
393
|
ownershipValidationService: new OwnershipValidationService(appConfig),
|
|
356
394
|
assetProcessingIntegration,
|
|
395
|
+
recordsShellDependencies: () => isProductionRuntime() && this.getActiveHmrManager()?.isEnabled() !== true,
|
|
357
396
|
});
|
|
358
397
|
this.integrationHooks =
|
|
359
398
|
typeof hooks === 'function'
|
|
@@ -400,6 +439,9 @@ export class IntegrationRenderer {
|
|
|
400
439
|
return;
|
|
401
440
|
}
|
|
402
441
|
if (requireAppRuntime(this.appConfig).staticGenerationActive) {
|
|
442
|
+
if (error instanceof MissingProductionServerModuleError) {
|
|
443
|
+
throw new Error(`The ssr script ${scriptPath} is not in the server build. \`ecopages build\` finds ssr scripts from a string literal \`src\` beside \`ssr: true\` in a Component's dependencies; declare its \`src\` as a string literal.`, { cause: error });
|
|
444
|
+
}
|
|
403
445
|
const cause = error instanceof Error ? error.message : String(error);
|
|
404
446
|
throw new Error(`Failed to preload the ssr script ${scriptPath}: ${cause}`, { cause: error });
|
|
405
447
|
}
|
|
@@ -551,12 +593,11 @@ export class IntegrationRenderer {
|
|
|
551
593
|
applyAttributesToHtmlElement: (html, attributes) => this.applyAttributesToHtmlElement(html, attributes),
|
|
552
594
|
});
|
|
553
595
|
}
|
|
554
|
-
async
|
|
555
|
-
const
|
|
596
|
+
async transformRouteHtml(html, htmlContributions, renderOptions) {
|
|
597
|
+
const body = this.htmlTransformer.transform(html, {
|
|
556
598
|
contributions: htmlContributions,
|
|
557
599
|
pagePackage: renderOptions.pagePackage,
|
|
558
600
|
});
|
|
559
|
-
const body = (transformedResponse.body ?? (await transformedResponse.text()));
|
|
560
601
|
return this.finalizeDocument(body, renderOptions);
|
|
561
602
|
}
|
|
562
603
|
finalizeDocument(body, renderOptions) {
|
|
@@ -566,7 +607,7 @@ export class IntegrationRenderer {
|
|
|
566
607
|
const resolvedPageModule = await this.pageModuleLoaderService.resolvePageModule({
|
|
567
608
|
file: routeOptions.file,
|
|
568
609
|
pageModule: routeOptions.pageModule,
|
|
569
|
-
importPageFileFn: (targetFile) => this.
|
|
610
|
+
importPageFileFn: (targetFile) => this.importRouteModule(targetFile),
|
|
570
611
|
});
|
|
571
612
|
const { Page, integrationSpecificProps, module: pageModule } = resolvedPageModule;
|
|
572
613
|
const HtmlTemplate = await this.getHtmlTemplate();
|
|
@@ -601,12 +642,28 @@ export class IntegrationRenderer {
|
|
|
601
642
|
async resolvePageDependenciesForRoute(context) {
|
|
602
643
|
return resolvePageDependenciesFromContext(context, this.name);
|
|
603
644
|
}
|
|
604
|
-
/**
|
|
645
|
+
/**
|
|
646
|
+
* Resolves a route's component assets.
|
|
647
|
+
*
|
|
648
|
+
* @remarks `declarationOrder` returns them in the order the asset ledger records them, for a recorded shell.
|
|
649
|
+
*/
|
|
605
650
|
async resolveRouteDependencies(input) {
|
|
606
651
|
return {
|
|
607
|
-
resolvedDependencies:
|
|
652
|
+
resolvedDependencies: input.declarationOrder
|
|
653
|
+
? await this.dependencyResolverService.processPreparedComponentDependencies(input.components, this.name, true)
|
|
654
|
+
: await this.resolveDependencies(input.components, { preparedGraph: true }),
|
|
608
655
|
};
|
|
609
656
|
}
|
|
657
|
+
/**
|
|
658
|
+
* Holds the lazy client entries of a route's shell components for the page client build.
|
|
659
|
+
*
|
|
660
|
+
* @remarks
|
|
661
|
+
* Processing the shell holds them as a side effect; a shell read from the asset ledger is not processed, so its
|
|
662
|
+
* lazy entries are collected here.
|
|
663
|
+
*/
|
|
664
|
+
prepareRouteLazyDependencies(components) {
|
|
665
|
+
this.dependencyResolverService.prepareLazyClientDependencies(components, this.name);
|
|
666
|
+
}
|
|
610
667
|
async renderRouteBody(renderOptions) {
|
|
611
668
|
return this.render(renderOptions);
|
|
612
669
|
}
|
|
@@ -629,9 +686,8 @@ export class IntegrationRenderer {
|
|
|
629
686
|
* Execution flow:
|
|
630
687
|
* 1. Build normalized render options (`prepareRenderOptions`).
|
|
631
688
|
* 2. Render the route body once.
|
|
632
|
-
* 3.
|
|
633
|
-
* 4.
|
|
634
|
-
* 5. Run HTML transformer with final dependency set.
|
|
689
|
+
* 3. Optionally apply document attributes for integration-owned document boundaries.
|
|
690
|
+
* 4. Run HTML transformer with final dependency set.
|
|
635
691
|
*
|
|
636
692
|
* Stream-safety note: the first render result is normalized to a string once,
|
|
637
693
|
* then the pipeline continues with that immutable HTML value to avoid disturbed
|
|
@@ -697,7 +753,7 @@ export class IntegrationRenderer {
|
|
|
697
753
|
*
|
|
698
754
|
* @remarks
|
|
699
755
|
* `file` is the view's identity file, or a stable synthetic key when the view has
|
|
700
|
-
* none. `props` are the view's final props: its `
|
|
756
|
+
* none. `props` are the view's final props: its `props` hook is the caller's
|
|
701
757
|
* to run, so it is not run here.
|
|
702
758
|
*/
|
|
703
759
|
async executeExplicitView(view, props, ctx = {}) {
|
|
@@ -711,7 +767,7 @@ export class IntegrationRenderer {
|
|
|
711
767
|
query: ctx.query,
|
|
712
768
|
locals: ctx.locals,
|
|
713
769
|
props: (props ?? {}),
|
|
714
|
-
|
|
770
|
+
skipPropsHook: true,
|
|
715
771
|
});
|
|
716
772
|
}
|
|
717
773
|
/**
|
|
@@ -788,10 +844,9 @@ export class IntegrationRenderer {
|
|
|
788
844
|
...options.props,
|
|
789
845
|
params: options.params ?? {},
|
|
790
846
|
query: options.query ?? {},
|
|
791
|
-
locals: options.pageLocals,
|
|
792
847
|
},
|
|
793
848
|
},
|
|
794
|
-
layouts:
|
|
849
|
+
layouts: resolveRenderLayouts(options, {
|
|
795
850
|
layout: options.Layout,
|
|
796
851
|
layoutEntries: options.layoutEntries,
|
|
797
852
|
params: options.params,
|
|
@@ -826,7 +881,6 @@ export class IntegrationRenderer {
|
|
|
826
881
|
currentIntegrationName: this.name,
|
|
827
882
|
input,
|
|
828
883
|
renderComponent: (renderInput) => this.renderComponent(renderInput),
|
|
829
|
-
normalizeComponentRenderOutput: (result) => this.normalizeComponentRenderOutput(result),
|
|
830
884
|
hasForeignChildDescendants: (component, foreignChildRoots) => this.hasForeignChildDescendants(component, foreignChildRoots),
|
|
831
885
|
createForeignChildRuntime: ({ renderInput, rendererCache }) => this.createForeignChildRuntime({
|
|
832
886
|
renderInput,
|
|
@@ -873,31 +927,18 @@ export class IntegrationRenderer {
|
|
|
873
927
|
});
|
|
874
928
|
}
|
|
875
929
|
/**
|
|
876
|
-
* Stamps `result` as an Island Host when the component itself
|
|
930
|
+
* Stamps `result` as an Island Host when the component itself ships a client script.
|
|
877
931
|
*
|
|
878
932
|
* @remarks Reads the component's own declarations, excluding Foreign Children: a component without
|
|
879
933
|
* scripts that wraps an island is not an island itself. Components without `dependencies` are never stamped.
|
|
880
934
|
*/
|
|
881
935
|
finalizeIslandComponentRender(input, result) {
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
return finalizeIslandComponentRender(input, {
|
|
936
|
+
const shipsScript = input.component.config?.dependencies !== undefined &&
|
|
937
|
+
this.dependencyResolverService.componentShipsScript(input.component, this.name);
|
|
938
|
+
return stampIslandHost(input, {
|
|
886
939
|
...result,
|
|
887
940
|
html: finalizeComponentRender(input.component, result.html),
|
|
888
|
-
},
|
|
889
|
-
}
|
|
890
|
-
normalizeComponentRenderOutput(result) {
|
|
891
|
-
const normalizedHtml = this.normalizeUnresolvedMarkerArtifactHtml(result.html);
|
|
892
|
-
return normalizedHtml === result.html
|
|
893
|
-
? result
|
|
894
|
-
: {
|
|
895
|
-
...result,
|
|
896
|
-
html: normalizedHtml,
|
|
897
|
-
};
|
|
898
|
-
}
|
|
899
|
-
normalizeUnresolvedMarkerArtifactHtml(html) {
|
|
900
|
-
return normalizeUnresolvedMarkerArtifactHtml(html);
|
|
941
|
+
}, shipsScript);
|
|
901
942
|
}
|
|
902
943
|
/**
|
|
903
944
|
* @remarks
|
|
@@ -1074,8 +1115,7 @@ export class IntegrationRenderer {
|
|
|
1074
1115
|
const runtime = createQueuedRuntime({
|
|
1075
1116
|
renderInput: options.renderInput,
|
|
1076
1117
|
rendererCache: options.rendererCache,
|
|
1077
|
-
|
|
1078
|
-
tokenPrefix: getForeignSubtreeTokenPrefix(this.name),
|
|
1118
|
+
integrationName: this.name,
|
|
1079
1119
|
});
|
|
1080
1120
|
const normalizeForeignChildProps = this.integrationHooks.normalizeForeignChildProps;
|
|
1081
1121
|
if (!normalizeForeignChildProps) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createPagePackage } from '../../../assets/asset-processing-service/index.js';
|
|
2
2
|
import { dedupeProcessedAssets } from '../../../assets/processed-asset-dedupe.js';
|
|
3
|
-
import { createPageLocalsProxy } from './route-prepared-options.utils.js';
|
|
4
3
|
/**
|
|
5
4
|
* Assembles the final integration render options after route prep dependencies resolve.
|
|
6
5
|
*/
|
|
@@ -16,7 +15,6 @@ export function buildPreparedRenderOptions(input) {
|
|
|
16
15
|
query: routeOptions.query || {},
|
|
17
16
|
};
|
|
18
17
|
const cacheStrategy = Page.cache;
|
|
19
|
-
const pageLocals = routeOptions.locals ?? createPageLocalsProxy(routeOptions.file);
|
|
20
18
|
const locals = routeOptions.locals;
|
|
21
19
|
const preparedOptions = {
|
|
22
20
|
...routeOptions,
|
|
@@ -34,7 +32,6 @@ export function buildPreparedRenderOptions(input) {
|
|
|
34
32
|
query: routeOptions.query || {},
|
|
35
33
|
pageProps,
|
|
36
34
|
locals,
|
|
37
|
-
pageLocals,
|
|
38
35
|
cacheStrategy,
|
|
39
36
|
};
|
|
40
37
|
return {
|
|
@@ -30,20 +30,21 @@ export type RouteHtmlFinalization = {
|
|
|
30
30
|
finalizeHtml?(html: string): string;
|
|
31
31
|
htmlContributions?: HtmlDocumentContribution[];
|
|
32
32
|
};
|
|
33
|
-
export type RouteRenderHost<C> = Pick<IntegrationRenderer<C>, 'name' | 'resolveRouteRenderInputs' | 'resolveRouteDependencies' | 'collectPageBrowserGraphContribution' | 'resolvePageDependenciesForRoute' | 'resolvePageDependencyContribution' | 'buildPageClientBrowserAssets' | 'getPageSsrScriptIntegrationNames' | 'renderRouteBody' | 'getRouteHtmlFinalization' | '
|
|
34
|
-
/**
|
|
35
|
-
* Captured route-render output in both replayable body and string HTML forms.
|
|
36
|
-
*/
|
|
37
|
-
export interface CapturedHtmlRenderResult {
|
|
38
|
-
body: RouteRendererBody;
|
|
39
|
-
html: string;
|
|
40
|
-
}
|
|
33
|
+
export type RouteRenderHost<C> = Pick<IntegrationRenderer<C>, 'name' | 'resolveRouteRenderInputs' | 'resolveRouteDependencies' | 'prepareRouteLazyDependencies' | 'collectPageBrowserGraphContribution' | 'resolvePageDependenciesForRoute' | 'resolvePageDependencyContribution' | 'buildPageClientBrowserAssets' | 'getPageSsrScriptIntegrationNames' | 'renderRouteBody' | 'getRouteHtmlFinalization' | 'transformRouteHtml'>;
|
|
41
34
|
/**
|
|
42
35
|
* Optional app-scoped collaborators used by the route render orchestrator.
|
|
43
36
|
*/
|
|
44
37
|
export interface RouteRenderOrchestratorDependencies {
|
|
45
38
|
ownershipValidationService?: OwnershipValidationService;
|
|
46
39
|
assetProcessingIntegration?: AssetProcessingIntegration;
|
|
40
|
+
/**
|
|
41
|
+
* Whether processed assets are final for the life of the process, so a route's shell Dependencies are recorded in
|
|
42
|
+
* the asset ledger once per Page and Html template and read from it afterwards.
|
|
43
|
+
*
|
|
44
|
+
* @remarks True in production without HMR. In development an edited stylesheet changes its processed output
|
|
45
|
+
* without re-importing any module, so the shell Dependencies are processed on every render.
|
|
46
|
+
*/
|
|
47
|
+
recordsShellDependencies?: () => boolean;
|
|
47
48
|
}
|
|
48
49
|
export type PreparedRouteGraphContext = {
|
|
49
50
|
dependencyInstanceKey: string;
|
|
@@ -80,11 +81,16 @@ export declare class RouteRenderOrchestrator {
|
|
|
80
81
|
private readonly ownershipValidationService;
|
|
81
82
|
private readonly pageBrowserGraphService;
|
|
82
83
|
private readonly requestPipelineMetrics;
|
|
84
|
+
private readonly recordsShellDependencies;
|
|
83
85
|
constructor(appConfig: EcoPagesAppConfig, assetProcessingService: AssetProcessingService, dependencies?: RouteRenderOrchestratorDependencies);
|
|
84
86
|
private validateOwnershipGraph;
|
|
85
87
|
/**
|
|
86
88
|
* Shares route graph preparation with the production grouped prebuild.
|
|
87
89
|
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* The graph context of a Dynamic Page carries no props: they come from the request, while its Page Browser Graph
|
|
92
|
+
* is planned at build and cached by Params and Query alone.
|
|
93
|
+
*
|
|
88
94
|
* @internal
|
|
89
95
|
*/
|
|
90
96
|
prepareRouteGraphContext<C>(input: {
|
|
@@ -96,6 +102,7 @@ export declare class RouteRenderOrchestrator {
|
|
|
96
102
|
planning?: true;
|
|
97
103
|
}): Promise<PreparedRouteGraphContext>;
|
|
98
104
|
private prepareRouteShellGraph;
|
|
105
|
+
private recordLayoutFiles;
|
|
99
106
|
private preparePageDependencyGraph;
|
|
100
107
|
private collectPageDependencyNodes;
|
|
101
108
|
private processPlannedPageDependencies;
|
|
@@ -115,9 +122,28 @@ export declare class RouteRenderOrchestrator {
|
|
|
115
122
|
*/
|
|
116
123
|
prepareRenderOptions<C = unknown>(routeOptions: RouteRendererOptions, renderer: RouteRenderHost<C>, planned?: PlannedRoutePreparation): Promise<InternalIntegrationRendererRenderOptions<C>>;
|
|
117
124
|
/**
|
|
118
|
-
*
|
|
125
|
+
* Reads the Dependencies of the route's shell from the asset ledger, or processes them.
|
|
126
|
+
*
|
|
127
|
+
* @remarks
|
|
128
|
+
* A route's shell is its Html template, Layouts and Page, and the Layouts are fixed by the Page, so the identities
|
|
129
|
+
* of the Page and the Html template fix the result. When processed assets are final, the first preparation of a
|
|
130
|
+
* Page in `ecopages build` records its shell in the ledger, and every later one reads it there, including those
|
|
131
|
+
* of `ecopages start`, which never packages or processes a shell. Packaging the shell reads its stylesheet
|
|
132
|
+
* sources, which a deploy may not hold. A read shell still holds its lazy client entries for the page client
|
|
133
|
+
* build, which processing would have held.
|
|
134
|
+
*/
|
|
135
|
+
private resolveShellDependencies;
|
|
136
|
+
/**
|
|
137
|
+
* Names a declaration the same wherever the app runs: its root-relative file and its id.
|
|
138
|
+
*
|
|
139
|
+
* @remarks
|
|
140
|
+
* A runtime identity, such as an HTML Page's, holds an absolute file, and the built-in Html shell has none.
|
|
141
|
+
*/
|
|
142
|
+
private describeIdentity;
|
|
143
|
+
/**
|
|
144
|
+
* Reads one route render body as an HTML string.
|
|
119
145
|
*/
|
|
120
|
-
captureHtmlRender(render: () => Promise<RouteRendererBody>): Promise<
|
|
146
|
+
captureHtmlRender(render: () => Promise<RouteRendererBody>): Promise<string>;
|
|
121
147
|
/**
|
|
122
148
|
* Executes the full route-render flow and returns the final body plus cache strategy.
|
|
123
149
|
*/
|
|
@@ -140,5 +166,4 @@ export declare class RouteRenderOrchestrator {
|
|
|
140
166
|
* closure is recorded only then. Editing any of them must miss the cached document.
|
|
141
167
|
*/
|
|
142
168
|
private withHtmlTemplateClosure;
|
|
143
|
-
private captureRenderedBody;
|
|
144
169
|
}
|
|
@@ -2,7 +2,8 @@ import { path } from '@ecopages/file-system/path';
|
|
|
2
2
|
import { isProductionRuntime } from '../../../utils/runtime.js';
|
|
3
3
|
import { collectHtmlCacheSourceDependencyPaths } from '../../../page-cache/html-page-cache-dependency-index.js';
|
|
4
4
|
import { requireAppRuntime } from '../../../utils/app-runtime.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getComponentIdentity } from '../../../eco/component-identity.js';
|
|
6
|
+
import { toRootRelativePath } from '../../../utils/root-relative-path.js';
|
|
6
7
|
import { createPreparedComponentGraphBuilder, } from '../ownership-graph/component-graph.js';
|
|
7
8
|
import { OwnershipValidationService, throwIfOwnershipInvalid, } from '../ownership-graph/ownership-validation.service.js';
|
|
8
9
|
import { collectComponentGraphWatchPaths, collectPageIntegrationDependencies, } from '../ownership-graph/component-graph-collectors.js';
|
|
@@ -12,6 +13,7 @@ import { buildGlobalInjectorAssets } from '../page-browser-graph/global-injector
|
|
|
12
13
|
import { mergePageBrowserGraphContributions } from '../page-browser-graph/page-browser-graph-contribution.merge.js';
|
|
13
14
|
import { PageBrowserGraphService } from '../page-browser-graph/page-browser-graph.service.js';
|
|
14
15
|
import { createPageDependencyInstanceKey } from '../page-browser-graph/route-instance-key.js';
|
|
16
|
+
import { isDynamicPage } from '../../../eco/page-data-hooks.js';
|
|
15
17
|
import { buildPreparedRenderOptions } from './route-prepared-options.builder.js';
|
|
16
18
|
import { measureRouteRenderPhase } from '../../../diagnostics/request-pipeline-metrics.js';
|
|
17
19
|
/**
|
|
@@ -28,10 +30,12 @@ export class RouteRenderOrchestrator {
|
|
|
28
30
|
ownershipValidationService;
|
|
29
31
|
pageBrowserGraphService;
|
|
30
32
|
requestPipelineMetrics;
|
|
33
|
+
recordsShellDependencies;
|
|
31
34
|
constructor(appConfig, assetProcessingService, dependencies = {}) {
|
|
32
35
|
this.appConfig = appConfig;
|
|
33
36
|
this.requestPipelineMetrics = requireAppRuntime(appConfig).requestPipelineMetrics;
|
|
34
37
|
this.assetProcessingService = assetProcessingService;
|
|
38
|
+
this.recordsShellDependencies = dependencies.recordsShellDependencies ?? (() => false);
|
|
35
39
|
this.ownershipValidationService =
|
|
36
40
|
dependencies.ownershipValidationService ?? new OwnershipValidationService(appConfig);
|
|
37
41
|
this.pageBrowserGraphService = new PageBrowserGraphService(appConfig, assetProcessingService, dependencies.assetProcessingIntegration);
|
|
@@ -45,6 +49,10 @@ export class RouteRenderOrchestrator {
|
|
|
45
49
|
/**
|
|
46
50
|
* Shares route graph preparation with the production grouped prebuild.
|
|
47
51
|
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* The graph context of a Dynamic Page carries no props: they come from the request, while its Page Browser Graph
|
|
54
|
+
* is planned at build and cached by Params and Query alone.
|
|
55
|
+
*
|
|
48
56
|
* @internal
|
|
49
57
|
*/
|
|
50
58
|
async prepareRouteGraphContext(input) {
|
|
@@ -57,7 +65,7 @@ export class RouteRenderOrchestrator {
|
|
|
57
65
|
const graphContext = {
|
|
58
66
|
file: routeOptions.file,
|
|
59
67
|
pageModule: resolvedInputs.pageModule,
|
|
60
|
-
props,
|
|
68
|
+
props: isDynamicPage(resolvedInputs.pageModule.default) ? undefined : props,
|
|
61
69
|
params: routeOptions.params,
|
|
62
70
|
query: routeOptions.query,
|
|
63
71
|
dependencyInstanceKey,
|
|
@@ -90,12 +98,23 @@ export class RouteRenderOrchestrator {
|
|
|
90
98
|
const graphBuilder = createPreparedComponentGraphBuilder(renderer.name);
|
|
91
99
|
graphBuilder.addRoots(shellRoots);
|
|
92
100
|
const shellGraph = graphBuilder.getGraph({ updateForeignDescendantFlags: false });
|
|
101
|
+
this.recordLayoutFiles(shellGraph);
|
|
93
102
|
const shellDependencyComponents = shellGraph.nodes
|
|
94
103
|
.filter((node) => node.dependencyCollectionVisible)
|
|
95
104
|
.map((node) => node.component);
|
|
96
105
|
await this.validateOwnershipGraph(shellGraph);
|
|
97
106
|
return { graphBuilder, shellGraph, shellDependencyComponents };
|
|
98
107
|
}
|
|
108
|
+
recordLayoutFiles(shellGraph) {
|
|
109
|
+
if (isProductionRuntime())
|
|
110
|
+
return;
|
|
111
|
+
const layoutFiles = requireAppRuntime(this.appConfig).layoutFiles;
|
|
112
|
+
for (const node of shellGraph.nodes) {
|
|
113
|
+
if (node.source === 'layout' && node.componentFile) {
|
|
114
|
+
layoutFiles.add(path.resolve(this.appConfig.rootDir, node.componentFile));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
99
118
|
async preparePageDependencyGraph(input) {
|
|
100
119
|
const { renderer, graphContext, graphBuilder } = input;
|
|
101
120
|
const resolvedPageDependencies = await renderer.resolvePageDependenciesForRoute(graphContext);
|
|
@@ -176,14 +195,12 @@ export class RouteRenderOrchestrator {
|
|
|
176
195
|
renderer,
|
|
177
196
|
});
|
|
178
197
|
const { dependencyInstanceKey, graphContext: contributionContext, resolvedPageDependencies, shellDependencyComponents, graph: preparedGraph, } = graphContext;
|
|
179
|
-
const
|
|
180
|
-
components: shellDependencyComponents,
|
|
181
|
-
}));
|
|
198
|
+
const resolvedDependencies = await measureRouteRenderPhase(this.requestPipelineMetrics, 'resolve-dependencies', () => this.resolveShellDependencies(renderer, finalResolvedInputs, shellDependencyComponents));
|
|
182
199
|
const pageBrowserGraph = await measureRouteRenderPhase(this.requestPipelineMetrics, 'page-browser-graph', () => this.pageBrowserGraphService.resolvePageBrowserGraph({
|
|
183
200
|
routeFile: routeOptions.file,
|
|
184
201
|
dependencyInstanceKey,
|
|
185
202
|
integrationName: renderer.name,
|
|
186
|
-
cacheable: !routeOptions.pageModule && !routeOptions.props && !routeOptions.
|
|
203
|
+
cacheable: !routeOptions.pageModule && !routeOptions.props && !routeOptions.skipPropsHook,
|
|
187
204
|
collectContribution: async () => mergePageBrowserGraphContributions(await renderer.collectPageBrowserGraphContribution(contributionContext), resolvedPageDependencies?.contribution),
|
|
188
205
|
}));
|
|
189
206
|
const graphDependencyPaths = this.pageBrowserGraphService.getDependencyPathsForRoute({
|
|
@@ -240,15 +257,56 @@ export class RouteRenderOrchestrator {
|
|
|
240
257
|
};
|
|
241
258
|
}
|
|
242
259
|
/**
|
|
243
|
-
*
|
|
260
|
+
* Reads the Dependencies of the route's shell from the asset ledger, or processes them.
|
|
261
|
+
*
|
|
262
|
+
* @remarks
|
|
263
|
+
* A route's shell is its Html template, Layouts and Page, and the Layouts are fixed by the Page, so the identities
|
|
264
|
+
* of the Page and the Html template fix the result. When processed assets are final, the first preparation of a
|
|
265
|
+
* Page in `ecopages build` records its shell in the ledger, and every later one reads it there, including those
|
|
266
|
+
* of `ecopages start`, which never packages or processes a shell. Packaging the shell reads its stylesheet
|
|
267
|
+
* sources, which a deploy may not hold. A read shell still holds its lazy client entries for the page client
|
|
268
|
+
* build, which processing would have held.
|
|
269
|
+
*/
|
|
270
|
+
async resolveShellDependencies(renderer, resolvedInputs, components) {
|
|
271
|
+
const pageIdentity = getComponentIdentity(resolvedInputs.Page);
|
|
272
|
+
const key = this.recordsShellDependencies() && pageIdentity
|
|
273
|
+
? `${this.describeIdentity(pageIdentity)}|${this.describeIdentity(getComponentIdentity(resolvedInputs.HtmlTemplate))}`
|
|
274
|
+
: undefined;
|
|
275
|
+
const ledger = requireAppRuntime(this.appConfig).processedAssets;
|
|
276
|
+
const recorded = key ? ledger.lookupShell(key) : undefined;
|
|
277
|
+
if (recorded) {
|
|
278
|
+
renderer.prepareRouteLazyDependencies(components);
|
|
279
|
+
return recorded;
|
|
280
|
+
}
|
|
281
|
+
if (key && ledger.isSealed) {
|
|
282
|
+
throw new Error(`The production build did not record the shell Dependencies of ${this.describeIdentity(pageIdentity)}. Run \`ecopages build\` again.`);
|
|
283
|
+
}
|
|
284
|
+
const { resolvedDependencies } = await renderer.resolveRouteDependencies({
|
|
285
|
+
components,
|
|
286
|
+
declarationOrder: key !== undefined,
|
|
287
|
+
});
|
|
288
|
+
if (key)
|
|
289
|
+
ledger.recordShell(key, resolvedDependencies);
|
|
290
|
+
return resolvedDependencies;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Names a declaration the same wherever the app runs: its root-relative file and its id.
|
|
294
|
+
*
|
|
295
|
+
* @remarks
|
|
296
|
+
* A runtime identity, such as an HTML Page's, holds an absolute file, and the built-in Html shell has none.
|
|
297
|
+
*/
|
|
298
|
+
describeIdentity(identity) {
|
|
299
|
+
if (!identity)
|
|
300
|
+
return 'built-in';
|
|
301
|
+
const { rootDir } = this.appConfig;
|
|
302
|
+
return `${toRootRelativePath(rootDir, path.resolve(rootDir, identity.file))}#${identity.id}`;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Reads one route render body as an HTML string.
|
|
244
306
|
*/
|
|
245
307
|
async captureHtmlRender(render) {
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
return {
|
|
249
|
-
body: capturedRender.body,
|
|
250
|
-
html: capturedRender.html,
|
|
251
|
-
};
|
|
308
|
+
const body = await render();
|
|
309
|
+
return typeof body === 'string' ? body : new Response(body).text();
|
|
252
310
|
}
|
|
253
311
|
/**
|
|
254
312
|
* Executes the full route-render flow and returns the final body plus cache strategy.
|
|
@@ -261,37 +319,11 @@ export class RouteRenderOrchestrator {
|
|
|
261
319
|
* Executes the route-render finalization path for already prepared render options.
|
|
262
320
|
*/
|
|
263
321
|
async executePrepared(renderOptions, renderer) {
|
|
264
|
-
const
|
|
322
|
+
const renderedHtml = await measureRouteRenderPhase(this.requestPipelineMetrics, 'render-body', () => this.captureHtmlRender(async () => renderer.renderRouteBody(renderOptions)));
|
|
265
323
|
const sourceDependencyPaths = this.withHtmlTemplateClosure(renderOptions.sourceDependencyPaths);
|
|
266
|
-
const unresolvedArtifactInspection = inspectUnresolvedMarkerArtifactHtml(renderExecution.html);
|
|
267
324
|
const htmlFinalization = renderer.getRouteHtmlFinalization(renderOptions);
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
throw new Error('[ecopages] Route render returned unresolved eco-marker artifact HTML. Full-route unresolved-marker fallback has been removed; resolve mixed foreign children inside renderComponentWithForeignChildren().');
|
|
271
|
-
}
|
|
272
|
-
const canReuseCapturedBody = !hasUnresolvedMarkerHtml && htmlFinalization.finalizeHtml === undefined;
|
|
273
|
-
if (canReuseCapturedBody) {
|
|
274
|
-
const responseBody = typeof renderExecution.body === 'string' ? renderExecution.body : renderExecution.html;
|
|
275
|
-
const body = await measureRouteRenderPhase(this.requestPipelineMetrics, 'transform-response', () => renderer.transformRouteResponse(new Response(responseBody, {
|
|
276
|
-
headers: {
|
|
277
|
-
'Content-Type': 'text/html',
|
|
278
|
-
},
|
|
279
|
-
}), htmlFinalization.htmlContributions, renderOptions));
|
|
280
|
-
return {
|
|
281
|
-
body,
|
|
282
|
-
cacheStrategy: renderOptions.cacheStrategy,
|
|
283
|
-
sourceDependencyPaths,
|
|
284
|
-
metadata: renderOptions.metadata,
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
const finalization = htmlFinalization.finalizeHtml
|
|
288
|
-
? htmlFinalization.finalizeHtml(unresolvedArtifactInspection.normalizedHtml)
|
|
289
|
-
: unresolvedArtifactInspection.normalizedHtml;
|
|
290
|
-
const body = await measureRouteRenderPhase(this.requestPipelineMetrics, 'transform-response', () => renderer.transformRouteResponse(new Response(finalization, {
|
|
291
|
-
headers: {
|
|
292
|
-
'Content-Type': 'text/html',
|
|
293
|
-
},
|
|
294
|
-
}), htmlFinalization.htmlContributions, renderOptions));
|
|
325
|
+
const finalHtml = htmlFinalization.finalizeHtml ? htmlFinalization.finalizeHtml(renderedHtml) : renderedHtml;
|
|
326
|
+
const body = await measureRouteRenderPhase(this.requestPipelineMetrics, 'transform-response', () => renderer.transformRouteHtml(finalHtml, htmlFinalization.htmlContributions, renderOptions));
|
|
295
327
|
return {
|
|
296
328
|
body,
|
|
297
329
|
cacheStrategy: renderOptions.cacheStrategy,
|
|
@@ -339,26 +371,6 @@ export class RouteRenderOrchestrator {
|
|
|
339
371
|
});
|
|
340
372
|
return [...new Set([...sourcePaths, ...templateClosure])];
|
|
341
373
|
}
|
|
342
|
-
async captureRenderedBody(body) {
|
|
343
|
-
const response = new Response(body);
|
|
344
|
-
if (typeof body === 'string') {
|
|
345
|
-
return {
|
|
346
|
-
body,
|
|
347
|
-
html: await response.text(),
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
if (!response.body) {
|
|
351
|
-
return {
|
|
352
|
-
body,
|
|
353
|
-
html: await response.text(),
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
const [capturedBody, replayBody] = response.body.tee();
|
|
357
|
-
return {
|
|
358
|
-
body: replayBody,
|
|
359
|
-
html: await new Response(capturedBody).text(),
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
374
|
}
|
|
363
375
|
/**
|
|
364
376
|
* @remarks
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether `page` is a declared component whose build-time identity names `file`, absolute or relative to `rootDir`.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The identity transform stamps the file that holds the literal `eco.page(...)` call, so a Page made by a
|
|
6
|
+
* wrapper in another file, or re-exported from one, names that other file.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isPageDeclaredIn(file: string, page: unknown, rootDir: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Whether `page` is a function carrying a `config`, which is what a wrapped or re-exported `eco.page()` result
|
|
11
|
+
* looks like when {@link isPageDeclaredIn} fails.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isUnattributedPage(page: unknown): boolean;
|
|
14
|
+
/** The error for a view or route file whose Page the build did not attribute to it. */
|
|
15
|
+
export declare function createLiteralPageDeclarationError(file: string): Error;
|
|
16
|
+
/**
|
|
17
|
+
* Fails when a view loaded from `file` is not a Page that file declares with a literal `eco.page(...)` call.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Applies the route-file check to views passed to `app.static()`, `app.errorPage()` and `ctx.render()`, so a view
|
|
21
|
+
* behaves the same however it is routed. A value that is not a declared component at all is left to the
|
|
22
|
+
* renderer lookup, which reports a missing integration.
|
|
23
|
+
* @throws When `view` carries a config that the build did not attribute to `file`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function assertViewDeclaredIn(file: string, view: unknown, rootDir: string): void;
|