@ecopages/core 0.3.0 → 0.3.2

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 (201) hide show
  1. package/README.md +2 -2
  2. package/package.json +3 -3
  3. package/src/adapters/node/create-app.d.ts +40 -11
  4. package/src/adapters/node/create-app.js +95 -69
  5. package/src/adapters/node/dev-session.js +0 -1
  6. package/src/adapters/node/http-request-bridge.d.ts +4 -0
  7. package/src/adapters/node/http-request-bridge.js +9 -1
  8. package/src/adapters/node/runtime-host.d.ts +28 -6
  9. package/src/adapters/node/runtime-host.js +35 -9
  10. package/src/adapters/node/server-adapter.d.ts +10 -35
  11. package/src/adapters/node/server-adapter.js +21 -58
  12. package/src/adapters/shared/hmr/hmr-manager.d.ts +21 -7
  13. package/src/adapters/shared/hmr/hmr-manager.js +58 -70
  14. package/src/adapters/shared/http/api-request-pipeline.d.ts +3 -12
  15. package/src/adapters/shared/http/api-request-pipeline.js +7 -7
  16. package/src/adapters/shared/http/dist-file-handler.d.ts +16 -0
  17. package/src/adapters/shared/http/dist-file-handler.js +172 -0
  18. package/src/adapters/shared/http/explicit-static-route-matcher.js +2 -1
  19. package/src/adapters/shared/http/fs-server-response-matcher.js +3 -2
  20. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +5 -7
  21. package/src/adapters/shared/runtime/bind-runtime-server.js +8 -12
  22. package/src/adapters/shared/runtime/copy-runtime-public-dir.js +10 -9
  23. package/src/adapters/shared/runtime/port-manager.d.ts +8 -11
  24. package/src/adapters/shared/runtime/port-manager.js +19 -30
  25. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +6 -9
  26. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +2 -5
  27. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +1 -3
  28. package/src/adapters/shared/runtime/server-request-pipeline.js +1 -5
  29. package/src/adapters/shared/runtime/server-static-builder.d.ts +3 -3
  30. package/src/adapters/shared/runtime/server-static-builder.js +3 -3
  31. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +2 -1
  32. package/src/adapters/shared/ws/websocket-lifecycle.d.ts +5 -6
  33. package/src/adapters/shared/ws/websocket-lifecycle.js +1 -2
  34. package/src/assets/app-browser-client-build.js +1 -2
  35. package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +8 -8
  36. package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +4 -4
  37. package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +12 -8
  38. package/src/assets/asset-processing-service/processors/script/file-script.processor.js +36 -16
  39. package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +11 -6
  40. package/src/assets/browser-asset-output.d.ts +19 -0
  41. package/src/assets/browser-asset-output.js +30 -0
  42. package/src/assets/hashed-browser-asset.d.ts +8 -6
  43. package/src/assets/hashed-browser-asset.js +8 -6
  44. package/src/build/build-adapter.d.ts +2 -19
  45. package/src/build/build-adapter.js +0 -21
  46. package/src/build/build-graph.js +2 -2
  47. package/src/build/cache/cache-keys.d.ts +0 -3
  48. package/src/build/cache/cache-keys.js +0 -14
  49. package/src/build/cache/pages-unified-graph-build.js +2 -17
  50. package/src/build/contracts/build-contracts.d.ts +0 -3
  51. package/src/build/preserve-import-meta-transform.js +2 -2
  52. package/src/build/rolldown/app-package-declarations.js +3 -3
  53. package/src/build/rolldown/rolldown-adapter-helpers.js +3 -3
  54. package/src/build/rolldown/rolldown-build-adapter.d.ts +0 -1
  55. package/src/build/rolldown/rolldown-build-adapter.js +1 -2
  56. package/src/build/rolldown/rolldown-build-invocation-metrics.d.ts +1 -2
  57. package/src/build/rolldown/rolldown-build-invocation-metrics.js +5 -12
  58. package/src/build/rolldown/server-side-css-shim-plugin.js +3 -3
  59. package/src/build/runtime/build-queue.d.ts +8 -13
  60. package/src/build/runtime/build-queue.js +6 -17
  61. package/src/build/server/app-module-loader.service.d.ts +1 -1
  62. package/src/build/server/app-module-loader.service.js +0 -2
  63. package/src/build/server/page-module-import.service.d.ts +2 -3
  64. package/src/build/server/page-module-import.service.js +3 -4
  65. package/src/build/server-bundle-deploy-manifest.d.ts +5 -0
  66. package/src/build/server-bundle-deploy-manifest.js +15 -1
  67. package/src/build/server-bundle-publication.js +4 -5
  68. package/src/build.d.ts +2 -2
  69. package/src/build.js +2 -2
  70. package/src/config/assembly/app-runtime.d.ts +2 -2
  71. package/src/config/assembly/app-runtime.js +2 -2
  72. package/src/config/assembly/finalize-config.d.ts +4 -4
  73. package/src/config/assembly/finalize-config.js +4 -5
  74. package/src/config/config-module-files.js +2 -3
  75. package/src/config/internal-types.d.ts +0 -7
  76. package/src/config/user-config-types.d.ts +0 -4
  77. package/src/diagnostics/request-pipeline-metrics.d.ts +3 -3
  78. package/src/diagnostics/request-pipeline-metrics.js +4 -4
  79. package/src/diagnostics/startup-trace.js +2 -5
  80. package/src/errors/http-error.d.ts +2 -2
  81. package/src/errors/http-error.js +4 -4
  82. package/src/hmr/client/hmr-runtime.js +16 -7
  83. package/src/hmr/client/module-update.d.ts +7 -0
  84. package/src/hmr/client/module-update.js +21 -4
  85. package/src/hmr/hmr-strategy.d.ts +0 -3
  86. package/src/hmr/hmr-strategy.js +0 -3
  87. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -3
  88. package/src/hmr/strategies/js-hmr-strategy.js +3 -6
  89. package/src/html-pages/html-page-module-scripts.js +4 -3
  90. package/src/html-pages/html-page-renderer.js +2 -3
  91. package/src/plugins/alias-resolver-cache.d.ts +4 -3
  92. package/src/plugins/alias-resolver-cache.js +4 -3
  93. package/src/plugins/component-import-discovery.js +4 -4
  94. package/src/plugins/eco-component-meta-plugin.d.ts +10 -1
  95. package/src/plugins/eco-component-meta-plugin.js +66 -10
  96. package/src/plugins/foreign-jsx-override-plugin.js +4 -3
  97. package/src/plugins/tsconfig-import-resolver.js +12 -12
  98. package/src/route-renderer/error-pages/default-error-pages.js +2 -1
  99. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -1
  100. package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +0 -1
  101. package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -5
  102. package/src/route-renderer/orchestration/integration-renderer.js +13 -14
  103. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -23
  104. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -29
  105. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
  106. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +2 -2
  107. package/src/route-renderer/page-loading/page-dependency-bundling.js +5 -5
  108. package/src/route-renderer/page-loading/page-module-loader.js +1 -1
  109. package/src/route-renderer/route-renderer.d.ts +2 -5
  110. package/src/route-renderer/route-renderer.js +2 -4
  111. package/src/router/client/link-navigation-policy.d.ts +4 -1
  112. package/src/router/client/link-navigation-policy.js +20 -6
  113. package/src/router/server/route-registry.d.ts +0 -1
  114. package/src/router/server/route-registry.js +3 -13
  115. package/src/router/server/segment-path-matcher.d.ts +12 -0
  116. package/src/router/server/segment-path-matcher.js +30 -0
  117. package/src/static-site-generator/static-site-generator.d.ts +0 -5
  118. package/src/static-site-generator/static-site-generator.js +2 -15
  119. package/src/types/contracts.d.ts +17 -27
  120. package/src/types/public-types.d.ts +1 -1
  121. package/src/utils/format-error-chain.d.ts +9 -0
  122. package/src/utils/format-error-chain.js +20 -0
  123. package/src/utils/invariant.d.ts +6 -1
  124. package/src/utils/invariant.js +7 -2
  125. package/src/watchers/project-watcher.d.ts +20 -1
  126. package/src/watchers/project-watcher.js +40 -9
  127. package/src/watchers/workspace-package-watch-roots.js +5 -5
  128. package/src/adapters/README.md +0 -58
  129. package/src/adapters/shared/hmr/hmr-manager.test-helpers.d.ts +0 -28
  130. package/src/adapters/shared/hmr/hmr-manager.test-helpers.js +0 -53
  131. package/src/adapters/shared/runtime/runtime-host.d.ts +0 -15
  132. package/src/adapters/shared/runtime/runtime-host.js +0 -1
  133. package/src/assets/README.md +0 -35
  134. package/src/build/README.md +0 -298
  135. package/src/build/server/README.md +0 -50
  136. package/src/cache/README.md +0 -5
  137. package/src/client/README.md +0 -5
  138. package/src/client/navigation-scripts/navigation-scripts.test.browser.d.ts +0 -1
  139. package/src/client/navigation-scripts/navigation-scripts.test.browser.js +0 -111
  140. package/src/client/scroll.test.browser.d.ts +0 -1
  141. package/src/client/scroll.test.browser.js +0 -31
  142. package/src/client/view-transitions.test.browser.d.ts +0 -1
  143. package/src/client/view-transitions.test.browser.js +0 -53
  144. package/src/config/README.md +0 -58
  145. package/src/config/constants.d.ts +0 -1
  146. package/src/config/constants.js +0 -1
  147. package/src/dev/README.md +0 -61
  148. package/src/dev/invalidation/README.md +0 -11
  149. package/src/dev-toolbar/README.md +0 -66
  150. package/src/diagnostics/README.md +0 -11
  151. package/src/eco/README.md +0 -776
  152. package/src/errors/README.md +0 -5
  153. package/src/global/README.md +0 -5
  154. package/src/hmr/README.md +0 -64
  155. package/src/hmr/client/build-error-overlay.test.browser.d.ts +0 -1
  156. package/src/hmr/client/build-error-overlay.test.browser.js +0 -48
  157. package/src/hmr/client/hmr-runtime.test.browser.d.ts +0 -1
  158. package/src/hmr/client/hmr-runtime.test.browser.js +0 -32
  159. package/src/hmr/entrypoint-dependency-graph.d.ts +0 -12
  160. package/src/hmr/entrypoint-dependency-graph.js +0 -27
  161. package/src/hmr/hmr-file-change-prep.d.ts +0 -9
  162. package/src/hmr/hmr-file-change-prep.js +0 -11
  163. package/src/html/README.md +0 -15
  164. package/src/html-pages/README.md +0 -104
  165. package/src/islands/README.md +0 -44
  166. package/src/page-cache/README.md +0 -17
  167. package/src/plugins/README.md +0 -53
  168. package/src/route-renderer/GRAPH.md +0 -142
  169. package/src/route-renderer/README.md +0 -160
  170. package/src/route-renderer/error-pages/README.md +0 -11
  171. package/src/route-renderer/orchestration/custom-element-scripts/README.md +0 -15
  172. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.d.ts +0 -39
  173. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +0 -94
  174. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.d.ts +0 -35
  175. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.js +0 -69
  176. package/src/router/README.md +0 -160
  177. package/src/router/client/link-intent.test.browser.d.ts +0 -1
  178. package/src/router/client/link-intent.test.browser.js +0 -33
  179. package/src/router/client/link-navigation-policy.test.browser.d.ts +0 -1
  180. package/src/router/client/link-navigation-policy.test.browser.js +0 -142
  181. package/src/router/client/navigation-commit.test.browser.d.ts +0 -1
  182. package/src/router/client/navigation-commit.test.browser.js +0 -116
  183. package/src/router/client/navigation-document.test.browser.d.ts +0 -1
  184. package/src/router/client/navigation-document.test.browser.js +0 -77
  185. package/src/router/client/navigation-head.test.browser.d.ts +0 -1
  186. package/src/router/client/navigation-head.test.browser.js +0 -101
  187. package/src/router/client/navigation-lifecycle.test.browser.d.ts +0 -1
  188. package/src/router/client/navigation-lifecycle.test.browser.js +0 -97
  189. package/src/router/client/navigation-view-transition.test.browser.d.ts +0 -1
  190. package/src/router/client/navigation-view-transition.test.browser.js +0 -189
  191. package/src/router/client/staged-stylesheets.test-fixtures.d.ts +0 -18
  192. package/src/router/client/staged-stylesheets.test-fixtures.js +0 -31
  193. package/src/static-site-generator/README.md +0 -67
  194. package/src/static-site-generator/static-site-generator.test-utils.d.ts +0 -2
  195. package/src/static-site-generator/static-site-generator.test-utils.js +0 -41
  196. package/src/types/README.md +0 -5
  197. package/src/utils/README.md +0 -7
  198. package/src/validation/README.md +0 -9
  199. package/src/watchers/README.md +0 -15
  200. package/src/watchers/project-watcher.test-helpers.d.ts +0 -60
  201. package/src/watchers/project-watcher.test-helpers.js +0 -108
@@ -1,5 +1,5 @@
1
- import { existsSync, readFileSync, realpathSync } from 'node:fs';
2
1
  import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
3
  import { ResolverFactory } from 'oxc-resolver';
4
4
  import { toPackageRootSpecifier } from './package-specifier.js';
5
5
  const RESOLVABLE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.mdx'];
@@ -10,10 +10,10 @@ function stripJsonComments(source) {
10
10
  }
11
11
  function findTsconfigPath(projectRoot) {
12
12
  const candidate = path.join(projectRoot, 'tsconfig.json');
13
- return existsSync(candidate) ? candidate : undefined;
13
+ return fileSystem.exists(candidate) ? candidate : undefined;
14
14
  }
15
15
  function readJsonFile(filePath) {
16
- const source = readFileSync(filePath, 'utf8');
16
+ const source = fileSystem.readFileSync(filePath);
17
17
  try {
18
18
  return JSON.parse(source);
19
19
  }
@@ -173,7 +173,7 @@ export function resolveBarePackageBrowserEntry(projectRoot, specifier) {
173
173
  return undefined;
174
174
  }
175
175
  try {
176
- return { path: realpathSync(result.path), packageJsonPath: result.packageJsonPath };
176
+ return { path: fileSystem.realpath(result.path), packageJsonPath: result.packageJsonPath };
177
177
  }
178
178
  catch {
179
179
  return { path: result.path, packageJsonPath: result.packageJsonPath };
@@ -183,7 +183,7 @@ function resolveAliasedBarrelTarget(resolvedPath) {
183
183
  if (!path.basename(resolvedPath).startsWith('index.')) {
184
184
  return resolvedPath;
185
185
  }
186
- const source = readFileSync(resolvedPath, 'utf8').trim();
186
+ const source = fileSystem.readFileSync(resolvedPath).trim();
187
187
  const match = source.match(/^export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?$/);
188
188
  if (!match?.[1]?.startsWith('.')) {
189
189
  return resolvedPath;
@@ -192,13 +192,13 @@ function resolveAliasedBarrelTarget(resolvedPath) {
192
192
  const targetBase = path.resolve(targetDir, match[1]);
193
193
  for (const extension of RESOLVABLE_EXTENSIONS) {
194
194
  const candidate = `${targetBase}${extension}`;
195
- if (existsSync(candidate)) {
195
+ if (fileSystem.exists(candidate)) {
196
196
  return candidate;
197
197
  }
198
198
  }
199
199
  for (const extension of RESOLVABLE_EXTENSIONS) {
200
200
  const candidate = path.join(targetBase, `index${extension}`);
201
- if (existsSync(candidate)) {
201
+ if (fileSystem.exists(candidate)) {
202
202
  return candidate;
203
203
  }
204
204
  }
@@ -216,18 +216,18 @@ export function resolveRelativeModulePath(fromFile, specifier) {
216
216
  return undefined;
217
217
  }
218
218
  const targetBase = path.resolve(path.dirname(fromFile), specifier);
219
- if (existsSync(targetBase)) {
219
+ if (fileSystem.exists(targetBase)) {
220
220
  return path.resolve(targetBase);
221
221
  }
222
222
  for (const candidateExtension of RESOLVABLE_EXTENSIONS) {
223
223
  const candidate = `${targetBase}${candidateExtension}`;
224
- if (existsSync(candidate)) {
224
+ if (fileSystem.exists(candidate)) {
225
225
  return path.resolve(candidate);
226
226
  }
227
227
  }
228
228
  for (const candidateExtension of RESOLVABLE_EXTENSIONS) {
229
229
  const candidate = path.join(targetBase, `index${candidateExtension}`);
230
- if (existsSync(candidate)) {
230
+ if (fileSystem.exists(candidate)) {
231
231
  return path.resolve(candidate);
232
232
  }
233
233
  }
@@ -248,8 +248,8 @@ export function resolveProjectModulePath(projectRoot, fromFile, specifier, optio
248
248
  const result = resolver.sync(path.dirname(fromFile), specifier);
249
249
  if (result.path) {
250
250
  return options?.preserveBarrel
251
- ? realpathSync(result.path)
252
- : resolveAliasedBarrelTarget(realpathSync(result.path));
251
+ ? fileSystem.realpath(result.path)
252
+ : resolveAliasedBarrelTarget(fileSystem.realpath(result.path));
253
253
  }
254
254
  }
255
255
  if (isRelative) {
@@ -1,4 +1,5 @@
1
1
  import { isDevelopmentRuntime } from '../../utils/runtime.js';
2
+ import { formatErrorChain } from '../../utils/format-error-chain.js';
2
3
  import { escapeHtml } from '../../utils/html-escaping.js';
3
4
  import { ERROR_PAGE_COPY, isHttpErrorPageStatus, isHttpErrorStatus } from '../../errors/http-error-page-contract.js';
4
5
  /** Stable class hooks exposed by the framework-owned error documents. */
@@ -179,7 +180,7 @@ export function getDefaultServerErrorDetails(error) {
179
180
  return undefined;
180
181
  }
181
182
  if (error instanceof Error) {
182
- return { message: error.message, stack: error.stack };
183
+ return { message: error.message, stack: formatErrorChain(error) };
183
184
  }
184
185
  return { message: String(error) };
185
186
  }
@@ -156,6 +156,6 @@ export async function finalizeDocumentShellHtml(htmlTransformer, options) {
156
156
  const context = getComponentRenderContext()?.renderState;
157
157
  return htmlTransformer.injectPageAssets(html, {
158
158
  contributions: options.htmlContributions,
159
- pagePackage: context?.session?.pagePackage ?? context?.pagePackage,
159
+ pagePackage: context?.session?.pagePackage,
160
160
  });
161
161
  }
@@ -18,7 +18,6 @@ export type RenderSession = {
18
18
  export type RouteRenderContextState = {
19
19
  pageClientPlan?: PageClientPlan;
20
20
  islandRenderAssetsByFile?: ReadonlyMap<string, ProcessedAsset[]>;
21
- pagePackage?: PagePackageResult;
22
21
  session?: RenderSession;
23
22
  };
24
23
  /**
@@ -29,7 +29,7 @@ export type RouteModuleLoadOptions = {
29
29
  /**
30
30
  * Response options for an explicit view render.
31
31
  */
32
- export interface RenderToResponseContext {
32
+ export interface ExplicitViewResponseOptions {
33
33
  partial?: boolean;
34
34
  status?: number;
35
35
  headers?: HeadersInit;
@@ -37,7 +37,7 @@ export interface RenderToResponseContext {
37
37
  /**
38
38
  * Request data an explicit view render forwards to the route pipeline.
39
39
  */
40
- export type ExplicitViewRenderContext = RenderToResponseContext & Partial<Pick<RouteRendererOptions, 'params' | 'query' | 'locals' | 'file'>>;
40
+ export type ExplicitViewRenderContext = ExplicitViewResponseOptions & Partial<Pick<RouteRendererOptions, 'params' | 'query' | 'locals' | 'file'>>;
41
41
  export type HtmlDocumentContributionContext<C = EcoPagesElement> = {
42
42
  renderOptions?: IntegrationRendererRenderOptions<C>;
43
43
  partial?: boolean;
@@ -170,7 +170,11 @@ export declare abstract class IntegrationRenderer<C = EcoPagesElement> {
170
170
  private getPrebuiltRoutePreparation;
171
171
  getPrebuiltRouteComponentGraphs(routeOptions: RouteRendererOptions): PreparedRouteComponentGraphs | undefined;
172
172
  /**
173
- * Drops a production prebuild result when static export skips that route.
173
+ * Drops every production prebuild result for a route, including its grouped plan and page-client assets.
174
+ *
175
+ * @remarks
176
+ * Static export calls this when it skips a dynamic route. A render only consumes the one-shot route preparation,
177
+ * so the grouped plan and page-client assets keep serving later renders of the same route in production start.
174
178
  */
175
179
  clearPrebuiltRoutePreparation(input: Pick<RouteRendererOptions, 'file' | 'params' | 'query'>): void;
176
180
  /**
@@ -196,12 +200,13 @@ export declare abstract class IntegrationRenderer<C = EcoPagesElement> {
196
200
  * @param ctx - Render context with status and headers
197
201
  * @returns Response object
198
202
  */
199
- protected createHtmlResponse(body: BodyInit, ctx: RenderToResponseContext): Response;
203
+ protected createHtmlResponse(body: BodyInit, ctx: ExplicitViewResponseOptions): Response;
200
204
  /**
201
205
  * Create an HttpError for unexpected render failures.
202
206
  * @param message - Error message
203
207
  * @param cause - Original error if available
204
- * @returns The original HttpError when the cause is already one, otherwise a 500 HttpError
208
+ * @returns The original HttpError when the cause is already one, otherwise a 500 HttpError that keeps the
209
+ * original failure as `cause`
205
210
  * @remarks HttpError from pages (for example NotFound from content lookup) must keep its
206
211
  * status so the request matcher can serve a 404 instead of a 500.
207
212
  */
@@ -230,7 +230,11 @@ export class IntegrationRenderer {
230
230
  return this.getPrebuiltRoutePreparation(routeOptions)?.componentGraphs;
231
231
  }
232
232
  /**
233
- * Drops a production prebuild result when static export skips that route.
233
+ * Drops every production prebuild result for a route, including its grouped plan and page-client assets.
234
+ *
235
+ * @remarks
236
+ * Static export calls this when it skips a dynamic route. A render only consumes the one-shot route preparation,
237
+ * so the grouped plan and page-client assets keep serving later renders of the same route in production start.
234
238
  */
235
239
  clearPrebuiltRoutePreparation(input) {
236
240
  const routeKey = createPrebuiltRoutePreparationKey(input);
@@ -285,7 +289,8 @@ export class IntegrationRenderer {
285
289
  * Create an HttpError for unexpected render failures.
286
290
  * @param message - Error message
287
291
  * @param cause - Original error if available
288
- * @returns The original HttpError when the cause is already one, otherwise a 500 HttpError
292
+ * @returns The original HttpError when the cause is already one, otherwise a 500 HttpError that keeps the
293
+ * original failure as `cause`
289
294
  * @remarks HttpError from pages (for example NotFound from content lookup) must keep its
290
295
  * status so the request matcher can serve a 404 instead of a 500.
291
296
  */
@@ -294,7 +299,7 @@ export class IntegrationRenderer {
294
299
  return cause;
295
300
  }
296
301
  const errorMessage = cause instanceof Error ? `${message}: ${cause.message}` : message;
297
- return HttpError.InternalServerError(errorMessage);
302
+ return HttpError.InternalServerError(errorMessage, { cause });
298
303
  }
299
304
  async resolvePageBrowserGraphForFile(filePath) {
300
305
  /**
@@ -341,9 +346,8 @@ export class IntegrationRenderer {
341
346
  if (nextDependencies.length === 0) {
342
347
  return nextDependencies;
343
348
  }
344
- const renderState = getComponentRenderContext()?.renderState;
345
- const session = renderState?.session;
346
- const existingPackage = session?.pagePackage ?? renderState?.pagePackage;
349
+ const session = getComponentRenderContext()?.renderState?.session;
350
+ const existingPackage = session?.pagePackage;
347
351
  const existingDependencies = existingPackage?.assets ?? [];
348
352
  const mergedDependencies = this.htmlTransformer.dedupeProcessedAssets([
349
353
  ...existingDependencies,
@@ -355,9 +359,6 @@ export class IntegrationRenderer {
355
359
  if (session) {
356
360
  session.pagePackage = pagePackage;
357
361
  }
358
- if (renderState) {
359
- renderState.pagePackage = pagePackage;
360
- }
361
362
  return nextDependencies;
362
363
  }
363
364
  /**
@@ -501,7 +502,7 @@ export class IntegrationRenderer {
501
502
  return HtmlTemplate;
502
503
  }
503
504
  catch (error) {
504
- invariant(false, `Error importing HtmlTemplate: ${error}`);
505
+ invariant(false, `Error importing HtmlTemplate: ${error}`, { cause: error });
505
506
  }
506
507
  }
507
508
  normalizeImportedPageFile(file, pageModule) {
@@ -570,8 +571,7 @@ export class IntegrationRenderer {
570
571
  });
571
572
  }
572
573
  async transformRouteResponse(response, htmlContributions, pagePackage, renderOptions) {
573
- const renderState = getComponentRenderContext()?.renderState;
574
- const resolvedPagePackage = renderState?.session?.pagePackage ?? renderState?.pagePackage ?? pagePackage;
574
+ const resolvedPagePackage = getComponentRenderContext()?.renderState?.session?.pagePackage ?? pagePackage;
575
575
  const transformedResponse = this.htmlTransformer.transform(response, {
576
576
  contributions: htmlContributions,
577
577
  pagePackage: resolvedPagePackage,
@@ -739,7 +739,6 @@ export class IntegrationRenderer {
739
739
  if (renderState) {
740
740
  renderState.pageClientPlan = renderOptions.pageClientPlan;
741
741
  renderState.islandRenderAssetsByFile = renderOptions.islandRenderAssetsByFile;
742
- renderState.pagePackage = renderOptions.pagePackage;
743
742
  }
744
743
  session.pagePackage = renderOptions.pagePackage;
745
744
  return this.routeRenderOrchestrator.executePrepared(renderOptions, this);
@@ -748,7 +747,7 @@ export class IntegrationRenderer {
748
747
  }
749
748
  finally {
750
749
  if (preparation) {
751
- this.clearPrebuiltRoutePreparation(options);
750
+ this.prebuiltRoutePreparations.delete(createPrebuiltRoutePreparationKey(options));
752
751
  }
753
752
  }
754
753
  }
@@ -1,5 +1,4 @@
1
1
  import type { GroupedGraphScope } from './route-instance-key.js';
2
- import type { EcoPagesAppConfig } from '../../../config/internal-types.js';
3
2
  import type { PageBrowserGraphContribution, PageBrowserGraphResult } from '../../../types/contracts.js';
4
3
  import type { ProcessedAsset } from '../../../assets/asset-processing-service/assets.types.js';
5
4
  import { BuildInputDependencyIndex } from '../../../build/cache/build-input-dependency-index.js';
@@ -32,18 +31,6 @@ type GroupedGraphRecord = {
32
31
  dependencyPaths: ReadonlySet<string>;
33
32
  generation: number;
34
33
  };
35
- export type GroupedGraphBuildOutcome = GroupedGraphRecord | {
36
- skipCache: true;
37
- assetsByRoute: Map<string, ProcessedAsset[]>;
38
- dependencyPaths: ReadonlySet<string>;
39
- };
40
- export type AffectedGraphIdentity = {
41
- integrationName: string;
42
- routeFile: string;
43
- dependencyInstanceKey: string;
44
- policy: GraphPolicy;
45
- entryFingerprint: string;
46
- };
47
34
  /**
48
35
  * Session-local Page Browser Graph cache with precise dependency invalidation.
49
36
  */
@@ -68,12 +55,11 @@ export declare class SessionPageBrowserGraphCache {
68
55
  getBuildCount(): number;
69
56
  getGraphByRoute(integrationName: string, routeFile: string, policy: GraphPolicy, dependencyInstanceKey?: string): PageBrowserGraphResult | undefined;
70
57
  getDependencyPathsByRoute(integrationName: string, routeFile: string, policy: GraphPolicy, dependencyInstanceKey?: string): ReadonlySet<string> | undefined;
71
- getAffectedGraphIdentities(filePath: string): AffectedGraphIdentity[];
72
58
  resolveGraph(key: GraphKey, provisionalDependencyPaths: ReadonlySet<string>, build: () => Promise<GraphBuildResult | undefined>, options?: {
73
59
  reuseCachedResult?: boolean;
74
60
  }): Promise<PageBrowserGraphResult | undefined>;
75
61
  private buildGraphWithoutCaching;
76
- resolveGroupedGraph(scope: GroupedGraphScope, build: () => Promise<GroupedGraphBuildOutcome | undefined>): Promise<Map<string, ProcessedAsset[]>>;
62
+ resolveGroupedGraph(scope: GroupedGraphScope, build: () => Promise<GroupedGraphRecord | undefined>): Promise<Map<string, ProcessedAsset[]>>;
77
63
  peekGroupedGraph(scope: GroupedGraphScope): Map<string, ProcessedAsset[]> | undefined;
78
64
  invalidateByFilePath(filePath: string): number;
79
65
  invalidateRoute(integrationName: string, routeFile: string): void;
@@ -94,14 +80,6 @@ export declare class SessionPageBrowserGraphCache {
94
80
  private clearInFlightBuild;
95
81
  private releaseInFlightDependencyPaths;
96
82
  }
97
- /**
98
- * Invalidates graph records that depend on the changed file path.
99
- */
100
- export declare function invalidatePageBrowserGraphSession(appConfig: EcoPagesAppConfig, filePath: string): void;
101
- /**
102
- * Returns graph identities affected by a source file change.
103
- */
104
- export declare function getAffectedPageBrowserGraphIdentities(appConfig: EcoPagesAppConfig, filePath: string): AffectedGraphIdentity[];
105
83
  /**
106
84
  * Builds a stable fingerprint from declared browser-entry dependencies and assets.
107
85
  */
@@ -3,13 +3,9 @@ import { serializeGroupedGraphCacheKey } from './route-instance-key.js';
3
3
  import { contentHash } from '../../../utils/content-hash.js';
4
4
  import { appLogger } from '../../../global/app-logger.js';
5
5
  import { BuildInputDependencyIndex, } from '../../../build/cache/build-input-dependency-index.js';
6
- import { requireAppRuntime } from '../../../utils/app-runtime.js';
7
6
  function graphBinding(key) {
8
7
  return { consumer: 'page-browser-graph', key };
9
8
  }
10
- function isSkipCacheGroupedOutcome(outcome) {
11
- return 'skipCache' in outcome;
12
- }
13
9
  function serializeGraphKey(key) {
14
10
  return JSON.stringify([
15
11
  'graph',
@@ -109,16 +105,6 @@ export class SessionPageBrowserGraphCache {
109
105
  }
110
106
  return undefined;
111
107
  }
112
- getAffectedGraphIdentities(filePath) {
113
- const identities = [];
114
- for (const serializedKey of this.graphKeysFor(filePath)) {
115
- const identity = parseSerializedGraphKey(serializedKey);
116
- if (identity) {
117
- identities.push(identity);
118
- }
119
- }
120
- return identities;
121
- }
122
108
  resolveGraph(key, provisionalDependencyPaths, build, options = {}) {
123
109
  if (options.reuseCachedResult === false) {
124
110
  return this.buildGraphWithoutCaching(build);
@@ -343,9 +329,6 @@ export class SessionPageBrowserGraphCache {
343
329
  if (!buildResult) {
344
330
  return new Map();
345
331
  }
346
- if (isSkipCacheGroupedOutcome(buildResult)) {
347
- return buildResult.assetsByRoute;
348
- }
349
332
  if (!this.canCommitGroupedBuild(cacheKey, buildGeneration)) {
350
333
  const existing = this.groupedRecords.get(cacheKey);
351
334
  return existing?.assetsByRoute ?? new Map();
@@ -402,18 +385,6 @@ export class SessionPageBrowserGraphCache {
402
385
  this.inFlightDependencyPaths.delete(serializedKey);
403
386
  }
404
387
  }
405
- /**
406
- * Invalidates graph records that depend on the changed file path.
407
- */
408
- export function invalidatePageBrowserGraphSession(appConfig, filePath) {
409
- requireAppRuntime(appConfig).pageBrowserGraphSession.invalidateByFilePath(filePath);
410
- }
411
- /**
412
- * Returns graph identities affected by a source file change.
413
- */
414
- export function getAffectedPageBrowserGraphIdentities(appConfig, filePath) {
415
- return requireAppRuntime(appConfig).pageBrowserGraphSession.getAffectedGraphIdentities(filePath);
416
- }
417
388
  /**
418
389
  * Builds a stable fingerprint from declared browser-entry dependencies and assets.
419
390
  */
@@ -182,7 +182,6 @@ export class PageBrowserGraphService {
182
182
  return {
183
183
  assetsByRoute: new Map([[routeLookupKey, [...plannedInstance.prebuiltGroupedAssets]]]),
184
184
  dependencyPaths: new Set(),
185
- hasCollectionFailures: false,
186
185
  cacheable: true,
187
186
  };
188
187
  }
@@ -212,17 +211,8 @@ export class PageBrowserGraphService {
212
211
  integrationName: input.integrationName,
213
212
  planKey: input.groupedBuildPlan.planKey,
214
213
  };
215
- let groupedCacheable = true;
216
214
  const assetsByRoute = await session.resolveGroupedGraph(groupedScope, async () => {
217
215
  const built = await this.buildGroupedPageBrowserAssets(input, currentContribution);
218
- groupedCacheable = !built.hasCollectionFailures;
219
- if (built.hasCollectionFailures) {
220
- return {
221
- skipCache: true,
222
- assetsByRoute: built.assetsByRoute,
223
- dependencyPaths: built.dependencyPaths,
224
- };
225
- }
226
216
  return {
227
217
  assetsByRoute: built.assetsByRoute,
228
218
  dependencyPaths: built.dependencyPaths,
@@ -232,22 +222,15 @@ export class PageBrowserGraphService {
232
222
  return {
233
223
  assetsByRoute,
234
224
  dependencyPaths: new Set(),
235
- hasCollectionFailures: !groupedCacheable,
236
- cacheable: groupedCacheable,
225
+ cacheable: true,
237
226
  };
238
227
  }
239
228
  collectGroupedBuildPlanContributions(input) {
240
- if (!input.groupedBuildPlan) {
241
- return { contributions: [], hasCollectionFailures: false };
242
- }
243
- return {
244
- contributions: input.groupedBuildPlan.instances.map((instance) => ({
245
- routeFile: instance.routeFile,
246
- dependencyInstanceKey: instance.dependencyInstanceKey,
247
- contribution: instance.contribution,
248
- })),
249
- hasCollectionFailures: false,
250
- };
229
+ return (input.groupedBuildPlan?.instances ?? []).map((instance) => ({
230
+ routeFile: instance.routeFile,
231
+ dependencyInstanceKey: instance.dependencyInstanceKey,
232
+ contribution: instance.contribution,
233
+ }));
251
234
  }
252
235
  registerRouteGroupedDependencies(routeLookupKey, routeFile, routeGroupedDependencies, groupedDependencies, groupedAssetKeysByRoute, routeDisplayPaths, dependencyPaths) {
253
236
  if (routeGroupedDependencies.length === 0) {
@@ -258,7 +241,7 @@ export class PageBrowserGraphService {
258
241
  routeDisplayPaths.set(routeLookupKey, routeFile);
259
242
  dependencyPaths.add(path.resolve(routeFile));
260
243
  }
261
- mergePeerGroupedContributions(input, currentContribution, groupedContributions, hasCollectionFailures) {
244
+ mergePeerGroupedContributions(input, currentContribution, groupedContributions) {
262
245
  const dependencyInstanceKey = input.dependencyInstanceKey ?? '';
263
246
  const currentRouteLookupKey = createRouteGraphLookupKey(input.routeFile, dependencyInstanceKey);
264
247
  const currentRouteGroupedDependencies = (currentContribution.dependencies ?? []).filter((dep) => isGroupedContentScriptAsset(dep));
@@ -287,7 +270,6 @@ export class PageBrowserGraphService {
287
270
  groupedAssetKeysByRoute,
288
271
  routeDisplayPaths,
289
272
  dependencyPaths,
290
- hasCollectionFailures,
291
273
  };
292
274
  }
293
275
  addGroupedDependencyFilePaths(groupedDependencies, dependencyPaths) {
@@ -322,15 +304,12 @@ export class PageBrowserGraphService {
322
304
  }
323
305
  }
324
306
  async buildGroupedPageBrowserAssets(input, currentContribution) {
325
- const groupedCollection = this.collectGroupedBuildPlanContributions(input);
326
- const merged = this.mergePeerGroupedContributions(input, currentContribution, groupedCollection.contributions, groupedCollection.hasCollectionFailures);
327
- const { groupedDependencies, groupedAssetKeysByRoute, routeDisplayPaths, dependencyPaths, hasCollectionFailures, } = merged;
307
+ const { groupedDependencies, groupedAssetKeysByRoute, routeDisplayPaths, dependencyPaths } = this.mergePeerGroupedContributions(input, currentContribution, this.collectGroupedBuildPlanContributions(input));
328
308
  if (groupedDependencies.length === 0) {
329
309
  return {
330
310
  assetsByRoute: new Map(),
331
311
  dependencyPaths,
332
- hasCollectionFailures,
333
- cacheable: Boolean(input.groupedBuildPlan) && !hasCollectionFailures,
312
+ cacheable: Boolean(input.groupedBuildPlan),
334
313
  };
335
314
  }
336
315
  this.addGroupedDependencyFilePaths(groupedDependencies, dependencyPaths);
@@ -341,8 +320,7 @@ export class PageBrowserGraphService {
341
320
  return {
342
321
  assetsByRoute: groupedAssetsByRoute,
343
322
  dependencyPaths,
344
- hasCollectionFailures,
345
- cacheable: Boolean(input.groupedBuildPlan) && !hasCollectionFailures,
323
+ cacheable: Boolean(input.groupedBuildPlan),
346
324
  };
347
325
  }
348
326
  partitionPageBrowserGraphAssets(assets) {
@@ -1,4 +1,4 @@
1
- import { readFileSync } from 'node:fs';
1
+ import { fileSystem } from '@ecopages/file-system';
2
2
  import { isContentServerVirtualModule } from '../../build/contracts/content-virtual-modules.js';
3
3
  import { parseModuleSource } from '../../cache/module-parse-cache.js';
4
4
  import { isProductionRuntime } from '../../utils/runtime.js';
@@ -70,7 +70,7 @@ const productionVirtualImportsByFile = new Map();
70
70
  function readEcopagesVirtualImports(file) {
71
71
  let source;
72
72
  try {
73
- source = readFileSync(file, 'utf-8');
73
+ source = fileSystem.readFileSync(file);
74
74
  }
75
75
  catch {
76
76
  return [];
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync } from 'node:fs';
1
+ import { fileSystem } from '@ecopages/file-system';
2
2
  import { AssetFactory } from '../../assets/asset-processing-service/index.js';
3
3
  import { contentHash } from '../../utils/content-hash.js';
4
4
  import { isProductionRuntime } from '../../utils/runtime.js';
@@ -74,10 +74,10 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
74
74
  if (dependency.source === 'content') {
75
75
  return isSafeBundledStylesheetContent(dependency.content);
76
76
  }
77
- if (!existsSync(dependency.filepath)) {
77
+ if (!fileSystem.exists(dependency.filepath)) {
78
78
  return false;
79
79
  }
80
- return isSafeBundledStylesheetContent(readFileSync(dependency.filepath, 'utf8'));
80
+ return isSafeBundledStylesheetContent(fileSystem.readFileSync(dependency.filepath));
81
81
  })
82
82
  .filter(isBundleableFileStylesheetAsset);
83
83
  const bundleableScripts = dependencies
@@ -93,7 +93,7 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
93
93
  !dependency.packageRole &&
94
94
  dependency.bundle !== false &&
95
95
  hasOnlyExpectedAttributes(dependency.attributes, { type: 'module', defer: '' }) &&
96
- existsSync(dependency.filepath));
96
+ fileSystem.exists(dependency.filepath));
97
97
  })
98
98
  .filter(isBundleableFileScriptAsset);
99
99
  const eligibleStyles = new Set(bundleableStyles);
@@ -106,7 +106,7 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
106
106
  const bundledScriptMembers = new Set();
107
107
  for (const run of collectContiguousEligibleRuns(dependencies, isEligibleStyle)) {
108
108
  const bundledStylesheet = AssetFactory.createContentStylesheet({
109
- content: run.assets.map((dependency) => readFileSync(dependency.filepath, 'utf8')).join('\n'),
109
+ content: run.assets.map((dependency) => fileSystem.readFileSync(dependency.filepath)).join('\n'),
110
110
  position: 'head',
111
111
  attributes: { rel: 'stylesheet' },
112
112
  packageRole: 'page-style',
@@ -38,7 +38,7 @@ export class PageModuleLoaderService {
38
38
  });
39
39
  }
40
40
  catch (error) {
41
- invariant(false, `Error importing page file: ${error}`);
41
+ invariant(false, `Error importing page file: ${error}`, { cause: error });
42
42
  }
43
43
  }
44
44
  /**
@@ -1,4 +1,3 @@
1
- import type { AppRuntime } from '../config/assembly/app-runtime.js';
2
1
  import type { EcoPagesAppConfig } from '../config/internal-types.js';
3
2
  import type { AnyIntegrationPlugin } from '../plugins/integration-plugin.js';
4
3
  import type { IntegrationRenderer } from './orchestration/integration-renderer.js';
@@ -40,13 +39,11 @@ export type StaticGenerationRendererResolver = PageRendererResolver & ExplicitVi
40
39
  */
41
40
  export declare class RouteRendererFactory {
42
41
  private appConfig;
43
- private readonly runtime;
44
42
  /**
45
- * Creates the route-renderer factory for one app/runtime instance.
43
+ * Creates the route-renderer factory for one app config.
46
44
  */
47
- constructor({ appConfig, runtime }: {
45
+ constructor({ appConfig }: {
48
46
  appConfig: EcoPagesAppConfig;
49
- runtime: AppRuntime;
50
47
  });
51
48
  /**
52
49
  * Returns a route renderer for the supplied route file.
@@ -10,13 +10,11 @@ import { findIntegrationForFile } from '../plugins/find-integration-for-file.js'
10
10
  */
11
11
  export class RouteRendererFactory {
12
12
  appConfig;
13
- runtime;
14
13
  /**
15
- * Creates the route-renderer factory for one app/runtime instance.
14
+ * Creates the route-renderer factory for one app config.
16
15
  */
17
- constructor({ appConfig, runtime }) {
16
+ constructor({ appConfig }) {
18
17
  this.appConfig = appConfig;
19
- this.runtime = runtime;
20
18
  }
21
19
  /**
22
20
  * Returns a route renderer for the supplied route file.
@@ -27,10 +27,13 @@ export declare function isSamePageHref(href: string, currentHref?: string): bool
27
27
  export declare function isSamePageHashNavigationHref(href: string): boolean;
28
28
  /**
29
29
  * Decides whether a pointer or click on an anchor should be handled as SPA navigation.
30
+ *
31
+ * @remarks
32
+ * An intercepted decision carries the resolved same-origin path, query, and hash, never the raw attribute.
30
33
  */
31
34
  export declare function getLinkNavigationDecision(event: MouseEvent | PointerEvent, link: HTMLAnchorElement, options: LinkNavigationPolicyOptions): LinkNavigationDecision;
32
35
  /**
33
- * Returns the href when SPA navigation should intercept the click, otherwise `null`.
36
+ * Returns the resolved same-origin href when SPA navigation should intercept the click, otherwise `null`.
34
37
  */
35
38
  export declare function getNavigableHrefFromClick(event: MouseEvent | PointerEvent, link: HTMLAnchorElement, options: LinkNavigationPolicyOptions): string | null;
36
39
  /**
@@ -16,15 +16,27 @@ function getLinkIneligibilityReason(link, options) {
16
16
  if (!href || href.startsWith('#') || href.startsWith('javascript:')) {
17
17
  return 'invalid-href';
18
18
  }
19
- const url = new URL(href, window.location.origin);
19
+ const url = new URL(link.href);
20
20
  if (url.origin !== window.location.origin) {
21
21
  return 'cross-origin';
22
22
  }
23
- if (isStaticAssetHref(href)) {
23
+ if (isStaticAssetHref(link.href)) {
24
24
  return 'static-asset';
25
25
  }
26
26
  return null;
27
27
  }
28
+ /**
29
+ * Returns the same-origin path, query, and hash an anchor navigates to.
30
+ *
31
+ * @remarks
32
+ * Resolves through the anchor's own `href` property, so relative links (`?page=2`,
33
+ * `next`, `../x`) and `<base href>` resolve exactly as a full page load would instead
34
+ * of against the origin. Call only after the link passed the same-origin checks.
35
+ */
36
+ function getLinkNavigationHref(link) {
37
+ const url = new URL(link.href);
38
+ return `${url.pathname}${url.search}${url.hash}`;
39
+ }
28
40
  /**
29
41
  * Returns whether an href targets the current origin, pathname, and query.
30
42
  *
@@ -48,6 +60,9 @@ export function isSamePageHashNavigationHref(href) {
48
60
  }
49
61
  /**
50
62
  * Decides whether a pointer or click on an anchor should be handled as SPA navigation.
63
+ *
64
+ * @remarks
65
+ * An intercepted decision carries the resolved same-origin path, query, and hash, never the raw attribute.
51
66
  */
52
67
  export function getLinkNavigationDecision(event, link, options) {
53
68
  if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
@@ -64,14 +79,14 @@ export function getLinkNavigationDecision(event, link, options) {
64
79
  if (ineligibility) {
65
80
  return { shouldIntercept: false, reason: ineligibility };
66
81
  }
67
- const href = link.getAttribute('href');
82
+ const href = getLinkNavigationHref(link);
68
83
  if (isSamePageHashNavigationHref(href)) {
69
84
  return { shouldIntercept: false, reason: 'same-page-hash' };
70
85
  }
71
86
  return { shouldIntercept: true, href };
72
87
  }
73
88
  /**
74
- * Returns the href when SPA navigation should intercept the click, otherwise `null`.
89
+ * Returns the resolved same-origin href when SPA navigation should intercept the click, otherwise `null`.
75
90
  */
76
91
  export function getNavigableHrefFromClick(event, link, options) {
77
92
  const decision = getLinkNavigationDecision(event, link, options);
@@ -84,8 +99,7 @@ export function shouldPrefetchLink(link, options) {
84
99
  if (getLinkIneligibilityReason(link, options)) {
85
100
  return false;
86
101
  }
87
- const href = link.getAttribute('href');
88
- return !isSamePageHref(href);
102
+ return !isSamePageHref(getLinkNavigationHref(link));
89
103
  }
90
104
  /**
91
105
  * @remarks
@@ -99,5 +99,4 @@ export declare class RouteRegistry {
99
99
  private classifyRouteKind;
100
100
  private getParamNames;
101
101
  private getSearchParams;
102
- private resolveTemplatePath;
103
102
  }