@uniweb/build 1.10.11 → 1.10.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "1.10.11",
3
+ "version": "1.10.13",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -57,14 +57,14 @@
57
57
  "sharp": "^0.35.5",
58
58
  "yaml": "^2.5.0",
59
59
  "@uniweb/content-reader": "~1.5.7",
60
+ "@uniweb/content-writer": "~1.3.1",
61
+ "@uniweb/projections": "~1.2.7",
60
62
  "@uniweb/schemas": "~1.6.5",
61
- "@uniweb/theming": "~1.2.1",
62
63
  "@uniweb/semantic-parser": "~1.13.0",
63
- "@uniweb/content-writer": "~1.3.1",
64
- "@uniweb/projections": "~1.2.6"
64
+ "@uniweb/theming": "~1.2.1"
65
65
  },
66
66
  "optionalDependencies": {
67
- "@uniweb/runtime": "~1.2.11"
67
+ "@uniweb/runtime": "~1.2.12"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
@@ -73,8 +73,8 @@
73
73
  "@tailwindcss/vite": "^4.0.0",
74
74
  "@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
75
75
  "vite-plugin-svgr": "^4.0.0",
76
- "@uniweb/runtime": "~1.2.11",
77
- "@uniweb/core": "~1.4.11"
76
+ "@uniweb/core": "~1.4.12",
77
+ "@uniweb/runtime": "~1.2.12"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "vite": {
package/src/images.js CHANGED
@@ -39,6 +39,40 @@ async function getImageMetadata(imagePath) {
39
39
  }
40
40
  }
41
41
 
42
+ /**
43
+ * An image's size and format, read from its bytes — or null when sharp cannot read the file as an
44
+ * image. Quiet: a caller that reports an unreadable image says so in its own words
45
+ * (`uniweb doctor`, measuring the image a link to the site shows).
46
+ *
47
+ * @param {string} imagePath
48
+ * @returns {Promise<{ width: number, height: number, format: string } | null>}
49
+ */
50
+ export async function readImageSize(imagePath) {
51
+ try {
52
+ const { width, height, format } = await sharp(imagePath).metadata()
53
+ return width && height ? { width, height, format } : null
54
+ } catch {
55
+ return null
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Whether every pixel of an image is opaque — an alpha channel alone does not say, since most
61
+ * PNGs carry one whether they use it or not — or null when sharp cannot read the file. It decodes
62
+ * the whole image, so it is for a small one: `uniweb doctor` asks it of a site's touch icon,
63
+ * whose transparent pixels iOS draws black.
64
+ *
65
+ * @param {string} imagePath
66
+ * @returns {Promise<boolean|null>}
67
+ */
68
+ export async function isImageOpaque(imagePath) {
69
+ try {
70
+ return (await sharp(imagePath).stats()).isOpaque
71
+ } catch {
72
+ return null
73
+ }
74
+ }
75
+
42
76
  /**
43
77
  * Convert an image to webp format
44
78
  */
@@ -0,0 +1,61 @@
1
+ /**
2
+ * A static build's icons (`plugin.js` links them). The favicon: `site.yml`'s `favicon:`, else the
3
+ * first of these in the site's public folder. A site sent to a Uniweb host has no such fallback —
4
+ * its pages link only the favicon `favicon:` names, and only that file is uploaded — so
5
+ * `uniweb doctor` reads this same list to say when a site has an icon on one lane and none on the
6
+ * other. The touch icon — the PNG iOS puts on a home screen — is `site.yml`'s `touchIcon:`, and
7
+ * only that: nothing is looked for.
8
+ */
9
+
10
+ import { existsSync } from 'node:fs'
11
+ import { resolve } from 'node:path'
12
+
13
+ const FAVICON_FILES = ['favicon.svg', 'favicon.ico', 'favicon.png']
14
+
15
+ /**
16
+ * @param {string|null|undefined} publicDir
17
+ * @returns {string|null} the file name the build would link (`favicon.svg`), or null
18
+ */
19
+ export function findPublicFavicon(publicDir) {
20
+ if (!publicDir) return null
21
+ return FAVICON_FILES.find((name) => existsSync(resolve(publicDir, name))) || null
22
+ }
23
+
24
+ /**
25
+ * The href a static build links its favicon at. A named site path (`/favicon.ico`) and a found file
26
+ * are both the site's own, served under its base like every other file of its own
27
+ * (`asset-processor-base.test.js`); an address of its own is linked as written. ⛔ Until 2026-10-27
28
+ * a named favicon was linked as written, so under a base (a GitHub Pages project site's `/repo/`)
29
+ * a site that named its favicon linked one directory too high, while one the build found did not.
30
+ *
31
+ * @param {unknown} named - `site.yml`'s `favicon:`
32
+ * @param {string|null|undefined} publicDir
33
+ * @param {string} [basePath] - the deployment base (`/`, `/repo/`)
34
+ * @returns {string|null}
35
+ */
36
+ export function faviconHref(named, publicDir, basePath) {
37
+ const href = siteHref(named, basePath)
38
+ if (href) return href
39
+ const found = findPublicFavicon(publicDir)
40
+ return found ? siteHref(`/${found}`, basePath) : null
41
+ }
42
+
43
+ /**
44
+ * The href a static build links its touch icon at — `site.yml`'s `touchIcon:`, under the base as
45
+ * the favicon is.
46
+ *
47
+ * @param {unknown} named
48
+ * @param {string} [basePath]
49
+ * @returns {string|null}
50
+ */
51
+ export function touchIconHref(named, basePath) {
52
+ return siteHref(named, basePath)
53
+ }
54
+
55
+ /** A site path under the deployment base; an address of its own as written; null for none. */
56
+ function siteHref(named, basePath) {
57
+ const href = typeof named === 'string' ? named.trim() : ''
58
+ if (!href) return null
59
+ const base = (basePath || '/').replace(/\/$/, '')
60
+ return href.startsWith('/') && !href.startsWith('//') ? `${base}${href}` : href
61
+ }
package/src/site/index.js CHANGED
@@ -15,6 +15,8 @@ export { DEV_PORT_ENV, DEV_RECORD_ENV, runningDevServer, stopDevServer } from '.
15
15
  // Where a statically built site lives, as its deploy target or author states it (`./site-address.js`).
16
16
  export { ORIGIN_ENV, refuseUnreadableAddress } from './site-address.js'
17
17
  export { collectSiteContent, mountEntriesOf } from './content-collector.js'
18
+ // The favicon a build links when site.yml names none, for `uniweb doctor` (`./favicon.js`).
19
+ export { findPublicFavicon } from './favicon.js'
18
20
  // The `agents:` vocabulary lives in @uniweb/projections (which owns the block);
19
21
  // re-exported so the CLI can validate an author's spelling, and read an
20
22
  // `expectedOrigins` entry by its rule, without taking a direct dependency on it.
@@ -45,12 +45,11 @@ import { FONT_LINKS_MARKER } from './head-markers.js'
45
45
  import { effectiveSeo, resolveSiteAddress } from './site-address.js'
46
46
  import { collectExtensionAssets, isBrowserAsset } from './emit-extensions.js'
47
47
  import { extensionNameOf, findSiteExtension } from './workspace-extension.js'
48
+ import { faviconHref, touchIconHref } from './favicon.js'
48
49
 
49
50
  // BCP 47 locale code pattern: en, zh-CN, zh-Hant, pt-BR, fr-CA, sr-Latn, etc.
50
51
  const LOCALE_RE = '[a-z]{2,3}(?:-[A-Za-z]{2,4})?'
51
52
 
52
- const FAVICON_AUTODETECT = ['favicon.svg', 'favicon.ico', 'favicon.png']
53
-
54
53
  const EXTENSION_CONTENT_TYPES = {
55
54
  js: 'text/javascript',
56
55
  mjs: 'text/javascript',
@@ -75,26 +74,6 @@ function extensionContentType(file) {
75
74
  return EXTENSION_CONTENT_TYPES[file.split('.').pop()?.toLowerCase()] || 'application/octet-stream'
76
75
  }
77
76
 
78
- /**
79
- * Resolve a favicon href for index.html injection.
80
- * - If config.favicon is a string, use it as-is.
81
- * - Otherwise, scan the public dir for favicon.{svg,ico,png} and link the first match.
82
- * - Returns null if nothing found.
83
- */
84
- function resolveFaviconHref(configFavicon, publicDir, basePath) {
85
- if (typeof configFavicon === 'string' && configFavicon.trim()) {
86
- return configFavicon.trim()
87
- }
88
- if (!publicDir) return null
89
- for (const name of FAVICON_AUTODETECT) {
90
- if (existsSync(resolve(publicDir, name))) {
91
- const base = (basePath || '/').replace(/\/$/, '')
92
- return `${base}/${name}`
93
- }
94
- }
95
- return null
96
- }
97
-
98
77
  /**
99
78
  * Should this fetch config be pre-executed at build time and embedded into the
100
79
  * dev boot payload, or left for the runtime to fetch live?
@@ -1130,15 +1109,16 @@ export function siteContentPlugin(options = {}) {
1130
1109
  // page is rendered into: the prerender writes each page's own (`injectPageContent`), and the
1131
1110
  // browser keeps them (`useHeadMeta`). Until 2026-10-25 the home page's were written here.
1132
1111
 
1133
- // Inject favicon link
1134
- // Source 1: contentToInject.config.favicon (matches Cloudflare publish schema)
1135
- // Source 2: auto-detect public/favicon.{ico,svg,png}
1136
- const faviconHref = resolveFaviconHref(contentToInject?.config?.favicon, resolvedPublicDir, basePath)
1137
- if (faviconHref) {
1138
- const type = faviconType(faviconHref)
1112
+ // The favicon: site.yml's `favicon:`, else the one public/ holds (`./favicon.js`).
1113
+ const favicon = faviconHref(contentToInject?.config?.favicon, resolvedPublicDir, basePath)
1114
+ if (favicon) {
1115
+ const type = faviconType(favicon)
1139
1116
  const typeAttr = type ? ` type="${type}"` : ''
1140
- headInjection += ` <link rel="icon"${typeAttr} href="${faviconHref}">\n`
1117
+ headInjection += ` <link rel="icon"${typeAttr} href="${favicon}">\n`
1141
1118
  }
1119
+ // The touch icon: site.yml's `touchIcon:`, the PNG iOS puts on a home screen.
1120
+ const touchIcon = touchIconHref(contentToInject?.config?.touchIcon, basePath)
1121
+ if (touchIcon) headInjection += ` <link rel="apple-touch-icon" href="${touchIcon}">\n`
1142
1122
 
1143
1123
  // Inject content as JSON script tag
1144
1124
  if (inject) {
@@ -89,7 +89,10 @@
89
89
  "seo": [
90
90
  "site.yml::seo"
91
91
  ],
92
- "theme": null
92
+ "theme": null,
93
+ "touch_icon": [
94
+ "site.yml::touchIcon"
95
+ ]
93
96
  }
94
97
  },
95
98
  "services": {
@@ -192,6 +192,9 @@ const SETTINGS_TO_SITE_YML = {
192
192
  // offered through `config.services` and resolved at render, never entering the
193
193
  // stored record, so a pull cannot launder it into authored config.
194
194
  agents: 'agents',
195
+ // The touch icon, verbatim: the path the author wrote, which `restoreAssetRefs` has already put
196
+ // back from the serve URL the push recorded (asset-map.js), else a URL.
197
+ touch_icon: 'touchIcon',
195
198
  }
196
199
 
197
200
 
package/src/uwx/site.js CHANGED
@@ -1356,6 +1356,12 @@ function settingsNested(siteYml, { headHtml, themeYml, sourceLocale, translation
1356
1356
  // carries the translation collector with it.
1357
1357
  setIf(settings, 'keywords', plainTextTargets(localizeScalarList(siteYml.keywords, sourceLocale, translations), sourceLocale))
1358
1358
 
1359
+ // ⭐ The touch icon — `site.yml::touchIcon`, the PNG iOS puts on a home screen — where the
1360
+ // deployment's `settings` takes it (`touchIconValue`). A site path is media to the upload walk
1361
+ // (`sync-package.js::walkEntityAssets`), so it goes up with the site's other files and is sent
1362
+ // as its serve URL, which a pull puts back as the path (`asset-map.js::restoreAssetRefs`).
1363
+ setIf(settings, 'touch_icon', touchIconValue(siteYml.touchIcon, settingsFields))
1364
+
1359
1365
  // ⛔ NO SERVICE IS HERE. A service's address and options ride its row in the
1360
1366
  // `services` Section, whole (`requestedServices`) [Diego, 2026-10-06: "If it's on and
1361
1367
  // has configuration, it can all be in the same place"]. *Until that evening
@@ -1390,6 +1396,21 @@ function settingsNested(siteYml, { headHtml, themeYml, sourceLocale, translation
1390
1396
  return Object.keys(settings).length > 0 ? settings : undefined
1391
1397
  }
1392
1398
 
1399
+ /**
1400
+ * `site.yml::touchIcon` as a push sends it: only to a deployment whose `settings` declares
1401
+ * `touch_icon`, since one that does not refuses a push carrying it (`deploymentFields`). Such a
1402
+ * site is told; with no list in hand, nothing optional is sent.
1403
+ */
1404
+ function touchIconValue(named, settingsFields) {
1405
+ if (typeof named !== 'string' || !named.trim() || !Array.isArray(settingsFields)) return undefined
1406
+ if (settingsFields.includes('touch_icon')) return named
1407
+ console.warn(
1408
+ "uwx/site: `touchIcon:` is not sent — this backend's site settings take no touch icon, so " +
1409
+ 'the pages it serves link none.'
1410
+ )
1411
+ return undefined
1412
+ }
1413
+
1393
1414
  /**
1394
1415
  * Map a file site project to the nested `@uniweb/site-content` `$`-document
1395
1416
  * (see the lane header above). PURE — reads the project, never mints, never writes.
@@ -493,6 +493,12 @@ export async function emitSyncPackages(siteRoot, opts = {}) {
493
493
  })
494
494
  collectFrom(siteDoc)
495
495
  for (const e of col.entities) collectFrom(e.document)
496
+ // ⭐ The site's favicon, whatever its type. `.ico` is not media to the walker
497
+ // (`isLocalAssetPath`), but a host serves the favicon its page shell links only from
498
+ // the asset store: left as a site path, `/favicon.ico` was linked on every hosted page
499
+ // and answered 404. The rewrite above already swaps any path the upload map names.
500
+ const favicon = siteDoc?.info?.favicon
501
+ if (typeof favicon === 'string' && favicon.startsWith('/') && !favicon.startsWith('//')) localAssetSet.add(favicon)
496
502
  const localAssets = [...localAssetSet]
497
503
 
498
504
  // ⭐ THE IDENTITY OF A RECORD'S LIST ITEMS (`record-items.js`), taken on each document as it