@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.
Files changed (172) hide show
  1. package/README.md +2 -2
  2. package/package.json +14 -4
  3. package/src/adapters/node/create-app.d.ts +5 -5
  4. package/src/adapters/node/create-app.js +1 -1
  5. package/src/adapters/node/server-adapter.d.ts +1 -0
  6. package/src/adapters/node/server-adapter.js +4 -1
  7. package/src/adapters/shared/hmr/hmr-manager.d.ts +2 -0
  8. package/src/adapters/shared/hmr/hmr-manager.js +8 -4
  9. package/src/adapters/shared/http/api-request-pipeline.d.ts +16 -3
  10. package/src/adapters/shared/http/api-request-pipeline.js +23 -16
  11. package/src/adapters/shared/http/define-api-handler.d.ts +8 -8
  12. package/src/adapters/shared/http/explicit-static-route-matcher.js +8 -4
  13. package/src/adapters/shared/http/file-route-middleware-pipeline.d.ts +10 -11
  14. package/src/adapters/shared/http/file-route-middleware-pipeline.js +5 -6
  15. package/src/adapters/shared/http/fs-server-response-matcher.js +12 -4
  16. package/src/adapters/shared/http/run-middleware-chain.d.ts +29 -2
  17. package/src/adapters/shared/http/run-middleware-chain.js +108 -10
  18. package/src/adapters/shared/runtime/render-context.d.ts +2 -0
  19. package/src/adapters/shared/runtime/render-context.js +6 -21
  20. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +2 -2
  21. package/src/adapters/shared/runtime/server-request-pipeline.js +4 -3
  22. package/src/adapters/shared/runtime/server-static-builder.js +4 -1
  23. package/src/adapters/shared/runtime/unattached-scripts.d.ts +17 -0
  24. package/src/adapters/shared/runtime/unattached-scripts.js +57 -0
  25. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +3 -2
  26. package/src/adapters/shared/ws/ws-pattern-matcher.d.ts +14 -1
  27. package/src/adapters/shared/ws/ws-pattern-matcher.js +14 -13
  28. package/src/assets/app-browser-client-build.js +3 -0
  29. package/src/assets/asset-processing-service/asset-processing.service.d.ts +9 -0
  30. package/src/assets/asset-processing-service/asset-processing.service.js +19 -0
  31. package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +16 -2
  32. package/src/assets/asset-processing-service/processed-asset-ledger.js +31 -3
  33. package/src/build/build-graph.d.ts +19 -2
  34. package/src/build/build-graph.js +19 -18
  35. package/src/build/cache/pages-unified-graph-build.d.ts +4 -6
  36. package/src/build/cache/pages-unified-graph-build.js +14 -51
  37. package/src/build/cache/server-module-entries.d.ts +5 -9
  38. package/src/build/cache/server-module-entries.js +5 -58
  39. package/src/build/contracts/build-contracts.d.ts +15 -0
  40. package/src/build/contracts.d.ts +1 -1
  41. package/src/build/contracts.js +1 -1
  42. package/src/build/production-asset-ledger.d.ts +1 -1
  43. package/src/build/production-asset-ledger.js +4 -2
  44. package/src/build/rolldown/file-role-grammar-plugin.d.ts +11 -0
  45. package/src/build/rolldown/file-role-grammar-plugin.js +32 -0
  46. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +11 -0
  47. package/src/build/rolldown/rolldown-adapter-helpers.js +79 -10
  48. package/src/build/rolldown/ssr-script-entries-plugin.d.ts +31 -0
  49. package/src/build/rolldown/ssr-script-entries-plugin.js +104 -0
  50. package/src/build/runtime/build-request-policy.js +4 -1
  51. package/src/build/server/server-modules-manifest.d.ts +6 -1
  52. package/src/build/server/server-modules-manifest.js +10 -1
  53. package/src/build/server/view-reference.d.ts +9 -0
  54. package/src/build/server/view-reference.js +11 -0
  55. package/src/build.d.ts +3 -1
  56. package/src/build.js +3 -1
  57. package/src/cli.d.ts +14 -0
  58. package/src/cli.js +14 -0
  59. package/src/config/assembly/app-runtime.d.ts +13 -0
  60. package/src/config/assembly/app-runtime.js +2 -0
  61. package/src/config/assembly/finalize-config.js +13 -8
  62. package/src/config/internal-types.d.ts +0 -12
  63. package/src/config/resolve-eco-config-path.d.ts +2 -0
  64. package/src/config/resolve-eco-config-path.js +2 -1
  65. package/src/config/server-config-bundle.d.ts +0 -1
  66. package/src/config/server-config-bundle.js +1 -1
  67. package/src/config/user-config-types.d.ts +0 -12
  68. package/src/declarations.d.ts +2 -0
  69. package/src/dev/invalidation/development-invalidation.service.d.ts +0 -2
  70. package/src/dev/invalidation/development-invalidation.service.js +1 -11
  71. package/src/dev/transform-server/dev-transform-vendor-registry.js +33 -19
  72. package/src/eco/discovered-dependencies.d.ts +5 -0
  73. package/src/eco/discovered-dependencies.js +9 -0
  74. package/src/eco/eco.browser.js +6 -26
  75. package/src/eco/eco.js +24 -16
  76. package/src/eco/migration-docs.d.ts +7 -0
  77. package/src/eco/migration-docs.js +7 -0
  78. package/src/eco/page-data-hooks.d.ts +27 -0
  79. package/src/eco/page-data-hooks.js +64 -0
  80. package/src/eco/page-layout-normalization.d.ts +2 -2
  81. package/src/hmr/client/hmr-runtime.js +1 -1
  82. package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -2
  83. package/src/hmr/strategies/server-rendered-template-hmr-strategy.d.ts +2 -1
  84. package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +4 -3
  85. package/src/html/html-rewriter.d.ts +9 -7
  86. package/src/html/html-rewriter.js +26 -41
  87. package/src/html/html-transformer.service.d.ts +2 -2
  88. package/src/html/html-transformer.service.js +21 -15
  89. package/src/html-pages/html-page-module-scripts.js +2 -1
  90. package/src/html-pages/html-pages.plugin.d.ts +1 -1
  91. package/src/html-pages/html-pages.plugin.js +1 -1
  92. package/src/index.d.ts +1 -0
  93. package/src/index.js +1 -0
  94. package/src/integration.d.ts +2 -2
  95. package/src/integration.js +2 -2
  96. package/src/islands/island-host.d.ts +16 -5
  97. package/src/islands/island-host.js +8 -1
  98. package/src/middleware/create-middleware.d.ts +41 -0
  99. package/src/middleware/create-middleware.js +72 -0
  100. package/src/plugins/component-import-discovery.d.ts +14 -1
  101. package/src/plugins/component-import-discovery.js +36 -16
  102. package/src/plugins/eco-component-meta-plugin.d.ts +38 -0
  103. package/src/plugins/eco-component-meta-plugin.js +208 -44
  104. package/src/plugins/ecopages-virtual-imports.d.ts +15 -0
  105. package/src/plugins/ecopages-virtual-imports.js +25 -0
  106. package/src/plugins/integration-plugin.d.ts +1 -1
  107. package/src/plugins/integration-plugin.js +1 -1
  108. package/src/plugins/tsconfig-import-resolver.d.ts +2 -0
  109. package/src/plugins/tsconfig-import-resolver.js +7 -5
  110. package/src/route-renderer/error-pages/error-page-renderer.js +32 -3
  111. package/src/route-renderer/explicit-view-render-preparation.d.ts +28 -3
  112. package/src/route-renderer/explicit-view-render-preparation.js +63 -11
  113. package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +15 -5
  114. package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +27 -15
  115. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +24 -9
  116. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +73 -50
  117. package/src/route-renderer/orchestration/integration-renderer.d.ts +42 -11
  118. package/src/route-renderer/orchestration/integration-renderer.js +83 -43
  119. package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.builder.js +0 -3
  120. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +36 -11
  121. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +74 -62
  122. package/src/route-renderer/page-declaration.d.ts +25 -0
  123. package/src/route-renderer/page-declaration.js +39 -0
  124. package/src/route-renderer/page-loading/component-declarations.d.ts +65 -0
  125. package/src/route-renderer/page-loading/component-declarations.js +77 -0
  126. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -16
  127. package/src/route-renderer/page-loading/component-dependency-collection.js +36 -105
  128. package/src/route-renderer/page-loading/declared-asset-collection.d.ts +19 -14
  129. package/src/route-renderer/page-loading/declared-asset-collection.js +66 -67
  130. package/src/route-renderer/page-loading/dependency-resolver.d.ts +18 -10
  131. package/src/route-renderer/page-loading/dependency-resolver.js +58 -99
  132. package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +19 -26
  133. package/src/route-renderer/page-loading/lazy-entry-collection.js +53 -64
  134. package/src/route-renderer/page-loading/module-declaration-aggregation.d.ts +17 -3
  135. package/src/route-renderer/page-loading/module-declaration-aggregation.js +14 -13
  136. package/src/route-renderer/page-loading/page-module-loader.d.ts +31 -12
  137. package/src/route-renderer/page-loading/page-module-loader.js +66 -35
  138. package/src/route-renderer/page-loading/resolved-page-dependencies.js +14 -9
  139. package/src/router/server/pages-dir.d.ts +7 -0
  140. package/src/router/server/pages-dir.js +7 -0
  141. package/src/router/server/route-registry.d.ts +22 -10
  142. package/src/router/server/route-registry.js +54 -23
  143. package/src/router/server/segment-path-matcher.d.ts +29 -5
  144. package/src/router/server/segment-path-matcher.js +22 -19
  145. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +2 -2
  146. package/src/static-site-generator/production-page-browser-graph-prebuild.js +5 -5
  147. package/src/static-site-generator/static-site-generator.d.ts +17 -2
  148. package/src/static-site-generator/static-site-generator.js +52 -18
  149. package/src/types/contracts.d.ts +216 -160
  150. package/src/types/eco-api-types.d.ts +86 -51
  151. package/src/types/locals-brand.d.ts +9 -0
  152. package/src/types/locals-brand.js +9 -0
  153. package/src/types/middleware-types.d.ts +143 -0
  154. package/src/types/middleware-types.js +1 -0
  155. package/src/types/public-types.d.ts +3 -2
  156. package/src/utils/file-roles.d.ts +48 -0
  157. package/src/utils/file-roles.js +85 -0
  158. package/src/utils/node-builtin.d.ts +10 -0
  159. package/src/utils/node-builtin.js +13 -0
  160. package/src/watchers/project-watcher.js +2 -2
  161. package/src/build/contracts/server-only-specifier.d.ts +0 -8
  162. package/src/build/contracts/server-only-specifier.js +0 -11
  163. package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.d.ts +0 -5
  164. package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.js +0 -11
  165. package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.d.ts +0 -4
  166. package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.js +0 -30
  167. package/src/route-renderer/page-loading/ecopages-virtual-imports.d.ts +0 -12
  168. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +0 -100
  169. package/src/utils/endpoint-file-extensions.d.ts +0 -11
  170. package/src/utils/endpoint-file-extensions.js +0 -13
  171. package/src/utils/locals-utils.d.ts +0 -15
  172. package/src/utils/locals-utils.js +0 -34
@@ -82,6 +82,24 @@ function parsePattern(pattern, syntax) {
82
82
  .filter(Boolean)
83
83
  .map((segment) => parsePatternSegment(segment, options));
84
84
  }
85
+ function scorePatternSegments(segments, syntax) {
86
+ if (syntax === 'websocket') {
87
+ const literals = segments.filter((segment) => segment.kind === 'literal').length;
88
+ const params = segments.length - literals;
89
+ return literals * 100 - params * 10 + segments.length;
90
+ }
91
+ return segments.reduce((score, segment) => {
92
+ if (segment.kind === 'literal')
93
+ return score + 100;
94
+ if (segment.kind === 'parameter')
95
+ return score + 50;
96
+ return score + 10;
97
+ }, 0);
98
+ }
99
+ export function compileSegmentPattern(pattern, syntax) {
100
+ const segments = parsePattern(pattern, syntax);
101
+ return { syntax, segments, score: scorePatternSegments(segments, syntax) };
102
+ }
85
103
  /**
86
104
  * Normalizes and decodes a request pathname once for matching multiple routes.
87
105
  *
@@ -102,10 +120,10 @@ export function parseSegmentPath(pathname) {
102
120
  }
103
121
  });
104
122
  }
105
- export function matchParsedSegmentPath(pattern, pathSegments, syntax) {
106
- const patternSegments = parsePattern(pattern, syntax);
123
+ export function matchParsedSegmentPath(pattern, pathSegments) {
124
+ const patternSegments = pattern.segments;
107
125
  const params = {};
108
- const { catchAllValue } = syntaxOptions[syntax];
126
+ const { catchAllValue } = syntaxOptions[pattern.syntax];
109
127
  for (const [index, patternSegment] of patternSegments.entries()) {
110
128
  if (patternSegment.kind === 'wildcard') {
111
129
  return params;
@@ -130,7 +148,7 @@ export function matchParsedSegmentPath(pattern, pathSegments, syntax) {
130
148
  return pathSegments.length === patternSegments.length ? params : null;
131
149
  }
132
150
  export function matchSegmentPath(pattern, pathname, syntax) {
133
- return matchParsedSegmentPath(pattern, parseSegmentPath(pathname), syntax);
151
+ return matchParsedSegmentPath(compileSegmentPattern(pattern, syntax), parseSegmentPath(pathname));
134
152
  }
135
153
  /**
136
154
  * Builds a concrete pathname from a route pattern and its params.
@@ -177,18 +195,3 @@ export function segmentPathPatternKey(pattern, syntax) {
177
195
  });
178
196
  return `/${segments.join('/')}`;
179
197
  }
180
- export function scoreSegmentPathPattern(pattern, syntax) {
181
- const segments = parsePattern(pattern, syntax);
182
- if (syntax === 'websocket') {
183
- const literals = segments.filter((segment) => segment.kind === 'literal').length;
184
- const params = segments.length - literals;
185
- return literals * 100 - params * 10 + segments.length;
186
- }
187
- return segments.reduce((score, segment) => {
188
- if (segment.kind === 'literal')
189
- return score + 100;
190
- if (segment.kind === 'parameter')
191
- return score + 50;
192
- return score + 10;
193
- }, 0);
194
- }
@@ -19,7 +19,7 @@ export declare function shouldPrebuildProductionPageBrowserGraphs(): boolean;
19
19
  * file a previous build wrote. Development session records are left intact.
20
20
  */
21
21
  export declare function clearProductionPageBrowserGraphSession(appConfig: EcoPagesAppConfig): void;
22
- /** Identifies one planned route instance: its file, Params and whether it is a template without static props. */
22
+ /** Identifies one planned route instance: its file, Params and whether it is a template without a `props` run. */
23
23
  export declare function getPlannedRouteKey(instance: PlannedRouteInstance): string;
24
24
  /**
25
25
  * Builds the production browser client for the supplied route instances and prepares each of them.
@@ -32,7 +32,7 @@ export declare function getPlannedRouteKey(instance: PlannedRouteInstance): stri
32
32
  * worker restores it during the export. A route that fails to plan is left out and reported to `onRouteFailure`.
33
33
  * Each Integration's global scripts are resolved once, after that build, or on their own when no route is planned.
34
34
  *
35
- * Returns the preparation of every planned instance that runs its static props, by {@link getPlannedRouteKey}, so
35
+ * Returns the preparation of every planned instance that runs its `props` hook, by {@link getPlannedRouteKey}, so
36
36
  * static export renders it without running its data hooks again. The caller owns the map for the build; no
37
37
  * renderer keeps it.
38
38
  */
@@ -29,17 +29,17 @@ export function shouldPrebuildProductionPageBrowserGraphs() {
29
29
  export function clearProductionPageBrowserGraphSession(appConfig) {
30
30
  const runtime = requireAppRuntime(appConfig);
31
31
  runtime.pageBrowserGraphSession.clearPolicyRecords('production');
32
- runtime.processedAssets.clearBrowserOutputs();
32
+ runtime.processedAssets.clearBuildOutputs();
33
33
  clearProductionAssetLedger(appConfig);
34
34
  }
35
- /** Identifies one planned route instance: its file, Params and whether it is a template without static props. */
35
+ /** Identifies one planned route instance: its file, Params and whether it is a template without a `props` run. */
36
36
  export function getPlannedRouteKey(instance) {
37
37
  const routeFile = path.resolve(instance.routeFile);
38
38
  const dependencyInstanceKey = createPageDependencyInstanceKey({ params: instance.params });
39
39
  return JSON.stringify([
40
40
  routeFile,
41
41
  dependencyInstanceKey,
42
- instance.skipStaticProps ?? false,
42
+ instance.skipPropsHook ?? false,
43
43
  instance.isRouteTemplate ?? false,
44
44
  ]);
45
45
  }
@@ -64,7 +64,7 @@ function groupRouteInstancesByRenderer(routeInstances, routeRendererFactory) {
64
64
  * worker restores it during the export. A route that fails to plan is left out and reported to `onRouteFailure`.
65
65
  * Each Integration's global scripts are resolved once, after that build, or on their own when no route is planned.
66
66
  *
67
- * Returns the preparation of every planned instance that runs its static props, by {@link getPlannedRouteKey}, so
67
+ * Returns the preparation of every planned instance that runs its `props` hook, by {@link getPlannedRouteKey}, so
68
68
  * static export renders it without running its data hooks again. The caller owns the map for the build; no
69
69
  * renderer keeps it.
70
70
  */
@@ -95,7 +95,7 @@ export async function prebuildProductionPageBrowserGraphs(appConfig, routeInstan
95
95
  }
96
96
  writeProductionAssetLedger(appConfig, await getPrebuiltHtmlPageModuleScriptUrls(appConfig));
97
97
  for (const { instance, preparation } of routePlans.flatMap((routePlan) => routePlan.preparations)) {
98
- if (!instance.skipStaticProps)
98
+ if (!instance.skipPropsHook)
99
99
  preparations.set(getPlannedRouteKey(instance), preparation);
100
100
  }
101
101
  return preparations;
@@ -31,7 +31,7 @@ export declare const STATIC_SITE_GENERATOR_ERRORS: {
31
31
  readonly unsupportedBodyType: (bodyType: string) => string;
32
32
  readonly missingIntegration: (routePath: string) => string;
33
33
  readonly noRendererForIntegration: (integrationName: string) => string;
34
- readonly dynamicRouteRequiresStaticPaths: (routePath: string) => string;
34
+ readonly dynamicRouteRequiresPaths: (routePath: string) => string;
35
35
  };
36
36
  /**
37
37
  * Generates static output files from the finalized app config and route graph.
@@ -52,7 +52,6 @@ export declare class StaticSiteGenerator {
52
52
  });
53
53
  private getExportDir;
54
54
  private shouldSkipStaticPageFile;
55
- private shouldSkipStaticView;
56
55
  /**
57
56
  * Writes the robots.txt file declared by the app config.
58
57
  */
@@ -91,6 +90,13 @@ export declare class StaticSiteGenerator {
91
90
  routePlans?: StaticExportRoutePlans;
92
91
  }): Promise<void>;
93
92
  private createStaticExportContext;
93
+ /**
94
+ * Starts every Integration's static export.
95
+ *
96
+ * @remarks
97
+ * The caller runs this concurrently with planning and the browser-graph prebuild and awaits it before the
98
+ * first page render, the earliest point an export's output (the Lit render worker) is consumed.
99
+ */
94
100
  private startStaticExports;
95
101
  private releaseStaticExports;
96
102
  private resetStaticGenerationState;
@@ -131,6 +137,15 @@ export declare class StaticSiteGenerator {
131
137
  force?: boolean;
132
138
  keepGoing?: boolean;
133
139
  }): Promise<void>;
140
+ /**
141
+ * Releases the static exports, tears down the Integrations, and throws whatever failed.
142
+ *
143
+ * @remarks
144
+ * Static exports start while the generation runs, so they are awaited here even when generation failed; their
145
+ * own failure is reported only when it is not the error generation already threw. Every cleanup step runs,
146
+ * and a generation error is thrown together with any cleanup errors.
147
+ */
148
+ private cleanUpStaticGeneration;
134
149
  /**
135
150
  * Loads each explicit static view, resolves its renderer and lists its pathnames.
136
151
  *
@@ -4,7 +4,7 @@ import { requireAppRuntime } from '../utils/app-runtime.js';
4
4
  import { resolveBuildParallelism } from '../build/build-parallelism.js';
5
5
  import { fileSystem } from '@ecopages/file-system';
6
6
  import { CLIENT_OUTPUT_DIR } from '../utils/resolve-entry-file.js';
7
- import { prepareExplicitStaticRender, resolveExplicitViewRenderer, } from '../route-renderer/explicit-view-render-preparation.js';
7
+ import { assertViewRendersWithoutRequest, prepareExplicitStaticRender, resolveExplicitViewRenderer, } from '../route-renderer/explicit-view-render-preparation.js';
8
8
  import { ensureIntegrationRuntimeReady, requireBrowserBuildGlobalScriptResolution, resolveIntegrationDependencies, setupAppRuntimeIntegrations, teardownAppRuntimeIntegrations, } from '../build/app-build-manifest-runtime.js';
9
9
  import { emitProductionServerModules, shouldBuildPagesUnifiedGraph } from '../build/cache/pages-unified-graph-build.js';
10
10
  import { getImportedViewPaths } from '../build/server/imported-view-plugin.js';
@@ -15,6 +15,7 @@ import { toEcopagesRouteInfo } from '../utils/ecopages-route-info.js';
15
15
  import { buildSegmentPath } from '../router/server/segment-path-matcher.js';
16
16
  import { normalizePathname } from '../utils/path-pattern.js';
17
17
  import { ErrorPageRenderer } from '../route-renderer/error-pages/error-page-renderer.js';
18
+ import { isDynamicPage } from '../eco/page-data-hooks.js';
18
19
  import { SemanticErrorPageExporter, SEMANTIC_ERROR_PAGE_PATHNAMES, } from '../route-renderer/error-pages/semantic-error-page-exporter.js';
19
20
  function createStaticGenerationPageError(route, error, label = 'static page') {
20
21
  const cause = error instanceof Error ? error : new Error(String(error));
@@ -42,7 +43,7 @@ export const STATIC_SITE_GENERATOR_ERRORS = {
42
43
  unsupportedBodyType: (bodyType) => `Unsupported body type for static generation: ${bodyType}`,
43
44
  missingIntegration: (routePath) => `View at ${routePath} is missing component identity integration. Ensure it's defined with eco.page().`,
44
45
  noRendererForIntegration: (integrationName) => `No renderer found for integration: ${integrationName}`,
45
- dynamicRouteRequiresStaticPaths: (routePath) => `Dynamic route ${routePath} requires staticPaths to be defined on the view.`,
46
+ dynamicRouteRequiresPaths: (routePath) => `Dynamic route ${routePath} requires paths to be defined on the view.`,
46
47
  };
47
48
  async function runWithConcurrency(items, concurrency, worker) {
48
49
  if (items.length === 0) {
@@ -81,10 +82,7 @@ export class StaticSiteGenerator {
81
82
  }
82
83
  async shouldSkipStaticPageFile(filePath, routeRendererFactory) {
83
84
  const pageModule = await routeRendererFactory.getPageRenderer(filePath).loadPageModule(filePath);
84
- return pageModule.default.cache === 'dynamic';
85
- }
86
- shouldSkipStaticView(_routePath, view) {
87
- return view.cache === 'dynamic';
85
+ return isDynamicPage(pageModule.default);
88
86
  }
89
87
  /**
90
88
  * Writes the robots.txt file declared by the app config.
@@ -236,6 +234,13 @@ export class StaticSiteGenerator {
236
234
  routes: input.routes,
237
235
  };
238
236
  }
237
+ /**
238
+ * Starts every Integration's static export.
239
+ *
240
+ * @remarks
241
+ * The caller runs this concurrently with planning and the browser-graph prebuild and awaits it before the
242
+ * first page render, the earliest point an export's output (the Lit render worker) is consumed.
243
+ */
239
244
  async startStaticExports(context) {
240
245
  const releases = [];
241
246
  try {
@@ -330,10 +335,10 @@ export class StaticSiteGenerator {
330
335
  ]);
331
336
  const dynamicRouteTemplates = (input.router.templateRoutes ?? [])
332
337
  .filter((route) => route.kind !== 'exact' && route.role === 'page' && !expandedRouteFiles.has(route.filePath))
333
- .map((route) => ({ routeFile: route.filePath, skipStaticProps: true, isRouteTemplate: true }));
338
+ .map((route) => ({ routeFile: route.filePath, skipPropsHook: true, isRouteTemplate: true }));
334
339
  const importedViews = getImportedViewPaths(this.appConfig).map((routeFile) => ({
335
340
  routeFile,
336
- skipStaticProps: true,
341
+ skipPropsHook: true,
337
342
  isRouteTemplate: true,
338
343
  }));
339
344
  const exportedRouteKeys = new Set(input.routes.map((route) => getPlannedRouteKey({ routeFile: route.templateRoute.filePath, params: route.params })));
@@ -345,6 +350,7 @@ export class StaticSiteGenerator {
345
350
  ...dynamicPageEntries.map((route) => ({
346
351
  routeFile: route.templateRoute.filePath,
347
352
  params: route.params,
353
+ skipPropsHook: true,
348
354
  })),
349
355
  ...dynamicRouteTemplates,
350
356
  ...importedViews,
@@ -360,6 +366,7 @@ export class StaticSiteGenerator {
360
366
  else {
361
367
  await resolveIntegrationDependencies({ appConfig: this.appConfig });
362
368
  }
369
+ await input.staticExportsReady;
363
370
  this.generateRobotsTxt();
364
371
  const semanticErrorPathnames = new Set(SEMANTIC_ERROR_PAGE_PATHNAMES);
365
372
  const pageRoutes = input.routes.filter((route) => !semanticErrorPathnames.has(route.pathname));
@@ -422,7 +429,7 @@ export class StaticSiteGenerator {
422
429
  requireBrowserBuildGlobalScriptResolution(this.appConfig);
423
430
  this.resetStaticGenerationState(force);
424
431
  requireAppRuntime(this.appConfig).staticGenerationActive = true;
425
- let releases = [];
432
+ let staticExportsStarted;
426
433
  let generationFailed = false;
427
434
  let generationError;
428
435
  try {
@@ -443,7 +450,8 @@ export class StaticSiteGenerator {
443
450
  force,
444
451
  routes: exportRoutes,
445
452
  });
446
- releases = await this.startStaticExports(staticExportContext);
453
+ staticExportsStarted = this.startStaticExports(staticExportContext);
454
+ staticExportsStarted.catch(() => undefined);
447
455
  try {
448
456
  await this.executeStaticGenerationBody({
449
457
  router,
@@ -456,6 +464,7 @@ export class StaticSiteGenerator {
456
464
  pageFailures,
457
465
  activeStaticPathnames,
458
466
  sitemapEligiblePathnames,
467
+ staticExportsReady: staticExportsStarted,
459
468
  });
460
469
  }
461
470
  catch (error) {
@@ -476,7 +485,28 @@ export class StaticSiteGenerator {
476
485
  }
477
486
  requireAppRuntime(this.appConfig).staticGenerationActive = false;
478
487
  clearProductionAssetLedgerOnFailure(this.appConfig, generationFailed);
488
+ await this.cleanUpStaticGeneration({ staticExportsStarted, generationFailed, generationError });
489
+ }
490
+ /**
491
+ * Releases the static exports, tears down the Integrations, and throws whatever failed.
492
+ *
493
+ * @remarks
494
+ * Static exports start while the generation runs, so they are awaited here even when generation failed; their
495
+ * own failure is reported only when it is not the error generation already threw. Every cleanup step runs,
496
+ * and a generation error is thrown together with any cleanup errors.
497
+ */
498
+ async cleanUpStaticGeneration(input) {
499
+ let releases = [];
479
500
  const cleanupErrors = [];
501
+ try {
502
+ if (input.staticExportsStarted) {
503
+ releases = await input.staticExportsStarted;
504
+ }
505
+ }
506
+ catch (error) {
507
+ if (!input.generationFailed || error !== input.generationError)
508
+ cleanupErrors.push(error);
509
+ }
480
510
  try {
481
511
  await this.releaseStaticExports(releases);
482
512
  }
@@ -489,13 +519,13 @@ export class StaticSiteGenerator {
489
519
  catch (error) {
490
520
  cleanupErrors.push(error);
491
521
  }
492
- if (generationFailed) {
522
+ if (input.generationFailed) {
493
523
  if (cleanupErrors.length > 0) {
494
- throw new AggregateError([generationError, ...cleanupErrors], 'Static generation and cleanup failed', {
495
- cause: generationError,
524
+ throw new AggregateError([input.generationError, ...cleanupErrors], 'Static generation and cleanup failed', {
525
+ cause: input.generationError,
496
526
  });
497
527
  }
498
- throw generationError;
528
+ throw input.generationError;
499
529
  }
500
530
  if (cleanupErrors.length === 1)
501
531
  throw cleanupErrors[0];
@@ -515,13 +545,17 @@ export class StaticSiteGenerator {
515
545
  for (const route of input.staticRoutes) {
516
546
  try {
517
547
  const view = (await route.loader()).default;
518
- if (this.shouldSkipStaticView(route.path, view)) {
548
+ assertViewRendersWithoutRequest(route.path, view);
549
+ if (isDynamicPage(view)) {
519
550
  input.skipped.push(route.path);
520
551
  continue;
521
552
  }
522
553
  const { renderer } = resolveExplicitViewRenderer({
523
554
  routePath: route.path,
524
555
  view,
556
+ declaredIn: route.loader.filePath
557
+ ? { file: route.loader.filePath, rootDir: this.appConfig.rootDir }
558
+ : undefined,
525
559
  routeRendererFactory: input.routeRendererFactory,
526
560
  errors: STATIC_SITE_GENERATOR_ERRORS,
527
561
  });
@@ -609,10 +643,10 @@ export class StaticSiteGenerator {
609
643
  if (!isDynamic) {
610
644
  return [{ pathname: routePath, params: {} }];
611
645
  }
612
- if (!view.staticPaths) {
613
- throw new Error(STATIC_SITE_GENERATOR_ERRORS.dynamicRouteRequiresStaticPaths(routePath));
646
+ if (!view.paths) {
647
+ throw new Error(STATIC_SITE_GENERATOR_ERRORS.dynamicRouteRequiresPaths(routePath));
614
648
  }
615
- const { paths } = await view.staticPaths({
649
+ const paths = await view.paths({
616
650
  appConfig: this.appConfig,
617
651
  runtimeOrigin: this.appConfig.baseUrl,
618
652
  });