@ecopages/core 0.5.0 → 0.6.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.
- package/README.md +18 -14
- package/package.json +13 -4
- package/src/adapters/create-app.js +9 -5
- package/src/adapters/node/create-app.d.ts +18 -16
- package/src/adapters/node/create-app.js +26 -30
- package/src/adapters/node/server-adapter.d.ts +26 -9
- package/src/adapters/node/server-adapter.js +38 -8
- package/src/adapters/shared/hmr/hmr-manager.js +3 -2
- package/src/adapters/shared/http/dist-file-handler.js +25 -7
- package/src/adapters/shared/runtime/render-context.d.ts +2 -1
- package/src/adapters/shared/runtime/render-context.js +18 -21
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +4 -3
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +6 -4
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +6 -1
- package/src/adapters/shared/runtime/server-request-pipeline.js +10 -10
- package/src/adapters/shared/runtime/server-static-builder.d.ts +11 -11
- package/src/adapters/shared/runtime/server-static-builder.js +37 -18
- package/src/assets/app-browser-client-manifest.d.ts +1 -3
- package/src/assets/app-browser-client-manifest.js +5 -58
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +2 -2
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +2 -2
- package/src/assets/browser-asset-output.d.ts +1 -1
- package/src/assets/browser-asset-output.js +1 -1
- package/src/build/app-build-manifest-runtime.d.ts +11 -1
- package/src/build/app-build-manifest-runtime.js +17 -3
- package/src/build/cache/pages-unified-graph-build.d.ts +32 -35
- package/src/build/cache/pages-unified-graph-build.js +206 -124
- package/src/build/cache/server-module-entries.d.ts +35 -0
- package/src/build/cache/server-module-entries.js +109 -0
- package/src/build/contracts/build-contracts.d.ts +5 -0
- package/src/build/copy-server-files.d.ts +10 -0
- package/src/build/copy-server-files.js +37 -0
- package/src/build/preserve-import-meta-transform.d.ts +1 -1
- package/src/build/preserve-import-meta-transform.js +1 -1
- package/src/build/production-build-id.d.ts +9 -0
- package/src/build/production-build-id.js +19 -0
- package/src/build/production-dist-complete.d.ts +5 -0
- package/src/build/production-dist-complete.js +101 -0
- package/src/build/production-route-list.d.ts +26 -0
- package/src/build/production-route-list.js +78 -0
- package/src/build/rolldown/rolldown-adapter-helpers.d.ts +2 -2
- package/src/build/rolldown/rolldown-adapter-helpers.js +56 -4
- package/src/build/rolldown/rolldown-build-adapter.js +1 -1
- package/src/build/runtime/build-request-identity.js +2 -1
- package/src/build/runtime/build-request-policy.d.ts +3 -2
- package/src/build/runtime/build-request-policy.js +5 -3
- package/src/build/server/import-view-module.d.ts +11 -0
- package/src/build/server/import-view-module.js +21 -0
- package/src/build/server/imported-view-plugin.d.ts +16 -0
- package/src/build/server/imported-view-plugin.js +59 -0
- package/src/build/server/page-module-import.service.d.ts +19 -20
- package/src/build/server/page-module-import.service.js +65 -36
- package/src/build/server/resolve-static-view.d.ts +9 -0
- package/src/build/server/resolve-static-view.js +28 -0
- package/src/build/server/route-module-build-cache-registry.d.ts +5 -3
- package/src/build/server/route-module-build-cache-registry.js +5 -3
- package/src/build/server/server-modules-manifest.d.ts +51 -0
- package/src/build/server/server-modules-manifest.js +129 -0
- package/src/build/server/view-reference.d.ts +38 -0
- package/src/build/server/view-reference.js +112 -0
- package/src/build/server-bundle-deploy-manifest.d.ts +9 -9
- package/src/build/server-bundle-deploy-manifest.js +24 -28
- package/src/build.d.ts +3 -1
- package/src/build.js +3 -1
- package/src/config/assembly/app-runtime.d.ts +15 -2
- package/src/config/assembly/app-runtime.js +3 -1
- package/src/config/assembly/finalize-config.js +64 -13
- package/src/config/index.d.ts +1 -0
- package/src/config/index.js +1 -0
- package/src/config/internal-types.d.ts +6 -0
- package/src/config/load-eco-config.d.ts +1 -0
- package/src/config/load-eco-config.js +11 -2
- package/src/config/resolve-eco-config-path.d.ts +2 -1
- package/src/config/resolve-eco-config-path.js +21 -15
- package/src/config/user-config-types.d.ts +9 -2
- package/src/html-pages/html-page-module.d.ts +19 -0
- package/src/html-pages/html-page-module.js +66 -13
- package/src/html-pages/html-page-renderer.d.ts +4 -0
- package/src/html-pages/html-page-renderer.js +9 -3
- package/src/html-pages/html-pages.plugin.d.ts +10 -0
- package/src/html-pages/html-pages.plugin.js +7 -1
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/integration.d.ts +2 -1
- package/src/integration.js +1 -0
- package/src/page-cache/page-cache-service.d.ts +8 -0
- package/src/page-cache/page-cache-service.js +12 -0
- package/src/plugins/integration-plugin.d.ts +33 -6
- package/src/plugins/integration-plugin.js +14 -2
- package/src/plugins/processor.d.ts +17 -0
- package/src/plugins/processor.js +20 -1
- package/src/plugins/server-dom.d.ts +29 -0
- package/src/plugins/server-dom.js +36 -0
- package/src/route-renderer/error-pages/error-page-renderer.d.ts +6 -4
- package/src/route-renderer/error-pages/error-page-renderer.js +9 -5
- package/src/route-renderer/orchestration/integration-renderer.d.ts +1 -0
- package/src/route-renderer/orchestration/integration-renderer.js +17 -2
- package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +21 -0
- package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +31 -0
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +58 -24
- package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +12 -0
- package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +55 -0
- package/src/router/client/navigation-commit.js +16 -2
- package/src/router/client/navigation-head-order.fixture.css +3 -0
- package/src/router/client/navigation-head.d.ts +2 -1
- package/src/router/client/navigation-head.fixture.css +3 -0
- package/src/router/client/navigation-head.js +222 -39
- package/src/router/server/route-registry.d.ts +22 -2
- package/src/router/server/route-registry.js +39 -15
- package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +8 -2
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +14 -9
- package/src/static-site-generator/static-site-generator.d.ts +19 -3
- package/src/static-site-generator/static-site-generator.js +78 -40
- package/src/types/contracts.d.ts +20 -31
- package/src/types/public-types.d.ts +1 -0
- package/src/types/view-reference.d.ts +31 -0
- package/src/types/view-reference.js +15 -0
- package/src/utils/additional-watch-paths.d.ts +3 -3
- package/src/utils/additional-watch-paths.js +3 -1
- package/src/utils/resolve-entry-file.d.ts +4 -2
- package/src/utils/resolve-entry-file.js +4 -2
- package/src/utils/root-relative-path.d.ts +4 -0
- package/src/utils/root-relative-path.js +8 -0
- package/src/utils/server-bundle-context.d.ts +14 -0
- package/src/utils/server-bundle-context.js +45 -0
- package/src/watchers/project-watcher-ignore.d.ts +2 -5
- package/src/watchers/project-watcher-ignore.js +2 -5
- package/src/watchers/project-watcher.d.ts +9 -7
- package/src/watchers/project-watcher.js +100 -52
- package/src/watchers/workspace-package-watch-roots.d.ts +4 -4
- package/src/watchers/workspace-package-watch-roots.js +41 -25
- package/src/build/server/view-module-loader.d.ts +0 -10
- package/src/build/server/view-module-loader.js +0 -46
|
@@ -3,6 +3,8 @@ import { collectRerunScripts, isNonExecutableHeadScript, isRerunScript, shouldPe
|
|
|
3
3
|
import { getNavigationScriptIdentity } from '../../client/navigation-scripts/identity.js';
|
|
4
4
|
import { ECO_PERSIST_ATTRIBUTE } from '../../client/navigation-attributes.js';
|
|
5
5
|
const stagedStylesheetLoads = new Map();
|
|
6
|
+
const pendingStylesheetLinks = new Map();
|
|
7
|
+
let latestHeadUpdateGeneration = 0;
|
|
6
8
|
function resolveMetaElementKey(element) {
|
|
7
9
|
const identity = element.getAttribute('name') ||
|
|
8
10
|
element.getAttribute('property') ||
|
|
@@ -47,6 +49,8 @@ function indexHeadChildren(head) {
|
|
|
47
49
|
for (const element of Array.from(head.children)) {
|
|
48
50
|
if (element.hasAttribute('data-eco-injected'))
|
|
49
51
|
continue;
|
|
52
|
+
if (element instanceof HTMLLinkElement && pendingStylesheetLinks.has(element))
|
|
53
|
+
continue;
|
|
50
54
|
const key = resolveHeadElementKey(element);
|
|
51
55
|
if (key)
|
|
52
56
|
elements.set(key, element);
|
|
@@ -84,19 +88,100 @@ function syncAttributes(current, incoming) {
|
|
|
84
88
|
}
|
|
85
89
|
for (const attribute of Array.from(incoming.attributes)) {
|
|
86
90
|
if ((incoming.tagName === 'LINK' || incoming.tagName === 'BASE') && attribute.name === 'href') {
|
|
87
|
-
|
|
91
|
+
const href = incoming.href;
|
|
92
|
+
if (current.href !== href)
|
|
93
|
+
current.setAttribute('href', href);
|
|
88
94
|
}
|
|
89
95
|
else {
|
|
90
96
|
current.setAttribute(attribute.name, attribute.value);
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
}
|
|
100
|
+
function isCascadeOrderedElement(key, element) {
|
|
101
|
+
return element.tagName === 'STYLE' || key.startsWith('link:stylesheet:');
|
|
102
|
+
}
|
|
103
|
+
function insertIncomingHeadElement(element, key, incomingElements, currentElements) {
|
|
104
|
+
let anchor = null;
|
|
105
|
+
if (isCascadeOrderedElement(key, element)) {
|
|
106
|
+
let found = false;
|
|
107
|
+
for (const [nextKey, nextIncoming] of incomingElements) {
|
|
108
|
+
if (nextKey === key) {
|
|
109
|
+
found = true;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (!found || !isCascadeOrderedElement(nextKey, nextIncoming))
|
|
113
|
+
continue;
|
|
114
|
+
anchor = currentElements.get(nextKey) ?? null;
|
|
115
|
+
if (anchor)
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (anchor) {
|
|
120
|
+
document.head.insertBefore(element, anchor);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
document.head.appendChild(element);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function isInIncomingCascadePosition(key, element, incomingElements, currentElements) {
|
|
127
|
+
let before = true;
|
|
128
|
+
for (const [otherKey, incoming] of incomingElements) {
|
|
129
|
+
if (otherKey === key) {
|
|
130
|
+
before = false;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (!isCascadeOrderedElement(otherKey, incoming))
|
|
134
|
+
continue;
|
|
135
|
+
const other = currentElements.get(otherKey);
|
|
136
|
+
if (!other || other === element)
|
|
137
|
+
continue;
|
|
138
|
+
const otherFollows = Boolean(element.compareDocumentPosition(other) & Node.DOCUMENT_POSITION_FOLLOWING);
|
|
139
|
+
if (otherFollows === before)
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
function cascadeOrderChanged(incoming, current) {
|
|
145
|
+
const retained = new Map([...current].filter(([, element]) => !(element instanceof HTMLLinkElement && pendingStylesheetLinks.has(element))));
|
|
146
|
+
const incomingKeys = [...incoming]
|
|
147
|
+
.filter(([key, element]) => isCascadeOrderedElement(key, element) && retained.has(key))
|
|
148
|
+
.map(([key]) => key);
|
|
149
|
+
const currentKeys = [...retained]
|
|
150
|
+
.filter(([key, element]) => isCascadeOrderedElement(key, element) && incoming.has(key))
|
|
151
|
+
.map(([key]) => key);
|
|
152
|
+
return incomingKeys.some((key, index) => currentKeys[index] !== key);
|
|
153
|
+
}
|
|
94
154
|
function isPersisted(element, persistAttribute) {
|
|
95
155
|
return (element.hasAttribute(persistAttribute) ||
|
|
96
156
|
element.hasAttribute(ECO_PERSIST_ATTRIBUTE) ||
|
|
97
157
|
element.matches('meta[charset]') ||
|
|
98
158
|
shouldPersistExecutableInlineHeadScript(element));
|
|
99
159
|
}
|
|
160
|
+
function hasPersistedCascadeReorder(incoming, current, persistAttribute) {
|
|
161
|
+
return (cascadeOrderChanged(incoming, current) &&
|
|
162
|
+
[...current].some(([key, element]) => incoming.has(key) && isCascadeOrderedElement(key, element) && isPersisted(element, persistAttribute)));
|
|
163
|
+
}
|
|
164
|
+
function stylesheetOrderChanged(incoming, active, staged) {
|
|
165
|
+
let previous;
|
|
166
|
+
for (const key of incoming.keys()) {
|
|
167
|
+
if (!key.startsWith('link:stylesheet:'))
|
|
168
|
+
continue;
|
|
169
|
+
const stage = staged.get(key);
|
|
170
|
+
const current = stage && !stage.committed ? stage.link : active.get(key);
|
|
171
|
+
if (!current)
|
|
172
|
+
return true;
|
|
173
|
+
if (previous && !(previous.compareDocumentPosition(current) & Node.DOCUMENT_POSITION_FOLLOWING))
|
|
174
|
+
return true;
|
|
175
|
+
previous = current;
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
function hasPersistedStylesheetForStage(key, stage, persistAttribute) {
|
|
180
|
+
return Array.from(document.head.children).some((element) => element !== stage.link &&
|
|
181
|
+
!(element instanceof HTMLLinkElement && pendingStylesheetLinks.has(element)) &&
|
|
182
|
+
resolveHeadElementKey(element) === key &&
|
|
183
|
+
isPersisted(element, persistAttribute));
|
|
184
|
+
}
|
|
100
185
|
function createHeadScriptActivations(newDocument, currentElements, shouldSkip) {
|
|
101
186
|
const knownScriptKeys = new Set([...currentElements.keys()].filter((key) => key.startsWith('script:')));
|
|
102
187
|
const activations = [];
|
|
@@ -130,100 +215,198 @@ function waitForStylesheet(link) {
|
|
|
130
215
|
let timeout;
|
|
131
216
|
const observer = new MutationObserver(() => {
|
|
132
217
|
if (!link.isConnected)
|
|
133
|
-
done();
|
|
218
|
+
done(false);
|
|
134
219
|
});
|
|
135
|
-
const done = () => {
|
|
220
|
+
const done = (loaded) => {
|
|
136
221
|
clearTimeout(timeout);
|
|
137
222
|
observer.disconnect();
|
|
138
|
-
link.removeEventListener('load',
|
|
139
|
-
link.removeEventListener('error',
|
|
140
|
-
resolve();
|
|
223
|
+
link.removeEventListener('load', onLoad);
|
|
224
|
+
link.removeEventListener('error', onError);
|
|
225
|
+
resolve(loaded);
|
|
141
226
|
};
|
|
142
|
-
|
|
227
|
+
const onLoad = () => done(true);
|
|
228
|
+
const onError = () => done(false);
|
|
229
|
+
timeout = setTimeout(() => done(false), 5000);
|
|
143
230
|
observer.observe(document.head, { childList: true, subtree: true });
|
|
144
|
-
link.addEventListener('load',
|
|
145
|
-
link.addEventListener('error',
|
|
231
|
+
link.addEventListener('load', onLoad, { once: true });
|
|
232
|
+
link.addEventListener('error', onError, { once: true });
|
|
146
233
|
});
|
|
147
234
|
}
|
|
148
|
-
async function
|
|
235
|
+
async function replacementStylesheetsLoaded(currentElements, stagedStylesheets) {
|
|
236
|
+
for (const [key, stage] of stagedStylesheets) {
|
|
237
|
+
if (currentElements.has(key) && !(await stage.loaded))
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
async function preloadIncomingStylesheets(incomingElements, currentElements, stagedStylesheets, generation) {
|
|
149
243
|
const loadPromises = [];
|
|
150
|
-
|
|
244
|
+
const reorder = cascadeOrderChanged(incomingElements, currentElements);
|
|
245
|
+
const placementElements = new Map(currentElements);
|
|
246
|
+
if (reorder) {
|
|
247
|
+
for (const [key] of incomingElements) {
|
|
248
|
+
if (key.startsWith('link:stylesheet:'))
|
|
249
|
+
placementElements.delete(key);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const entries = [...incomingElements];
|
|
253
|
+
const signature = JSON.stringify(entries.filter(([key, element]) => isCascadeOrderedElement(key, element)).map(([key]) => key));
|
|
254
|
+
if (reorder)
|
|
255
|
+
entries.reverse();
|
|
256
|
+
for (const [key, element] of entries) {
|
|
151
257
|
if (!key.startsWith('link:stylesheet:'))
|
|
152
258
|
continue;
|
|
153
|
-
const
|
|
154
|
-
|
|
259
|
+
const registryKey = JSON.stringify([signature, key]);
|
|
260
|
+
const existingStage = stagedStylesheetLoads.get(registryKey);
|
|
261
|
+
if (existingStage &&
|
|
262
|
+
existingStage.link.isConnected &&
|
|
263
|
+
isInIncomingCascadePosition(key, existingStage.link, incomingElements, currentElements)) {
|
|
155
264
|
existingStage.users += 1;
|
|
265
|
+
existingStage.latestGeneration = generation;
|
|
156
266
|
stagedStylesheets.set(key, existingStage);
|
|
157
267
|
loadPromises.push(existingStage.loaded);
|
|
268
|
+
placementElements.set(key, existingStage.link);
|
|
158
269
|
continue;
|
|
159
270
|
}
|
|
160
|
-
if (currentElements.has(key))
|
|
271
|
+
if (currentElements.has(key) && !existingStage && !reorder)
|
|
161
272
|
continue;
|
|
162
273
|
const link = cloneHeadElement(element);
|
|
163
|
-
|
|
164
|
-
|
|
274
|
+
link.media = 'not all';
|
|
275
|
+
const stage = {
|
|
276
|
+
link,
|
|
277
|
+
loaded: waitForStylesheet(link),
|
|
278
|
+
users: 1,
|
|
279
|
+
committed: false,
|
|
280
|
+
registryKey,
|
|
281
|
+
loadedSuccessfully: null,
|
|
282
|
+
latestGeneration: generation,
|
|
283
|
+
};
|
|
284
|
+
void stage.loaded.then((loaded) => {
|
|
285
|
+
stage.loadedSuccessfully = loaded;
|
|
286
|
+
});
|
|
287
|
+
pendingStylesheetLinks.set(link, stage);
|
|
288
|
+
stagedStylesheetLoads.set(registryKey, stage);
|
|
165
289
|
stagedStylesheets.set(key, stage);
|
|
166
290
|
loadPromises.push(stage.loaded);
|
|
167
|
-
|
|
291
|
+
insertIncomingHeadElement(link, key, incomingElements, placementElements);
|
|
292
|
+
placementElements.set(key, link);
|
|
168
293
|
}
|
|
169
294
|
await Promise.all(loadPromises);
|
|
295
|
+
return await replacementStylesheetsLoaded(currentElements, stagedStylesheets);
|
|
296
|
+
}
|
|
297
|
+
function activateStagedStylesheet(key, stage, incoming) {
|
|
298
|
+
for (const candidate of Array.from(document.head.children)) {
|
|
299
|
+
if (candidate === stage.link || resolveHeadElementKey(candidate) !== key)
|
|
300
|
+
continue;
|
|
301
|
+
if (candidate instanceof HTMLLinkElement && pendingStylesheetLinks.has(candidate))
|
|
302
|
+
continue;
|
|
303
|
+
candidate.remove();
|
|
304
|
+
}
|
|
305
|
+
syncHeadElement(stage.link, incoming);
|
|
306
|
+
}
|
|
307
|
+
function reconcileIncomingHead(incomingElements, stagedStylesheets) {
|
|
308
|
+
const current = indexHeadChildren(document.head);
|
|
309
|
+
for (const [key, incoming] of incomingElements) {
|
|
310
|
+
if (incoming.tagName === 'SCRIPT' && !isNonExecutableHeadScript(incoming))
|
|
311
|
+
continue;
|
|
312
|
+
const existing = current.get(key);
|
|
313
|
+
const staged = stagedStylesheets.get(key);
|
|
314
|
+
if (staged && !staged.committed) {
|
|
315
|
+
activateStagedStylesheet(key, staged, incoming);
|
|
316
|
+
current.set(key, staged.link);
|
|
317
|
+
}
|
|
318
|
+
else if (existing) {
|
|
319
|
+
syncHeadElement(existing, incoming);
|
|
320
|
+
}
|
|
321
|
+
else if (!staged) {
|
|
322
|
+
const clone = cloneHeadElement(incoming);
|
|
323
|
+
insertIncomingHeadElement(clone, key, incomingElements, current);
|
|
324
|
+
current.set(key, clone);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
for (const [key, incoming] of [...incomingElements].reverse()) {
|
|
328
|
+
if (incoming.tagName !== 'STYLE')
|
|
329
|
+
continue;
|
|
330
|
+
const style = current.get(key);
|
|
331
|
+
if (style && !isInIncomingCascadePosition(key, style, incomingElements, current)) {
|
|
332
|
+
insertIncomingHeadElement(style, key, incomingElements, current);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return current;
|
|
170
336
|
}
|
|
171
337
|
/**
|
|
172
|
-
* Stages incoming stylesheets and prepares one diff for either router to commit.
|
|
338
|
+
* Stages incoming stylesheets without applying them and prepares one diff for either router to commit.
|
|
173
339
|
*/
|
|
174
340
|
export async function prepareNavigationHead(newDocument, persistAttribute = ECO_PERSIST_ATTRIBUTE, shouldSkipScriptActivation = () => false) {
|
|
341
|
+
const generation = ++latestHeadUpdateGeneration;
|
|
175
342
|
const incomingElements = indexHeadChildren(newDocument.head);
|
|
176
343
|
const currentElements = indexHeadChildren(document.head);
|
|
177
344
|
const pendingRerunScripts = collectRerunScripts(newDocument, (script) => !shouldSkipScriptActivation(script));
|
|
178
345
|
const scriptActivations = createHeadScriptActivations(newDocument, currentElements, shouldSkipScriptActivation);
|
|
179
346
|
const rerunScriptActivations = pendingRerunScripts.map(toRerunScriptActivation);
|
|
180
347
|
const stagedStylesheets = new Map();
|
|
181
|
-
|
|
348
|
+
const hasPersistedReorder = hasPersistedCascadeReorder(incomingElements, currentElements, persistAttribute);
|
|
349
|
+
const requiresReload = hasPersistedReorder ||
|
|
350
|
+
!(await preloadIncomingStylesheets(incomingElements, currentElements, stagedStylesheets, generation));
|
|
182
351
|
let committed = false;
|
|
183
352
|
let cancelled = false;
|
|
353
|
+
const reloadRequired = () => {
|
|
354
|
+
if (requiresReload)
|
|
355
|
+
return true;
|
|
356
|
+
const active = indexHeadChildren(document.head);
|
|
357
|
+
if (hasPersistedCascadeReorder(incomingElements, active, persistAttribute))
|
|
358
|
+
return true;
|
|
359
|
+
if (stylesheetOrderChanged(incomingElements, active, stagedStylesheets))
|
|
360
|
+
return true;
|
|
361
|
+
for (const [key, stage] of stagedStylesheets) {
|
|
362
|
+
if (!stage.link.isConnected || (active.has(key) && stage.loadedSuccessfully === false))
|
|
363
|
+
return true;
|
|
364
|
+
if (hasPersistedStylesheetForStage(key, stage, persistAttribute))
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
return false;
|
|
368
|
+
};
|
|
184
369
|
return {
|
|
185
370
|
scriptActivations,
|
|
186
371
|
rerunScriptActivations,
|
|
372
|
+
get requiresReload() {
|
|
373
|
+
return reloadRequired();
|
|
374
|
+
},
|
|
187
375
|
commit() {
|
|
188
376
|
if (committed || cancelled)
|
|
189
377
|
return;
|
|
378
|
+
if (reloadRequired())
|
|
379
|
+
throw new Error('Navigation head update requires a full document navigation');
|
|
190
380
|
committed = true;
|
|
191
|
-
const current =
|
|
192
|
-
for (const [
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const staged = stagedStylesheets.get(key);
|
|
197
|
-
if (existing) {
|
|
198
|
-
if (staged && staged.link !== existing)
|
|
199
|
-
staged.link.remove();
|
|
200
|
-
syncHeadElement(existing, incoming);
|
|
201
|
-
}
|
|
202
|
-
else if (!staged) {
|
|
203
|
-
document.head.appendChild(cloneHeadElement(incoming));
|
|
204
|
-
}
|
|
381
|
+
const current = reconcileIncomingHead(incomingElements, stagedStylesheets);
|
|
382
|
+
for (const [link, stage] of pendingStylesheetLinks) {
|
|
383
|
+
const key = resolveHeadElementKey(link);
|
|
384
|
+
if (stage.latestGeneration < generation && key && !incomingElements.has(key))
|
|
385
|
+
link.remove();
|
|
205
386
|
}
|
|
206
387
|
for (const [key, element] of current) {
|
|
207
388
|
if (incomingElements.has(key) || isPersisted(element, persistAttribute))
|
|
208
389
|
continue;
|
|
209
390
|
element.remove();
|
|
210
391
|
}
|
|
211
|
-
for (const
|
|
392
|
+
for (const stage of stagedStylesheets.values()) {
|
|
212
393
|
stage.committed = true;
|
|
213
|
-
|
|
214
|
-
|
|
394
|
+
pendingStylesheetLinks.delete(stage.link);
|
|
395
|
+
if (stagedStylesheetLoads.get(stage.registryKey) === stage)
|
|
396
|
+
stagedStylesheetLoads.delete(stage.registryKey);
|
|
215
397
|
}
|
|
216
398
|
},
|
|
217
399
|
cancel() {
|
|
218
400
|
if (committed || cancelled)
|
|
219
401
|
return;
|
|
220
402
|
cancelled = true;
|
|
221
|
-
for (const
|
|
403
|
+
for (const stage of stagedStylesheets.values()) {
|
|
222
404
|
stage.users -= 1;
|
|
223
405
|
if (stage.users === 0 && !stage.committed) {
|
|
224
406
|
stage.link.remove();
|
|
225
|
-
|
|
226
|
-
|
|
407
|
+
pendingStylesheetLinks.delete(stage.link);
|
|
408
|
+
if (stagedStylesheetLoads.get(stage.registryKey) === stage)
|
|
409
|
+
stagedStylesheetLoads.delete(stage.registryKey);
|
|
227
410
|
}
|
|
228
411
|
}
|
|
229
412
|
},
|
|
@@ -22,11 +22,12 @@ export type RouteMatch = {
|
|
|
22
22
|
readonly params: RouteParams;
|
|
23
23
|
readonly query: RouteQuery;
|
|
24
24
|
};
|
|
25
|
-
export type
|
|
25
|
+
export type PathExpansion = {
|
|
26
26
|
readonly pathname: string;
|
|
27
27
|
readonly templateRoute: TemplateRoute;
|
|
28
28
|
readonly params: RouteParams;
|
|
29
29
|
};
|
|
30
|
+
export type StaticPathExpansion = PathExpansion;
|
|
30
31
|
export type StaticGenerationRoute = {
|
|
31
32
|
readonly requestUrl: string;
|
|
32
33
|
readonly pathname: string;
|
|
@@ -44,7 +45,13 @@ export type RouteRegistryPageModule = {
|
|
|
44
45
|
}>;
|
|
45
46
|
}>;
|
|
46
47
|
readonly staticProps?: unknown;
|
|
47
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* The Page's Cache Strategy.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* `'dynamic'` Pages are omitted from Static Path Expansions (no HTML at Build-Time Rendering).
|
|
53
|
+
* When they declare `staticPaths`, those Params are still listed for Page Browser Graph planning.
|
|
54
|
+
*/
|
|
48
55
|
readonly cache?: unknown;
|
|
49
56
|
};
|
|
50
57
|
export interface RouteRegistryPageModuleAdapter {
|
|
@@ -88,9 +95,22 @@ export declare class RouteRegistry {
|
|
|
88
95
|
private compareSpecificity;
|
|
89
96
|
private getSpecificitySegments;
|
|
90
97
|
private isDynamicRouteSegment;
|
|
98
|
+
private expandStaticPaths;
|
|
99
|
+
private listPathExpansions;
|
|
91
100
|
listStaticPathExpansions(input: {
|
|
92
101
|
runtimeOrigin: string;
|
|
93
102
|
}): Promise<readonly StaticPathExpansion[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Params of Dynamic Pages that declare `staticPaths`, for Page Browser Graph planning.
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* The return shape is {@link PathExpansion}, the same records `staticPaths` produces. They are
|
|
108
|
+
* not Static Path Expansions: HTML still uses Request-Time Rendering. The build uses them so
|
|
109
|
+
* each Params list's graph is in the browser client manifest.
|
|
110
|
+
*/
|
|
111
|
+
listDynamicPagePathExpansions(input: {
|
|
112
|
+
runtimeOrigin: string;
|
|
113
|
+
}): Promise<readonly PathExpansion[]>;
|
|
94
114
|
listStaticGenerationRoutes(input: {
|
|
95
115
|
runtimeOrigin: string;
|
|
96
116
|
}): Promise<readonly StaticGenerationRoute[]>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { fileSystem } from '@ecopages/file-system';
|
|
3
3
|
import { appLogger } from '../../global/app-logger.js';
|
|
4
|
+
import { loadProductionTemplateRoutes } from '../../build/production-route-list.js';
|
|
4
5
|
import { invariant } from '../../utils/invariant.js';
|
|
6
|
+
import { isProductionRuntime } from '../../env.js';
|
|
5
7
|
import { hasKnownStaticExtension } from '../../utils/static-file-extensions.js';
|
|
6
8
|
import { ENDPOINT_FILE_EXTENSIONS, findEndpointFileExtension } from '../../utils/endpoint-file-extensions.js';
|
|
7
9
|
import { normalizePathname } from '../../utils/path-pattern.js';
|
|
@@ -40,7 +42,8 @@ export class RouteRegistry {
|
|
|
40
42
|
return this.templateRouteList.filter((route) => route.role === 'page');
|
|
41
43
|
}
|
|
42
44
|
async init() {
|
|
43
|
-
|
|
45
|
+
const productionRoutes = isProductionRuntime() ? loadProductionTemplateRoutes(this.appConfig) : undefined;
|
|
46
|
+
this.templateRouteList = productionRoutes ?? (await this.scanTemplateRoutes());
|
|
44
47
|
appLogger.debug('RouteRegistry initialized', this.templateRouteList);
|
|
45
48
|
}
|
|
46
49
|
async reload() {
|
|
@@ -105,38 +108,59 @@ export class RouteRegistry {
|
|
|
105
108
|
isDynamicRouteSegment(segment) {
|
|
106
109
|
return segment.startsWith('[') && segment.endsWith(']');
|
|
107
110
|
}
|
|
108
|
-
async
|
|
111
|
+
async expandStaticPaths(route, staticPaths, runtimeOrigin) {
|
|
112
|
+
const result = await staticPaths({
|
|
113
|
+
appConfig: this.appConfig,
|
|
114
|
+
runtimeOrigin,
|
|
115
|
+
});
|
|
116
|
+
return result.paths.map(({ params }) => ({
|
|
117
|
+
pathname: buildSegmentPath(route.pathname, params, 'filesystem'),
|
|
118
|
+
templateRoute: route,
|
|
119
|
+
params,
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
async listPathExpansions(input, options) {
|
|
109
123
|
const expansions = [];
|
|
110
124
|
for (const route of this.pageRoutes) {
|
|
111
125
|
if (route.kind === 'exact') {
|
|
112
126
|
continue;
|
|
113
127
|
}
|
|
114
128
|
const pageModule = await this.pageModuleAdapter.loadPageModule(route.filePath);
|
|
115
|
-
if (pageModule
|
|
129
|
+
if (!options.include(pageModule)) {
|
|
116
130
|
continue;
|
|
117
131
|
}
|
|
118
132
|
const staticPaths = pageModule.staticPaths;
|
|
119
|
-
if (this.buildMode) {
|
|
133
|
+
if (options.requireStaticHooks && this.buildMode) {
|
|
120
134
|
invariant(staticPaths !== undefined, `[ecopages] Missing getStaticPaths in ${route.filePath}`);
|
|
121
135
|
invariant(pageModule.staticProps !== undefined, `[ecopages] Missing getStaticProps in ${route.filePath}`);
|
|
122
136
|
}
|
|
123
137
|
if (!staticPaths) {
|
|
124
138
|
continue;
|
|
125
139
|
}
|
|
126
|
-
|
|
127
|
-
appConfig: this.appConfig,
|
|
128
|
-
runtimeOrigin: input.runtimeOrigin,
|
|
129
|
-
});
|
|
130
|
-
for (const { params } of result.paths) {
|
|
131
|
-
expansions.push({
|
|
132
|
-
pathname: buildSegmentPath(route.pathname, params, 'filesystem'),
|
|
133
|
-
templateRoute: route,
|
|
134
|
-
params,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
140
|
+
expansions.push(...(await this.expandStaticPaths(route, staticPaths, input.runtimeOrigin)));
|
|
137
141
|
}
|
|
138
142
|
return expansions;
|
|
139
143
|
}
|
|
144
|
+
async listStaticPathExpansions(input) {
|
|
145
|
+
return this.listPathExpansions(input, {
|
|
146
|
+
include: (pageModule) => pageModule.cache !== 'dynamic',
|
|
147
|
+
requireStaticHooks: true,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Params of Dynamic Pages that declare `staticPaths`, for Page Browser Graph planning.
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* The return shape is {@link PathExpansion}, the same records `staticPaths` produces. They are
|
|
155
|
+
* not Static Path Expansions: HTML still uses Request-Time Rendering. The build uses them so
|
|
156
|
+
* each Params list's graph is in the browser client manifest.
|
|
157
|
+
*/
|
|
158
|
+
async listDynamicPagePathExpansions(input) {
|
|
159
|
+
return this.listPathExpansions(input, {
|
|
160
|
+
include: (pageModule) => pageModule.cache === 'dynamic' && pageModule.staticPaths !== undefined,
|
|
161
|
+
requireStaticHooks: false,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
140
164
|
async listStaticGenerationRoutes(input) {
|
|
141
165
|
const staticPathExpansions = await this.listStaticPathExpansions(input);
|
|
142
166
|
return [
|
|
@@ -20,7 +20,8 @@ export declare function shouldPrebuildProductionPageBrowserGraphs(): boolean;
|
|
|
20
20
|
*
|
|
21
21
|
* @remarks
|
|
22
22
|
* Clears only the `'production'` policy so a failed or force export cannot
|
|
23
|
-
* reuse staged graph output.
|
|
23
|
+
* reuse staged graph output. Also sets `productionBrowserGraphsSealed` to false so a
|
|
24
|
+
* retry of `ecopages build` can still emit graphs. Development session records are left intact.
|
|
24
25
|
*/
|
|
25
26
|
export declare function clearProductionPageBrowserGraphSession(appConfig: EcoPagesAppConfig): void;
|
|
26
27
|
/**
|
|
@@ -32,5 +33,10 @@ export declare function clearProductionPageBrowserGraphSession(appConfig: EcoPag
|
|
|
32
33
|
* then resolves into `page-browser-graph-session`). Does not persist a disk manifest.
|
|
33
34
|
*/
|
|
34
35
|
export declare function prebuildProductionPageBrowserGraphs(appConfig: EcoPagesAppConfig, routeInstances: readonly ProductionPageBrowserGraphRouteInstance[], routeRendererFactory: PageRendererResolver): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Reuses the browser outputs written by `ecopages build` while `ecopages start` prepares SSR routes.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* A successful restore sets `productionBrowserGraphsSealed` so a missing graph is an error.
|
|
41
|
+
*/
|
|
36
42
|
export declare function prebuildProductionPageBrowserGraphsFromManifest(appConfig: EcoPagesAppConfig, routeRendererFactory: PageRendererResolver): Promise<boolean>;
|
|
@@ -2,9 +2,9 @@ import path from 'node:path';
|
|
|
2
2
|
import { isProductionRuntime } from '../utils/runtime.js';
|
|
3
3
|
import { requireAppRuntime } from '../utils/app-runtime.js';
|
|
4
4
|
import { createPageDependencyInstanceKey } from '../route-renderer/orchestration/page-browser-graph/route-instance-key.js';
|
|
5
|
-
import {
|
|
5
|
+
import { setPrebuiltHtmlPageModuleScriptUrls } from '../html-pages/html-page-module-scripts.js';
|
|
6
6
|
import { buildAppBrowserClient } from '../assets/app-browser-client-build.js';
|
|
7
|
-
import { assertAppBrowserClientOutputsExist, assertAppBrowserClientManifestHtmlOutputsExist, clearAppBrowserClientManifest,
|
|
7
|
+
import { assertAppBrowserClientOutputsExist, assertAppBrowserClientManifestHtmlOutputsExist, clearAppBrowserClientManifest, createNormalizedAppBrowserClientEntryKey, readAppBrowserClientManifest, restoreAppBrowserClientAssets, resolveAppBrowserClientManifestPath, writeAppBrowserClientManifest, } from '../assets/app-browser-client-manifest.js';
|
|
8
8
|
/**
|
|
9
9
|
* Returns whether production should reuse prebuilt Page Browser Graphs.
|
|
10
10
|
*
|
|
@@ -20,10 +20,13 @@ export function shouldPrebuildProductionPageBrowserGraphs() {
|
|
|
20
20
|
*
|
|
21
21
|
* @remarks
|
|
22
22
|
* Clears only the `'production'` policy so a failed or force export cannot
|
|
23
|
-
* reuse staged graph output.
|
|
23
|
+
* reuse staged graph output. Also sets `productionBrowserGraphsSealed` to false so a
|
|
24
|
+
* retry of `ecopages build` can still emit graphs. Development session records are left intact.
|
|
24
25
|
*/
|
|
25
26
|
export function clearProductionPageBrowserGraphSession(appConfig) {
|
|
26
|
-
requireAppRuntime(appConfig)
|
|
27
|
+
const runtime = requireAppRuntime(appConfig);
|
|
28
|
+
runtime.pageBrowserGraphSession.clearPolicyRecords('production');
|
|
29
|
+
runtime.productionBrowserGraphsSealed = false;
|
|
27
30
|
clearAppBrowserClientManifest(appConfig);
|
|
28
31
|
}
|
|
29
32
|
function serializeProductionRouteInstance(instance) {
|
|
@@ -168,17 +171,18 @@ async function prebuildManifestEntriesForRenderer(appConfig, renderer, entries)
|
|
|
168
171
|
});
|
|
169
172
|
}
|
|
170
173
|
}
|
|
171
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* Reuses the browser outputs written by `ecopages build` while `ecopages start` prepares SSR routes.
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* A successful restore sets `productionBrowserGraphsSealed` so a missing graph is an error.
|
|
179
|
+
*/
|
|
172
180
|
export async function prebuildProductionPageBrowserGraphsFromManifest(appConfig, routeRendererFactory) {
|
|
173
181
|
if (!shouldPrebuildProductionPageBrowserGraphs())
|
|
174
182
|
return false;
|
|
175
183
|
const manifest = readAppBrowserClientManifest(appConfig);
|
|
176
184
|
if (!manifest)
|
|
177
185
|
return false;
|
|
178
|
-
assertAppBrowserClientSourcesMatch(appConfig, manifest.sourceFingerprints);
|
|
179
|
-
if (collectHtmlPageModuleScriptBuildInputs(appConfig).fingerprint !== manifest.htmlPageModuleScriptFingerprint) {
|
|
180
|
-
throw new Error(`The app browser build manifest does not match the current HTML Page module scripts. Run \`ecopages build\` again.`);
|
|
181
|
-
}
|
|
182
186
|
assertAppBrowserClientOutputsExist(appConfig, manifest.browserOutputPaths);
|
|
183
187
|
assertAppBrowserClientManifestHtmlOutputsExist(appConfig, manifest.htmlPageModuleScriptUrls);
|
|
184
188
|
setPrebuiltHtmlPageModuleScriptUrls(appConfig, new Map(Object.entries(manifest.htmlPageModuleScriptUrls).map(([filePath, url]) => [
|
|
@@ -188,5 +192,6 @@ export async function prebuildProductionPageBrowserGraphsFromManifest(appConfig,
|
|
|
188
192
|
for (const [renderer, entries] of groupManifestEntriesByRenderer(appConfig, routeRendererFactory, manifest.entries)) {
|
|
189
193
|
await prebuildManifestEntriesForRenderer(appConfig, renderer, entries);
|
|
190
194
|
}
|
|
195
|
+
requireAppRuntime(appConfig).productionBrowserGraphsSealed = true;
|
|
191
196
|
return true;
|
|
192
197
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { EcoPagesAppConfig } from '../config/internal-types.js';
|
|
2
2
|
import type { SitemapConfig, StaticRoute, ErrorPageLoaders } from '../types/contracts.js';
|
|
3
3
|
import type { PageRendererResolver, StaticGenerationRendererResolver } from '../route-renderer/route-renderer.js';
|
|
4
|
-
import type { StaticGenerationRoute, TemplateRoute } from '../router/server/route-registry.js';
|
|
4
|
+
import type { PathExpansion, StaticGenerationRoute, TemplateRoute } from '../router/server/route-registry.js';
|
|
5
5
|
type StaticGenerationRouteSource = {
|
|
6
6
|
listStaticGenerationRoutes(input: {
|
|
7
7
|
runtimeOrigin: string;
|
|
8
8
|
}): Promise<readonly StaticGenerationRoute[]>;
|
|
9
|
+
listDynamicPagePathExpansions?(input: {
|
|
10
|
+
runtimeOrigin: string;
|
|
11
|
+
}): Promise<readonly PathExpansion[]>;
|
|
9
12
|
templateRoutes?: readonly TemplateRoute[];
|
|
10
13
|
};
|
|
11
14
|
type StaticPageRouteRendererFactory = PageRendererResolver;
|
|
@@ -81,7 +84,13 @@ export declare class StaticSiteGenerator {
|
|
|
81
84
|
private startStaticExports;
|
|
82
85
|
private releaseStaticExports;
|
|
83
86
|
private resetStaticGenerationState;
|
|
84
|
-
|
|
87
|
+
/**
|
|
88
|
+
* @remarks
|
|
89
|
+
* An empty `templateRoutes` array still emits explicit views, the Html shell,
|
|
90
|
+
* Layouts, and error pages. When the route source omits `templateRoutes`,
|
|
91
|
+
* listed Pages are used instead.
|
|
92
|
+
*/
|
|
93
|
+
private emitProductionServerModulesForStaticGeneration;
|
|
85
94
|
private executeStaticGenerationBody;
|
|
86
95
|
private finalizeStaticGenerationRun;
|
|
87
96
|
/**
|
|
@@ -96,9 +105,16 @@ export declare class StaticSiteGenerator {
|
|
|
96
105
|
force?: boolean;
|
|
97
106
|
keepGoing?: boolean;
|
|
98
107
|
}): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Loads each explicit static view, resolves its renderer and lists its pathnames.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* A view that fails here is recorded as a page failure and left out of both
|
|
113
|
+
* production browser-graph prebuild and generation.
|
|
114
|
+
*/
|
|
115
|
+
private prepareExplicitStaticRoutes;
|
|
99
116
|
private generateExplicitStaticPages;
|
|
100
117
|
private generateExplicitStaticRoute;
|
|
101
|
-
private planExplicitStaticRoute;
|
|
102
118
|
private createExplicitStaticContents;
|
|
103
119
|
private listExplicitStaticRouteEntries;
|
|
104
120
|
/**
|