@ecopages/core 0.3.0 → 0.3.1

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 (176) hide show
  1. package/README.md +2 -2
  2. package/package.json +3 -3
  3. package/src/adapters/node/create-app.d.ts +29 -11
  4. package/src/adapters/node/create-app.js +78 -67
  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 +23 -6
  9. package/src/adapters/node/runtime-host.js +27 -8
  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 +9 -5
  13. package/src/adapters/shared/hmr/hmr-manager.js +38 -54
  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 +5 -11
  22. package/src/adapters/shared/runtime/port-manager.d.ts +2 -11
  23. package/src/adapters/shared/runtime/port-manager.js +3 -28
  24. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +6 -9
  25. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +2 -5
  26. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +1 -3
  27. package/src/adapters/shared/runtime/server-request-pipeline.js +1 -5
  28. package/src/adapters/shared/runtime/server-static-builder.d.ts +3 -3
  29. package/src/adapters/shared/runtime/server-static-builder.js +3 -3
  30. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +2 -1
  31. package/src/adapters/shared/ws/websocket-lifecycle.d.ts +5 -6
  32. package/src/adapters/shared/ws/websocket-lifecycle.js +1 -2
  33. package/src/build/build-adapter.d.ts +2 -19
  34. package/src/build/build-adapter.js +0 -21
  35. package/src/build/cache/cache-keys.d.ts +0 -3
  36. package/src/build/cache/cache-keys.js +0 -14
  37. package/src/build/cache/pages-unified-graph-build.js +2 -17
  38. package/src/build/contracts/build-contracts.d.ts +0 -3
  39. package/src/build/rolldown/rolldown-build-adapter.d.ts +0 -1
  40. package/src/build/rolldown/rolldown-build-adapter.js +1 -2
  41. package/src/build/rolldown/rolldown-build-invocation-metrics.d.ts +1 -2
  42. package/src/build/rolldown/rolldown-build-invocation-metrics.js +5 -12
  43. package/src/build/runtime/build-queue.d.ts +8 -13
  44. package/src/build/runtime/build-queue.js +6 -17
  45. package/src/build/server/app-module-loader.service.d.ts +1 -1
  46. package/src/build/server/app-module-loader.service.js +0 -2
  47. package/src/build/server/page-module-import.service.d.ts +2 -3
  48. package/src/build/server/page-module-import.service.js +3 -4
  49. package/src/build/server-bundle-deploy-manifest.d.ts +5 -0
  50. package/src/build/server-bundle-deploy-manifest.js +15 -1
  51. package/src/build.d.ts +2 -2
  52. package/src/build.js +2 -2
  53. package/src/config/assembly/app-runtime.d.ts +2 -2
  54. package/src/config/assembly/app-runtime.js +2 -2
  55. package/src/config/assembly/finalize-config.d.ts +4 -4
  56. package/src/config/assembly/finalize-config.js +4 -5
  57. package/src/config/internal-types.d.ts +0 -7
  58. package/src/config/user-config-types.d.ts +0 -4
  59. package/src/diagnostics/request-pipeline-metrics.d.ts +3 -3
  60. package/src/diagnostics/request-pipeline-metrics.js +4 -4
  61. package/src/errors/http-error.d.ts +2 -2
  62. package/src/errors/http-error.js +4 -4
  63. package/src/hmr/client/hmr-runtime.js +16 -7
  64. package/src/hmr/client/module-update.d.ts +7 -0
  65. package/src/hmr/client/module-update.js +21 -4
  66. package/src/hmr/hmr-strategy.d.ts +0 -3
  67. package/src/hmr/hmr-strategy.js +0 -3
  68. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -3
  69. package/src/hmr/strategies/js-hmr-strategy.js +3 -6
  70. package/src/plugins/alias-resolver-cache.d.ts +4 -3
  71. package/src/plugins/alias-resolver-cache.js +4 -3
  72. package/src/plugins/eco-component-meta-plugin.d.ts +10 -1
  73. package/src/plugins/eco-component-meta-plugin.js +66 -10
  74. package/src/plugins/foreign-jsx-override-plugin.js +2 -1
  75. package/src/route-renderer/error-pages/default-error-pages.js +2 -1
  76. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -1
  77. package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +0 -1
  78. package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -5
  79. package/src/route-renderer/orchestration/integration-renderer.js +13 -14
  80. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -6
  81. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -6
  82. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
  83. package/src/route-renderer/page-loading/page-module-loader.js +1 -1
  84. package/src/route-renderer/route-renderer.d.ts +2 -5
  85. package/src/route-renderer/route-renderer.js +2 -4
  86. package/src/router/client/link-navigation-policy.d.ts +4 -1
  87. package/src/router/client/link-navigation-policy.js +20 -6
  88. package/src/router/server/route-registry.d.ts +0 -1
  89. package/src/router/server/route-registry.js +2 -11
  90. package/src/router/server/segment-path-matcher.d.ts +12 -0
  91. package/src/router/server/segment-path-matcher.js +30 -0
  92. package/src/static-site-generator/static-site-generator.d.ts +0 -5
  93. package/src/static-site-generator/static-site-generator.js +2 -15
  94. package/src/types/contracts.d.ts +17 -27
  95. package/src/types/public-types.d.ts +1 -1
  96. package/src/utils/format-error-chain.d.ts +9 -0
  97. package/src/utils/format-error-chain.js +20 -0
  98. package/src/utils/invariant.d.ts +6 -1
  99. package/src/utils/invariant.js +7 -2
  100. package/src/watchers/project-watcher.d.ts +20 -1
  101. package/src/watchers/project-watcher.js +40 -9
  102. package/src/watchers/workspace-package-watch-roots.js +5 -5
  103. package/src/adapters/README.md +0 -58
  104. package/src/adapters/shared/hmr/hmr-manager.test-helpers.d.ts +0 -28
  105. package/src/adapters/shared/hmr/hmr-manager.test-helpers.js +0 -53
  106. package/src/adapters/shared/runtime/runtime-host.d.ts +0 -15
  107. package/src/adapters/shared/runtime/runtime-host.js +0 -1
  108. package/src/assets/README.md +0 -35
  109. package/src/build/README.md +0 -298
  110. package/src/build/server/README.md +0 -50
  111. package/src/cache/README.md +0 -5
  112. package/src/client/README.md +0 -5
  113. package/src/client/navigation-scripts/navigation-scripts.test.browser.d.ts +0 -1
  114. package/src/client/navigation-scripts/navigation-scripts.test.browser.js +0 -111
  115. package/src/client/scroll.test.browser.d.ts +0 -1
  116. package/src/client/scroll.test.browser.js +0 -31
  117. package/src/client/view-transitions.test.browser.d.ts +0 -1
  118. package/src/client/view-transitions.test.browser.js +0 -53
  119. package/src/config/README.md +0 -58
  120. package/src/config/constants.d.ts +0 -1
  121. package/src/config/constants.js +0 -1
  122. package/src/dev/README.md +0 -61
  123. package/src/dev/invalidation/README.md +0 -11
  124. package/src/dev-toolbar/README.md +0 -66
  125. package/src/diagnostics/README.md +0 -11
  126. package/src/eco/README.md +0 -776
  127. package/src/errors/README.md +0 -5
  128. package/src/global/README.md +0 -5
  129. package/src/hmr/README.md +0 -64
  130. package/src/hmr/client/build-error-overlay.test.browser.d.ts +0 -1
  131. package/src/hmr/client/build-error-overlay.test.browser.js +0 -48
  132. package/src/hmr/client/hmr-runtime.test.browser.d.ts +0 -1
  133. package/src/hmr/client/hmr-runtime.test.browser.js +0 -32
  134. package/src/hmr/entrypoint-dependency-graph.d.ts +0 -12
  135. package/src/hmr/entrypoint-dependency-graph.js +0 -27
  136. package/src/hmr/hmr-file-change-prep.d.ts +0 -9
  137. package/src/hmr/hmr-file-change-prep.js +0 -11
  138. package/src/html/README.md +0 -15
  139. package/src/html-pages/README.md +0 -104
  140. package/src/islands/README.md +0 -44
  141. package/src/page-cache/README.md +0 -17
  142. package/src/plugins/README.md +0 -53
  143. package/src/route-renderer/GRAPH.md +0 -142
  144. package/src/route-renderer/README.md +0 -160
  145. package/src/route-renderer/error-pages/README.md +0 -11
  146. package/src/route-renderer/orchestration/custom-element-scripts/README.md +0 -15
  147. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.d.ts +0 -39
  148. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +0 -94
  149. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.d.ts +0 -35
  150. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.js +0 -69
  151. package/src/router/README.md +0 -160
  152. package/src/router/client/link-intent.test.browser.d.ts +0 -1
  153. package/src/router/client/link-intent.test.browser.js +0 -33
  154. package/src/router/client/link-navigation-policy.test.browser.d.ts +0 -1
  155. package/src/router/client/link-navigation-policy.test.browser.js +0 -142
  156. package/src/router/client/navigation-commit.test.browser.d.ts +0 -1
  157. package/src/router/client/navigation-commit.test.browser.js +0 -116
  158. package/src/router/client/navigation-document.test.browser.d.ts +0 -1
  159. package/src/router/client/navigation-document.test.browser.js +0 -77
  160. package/src/router/client/navigation-head.test.browser.d.ts +0 -1
  161. package/src/router/client/navigation-head.test.browser.js +0 -101
  162. package/src/router/client/navigation-lifecycle.test.browser.d.ts +0 -1
  163. package/src/router/client/navigation-lifecycle.test.browser.js +0 -97
  164. package/src/router/client/navigation-view-transition.test.browser.d.ts +0 -1
  165. package/src/router/client/navigation-view-transition.test.browser.js +0 -189
  166. package/src/router/client/staged-stylesheets.test-fixtures.d.ts +0 -18
  167. package/src/router/client/staged-stylesheets.test-fixtures.js +0 -31
  168. package/src/static-site-generator/README.md +0 -67
  169. package/src/static-site-generator/static-site-generator.test-utils.d.ts +0 -2
  170. package/src/static-site-generator/static-site-generator.test-utils.js +0 -41
  171. package/src/types/README.md +0 -5
  172. package/src/utils/README.md +0 -7
  173. package/src/validation/README.md +0 -9
  174. package/src/watchers/README.md +0 -15
  175. package/src/watchers/project-watcher.test-helpers.d.ts +0 -60
  176. package/src/watchers/project-watcher.test-helpers.js +0 -108
@@ -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) {
@@ -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
  }
@@ -6,7 +6,7 @@ import { invariant } from '../../utils/invariant.js';
6
6
  import { normalizePathname } from '../../utils/path-pattern.js';
7
7
  import { parseSearchParams } from './parse-search-params.js';
8
8
  import { findIntegrationForFile, findLongestExtension } from '../../plugins/find-integration-for-file.js';
9
- import { matchParsedSegmentPath, parseSegmentPath } from './segment-path-matcher.js';
9
+ import { buildSegmentPath, matchParsedSegmentPath, parseSegmentPath, } from './segment-path-matcher.js';
10
10
  const ROUTE_PRIORITY = {
11
11
  exact: 0,
12
12
  dynamic: 1,
@@ -122,7 +122,7 @@ export class RouteRegistry {
122
122
  });
123
123
  for (const { params } of result.paths) {
124
124
  expansions.push({
125
- pathname: this.resolveTemplatePath(route.pathname, params),
125
+ pathname: buildSegmentPath(route.pathname, params, 'filesystem'),
126
126
  templateRoute: route,
127
127
  params,
128
128
  });
@@ -227,13 +227,4 @@ export class RouteRegistry {
227
227
  getSearchParams(url) {
228
228
  return parseSearchParams(url.searchParams);
229
229
  }
230
- resolveTemplatePath(pathname, params) {
231
- let resolvedPath = pathname;
232
- for (const [key, value] of Object.entries(params)) {
233
- const serializedValue = Array.isArray(value) ? value.join('/') : value;
234
- resolvedPath = resolvedPath.replace(`[...${key}]`, serializedValue);
235
- resolvedPath = resolvedPath.replace(`[${key}]`, serializedValue);
236
- }
237
- return normalizePathname(resolvedPath);
238
- }
239
230
  }
@@ -23,5 +23,17 @@ export declare function matchParsedSegmentPath(pattern: string, pathSegments: Pa
23
23
  export declare function matchSegmentPath(pattern: string, pathname: string, syntax: 'filesystem' | 'api'): SegmentPathParams | null;
24
24
  export declare function matchSegmentPath(pattern: string, pathname: string, syntax: 'explicit' | 'websocket'): Record<string, string> | null;
25
25
  export declare function matchSegmentPath(pattern: string, pathname: string, syntax: SegmentPathSyntax): SegmentPathParams | null;
26
+ /**
27
+ * Builds a concrete pathname from a route pattern and its params.
28
+ *
29
+ * @remarks
30
+ * The inverse of {@link matchSegmentPath}: it reads the pattern with the same
31
+ * segment grammar, so `:id` never touches `:idx`, and a catch-all segment
32
+ * (`[...name]` or, for explicit routes, `:...name`) expands to every value of
33
+ * an array param or to a joined string. Values are inserted as given, without
34
+ * percent-encoding. A segment whose param is missing is kept verbatim, and a
35
+ * catch-all with no values disappears from the pathname.
36
+ */
37
+ export declare function buildSegmentPath(pattern: string, params: SegmentPathParams, syntax: SegmentPathSyntax): string;
26
38
  export declare function scoreSegmentPathPattern(pattern: string, syntax: 'api'): number;
27
39
  export declare function scoreSegmentPathPattern(pattern: string, syntax: 'websocket'): number;
@@ -132,6 +132,36 @@ export function matchParsedSegmentPath(pattern, pathSegments, syntax) {
132
132
  export function matchSegmentPath(pattern, pathname, syntax) {
133
133
  return matchParsedSegmentPath(pattern, parseSegmentPath(pathname), syntax);
134
134
  }
135
+ /**
136
+ * Builds a concrete pathname from a route pattern and its params.
137
+ *
138
+ * @remarks
139
+ * The inverse of {@link matchSegmentPath}: it reads the pattern with the same
140
+ * segment grammar, so `:id` never touches `:idx`, and a catch-all segment
141
+ * (`[...name]` or, for explicit routes, `:...name`) expands to every value of
142
+ * an array param or to a joined string. Values are inserted as given, without
143
+ * percent-encoding. A segment whose param is missing is kept verbatim, and a
144
+ * catch-all with no values disappears from the pathname.
145
+ */
146
+ export function buildSegmentPath(pattern, params, syntax) {
147
+ const options = syntaxOptions[syntax];
148
+ const segments = normalizePathname(pattern)
149
+ .split('/')
150
+ .filter(Boolean)
151
+ .flatMap((segment) => {
152
+ const patternSegment = parsePatternSegment(segment, options);
153
+ if (patternSegment.kind !== 'parameter' && patternSegment.kind !== 'catch-all') {
154
+ return [segment];
155
+ }
156
+ const value = params[patternSegment.name];
157
+ if (value === undefined) {
158
+ return [segment];
159
+ }
160
+ return Array.isArray(value) ? value : [value];
161
+ })
162
+ .filter((segment) => segment !== '');
163
+ return normalizePathname(segments.join('/'));
164
+ }
135
165
  export function scoreSegmentPathPattern(pattern, syntax) {
136
166
  const segments = parsePattern(pattern, syntax);
137
167
  if (syntax === 'websocket') {
@@ -101,11 +101,6 @@ export declare class StaticSiteGenerator {
101
101
  private planExplicitStaticRoute;
102
102
  private createExplicitStaticContents;
103
103
  private listExplicitStaticRouteEntries;
104
- /**
105
- * Resolve a route path template with actual params.
106
- * Supports both :param and [param] syntax.
107
- */
108
- private resolveRoutePath;
109
104
  /**
110
105
  * Get the output file path for a given route.
111
106
  */
@@ -10,6 +10,7 @@ import { clearProductionPageBrowserGraphSession, prebuildProductionPageBrowserGr
10
10
  import { renderSitemap } from './sitemap.js';
11
11
  import { resolveSitemapLocations } from './sitemap-routes.js';
12
12
  import { toEcopagesRouteInfo } from '../utils/ecopages-route-info.js';
13
+ import { buildSegmentPath } from '../router/server/segment-path-matcher.js';
13
14
  import { normalizePathname } from '../utils/path-pattern.js';
14
15
  import { ErrorPageRenderer } from '../route-renderer/error-pages/error-page-renderer.js';
15
16
  import { SemanticErrorPageExporter, SEMANTIC_ERROR_PAGE_PATHNAMES, } from '../route-renderer/error-pages/semantic-error-page-exporter.js';
@@ -537,24 +538,10 @@ export class StaticSiteGenerator {
537
538
  runtimeOrigin: this.appConfig.baseUrl,
538
539
  });
539
540
  return paths.map(({ params }) => ({
540
- pathname: this.resolveRoutePath(routePath, params),
541
+ pathname: buildSegmentPath(routePath, params, 'explicit'),
541
542
  params,
542
543
  }));
543
544
  }
544
- /**
545
- * Resolve a route path template with actual params.
546
- * Supports both :param and [param] syntax.
547
- */
548
- resolveRoutePath(routePath, params) {
549
- let resolved = routePath;
550
- for (const [key, value] of Object.entries(params)) {
551
- const paramValue = Array.isArray(value) ? value.join('/') : value;
552
- resolved = resolved.replace(`:${key}`, paramValue);
553
- resolved = resolved.replace(`[${key}]`, paramValue);
554
- resolved = resolved.replace(`[...${key}]`, paramValue);
555
- }
556
- return resolved;
557
- }
558
545
  /**
559
546
  * Get the output file path for a given route.
560
547
  */
@@ -35,8 +35,8 @@ export type PageDependenciesInput<T = Record<string, unknown>> = EcoComponentDep
35
35
  /**
36
36
  * Runtime-agnostic incoming WebSocket frame.
37
37
  *
38
- * Both Bun and Node `ws` deliver text and binary frames; this discriminated
39
- * union lets handlers deal with both without runtime-specific casts.
38
+ * Node `ws` delivers text and binary frames; this discriminated
39
+ * union lets handlers deal with both without casts.
40
40
  */
41
41
  export type IncomingWebSocketMessage = {
42
42
  readonly kind: 'text';
@@ -71,7 +71,7 @@ interface WebSocketContextFactoryInput<TParams extends Record<string, string> =
71
71
  readonly request: Request;
72
72
  readonly kind: string;
73
73
  readonly params: TParams;
74
- readonly search: Readonly<Record<string, string>>;
74
+ readonly search: Readonly<PageQuery>;
75
75
  readonly locals?: RequestLocals;
76
76
  }
77
77
  /**
@@ -80,7 +80,7 @@ interface WebSocketContextFactoryInput<TParams extends Record<string, string> =
80
80
  * Framework-owned fields:
81
81
  * - `kind`: the registered route pattern (e.g. '/ws/chat/:roomId')
82
82
  * - `params`: dynamic segments captured at match time
83
- * - `search`: query string, always string-typed
83
+ * - `search`: query string parameters, shaped like {@link PageQuery}: a repeated key is an array
84
84
  *
85
85
  * App-owned field:
86
86
  * - `context`: returned by the handler's `context()` factory
@@ -88,7 +88,7 @@ interface WebSocketContextFactoryInput<TParams extends Record<string, string> =
88
88
  export interface EcopagesSocket<TContext = unknown, TParams extends Record<string, string> = Record<string, string>> {
89
89
  readonly kind: string;
90
90
  readonly params: TParams;
91
- readonly search: Readonly<Record<string, string>>;
91
+ readonly search: Readonly<PageQuery>;
92
92
  readonly context: TContext;
93
93
  send(message: OutgoingWebSocketMessage): void;
94
94
  sendStream(stream: ReadableStream<Uint8Array>): Promise<void>;
@@ -229,15 +229,6 @@ export type ClientBridgeEvent = {
229
229
  * Timestamp for cache busting
230
230
  */
231
231
  timestamp?: number;
232
- /**
233
- * Page Browser Graph identities invalidated by the originating file change.
234
- */
235
- graphIdentities?: Array<{
236
- integrationName: string;
237
- routeFile: string;
238
- policy: 'development' | 'production';
239
- entryFingerprint: string;
240
- }>;
241
232
  };
242
233
  export interface HmrAction {
243
234
  type: 'broadcast' | 'none';
@@ -248,7 +239,6 @@ export interface HmrAction {
248
239
  */
249
240
  export type HmrFileChangeOptions = {
250
241
  broadcast?: boolean;
251
- graphIdentities?: ClientBridgeEvent['graphIdentities'];
252
242
  };
253
243
  /**
254
244
  * Integration callback for registered `dependencies.scripts` entrypoint changes in development.
@@ -259,7 +249,7 @@ export type HmrFileChangeOptions = {
259
249
  export type RegisteredScriptEntrypointChangeHandler = (filePath: string) => void | boolean | Promise<void | boolean>;
260
250
  /**
261
251
  * Adapter-agnostic interface for broadcasting development events to connected clients.
262
- * Implemented by both the Bun and Node client bridges.
252
+ * Implemented by the Node client bridge.
263
253
  */
264
254
  export interface IClientBridge {
265
255
  broadcast(event: ClientBridgeEvent): void;
@@ -350,10 +340,6 @@ export interface IHmrManager {
350
340
  * Gets the default HMR context.
351
341
  */
352
342
  getDefaultContext(): DefaultHmrContext;
353
- /**
354
- * Handles a file change event.
355
- */
356
- handleFileChange(path: string, options?: HmrFileChangeOptions): Promise<void>;
357
343
  /**
358
344
  * Handles all file changes from one watcher batch and coalesces their client update.
359
345
  */
@@ -690,8 +676,15 @@ export interface ErrorPageTemplateProps extends Omit<HtmlTemplateProps, 'childre
690
676
  */
691
677
  export type PageParams = Record<string, string | string[]>;
692
678
  /**
693
- * Represents a query object for a page.
694
- * The keys are strings and the values can be either a string or an array of strings.
679
+ * Query parameters parsed from the URL.
680
+ *
681
+ * @remarks
682
+ * A key that appears once is a string. A key repeated in the URL (`?tag=a&tag=b`)
683
+ * is an array of its values in URL order, never just its last value. Page props,
684
+ * API handlers (`ctx.query` and the value a query schema validates) and WebSocket
685
+ * `search` all share this shape, so a schema that expects a plain string rejects
686
+ * a repeated key with HTTP 400. Accept both with
687
+ * `z.union([z.string(), z.array(z.string())])`.
695
688
  */
696
689
  export type PageQuery = Record<string, string | string[]>;
697
690
  /**
@@ -781,9 +774,6 @@ export type EcoPagesAppConfig = {
781
774
  enabled?: boolean;
782
775
  package?: string;
783
776
  };
784
- experimental?: {
785
- unsafe?: Record<string, unknown>;
786
- };
787
777
  };
788
778
  export type PagePropsFor<T> = T extends GetStaticProps<infer P> ? P & {
789
779
  params?: PageParams;
@@ -1316,7 +1306,7 @@ type MiddlewareNext = () => Promise<Response>;
1316
1306
  *
1317
1307
  * @example Middleware with extended context (use EcoMiddleware helper)
1318
1308
  * ```typescript
1319
- * type AuthContext = ApiHandlerContext<BunRequest<string>, Server> & { user: User };
1309
+ * type AuthContext = ApiHandlerContext<Request, unknown> & { user: User };
1320
1310
  *
1321
1311
  * const authMiddleware: EcoMiddleware<AuthContext> = async (ctx, next) => {
1322
1312
  * const user = await authenticate(ctx.request);
@@ -1339,7 +1329,7 @@ export type FileRouteMiddleware<TRequest extends Request = Request, TServer = an
1339
1329
  *
1340
1330
  * @example
1341
1331
  * ```typescript
1342
- * type AuthContext = ApiHandlerContext<BunRequest<string>, Server> & {
1332
+ * type AuthContext = ApiHandlerContext<Request, unknown> & {
1343
1333
  * session: { user: User };
1344
1334
  * };
1345
1335
  *
@@ -1,3 +1,3 @@
1
- export type { ApiHandler, ApiHandlerContext, EcoComponent, EcoComponentConfig, EcoComponentDependencies, DependencyAttributes, EcoChildren, EcoFunctionComponent, EcoPageComponent, EcoPageFile, EcoPagesAppConfig, EcoPagesElement, EcoPageLayoutEntry, EcoPageLayoutSpec, EcoPageLayouts, EcoHtmlComponent, EcoLayoutComponent, ErrorHandler, ErrorPageTemplateProps, EcopagesRouteInfo, EcopagesSocket, EcopagesWebSocketHandler, FileRouteMiddleware, FileRouteMiddlewareContext, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, GetMetadata, GetMetadataContext, GetStaticPaths, GetStaticProps, HtmlTemplateProps, LayoutProps, LayoutPropsContext, Middleware, OutgoingWebSocketMessage, IncomingWebSocketMessage, PageHeadProps, PageMetadataProps, PageParams, PageQuery, PageDependenciesInput, PageDependenciesResult, PageProps, PagePropsFor, PageRequires, PageRobotsMetadata, RequestLocals, RequestPageContext, RenderContext, RenderOptions, RouteGroupBuilder, RouteOptions, RouteSchema, SitemapConfig, StandardSchema, StandardSchemaFailureResult, StandardSchemaIssue, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaV1, StaticPageContext, StaticPath, TypedGroupHandlerContext, WebSocketCloseInfo, WithLocals, } from './contracts.js';
1
+ export type { ApiHandler, ApiHandlerContext, EcoComponent, EcoComponentConfig, EcoComponentDependencies, DependencyAttributes, EcoChildren, EcoFunctionComponent, EcoPageComponent, EcoPageFile, EcoPagesAppConfig, EcoPagesElement, EcoPageLayoutEntry, EcoPageLayoutSpec, EcoPageLayouts, EcoHtmlComponent, EcoLayoutComponent, EcoMiddleware, ErrorHandler, ErrorPageTemplateProps, EcopagesRouteInfo, EcopagesSocket, EcopagesWebSocketHandler, FileRouteMiddleware, FileRouteMiddlewareContext, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, GetMetadata, GetMetadataContext, GetStaticPaths, GetStaticProps, HtmlTemplateProps, LayoutProps, LayoutPropsContext, Middleware, OutgoingWebSocketMessage, IncomingWebSocketMessage, PageHeadProps, PageMetadataProps, PageParams, PageQuery, PageDependenciesInput, PageDependenciesResult, PageProps, PagePropsFor, PageRequires, PageRobotsMetadata, RequestLocals, RequestPageContext, RenderContext, RenderOptions, RouteGroupBuilder, RouteOptions, RouteSchema, SitemapConfig, StandardSchema, StandardSchemaFailureResult, StandardSchemaIssue, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaV1, StaticPageContext, StaticPath, TypedGroupHandlerContext, WebSocketCloseInfo, WithLocals, } from './contracts.js';
2
2
  export type { CacheConfig, CacheStrategy } from './cache-types.js';
3
3
  export type { CallableComponentOf, ChildrenOf, ComponentOptions, Eco, EcoEmbedProps, EmbedPropsOf, HtmlOptions, LayoutOptions, LazyTrigger, PageOptions, PageOptionsBase, PagePropsForWithLocals, PropsOf, ResultOf, } from './eco-api-types.js';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Formats an error and its `cause` chain as one multi-line string.
3
+ *
4
+ * @remarks
5
+ * `Error.prototype.stack` never includes `cause`, and the app logger prints only `stack`, so a wrapper error such
6
+ * as a render failure would otherwise hide the stack and code frame of the error it wraps. An error without a
7
+ * cause formats to its own stack unchanged. Circular cause chains stop at the first repeated error.
8
+ */
9
+ export declare function formatErrorChain(error: unknown): string;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Formats an error and its `cause` chain as one multi-line string.
3
+ *
4
+ * @remarks
5
+ * `Error.prototype.stack` never includes `cause`, and the app logger prints only `stack`, so a wrapper error such
6
+ * as a render failure would otherwise hide the stack and code frame of the error it wraps. An error without a
7
+ * cause formats to its own stack unchanged. Circular cause chains stop at the first repeated error.
8
+ */
9
+ export function formatErrorChain(error) {
10
+ const seen = new Set();
11
+ const lines = [];
12
+ let current = error;
13
+ while (current !== undefined && !seen.has(current)) {
14
+ seen.add(current);
15
+ const text = current instanceof Error ? (current.stack ?? `${current.name}: ${current.message}`) : String(current);
16
+ lines.push(lines.length === 0 ? text : `Caused by: ${text}`);
17
+ current = current instanceof Error ? current.cause : undefined;
18
+ }
19
+ return lines.join('\n');
20
+ }
@@ -2,4 +2,9 @@
2
2
  * This module contains a simple utility invariant function that throws an error if the condition is not met
3
3
  * @module
4
4
  */
5
- export declare function invariant(condition: boolean, message?: string): asserts condition;
5
+ /**
6
+ * Throws a prefixed error when the condition is false.
7
+ *
8
+ * @param options Forwarded to the thrown error so callers can keep the original failure as `cause`.
9
+ */
10
+ export declare function invariant(condition: boolean, message?: string, options?: ErrorOptions): asserts condition;
@@ -3,10 +3,15 @@
3
3
  * @module
4
4
  */
5
5
  const prefix = '[ecopages]';
6
- export function invariant(condition, message) {
6
+ /**
7
+ * Throws a prefixed error when the condition is false.
8
+ *
9
+ * @param options Forwarded to the thrown error so callers can keep the original failure as `cause`.
10
+ */
11
+ export function invariant(condition, message, options) {
7
12
  if (condition) {
8
13
  return;
9
14
  }
10
15
  const value = message ? `${prefix} ${message}` : `${prefix} An error occurred`;
11
- throw new Error(value);
16
+ throw new Error(value, options);
12
17
  }
@@ -63,9 +63,24 @@ export declare class ProjectWatcher {
63
63
  private pendingFlushResolvers;
64
64
  private changeQueue;
65
65
  private closePromise;
66
+ /**
67
+ * Reads `ECOPAGES_WATCH_CHANGE_DEBOUNCE_MS`.
68
+ *
69
+ * @remarks
70
+ * A value that is not a non-negative number would otherwise become `NaN` or a negative delay, which timers
71
+ * treat as about 1 ms and so silently turn debouncing off. It is ignored with a warning instead, so the
72
+ * default window applies.
73
+ */
74
+ private static resolveEnvDebounceMs;
66
75
  constructor({ config, refreshRouterRoutesCallback, hmrManager, bridge, changeDebounceMs, onRestartRequest, entryWatcherOwnsConfig, }: ProjectWatcherConfig);
67
76
  private requestBrowserReload;
68
- private copyPublicDirFile;
77
+ /**
78
+ * Mirrors one public file change into dist.
79
+ *
80
+ * @remarks
81
+ * A deleted source is removed from dist, otherwise the stale copy keeps being served by the dev server.
82
+ */
83
+ private syncPublicDirFile;
69
84
  /**
70
85
  * Serializes file change handling so that concurrent chokidar events are
71
86
  * processed one at a time, preventing overlapping builds and race conditions.
@@ -105,6 +120,10 @@ export declare class ProjectWatcher {
105
120
  * @param {unknown} error - The error to handle
106
121
  */
107
122
  handleError(error: unknown): void;
123
+ /**
124
+ * Logs an error and shows it in the browser error overlay.
125
+ */
126
+ private reportError;
108
127
  /**
109
128
  * @remarks
110
129
  * The subscription watches `srcDir` recursively alongside external recorded