@ecopages/core 0.5.0 → 0.6.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.
Files changed (128) hide show
  1. package/README.md +17 -13
  2. package/package.json +13 -4
  3. package/src/adapters/create-app.js +9 -5
  4. package/src/adapters/node/create-app.d.ts +18 -16
  5. package/src/adapters/node/create-app.js +26 -30
  6. package/src/adapters/node/server-adapter.d.ts +26 -9
  7. package/src/adapters/node/server-adapter.js +38 -8
  8. package/src/adapters/shared/hmr/hmr-manager.js +3 -2
  9. package/src/adapters/shared/http/dist-file-handler.js +25 -7
  10. package/src/adapters/shared/runtime/render-context.d.ts +2 -1
  11. package/src/adapters/shared/runtime/render-context.js +18 -21
  12. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +4 -3
  13. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +6 -4
  14. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +6 -1
  15. package/src/adapters/shared/runtime/server-request-pipeline.js +10 -10
  16. package/src/adapters/shared/runtime/server-static-builder.d.ts +11 -11
  17. package/src/adapters/shared/runtime/server-static-builder.js +37 -18
  18. package/src/assets/app-browser-client-manifest.d.ts +1 -3
  19. package/src/assets/app-browser-client-manifest.js +5 -58
  20. package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +2 -2
  21. package/src/assets/asset-processing-service/processors/script/file-script.processor.js +2 -2
  22. package/src/assets/browser-asset-output.d.ts +1 -1
  23. package/src/assets/browser-asset-output.js +1 -1
  24. package/src/build/app-build-manifest-runtime.d.ts +11 -1
  25. package/src/build/app-build-manifest-runtime.js +17 -3
  26. package/src/build/cache/pages-unified-graph-build.d.ts +32 -35
  27. package/src/build/cache/pages-unified-graph-build.js +206 -124
  28. package/src/build/cache/server-module-entries.d.ts +35 -0
  29. package/src/build/cache/server-module-entries.js +109 -0
  30. package/src/build/contracts/build-contracts.d.ts +5 -0
  31. package/src/build/copy-server-files.d.ts +10 -0
  32. package/src/build/copy-server-files.js +37 -0
  33. package/src/build/preserve-import-meta-transform.d.ts +1 -1
  34. package/src/build/preserve-import-meta-transform.js +1 -1
  35. package/src/build/production-build-id.d.ts +9 -0
  36. package/src/build/production-build-id.js +19 -0
  37. package/src/build/production-dist-complete.d.ts +5 -0
  38. package/src/build/production-dist-complete.js +101 -0
  39. package/src/build/production-route-list.d.ts +26 -0
  40. package/src/build/production-route-list.js +78 -0
  41. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +2 -2
  42. package/src/build/rolldown/rolldown-adapter-helpers.js +56 -4
  43. package/src/build/rolldown/rolldown-build-adapter.js +1 -1
  44. package/src/build/runtime/build-request-identity.js +2 -1
  45. package/src/build/runtime/build-request-policy.d.ts +3 -2
  46. package/src/build/runtime/build-request-policy.js +5 -3
  47. package/src/build/server/import-view-module.d.ts +11 -0
  48. package/src/build/server/import-view-module.js +21 -0
  49. package/src/build/server/imported-view-plugin.d.ts +16 -0
  50. package/src/build/server/imported-view-plugin.js +59 -0
  51. package/src/build/server/page-module-import.service.d.ts +19 -20
  52. package/src/build/server/page-module-import.service.js +65 -36
  53. package/src/build/server/resolve-static-view.d.ts +9 -0
  54. package/src/build/server/resolve-static-view.js +28 -0
  55. package/src/build/server/route-module-build-cache-registry.d.ts +5 -3
  56. package/src/build/server/route-module-build-cache-registry.js +5 -3
  57. package/src/build/server/server-modules-manifest.d.ts +51 -0
  58. package/src/build/server/server-modules-manifest.js +129 -0
  59. package/src/build/server/view-reference.d.ts +38 -0
  60. package/src/build/server/view-reference.js +112 -0
  61. package/src/build/server-bundle-deploy-manifest.d.ts +9 -9
  62. package/src/build/server-bundle-deploy-manifest.js +24 -28
  63. package/src/build.d.ts +3 -1
  64. package/src/build.js +3 -1
  65. package/src/config/assembly/app-runtime.d.ts +15 -2
  66. package/src/config/assembly/app-runtime.js +3 -1
  67. package/src/config/assembly/finalize-config.js +64 -13
  68. package/src/config/index.d.ts +1 -0
  69. package/src/config/index.js +1 -0
  70. package/src/config/internal-types.d.ts +6 -0
  71. package/src/config/load-eco-config.d.ts +1 -0
  72. package/src/config/load-eco-config.js +11 -2
  73. package/src/config/resolve-eco-config-path.d.ts +2 -1
  74. package/src/config/resolve-eco-config-path.js +21 -15
  75. package/src/config/user-config-types.d.ts +9 -2
  76. package/src/html-pages/html-page-module.d.ts +19 -0
  77. package/src/html-pages/html-page-module.js +66 -13
  78. package/src/html-pages/html-page-renderer.d.ts +4 -0
  79. package/src/html-pages/html-page-renderer.js +9 -3
  80. package/src/html-pages/html-pages.plugin.d.ts +10 -0
  81. package/src/html-pages/html-pages.plugin.js +7 -1
  82. package/src/index.d.ts +2 -0
  83. package/src/index.js +2 -0
  84. package/src/integration.d.ts +2 -1
  85. package/src/integration.js +1 -0
  86. package/src/page-cache/page-cache-service.d.ts +8 -0
  87. package/src/page-cache/page-cache-service.js +12 -0
  88. package/src/plugins/integration-plugin.d.ts +33 -6
  89. package/src/plugins/integration-plugin.js +14 -2
  90. package/src/plugins/processor.d.ts +17 -0
  91. package/src/plugins/processor.js +20 -1
  92. package/src/plugins/server-dom.d.ts +29 -0
  93. package/src/plugins/server-dom.js +36 -0
  94. package/src/route-renderer/error-pages/error-page-renderer.d.ts +6 -4
  95. package/src/route-renderer/error-pages/error-page-renderer.js +9 -5
  96. package/src/route-renderer/orchestration/integration-renderer.d.ts +1 -0
  97. package/src/route-renderer/orchestration/integration-renderer.js +17 -2
  98. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +21 -0
  99. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +31 -0
  100. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +58 -24
  101. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +12 -0
  102. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +55 -0
  103. package/src/router/server/route-registry.d.ts +22 -2
  104. package/src/router/server/route-registry.js +39 -15
  105. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +8 -2
  106. package/src/static-site-generator/production-page-browser-graph-prebuild.js +14 -9
  107. package/src/static-site-generator/static-site-generator.d.ts +19 -3
  108. package/src/static-site-generator/static-site-generator.js +78 -40
  109. package/src/types/contracts.d.ts +20 -31
  110. package/src/types/public-types.d.ts +1 -0
  111. package/src/types/view-reference.d.ts +31 -0
  112. package/src/types/view-reference.js +15 -0
  113. package/src/utils/additional-watch-paths.d.ts +3 -3
  114. package/src/utils/additional-watch-paths.js +3 -1
  115. package/src/utils/resolve-entry-file.d.ts +4 -2
  116. package/src/utils/resolve-entry-file.js +4 -2
  117. package/src/utils/root-relative-path.d.ts +4 -0
  118. package/src/utils/root-relative-path.js +8 -0
  119. package/src/utils/server-bundle-context.d.ts +14 -0
  120. package/src/utils/server-bundle-context.js +45 -0
  121. package/src/watchers/project-watcher-ignore.d.ts +2 -5
  122. package/src/watchers/project-watcher-ignore.js +2 -5
  123. package/src/watchers/project-watcher.d.ts +9 -7
  124. package/src/watchers/project-watcher.js +100 -52
  125. package/src/watchers/workspace-package-watch-roots.d.ts +4 -4
  126. package/src/watchers/workspace-package-watch-roots.js +41 -25
  127. package/src/build/server/view-module-loader.d.ts +0 -10
  128. package/src/build/server/view-module-loader.js +0 -46
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Process-wide server DOM installation for Integrations that render custom elements.
3
+ *
4
+ * @remarks
5
+ * Lit and Radiant each need constructors on `globalThis`. Installing a complete
6
+ * surface after an incomplete one replaces `customElements` and drops defined
7
+ * elements. Core therefore runs every configured `complete` installer, then
8
+ * every `repair`, before Integration `setup()` continues. Config order does not
9
+ * change the result. Installers must be idempotent and must not replace an
10
+ * existing custom element registry.
11
+ */
12
+ export type ServerDomSurfaceKind = 'complete' | 'repair';
13
+ export type ServerDomInstaller = {
14
+ kind: ServerDomSurfaceKind;
15
+ install: () => void | Promise<void>;
16
+ };
17
+ export type ServerDomContributor = {
18
+ serverDom?: ServerDomInstaller;
19
+ };
20
+ /**
21
+ * Installs the configured server DOM surfaces, serializing concurrent callers.
22
+ *
23
+ * @remarks
24
+ * Complete surfaces run first, then repairs, regardless of Integration order.
25
+ * Each caller runs its own installers after the previous pass, so a second app
26
+ * that starts while the first is still installing is not skipped. Installers
27
+ * must be idempotent and must not replace an existing custom element registry.
28
+ */
29
+ export declare function installConfiguredServerDom(integrations: ReadonlyArray<ServerDomContributor>): Promise<void>;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Process-wide server DOM installation for Integrations that render custom elements.
3
+ *
4
+ * @remarks
5
+ * Lit and Radiant each need constructors on `globalThis`. Installing a complete
6
+ * surface after an incomplete one replaces `customElements` and drops defined
7
+ * elements. Core therefore runs every configured `complete` installer, then
8
+ * every `repair`, before Integration `setup()` continues. Config order does not
9
+ * change the result. Installers must be idempotent and must not replace an
10
+ * existing custom element registry.
11
+ */
12
+ let tail = Promise.resolve();
13
+ /**
14
+ * Installs the configured server DOM surfaces, serializing concurrent callers.
15
+ *
16
+ * @remarks
17
+ * Complete surfaces run first, then repairs, regardless of Integration order.
18
+ * Each caller runs its own installers after the previous pass, so a second app
19
+ * that starts while the first is still installing is not skipped. Installers
20
+ * must be idempotent and must not replace an existing custom element registry.
21
+ */
22
+ export async function installConfiguredServerDom(integrations) {
23
+ const run = tail.then(() => runInstallers(integrations));
24
+ tail = run.then(() => undefined, () => undefined);
25
+ await run;
26
+ }
27
+ async function runInstallers(integrations) {
28
+ const installers = integrations
29
+ .map((integration) => integration.serverDom)
30
+ .filter((installer) => installer !== undefined);
31
+ const complete = installers.filter((installer) => installer.kind === 'complete');
32
+ const repair = installers.filter((installer) => installer.kind !== 'complete');
33
+ for (const installer of [...complete, ...repair]) {
34
+ await installer.install();
35
+ }
36
+ }
@@ -15,10 +15,12 @@ export type ErrorPageRenderInput = {
15
15
  * Owns error-page source precedence and rendering for runtime and static paths.
16
16
  *
17
17
  * @remarks
18
- * Filesystem semantic pages win over explicitly registered views. A missing
19
- * custom source is the only case that uses a framework default; rendering
20
- * failures are intentionally propagated so callers can apply their own retry
21
- * or fallback policy without hiding the original failure.
18
+ * Filesystem semantic pages win over explicitly registered views. A recorded
19
+ * production server-modules entry counts as a filesystem source when the
20
+ * original file is gone. A missing custom source is the only case that uses a
21
+ * framework default; rendering failures are intentionally propagated so
22
+ * callers can apply their own retry or fallback policy without hiding the
23
+ * original failure.
22
24
  */
23
25
  export declare class ErrorPageRenderer {
24
26
  private readonly appConfig;
@@ -1,6 +1,7 @@
1
1
  import { fileSystem } from '@ecopages/file-system';
2
2
  import { appLogger } from '../../global/app-logger.js';
3
3
  import { ensureIntegrationRuntimeReady } from '../../build/app-build-manifest-runtime.js';
4
+ import { hasProductionServerModule } from '../../build/server/server-modules-manifest.js';
4
5
  import { findIntegrationForFile } from '../../plugins/find-integration-for-file.js';
5
6
  import { prepareExplicitStaticRender } from '../explicit-view-render-preparation.js';
6
7
  import { ERROR_PAGE_STATUS_BY_KIND, kindForStatus } from '../../errors/http-error-page-contract.js';
@@ -20,10 +21,12 @@ function resolveRenderTarget(input) {
20
21
  * Owns error-page source precedence and rendering for runtime and static paths.
21
22
  *
22
23
  * @remarks
23
- * Filesystem semantic pages win over explicitly registered views. A missing
24
- * custom source is the only case that uses a framework default; rendering
25
- * failures are intentionally propagated so callers can apply their own retry
26
- * or fallback policy without hiding the original failure.
24
+ * Filesystem semantic pages win over explicitly registered views. A recorded
25
+ * production server-modules entry counts as a filesystem source when the
26
+ * original file is gone. A missing custom source is the only case that uses a
27
+ * framework default; rendering failures are intentionally propagated so
28
+ * callers can apply their own retry or fallback policy without hiding the
29
+ * original failure.
27
30
  */
28
31
  export class ErrorPageRenderer {
29
32
  appConfig;
@@ -62,7 +65,8 @@ export class ErrorPageRenderer {
62
65
  }
63
66
  resolveCustomSource(kind) {
64
67
  const templatePath = this.getTemplatePath(kind);
65
- if (templatePath && fileSystem.exists(templatePath)) {
68
+ if (templatePath &&
69
+ (fileSystem.exists(templatePath) || hasProductionServerModule(this.appConfig, templatePath))) {
66
70
  return { kind: 'filesystem', templatePath };
67
71
  }
68
72
  const loader = this.loaders[kind];
@@ -455,6 +455,7 @@ export declare abstract class IntegrationRenderer<C = EcoPagesElement> {
455
455
  */
456
456
  buildPageClientBrowserAssets(plan: PageClientPlan, route?: Pick<RouteRendererOptions, 'file' | 'params' | 'query'>): Promise<PageClientBrowserAssets>;
457
457
  private buildPrebuiltPageClientBrowserAssets;
458
+ private rejectUnplannedProductionPageClientGraph;
458
459
  private resolvePrebuiltPageClientInstance;
459
460
  private collectAppBrowserClientBuildEntries;
460
461
  private prepareGraphLazyClientDependencies;
@@ -37,6 +37,7 @@ import { renderPageDocumentShell, } from './document-shell/document-shell-render
37
37
  import { resolveInnermostPageLayout, resolvePageLayoutComponents, resolveDocumentShellLayouts, } from './document-shell/layout-shell-props.service.js';
38
38
  import { finalizeIslandComponentRender } from '../../islands/island-host.js';
39
39
  import { isProductionRuntime } from '../../utils/runtime.js';
40
+ import { describeProductionBrowserGraphEntry, missingProductionBrowserGraphError, shouldRejectUnplannedProductionBrowserGraph, } from './page-browser-graph/missing-production-browser-graph.js';
40
41
  const syntheticExplicitViewKeys = new WeakMap();
41
42
  let nextSyntheticExplicitViewKey = 0;
42
43
  /**
@@ -980,8 +981,10 @@ export class IntegrationRenderer {
980
981
  }
981
982
  async buildPrebuiltPageClientBrowserAssets(plan, route) {
982
983
  const prebuiltInstance = this.resolvePrebuiltPageClientInstance(route);
983
- if (!prebuiltInstance)
984
+ if (!prebuiltInstance) {
985
+ await this.rejectUnplannedProductionPageClientGraph(plan, route);
984
986
  return undefined;
987
+ }
985
988
  const currentEntries = await this.collectAppBrowserClientBuildEntries(plan);
986
989
  const plannedEntries = prebuiltInstance.pageClientBuildEntries ?? [];
987
990
  const hasMatchingEntries = JSON.stringify(currentEntries
@@ -991,8 +994,12 @@ export class IntegrationRenderer {
991
994
  .map((entry) => createAppBrowserClientEntryKey(entry.integrationName, entry.dependency))
992
995
  .sort());
993
996
  const prebuilt = hasMatchingEntries ? prebuiltInstance.prebuiltPageClientBrowserAssets : undefined;
994
- if (!prebuilt)
997
+ if (!prebuilt) {
998
+ if (shouldRejectUnplannedProductionBrowserGraph(this.appConfig)) {
999
+ throw missingProductionBrowserGraphError(route.file, describeProductionBrowserGraphEntry(route.params));
1000
+ }
995
1001
  return undefined;
1002
+ }
996
1003
  const fallbackGroups = new Map();
997
1004
  for (const { dependency, integrationName } of prebuilt.fallbackDependencies) {
998
1005
  const dependencies = fallbackGroups.get(integrationName) ?? [];
@@ -1006,6 +1013,14 @@ export class IntegrationRenderer {
1006
1013
  lazyTriggers: this.dependencyResolverService.applyPendingLazyTriggers(processedAssets, plan.lazyConfigs),
1007
1014
  };
1008
1015
  }
1016
+ async rejectUnplannedProductionPageClientGraph(plan, route) {
1017
+ if (!shouldRejectUnplannedProductionBrowserGraph(this.appConfig))
1018
+ return;
1019
+ const currentEntries = await this.collectAppBrowserClientBuildEntries(plan);
1020
+ if (currentEntries.length > 0 || this.integrationHooks.buildIslandClientAssets) {
1021
+ throw missingProductionBrowserGraphError(route.file, describeProductionBrowserGraphEntry(route.params));
1022
+ }
1023
+ }
1009
1024
  resolvePrebuiltPageClientInstance(route) {
1010
1025
  const routeKey = createPrebuiltRoutePreparationKey(route);
1011
1026
  const exact = this.prebuiltPageClientBrowserAssets.get(routeKey);
@@ -0,0 +1,21 @@
1
+ import type { EcoPagesAppConfig } from '../../../config/internal-types.js';
2
+ import type { PageParams } from '../../../types/contracts.js';
3
+ /**
4
+ * Formats the `entry …` label for {@link missingProductionBrowserGraphError}.
5
+ *
6
+ * @remarks
7
+ * Prefers Params when present. Otherwise formats the instance key next to its serializer.
8
+ */
9
+ export declare function describeProductionBrowserGraphEntry(params?: PageParams, dependencyInstanceKey?: string): string;
10
+ /**
11
+ * Returns whether production serving must reject a Page Browser Graph that was not built.
12
+ *
13
+ * @remarks
14
+ * True only after `ecopages start` restores the browser client manifest. Static export still
15
+ * builds a graph while writing HTML, including Lit workers that never load that manifest.
16
+ */
17
+ export declare function shouldRejectUnplannedProductionBrowserGraph(appConfig: EcoPagesAppConfig): boolean;
18
+ /**
19
+ * Error for a production request whose Page Browser Graph was not built by `ecopages build`.
20
+ */
21
+ export declare function missingProductionBrowserGraphError(routeFile: string, entry: string): Error;
@@ -0,0 +1,31 @@
1
+ import { isProductionRuntime } from '../../../utils/runtime.js';
2
+ import { requireAppRuntime } from '../../../utils/app-runtime.js';
3
+ import { describePageDependencyInstance, describePageDependencyInstanceKey } from './route-instance-key.js';
4
+ /**
5
+ * Formats the `entry …` label for {@link missingProductionBrowserGraphError}.
6
+ *
7
+ * @remarks
8
+ * Prefers Params when present. Otherwise formats the instance key next to its serializer.
9
+ */
10
+ export function describeProductionBrowserGraphEntry(params, dependencyInstanceKey) {
11
+ if (params && Object.keys(params).length > 0) {
12
+ return describePageDependencyInstance({ params });
13
+ }
14
+ return describePageDependencyInstanceKey(dependencyInstanceKey ?? '');
15
+ }
16
+ /**
17
+ * Returns whether production serving must reject a Page Browser Graph that was not built.
18
+ *
19
+ * @remarks
20
+ * True only after `ecopages start` restores the browser client manifest. Static export still
21
+ * builds a graph while writing HTML, including Lit workers that never load that manifest.
22
+ */
23
+ export function shouldRejectUnplannedProductionBrowserGraph(appConfig) {
24
+ return isProductionRuntime() && requireAppRuntime(appConfig).productionBrowserGraphsSealed;
25
+ }
26
+ /**
27
+ * Error for a production request whose Page Browser Graph was not built by `ecopages build`.
28
+ */
29
+ export function missingProductionBrowserGraphError(routeFile, entry) {
30
+ return new Error(`The production Page Browser Graph for ${routeFile} is missing from the manifest (entry ${entry}). Run \`ecopages build\` again.`);
31
+ }
@@ -6,7 +6,8 @@ import { requireAppRuntime } from '../../../utils/app-runtime.js';
6
6
  import { startupTrace } from '../../../diagnostics/startup-trace.js';
7
7
  import { createAppBrowserClientEntryKey } from '../../../assets/app-browser-client-build.js';
8
8
  import { collectPageBrowserGraphDependencyPaths, createPageBrowserGraphEntryFingerprint, } from './page-browser-graph-session.js';
9
- import { createRouteGraphLookupKey } from './route-instance-key.js';
9
+ import { createRouteGraphLookupKey, pageDependencyInstanceParams } from './route-instance-key.js';
10
+ import { describeProductionBrowserGraphEntry, missingProductionBrowserGraphError, shouldRejectUnplannedProductionBrowserGraph, } from './missing-production-browser-graph.js';
10
11
  function isGroupedContentScriptAsset(asset) {
11
12
  return asset.kind === 'script' && asset.source === 'content' && Boolean(asset.groupedBundle?.id);
12
13
  }
@@ -30,6 +31,50 @@ function applyPrebuiltGroupedDependencyMetadata(currentContribution, plannedCont
30
31
  }),
31
32
  };
32
33
  }
34
+ function groupedKeysMatch(integrationName, left, right) {
35
+ return (JSON.stringify(groupedDependencyKeys(integrationName, left)) ===
36
+ JSON.stringify(groupedDependencyKeys(integrationName, right)));
37
+ }
38
+ function findPlannedGroupedInstance(input, contribution, dependencyInstanceKey) {
39
+ const instances = input.groupedBuildPlan?.instances;
40
+ if (!instances)
41
+ return undefined;
42
+ const routeLookupKey = createRouteGraphLookupKey(input.routeFile, dependencyInstanceKey);
43
+ const exact = instances.find((instance) => !instance.isRouteTemplate &&
44
+ createRouteGraphLookupKey(instance.routeFile, instance.dependencyInstanceKey) === routeLookupKey);
45
+ if (exact)
46
+ return exact;
47
+ const requestParams = pageDependencyInstanceParams(dependencyInstanceKey);
48
+ const paramsMatch = instances.find((instance) => {
49
+ if (instance.isRouteTemplate || instance.routeFile !== input.routeFile)
50
+ return false;
51
+ if (!groupedKeysMatch(input.integrationName, instance.contribution, contribution))
52
+ return false;
53
+ return (JSON.stringify(pageDependencyInstanceParams(instance.dependencyInstanceKey)) ===
54
+ JSON.stringify(requestParams));
55
+ });
56
+ if (paramsMatch)
57
+ return paramsMatch;
58
+ return instances.find((instance) => instance.routeFile === input.routeFile &&
59
+ instance.isRouteTemplate === true &&
60
+ instance.prebuiltGroupedAssets !== undefined &&
61
+ groupedKeysMatch(input.integrationName, instance.contribution, contribution));
62
+ }
63
+ function remapPlannedInstanceKey(plan, plannedInstance, dependencyInstanceKey) {
64
+ if (plannedInstance.dependencyInstanceKey === dependencyInstanceKey)
65
+ return plan;
66
+ return {
67
+ ...plan,
68
+ instances: plan.instances.map((instance) => instance === plannedInstance
69
+ ? {
70
+ ...instance,
71
+ dependencyInstanceKey,
72
+ skipStaticProps: false,
73
+ isRouteTemplate: false,
74
+ }
75
+ : instance),
76
+ };
77
+ }
33
78
  function resolveGroupedBuildPlan(input, contribution, dependencyInstanceKey) {
34
79
  if (input.cacheable === false) {
35
80
  return {
@@ -38,30 +83,13 @@ function resolveGroupedBuildPlan(input, contribution, dependencyInstanceKey) {
38
83
  usesPrebuiltGroupedAssets: false,
39
84
  };
40
85
  }
41
- const routeLookupKey = createRouteGraphLookupKey(input.routeFile, dependencyInstanceKey);
42
- const exactPlanInstance = input.groupedBuildPlan?.instances.find((instance) => !instance.isRouteTemplate &&
43
- createRouteGraphLookupKey(instance.routeFile, instance.dependencyInstanceKey) === routeLookupKey);
44
- const templatePlanInstance = exactPlanInstance
45
- ? undefined
46
- : input.groupedBuildPlan?.instances.find((instance) => instance.routeFile === input.routeFile &&
47
- instance.isRouteTemplate === true &&
48
- instance.prebuiltGroupedAssets !== undefined &&
49
- JSON.stringify(groupedDependencyKeys(input.integrationName, instance.contribution)) ===
50
- JSON.stringify(groupedDependencyKeys(input.integrationName, contribution)));
51
- const plannedInstance = exactPlanInstance ?? templatePlanInstance;
52
- const groupedBuildPlan = templatePlanInstance
53
- ? input.groupedBuildPlan && {
54
- ...input.groupedBuildPlan,
55
- instances: input.groupedBuildPlan.instances.map((instance) => instance === templatePlanInstance
56
- ? { ...instance, dependencyInstanceKey, skipStaticProps: false, isRouteTemplate: false }
57
- : instance),
58
- }
59
- : exactPlanInstance
60
- ? input.groupedBuildPlan
61
- : undefined;
86
+ const plannedInstance = findPlannedGroupedInstance(input, contribution, dependencyInstanceKey);
87
+ const groupedBuildPlan = plannedInstance && input.groupedBuildPlan
88
+ ? remapPlannedInstanceKey(input.groupedBuildPlan, plannedInstance, dependencyInstanceKey)
89
+ : undefined;
62
90
  const usesPrebuiltGroupedAssets = plannedInstance?.prebuiltGroupedAssets !== undefined;
63
- const graphContribution = templatePlanInstance
64
- ? applyPrebuiltGroupedDependencyMetadata(contribution, templatePlanInstance.contribution, input.integrationName)
91
+ const graphContribution = plannedInstance?.isRouteTemplate
92
+ ? applyPrebuiltGroupedDependencyMetadata(contribution, plannedInstance.contribution, input.integrationName)
65
93
  : usesPrebuiltGroupedAssets
66
94
  ? (plannedInstance.contribution ?? contribution)
67
95
  : contribution;
@@ -185,6 +213,12 @@ export class PageBrowserGraphService {
185
213
  cacheable: true,
186
214
  };
187
215
  }
216
+ const ungroupedDependencies = (contribution.dependencies ?? []).filter((dep) => !isGroupedContentScriptAsset(dep));
217
+ if (!hasGroupedDependencies && ungroupedDependencies.length === 0)
218
+ return undefined;
219
+ if (shouldRejectUnplannedProductionBrowserGraph(this.appConfig)) {
220
+ throw missingProductionBrowserGraphError(input.routeFile, describeProductionBrowserGraphEntry(undefined, input.dependencyInstanceKey));
221
+ }
188
222
  if (!hasGroupedDependencies)
189
223
  return undefined;
190
224
  return this.resolveGroupedPageBrowserAssets(input, contribution);
@@ -15,6 +15,18 @@ export type GroupedGraphScope = {
15
15
  * encodings would make otherwise distinct route inputs collide.
16
16
  */
17
17
  export declare function createPageDependencyInstanceKey(input: PageDependencyInstance): string;
18
+ /**
19
+ * Formats Params for a missing production Page Browser Graph error.
20
+ */
21
+ export declare function describePageDependencyInstance(input: PageDependencyInstance): string;
22
+ /**
23
+ * Params encoded in a {@link createPageDependencyInstanceKey} value, ignoring query.
24
+ */
25
+ export declare function pageDependencyInstanceParams(dependencyInstanceKey: string): Array<[string, string | string[]]> | undefined;
26
+ /**
27
+ * Formats a {@link createPageDependencyInstanceKey} value for a missing-manifest error.
28
+ */
29
+ export declare function describePageDependencyInstanceKey(dependencyInstanceKey: string): string;
18
30
  /**
19
31
  * Combines a route file with an optional dependency-instance key for grouped graph maps.
20
32
  */
@@ -1,3 +1,6 @@
1
+ function formatParamEntries(entries) {
2
+ return [...entries].map(([key, value]) => `${key}=${Array.isArray(value) ? value.join('/') : value}`).join(',');
3
+ }
1
4
  /**
2
5
  * Builds a stable cache key for one concrete dependency resolver input.
3
6
  *
@@ -13,6 +16,58 @@ export function createPageDependencyInstanceKey(input) {
13
16
  }
14
17
  return JSON.stringify({ params, query });
15
18
  }
19
+ /**
20
+ * Formats Params for a missing production Page Browser Graph error.
21
+ */
22
+ export function describePageDependencyInstance(input) {
23
+ const params = canonicalizeInput(input.params);
24
+ if (params.length === 0)
25
+ return 'default';
26
+ return formatParamEntries(params);
27
+ }
28
+ /**
29
+ * Params encoded in a {@link createPageDependencyInstanceKey} value, ignoring query.
30
+ */
31
+ export function pageDependencyInstanceParams(dependencyInstanceKey) {
32
+ if (dependencyInstanceKey.length === 0)
33
+ return [];
34
+ try {
35
+ const parsed = JSON.parse(dependencyInstanceKey);
36
+ if (typeof parsed !== 'object' || parsed === null || !('params' in parsed)) {
37
+ return undefined;
38
+ }
39
+ const params = parsed.params;
40
+ if (!Array.isArray(params))
41
+ return undefined;
42
+ const entries = [];
43
+ for (const item of params) {
44
+ if (!Array.isArray(item) || item.length !== 2 || typeof item[0] !== 'string') {
45
+ return undefined;
46
+ }
47
+ const value = item[1];
48
+ if (typeof value !== 'string' &&
49
+ !(Array.isArray(value) && value.every((part) => typeof part === 'string'))) {
50
+ return undefined;
51
+ }
52
+ entries.push([item[0], value]);
53
+ }
54
+ return entries;
55
+ }
56
+ catch {
57
+ return undefined;
58
+ }
59
+ }
60
+ /**
61
+ * Formats a {@link createPageDependencyInstanceKey} value for a missing-manifest error.
62
+ */
63
+ export function describePageDependencyInstanceKey(dependencyInstanceKey) {
64
+ const params = pageDependencyInstanceParams(dependencyInstanceKey);
65
+ if (params === undefined)
66
+ return dependencyInstanceKey;
67
+ if (params.length === 0)
68
+ return 'default';
69
+ return formatParamEntries(params);
70
+ }
16
71
  /**
17
72
  * Combines a route file with an optional dependency-instance key for grouped graph maps.
18
73
  */
@@ -22,11 +22,12 @@ export type RouteMatch = {
22
22
  readonly params: RouteParams;
23
23
  readonly query: RouteQuery;
24
24
  };
25
- export type StaticPathExpansion = {
25
+ export type PathExpansion = {
26
26
  readonly pathname: string;
27
27
  readonly templateRoute: TemplateRoute;
28
28
  readonly params: RouteParams;
29
29
  };
30
+ export type StaticPathExpansion = PathExpansion;
30
31
  export type StaticGenerationRoute = {
31
32
  readonly requestUrl: string;
32
33
  readonly pathname: string;
@@ -44,7 +45,13 @@ export type RouteRegistryPageModule = {
44
45
  }>;
45
46
  }>;
46
47
  readonly staticProps?: unknown;
47
- /** The Page's Cache Strategy; `'dynamic'` Pages render per request and are never expanded. */
48
+ /**
49
+ * The Page's Cache Strategy.
50
+ *
51
+ * @remarks
52
+ * `'dynamic'` Pages are omitted from Static Path Expansions (no HTML at Build-Time Rendering).
53
+ * When they declare `staticPaths`, those Params are still listed for Page Browser Graph planning.
54
+ */
48
55
  readonly cache?: unknown;
49
56
  };
50
57
  export interface RouteRegistryPageModuleAdapter {
@@ -88,9 +95,22 @@ export declare class RouteRegistry {
88
95
  private compareSpecificity;
89
96
  private getSpecificitySegments;
90
97
  private isDynamicRouteSegment;
98
+ private expandStaticPaths;
99
+ private listPathExpansions;
91
100
  listStaticPathExpansions(input: {
92
101
  runtimeOrigin: string;
93
102
  }): Promise<readonly StaticPathExpansion[]>;
103
+ /**
104
+ * Params of Dynamic Pages that declare `staticPaths`, for Page Browser Graph planning.
105
+ *
106
+ * @remarks
107
+ * The return shape is {@link PathExpansion}, the same records `staticPaths` produces. They are
108
+ * not Static Path Expansions: HTML still uses Request-Time Rendering. The build uses them so
109
+ * each Params list's graph is in the browser client manifest.
110
+ */
111
+ listDynamicPagePathExpansions(input: {
112
+ runtimeOrigin: string;
113
+ }): Promise<readonly PathExpansion[]>;
94
114
  listStaticGenerationRoutes(input: {
95
115
  runtimeOrigin: string;
96
116
  }): Promise<readonly StaticGenerationRoute[]>;
@@ -1,7 +1,9 @@
1
1
  import path from 'node:path';
2
2
  import { fileSystem } from '@ecopages/file-system';
3
3
  import { appLogger } from '../../global/app-logger.js';
4
+ import { loadProductionTemplateRoutes } from '../../build/production-route-list.js';
4
5
  import { invariant } from '../../utils/invariant.js';
6
+ import { isProductionRuntime } from '../../env.js';
5
7
  import { hasKnownStaticExtension } from '../../utils/static-file-extensions.js';
6
8
  import { ENDPOINT_FILE_EXTENSIONS, findEndpointFileExtension } from '../../utils/endpoint-file-extensions.js';
7
9
  import { normalizePathname } from '../../utils/path-pattern.js';
@@ -40,7 +42,8 @@ export class RouteRegistry {
40
42
  return this.templateRouteList.filter((route) => route.role === 'page');
41
43
  }
42
44
  async init() {
43
- this.templateRouteList = await this.scanTemplateRoutes();
45
+ const productionRoutes = isProductionRuntime() ? loadProductionTemplateRoutes(this.appConfig) : undefined;
46
+ this.templateRouteList = productionRoutes ?? (await this.scanTemplateRoutes());
44
47
  appLogger.debug('RouteRegistry initialized', this.templateRouteList);
45
48
  }
46
49
  async reload() {
@@ -105,38 +108,59 @@ export class RouteRegistry {
105
108
  isDynamicRouteSegment(segment) {
106
109
  return segment.startsWith('[') && segment.endsWith(']');
107
110
  }
108
- async listStaticPathExpansions(input) {
111
+ async expandStaticPaths(route, staticPaths, runtimeOrigin) {
112
+ const result = await staticPaths({
113
+ appConfig: this.appConfig,
114
+ runtimeOrigin,
115
+ });
116
+ return result.paths.map(({ params }) => ({
117
+ pathname: buildSegmentPath(route.pathname, params, 'filesystem'),
118
+ templateRoute: route,
119
+ params,
120
+ }));
121
+ }
122
+ async listPathExpansions(input, options) {
109
123
  const expansions = [];
110
124
  for (const route of this.pageRoutes) {
111
125
  if (route.kind === 'exact') {
112
126
  continue;
113
127
  }
114
128
  const pageModule = await this.pageModuleAdapter.loadPageModule(route.filePath);
115
- if (pageModule.cache === 'dynamic') {
129
+ if (!options.include(pageModule)) {
116
130
  continue;
117
131
  }
118
132
  const staticPaths = pageModule.staticPaths;
119
- if (this.buildMode) {
133
+ if (options.requireStaticHooks && this.buildMode) {
120
134
  invariant(staticPaths !== undefined, `[ecopages] Missing getStaticPaths in ${route.filePath}`);
121
135
  invariant(pageModule.staticProps !== undefined, `[ecopages] Missing getStaticProps in ${route.filePath}`);
122
136
  }
123
137
  if (!staticPaths) {
124
138
  continue;
125
139
  }
126
- const result = await staticPaths({
127
- appConfig: this.appConfig,
128
- runtimeOrigin: input.runtimeOrigin,
129
- });
130
- for (const { params } of result.paths) {
131
- expansions.push({
132
- pathname: buildSegmentPath(route.pathname, params, 'filesystem'),
133
- templateRoute: route,
134
- params,
135
- });
136
- }
140
+ expansions.push(...(await this.expandStaticPaths(route, staticPaths, input.runtimeOrigin)));
137
141
  }
138
142
  return expansions;
139
143
  }
144
+ async listStaticPathExpansions(input) {
145
+ return this.listPathExpansions(input, {
146
+ include: (pageModule) => pageModule.cache !== 'dynamic',
147
+ requireStaticHooks: true,
148
+ });
149
+ }
150
+ /**
151
+ * Params of Dynamic Pages that declare `staticPaths`, for Page Browser Graph planning.
152
+ *
153
+ * @remarks
154
+ * The return shape is {@link PathExpansion}, the same records `staticPaths` produces. They are
155
+ * not Static Path Expansions: HTML still uses Request-Time Rendering. The build uses them so
156
+ * each Params list's graph is in the browser client manifest.
157
+ */
158
+ async listDynamicPagePathExpansions(input) {
159
+ return this.listPathExpansions(input, {
160
+ include: (pageModule) => pageModule.cache === 'dynamic' && pageModule.staticPaths !== undefined,
161
+ requireStaticHooks: false,
162
+ });
163
+ }
140
164
  async listStaticGenerationRoutes(input) {
141
165
  const staticPathExpansions = await this.listStaticPathExpansions(input);
142
166
  return [
@@ -20,7 +20,8 @@ export declare function shouldPrebuildProductionPageBrowserGraphs(): boolean;
20
20
  *
21
21
  * @remarks
22
22
  * Clears only the `'production'` policy so a failed or force export cannot
23
- * reuse staged graph output. Development session records are left intact.
23
+ * reuse staged graph output. Also sets `productionBrowserGraphsSealed` to false so a
24
+ * retry of `ecopages build` can still emit graphs. Development session records are left intact.
24
25
  */
25
26
  export declare function clearProductionPageBrowserGraphSession(appConfig: EcoPagesAppConfig): void;
26
27
  /**
@@ -32,5 +33,10 @@ export declare function clearProductionPageBrowserGraphSession(appConfig: EcoPag
32
33
  * then resolves into `page-browser-graph-session`). Does not persist a disk manifest.
33
34
  */
34
35
  export declare function prebuildProductionPageBrowserGraphs(appConfig: EcoPagesAppConfig, routeInstances: readonly ProductionPageBrowserGraphRouteInstance[], routeRendererFactory: PageRendererResolver): Promise<void>;
35
- /** Reuses the browser outputs written by `ecopages build` while `ecopages start` prepares SSR routes. */
36
+ /**
37
+ * Reuses the browser outputs written by `ecopages build` while `ecopages start` prepares SSR routes.
38
+ *
39
+ * @remarks
40
+ * A successful restore sets `productionBrowserGraphsSealed` so a missing graph is an error.
41
+ */
36
42
  export declare function prebuildProductionPageBrowserGraphsFromManifest(appConfig: EcoPagesAppConfig, routeRendererFactory: PageRendererResolver): Promise<boolean>;