@ecopages/core 0.2.0-rc.1 → 0.2.0-rc.10

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 (179) hide show
  1. package/README.md +50 -32
  2. package/package.json +50 -4
  3. package/src/adapters/README.md +3 -1
  4. package/src/adapters/abstract/application-adapter.d.ts +28 -6
  5. package/src/adapters/abstract/application-adapter.js +58 -5
  6. package/src/adapters/abstract/segment-path-matcher.js +56 -38
  7. package/src/adapters/abstract/server-adapter.d.ts +14 -0
  8. package/src/adapters/abstract/server-adapter.js +10 -0
  9. package/src/adapters/bun/create-app.d.ts +8 -4
  10. package/src/adapters/bun/create-app.js +64 -37
  11. package/src/adapters/bun/server-adapter.d.ts +6 -2
  12. package/src/adapters/bun/server-adapter.js +14 -1
  13. package/src/adapters/create-app.d.ts +62 -7
  14. package/src/adapters/create-app.js +61 -5
  15. package/src/adapters/node/create-app.d.ts +5 -5
  16. package/src/adapters/node/create-app.js +18 -5
  17. package/src/adapters/node/runtime-host.js +9 -4
  18. package/src/adapters/node/server-adapter.d.ts +5 -1
  19. package/src/adapters/node/server-adapter.js +16 -1
  20. package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
  21. package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -8
  22. package/src/adapters/shared/http/fs-server-response-factory.js +5 -30
  23. package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
  24. package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
  25. package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
  26. package/src/adapters/shared/runtime/application-adapter.js +12 -0
  27. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
  28. package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
  29. package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
  30. package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
  31. package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
  32. package/src/adapters/shared/runtime/port-manager.js +14 -45
  33. package/src/adapters/shared/runtime/server-adapter.d.ts +14 -5
  34. package/src/adapters/shared/runtime/server-adapter.js +22 -30
  35. package/src/adapters/shared/runtime/server-route-handler.js +11 -3
  36. package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
  37. package/src/adapters/shared/runtime/server-static-builder.js +59 -37
  38. package/src/build/README.md +4 -0
  39. package/src/build/cache/server-entry-build-cache.d.ts +24 -1
  40. package/src/build/cache/server-entry-build-cache.js +125 -8
  41. package/src/build/contracts/content-virtual-modules.d.ts +3 -1
  42. package/src/build/contracts/content-virtual-modules.js +8 -0
  43. package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
  44. package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
  45. package/src/build/runtime/build-request-policy.js +1 -1
  46. package/src/build/server-bundle-publication.d.ts +14 -0
  47. package/src/build/server-bundle-publication.js +49 -0
  48. package/src/config/README.md +17 -2
  49. package/src/config/apply-user-config.d.ts +6 -0
  50. package/src/config/apply-user-config.js +67 -0
  51. package/src/config/config-builder.d.ts +10 -1
  52. package/src/config/config-builder.js +51 -10
  53. package/src/config/constants.d.ts +4 -0
  54. package/src/config/constants.js +4 -0
  55. package/src/config/define-config.d.ts +9 -0
  56. package/src/config/define-config.js +10 -0
  57. package/src/config/index.d.ts +5 -0
  58. package/src/config/index.js +4 -0
  59. package/src/config/is-finalized-app-config.d.ts +6 -0
  60. package/src/config/is-finalized-app-config.js +11 -0
  61. package/src/config/load-eco-config.d.ts +21 -0
  62. package/src/config/load-eco-config.js +100 -0
  63. package/src/config/resolve-eco-config-path.d.ts +23 -0
  64. package/src/config/resolve-eco-config-path.js +47 -0
  65. package/src/config/server-config-bundle.d.ts +25 -0
  66. package/src/config/server-config-bundle.js +148 -0
  67. package/src/config/user-config-types.d.ts +164 -0
  68. package/src/config/user-config-types.js +1 -0
  69. package/src/css-imports.d.ts +4 -0
  70. package/src/declarations.d.ts +11 -5
  71. package/src/dev/README.md +6 -0
  72. package/src/dev/development-restart-watch-paths.d.ts +13 -0
  73. package/src/dev/development-restart-watch-paths.js +37 -0
  74. package/src/dev/development-restart.d.ts +13 -0
  75. package/src/dev/development-restart.js +21 -0
  76. package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
  77. package/src/dev/transform-server/dev-transform-server.js +16 -5
  78. package/src/eco/README.md +73 -5
  79. package/src/eco/component-identity.d.ts +3 -2
  80. package/src/eco/component-identity.js +5 -2
  81. package/src/eco/discovered-dependencies.d.ts +45 -0
  82. package/src/eco/discovered-dependencies.js +87 -0
  83. package/src/eco/eco.js +6 -0
  84. package/src/eco/eco.types.d.ts +18 -2
  85. package/src/eco/lazy-injector-map.js +57 -41
  86. package/src/eco/page-dependency-contributions.d.ts +19 -0
  87. package/src/eco/page-dependency-contributions.js +52 -0
  88. package/src/errors/http-error-page-contract.d.ts +77 -0
  89. package/src/errors/http-error-page-contract.js +106 -0
  90. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
  91. package/src/hmr/strategies/js-hmr-strategy.js +24 -16
  92. package/src/index.browser.d.ts +3 -0
  93. package/src/index.browser.js +3 -0
  94. package/src/index.d.ts +4 -1
  95. package/src/index.js +4 -1
  96. package/src/islands/README.md +5 -1
  97. package/src/plugins/README.md +8 -1
  98. package/src/plugins/component-import-discovery.d.ts +19 -0
  99. package/src/plugins/component-import-discovery.js +241 -0
  100. package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
  101. package/src/plugins/eco-component-meta-plugin.js +118 -16
  102. package/src/plugins/processor.d.ts +10 -2
  103. package/src/plugins/processor.js +4 -0
  104. package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
  105. package/src/plugins/tsconfig-import-resolver.js +4 -2
  106. package/src/route-renderer/GRAPH.md +1 -1
  107. package/src/route-renderer/README.md +15 -2
  108. package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
  109. package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
  110. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
  111. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
  112. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +80 -0
  113. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
  114. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
  115. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -0
  116. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
  117. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
  118. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
  119. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
  120. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
  121. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
  122. package/src/route-renderer/orchestration/integration-renderer.d.ts +9 -5
  123. package/src/route-renderer/orchestration/integration-renderer.js +42 -29
  124. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
  125. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
  126. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
  127. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
  128. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
  129. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +8 -10
  130. package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
  131. package/src/route-renderer/orchestration/string-markup-renderer.js +2 -1
  132. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
  133. package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
  134. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
  135. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
  136. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
  137. package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
  138. package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
  139. package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
  140. package/src/route-renderer/route-renderer.d.ts +9 -0
  141. package/src/route-renderer/route-renderer.js +18 -0
  142. package/src/router/README.md +7 -1
  143. package/src/router/server/route-registry.d.ts +13 -0
  144. package/src/router/server/route-registry.js +46 -32
  145. package/src/services/README.md +5 -0
  146. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
  147. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
  148. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
  149. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
  150. package/src/services/assets/asset-processing-service/page-package.js +42 -39
  151. package/src/services/error-pages/README.md +9 -0
  152. package/src/services/error-pages/default-error-pages.d.ts +44 -0
  153. package/src/services/error-pages/default-error-pages.js +207 -0
  154. package/src/services/error-pages/error-page-renderer.d.ts +58 -0
  155. package/src/services/error-pages/error-page-renderer.js +146 -0
  156. package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
  157. package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
  158. package/src/services/invalidation/development-invalidation.service.d.ts +7 -1
  159. package/src/services/invalidation/development-invalidation.service.js +35 -3
  160. package/src/services/module-loading/README.md +16 -13
  161. package/src/services/module-loading/app-server-module-transpiler.service.js +2 -0
  162. package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -0
  163. package/src/services/module-loading/collection-server-module-build.service.js +5 -2
  164. package/src/services/module-loading/page-module-import.service.d.ts +8 -0
  165. package/src/services/module-loading/page-module-import.service.js +62 -28
  166. package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
  167. package/src/services/module-loading/view-module-loader.d.ts +10 -0
  168. package/src/services/module-loading/view-module-loader.js +46 -0
  169. package/src/services/validation/schema-validation-service.d.ts +1 -0
  170. package/src/services/validation/schema-validation-service.js +23 -36
  171. package/src/static-site-generator/README.md +6 -1
  172. package/src/static-site-generator/static-site-generator.d.ts +7 -2
  173. package/src/static-site-generator/static-site-generator.js +90 -49
  174. package/src/types/internal-types.d.ts +6 -1
  175. package/src/types/public-types.d.ts +32 -22
  176. package/src/utils/parse-cli-args.js +29 -22
  177. package/src/watchers/project-watcher.d.ts +14 -1
  178. package/src/watchers/project-watcher.js +85 -34
  179. /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
@@ -0,0 +1,87 @@
1
+ const discoveries = new WeakMap();
2
+ const INFERRED_STYLESHEETS = Symbol.for('ecopages.identity.inferredStylesheets');
3
+ const DISCOVERED_WATCH_FILES = Symbol.for('ecopages.identity.watchFiles');
4
+ function discoveryRecord(identity) {
5
+ return identity;
6
+ }
7
+ /**
8
+ * Records discovered Components, inferred styles, and barrel watch hops on identity.
9
+ *
10
+ * @remarks
11
+ * Styles and watch hops are stored on the identity object through interned symbols so
12
+ * a bundled copy of this module still sees them during collection. The component getter
13
+ * stays on a same-isolate WeakMap and is attached to `config.dependencies` at factory time.
14
+ */
15
+ export function registerDiscoveredDependencies(identity, discovered) {
16
+ discoveries.set(identity, discovered);
17
+ const record = discoveryRecord(identity);
18
+ record[INFERRED_STYLESHEETS] = discovered.stylesheets;
19
+ record[DISCOVERED_WATCH_FILES] = discovered.watchFiles;
20
+ }
21
+ /**
22
+ * Inferred stylesheet paths registered for this component identity.
23
+ *
24
+ * @remarks
25
+ * Provenance stays on identity so copying or merging `config.dependencies` cannot
26
+ * turn inferred styles into explicit ones. Paths are stored on the identity object
27
+ * so collection still sees them when server modules bundle a separate copy of `eco`.
28
+ * The collector prefers explicit entries across the whole graph by resolved path.
29
+ */
30
+ export function getInferredStylesheets(config) {
31
+ const identity = config?.identity;
32
+ if (!identity)
33
+ return [];
34
+ return discoveryRecord(identity)[INFERRED_STYLESHEETS] ?? discoveries.get(identity)?.stylesheets ?? [];
35
+ }
36
+ /**
37
+ * Named re-export hops recorded for this component identity.
38
+ *
39
+ * @remarks
40
+ * Barrel files are not Component identity files. Collecting them as watch paths
41
+ * lets a barrel retarget invalidate HTML and Page Browser Graph caches without
42
+ * editing the importing Page.
43
+ */
44
+ export function getDiscoveredWatchFiles(config) {
45
+ const identity = config?.identity;
46
+ if (!identity)
47
+ return [];
48
+ return discoveryRecord(identity)[DISCOVERED_WATCH_FILES] ?? discoveries.get(identity)?.watchFiles ?? [];
49
+ }
50
+ function isDeclared(value) {
51
+ return typeof value === 'function' && Boolean(value.config?.identity);
52
+ }
53
+ /**
54
+ * Attaches deferred discovered Component references to `config.dependencies`.
55
+ *
56
+ * @remarks
57
+ * The component getter reads live import bindings only during graph traversal,
58
+ * after module initialization. Inferred stylesheets stay keyed by identity and are
59
+ * not copied into the public bag, so rendering, SSR preload, ownership, and watch
60
+ * collectors share the same graph without object-identity bookkeeping.
61
+ */
62
+ export function attachDiscoveredDependencies(config) {
63
+ const discovery = config.identity && discoveries.get(config.identity);
64
+ if (!discovery)
65
+ return;
66
+ let explicit = config.dependencies;
67
+ let merged;
68
+ const merge = () => {
69
+ const current = explicit;
70
+ merged = {
71
+ ...current,
72
+ get components() {
73
+ return [...new Set([...(current?.components ?? []), ...discovery.components().filter(isDeclared)])];
74
+ },
75
+ };
76
+ };
77
+ merge();
78
+ Object.defineProperty(config, 'dependencies', {
79
+ enumerable: true,
80
+ configurable: true,
81
+ get: () => merged,
82
+ set: (value) => {
83
+ explicit = value;
84
+ merge();
85
+ },
86
+ });
87
+ }
package/src/eco/eco.js CHANGED
@@ -6,6 +6,7 @@ import { finalizeComponentRender, getComponentRenderContext, interceptForeignChi
6
6
  import { isThenable } from '../route-renderer/orchestration/foreign-child/foreign-child-output.utils.js';
7
7
  import { applyPageLayoutConfig, mergeLayoutDependencies, normalizePageLayouts } from './page-layout-normalization.js';
8
8
  import { getComponentIdentity } from './component-identity.js';
9
+ import { attachDiscoveredDependencies } from './discovered-dependencies.js';
9
10
  /**
10
11
  * Creates a component factory with lazy-trigger support and foreign-child-runtime
11
12
  * interception.
@@ -58,6 +59,7 @@ function createComponentFactory(options) {
58
59
  integration: options.integration,
59
60
  dependencies: options.dependencies,
60
61
  };
62
+ attachDiscoveredDependencies(comp.config);
61
63
  return comp;
62
64
  }
63
65
  /**
@@ -94,6 +96,10 @@ function embed(component, props, children) {
94
96
  }
95
97
  /**
96
98
  * Creates a document shell component.
99
+ *
100
+ * @remarks
101
+ * Pass one generic for the renderable (`eco.html<JsxRenderable>()`,
102
+ * `eco.html<ReactNode>()`). Props are {@link HtmlTemplateProps}.
97
103
  */
98
104
  function html(options) {
99
105
  return createComponentFactory(options);
@@ -64,11 +64,27 @@ export type GetPageDependenciesContext<T = Record<string, unknown>> = {
64
64
  query?: PageQuery;
65
65
  };
66
66
  /**
67
- * Page dependency bag optionally scoped to a declaring file.
67
+ * Explicit dependency declarations owned by one file.
68
+ *
69
+ * @remarks
70
+ * Relative `scripts`, `stylesheets`, and `modules` resolve against `ownerFile`
71
+ * when present. Component entries keep their own identity files. Inferred
72
+ * stylesheets are not stored here; the collector reads them from identity.
68
73
  */
69
- export type PageDependenciesResult = EcoComponentDependencies & {
74
+ export type FileOwnedDependencyContribution = EcoComponentDependencies & {
70
75
  ownerFile?: string;
71
76
  };
77
+ /**
78
+ * Page dependency bag made of one or more file-owned contributions.
79
+ *
80
+ * @remarks
81
+ * A single bag with `ownerFile` is one contribution. `contributions` keeps
82
+ * assets from different files separate until collection, so merging a Page and
83
+ * a content entry cannot re-home relative paths.
84
+ */
85
+ export type PageDependenciesResult = FileOwnedDependencyContribution & {
86
+ contributions?: FileOwnedDependencyContribution[];
87
+ };
72
88
  /**
73
89
  * Resolves request-specific page dependencies for one route render.
74
90
  */
@@ -35,48 +35,51 @@ function dedupeCsvValues(values) {
35
35
  }
36
36
  return Array.from(seen).join(',');
37
37
  }
38
- /**
39
- * Builds a scripts-injector map config from resolved lazy script groups.
40
- *
41
- * @param lazyGroups Lazy script groups resolved during dependency processing.
42
- * @returns Injector map config keyed by lazy trigger.
43
- */
44
- function buildInjectorMap(lazyGroups) {
45
- const map = {};
46
- for (const group of lazyGroups) {
47
- const scripts = normalizeScripts(group.scripts);
48
- const lazy = group.lazy;
49
- if ('on:idle' in lazy) {
50
- map['on:idle'] = {
51
- scripts: [...(map['on:idle']?.scripts ?? []), ...scripts],
52
- };
53
- continue;
54
- }
55
- if ('on:interaction' in lazy) {
56
- const currentValue = map['on:interaction']?.value;
57
- const nextValue = lazy['on:interaction'];
58
- map['on:interaction'] = {
59
- value: typeof currentValue === 'string' ? dedupeCsvValues([currentValue, nextValue]) : nextValue,
60
- scripts: [...(map['on:interaction']?.scripts ?? []), ...scripts],
61
- };
62
- continue;
63
- }
64
- if ('on:visible' in lazy) {
65
- const currentValue = map['on:visible']?.value;
66
- const currentThreshold = typeof currentValue === 'string' ? currentValue : undefined;
67
- const nextValue = lazy['on:visible'];
68
- map['on:visible'] = {
69
- ...(nextValue === true
70
- ? currentThreshold
71
- ? { value: currentThreshold }
72
- : {}
73
- : { value: String(nextValue) }),
74
- scripts: [...(map['on:visible']?.scripts ?? []), ...scripts],
75
- };
76
- continue;
77
- }
78
- throw new Error(`Invalid lazy options: must specify on:idle, on:interaction, or on:visible. Received: ${JSON.stringify(lazy)}`);
38
+ function mergeInjectorScripts(map, key, scripts) {
39
+ const entry = map[key];
40
+ map[key] = {
41
+ ...entry,
42
+ scripts: [...(entry?.scripts ?? []), ...scripts],
43
+ };
44
+ }
45
+ function applyIdleLazyTrigger(map, scripts) {
46
+ mergeInjectorScripts(map, 'on:idle', scripts);
47
+ }
48
+ function applyInteractionLazyTrigger(map, lazy, scripts) {
49
+ const currentValue = map['on:interaction']?.value;
50
+ const nextValue = lazy['on:interaction'];
51
+ map['on:interaction'] = {
52
+ value: typeof currentValue === 'string' ? dedupeCsvValues([currentValue, nextValue]) : nextValue,
53
+ scripts: [...(map['on:interaction']?.scripts ?? []), ...scripts],
54
+ };
55
+ }
56
+ function applyVisibleLazyTrigger(map, lazy, scripts) {
57
+ const currentValue = map['on:visible']?.value;
58
+ const currentThreshold = typeof currentValue === 'string' ? currentValue : undefined;
59
+ const nextValue = lazy['on:visible'];
60
+ map['on:visible'] = {
61
+ ...(nextValue === true ? (currentThreshold ? { value: currentThreshold } : {}) : { value: String(nextValue) }),
62
+ scripts: [...(map['on:visible']?.scripts ?? []), ...scripts],
63
+ };
64
+ }
65
+ function applyLazyGroupToInjectorMap(map, group) {
66
+ const scripts = normalizeScripts(group.scripts);
67
+ const lazy = group.lazy;
68
+ if ('on:idle' in lazy) {
69
+ applyIdleLazyTrigger(map, scripts);
70
+ return;
71
+ }
72
+ if ('on:interaction' in lazy) {
73
+ applyInteractionLazyTrigger(map, lazy, scripts);
74
+ return;
75
+ }
76
+ if ('on:visible' in lazy) {
77
+ applyVisibleLazyTrigger(map, lazy, scripts);
78
+ return;
79
79
  }
80
+ throw new Error(`Invalid lazy options: must specify on:idle, on:interaction, or on:visible. Received: ${JSON.stringify(lazy)}`);
81
+ }
82
+ function dedupeInjectorMapScripts(map) {
80
83
  for (const key of Object.keys(map)) {
81
84
  const scripts = map[key]?.scripts;
82
85
  if (scripts) {
@@ -86,6 +89,19 @@ function buildInjectorMap(lazyGroups) {
86
89
  };
87
90
  }
88
91
  }
92
+ }
93
+ /**
94
+ * Builds a scripts-injector map config from resolved lazy script groups.
95
+ *
96
+ * @param lazyGroups Lazy script groups resolved during dependency processing.
97
+ * @returns Injector map config keyed by lazy trigger.
98
+ */
99
+ function buildInjectorMap(lazyGroups) {
100
+ const map = {};
101
+ for (const group of lazyGroups) {
102
+ applyLazyGroupToInjectorMap(map, group);
103
+ }
104
+ dedupeInjectorMapScripts(map);
89
105
  return map;
90
106
  }
91
107
  /**
@@ -0,0 +1,19 @@
1
+ import type { EcoComponentDependencies, FileOwnedDependencyContribution, PageDependenciesResult } from '../types/public-types.js';
2
+ /**
3
+ * Expands a page dependency result into file-owned contributions.
4
+ *
5
+ * @remarks
6
+ * Nested `contributions` are expanded so collection can resolve each bag against
7
+ * its own owner. Empty bags are omitted.
8
+ */
9
+ export declare function listFileOwnedDependencyContributions(value: PageDependenciesResult | EcoComponentDependencies | undefined): FileOwnedDependencyContribution[];
10
+ /**
11
+ * Merges base page dependencies with additional dependencies (such as those returned by a content entry).
12
+ *
13
+ * @remarks
14
+ * Keeps each file-owned contribution intact, including `modules`. Relative assets
15
+ * are not flattened under a single `ownerFile`, so a Page's `./page.css` cannot
16
+ * resolve against a content entry directory. Object-spread of two bags copies
17
+ * `ownerFile` onto the other side's relative paths; use this helper instead.
18
+ */
19
+ export declare function mergePageDependencies(base: EcoComponentDependencies | undefined, additional: PageDependenciesResult | EcoComponentDependencies | undefined): PageDependenciesResult | undefined;
@@ -0,0 +1,52 @@
1
+ function hasCollectableDependencyFields(dependencies) {
2
+ return Boolean(dependencies.stylesheets?.length ||
3
+ dependencies.scripts?.length ||
4
+ dependencies.modules?.length ||
5
+ dependencies.components?.length);
6
+ }
7
+ /**
8
+ * Expands a page dependency result into file-owned contributions.
9
+ *
10
+ * @remarks
11
+ * Nested `contributions` are expanded so collection can resolve each bag against
12
+ * its own owner. Empty bags are omitted.
13
+ */
14
+ export function listFileOwnedDependencyContributions(value) {
15
+ if (!value)
16
+ return [];
17
+ const result = value;
18
+ const nested = result.contributions ?? [];
19
+ const { contributions: _contributions, ownerFile, ...dependencies } = result;
20
+ const listed = [];
21
+ if (hasCollectableDependencyFields(dependencies)) {
22
+ listed.push(ownerFile ? { ...dependencies, ownerFile } : dependencies);
23
+ }
24
+ for (const contribution of nested) {
25
+ listed.push(...listFileOwnedDependencyContributions(contribution));
26
+ }
27
+ return listed;
28
+ }
29
+ /**
30
+ * Merges base page dependencies with additional dependencies (such as those returned by a content entry).
31
+ *
32
+ * @remarks
33
+ * Keeps each file-owned contribution intact, including `modules`. Relative assets
34
+ * are not flattened under a single `ownerFile`, so a Page's `./page.css` cannot
35
+ * resolve against a content entry directory. Object-spread of two bags copies
36
+ * `ownerFile` onto the other side's relative paths; use this helper instead.
37
+ */
38
+ export function mergePageDependencies(base, additional) {
39
+ if (!base)
40
+ return additional;
41
+ if (!additional)
42
+ return base;
43
+ const contributions = [
44
+ ...listFileOwnedDependencyContributions(base),
45
+ ...listFileOwnedDependencyContributions(additional),
46
+ ];
47
+ if (contributions.length === 0)
48
+ return undefined;
49
+ if (contributions.length === 1)
50
+ return contributions[0];
51
+ return { contributions };
52
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * HTTP statuses that own a semantic HTML error page (`pages/{status}.*` and
3
+ * matching `app.*()` loaders).
4
+ */
5
+ export declare const HTTP_ERROR_PAGE_STATUSES: readonly [400, 401, 403, 404, 409, 500];
6
+ export type HttpErrorPageStatus = (typeof HTTP_ERROR_PAGE_STATUSES)[number];
7
+ export type ErrorPageKind = 'badRequest' | 'unauthorized' | 'forbidden' | 'notFound' | 'conflict' | 'serverError';
8
+ export declare const ERROR_PAGE_KIND_BY_STATUS: {
9
+ readonly 400: "badRequest";
10
+ readonly 401: "unauthorized";
11
+ readonly 403: "forbidden";
12
+ readonly 404: "notFound";
13
+ readonly 409: "conflict";
14
+ readonly 500: "serverError";
15
+ };
16
+ export declare const ERROR_PAGE_STATUS_BY_KIND: {
17
+ readonly badRequest: 400;
18
+ readonly unauthorized: 401;
19
+ readonly forbidden: 403;
20
+ readonly notFound: 404;
21
+ readonly conflict: 409;
22
+ readonly serverError: 500;
23
+ };
24
+ export declare const SEMANTIC_ERROR_PAGE_PATHNAMES: readonly `/${HttpErrorPageStatus}`[];
25
+ /**
26
+ * Built-in copy and CSS modifier suffix for each semantic HTML error page.
27
+ */
28
+ export declare const ERROR_PAGE_COPY: {
29
+ readonly 400: {
30
+ readonly title: "Bad Request";
31
+ readonly message: "The request could not be understood.";
32
+ readonly modifier: "bad-request";
33
+ };
34
+ readonly 401: {
35
+ readonly title: "Unauthorized";
36
+ readonly message: "Authentication is required to access this page.";
37
+ readonly modifier: "unauthorized";
38
+ };
39
+ readonly 403: {
40
+ readonly title: "Forbidden";
41
+ readonly message: "You do not have permission to access this page.";
42
+ readonly modifier: "forbidden";
43
+ };
44
+ readonly 404: {
45
+ readonly title: "Not Found";
46
+ readonly message: "The page you requested could not be found.";
47
+ readonly modifier: "not-found";
48
+ };
49
+ readonly 409: {
50
+ readonly title: "Conflict";
51
+ readonly message: "The request could not be completed due to a conflict.";
52
+ readonly modifier: "conflict";
53
+ };
54
+ readonly 500: {
55
+ readonly title: "Something went wrong";
56
+ readonly message: "An error occurred while handling this request.";
57
+ readonly modifier: "server-error";
58
+ };
59
+ };
60
+ export type PageFailureClassification = {
61
+ status: number;
62
+ kind: ErrorPageKind | undefined;
63
+ logAsServerError: boolean;
64
+ };
65
+ export declare function isHttpErrorPageStatus(status: number): status is HttpErrorPageStatus;
66
+ export declare function isHttpErrorStatus(status: number): boolean;
67
+ /**
68
+ * Resolves the semantic page kind for an HTTP status.
69
+ *
70
+ * @remarks
71
+ * Factory statuses map 1:1. Other 5xx statuses reuse the server-error page
72
+ * with the original status. Other 4xx statuses have no custom page and use a
73
+ * built-in document.
74
+ */
75
+ export declare function kindForStatus(status: number): ErrorPageKind | undefined;
76
+ export declare function classifyPageFailure(error: unknown): PageFailureClassification;
77
+ export declare function shouldLogPageFailure(error: unknown): boolean;
@@ -0,0 +1,106 @@
1
+ import { HttpError } from './http-error.js';
2
+ /**
3
+ * HTTP statuses that own a semantic HTML error page (`pages/{status}.*` and
4
+ * matching `app.*()` loaders).
5
+ */
6
+ export const HTTP_ERROR_PAGE_STATUSES = [400, 401, 403, 404, 409, 500];
7
+ export const ERROR_PAGE_KIND_BY_STATUS = {
8
+ 400: 'badRequest',
9
+ 401: 'unauthorized',
10
+ 403: 'forbidden',
11
+ 404: 'notFound',
12
+ 409: 'conflict',
13
+ 500: 'serverError',
14
+ };
15
+ export const ERROR_PAGE_STATUS_BY_KIND = {
16
+ badRequest: 400,
17
+ unauthorized: 401,
18
+ forbidden: 403,
19
+ notFound: 404,
20
+ conflict: 409,
21
+ serverError: 500,
22
+ };
23
+ export const SEMANTIC_ERROR_PAGE_PATHNAMES = HTTP_ERROR_PAGE_STATUSES.map((status) => `/${status}`);
24
+ /**
25
+ * Built-in copy and CSS modifier suffix for each semantic HTML error page.
26
+ */
27
+ export const ERROR_PAGE_COPY = {
28
+ 400: {
29
+ title: 'Bad Request',
30
+ message: 'The request could not be understood.',
31
+ modifier: 'bad-request',
32
+ },
33
+ 401: {
34
+ title: 'Unauthorized',
35
+ message: 'Authentication is required to access this page.',
36
+ modifier: 'unauthorized',
37
+ },
38
+ 403: {
39
+ title: 'Forbidden',
40
+ message: 'You do not have permission to access this page.',
41
+ modifier: 'forbidden',
42
+ },
43
+ 404: {
44
+ title: 'Not Found',
45
+ message: 'The page you requested could not be found.',
46
+ modifier: 'not-found',
47
+ },
48
+ 409: {
49
+ title: 'Conflict',
50
+ message: 'The request could not be completed due to a conflict.',
51
+ modifier: 'conflict',
52
+ },
53
+ 500: {
54
+ title: 'Something went wrong',
55
+ message: 'An error occurred while handling this request.',
56
+ modifier: 'server-error',
57
+ },
58
+ };
59
+ export function isHttpErrorPageStatus(status) {
60
+ return HTTP_ERROR_PAGE_STATUSES.includes(status);
61
+ }
62
+ export function isHttpErrorStatus(status) {
63
+ return Number.isInteger(status) && status >= 400 && status <= 599;
64
+ }
65
+ /**
66
+ * Resolves the semantic page kind for an HTTP status.
67
+ *
68
+ * @remarks
69
+ * Factory statuses map 1:1. Other 5xx statuses reuse the server-error page
70
+ * with the original status. Other 4xx statuses have no custom page and use a
71
+ * built-in document.
72
+ */
73
+ export function kindForStatus(status) {
74
+ if (isHttpErrorPageStatus(status)) {
75
+ return ERROR_PAGE_KIND_BY_STATUS[status];
76
+ }
77
+ if (status >= 500 && status <= 599) {
78
+ return 'serverError';
79
+ }
80
+ return undefined;
81
+ }
82
+ export function classifyPageFailure(error) {
83
+ if (error instanceof Response) {
84
+ return {
85
+ status: error.status,
86
+ kind: kindForStatus(error.status),
87
+ logAsServerError: error.status >= 500,
88
+ };
89
+ }
90
+ if (HttpError.isHttpError(error)) {
91
+ const status = isHttpErrorStatus(error.status) ? error.status : 500;
92
+ return {
93
+ status,
94
+ kind: kindForStatus(status),
95
+ logAsServerError: status >= 500,
96
+ };
97
+ }
98
+ return {
99
+ status: 500,
100
+ kind: 'serverError',
101
+ logAsServerError: true,
102
+ };
103
+ }
104
+ export function shouldLogPageFailure(error) {
105
+ return classifyPageFailure(error).logAsServerError;
106
+ }
@@ -39,5 +39,7 @@ export declare class JsHmrStrategy extends HmrStrategy {
39
39
  private context;
40
40
  constructor(context: JsHmrContext);
41
41
  matches(filePath: string): boolean;
42
+ private resolveImpactedEntrypoints;
43
+ private collectDevTransformHmrOutcome;
42
44
  process(filePath: string): Promise<HmrAction>;
43
45
  }
@@ -45,16 +45,7 @@ export class JsHmrStrategy extends HmrStrategy {
45
45
  }
46
46
  return true;
47
47
  }
48
- async process(filePath) {
49
- appLogger.debug(`[JsHmrStrategy] Processing ${filePath}`);
50
- const watchedFiles = this.context.getWatchedFiles();
51
- const resolvedChanged = path.resolve(filePath);
52
- const registeredEntrypoints = this.context.getRegisteredEntrypoints();
53
- const isRegisteredEntrypointEdit = isRegisteredDevTransformEntrypoint(registeredEntrypoints, resolvedChanged);
54
- if (watchedFiles.size === 0) {
55
- appLogger.debug(`[JsHmrStrategy] No watched files to rebuild`);
56
- return { type: 'none' };
57
- }
48
+ resolveImpactedEntrypoints(filePath, watchedFiles, resolvedChanged, isRegisteredEntrypointEdit) {
58
49
  const dependencyHits = this.context.getEntrypointDependencyGraph().getDependencyEntrypoints(filePath);
59
50
  const hasDependencyHit = dependencyHits.size > 0;
60
51
  const impactedEntrypoints = isRegisteredEntrypointEdit
@@ -63,12 +54,9 @@ export class JsHmrStrategy extends HmrStrategy {
63
54
  ? Array.from(dependencyHits).filter((entrypoint) => watchedFiles.has(path.resolve(entrypoint)))
64
55
  : Array.from(watchedFiles.keys());
65
56
  const buildableEntrypoints = impactedEntrypoints.filter((entrypoint) => this.context.shouldProcessEntrypoint?.(entrypoint) ?? true);
66
- if (!hasDependencyHit && !isRegisteredEntrypointEdit) {
67
- appLogger.debug('[JsHmrStrategy] Dependency graph miss, rebuilding all watched entrypoints');
68
- }
69
- if (buildableEntrypoints.length === 0) {
70
- return { type: 'none' };
71
- }
57
+ return { buildableEntrypoints, hasDependencyHit };
58
+ }
59
+ collectDevTransformHmrOutcome(buildableEntrypoints, watchedFiles, registeredEntrypoints) {
72
60
  const devTransformUpdates = [];
73
61
  let devTransformReloadRequired = false;
74
62
  for (const entrypoint of buildableEntrypoints) {
@@ -91,6 +79,26 @@ export class JsHmrStrategy extends HmrStrategy {
91
79
  devTransformUpdates.push(outputUrl);
92
80
  }
93
81
  }
82
+ return { devTransformUpdates, devTransformReloadRequired };
83
+ }
84
+ async process(filePath) {
85
+ appLogger.debug(`[JsHmrStrategy] Processing ${filePath}`);
86
+ const watchedFiles = this.context.getWatchedFiles();
87
+ const resolvedChanged = path.resolve(filePath);
88
+ const registeredEntrypoints = this.context.getRegisteredEntrypoints();
89
+ const isRegisteredEntrypointEdit = isRegisteredDevTransformEntrypoint(registeredEntrypoints, resolvedChanged);
90
+ if (watchedFiles.size === 0) {
91
+ appLogger.debug(`[JsHmrStrategy] No watched files to rebuild`);
92
+ return { type: 'none' };
93
+ }
94
+ const { buildableEntrypoints, hasDependencyHit } = this.resolveImpactedEntrypoints(filePath, watchedFiles, resolvedChanged, isRegisteredEntrypointEdit);
95
+ if (!hasDependencyHit && !isRegisteredEntrypointEdit) {
96
+ appLogger.debug('[JsHmrStrategy] Dependency graph miss, rebuilding all watched entrypoints');
97
+ }
98
+ if (buildableEntrypoints.length === 0) {
99
+ return { type: 'none' };
100
+ }
101
+ const { devTransformUpdates, devTransformReloadRequired } = this.collectDevTransformHmrOutcome(buildableEntrypoints, watchedFiles, registeredEntrypoints);
94
102
  if (devTransformReloadRequired) {
95
103
  appLogger.debug(`[JsHmrStrategy] Full reload required (no HMR accept found)`);
96
104
  return {
@@ -2,3 +2,6 @@ export type * from './types/public-types.js';
2
2
  export type * from './eco/eco.types.js';
3
3
  export { eco } from './eco/eco.browser.js';
4
4
  export { bindComponentIdentity, getComponentIdentity, type ComponentIdentity } from './eco/component-identity.js';
5
+ export { attachDiscoveredDependencies } from './eco/discovered-dependencies.js';
6
+ export { listFileOwnedDependencyContributions, mergePageDependencies } from './eco/page-dependency-contributions.js';
7
+ export { mergeLayoutDependencies } from './eco/page-layout-normalization.js';
@@ -1,2 +1,5 @@
1
1
  export { eco } from './eco/eco.browser.js';
2
2
  export { bindComponentIdentity, getComponentIdentity } from './eco/component-identity.js';
3
+ export { attachDiscoveredDependencies } from './eco/discovered-dependencies.js';
4
+ export { listFileOwnedDependencyContributions, mergePageDependencies } from './eco/page-dependency-contributions.js';
5
+ export { mergeLayoutDependencies } from './eco/page-layout-normalization.js';
package/src/index.d.ts CHANGED
@@ -3,7 +3,10 @@ export type * from './eco/eco.types.js';
3
3
  export { eco } from './eco/eco.js';
4
4
  export { defineApiHandler, defineGroupHandler, defineGet, definePost, definePut, defineDelete, definePatch, defineOptions, defineHead, json, html, redirect, type GroupHandler, } from './adapters/shared/http/define-api-handler.js';
5
5
  export { createEcoBuildPluginFromSourceTransform, createVitePluginsFromAppSourceTransforms, getAppSourceTransforms, createVitePluginFromSourceTransform, normalizeTransformId, type EcoSourceTransform, type EcoSourceTransformResult, type EcoViteCompatiblePlugin, } from './plugins/source-transform.js';
6
- export { createEcoComponentMetaTransform } from './plugins/eco-component-meta-plugin.js';
6
+ export { attributeComponentIdentity, attributeMdxComponentIdentity, createEcoComponentMetaTransform, } from './plugins/eco-component-meta-plugin.js';
7
7
  export { bindComponentIdentity, getComponentIdentity, type ComponentIdentity } from './eco/component-identity.js';
8
+ export { attachDiscoveredDependencies, registerDiscoveredDependencies, getInferredStylesheets, type DiscoveredDependencies, } from './eco/discovered-dependencies.js';
9
+ export { listFileOwnedDependencyContributions, mergePageDependencies } from './eco/page-dependency-contributions.js';
10
+ export { mergeLayoutDependencies } from './eco/page-layout-normalization.js';
8
11
  export { SchemaError, validateStandardSchema } from './services/validation/validate-standard-schema.js';
9
12
  export { buildIslandHostAttributes, ECO_ISLAND_HOST_ATTRIBUTE, ECO_ISLAND_INTEGRATION_ATTRIBUTE, finalizeIslandComponentRender, isIslandHostElement, mergeIslandHostAttributes, } from './islands/island-host.js';
package/src/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  export { eco } from './eco/eco.js';
2
2
  export { defineApiHandler, defineGroupHandler, defineGet, definePost, definePut, defineDelete, definePatch, defineOptions, defineHead, json, html, redirect, } from './adapters/shared/http/define-api-handler.js';
3
3
  export { createEcoBuildPluginFromSourceTransform, createVitePluginsFromAppSourceTransforms, getAppSourceTransforms, createVitePluginFromSourceTransform, normalizeTransformId, } from './plugins/source-transform.js';
4
- export { createEcoComponentMetaTransform } from './plugins/eco-component-meta-plugin.js';
4
+ export { attributeComponentIdentity, attributeMdxComponentIdentity, createEcoComponentMetaTransform, } from './plugins/eco-component-meta-plugin.js';
5
5
  export { bindComponentIdentity, getComponentIdentity } from './eco/component-identity.js';
6
+ export { attachDiscoveredDependencies, registerDiscoveredDependencies, getInferredStylesheets, } from './eco/discovered-dependencies.js';
7
+ export { listFileOwnedDependencyContributions, mergePageDependencies } from './eco/page-dependency-contributions.js';
8
+ export { mergeLayoutDependencies } from './eco/page-layout-normalization.js';
6
9
  export { SchemaError, validateStandardSchema } from './services/validation/validate-standard-schema.js';
7
10
  export { buildIslandHostAttributes, ECO_ISLAND_HOST_ATTRIBUTE, ECO_ISLAND_INTEGRATION_ATTRIBUTE, finalizeIslandComponentRender, isIslandHostElement, mergeIslandHostAttributes, } from './islands/island-host.js';
@@ -12,7 +12,11 @@ Hydratable component instances stamp a small, integration-agnostic attribute set
12
12
  | `data-eco-component-key` | Optional module key used by client hydration (React) |
13
13
  | `data-eco-props` | Optional base64 JSON props snapshot for hydration |
14
14
 
15
- React may still replace the SSR host with `<eco-island>` after hydration; the marker is applied at SSR time on the component root.
15
+ React integrations may emit `<eco-island>` as the SSR host. The host uses
16
+ `display: contents` so it does not introduce a layout box, while the host and
17
+ its children remain in place as the client calls `hydrateRoot()` on that host.
18
+ React island integrations may add `data-eco-hydrated` after the initial client
19
+ commit for development diagnostics.
16
20
 
17
21
  ## Where stamping happens
18
22