@uniweb/build 1.10.10 → 1.10.12

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.10",
3
+ "version": "1.10.12",
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/projections": "~1.2.5",
61
- "@uniweb/content-writer": "~1.3.1",
62
60
  "@uniweb/schemas": "~1.6.5",
61
+ "@uniweb/theming": "~1.2.1",
63
62
  "@uniweb/semantic-parser": "~1.13.0",
64
- "@uniweb/theming": "~1.2.1"
63
+ "@uniweb/projections": "~1.2.6",
64
+ "@uniweb/content-writer": "~1.3.1"
65
65
  },
66
66
  "optionalDependencies": {
67
- "@uniweb/runtime": "~1.2.8"
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/core": "~1.4.10",
77
- "@uniweb/runtime": "~1.2.8"
76
+ "@uniweb/core": "~1.4.12",
77
+ "@uniweb/runtime": "~1.2.12"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "vite": {
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A package a foundation imports DYNAMICALLY stays a dynamic import in `dist/entry-ssr.js`.
3
+ *
4
+ * The SSR twin is one file (`inlineDynamicImports`), so every dynamic import is folded into it,
5
+ * and a module folded in runs when the file loads: the browser bundle's laziness is gone. For a
6
+ * client-only library imported where it is used — a map inside an effect, a highlighter on demand
7
+ * — its code then runs in the host's isolate at load, and one that touches `window` there stops
8
+ * the foundation loading at all. Leaflet does (`window.requestAnimationFrame`, `window.L`), and
9
+ * every page of a site using it was served as the bare shell, with no prerendered body or head.
10
+ *
11
+ * Kept as the import it is, such a package stays dormant, as kit's Shiki always has
12
+ * (`isSSRExternal`): server rendering never awaits it, and a host has nothing to supply for it.
13
+ *
14
+ * Only a package. The foundation's own modules (`./chart.js`, `#components/x`) are folded in as
15
+ * before, since a host that loads one file could not reach them otherwise.
16
+ */
17
+ export function ssrDormantDynamicImports() {
18
+ return {
19
+ name: 'uniweb:ssr-dormant-dynamic-imports',
20
+ resolveDynamicImport(specifier) {
21
+ return typeof specifier === 'string' && isPackageSpecifier(specifier) ? { id: specifier, external: true } : null
22
+ },
23
+ }
24
+ }
25
+
26
+ /**
27
+ * A bare package specifier — `leaflet`, `@scope/pkg/sub` — rather than a relative or absolute
28
+ * path, a package-internal `#` import, a virtual module, or anything with a scheme.
29
+ *
30
+ * @param {string} specifier
31
+ * @returns {boolean}
32
+ */
33
+ export function isPackageSpecifier(specifier) {
34
+ if (!specifier || /^[.#/\\\0]/.test(specifier)) return false
35
+ if (/^[a-z][a-z0-9+.-]*:/i.test(specifier)) return false
36
+ return true
37
+ }
package/src/images.js CHANGED
@@ -39,6 +39,23 @@ 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
+
42
59
  /**
43
60
  * Convert an image to webp format
44
61
  */
@@ -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) {
@@ -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
@@ -19,6 +19,7 @@ import { deriveSupports } from './foundation/derive-supports.js'
19
19
  import { proseWithoutStyles, PROSE_WITHOUT_STYLES_WARNING } from './foundation/prose-styles.js'
20
20
  import { nodeEnvDefine } from './foundation/node-env.js'
21
21
  import { foundationScopeDefine } from './foundation/scope-define.js'
22
+ import { ssrDormantDynamicImports } from './foundation/ssr-dormant-imports.js'
22
23
  import { DEV_REBUILD_MARKER, hasDevRebuildMarker } from './foundation/dev-rebuild.js'
23
24
 
24
25
  // Foundations already told that their prose has no stylesheet — once per process, so a dev
@@ -282,7 +283,10 @@ async function emitFoundationVarsCss(outDir, schema) {
282
283
  * It hydrates in the browser and never runs during renderToString. Keeping it
283
284
  * external drops the ~10 MB Shiki language graph from the SSR bundle and leaves
284
285
  * it a DORMANT dynamic import that server rendering never awaits — so a host
285
- * has nothing to supply for it.
286
+ * has nothing to supply for it. Every other package a foundation imports
287
+ * dynamically gets the same treatment from `ssrDormantDynamicImports`
288
+ * (`foundation/ssr-dormant-imports.js`); Shiki keeps its own entry here, which
289
+ * also keeps a static import of it out.
286
290
  *
287
291
  * ⛔ `fuse.js` was listed here too, until the local search ranker became
288
292
  * `@uniweb/projections/search` (2026-09-06). Nothing imports fuse now, so the
@@ -350,7 +354,9 @@ async function buildEntrySSR(foundationRoot, entrySourcePath, outDir) {
350
354
  }
351
355
  const react = (await import('@vitejs/plugin-react')).default
352
356
  const svgr = (await import('vite-plugin-svgr')).default
353
- plugins.push(react(), svgr(), nodeEnvDefine(), foundationScopeDefine({ foundationDir: foundationRoot }))
357
+ // ssrDormantDynamicImports: a package imported dynamically stays `import('pkg')`, dormant,
358
+ // rather than folded in to run at load (see its module).
359
+ plugins.push(react(), svgr(), nodeEnvDefine(), foundationScopeDefine({ foundationDir: foundationRoot }), ssrDormantDynamicImports())
354
360
 
355
361
  await viteBuild({
356
362
  root: foundationRoot,