@uniweb/build 1.13.5 → 1.13.7

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.13.5",
3
+ "version": "1.13.7",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -56,15 +56,15 @@
56
56
  "js-yaml": "^4.3.2",
57
57
  "sharp": "^0.35.5",
58
58
  "yaml": "^2.5.0",
59
+ "@uniweb/semantic-parser": "~1.13.0",
60
+ "@uniweb/projections": "~1.2.9",
59
61
  "@uniweb/content-reader": "~1.5.7",
60
62
  "@uniweb/content-writer": "~1.3.1",
61
- "@uniweb/schemas": "~1.6.7",
62
- "@uniweb/projections": "~1.2.8",
63
- "@uniweb/semantic-parser": "~1.13.0",
64
- "@uniweb/theming": "~1.2.1"
63
+ "@uniweb/theming": "~1.2.1",
64
+ "@uniweb/schemas": "~1.6.7"
65
65
  },
66
66
  "optionalDependencies": {
67
- "@uniweb/runtime": "~1.3.3"
67
+ "@uniweb/runtime": "~1.3.5"
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.5.1",
77
- "@uniweb/runtime": "~1.3.3"
76
+ "@uniweb/runtime": "~1.3.5",
77
+ "@uniweb/core": "~1.5.1"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "vite": {
@@ -10,7 +10,7 @@
10
10
  * @module @uniweb/build/content
11
11
  */
12
12
 
13
- export { collectSiteContent } from '../site/content-collector.js'
13
+ export { collectSiteContent, pageSectionFiles } from '../site/content-collector.js'
14
14
 
15
15
  // Query + fetch resolution. Pure functions on the clean dep
16
16
  // chain — re-exported here so headless callers (unipress, sidecars)
@@ -0,0 +1,89 @@
1
+ /**
2
+ * A `@source` that finds nothing — the CSS loses what was behind it, and nothing says so.
3
+ *
4
+ * `@source` tells Tailwind where else to look for class names, relative to the stylesheet. A path
5
+ * that leads nowhere is no error to Tailwind: the build succeeds, and every class found only
6
+ * there is missing from the CSS. Measured 2026-10-31 on four foundations moved up a level with
7
+ * `@source "../node_modules/@uniweb/kit/src/**"` left as it was: exit 0, and CSS of 128,255 bytes
8
+ * down to 78,634, with only the foundation's digest to show it. And on a template installed with
9
+ * npm, which hoists kit to the workspace's root, away from the `./node_modules/@uniweb/kit` the
10
+ * template names: 39,183 bytes where pnpm gave 51,967, from the first build.
11
+ *
12
+ * ⚖️ Only a path that reaches outside the foundation's own source counts: one that climbs, or one
13
+ * into `node_modules`. A starter's `./components/**` names a folder a foundation may not have
14
+ * yet, and with no such folder there is nothing to lose.
15
+ *
16
+ * @module @uniweb/build/foundation/stale-sources
17
+ */
18
+
19
+ import { existsSync, readFileSync } from 'node:fs'
20
+ import { dirname, join, relative, resolve } from 'node:path'
21
+
22
+ // `@source not "…"` excludes a path and `@source inline("…")` names no path: neither has a quote
23
+ // right after the keyword.
24
+ const SOURCE = /@source\s+(["'])(.+?)\1/g
25
+
26
+ /** The part of a glob with no pattern in it: the folder it starts from. */
27
+ function fixedPrefix(glob) {
28
+ const at = glob.search(/[*?[{(!]/)
29
+ return at < 0 ? glob : glob.slice(0, glob.lastIndexOf('/', at) + 1)
30
+ }
31
+
32
+ const reachesOut = (path) => path.startsWith('../') || /(^|\/)node_modules(\/|$)/.test(path)
33
+
34
+ // ⛔ Quoted strings are skipped, not searched: a glob's `/**/` reads exactly like a comment.
35
+ const withoutComments = (css) =>
36
+ css.replace(/("(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')|\/\*[\s\S]*?\*\//g, (_, quoted) => quoted ?? '')
37
+
38
+ /**
39
+ * The `@source` lines of a stylesheet that reach outside the foundation and find nothing.
40
+ *
41
+ * @param {string} stylesPath - the foundation's stylesheet; none there, none stale
42
+ * @returns {Array<{ source: string, missing: string, foundAt: string|null }>} each path as written,
43
+ * the part of it that does not exist, and, for a package, where it is from the stylesheet
44
+ */
45
+ export function staleSources(stylesPath) {
46
+ let css
47
+ try {
48
+ css = readFileSync(stylesPath, 'utf8')
49
+ } catch {
50
+ return []
51
+ }
52
+ const dir = dirname(stylesPath)
53
+ const stale = []
54
+ for (const [, , source] of withoutComments(css).matchAll(SOURCE)) {
55
+ const missing = fixedPrefix(source)
56
+ if (missing && reachesOut(source) && !existsSync(resolve(dir, missing))) {
57
+ stale.push({ source, missing, foundAt: foundAbove(dir, missing) })
58
+ }
59
+ }
60
+ return stale
61
+ }
62
+
63
+ /**
64
+ * Where a path into `node_modules` does lead, looking up from the stylesheet as a package is
65
+ * resolved: relative to the stylesheet, or null when that package is nowhere above it.
66
+ */
67
+ function foundAbove(dir, missing) {
68
+ const tail = /(?:^|\/)(node_modules\/.*)$/.exec(missing)?.[1]
69
+ if (!tail) return null
70
+ for (let at = dir; ; at = dirname(at)) {
71
+ if (existsSync(join(at, tail))) {
72
+ const rel = relative(dir, join(at, tail))
73
+ return rel.startsWith('.') ? rel : `./${rel}`
74
+ }
75
+ if (dirname(at) === at) return null
76
+ }
77
+ }
78
+
79
+ /** A stale line's note: what is missing, and where it is instead when that is known. */
80
+ export const staleSourceNote = ({ missing, foundAt }) => `no ${missing}${foundAt ? `; it is at ${foundAt}` : ''}`
81
+
82
+ /** What the foundation build prints when `staleSources` finds any. */
83
+ export function staleSourcesWarning(stale) {
84
+ return [
85
+ '[uniweb] styles.css has a @source that finds nothing, so the CSS is missing every class that was only there:',
86
+ ...stale.map((line) => ` @source "${line.source}" (${staleSourceNote(line)})`),
87
+ 'Paths are relative to styles.css.'
88
+ ].join('\n')
89
+ }
package/src/i18n/index.js CHANGED
@@ -18,7 +18,7 @@ import { dataBlockModels } from './data-models.js'
18
18
  import { syncManifests, formatSyncReport, formatKeptTranslations } from './sync.js'
19
19
  import { keepEditedTranslations, rowsWantTranslation, manifestRows, settleFlags } from './outdated.js'
20
20
  import { readKept, standingFlags } from '../uwx/locale-sync.js'
21
- import { mergeTranslations, generateAllLocales } from './merge.js'
21
+ import { mergeTranslations, generateAllLocales, translationsHoldingHtml } from './merge.js'
22
22
  import { auditLocale, cleanLocale, formatAuditReport } from './audit.js'
23
23
  import {
24
24
  extractRecordContent,
@@ -512,6 +512,20 @@ export async function buildLocalizedContent(siteRoot, options = {}) {
512
512
  translations = JSON.parse(localeRaw)
513
513
  }
514
514
 
515
+ // ⭐ HTML in a translation shows on the page as written. Pages and free-form translations say
516
+ // so as they are read; a table's values are read one by one deep in the merge, with no file in
517
+ // hand, so this says it once for the file. ⛔ Until 2026-10-31 nothing did: a site's headlines
518
+ // showed `<span primary="true">` in ten languages through a build and two publishes.
519
+ const holdingHtml = translationsHoldingHtml(translations)
520
+ if (holdingHtml.length) {
521
+ const n = holdingHtml.length
522
+ const keys = holdingHtml.slice(0, 8).join(', ') + (n > 8 ? `, and ${n - 8} more` : '')
523
+ console.warn(
524
+ `[i18n] ${localesDir}/${locale}.json: ${n} translation${n === 1 ? ' holds' : 's hold'} HTML, which shows on the page as written: ${keys}. ` +
525
+ 'A translation is inline markdown: write a span as [text]{primary}.'
526
+ )
527
+ }
528
+
515
529
  // Check if free-form translations exist for this locale
516
530
  const freeformDir = join(localesPath, 'freeform', locale)
517
531
  const hasFreeform = freeformEnabled && existsSync(freeformDir)
package/src/i18n/merge.js CHANGED
@@ -418,6 +418,31 @@ function loneImage(fragment) {
418
418
  return nodes.length === 1 && nodes[0].type === 'image' ? nodes[0] : null
419
419
  }
420
420
 
421
+ /**
422
+ * The translations in a locale's table that hold HTML, by key. HTML is not content, so what the
423
+ * merge makes of such a value shows the tag on the page; the words are the merge's own, read the
424
+ * way it reads them (`@uniweb/content-reader`), and saying so is the caller's job.
425
+ *
426
+ * @param {Object} [translations] - a locale's table: `{ key: value }`, a value a string or
427
+ * `{ default, overrides }`
428
+ * @returns {string[]} the keys
429
+ */
430
+ export function translationsHoldingHtml(translations) {
431
+ const holdsHtml = (value) => {
432
+ if (typeof value !== 'string') return false
433
+ let found = false
434
+ inlineMarkdownToProseMirror(value.trim(), { onWarning: () => (found = true) })
435
+ return found
436
+ }
437
+ return Object.entries(translations || {})
438
+ .filter(([, entry]) =>
439
+ typeof entry === 'string'
440
+ ? holdsHtml(entry)
441
+ : holdsHtml(entry?.default) || Object.values(entry?.overrides || {}).some(holdsHtml)
442
+ )
443
+ .map(([key]) => key)
444
+ }
445
+
421
446
  /**
422
447
  * Does a translation keep the inline markup of its source element? The merge's own answer —
423
448
  * what `translatedInline` makes of the value — so the audit can neither report a loss the merge
package/src/index.js CHANGED
@@ -85,6 +85,7 @@ export {
85
85
 
86
86
  // Foundation source root resolution (reads package.json::main)
87
87
  export { resolveFoundationSrcDir, resolveFoundationSrcPath } from './utils/foundation-source-root.js'
88
+ export { staleSources, staleSourceNote } from './foundation/stale-sources.js'
88
89
 
89
90
  // Package classification (foundation vs site vs standalone schemas package)
90
91
  export { classifyPackage, isExtensionPackage, isSchemasPackage } from './utils/classify-package.js'
package/src/prerender.js CHANGED
@@ -1246,7 +1246,8 @@ export async function prerenderSite(siteDir, options = {}) {
1246
1246
  // 1) CLI --host flag (hostOverride)
1247
1247
  // 2) CI host detected from env vars (Vercel, CF Pages, Netlify)
1248
1248
  // 3) 'cloudflare-pages' default (preserves the historical
1249
- // `_redirects` output; same format also works on Netlify)
1249
+ // `_redirects` output; same format also works on Netlify). This is a
1250
+ // file format, not a host anyone chose, so the build names no adapter for it.
1250
1251
  //
1251
1252
  // The build does not read deploy.yml. When the orchestrator
1252
1253
  // (uniweb deploy) needs adapter-specific config (bucket,
@@ -1259,7 +1260,7 @@ export async function prerenderSite(siteDir, options = {}) {
1259
1260
  if (ciContext?.runner) {
1260
1261
  onProgress(`CI runner: ${ciContext.runner}${ciContext.host ? '' : ' (host not implied)'}`)
1261
1262
  }
1262
- onProgress(`Host adapter: ${adapter.name}`)
1263
+ if (hostOverride || ciContext?.host) onProgress(`Host adapter: ${adapter.name}`)
1263
1264
  await adapter.postBuild({
1264
1265
  distDir,
1265
1266
  siteContent: defaultSiteContent,
package/src/schema.js CHANGED
@@ -1234,8 +1234,8 @@ export function reportPlacementDeclarations(components) {
1234
1234
  * Returns { _self: { identity + config }, ComponentName: componentMeta, ... }
1235
1235
  *
1236
1236
  * The _self object contains:
1237
- * - Identity from package.json (name, version, description)
1238
- * - Configuration from foundation.js (vars, Layout, etc.)
1237
+ * - Identity from package.json (version, description, and the name when main.js gives none)
1238
+ * - Declarations from main.js (name, vars, etc.)
1239
1239
  *
1240
1240
  * @param {string} srcDir - Source directory
1241
1241
  * @param {string[]} [sectionPaths] - Paths to scan for section types
@@ -1247,7 +1247,7 @@ export async function buildSchema(srcDir, sectionPaths, derivedSupports = null)
1247
1247
  // Load identity from package.json
1248
1248
  const identity = await loadPackageJson(srcDir)
1249
1249
 
1250
- // Load configuration from foundation.js
1250
+ // Load the declarations from main.js
1251
1251
  const foundationConfig = await loadFoundationConfig(srcDir)
1252
1252
 
1253
1253
  refuseDataDeclarations('the foundation (main.js)', lowerData(foundationConfig.data))
@@ -1814,6 +1814,31 @@ async function processPage(pagePath, pageName, siteRoot, { isIndex = false, pare
1814
1814
  }
1815
1815
  }
1816
1816
 
1817
+ /**
1818
+ * A page folder's markdown files in the order the page has them, each child after its parent. A
1819
+ * file the page leaves out, as a `sections:` list not naming it does, is not among them.
1820
+ *
1821
+ * The page's own walk (`processPage`), so a tool that shows a page (`uniweb inspect`) has no second
1822
+ * rule for what is on it or in what order.
1823
+ *
1824
+ * @param {string} pagePath - The page's folder
1825
+ * @param {string} siteRoot - The site's folder
1826
+ * @returns {Promise<string[]>} File names
1827
+ */
1828
+ export async function pageSectionFiles(pagePath, siteRoot) {
1829
+ const { page } = await processPage(pagePath, parse(pagePath).base, siteRoot)
1830
+ const filesOf = new Map()
1831
+ const files = (await readdir(pagePath)).filter(isMarkdownFile).sort(compareFilenames)
1832
+ for (const file of files) {
1833
+ const name = stripAtPrefix(parse(file).name)
1834
+ const key = parseNumericPrefix(name).name || name
1835
+ filesOf.set(key, [...(filesOf.get(key) || []), file])
1836
+ }
1837
+ const walk = (sections) =>
1838
+ sections.flatMap((section) => [filesOf.get(section.stableId)?.shift(), ...walk(section.subsections || [])])
1839
+ return walk(page.sections).filter(Boolean)
1840
+ }
1841
+
1817
1842
  /**
1818
1843
  * The homepage ONE config declares: the first named `pages:` entry, else `index:`.
1819
1844
  * `undefined` when it declares none; `null` when its first `pages:` entry names
@@ -18,7 +18,6 @@
18
18
  import { statSync } from 'node:fs'
19
19
  import { extname } from 'node:path'
20
20
  import { mimeFor } from '@uniweb/semantic-parser'
21
- import { generatePdfThumbnail } from './advanced-processors.js'
22
21
 
23
22
  export const FILE_MODEL = '@uniweb/file'
24
23
 
@@ -51,12 +50,23 @@ export function fileRecordValue({ absPath, name, url, preview }) {
51
50
 
52
51
  /**
53
52
  * Make a PDF's preview image at `outputPath` — a placeholder card, not a render of the page — or
54
- * report that none was made (not a PDF, or `pdf-lib` not installed).
53
+ * report that none was made (not a PDF, or `pdf-lib` or `sharp` not available).
54
+ *
55
+ * ⛔ The card's module is loaded here, not at the top of this file. This file is on the chain of
56
+ * `@uniweb/build/content`, which promises no `sharp`, and that module imports `sharp` as it loads:
57
+ * a standalone binary has no native `sharp`, and with the import at the top it could not start, on
58
+ * any command (`tests/content-entry-graph.test.js`).
55
59
  *
56
60
  * @returns {Promise<boolean>} whether a preview now exists at `outputPath`
57
61
  */
58
62
  export async function makeFilePreview(absPath, outputPath) {
59
63
  if (!isPdfFile(absPath)) return false
64
+ let generatePdfThumbnail
65
+ try {
66
+ ;({ generatePdfThumbnail } = await import('./advanced-processors.js'))
67
+ } catch {
68
+ return false
69
+ }
60
70
  const result = await generatePdfThumbnail(absPath, outputPath)
61
71
  return Boolean(result?.success)
62
72
  }
@@ -42,7 +42,7 @@ import { executeFetch, mergeDataIntoContent, toFetchList } from './data-fetcher.
42
42
  import { shouldSplitContent } from './split-content.js'
43
43
  import { jsonForScript } from '@uniweb/core/data-script'
44
44
  // A favicon's MIME type by its extension — the rule a host's page shell types it by too.
45
- import { faviconType } from '@uniweb/core/page-shell'
45
+ import { escapeHtml, faviconType } from '@uniweb/core/page-shell'
46
46
  import { FONT_LINKS_MARKER } from './head-markers.js'
47
47
  import { effectiveSeo, resolveSiteAddress } from './site-address.js'
48
48
  import { collectExtensionAssets, isBrowserAsset } from './emit-extensions.js'
@@ -1177,6 +1177,15 @@ export function siteContentPlugin(options = {}) {
1177
1177
  result = result.replace(/<html([^>]*)\slang="[^"]*"/, `<html$1 lang="${lang}"`)
1178
1178
  }
1179
1179
 
1180
+ // The shell's title is the site's name, as a hosted page's is (`@uniweb/core/page-shell`). A
1181
+ // page writes its own over it, so this is what shows where no page does: a static host's
1182
+ // 404.html, a site that does not prerender, a tab before the bundle runs. ⛔ Until 2026-10-31 it
1183
+ // stayed what the scaffold's `index.html` says, the project folder's name.
1184
+ const siteName = contentToInject?.config?.name
1185
+ if (siteName) {
1186
+ result = result.replace(/<title>[\s\S]*?<\/title>/, () => `<title>${escapeHtml(siteName)}</title>`)
1187
+ }
1188
+
1180
1189
  if (!headInjection) return result
1181
1190
 
1182
1191
  // Insert before </head>
@@ -17,6 +17,7 @@ import { generateFoundationVars } from './theme/index.js'
17
17
  import { DEFAULT_EXTERNALS } from './import-map-plugin.js'
18
18
  import { deriveSupports } from './foundation/derive-supports.js'
19
19
  import { proseWithoutStyles, PROSE_WITHOUT_STYLES_WARNING } from './foundation/prose-styles.js'
20
+ import { staleSources, staleSourcesWarning } from './foundation/stale-sources.js'
20
21
  import { nodeEnvDefine } from './foundation/node-env.js'
21
22
  import { foundationScopeDefine } from './foundation/scope-define.js'
22
23
  import { ssrDormantDynamicImports } from './foundation/ssr-dormant-imports.js'
@@ -26,6 +27,8 @@ import { DEV_REBUILD_MARKER, hasDevRebuildMarker } from './foundation/dev-rebuil
26
27
  // Foundations already told that their prose has no stylesheet — once per process, so a dev
27
28
  // server's rebuild on every save does not repeat it.
28
29
  const warnedProseWithoutStyles = new Set()
30
+ // Likewise for a `@source` that finds nothing.
31
+ const warnedStaleSources = new Set()
29
32
 
30
33
  /**
31
34
  * Build schema.json with preview image references
@@ -451,6 +454,16 @@ export function foundationBuildPlugin(options = {}) {
451
454
  console.warn(PROSE_WITHOUT_STYLES_WARNING)
452
455
  }
453
456
 
457
+ // A `@source` that finds nothing: the build succeeds and the CSS is short every class that
458
+ // was only there, and nothing else says so (`foundation/stale-sources.js`).
459
+ if (!warnedStaleSources.has(resolvedSrcDir)) {
460
+ const stale = staleSources(join(resolvedSrcDir, 'styles.css'))
461
+ if (stale.length) {
462
+ warnedStaleSources.add(resolvedSrcDir)
463
+ console.warn(staleSourcesWarning(stale))
464
+ }
465
+ }
466
+
454
467
  // What host services this foundation actually reaches for, read off the
455
468
  // post-tree-shake module graph rather than asked for in package.json.
456
469
  //