@uniweb/build 1.23.7 → 1.23.9

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 CHANGED
@@ -161,9 +161,10 @@ This processing is a static build's (`uniweb build`, `uniweb export`, `uniweb de
161
161
 
162
162
  **Image processing:**
163
163
  - PNG, JPG, JPEG, GIF → A WebP at quality 85 when it is at least 10% smaller, otherwise the file as it is. Either way it is turned upright as the photo's orientation says, keeps its transparency and animation, and loses its location and camera data. A WebP's colour is converted to sRGB with no profile embedded; a kept file keeps its own
164
- - TIFF, HEIC → Always a WebP, since most browsers can't show them (a HEIC this machine can't decode, and a BMP, is copied as it is, with a warning)
164
+ - TIFF, HEIC → Always a WebP, since most browsers can't show them (a HEIC this machine can't decode is copied without its location and camera data, and a BMP as it is, each with a warning)
165
165
  - WebP → Copied without its location and camera data, or turned and made again when its orientation says to turn it
166
- - SVG, AVIF → Copied as-is
166
+ - AVIF → Copied without its location and camera data, its EXIF and XMP zeroed in place
167
+ - SVG → Copied as-is
167
168
  - `public/` is copied as it is beside these copies, so a photo there keeps its metadata in that copy
168
169
  - All processed assets get content-hashed filenames for cache busting
169
170
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "1.23.7",
3
+ "version": "1.23.9",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -57,12 +57,12 @@
57
57
  "js-yaml": "^4.3.2",
58
58
  "sharp": "^0.35.5",
59
59
  "yaml": "^2.5.0",
60
+ "@uniweb/content-reader": "~1.5.11",
60
61
  "@uniweb/projections": "~1.2.17",
61
- "@uniweb/content-reader": "~1.5.10",
62
- "@uniweb/schemas": "~1.7.4",
63
- "@uniweb/content-writer": "~1.3.2",
64
62
  "@uniweb/semantic-parser": "~1.13.5",
65
- "@uniweb/theming": "~1.3.2"
63
+ "@uniweb/schemas": "~1.7.4",
64
+ "@uniweb/theming": "~1.3.2",
65
+ "@uniweb/content-writer": "~1.3.2"
66
66
  },
67
67
  "optionalDependencies": {
68
68
  "@uniweb/runtime": "~1.6.5"
@@ -0,0 +1,132 @@
1
+ import { PUBLISHED_MOUNT } from '../site/published.js'
2
+
3
+ /**
4
+ * `uniweb dev --published` — the dev server answers a published site's services at addresses of
5
+ * its own and forwards each request to the published address (`../site/published.js` has the
6
+ * contract and how the addresses are made).
7
+ *
8
+ * ⭐ Same-origin on purpose, as `mountDevApi` is. The page asks the dev server, so a session
9
+ * cookie the published site's backend sets is first-party on the dev server's origin, and nothing
10
+ * exercises CORS or third-party-cookie rules the published site does not have. A cookie is kept
11
+ * on the dev server's origin, for its whole path, and loses `Secure` over plain http, where a
12
+ * browser could drop it — except a `__Host-` or `__Secure-` cookie, whose name requires it.
13
+ *
14
+ * ⭐ The request goes as the published page would send it: its method, body and headers, with the
15
+ * published page's origin as its `Origin`, since that is the page a visitor's request comes from.
16
+ * The dev server's own `Host` and `Referer` stay behind, and so does `Accept-Encoding`, because
17
+ * the answer is read whole and handed on decoded. A redirect is handed to the browser as it came.
18
+ *
19
+ * ⚠️ The answer is read whole before it is sent on, so a streamed one arrives at its end.
20
+ *
21
+ * ⛔ Registered SYNCHRONOUSLY, like `mountDevApi`: Vite runs the middleware registered before
22
+ * `configureServer` returns ahead of its SPA fallback, which would answer every address with
23
+ * `index.html`.
24
+ *
25
+ * @param {import('vite').ViteDevServer} server
26
+ * @param {object} options
27
+ * @param {Record<string, string>} options.targets - service → the origin it forwards to (`localServices`)
28
+ * @param {string} options.site - the published page's address
29
+ * @param {string} [options.base] - the dev site's base path, which a request may still carry
30
+ * @param {typeof fetch} [options.fetch] - injected in tests
31
+ * @param {(line: string) => void} [options.log]
32
+ */
33
+ export function mountPublished(server, { targets, site, base = '/', fetch: send = globalThis.fetch, log = console.log }) {
34
+ const siteOrigin = new URL(site).origin
35
+
36
+ server.middlewares.use(async (req, res, next) => {
37
+ const url = withoutBase(req.url || '', base)
38
+ if (!url.startsWith(`${PUBLISHED_MOUNT}/`)) return next()
39
+ const after = url.slice(PUBLISHED_MOUNT.length + 1)
40
+ const cut = after.search(/[/?]/)
41
+ const name = cut === -1 ? after : after.slice(0, cut)
42
+ const rest = cut === -1 ? '/' : after[cut] === '?' ? `/${after.slice(cut)}` : after.slice(cut)
43
+ const origin = targets[name]
44
+ if (!origin) {
45
+ return problem(res, 404, 'No Such Service', `The site published at ${siteOrigin} offers no ${name} service.`)
46
+ }
47
+
48
+ const headers = new Headers()
49
+ for (const [key, value] of Object.entries(req.headers)) {
50
+ if (value === undefined || NOT_SENT.has(key)) continue
51
+ headers.set(key, Array.isArray(value) ? value.join(', ') : value)
52
+ }
53
+ if (headers.has('origin')) headers.set('origin', siteOrigin)
54
+ const init = { method: req.method, headers, redirect: 'manual' }
55
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
56
+ const chunks = []
57
+ for await (const chunk of req) chunks.push(chunk)
58
+ if (chunks.length) init.body = Buffer.concat(chunks)
59
+ }
60
+
61
+ let response
62
+ try {
63
+ response = await send(`${origin}${rest}`, init)
64
+ } catch (err) {
65
+ return problem(res, 502, 'Published Site Unreachable', `Could not reach ${origin}: ${err?.cause?.message || err.message}`)
66
+ }
67
+ res.statusCode = response.status
68
+ response.headers.forEach((value, key) => {
69
+ if (key !== 'set-cookie' && !NOT_RETURNED.has(key)) res.setHeader(key, value)
70
+ })
71
+ const cookies = response.headers.getSetCookie?.() ?? []
72
+ if (cookies.length) {
73
+ const secure = Boolean(req.socket?.encrypted)
74
+ res.setHeader('set-cookie', cookies.map((cookie) => firstPartyCookie(cookie, { secure })))
75
+ }
76
+ // Bytes, never text: an answer may be an image or a file.
77
+ const bytes = Buffer.from(await response.arrayBuffer())
78
+ res.end(bytes.length ? bytes : undefined)
79
+ })
80
+
81
+ const names = Object.keys(targets)
82
+ log(
83
+ names.length
84
+ ? `[dev-published] ${names.map((n) => `${PUBLISHED_MOUNT}/${n}`).join(', ')} → the site as published at ${siteOrigin}`
85
+ : `[dev-published] the site published at ${siteOrigin} offers no service with an address`
86
+ )
87
+ }
88
+
89
+ /**
90
+ * A cookie the published site set, for the dev server's origin: no `Domain`, the whole path, and,
91
+ * over plain http, no `Secure` — so `SameSite=None`, which needs it, becomes `Lax`, the
92
+ * first-party default — unless its name requires `Secure`.
93
+ *
94
+ * @param {string} cookie - one `Set-Cookie` value
95
+ * @param {{ secure: boolean }} options - whether the dev server is reached over https
96
+ * @returns {string}
97
+ */
98
+ export function firstPartyCookie(cookie, { secure }) {
99
+ const [pair, ...attributes] = cookie.split(';')
100
+ const name = pair.split('=')[0].trim()
101
+ const keepSecure = secure || /^__(Host|Secure)-/.test(name)
102
+ const kept = []
103
+ for (const raw of attributes) {
104
+ const attribute = raw.trim()
105
+ const key = attribute.split('=')[0].trim().toLowerCase()
106
+ if (!attribute || key === 'domain' || key === 'path') continue
107
+ if (!keepSecure && (key === 'secure' || key === 'partitioned')) continue
108
+ if (!keepSecure && key === 'samesite' && /=\s*none\s*$/i.test(attribute)) {
109
+ kept.push('SameSite=Lax')
110
+ continue
111
+ }
112
+ kept.push(attribute)
113
+ }
114
+ return [pair.trim(), 'Path=/', ...kept].join('; ')
115
+ }
116
+
117
+ const HOP_BY_HOP = ['connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', 'te', 'trailer', 'transfer-encoding', 'upgrade']
118
+ const NOT_SENT = new Set([...HOP_BY_HOP, 'host', 'referer', 'content-length', 'accept-encoding'])
119
+ // `fetch` hands the body on decoded, so its length and encoding are no longer the answer's.
120
+ const NOT_RETURNED = new Set([...HOP_BY_HOP, 'content-length', 'content-encoding'])
121
+
122
+ function problem(res, status, title, detail) {
123
+ res.statusCode = status
124
+ res.setHeader('content-type', 'application/problem+json')
125
+ res.end(JSON.stringify({ status, title, detail }))
126
+ }
127
+
128
+ /** A request may still carry the site's base path; the address is the dev server's own. */
129
+ function withoutBase(url, base) {
130
+ const prefix = String(base || '/').replace(/\/+$/, '')
131
+ return prefix && (url === prefix || url.startsWith(`${prefix}/`)) ? url.slice(prefix.length) || '/' : url
132
+ }
@@ -24,6 +24,13 @@
24
24
  * A dev rebuild never ships: it empties `dist/` and writes no `entry-ssr.js`,
25
25
  * so `register` builds again before it uploads (`foundationNeedsBuild`).
26
26
  *
27
+ * ⭐ The one working copy that talks to a real backend is one served by
28
+ * `uniweb dev --published` (`../site/published.js`): it is answered by the
29
+ * published site's own services, which hold the types as `register` stored
30
+ * them, so it is stamped as a build is and sends `@acme/x` as the published
31
+ * site does [Diego, 2026-11-15]. It still ships nothing: a dev rebuild stays
32
+ * one.
33
+ *
27
34
  * An author's own `define` for the key wins: it is left untouched.
28
35
  */
29
36
 
@@ -33,6 +40,7 @@ import { loadFoundationConfig } from '../schema.js'
33
40
  import { foundationNameOf, splitFoundationName } from '../foundation-name.js'
34
41
  import { resolveFoundationSrcDir } from '../utils/foundation-source-root.js'
35
42
  import { hasDevRebuildMarker } from './dev-rebuild.js'
43
+ import { PUBLISHED_ENV } from '../site/published.js'
36
44
 
37
45
  export const FOUNDATION_SCOPE_KEY = '__FOUNDATION_SCOPE__'
38
46
 
@@ -48,7 +56,7 @@ export function foundationScopeDefine({ foundationDir } = {}) {
48
56
  name: 'uniweb:foundation-scope',
49
57
  async config(config, { command }) {
50
58
  if (config.define && FOUNDATION_SCOPE_KEY in config.define) return
51
- const workingCopy = command === 'serve' || hasDevRebuildMarker(config)
59
+ const workingCopy = (command === 'serve' || hasDevRebuildMarker(config)) && !process.env[PUBLISHED_ENV]
52
60
  const scope = workingCopy ? null : await foundationScope(foundationDir ?? config.root ?? process.cwd())
53
61
  return { define: { [FOUNDATION_SCOPE_KEY]: JSON.stringify(scope) } }
54
62
  },
@@ -18,7 +18,7 @@ import { existsSync } from 'node:fs'
18
18
  import { join, dirname } from 'node:path'
19
19
  import { createHash } from 'node:crypto'
20
20
 
21
- const MANIFEST_FILENAME = '.manifest.json'
21
+ import { FREEFORM_MANIFEST as MANIFEST_FILENAME } from './locales.js'
22
22
 
23
23
  /**
24
24
  * Compute a hash of a ProseMirror document for staleness detection
@@ -16,6 +16,36 @@ import { normalizeLanguageList, resolveDefaultLocale } from '@uniweb/core/locale
16
16
  export const KEPT_FILE = '_kept.json'
17
17
  export const RESERVED_LOCALE_FILES = new Set(['manifest.json', '_memory.json', KEPT_FILE])
18
18
 
19
+ // Where record translations are kept, inside the locales directory: `locales/records/`.
20
+ export const RECORD_LOCALES_DIR = 'records'
21
+
22
+ // A free-form language's record of the source each of its bodies was translated from:
23
+ // `locales/freeform/{locale}/.manifest.json`.
24
+ export const FREEFORM_MANIFEST = '.manifest.json'
25
+
26
+ /**
27
+ * The files in a site's translations directory that are its tools' own, never part of what a push
28
+ * sends, as paths from the site (POSIX; `*` stands for a language): each reserved file but
29
+ * `_kept.json`, which a push sends back, beside the site's translations and its records', and each
30
+ * free-form language's manifest.
31
+ *
32
+ * ⭐ A CHANGE TO ONE IS NOT A CHANGE THE BACKEND LACKS. `i18n extract` refreshes `manifest.json`, and
33
+ * a commit that only did that was taken for a records change: a pull's merge then started from an older
34
+ * sync point than the one the backend named, and a teammate's own published work came back as the
35
+ * app's, in conflict with itself (measured on a site's pull, 2026-11-12).
36
+ *
37
+ * @param {string} [dir] - the translations directory, from the site
38
+ * @returns {string[]}
39
+ */
40
+ export function unsentTranslationFiles(dir = 'locales') {
41
+ const own = [...RESERVED_LOCALE_FILES].filter((f) => f !== KEPT_FILE)
42
+ return [
43
+ ...own.map((f) => `${dir}/${f}`),
44
+ ...own.map((f) => `${dir}/${RECORD_LOCALES_DIR}/${f}`),
45
+ `${dir}/freeform/*/${FREEFORM_MANIFEST}`,
46
+ ]
47
+ }
48
+
19
49
  /**
20
50
  * The locales a directory holds translations for — one per `<locale>.json` — sorted.
21
51
  *
@@ -13,7 +13,7 @@
13
13
  */
14
14
 
15
15
  import { readFile, writeFile, readdir, mkdir, rm } from 'fs/promises'
16
- import { RESERVED_LOCALE_FILES } from './locales.js'
16
+ import { RESERVED_LOCALE_FILES, RECORD_LOCALES_DIR } from './locales.js'
17
17
  import { existsSync } from 'node:fs'
18
18
  import { join, resolve, sep } from 'node:path'
19
19
  import { DATA_DIR, resolveDefaultLocale } from '@uniweb/core'
@@ -55,7 +55,7 @@ import {
55
55
  // ⚠️ `RECORD_LOCALES_DIR`, and not `RECORDS_DIR`, since 2026-09-21: that name is the
56
56
  // site's own `records/` directory now (`site/entity-pool.js`), and this one is
57
57
  // `locales/records/` — two directories, one word, so the constant says which.
58
- export const RECORD_LOCALES_DIR = 'records'
58
+ export { RECORD_LOCALES_DIR }
59
59
 
60
60
  // ---------------------------------------------------------------------------
61
61
  // A record's model — what a push sends it as
@@ -15,17 +15,17 @@
15
15
  * kept but needs turning is converted instead, so no picture a page draws depends on a tag to
16
16
  * stand up.
17
17
  * 5. **Location and camera data are dropped**, from a kept file too, which loses them without being
18
- * re-encoded (`withoutPrivateMetadata`). Its orientation stays, alone, since that is what turns
19
- * it. **A WebP's colour is converted to sRGB, with no profile embedded**, as a host converting a
18
+ * re-encoded (`withoutPrivateMetadata`), a HEIC this machine can't decode and an AVIF included.
19
+ * Its orientation stays, alone, since that is what turns it. **A WebP's colour is converted to sRGB, with no profile embedded**, as a host converting a
20
20
  * picture that wasn't prepared does, so the two agree: a phone's Display P3 photo keeps its
21
21
  * colours, managed into sRGB, and loses the wider gamut. A kept file keeps its own profile, since
22
22
  * it isn't re-encoded and dropping the profile alone would shift its colours.
23
23
  * 6. **No size cap.** A prepared file is the only copy kept, so it keeps its pixels.
24
24
  * 7. **Which files.** JPEG, PNG, GIF, TIFF, HEIC and BMP are converted under the keep test. A WebP is
25
- * kept without its location and camera data, unless its EXIF says to turn it. SVG, ICO and AVIF
26
- * are left as they are, an AVIF's metadata included. A file this machine can't decode (HEIC with
27
- * HEVC, and BMP, which sharp's builds don't read) is left as it is and reported `unreadable`, for
28
- * its caller to say so.
25
+ * kept without its location and camera data, unless its EXIF says to turn it, and so is an AVIF.
26
+ * SVG and ICO are left as they are. A file this machine can't decode (HEIC with HEVC, and BMP,
27
+ * which sharp's builds don't read) is kept without its private data and reported `unreadable`,
28
+ * for its caller to say so.
29
29
  * 8. **A picture other software fetches by its address** (`keepFormat`: a favicon, a touch icon, a
30
30
  * social image) stays in its format, since a home screen takes a PNG and a link preview a JPEG or
31
31
  * PNG. It only loses its location and camera data.
@@ -49,7 +49,7 @@ export const IMAGE_RULE = Object.freeze({
49
49
  })
50
50
 
51
51
  /** Formats the rule prepares, by extension. */
52
- const PREPARED = new Set(['jpg', 'jpeg', 'png', 'gif', 'tif', 'tiff', 'heic', 'heif', 'bmp', 'webp'])
52
+ const PREPARED = new Set(['jpg', 'jpeg', 'png', 'gif', 'tif', 'tiff', 'heic', 'heif', 'bmp', 'webp', 'avif'])
53
53
 
54
54
  /** Formats every browser draws: kept when the WebP saves too little. */
55
55
  const DRAWN_EVERYWHERE = new Set(['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'])
@@ -82,7 +82,8 @@ export async function prepareImage(bytes, ext, { quality = IMAGE_RULE.quality, k
82
82
  const kind = extOf(ext)
83
83
  if (!PREPARED.has(kind)) return { bytes, ext: kind, converted: false }
84
84
  const kept = () => ({ bytes: withoutPrivateMetadata(bytes, kind), ext: kind, converted: false })
85
- if (keepFormat || (kind === 'png' && isAnimatedPng(bytes))) return kept()
85
+ // An AVIF is drawn everywhere already, and its turn is a property of the image, not a tag.
86
+ if (keepFormat || kind === 'avif' || (kind === 'png' && isAnimatedPng(bytes))) return kept()
86
87
 
87
88
  let meta
88
89
  let webp
@@ -101,7 +102,7 @@ export async function prepareImage(bytes, ext, { quality = IMAGE_RULE.quality, k
101
102
  // nothing here could read, is reported, since a page may not show it.
102
103
  const drawn = DRAWN_EVERYWHERE.has(kind)
103
104
  return {
104
- bytes: drawn ? withoutPrivateMetadata(bytes, kind) : bytes,
105
+ bytes: withoutPrivateMetadata(bytes, kind),
105
106
  ext: kind,
106
107
  converted: false,
107
108
  ...(drawn && meta ? {} : { unreadable: true }),
@@ -126,6 +127,8 @@ export async function prepareImage(bytes, ext, { quality = IMAGE_RULE.quality, k
126
127
  * after the image data turns nothing in a browser, so its orientation goes with it.
127
128
  * - **WebP:** drops its `EXIF` and `XMP ` chunks and the flags that announce them, and keeps every
128
129
  * other chunk.
130
+ * - **HEIC, AVIF:** zeroes the bytes of its EXIF and XMP items where they lie (`stripHeif`), every
131
+ * size and offset unchanged, its colour profile and turn untouched.
129
132
  * - Anything else, or a file that doesn't parse as its format, is returned as it is.
130
133
  *
131
134
  * @param {Buffer} bytes
@@ -137,6 +140,7 @@ export function withoutPrivateMetadata(bytes, ext) {
137
140
  if (kind === 'jpg' || kind === 'jpeg') return stripJpeg(bytes) ?? bytes
138
141
  if (kind === 'png') return stripPng(bytes) ?? bytes
139
142
  if (kind === 'webp') return stripWebp(bytes) ?? bytes
143
+ if (kind === 'heic' || kind === 'heif' || kind === 'avif') return stripHeif(bytes) ?? bytes
140
144
  return bytes
141
145
  }
142
146
 
@@ -312,6 +316,131 @@ function isAnimatedPng(buf) {
312
316
  return animated
313
317
  }
314
318
 
319
+ // ── HEIF: HEIC and AVIF ──────────────────────────────────────────────────────────────────────────
320
+
321
+ /** An ISOBMFF box at `at`: its type and where its payload starts and ends, or null past `end`. */
322
+ function isoBox(buf, at, end) {
323
+ if (at + 8 > end) return null
324
+ let size = buf.readUInt32BE(at)
325
+ let head = 8
326
+ if (size === 1) {
327
+ if (at + 16 > end) return null
328
+ size = Number(buf.readBigUInt64BE(at + 8))
329
+ head = 16
330
+ } else if (size === 0) size = end - at
331
+ if (size < head || at + size > end) return null
332
+ return { type: buf.toString('latin1', at + 4, at + 8), start: at + head, end: at + size }
333
+ }
334
+
335
+ /** Every box between `from` and `end`, or null when one doesn't parse. */
336
+ function isoBoxes(buf, from, end) {
337
+ const boxes = []
338
+ for (let at = from; at < end; ) {
339
+ const box = isoBox(buf, at, end)
340
+ if (!box) return null
341
+ boxes.push(box)
342
+ at = box.end
343
+ }
344
+ return boxes
345
+ }
346
+
347
+ /** An unsigned number of 0, 2, 4 or 8 bytes, as an `iloc` box sizes its fields. */
348
+ function readSized(buf, at, size) {
349
+ if (size === 0) return 0
350
+ if (size === 2) return buf.readUInt16BE(at)
351
+ if (size === 4) return buf.readUInt32BE(at)
352
+ if (size === 8) return Number(buf.readBigUInt64BE(at))
353
+ return NaN
354
+ }
355
+
356
+ /** The ids of a HEIF file's private items: its EXIF, and XMP stored as a `mime` item. */
357
+ function privateHeifItems(buf, iinf) {
358
+ const version = buf[iinf.start]
359
+ const first = iinf.start + 4 + (version === 0 ? 2 : 4)
360
+ const entries = isoBoxes(buf, first, iinf.end)
361
+ if (!entries) return null
362
+ const ids = new Set()
363
+ for (const infe of entries) {
364
+ if (infe.type !== 'infe') continue
365
+ const v = buf[infe.start]
366
+ if (v < 2) continue // versions 0 and 1 name no item type
367
+ let at = infe.start + 4
368
+ const id = v === 2 ? buf.readUInt16BE(at) : buf.readUInt32BE(at)
369
+ at += (v === 2 ? 2 : 4) + 2 // the id, then its protection index
370
+ const type = buf.toString('latin1', at, at + 4)
371
+ at += 4
372
+ const nameEnd = buf.indexOf(0, at)
373
+ if (nameEnd < 0 || nameEnd >= infe.end) continue
374
+ if (type === 'Exif') ids.add(id)
375
+ if (type === 'mime') {
376
+ const contentEnd = buf.indexOf(0, nameEnd + 1)
377
+ const content = buf.toString('latin1', nameEnd + 1, contentEnd < 0 ? infe.end : Math.min(contentEnd, infe.end))
378
+ if (/xmp|rdf\+xml/i.test(content)) ids.add(id)
379
+ }
380
+ }
381
+ return ids
382
+ }
383
+
384
+ /**
385
+ * A HEIF file (a HEIC or an AVIF) without its EXIF and XMP. Each is an item whose bytes lie in
386
+ * `mdat` or `idat`, where `iloc` says; those bytes are zeroed in place, so no size or offset moves.
387
+ * The picture's colour profile (`colr`) and turn (`irot`) are properties of the image item, which
388
+ * this leaves alone, and an item's EXIF is not what turns a HEIF picture. Null when the file doesn't
389
+ * parse, or an item's place can't be read.
390
+ */
391
+ function stripHeif(buf) {
392
+ const top = isoBoxes(buf, 0, buf.length)
393
+ const meta = top?.find((b) => b.type === 'meta')
394
+ if (!meta) return null
395
+ const children = isoBoxes(buf, meta.start + 4, meta.end)
396
+ if (!children) return null
397
+ const iinf = children.find((b) => b.type === 'iinf')
398
+ const iloc = children.find((b) => b.type === 'iloc')
399
+ const idat = children.find((b) => b.type === 'idat')
400
+ if (!iinf || !iloc) return null
401
+ const ids = privateHeifItems(buf, iinf)
402
+ if (!ids) return null
403
+ if (ids.size === 0) return buf
404
+
405
+ const out = Buffer.from(buf)
406
+ const version = buf[iloc.start]
407
+ let at = iloc.start + 4
408
+ const offsetSize = buf[at] >> 4
409
+ const lengthSize = buf[at] & 15
410
+ const baseSize = buf[at + 1] >> 4
411
+ const indexSize = version === 1 || version === 2 ? buf[at + 1] & 15 : 0
412
+ at += 2
413
+ const wide = version === 2
414
+ const count = wide ? buf.readUInt32BE(at) : buf.readUInt16BE(at)
415
+ at += wide ? 4 : 2
416
+ for (let i = 0; i < count; i++) {
417
+ if (at > iloc.end) return null
418
+ const id = wide ? buf.readUInt32BE(at) : buf.readUInt16BE(at)
419
+ at += wide ? 4 : 2
420
+ const method = version === 1 || version === 2 ? buf.readUInt16BE(at) & 15 : 0
421
+ if (version === 1 || version === 2) at += 2
422
+ at += 2 // the data reference index
423
+ const base = readSized(buf, at, baseSize)
424
+ at += baseSize
425
+ const extents = buf.readUInt16BE(at)
426
+ at += 2
427
+ for (let e = 0; e < extents; e++) {
428
+ at += indexSize
429
+ const offset = readSized(buf, at, offsetSize)
430
+ at += offsetSize
431
+ const length = readSized(buf, at, lengthSize)
432
+ at += lengthSize
433
+ if (!ids.has(id)) continue
434
+ // Where the item's bytes are: in the file (method 0) or in `idat` (method 1). A length of 0
435
+ // would mean "to the end", which is never a metadata item's, so it is left alone.
436
+ const from = method === 0 ? base + offset : method === 1 && idat ? idat.start + base + offset : NaN
437
+ if (!Number.isFinite(from) || !(length > 0) || from + length > out.length) return null
438
+ out.fill(0, from, from + length)
439
+ }
440
+ }
441
+ return out
442
+ }
443
+
315
444
  // ── WebP ─────────────────────────────────────────────────────────────────────────────────────────
316
445
 
317
446
  /** The flags in a `VP8X` chunk that say an `EXIF` and an `XMP ` chunk follow. */
@@ -42,6 +42,7 @@ import { libraryImports } from '../foundation/library-imports.js'
42
42
  import { copiedLibraries, copiedLibrariesWarning } from '../foundation/libraries.js'
43
43
  import { workspaceRootOf } from './workspace-extension.js'
44
44
  import { readPreview, PREVIEW_ENV } from './preview.js'
45
+ import { PUBLISHED_ENV } from './published.js'
45
46
  import { previewMediaPlugin } from './preview-media.js'
46
47
  import { previewDirectoryIndexPlugin } from './preview-directory-index.js'
47
48
  import { devServerRecordPlugin, requestedDevPort } from './dev-server.js'
@@ -439,6 +440,22 @@ export async function defineSiteConfig(options = {}) {
439
440
  }))
440
441
  }
441
442
 
443
+ if (process.env[PUBLISHED_ENV]) {
444
+ // ⛔ NOR DOES A PUBLISHED SITE'S. `uniweb dev --published` hands its dev server the
445
+ // services a published page carries, for that server alone (`./published.js`).
446
+ plugins.push({
447
+ name: 'uniweb:published-only',
448
+ config(_config, env) {
449
+ if (env.command === 'build') {
450
+ throw new Error(
451
+ `[site] ${PUBLISHED_ENV} is what \`uniweb dev --published\` read from a published ` +
452
+ 'site, for one dev server, and a build does not take it. Unset it to build.'
453
+ )
454
+ }
455
+ }
456
+ })
457
+ }
458
+
442
459
  if (preview) {
443
460
  // ⛔ A PREVIEW'S ANSWER NEVER REACHES A BUILT ARTIFACT. Where the backend serves a
444
461
  // version is decided at publish and read for one preview (`./preview.js`); written into
@@ -25,6 +25,7 @@ import { resolveQueriesConfig, toConfigQueries, dataKeyTyping, foundationSection
25
25
  import { isSectionKey } from '@uniweb/schemas/section'
26
26
  import { parseNumericPrefix, compareByNumericPrefix } from '../utils/numeric-prefix.js'
27
27
  import { isMarkdownFile, isIgnoredFolder } from '../utils/content-files.js'
28
+ import { sectionFilesNamedTwice, describeSectionsNamedTwice } from './section-files.js'
28
29
  import { readLayoutFolder, DEFAULT_LAYOUT, layoutAreaRoute } from './layout-folder.js'
29
30
  import { mountEntriesOf } from './mount-entries.js'
30
31
  import { basename, join, parse, relative, resolve, sep } from 'node:path'
@@ -1626,6 +1627,17 @@ async function processPage(pagePath, pageName, siteRoot, { isIndex = false, pare
1626
1627
  }
1627
1628
  }
1628
1629
 
1630
+ // ⛔ One section, one file: `1-lost.md` beside `lost.md` is the section `lost` twice, which a merge
1631
+ // leaves without a word (`section-files.js`). A build draws both, so it says so and goes on, as a
1632
+ // build does; a push refuses the page (`sync-package.js`), and a pull names it after its merge.
1633
+ const twice = sectionFilesNamedTwice(await readdir(pagePath))
1634
+ if (twice.length) {
1635
+ console.warn(
1636
+ `[content-collector] ${describeSectionsNamedTwice(relative(siteRoot, pagePath).split(sep).join('/'), twice)}. ` +
1637
+ 'A number orders a section and never names it, so a push refuses this page: give each its own name, or keep one.'
1638
+ )
1639
+ }
1640
+
1629
1641
  let hierarchicalSections = []
1630
1642
  let pageAssetCollection = {
1631
1643
  assets: {},
package/src/site/index.js CHANGED
@@ -10,6 +10,7 @@ export { siteContentPlugin } from './plugin.js'
10
10
  export { defineSiteConfig, readSiteConfig, default } from './config.js'
11
11
  // What `uniweb dev` hands the dev server of a site a backend holds (`./preview.js`).
12
12
  export { PREVIEW_ENV, encodePreview, readPreview } from './preview.js'
13
+ export { PUBLISHED_ENV, encodePublished, readPublished } from './published.js'
13
14
  // Where a site's dev server listens, as it states it, for `uniweb dev` (`./dev-server.js`).
14
15
  export { DEV_PORT_ENV, DEV_RECORD_ENV, runningDevServer, stopDevServer } from './dev-server.js'
15
16
  // Where a statically built site lives, as its deploy target or author states it (`./site-address.js`).
@@ -59,4 +60,6 @@ export {
59
60
  mergeDataIntoContent
60
61
  } from './data-fetcher.js'
61
62
  export { loadDeployYml, resolveTarget, resolvePublishTarget } from './deploy-config.js'
63
+ // One section, one file: what a page holds twice, for the build and a pull to say alike.
64
+ export { sectionFilesNamedTwice, describeSectionsNamedTwice } from './section-files.js'
62
65
  export { recordLastDeploy, recordTarget, forgetDeploys, forgetDeployYml, retireDeployYmlKeys } from './deploy-config-writer.js'
@@ -244,6 +244,9 @@ import { dataBlockModels, NO_DATA_MODELS } from '../i18n/data-models.js'
244
244
  import { refuseSearchOption } from './search-declared.js'
245
245
  import { mountDevApi } from '../dev/api-mount.js'
246
246
  import { mountDevSubmit } from '../dev/submit-mount.js'
247
+ import { mountPublished } from '../dev/published-mount.js'
248
+ import { readPublished, localServices, queriesInFull } from './published.js'
249
+ import { foundationScope } from '../foundation/scope-define.js'
247
250
 
248
251
  /**
249
252
  * A shell carrying the page's look by the runtime's own rule (`@uniweb/runtime/ssr`, which a
@@ -402,12 +405,24 @@ export function siteContentPlugin(options = {}) {
402
405
  // never in a build.
403
406
  let devApiAddress = null
404
407
  let devSubmitAddress = null
408
+ // Under `uniweb dev --published`, the published site's services instead, at the dev server's
409
+ // own addresses (`./published.js`): the host tier, as the published page carries it.
410
+ let publishedServices = null
411
+ // ...and the scope of the foundation's name, which names the site's queries in full there.
412
+ let publishedScope = null
405
413
  /**
406
414
  * The dev payload names those addresses as the site's `backend` and `submit` services:
407
415
  * the site tier, which `resolveService` reads when no host speaks. A build never gets
408
- * here with one.
416
+ * here with one. Under `--published` the dev server is the host, and its payload carries
417
+ * the host's block, as a published page does, and its queries with their types named in
418
+ * full, as the published page holds them (`queriesInFull`).
409
419
  */
410
420
  const withDevServices = (content) => {
421
+ if (publishedServices && content?.config) {
422
+ content.config.services = publishedServices
423
+ content.config.queries = queriesInFull(content.config.queries, publishedScope)
424
+ return content
425
+ }
411
426
  if (devApiAddress && content?.config) content.config.backend = devApiAddress
412
427
  if (devSubmitAddress && content?.config) content.config.submit = devSubmitAddress
413
428
  return content
@@ -659,6 +674,7 @@ export function siteContentPlugin(options = {}) {
659
674
  viteRoot = config.root
660
675
  isProduction = config.command === 'build'
661
676
  basePath = config.base || '/'
677
+ if (!isProduction && foundationPath && readPublished()) publishedScope = await foundationScope(foundationPath)
662
678
 
663
679
  // In dev mode, process collections early so JSON files exist before server starts
664
680
  // This runs before configureServer, ensuring data is available immediately
@@ -756,20 +772,32 @@ export function siteContentPlugin(options = {}) {
756
772
  // ⚠️ Synchronous on purpose — see mountDevApi. An await here and the
757
773
  // middleware lands after Vite's SPA fallback, which answers the API with
758
774
  // index.html and says nothing about why.
759
- try {
760
- devApiAddress = mountDevApi(devServer, { root: resolvedSitePath })
761
- } catch (err) {
762
- console.error(`[dev-api] ${err.message}`)
763
- }
775
+ //
776
+ // ⭐ `uniweb dev --published` answers every service the published site has with that
777
+ // site's own, forwarded (`../dev/published-mount.js`), so neither the mock nor the
778
+ // local form handler is mounted: the page talks to what visitors of the published site
779
+ // talk to. A handed value that says nothing usable stops the server here.
780
+ const published = readPublished()
781
+ if (published) {
782
+ const { services, targets } = localServices(published)
783
+ publishedServices = services
784
+ mountPublished(devServer, { targets, site: published.site, base: basePath })
785
+ } else {
786
+ try {
787
+ devApiAddress = mountDevApi(devServer, { root: resolvedSitePath })
788
+ } catch (err) {
789
+ console.error(`[dev-api] ${err.message}`)
790
+ }
764
791
 
765
- // A site's forms, taken locally in development when site.yml asks its host for
766
- // them (`services: { submit: true }`): the dev server is that host here, so a form
767
- // shows and can be sent before the site is published. Synchronous for the same
768
- // reason as the mount above.
769
- try {
770
- devSubmitAddress = mountDevSubmit(devServer, { root: resolvedSitePath, base: basePath })
771
- } catch (err) {
772
- console.error(`[dev-submit] ${err.message}`)
792
+ // A site's forms, taken locally in development when site.yml asks its host for
793
+ // them (`services: { submit: true }`): the dev server is that host here, so a form
794
+ // shows and can be sent before the site is published. Synchronous for the same
795
+ // reason as the mount above.
796
+ try {
797
+ devSubmitAddress = mountDevSubmit(devServer, { root: resolvedSitePath, base: basePath })
798
+ } catch (err) {
799
+ console.error(`[dev-submit] ${err.message}`)
800
+ }
773
801
  }
774
802
 
775
803
  // A site-relative workspace extension (`/effects/entry.js`) is served from
@@ -0,0 +1,162 @@
1
+ /**
2
+ * THE SITE AS PUBLISHED — what `uniweb dev --published` read from a published site, handed to the
3
+ * one dev server it starts.
4
+ *
5
+ * A site's services — its own `backend`, its `records`, its forms — are its host's to answer once
6
+ * the site is published, at addresses the host chooses. `uniweb dev --published` serves the working
7
+ * copy, its foundation and pages with live reload, against those services. `uniweb dev` reads the
8
+ * host's answer from the published page itself (`__DATA__`, `content.config.services`) and passes
9
+ * it in `UNIWEB_PUBLISHED`, as JSON:
10
+ *
11
+ * { site: 'https://…/', the published page the services were read from
12
+ * backend: 'https://…', the backend the site is published from
13
+ * base: '/' | null, that page's `config.base`
14
+ * services: { backend: '/_api', … } } the host's block, as the page carries it
15
+ *
16
+ * The dev server then plays the host (`../dev/published-mount.js`): its payload carries that block
17
+ * with each address replaced by one of its own, under `PUBLISHED_MOUNT`, and it forwards a request
18
+ * for one of those to the published address. The page sees one origin, so a sign-in cookie is
19
+ * first-party, as it is on the published site, and a query is answered by the site's records
20
+ * service, the entries its public queries open included, as a visitor's is.
21
+ *
22
+ * ⭐ Read, never composed. A host owns its services' addresses and states them in the page it
23
+ * serves (`@uniweb/core/services`), so one is resolved as the published page's runtime resolves it
24
+ * (`resolveServiceUrl`, with that page's base) and against that page's address, and nothing here
25
+ * knows a route.
26
+ *
27
+ * ⛔ Nothing keeps it. It lives as long as the dev server, as a preview does (`./preview.js`), and a
28
+ * build handed it refuses it (`./config.js`), so a published site's addresses never reach a built
29
+ * artifact.
30
+ */
31
+ import { readEndpoint, resolveServiceUrl } from '@uniweb/core/services'
32
+
33
+ /** The variable `uniweb dev --published` sets for the dev server it starts. */
34
+ export const PUBLISHED_ENV = 'UNIWEB_PUBLISHED'
35
+
36
+ /** Where the dev server answers the published site's services: `/_published/<service>/…`. */
37
+ export const PUBLISHED_MOUNT = '/_published'
38
+
39
+ /**
40
+ * The variable's value.
41
+ *
42
+ * @param {{ site: string, backend: string, base?: string|null, services: object }} published
43
+ * @returns {string}
44
+ */
45
+ export function encodePublished({ site, backend, base = null, services }) {
46
+ return JSON.stringify({ site, backend, base: typeof base === 'string' ? base : null, services })
47
+ }
48
+
49
+ /**
50
+ * What a dev server was handed, or null when it was handed nothing.
51
+ *
52
+ * @param {Record<string, string|undefined>} [env]
53
+ * @returns {{ site: string, backend: string, base: string|null, services: object }|null}
54
+ * @throws {Error} when the variable is set and says nothing usable: a dev server told to use a
55
+ * published site's services must not start on its own mock instead
56
+ */
57
+ export function readPublished(env = process.env) {
58
+ const raw = env[PUBLISHED_ENV]
59
+ if (!raw) return null
60
+ let given = null
61
+ try {
62
+ given = JSON.parse(raw)
63
+ } catch {
64
+ // reported below
65
+ }
66
+ if (!isHttpUrl(given?.site) || !isHttpUrl(given?.backend) || !isPlainObject(given?.services)) {
67
+ throw new Error(
68
+ `${PUBLISHED_ENV} holds no published site (${JSON.stringify(raw).slice(0, 120)}). ` +
69
+ 'It is set by `uniweb dev --published`; run that rather than setting it.'
70
+ )
71
+ }
72
+ return {
73
+ site: new URL(given.site).href,
74
+ backend: new URL(given.backend).origin,
75
+ base: typeof given.base === 'string' ? given.base : null,
76
+ services: given.services,
77
+ }
78
+ }
79
+
80
+ /**
81
+ * The services block the dev payload carries — the host's, each address replaced by one of the dev
82
+ * server's — and the origin each service forwards to.
83
+ *
84
+ * An address keeps everything after its origin as written, a `{locale}` slot included, under
85
+ * `/_published/<service>`: the published `records` at `/_query/{locale}` becomes
86
+ * `/_published/records/_query/{locale}`, and a request for `/_published/records/_query/fr` goes to
87
+ * `<its origin>/_query/fr`. A service the host names with no address is carried as it is: the host
88
+ * answered, and offered none.
89
+ *
90
+ * @param {{ site: string, base?: string|null, services: object }} published - from `readPublished`
91
+ * @returns {{ services: object, targets: Record<string, string> }} targets: service → origin
92
+ */
93
+ export function localServices({ site, base = null, services }) {
94
+ const local = {}
95
+ const targets = {}
96
+ for (const [name, value] of Object.entries(services)) {
97
+ const endpoint = readEndpoint(value)
98
+ if (!endpoint || !SERVICE_NAME.test(name)) {
99
+ local[name] = value
100
+ continue
101
+ }
102
+ const { origin, rest } = splitAddress(resolveServiceUrl(endpoint, base || ''), site)
103
+ targets[name] = origin
104
+ const address = `${PUBLISHED_MOUNT}/${name}${rest}`
105
+ local[name] = typeof value === 'string' ? address : { ...value, endpoint: address }
106
+ }
107
+ return { services: local, targets }
108
+ }
109
+
110
+ /**
111
+ * The site's queries as the published page carries them: each `schema` the copy spells `@/x` named
112
+ * in full, `<scope>/x`, with the scope of the foundation's name. A backend matches a type's name
113
+ * exactly, and a published page holds its queries as the backend registered them, so a records ask
114
+ * for `@/course` finds nothing there. Every other value is left as written, and so is every query
115
+ * when the foundation's name has no scope.
116
+ *
117
+ * @param {object|undefined} queries - the payload's `config.queries`
118
+ * @param {string|null} scope - `@acme` for `@acme/courses`
119
+ * @returns {object|undefined}
120
+ */
121
+ export function queriesInFull(queries, scope) {
122
+ if (!isPlainObject(queries) || typeof scope !== 'string' || !scope.startsWith('@')) return queries
123
+ const full = {}
124
+ for (const [name, query] of Object.entries(queries)) {
125
+ const schema = query?.schema
126
+ full[name] =
127
+ isPlainObject(query) && typeof schema === 'string' && schema.startsWith('@/')
128
+ ? { ...query, schema: `${scope}/${schema.slice(2)}` }
129
+ : query
130
+ }
131
+ return full
132
+ }
133
+
134
+ // A segment of the dev server's own address, so only a name that is one.
135
+ const SERVICE_NAME = /^[A-Za-z0-9_-]+$/
136
+
137
+ /**
138
+ * An address the runtime would ask, split into the origin it goes to and the rest, kept as written
139
+ * so a `{locale}` slot survives: `new URL` would encode the braces.
140
+ */
141
+ function splitAddress(address, site) {
142
+ const absolute = /^((?:[a-z][a-z0-9+.-]*:)?\/\/[^/?#]*)(.*)$/i.exec(address)
143
+ if (absolute) {
144
+ const [, head, tail] = absolute
145
+ const origin = new URL(head.startsWith('//') ? `${new URL(site).protocol}${head}` : head).origin
146
+ return { origin, rest: tail.startsWith('/') ? tail : `/${tail}` }
147
+ }
148
+ return { origin: new URL(site).origin, rest: address.startsWith('/') ? address : `/${address}` }
149
+ }
150
+
151
+ // ⛔ `new URL('localhost:8080')` parses — as the scheme `localhost:` — so a URL is http(s) or nothing.
152
+ function isHttpUrl(value) {
153
+ try {
154
+ return /^https?:$/.test(new URL(value).protocol)
155
+ } catch {
156
+ return false
157
+ }
158
+ }
159
+
160
+ function isPlainObject(value) {
161
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
162
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * ONE SECTION, ONE FILE.
3
+ *
4
+ * A section's name is its file's stem without the number that orders it (`parseNumericPrefix`):
5
+ * `1-lost.md` holds the section `lost`, and so does `lost.md`. Two such files in one page are one
6
+ * section twice. A merge leaves them side by side without a word when each side added the section
7
+ * under its own name, and the page then shows it twice. A build draws both and says so: a static site
8
+ * has nothing to lose by it, and a site build gives a note, never a gate. A push refuses the page
9
+ * (`uwx/sync-package.js`), since a synced site's sections are known by their names, and a pull names
10
+ * both files the moment its merge leaves them (`uniweb pull`).
11
+ *
12
+ * ⛔ That happened on 2026-11-12. A pull merged a teammate's `pages/404/1-lost.md` with the backend's
13
+ * `pages/404/lost.md`, the same hero, and nothing said so: it was found by looking at the files.
14
+ *
15
+ * A child section keeps its `@` apart: `@card.md` is a child, `card.md` a section of the page's own.
16
+ */
17
+ import { parseNumericPrefix } from '../utils/numeric-prefix.js'
18
+ import { isMarkdownFile } from '../utils/content-files.js'
19
+
20
+ /**
21
+ * The sections a page directory holds in more than one file.
22
+ *
23
+ * @param {string[]} files - the directory's entries
24
+ * @returns {Array<{ name: string, files: string[] }>} each such section, `@` kept for a child, its files sorted
25
+ */
26
+ export function sectionFilesNamedTwice(files) {
27
+ const byName = new Map()
28
+ for (const file of files) {
29
+ if (!isMarkdownFile(file)) continue
30
+ const stem = file.slice(0, -'.md'.length)
31
+ const at = stem.match(/^@+/)?.[0] || ''
32
+ const bare = stem.slice(at.length)
33
+ const key = `${at}${parseNumericPrefix(bare).name || bare}`
34
+ if (!byName.has(key)) byName.set(key, [])
35
+ byName.get(key).push(file)
36
+ }
37
+ return [...byName].filter(([, list]) => list.length > 1).map(([name, list]) => ({ name, files: list.sort() }))
38
+ }
39
+
40
+ /**
41
+ * Say which sections a page holds twice, in the words the build and a pull both use.
42
+ *
43
+ * @param {string} dir - the page's directory, as the person knows it (`pages/404`)
44
+ * @param {Array<{ name: string, files: string[] }>} twice - `sectionFilesNamedTwice`'s answer
45
+ * @returns {string}
46
+ */
47
+ export function describeSectionsNamedTwice(dir, twice) {
48
+ return twice
49
+ .map(({ name, files }) => `${dir} holds the section "${name.replace(/^@+/, '')}" in ${files.length} files: ${files.join(', ')}`)
50
+ .join('\n')
51
+ }
@@ -29,10 +29,9 @@ import { ASSET_SLOTS } from '@uniweb/semantic-parser'
29
29
  import { computeSourceHash, manifestText } from '../i18n/freeform-manifest.js'
30
30
  import { sameMarkdownDocument, canonicalJson } from './same-content.js'
31
31
  import { parseFrontmatter } from '../utils/frontmatter.js'
32
- import { KEPT_FILE, RESERVED_LOCALE_FILES } from '../i18n/locales.js'
32
+ import { KEPT_FILE, RESERVED_LOCALE_FILES, FREEFORM_MANIFEST } from '../i18n/locales.js'
33
33
  import { isSmallEdit, wordOverlap } from '../i18n/word-overlap.js'
34
34
 
35
- const FREEFORM_MANIFEST = '.manifest.json'
36
35
 
37
36
  // The directory a site keeps its translations in — `site.yml`'s `i18n.localesDir`, else `locales`,
38
37
  // the rule the build and `uniweb i18n` read it by — for the push and the pull alike. `subdir` scopes a
@@ -32,7 +32,7 @@
32
32
  // site-content uuid. Nothing is silently dropped: an unplaceable or unresolvable
33
33
  // record is reported.
34
34
 
35
- import { readBackendState, updateBackendMap } from './sync-store.js'
35
+ import { readBackendState, updateBackendMap, setBackendMap } from './sync-store.js'
36
36
  import { restoreAssetRefs } from './asset-map.js'
37
37
  import { documentSchema } from './entity-document.js'
38
38
  import { readFileSync, readdirSync, existsSync, unlinkSync, writeFileSync } from 'node:fs'
@@ -105,6 +105,37 @@ export function findRecordFileByUuid(poolDir, uuid) {
105
105
  return null
106
106
  }
107
107
 
108
+ /**
109
+ * Every single-record file under the records directory, by the own id it holds — a mounted type's
110
+ * folder left out, since its files are another site's. A list file (BibTeX) is no single record.
111
+ *
112
+ * @returns {Map<string, string>} own id → path
113
+ */
114
+ function recordFilesByOwnId(recordsRoot, mountedDirs) {
115
+ const byOwnId = new Map()
116
+ const walk = (dir) => {
117
+ let entries
118
+ try {
119
+ entries = readdirSync(dir, { withFileTypes: true })
120
+ } catch {
121
+ return
122
+ }
123
+ for (const e of entries) {
124
+ if (e.name.startsWith('_') || e.name.startsWith('.')) continue
125
+ const path = join(dir, e.name)
126
+ if (e.isDirectory()) {
127
+ if (!mountedDirs.has(resolve(path))) walk(path)
128
+ continue
129
+ }
130
+ const format = formatForExt(extname(e.name).toLowerCase())
131
+ const own = format ? readFileUuid(path, format) : null
132
+ if (typeof own === 'string' && own && !byOwnId.has(own)) byOwnId.set(own, path)
133
+ }
134
+ }
135
+ walk(recordsRoot)
136
+ return byOwnId
137
+ }
138
+
108
139
  // ⭐ A RECORD KEPT IN A BIBTEX FILE — several entries in one — is found by its entry's `$uuid`, so
109
140
  // a pull does not write it again as a file of its own beside the list. ⛔ Until 2026-09-27 a JSON or
110
141
  // YAML array was such a list too; a file holds one record now (`site/record-file.js`).
@@ -738,7 +769,9 @@ function holdsPattern(abs) {
738
769
  * @param {{ own: Set<string>|null, keyTypes: Map<string, string>|null }} [params.opts.foundation] - what the
739
770
  * site's foundation declares, as `readSiteFoundationDeclarations` reads it; absent, its built schema
740
771
  * @param {string} [params.opts.sourceLocale]
741
- * @returns {{ updated: string[], placed: string[], unchanged: string[], skipped: object[], warnings: string[], locales: object }}
772
+ * @param {boolean} [params.opts.prune] - remove the file of a record this backend held and no longer
773
+ * holds, and its mapping: a record removed in the app (`removed`)
774
+ * @returns {{ updated: string[], placed: string[], unchanged: string[], removed: string[], skipped: object[], warnings: string[], locales: object }}
742
775
  */
743
776
  export function recordsToProject({ folderDoc, recordDocs = [], siteRoot, opts = {} }) {
744
777
  // The site's language, as its `site.yml` says it — written by the pull of the site's content, which
@@ -956,6 +989,42 @@ export function recordsToProject({ folderDoc, recordDocs = [], siteRoot, opts =
956
989
  for (const [theirs, rel] of pulledFiles.pathByUuid) poolPathByUuid.set(theirs, rel)
957
990
  warnings.push(...pulledFiles.warnings)
958
991
 
992
+ // ⭐ A RECORD REMOVED IN THE APP IS REMOVED HERE (`opts.prune`), as a page or a section is. A record
993
+ // this backend held — its own id mapped to the entity it became — and no longer holds anywhere in the
994
+ // folder it answered with was removed there: its file goes, and its mapping with it, so a file kept
995
+ // anyway goes up as a new record on the next push. In a repository the pull writes this onto its
996
+ // stand-in, so git merges the removal, or stops on it where the record was changed here too. A record
997
+ // never pushed to this backend has no mapping and is never touched, and a pull that took no folder
998
+ // removes nothing. ⛔ Until 2026-11-13 the file stayed, and a push called it unchanged, since nothing
999
+ // in it had changed: a record its owner deleted in the app stayed in a static build of the same files,
1000
+ // and the copy and the site disagreed with nothing to say so (measured on a site, 2026-11-12).
1001
+ const removed = []
1002
+ if (opts.prune && folderDoc && opts.backend) {
1003
+ const held = new Set([...recordDocs.map((d) => d?.$uuid).filter(Boolean), ...folderIndex.keys(), ...poolPathByUuid.keys()])
1004
+ const goneOwnIds = Object.entries(recordMap)
1005
+ .filter(([, theirs]) => typeof theirs === 'string' && theirs && !held.has(theirs))
1006
+ .map(([own]) => own)
1007
+ if (goneOwnIds.length && !held.size) {
1008
+ // ⛔ AN ANSWER HOLDING NO RECORD REMOVES NONE, as an empty level of pages removes none
1009
+ // (`site-project.js`), so a malformed or partial answer can't empty the records directory. Said,
1010
+ // since a site whose records were all removed in the app still has them in its files.
1011
+ warnings.push(
1012
+ `the backend's folder holds no records, so this pull removed none of the ${goneOwnIds.length} this copy has pushed. ` +
1013
+ 'If they were all removed in the app, delete their files'
1014
+ )
1015
+ } else if (goneOwnIds.length) {
1016
+ const files = recordFilesByOwnId(recordsRoot, new Set(mounts.map((m) => resolve(m.at))))
1017
+ for (const own of goneOwnIds) {
1018
+ const path = files.get(own)
1019
+ if (!path) continue
1020
+ unlinkSync(path)
1021
+ removed.push(path)
1022
+ }
1023
+ const gone = new Set(goneOwnIds)
1024
+ setBackendMap(siteRoot, opts.backend, 'records', Object.fromEntries(Object.entries(recordMap).filter(([own]) => !gone.has(own))))
1025
+ }
1026
+ }
1027
+
959
1028
  const records = folderToFolderYml({ folderDoc, siteRoot, poolPathByUuid, sourceLocale })
960
1029
  warnings.push(...records.warnings)
961
1030
  for (const path of keptBib) {
@@ -977,7 +1046,7 @@ export function recordsToProject({ folderDoc, recordDocs = [], siteRoot, opts =
977
1046
  }
978
1047
 
979
1048
  return {
980
- updated, placed, unchanged, skipped, warnings, locales, freeform, records: records.status, recordsFile: records.file,
1049
+ updated, placed, unchanged, removed, skipped, warnings, locales, freeform, records: records.status, recordsFile: records.file,
981
1050
  // The file records' bytes to fetch — `{ url, path, poolPath }` each (`./file-records.js`).
982
1051
  fileDownloads: pulledFiles.downloads,
983
1052
  // Mounted records, another site's files, which this pull read and left as they are.
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { join, relative, resolve, sep } from 'node:path'
7
7
  import { mountEntriesOf } from '../site/mount-entries.js'
8
+ import { unsentTranslationFiles } from '../i18n/locales.js'
8
9
 
9
10
  /**
10
11
  * `site.yml::paths.pages` / `paths.layout`, else `pages/` and `layout/` — resolved
@@ -38,7 +39,8 @@ export function siteContentDirs(siteRoot, siteYml) {
38
39
  * mount's may lead out of it (`../docs`):
39
40
  *
40
41
  * - `config`: `site.yml`, `theme.yml`, `head.html`, `queries.yml`;
41
- * - `translations`: `locales`;
42
+ * - `translations`: `site.yml`'s `i18n.localesDir`, else `locales`, with `unsent`: the files there a push
43
+ * never sends, its tools' own (`unsentTranslationFiles`);
42
44
  * - `pages`, `layout`, `records`: where `paths:` puts them, else their own names;
43
45
  * - `media`: `public`, where the files a page names are kept;
44
46
  * - `mount`: each `paths: { pages/<segment>: <dir> }` folder, with its `segment` and `abs`.
@@ -53,7 +55,11 @@ export function siteContentDirs(siteRoot, siteYml) {
53
55
  *
54
56
  * @param {string} siteRoot
55
57
  * @param {object|null} siteYml - the parsed `site.yml`
56
- * @returns {Array<{ path: string, kind: 'config'|'translations'|'pages'|'layout'|'records'|'media'|'mount', segment?: string, abs: string }>}
58
+ * ⛔ Until 2026-11-13 the translations were always `locales`, whatever `i18n.localesDir` said, while the
59
+ * push read them where it said: a site that moved them had its translations outside what a push
60
+ * checks is committed, what `uniweb status` counts, and what a pull merges.
61
+ *
62
+ * @returns {Array<{ path: string, kind: 'config'|'translations'|'pages'|'layout'|'records'|'media'|'mount', segment?: string, abs: string, unsent?: string[] }>}
57
63
  */
58
64
  export function siteContentRoots(siteRoot, siteYml) {
59
65
  const paths = siteYml?.paths
@@ -63,7 +69,9 @@ export function siteContentRoots(siteRoot, siteYml) {
63
69
  }
64
70
  const roots = []
65
71
  for (const file of ['site.yml', 'theme.yml', 'head.html', 'queries.yml']) roots.push({ ...at(file), kind: 'config' })
66
- roots.push({ ...at('locales'), kind: 'translations' })
72
+ const localesDir = typeof siteYml?.i18n?.localesDir === 'string' && siteYml.i18n.localesDir.trim() ? siteYml.i18n.localesDir.trim() : 'locales'
73
+ const translations = at(localesDir)
74
+ roots.push({ ...translations, kind: 'translations', unsent: unsentTranslationFiles(translations.path) })
67
75
  roots.push({ ...at(paths?.pages || 'pages'), kind: 'pages' })
68
76
  roots.push({ ...at(paths?.layout || 'layout'), kind: 'layout' })
69
77
  roots.push({ ...at(paths?.records || 'records'), kind: 'records' })
@@ -125,9 +125,10 @@ const isReadersText = (node, key) => key === 'text' && node.type === 'text'
125
125
  /**
126
126
  * The site-root pictures that software other than the site's pages fetches by their address: the
127
127
  * favicon, the touch icon a phone puts on its home screen, the site's card picture (`info.preview`),
128
- * and every social image (`seo`, the site's and each page's). A push uploads them as they are,
129
- * because what fetches them takes a PNG icon or a JPEG or PNG picture, not the WebP a page's
130
- * picture is prepared to.
128
+ * and every social image (`seo`, the site's and each page's). A push uploads them in their own
129
+ * format, without their location and camera data (`prepareImage`'s `keepFormat`), because what
130
+ * fetches them takes a PNG icon or a JPEG or PNG picture, not the WebP a page's picture is prepared
131
+ * to. ⛔ Until 2026-11-12 they went up exactly as they were, location included.
131
132
  *
132
133
  * @param {object|null} siteDoc - the site-content document
133
134
  * @returns {Set<string>}