@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
@@ -1,101 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import { activatePreparedNavigationScripts, prepareNavigationHead } from './navigation-pipeline.js';
3
- import { stageStylesheets } from './staged-stylesheets.test-fixtures.js';
4
- function parseDocument(html) {
5
- return new DOMParser().parseFromString(html, 'text/html');
6
- }
7
- afterEach(() => {
8
- document.head.replaceChildren();
9
- vi.restoreAllMocks();
10
- });
11
- describe('shared navigation head updates', () => {
12
- it('updates metadata, waits for incoming stylesheets, removes stale stylesheets, and preserves stable elements', async () => {
13
- document.head.innerHTML = [
14
- '<meta charset="utf-8">',
15
- '<meta name="description" content="Old description">',
16
- '<meta name="theme-color" content="persisted" data-eco-persist>',
17
- '<link rel="stylesheet" href="/old.css">',
18
- ].join('');
19
- const incoming = parseDocument('<html><head><title>Next</title><meta name="description" content="New description"><meta name="keywords" content="navigation"><link rel="stylesheet" href="/new.css"></head><body></body></html>');
20
- const staged = stageStylesheets();
21
- const update = await prepareNavigationHead(incoming);
22
- staged.stop();
23
- expect(staged.links.map((link) => link.href)).toEqual([new URL('/new.css', window.location.origin).href]);
24
- update.commit();
25
- expect(document.title).toBe('Next');
26
- expect(document.head.querySelector('meta[name="description"]')?.getAttribute('content')).toBe('New description');
27
- expect(document.head.querySelector('meta[name="keywords"]')?.getAttribute('content')).toBe('navigation');
28
- expect(document.head.querySelector('meta[charset]')).not.toBeNull();
29
- expect(document.head.querySelector('meta[name="theme-color"]')?.getAttribute('content')).toBe('persisted');
30
- expect(document.head.querySelector('link[href$="old.css"]')).toBeNull();
31
- expect(document.head.querySelectorAll('link[href$="new.css"]')).toHaveLength(1);
32
- expect(document.head.querySelector('link[href$="new.css"]')).not.toBeNull();
33
- });
34
- it('cancels preloaded stylesheets when a navigation becomes stale', async () => {
35
- document.head.innerHTML = '<link rel="stylesheet" href="/current.css">';
36
- const incoming = parseDocument('<html><head><link rel="stylesheet" href="/stale.css"></head><body></body></html>');
37
- const staged = stageStylesheets();
38
- const update = await prepareNavigationHead(incoming);
39
- staged.stop();
40
- update.cancel();
41
- expect(staged.links).toHaveLength(1);
42
- expect(staged.links[0]?.isConnected).toBe(false);
43
- expect(document.head.querySelector('link[href$="current.css"]')).not.toBeNull();
44
- expect(document.head.querySelector('link[href$="stale.css"]')).toBeNull();
45
- });
46
- it('settles a stylesheet wait when a newer navigation removes its staged link', async () => {
47
- const staleNavigation = parseDocument('<html><head><link rel="stylesheet" href="https://example.invalid/stale-navigation.css"></head><body></body></html>');
48
- const currentNavigation = parseDocument('<html><head></head><body></body></html>');
49
- const staleUpdatePromise = prepareNavigationHead(staleNavigation);
50
- const stagedStylesheet = document.head.querySelector('link[href$="stale-navigation.css"]');
51
- expect(stagedStylesheet).not.toBeNull();
52
- let staleUpdateReady = false;
53
- const staleUpdateSettled = staleUpdatePromise.then((update) => {
54
- staleUpdateReady = true;
55
- update.cancel();
56
- });
57
- const currentUpdate = await prepareNavigationHead(currentNavigation);
58
- currentUpdate.commit();
59
- try {
60
- await vi.waitFor(() => expect(staleUpdateReady).toBe(true), { interval: 1 });
61
- expect(stagedStylesheet?.isConnected).toBe(false);
62
- }
63
- finally {
64
- stagedStylesheet?.dispatchEvent(new Event('error'));
65
- await staleUpdateSettled;
66
- }
67
- });
68
- it('keeps a shared staged stylesheet until every overlapping navigation is settled', async () => {
69
- const incoming = parseDocument('<html><head><link rel="stylesheet" href="/shared.css"></head><body></body></html>');
70
- const firstUpdatePromise = prepareNavigationHead(incoming);
71
- await vi.waitFor(() => expect(document.head.querySelector('link[href$="shared.css"]')).not.toBeNull());
72
- const secondUpdatePromise = prepareNavigationHead(incoming);
73
- let secondUpdateReady = false;
74
- void secondUpdatePromise.then(() => {
75
- secondUpdateReady = true;
76
- });
77
- await Promise.resolve();
78
- expect(secondUpdateReady).toBe(false);
79
- document.head.querySelector('link[href$="shared.css"]')?.dispatchEvent(new Event('load'));
80
- const [firstUpdate, secondUpdate] = await Promise.all([firstUpdatePromise, secondUpdatePromise]);
81
- firstUpdate.cancel();
82
- secondUpdate.commit();
83
- expect(document.head.querySelectorAll('link[href$="shared.css"]')).toHaveLength(1);
84
- expect(document.head.querySelector('link[href$="shared.css"]')?.isConnected).toBe(true);
85
- });
86
- it('shares script identity, skips router-specific bootstrap scripts, and activates fresh head scripts once', async () => {
87
- document.head.innerHTML = '<script id="page-data" type="application/json">{"route":"old"}</script>';
88
- const incoming = parseDocument('<html><head><script id="page-data" type="application/json">{"route":"new"}</script><script id="route-module" type="module" src="/route.js"></script><script src="/assets/ecopages-react-123.js" type="module"></script><script type="module" data-eco-rerun data-eco-script-id="ecopages-react-456">window.__ECO_PAGES__={page:{}}</script></head><body></body></html>');
89
- const update = await prepareNavigationHead(incoming, undefined, (script) => {
90
- const scriptId = script.getAttribute('data-eco-script-id');
91
- const src = script.getAttribute('src');
92
- return Boolean(scriptId?.startsWith('ecopages-react-') || src?.includes('ecopages-react-'));
93
- });
94
- update.commit();
95
- activatePreparedNavigationScripts(update, undefined, false);
96
- expect(document.head.querySelector('#page-data')?.textContent).toBe('{"route":"new"}');
97
- expect(document.head.querySelectorAll('script#route-module')).toHaveLength(1);
98
- expect(document.head.querySelector('script[src*="ecopages-react-"]')).toBeNull();
99
- expect(update.rerunScriptActivations).toHaveLength(0);
100
- });
101
- });
@@ -1,97 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- import { completeNavigationLifecycle, dispatchBeforeSwap, ECO_NAVIGATION_LIFECYCLE_EVENTS, } from './navigation-lifecycle.js';
3
- describe('navigation lifecycle dispatch', () => {
4
- it('dispatches before-swap with newDocument and reload hook', () => {
5
- const beforeSwapSpy = vi.fn();
6
- document.addEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.BEFORE_SWAP, beforeSwapSpy);
7
- try {
8
- const newDocument = new DOMParser().parseFromString('<html><body>Next</body></html>', 'text/html');
9
- const url = new URL('https://example.test/next');
10
- const { requestedReload } = dispatchBeforeSwap(document, {
11
- url,
12
- direction: 'forward',
13
- newDocument,
14
- });
15
- expect(requestedReload).toBe(false);
16
- expect(beforeSwapSpy).toHaveBeenCalledTimes(1);
17
- const detail = beforeSwapSpy.mock.calls[0][0].detail;
18
- expect(detail.url).toBe(url);
19
- expect(detail.direction).toBe('forward');
20
- expect(detail.newDocument).toBe(newDocument);
21
- expect(typeof detail.reload).toBe('function');
22
- }
23
- finally {
24
- document.removeEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.BEFORE_SWAP, beforeSwapSpy);
25
- }
26
- });
27
- it('reports reload requests from before-swap listeners', () => {
28
- const beforeSwapSpy = vi.fn((event) => {
29
- event.detail.reload();
30
- });
31
- document.addEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.BEFORE_SWAP, beforeSwapSpy);
32
- try {
33
- const { requestedReload } = dispatchBeforeSwap(document, {
34
- url: new URL('https://example.test/reload'),
35
- direction: 'forward',
36
- newDocument: document,
37
- });
38
- expect(requestedReload).toBe(true);
39
- }
40
- finally {
41
- document.removeEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.BEFORE_SWAP, beforeSwapSpy);
42
- }
43
- });
44
- it('dispatches after-swap with url and direction', () => {
45
- const afterSwapSpy = vi.fn();
46
- document.addEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.AFTER_SWAP, afterSwapSpy);
47
- try {
48
- const url = new URL('https://example.test/after');
49
- completeNavigationLifecycle(document, { url, direction: 'replace' }, { schedule: () => 1 });
50
- expect(afterSwapSpy).toHaveBeenCalledTimes(1);
51
- const detail = afterSwapSpy.mock.calls[0][0].detail;
52
- expect(detail.url).toBe(url);
53
- expect(detail.direction).toBe('replace');
54
- }
55
- finally {
56
- document.removeEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.AFTER_SWAP, afterSwapSpy);
57
- }
58
- });
59
- it('schedules page-load on the next animation frame', () => {
60
- const pageLoadSpy = vi.fn();
61
- const scheduleSpy = vi.fn((callback) => {
62
- callback(0);
63
- return 1;
64
- });
65
- document.addEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.PAGE_LOAD, pageLoadSpy);
66
- try {
67
- const url = new URL('https://example.test/page-load');
68
- completeNavigationLifecycle(document, { url, direction: 'forward' }, { schedule: scheduleSpy });
69
- expect(scheduleSpy).toHaveBeenCalledTimes(1);
70
- expect(pageLoadSpy).toHaveBeenCalledTimes(1);
71
- const detail = pageLoadSpy.mock.calls[0][0].detail;
72
- expect(detail.url).toBe(url);
73
- expect(detail.direction).toBe('forward');
74
- }
75
- finally {
76
- document.removeEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.PAGE_LOAD, pageLoadSpy);
77
- }
78
- });
79
- it('skips page-load when navigation becomes stale before the frame callback', () => {
80
- const pageLoadSpy = vi.fn();
81
- let stale = true;
82
- document.addEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.PAGE_LOAD, pageLoadSpy);
83
- try {
84
- completeNavigationLifecycle(document, { url: new URL('https://example.test/stale'), direction: 'forward' }, {
85
- isStale: () => stale,
86
- schedule: (callback) => {
87
- callback(0);
88
- return 1;
89
- },
90
- });
91
- expect(pageLoadSpy).not.toHaveBeenCalled();
92
- }
93
- finally {
94
- document.removeEventListener(ECO_NAVIGATION_LIFECYCLE_EVENTS.PAGE_LOAD, pageLoadSpy);
95
- }
96
- });
97
- });
@@ -1,189 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import { applyViewTransitionNames } from '../../client/view-transitions.js';
3
- import { runNavigationViewTransition } from './navigation-view-transition.js';
4
- const ROOT_STYLES_ID = 'eco-vt-root-styles';
5
- /**
6
- * Installs a `startViewTransition` that runs the update on a microtask and reports the outcome
7
- * the test hands it.
8
- */
9
- function installStartViewTransition(outcome) {
10
- const startViewTransition = vi.fn((callback) => ({
11
- ...outcome,
12
- updateCallbackDone: Promise.resolve().then(async () => {
13
- await callback();
14
- }),
15
- skipTransition() { },
16
- }));
17
- Reflect.set(document, 'startViewTransition', startViewTransition);
18
- return startViewTransition;
19
- }
20
- function installPendingViewTransitions() {
21
- const finishTransitions = [];
22
- const startViewTransition = vi.fn((callback) => {
23
- const finished = new Promise((resolve) => {
24
- finishTransitions.push(resolve);
25
- });
26
- return {
27
- finished,
28
- ready: Promise.resolve(),
29
- updateCallbackDone: Promise.resolve().then(async () => callback()),
30
- skipTransition() { },
31
- };
32
- });
33
- Reflect.set(document, 'startViewTransition', startViewTransition);
34
- return {
35
- finishTransition(index = 0) {
36
- const finish = finishTransitions[index];
37
- if (!finish)
38
- throw new Error(`No view transition at index ${index}`);
39
- finish();
40
- },
41
- startViewTransition,
42
- };
43
- }
44
- afterEach(() => {
45
- Reflect.deleteProperty(document, 'startViewTransition');
46
- document.getElementById(ROOT_STYLES_ID)?.remove();
47
- document.getElementById('eco-vt-dynamic-styles')?.remove();
48
- document.body.replaceChildren();
49
- });
50
- describe('runNavigationViewTransition', () => {
51
- it('does not clear the names from a newer transition when an older one finishes later', async () => {
52
- document.body.innerHTML = '<div data-view-transition="first">First</div>';
53
- const { finishTransition } = installPendingViewTransitions();
54
- await runNavigationViewTransition(() => {
55
- document.body.innerHTML = '<div data-view-transition="second">Second</div>';
56
- }, { enabled: true });
57
- await runNavigationViewTransition(() => {
58
- document.body.innerHTML = '<div data-view-transition="third">Third</div>';
59
- }, { enabled: true });
60
- finishTransition();
61
- await Promise.resolve();
62
- await Promise.resolve();
63
- const currentElement = document.querySelector('[data-view-transition]');
64
- expect(currentElement.style.viewTransitionName).toBe('third');
65
- finishTransition(1);
66
- await Promise.resolve();
67
- await Promise.resolve();
68
- expect(currentElement.style.viewTransitionName).toBe('');
69
- });
70
- it('does not clear names after a later navigation skips transitions', async () => {
71
- document.body.innerHTML = '<div data-view-transition="first">First</div>';
72
- const { finishTransition, startViewTransition } = installPendingViewTransitions();
73
- await runNavigationViewTransition(() => {
74
- document.body.innerHTML = '<div data-view-transition="second">Second</div>';
75
- }, { enabled: true });
76
- await runNavigationViewTransition(() => {
77
- document.body.innerHTML = '<div data-view-transition="third">Third</div>';
78
- applyViewTransitionNames();
79
- }, { enabled: false });
80
- finishTransition();
81
- await Promise.resolve();
82
- await Promise.resolve();
83
- const currentElement = document.querySelector('[data-view-transition]');
84
- expect(currentElement.style.viewTransitionName).toBe('third');
85
- expect(startViewTransition).toHaveBeenCalledOnce();
86
- });
87
- it('does not apply names from a superseded transition after a later noncommit', async () => {
88
- document.body.innerHTML = '<div data-view-transition="first">First</div>';
89
- const { finishTransition } = installPendingViewTransitions();
90
- let resolveUpdate;
91
- const pendingUpdate = new Promise((resolve) => {
92
- resolveUpdate = resolve;
93
- });
94
- const supersededTransition = runNavigationViewTransition(async () => {
95
- await pendingUpdate;
96
- }, { enabled: true });
97
- await Promise.resolve();
98
- await runNavigationViewTransition(() => {
99
- document.body.innerHTML = '<div data-view-transition="current">Current</div>';
100
- applyViewTransitionNames();
101
- return false;
102
- }, { enabled: false });
103
- const currentElement = document.querySelector('[data-view-transition]');
104
- expect(currentElement.style.viewTransitionName).toBe('');
105
- resolveUpdate();
106
- await supersededTransition;
107
- expect(currentElement.style.viewTransitionName).toBe('');
108
- finishTransition();
109
- await Promise.resolve();
110
- await Promise.resolve();
111
- expect(currentElement.style.viewTransitionName).toBe('');
112
- });
113
- it('clears names when a transition-skipping update rejects', async () => {
114
- document.body.innerHTML = '<div data-view-transition="third">Third</div>';
115
- let rejectUpdate;
116
- const failedUpdate = runNavigationViewTransition(async () => {
117
- applyViewTransitionNames();
118
- await new Promise((_resolve, reject) => {
119
- rejectUpdate = reject;
120
- });
121
- }, { enabled: false });
122
- const currentElement = document.querySelector('[data-view-transition]');
123
- expect(currentElement.style.viewTransitionName).toBe('third');
124
- rejectUpdate(new Error('update failed'));
125
- await expect(failedUpdate).rejects.toThrow('update failed');
126
- expect(currentElement.style.viewTransitionName).toBe('');
127
- });
128
- it('clears names when a later navigation without transitions does not commit', async () => {
129
- document.body.innerHTML = '<div data-view-transition="first">First</div>';
130
- const { finishTransition, startViewTransition } = installPendingViewTransitions();
131
- await runNavigationViewTransition(() => {
132
- document.body.innerHTML = '<div data-view-transition="second">Second</div>';
133
- }, { enabled: true });
134
- await runNavigationViewTransition(() => {
135
- document.body.innerHTML = '<div data-view-transition="third">Third</div>';
136
- applyViewTransitionNames();
137
- return false;
138
- }, { enabled: false });
139
- const currentElement = document.querySelector('[data-view-transition]');
140
- expect(currentElement.style.viewTransitionName).toBe('');
141
- finishTransition();
142
- await Promise.resolve();
143
- await Promise.resolve();
144
- expect(currentElement.style.viewTransitionName).toBe('');
145
- expect(startViewTransition).toHaveBeenCalledOnce();
146
- });
147
- it('swaps without startViewTransition when no named transition elements are present', async () => {
148
- const startViewTransition = installStartViewTransition({
149
- finished: Promise.resolve(),
150
- ready: Promise.resolve(),
151
- });
152
- await runNavigationViewTransition(() => {
153
- document.body.innerHTML = '<div>Updated</div>';
154
- }, { enabled: true });
155
- expect(startViewTransition).not.toHaveBeenCalled();
156
- expect(document.body.innerHTML).toContain('Updated');
157
- });
158
- it('swaps inside startViewTransition when the page has named elements and ignores a skipped transition', async () => {
159
- document.body.innerHTML = '<div data-view-transition="hero">Old</div>';
160
- const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => { });
161
- const skipped = new DOMException('Transition was skipped', 'AbortError');
162
- const startViewTransition = installStartViewTransition({
163
- finished: Promise.reject(skipped),
164
- ready: Promise.reject(skipped),
165
- });
166
- await runNavigationViewTransition(() => {
167
- document.body.innerHTML = '<div>Updated</div>';
168
- }, { enabled: true });
169
- await Promise.resolve();
170
- expect(startViewTransition).toHaveBeenCalledTimes(1);
171
- expect(document.body.innerHTML).toContain('Updated');
172
- expect(consoleSpy).not.toHaveBeenCalled();
173
- });
174
- it('logs a view transition failure that is not a skip', async () => {
175
- document.body.innerHTML = '<div data-view-transition="hero">Old</div>';
176
- const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => { });
177
- const failure = new Error('transition failed');
178
- installStartViewTransition({ finished: Promise.reject(failure), ready: Promise.resolve() });
179
- await runNavigationViewTransition(() => { }, { enabled: true });
180
- await vi.waitFor(() => expect(consoleSpy).toHaveBeenCalledWith('[ecopages] View transition lifecycle failed:', failure));
181
- });
182
- it.each([
183
- { enabled: true, expectedStyles: true },
184
- { enabled: false, expectedStyles: false },
185
- ])('installs the root styles only when enabled is $enabled', async ({ enabled, expectedStyles }) => {
186
- await runNavigationViewTransition(() => { }, { enabled });
187
- expect(document.getElementById(ROOT_STYLES_ID) !== null).toBe(expectedStyles);
188
- });
189
- });
@@ -1,18 +0,0 @@
1
- export type StagedStylesheets = {
2
- /** Every stylesheet link the pipeline staged while the fixture was active, in order. */
3
- links: HTMLLinkElement[];
4
- /** Fires `load` on a staged link, as the browser does once its fetch finishes. */
5
- finish(link: HTMLLinkElement): void;
6
- /** Restores `document.head.appendChild`. */
7
- stop(): void;
8
- };
9
- /**
10
- * Takes over how the head's stylesheet fetches end, so a test decides when a navigation may continue.
11
- *
12
- * @remarks
13
- * The pipeline waits for the `load` of every incoming stylesheet, and a test URL never answers.
14
- * A link that `defer` accepts is recorded but not attached, so the browser never fetches it and the
15
- * wait stays open until the test calls `finish`. Attaching it would end the wait with an `error`
16
- * on the first 404. Every other stylesheet is attached and loads on the next microtask.
17
- */
18
- export declare function stageStylesheets(defer?: (link: HTMLLinkElement) => boolean): StagedStylesheets;
@@ -1,31 +0,0 @@
1
- /**
2
- * Takes over how the head's stylesheet fetches end, so a test decides when a navigation may continue.
3
- *
4
- * @remarks
5
- * The pipeline waits for the `load` of every incoming stylesheet, and a test URL never answers.
6
- * A link that `defer` accepts is recorded but not attached, so the browser never fetches it and the
7
- * wait stays open until the test calls `finish`. Attaching it would end the wait with an `error`
8
- * on the first 404. Every other stylesheet is attached and loads on the next microtask.
9
- */
10
- export function stageStylesheets(defer = () => false) {
11
- const links = [];
12
- const originalAppendChild = document.head.appendChild.bind(document.head);
13
- const finish = (link) => link.dispatchEvent(new Event('load'));
14
- document.head.appendChild = ((node) => {
15
- if (!(node instanceof HTMLLinkElement) || node.rel !== 'stylesheet')
16
- return originalAppendChild(node);
17
- links.push(node);
18
- if (defer(node))
19
- return node;
20
- const attached = originalAppendChild(node);
21
- queueMicrotask(() => finish(node));
22
- return attached;
23
- });
24
- return {
25
- links,
26
- finish,
27
- stop: () => {
28
- Reflect.deleteProperty(document.head, 'appendChild');
29
- },
30
- };
31
- }
@@ -1,67 +0,0 @@
1
- # Static Site Generation
2
-
3
- **Layer:** Rendering.
4
-
5
- This directory contains the static-build execution path used when Ecopages renders pages ahead of time.
6
-
7
- ## Purpose
8
-
9
- The static-site generator reuses the same app-owned config, route matching, and rendering services that development and preview flows use, but drives them in a build-oriented loop.
10
-
11
- It is responsible for:
12
-
13
- - enumerating renderable routes
14
- - rendering static outputs through the normal rendering pipeline
15
- - respecting route-level constraints such as cache policy and unsupported dynamic server-only paths
16
- - emitting semantic 404/500 artifacts through the shared error-page renderer
17
-
18
- ## Design Rule
19
-
20
- Static generation should follow the same ownership model as runtime rendering.
21
-
22
- That means it should reuse:
23
-
24
- - built app config
25
- - route matching
26
- - render orchestration
27
- - asset processing
28
-
29
- It should not invent a parallel rendering stack just for build mode.
30
-
31
- Static export uses the same CPU-based concurrency limit as the build queue, and the startup trace reports that limit.
32
-
33
- Semantic error pages are excluded from ordinary page enumeration and emitted once by `route-renderer/error-pages/semantic-error-page-exporter.ts`, so runtime and static output share source precedence and rendering behavior.
34
-
35
- ## Files
36
-
37
- | File | Role |
38
- | ------------------------------------------- | -------------------------------------------------------------------------------------------------- |
39
- | `static-site-generator.ts` | Route enumeration, HTML artifact writes, integration export hooks, sitemap |
40
- | `static-export-context.ts` | Context and release types for `staticExport` |
41
- | `sitemap.ts` | Pure sitemap.xml renderer |
42
- | `sitemap-routes.ts` | Sitemap location assembly (`exclude`, `extraUrls`, dedupe) |
43
- | `production-page-browser-graph-prebuild.ts` | Collects renderer plans, persists the app-wide browser client manifest, and prebuilds route graphs |
44
-
45
- ## Export directory
46
-
47
- `ServerStaticBuilder.prepareExport()` empties `dist/`, copies the public directory into it, marks runtime assets for rebuilding and sets Processors and Integrations up. The Node adapter calls it during initialization, before the router reads any Page, and `build()` prepares the export itself only when nothing did. Every build renders every page from source in a fresh process, so nothing in an earlier `dist/` is reused and no HTML is skipped or pruned. Route-module transpile and the unified pages graph are reused in memory only, within the current process. Before rendering, production prebuild gathers grouped browser entries from every renderer and the HTML shell module scripts into compatible app-wide browser build groups, associates entry assets with the routes that use them, and writes `.server/browser-client-manifest.json`. It also writes a parameter-free plan for every non-exact route template without calling `staticProps` or metadata hooks for missing params. `ecopages start` restores those plans and their browser assets before accepting SSR requests, so a later product slug can reuse the app-wide output when its grouped browser dependencies and page-client entries match the template. A request with a new dependency graph keeps the request-time browser build path. A generation failure clears the manifest so a later start cannot use a partial build.
48
-
49
- Filesystem and explicit Page render failures are logged with their route and stack. By default, Core finishes the remaining routes and sitemap, releases export resources, then fails the build with all page failures; `ecopages build` exits with status 1. `ecopages build --keep-going` keeps the earlier log-and-continue behavior and exits successfully, leaving failed Pages out of the export.
50
-
51
- ## Integration hooks
52
-
53
- Integrations may implement:
54
-
55
- - `staticExport(context)` — runs after unified-graph prebuild, before page rendering. It may return a release function. Core awaits every release in reverse order once the export ends, including when it fails or an Integration listed later throws from `staticExport`, so a worker started for the export stops with it: `ecopages build` ends by itself and no longer calls `process.exit()`. A release that throws is logged and does not fail the export.
56
-
57
- Core calls no other Integration hook around generation.
58
-
59
- When `appConfig.sitemap.enabled` is true, `sitemap.xml` is written **after** every page, so a file an Integration writes during export can be listed through `extraUrls`. Development (`ecopages dev`) does not emit this file.
60
-
61
- Sitemap eligibility uses the metadata returned by the successful route render (`activeStaticPathnames` plus `robots.index !== false`, fail-closed when render metadata is unavailable). It does not load the route or rerun its `staticProps` and metadata hooks after writing the page. `resolveSitemapLocations` then applies `exclude` and appends `extraUrls`.
62
-
63
- `StaticExportContext.routes` is the unfiltered static-generation route list. Sitemap filtering is applied separately.
64
-
65
- See `StaticExportContext` in `static-export-context.ts`.
66
-
67
- User-facing guide: [Sitemap](https://github.com/ecopages/ecopages/blob/main/apps/docs/src/content/docs/core/sitemap.mdx) in the docs app.
@@ -1,2 +0,0 @@
1
- import type { EcoPagesAppConfig } from '../config/internal-types.js';
2
- export declare const createMockConfig: (overrides?: Partial<EcoPagesAppConfig>) => EcoPagesAppConfig;
@@ -1,41 +0,0 @@
1
- import { DEFAULT_ECOPAGES_WORK_DIR } from '../constants.js';
2
- export const createMockConfig = (overrides = {}) => {
3
- const integrations = (overrides.integrations ?? []).map((integration) => ({
4
- ...integration,
5
- setup: integration.setup ?? (async () => { }),
6
- teardown: integration.teardown ?? (async () => { }),
7
- }));
8
- return {
9
- rootDir: '/test/project',
10
- distDir: 'dist',
11
- workDir: DEFAULT_ECOPAGES_WORK_DIR,
12
- srcDir: 'src',
13
- defaultMetadata: {
14
- title: 'Test',
15
- description: 'Test site',
16
- },
17
- robotsTxt: {
18
- preferences: {
19
- '*': ['/admin', '/private'],
20
- Googlebot: ['/no-google'],
21
- },
22
- },
23
- sitemap: {
24
- enabled: false,
25
- fileName: 'sitemap.xml',
26
- extraUrls: [],
27
- exclude: [],
28
- },
29
- absolutePaths: {
30
- distDir: '/test/project/dist',
31
- workDir: '/test/project/.eco',
32
- },
33
- processors: new Map(),
34
- ...overrides,
35
- integrations,
36
- appRuntime: overrides.appRuntime ??
37
- {
38
- integrationActivations: new Map(),
39
- },
40
- };
41
- };
@@ -1,5 +0,0 @@
1
- # Core Types
2
-
3
- **Layer:** Foundation.
4
-
5
- This directory defines the user, Integration, and internal contracts shared across core. Contracts here may depend on sibling type files and external type packages; they do not import core implementation modules. `check:portability` enforces this boundary.
@@ -1,7 +0,0 @@
1
- # Shared Utilities
2
-
3
- **Layer:** Foundation.
4
-
5
- This directory contains generic helpers used across core. Utilities may depend on other Foundation modules, but should not import build, rendering, development, or application assembly code.
6
-
7
- Shared helpers here define path containment for both inclusive and strict descendants, markup escaping for HTML and XML, one-pass or stable HTML entity decoding, literal regular-expression escaping, and stable SHA-256 content digests. `contentHash(input)` accepts text or bytes and returns the full lowercase hexadecimal digest; pass an integer length from 1 to 64 to return a prefix. Other lengths throw `RangeError`.
@@ -1,9 +0,0 @@
1
- # Request Validation
2
-
3
- **Layer:** Foundation.
4
-
5
- This directory validates API request inputs against Standard Schema validators.
6
-
7
- `validateRequest()` validates the declared params, query, headers, and body. Available validators run concurrently. A declared body validator always runs, including when the parsed body is `undefined`, so required schemas reject an empty body and optional schemas can accept it. `validateStandardSchema()` adapts Standard Schema results into the validation error used by the API request pipeline.
8
-
9
- The API request pipeline owns parsing and response handling; this module owns schema execution and normalized validation errors.
@@ -1,15 +0,0 @@
1
- # Project Watcher
2
-
3
- **Layer:** Development and HMR.
4
-
5
- The Project Watcher recursively watches `srcDir` and any configured pages, components, includes, layouts or public directory that resolves outside it, plus recorded build inputs outside it, restart files, workspace-linked package roots, and configured additional watch paths. Recorded inputs include files loaded through build plugins, module closures, and Processor watch roots; they select which builds and caches a change invalidates without narrowing source-directory coverage. Startup waits up to 30 seconds for Chokidar’s `ready` event before the server advertises readiness, so the first edit cannot race initial filesystem subscription. A startup error or timeout closes the watcher and rejects initialization. `ignoreInitial` prevents existing files from being treated as new at startup. Subscription replays paths already recorded during initialization or Page rendering and adds paths recorded after listen. Chokidar emits no `add` for an existing path passed to `watcher.add`, so subscribing a recorded input after listen is not treated as a create. Genuine new source files invalidate immediately, including files copied with preserved timestamps. Linked-package creates still request a restart.
6
-
7
- Filesystem events use a trailing debounce with a 150 ms default; setting `changeDebounceMs` to `0` disables debouncing. With debouncing enabled, the maximum-wait timer schedules the batch no later than one second after its first event. Processing remains serialized behind earlier work, so it can start later. Closing the watcher drops scheduled batches that have not started. File and directory events share the same debounce window. The watcher submits one file batch to `DevelopmentInvalidationService`; a runtime-restart category returns its path without marking results dirty, then the watcher forwards it to the runtime owner. Other batches mark server modules, Page Browser Graph records, HTML cache entries, and route-module records dirty without rebuilding them. An unopened Page is rebuilt on the next request. For each non-restart file batch, matching Processors receive one `onChanges({ created, changed, deleted, bridge })` callback. The watcher passes every HMR-eligible file from that batch to the HMR manager in one call; the manager dispatches each file to its strategy and coalesces their results into one client update. Directory-only Pages batches refresh the Route Registry once without Processor or HMR notifications.
8
-
9
- At startup it resolves the application's declared dependencies, development dependencies, and optional dependencies through installed package directories, including hoisted installs. Real package roots outside any `node_modules` segment are watched directly. This covers server-only imports and packages with subpath-only exports without waiting for a browser request. Missing optional packages are skipped; aliases to the same root share a subscription.
10
-
11
- Adding, changing, or removing a linked package file requests a runtime restart before HMR or Processor notifications. The existing lifecycle coalesces pending restart requests and delegates shutdown to the process that owns the watcher. The next process reloads server imports and rebuilds browser vendors from memory; vendor bundles are not persisted under `dist`. A watcher with no restart callback warns and returns.
12
-
13
- Linked package `node_modules` and dot entries are ignored. Application work and dist directories remain ignored, while application dotenv files remain restart inputs. Discovery runs again on startup; changing the application's dependency declarations or links requires restarting the session. Dependencies declared only by another package are not discovered transitively.
14
-
15
- See [development](../dev/README.md) for in-memory vendor rebuilding and process supervision, and [core](../../README.md) for the architecture index.