@uniweb/core 1.4.2 → 1.4.3
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/package.json +2 -2
- package/src/page-shell-vectors.js +111 -0
- package/src/page-shell.js +38 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vitest": "^4.1.7"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@uniweb/semantic-parser": "~1.
|
|
55
|
+
"@uniweb/semantic-parser": "~1.13.0",
|
|
56
56
|
"@uniweb/theming": "~1.2.1"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The inputs `pageShellFingerprint` renders (`page-shell.js`). Together they reach every branch of
|
|
3
|
+
* `pageShell` and of the `__DATA__` it writes (`dataScript`, `splitPageSections`), so a change to
|
|
4
|
+
* the HTML for any input changes the fingerprint.
|
|
5
|
+
*
|
|
6
|
+
* ⭐ A branch added to `pageShell`, to `data-script.js` or to a helper they call takes a vector here
|
|
7
|
+
* in the same commit. Adding one changes the fingerprint, which is what a new branch needs: a page
|
|
8
|
+
* cached before it was written without it.
|
|
9
|
+
*
|
|
10
|
+
* ⛔ Editing a vector changes the fingerprint too, and a host that keys its cache on it renders
|
|
11
|
+
* every page it cached again. Change one only to reach a branch.
|
|
12
|
+
*
|
|
13
|
+
* Pure data, so a bundle that never calls `pageShellFingerprint` leaves it out — the runtime's
|
|
14
|
+
* browser build, which imports `foundationCssUrl` from `page-shell.js`, carries none of it.
|
|
15
|
+
*/
|
|
16
|
+
export const PAGE_SHELL_VECTORS = [
|
|
17
|
+
// The least a host passes: no name, icon, locale, extensions, entry or preloads.
|
|
18
|
+
{
|
|
19
|
+
content: { config: {}, pages: [{ route: '/', sections: [] }] },
|
|
20
|
+
foundation: { url: '/f/entry.js' },
|
|
21
|
+
runtime: { base: '', manifest: {} },
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
// Every part of the head, and text an author wrote that must be escaped where it lands.
|
|
25
|
+
{
|
|
26
|
+
content: {
|
|
27
|
+
config: {
|
|
28
|
+
name: `Café & "Co" <Ltd>'s`,
|
|
29
|
+
favicon: '/favicon.svg?v=2',
|
|
30
|
+
activeLocale: 'fr',
|
|
31
|
+
extensions: ['https://assets.test/effects/entry.js', { url: '/ext/charts/entry.js' }, null],
|
|
32
|
+
},
|
|
33
|
+
pages: [{ route: '/', sections: [{ type: 'Hero', content: { text: 'a </script><!-- b' } }] }],
|
|
34
|
+
},
|
|
35
|
+
route: '/',
|
|
36
|
+
foundation: {
|
|
37
|
+
url: 'https://assets.test/foundations/acme/site/1.0.0/entry.js',
|
|
38
|
+
cssUrl: 'https://assets.test/foundations/acme/site/1.0.0/custom.css',
|
|
39
|
+
},
|
|
40
|
+
runtime: {
|
|
41
|
+
base: 'https://cdn.test/runtime/1.1.17',
|
|
42
|
+
manifest: {
|
|
43
|
+
entry: '/assets/index-AAA.js',
|
|
44
|
+
preloads: ['assets/setup-BBB.js'],
|
|
45
|
+
importMap: { react: '/_importmap/react.js', '@uniweb/core': '_importmap/core.js' },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// Split content: the served page and a dynamic template keep their sections; a page with an
|
|
51
|
+
// address leaves them, saying whether it has content; one with no address, or no sections, stays.
|
|
52
|
+
{
|
|
53
|
+
content: {
|
|
54
|
+
config: {
|
|
55
|
+
activeLocale: 'en',
|
|
56
|
+
favicon: '/icon.png',
|
|
57
|
+
pageHashes: {
|
|
58
|
+
en: {
|
|
59
|
+
'/': '/_pages/a.json',
|
|
60
|
+
'/about': '/_pages/b.json',
|
|
61
|
+
'/empty': '/_pages/c.json',
|
|
62
|
+
'/docs': '/_pages/d.json',
|
|
63
|
+
'/blog/:slug': '/_pages/e.json',
|
|
64
|
+
'/group': '/_pages/f.json',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
pages: [
|
|
69
|
+
{ route: '/', sections: [{ type: 'Hero' }] },
|
|
70
|
+
{ route: '/about', sections: [{ type: 'Text' }] },
|
|
71
|
+
{ route: '/empty', sections: [] },
|
|
72
|
+
{ route: '/docs', sections: [], hasContent: true },
|
|
73
|
+
{ route: '/blog/:slug', isDynamic: true, sections: [{ type: 'Post' }] },
|
|
74
|
+
{ route: '/contact', sections: [{ type: 'Form' }] },
|
|
75
|
+
{ route: '/group' },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
route: '/',
|
|
79
|
+
foundation: { url: '/f/entry.js' },
|
|
80
|
+
runtime: { base: 'https://cdn.test/runtime/1.1.17/', manifest: { entry: 'assets/index-AAA.js' } },
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// Addresses, but no locale named to read them by, so nothing splits; an empty import map; a
|
|
84
|
+
// relative base.
|
|
85
|
+
{
|
|
86
|
+
content: {
|
|
87
|
+
config: { favicon: '/favicon.ico', pageHashes: { de: { '/': '/_pages/x.json' } } },
|
|
88
|
+
pages: [
|
|
89
|
+
{ route: '/', sections: [{ type: 'Hero' }] },
|
|
90
|
+
{ route: '/about', sections: [{ type: 'Text' }] },
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
route: '/',
|
|
94
|
+
foundation: { url: '/f/entry.js' },
|
|
95
|
+
runtime: { base: '/rt', manifest: { importMap: {} } },
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
// An icon of no known type, addresses but no pages, no foundation entry, no manifest.
|
|
99
|
+
{
|
|
100
|
+
content: { config: { activeLocale: 'en', favicon: '/logo.gif', pageHashes: { en: { '/': '/_pages/y.json' } } } },
|
|
101
|
+
foundation: {},
|
|
102
|
+
runtime: { base: 'https://cdn.test/rt/' },
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// Content with no config, and an empty preload list.
|
|
106
|
+
{
|
|
107
|
+
content: { pages: [] },
|
|
108
|
+
foundation: { url: 'https://assets.test/f/entry.js' },
|
|
109
|
+
runtime: { base: 'https://cdn.test/rt', manifest: { entry: 'assets/index-AAA.js', preloads: [] } },
|
|
110
|
+
},
|
|
111
|
+
]
|
package/src/page-shell.js
CHANGED
|
@@ -12,11 +12,17 @@
|
|
|
12
12
|
* of the site it served could start.
|
|
13
13
|
*
|
|
14
14
|
* Its output is a function of its inputs only — no request, no clock — because a host caches it
|
|
15
|
-
* under a key of publish-time facts, one entry serving a site's every hostname.
|
|
15
|
+
* under a key of publish-time facts, one entry serving a site's every hostname. Besides its inputs,
|
|
16
|
+
* only this code changes it, and `pageShellFingerprint` says when.
|
|
17
|
+
*
|
|
18
|
+
* ⛔ A change to what this writes that an older runtime's browser build cannot read — a new
|
|
19
|
+
* `__DATA__` encoding, a new split shape — is a breaking change: mark the commit `!` and name the
|
|
20
|
+
* oldest runtime that reads the new pages.
|
|
16
21
|
*
|
|
17
22
|
* Zero-dependency leaf, like `data-script.js`, which writes its `__DATA__`.
|
|
18
23
|
*/
|
|
19
24
|
import { dataScript, jsonForScript } from './data-script.js'
|
|
25
|
+
import { PAGE_SHELL_VECTORS } from './page-shell-vectors.js'
|
|
20
26
|
|
|
21
27
|
/**
|
|
22
28
|
* Escape a string for HTML text or a double-quoted attribute value.
|
|
@@ -126,3 +132,34 @@ export function pageShell({ content, route = null, foundation, runtime }) {
|
|
|
126
132
|
'',
|
|
127
133
|
].join('\n')
|
|
128
134
|
}
|
|
135
|
+
|
|
136
|
+
let fingerprint = null
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A fingerprint of what `pageShell` writes: eight hex digits that change whenever the HTML it
|
|
140
|
+
* returns changes, and only then. A host that caches the pages it assembles puts it in its cache
|
|
141
|
+
* key, so a page cached before a change to this module or to `data-script.js` is not served after
|
|
142
|
+
* it, and a change that leaves every page's bytes alone moves nothing.
|
|
143
|
+
*
|
|
144
|
+
* It is worked out from the code that runs — `pageShell` over `PAGE_SHELL_VECTORS`, which reach
|
|
145
|
+
* each of its branches — so it cannot fall behind a change, and there is nothing to bump. A branch
|
|
146
|
+
* added to the shell takes a vector in the same commit (`page-shell-vectors.js`).
|
|
147
|
+
*
|
|
148
|
+
* @returns {string}
|
|
149
|
+
*/
|
|
150
|
+
export function pageShellFingerprint() {
|
|
151
|
+
if (fingerprint === null) {
|
|
152
|
+
fingerprint = fnv1a(PAGE_SHELL_VECTORS.map((input) => pageShell(input)).join('\u0000'))
|
|
153
|
+
}
|
|
154
|
+
return fingerprint
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** FNV-1a, 32 bits, over UTF-16 code units: a fingerprint, not a security property. */
|
|
158
|
+
function fnv1a(text) {
|
|
159
|
+
let hash = 0x811c9dc5
|
|
160
|
+
for (let i = 0; i < text.length; i++) {
|
|
161
|
+
hash ^= text.charCodeAt(i)
|
|
162
|
+
hash = Math.imul(hash, 0x01000193)
|
|
163
|
+
}
|
|
164
|
+
return (hash >>> 0).toString(16).padStart(8, '0')
|
|
165
|
+
}
|