@uniweb/build 1.14.0 → 1.14.2

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.14.0",
3
+ "version": "1.14.2",
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.8",
60
- "@uniweb/projections": "~1.2.10",
61
60
  "@uniweb/schemas": "~1.6.7",
62
61
  "@uniweb/theming": "~1.2.1",
63
62
  "@uniweb/semantic-parser": "~1.13.2",
64
- "@uniweb/content-writer": "~1.3.1"
63
+ "@uniweb/content-writer": "~1.3.1",
64
+ "@uniweb/projections": "~1.2.10"
65
65
  },
66
66
  "optionalDependencies": {
67
- "@uniweb/runtime": "~1.3.9"
67
+ "@uniweb/runtime": "~1.3.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.6.0",
77
- "@uniweb/runtime": "~1.3.9"
76
+ "@uniweb/core": "~1.6.1",
77
+ "@uniweb/runtime": "~1.3.12"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "vite": {
@@ -4,13 +4,17 @@
4
4
  * Auto-generates the foundation entry point based on discovered components.
5
5
  *
6
6
  * Exports:
7
- * - `components` - Object map of component name -> React component
8
- * - `capabilities` - what the runtime reads of src/main.js (`extractFoundationRuntime`): the
9
- * code it calls, referenced from the module, and its data, lean — plus the discovered layouts
10
- * - `meta` - Per-component runtime metadata extracted from meta.js files
7
+ * - each section type, by name: `export { Hero, Team }`
8
+ * - a default export, `{ meta, capabilities, layoutMeta }`:
9
+ * - `capabilities` - what the runtime reads of src/main.js (`extractFoundationRuntime`): the
10
+ * code it calls, referenced from the module, and its data, lean — plus the discovered layouts
11
+ * - `meta` - per-component runtime metadata extracted from meta.js files
12
+ * - `layoutMeta` - per-layout runtime metadata (transitions, layers, scroll, defaults)
13
+ * - what `HOST_SHAREABLE_PACKAGES` names of a package the foundation depends on
11
14
  *
12
- * The `meta` export contains only properties needed at runtime:
15
+ * `meta` contains only properties needed at runtime (`runtime-schema.js`):
13
16
  * - `background` - 'self' opt-out when component handles its own background
17
+ * - `sticky` - whether the section stays in view unless its author says otherwise
14
18
  * - `data` - the `content.data` keys the component declares, with their schema refs
15
19
  * - `vars` - the CSS variables the component declares, with their defaults
16
20
  * - `defaults` - Param default values
package/src/prerender.js CHANGED
@@ -884,6 +884,10 @@ export async function prerenderSite(siteDir, options = {}) {
884
884
 
885
885
  // Pre-render each locale
886
886
  const renderedFiles = []
887
+ // The pages that didn't render, and those left to the browser. Every page has its turn before the
888
+ // build fails, so the report can name them all.
889
+ const failedPages = []
890
+ const skippedPages = []
887
891
  // Each locale's sitemap entries, for the pages it wrote: the sitemap lists what this build serves.
888
892
  const sitemapEntries = []
889
893
  // A redirect stub names its target as the target's own pages do: absolutely, on the site's address.
@@ -1143,8 +1147,13 @@ export async function prerenderSite(siteDir, options = {}) {
1143
1147
  ` Skipped SSG for ${outputRoute} — ${message}. ` +
1144
1148
  `The page will render correctly client-side.`
1145
1149
  )
1150
+ skippedPages.push(outputRoute)
1146
1151
  } else {
1147
- console.warn(` Warning: Failed to render ${outputRoute}: ${message}`)
1152
+ // `?.`: a lockfile can hold an older runtime patch than this build's, and the report
1153
+ // shouldn't turn into its own failure then.
1154
+ const section = renderer.failingSection?.(result.page || page, message) ?? null
1155
+ failedPages.push({ route: outputRoute, message, section })
1156
+ onProgress(` ✗ ${outputRoute}: ${message}`)
1148
1157
  }
1149
1158
  continue
1150
1159
  }
@@ -1231,6 +1240,15 @@ export async function prerenderSite(siteDir, options = {}) {
1231
1240
  }
1232
1241
  }
1233
1242
 
1243
+ // ⛔ A page that didn't render fails the build. Until 2026-11-02 it was a warning, and the build
1244
+ // ended `Workspace build complete!` and exit 0 with the page missing from `dist/`, or an empty
1245
+ // shell at `/`, so `uniweb deploy` went on to ship that. Only a page left to the browser above is
1246
+ // allowed through, since it's written off by what the error says, not by this list.
1247
+ if (failedPages.length > 0) {
1248
+ const total = renderedFiles.length + skippedPages.length + failedPages.length
1249
+ throw new Error(describeFailedPages(failedPages, total))
1250
+ }
1251
+
1234
1252
  // ⭐ The crawler files, from the pages just written (`./site/seo-files.js`). A site's own
1235
1253
  // `public/robots.txt` or `public/sitemap.xml` is its author's, and is left as it is.
1236
1254
  const crawl = crawlerFiles({ content: defaultSiteContent, entries: sitemapEntries })
@@ -1281,8 +1299,42 @@ export async function prerenderSite(siteDir, options = {}) {
1281
1299
 
1282
1300
  return {
1283
1301
  pages: renderedFiles.length,
1284
- files: renderedFiles
1302
+ files: renderedFiles,
1303
+ skipped: skippedPages,
1304
+ }
1305
+ }
1306
+
1307
+ const BROWSER_ONLY = /\b(window|document|navigator|localStorage|sessionStorage) is not defined/
1308
+
1309
+ /**
1310
+ * What a build says about the pages it couldn't render: each thing that went wrong once, where it
1311
+ * happened, and on which pages. One broken section in a layout fails every page, and that's one
1312
+ * thing to fix, not 200 lines to read.
1313
+ *
1314
+ * @param {Array<{ route: string, message: string, section: string|null }>} failed
1315
+ * @param {number} total - The pages the build tried
1316
+ * @returns {string}
1317
+ */
1318
+ function describeFailedPages(failed, total) {
1319
+ const groups = new Map()
1320
+ for (const { route, message, section } of failed) {
1321
+ const key = JSON.stringify([message, section])
1322
+ if (!groups.has(key)) groups.set(key, { message, section, routes: [] })
1323
+ groups.get(key).routes.push(route)
1324
+ }
1325
+
1326
+ const lines = [`${failed.length} of ${total} page${total === 1 ? '' : 's'} didn't render, so this build isn't complete.`]
1327
+ for (const { message, section, routes } of groups.values()) {
1328
+ const shown = routes.slice(0, 3).join(', ')
1329
+ const more = routes.length > 3 ? ` and ${routes.length - 3} more` : ''
1330
+ lines.push('', ` ${message}`)
1331
+ lines.push(section ? ` in section type ${section}` : ' in the layout, or something every section shares')
1332
+ lines.push(` on ${shown}${more}`)
1333
+ if (BROWSER_ONLY.test(message)) {
1334
+ lines.push(" A page is rendered at build time too, where there's no browser: read this inside useEffect.")
1335
+ }
1285
1336
  }
1337
+ return lines.join('\n')
1286
1338
  }
1287
1339
 
1288
1340
  export default prerenderSite
@@ -187,7 +187,10 @@ function refuseVersionsKey(folderYml, pageYml, dirPath) {
187
187
  throw new Error(
188
188
  `[uniweb] ${file}: \`versions:\` is retired. A version is a folder named like \`v1\`, labelled by the ` +
189
189
  `\`title\` in its own page.yml, and the pages beside those folders are the latest. Move the latest ` +
190
- `version's pages up beside the folders, and delete this key.`
190
+ `version's pages up beside the folders, and delete this key. A foundation that draws versions needs ` +
191
+ `the new \`useVersion\` too: \`versions\`, \`currentVersion\` and \`hierarchy\` are what it reads now, and ` +
192
+ `\`versionedScopes\` and \`getVersionUrl\` are gone, so a section still reading those fails to render. ` +
193
+ `See https://docs.uniweb.app/docs/reference/versioning`
191
194
  )
192
195
  }
193
196
 
@@ -1938,6 +1941,17 @@ function determineIndexPage(orderConfig, availableFolders) {
1938
1941
  return sorted[0].name
1939
1942
  }
1940
1943
 
1944
+ /**
1945
+ * The pages of a folder promoted to `/` are at the root and are still its pages, as a push sends
1946
+ * them, so their parent is the homepage. Their route can't say so: the one parent rule climbs a
1947
+ * route, and `/about` has nothing above it.
1948
+ */
1949
+ function notePagesOfHomepage(pages) {
1950
+ for (const page of pages) {
1951
+ if (page.route !== '/' && page.route.lastIndexOf('/') === 0) page.ofHomepage = true
1952
+ }
1953
+ }
1954
+
1941
1955
  /**
1942
1956
  * Recursively collect pages from a directory
1943
1957
  *
@@ -1947,9 +1961,14 @@ function determineIndexPage(orderConfig, availableFolders) {
1947
1961
  * @param {Object} orderConfig - { pages: [...], index: 'name', order: [...] } from parent's config
1948
1962
  * @param {Object} parentFetch - Parent page's fetch config (for dynamic child routes)
1949
1963
  * @param {string} contentMode - 'sections' (default) or 'pages' (md files are child pages)
1964
+ * @param {boolean} [isSiteRoot] - This is the pages directory itself, where a homepage is promoted
1965
+ * and a `404` folder is the site's not-found page. ⛔ Not `parentRoute === '/'`, which holds one
1966
+ * level down too, for the pages of a folder promoted to `/`. Until 2026-11-02 that promoted the
1967
+ * first page of a homepage folder with no content of its own, so a build served it at `/` with no
1968
+ * page at its own address, while a push kept the folder as a container at `/`, leading to it.
1950
1969
  * @returns {Promise<Object>} { pages, assetCollection, iconCollection, notFound }
1951
1970
  */
1952
- async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig = {}, parentFetch = null, contentMode = 'sections', mounts = null, parentLayout = null) {
1971
+ async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig = {}, parentFetch = null, contentMode = 'sections', mounts = null, parentLayout = null, isSiteRoot = false) {
1953
1972
  const entries = await readdir(dirPath)
1954
1973
  const pages = []
1955
1974
  let assetCollection = {
@@ -2053,7 +2072,7 @@ async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig
2053
2072
  // Index promotion only happens at the site root — at deeper levels,
2054
2073
  // pages: controls order only and every folder keeps its natural route.
2055
2074
  let indexName = null
2056
- if (parentRoute === '/') {
2075
+ if (isSiteRoot) {
2057
2076
  indexName = homepageOf(orderConfig) ?? null
2058
2077
  }
2059
2078
 
@@ -2199,19 +2218,20 @@ async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig
2199
2218
  }
2200
2219
  }
2201
2220
 
2221
+ if (parentRoute === '/' && !isSiteRoot) notePagesOfHomepage(pages)
2202
2222
  return { pages, assetCollection, iconCollection, notFound }
2203
2223
  }
2204
2224
 
2205
2225
  // --- Sections mode (default): existing behavior ---
2206
2226
 
2207
2227
  // Determine which page is the index for this level.
2208
- // Index promotion only happens at the site root (parentRoute === '/') — the
2228
+ // Index promotion only happens at the site root — the
2209
2229
  // homepage needs to live at '/'. At all other levels, folders keep their
2210
2230
  // natural route (1:1 folder-to-route mapping). Content-less containers
2211
2231
  // exist in the hierarchy with hasContent: false and auto-redirect at runtime.
2212
2232
  const hasExplicitOrder = orderConfig?.index || (Array.isArray(orderConfig?.pages) && orderConfig.pages.length > 0)
2213
2233
  const hasMdContent = entries.some(e => isMarkdownFile(e))
2214
- const indexPageName = parentRoute === '/' && !hasMdContent
2234
+ const indexPageName = isSiteRoot && !hasMdContent
2215
2235
  ? determineIndexPage(orderConfig, orderedFolders)
2216
2236
  : null
2217
2237
 
@@ -2264,7 +2284,7 @@ async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig
2264
2284
  order: typeof dirConfig.order === 'number' ? dirConfig.order : undefined
2265
2285
  }
2266
2286
 
2267
- if (parentRoute === '/' && entry === '404') {
2287
+ if (isSiteRoot && entry === '404') {
2268
2288
  notFound = containerPage
2269
2289
  } else {
2270
2290
  pages.push(containerPage)
@@ -2298,7 +2318,7 @@ async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig
2298
2318
  }
2299
2319
 
2300
2320
  // Handle 404 page - only at root level
2301
- if (parentRoute === '/' && entry === '404') {
2321
+ if (isSiteRoot && entry === '404') {
2302
2322
  notFound = page
2303
2323
  } else {
2304
2324
  pages.push(page)
@@ -2336,6 +2356,7 @@ async function collectPagesRecursive(dirPath, parentRoute, siteRoot, orderConfig
2336
2356
  }
2337
2357
  }
2338
2358
 
2359
+ if (parentRoute === '/' && !isSiteRoot) notePagesOfHomepage(pages)
2339
2360
  return { pages, assetCollection, iconCollection, notFound }
2340
2361
  }
2341
2362
 
@@ -2686,7 +2707,7 @@ export async function collectSiteContent(sitePath, options = {}) {
2686
2707
 
2687
2708
  // Recursively collect all pages
2688
2709
  let { pages, assetCollection, iconCollection, notFound } =
2689
- await collectPagesRecursive(pagesPath, '/', sitePath, siteOrderConfig, null, rootContentMode, mounts, siteLayout)
2710
+ await collectPagesRecursive(pagesPath, '/', sitePath, siteOrderConfig, null, rootContentMode, mounts, siteLayout, true)
2690
2711
 
2691
2712
  // The layout sections' assets and icons, beside the pages'.
2692
2713
  assetCollection = mergeAssetCollections(assetCollection, layoutAssets)
@@ -2750,8 +2771,9 @@ export async function collectSiteContent(sitePath, options = {}) {
2750
2771
  }
2751
2772
  const hasPage = (route) => pageRouteMap.has(route)
2752
2773
  for (const page of pages) {
2753
- const parentRoute = parentRouteOf(page.route, { has: hasPage })
2774
+ const parentRoute = parentRouteOf(page.route, { declared: page.ofHomepage ? '/' : null, has: hasPage })
2754
2775
  page.parent = parentRoute ? pageRouteMap.get(parentRoute).route : null
2776
+ delete page.ofHomepage
2755
2777
  }
2756
2778
 
2757
2779
  const siteFetch = parseFetchConfig(...fetchIn(siteConfig, 'site.yml', 'site'))
@@ -62,7 +62,7 @@ export const RUNTIME_KEYS = Object.freeze({
62
62
  search: Object.freeze(['enabled', 'provider', 'endpoint', 'include', 'exclude', 'fields', 'weight']),
63
63
  submit: Object.freeze(['enabled', 'endpoint']),
64
64
  assistant: Object.freeze(['enabled', 'endpoint']),
65
- tracking: Object.freeze(['enabled', 'endpoint', 'emit', 'consent', 'scripts', 'flushIntervalMs', 'debug']),
65
+ tracking: Object.freeze(['enabled', 'endpoint', 'emit', 'consent', 'scripts', 'flushIntervalMs', 'debug', 'conversions']),
66
66
  backend: Object.freeze(['enabled', 'endpoint'])
67
67
  })
68
68
 
@@ -87,9 +87,15 @@ const RENAMED_SITE_KEYS = Object.freeze({ $devApi: '$devBackend' })
87
87
  /**
88
88
  * Services only a host provides, which a site never answers itself: no address, no
89
89
  * runtime part. A site does not declare its own record provider — a third-party
90
- * source is a foundation transport.
90
+ * source is a foundation transport. And a Google tag on a site its host publishes is
91
+ * the host's to serve; a site it does not publish installs one its own way (`head.html`).
92
+ *
93
+ * Each with what to write instead of an address.
91
94
  */
92
- const HOST_ONLY = new Set(['records'])
95
+ const HOST_ONLY = new Map([
96
+ ['records', () => '`records: true`'],
97
+ ['google', (value) => `\`google: { id: ${value} }\``]
98
+ ])
93
99
 
94
100
  /**
95
101
  * Credential-shaped keys, mirroring the set the delivery edge strips on the reading
@@ -150,7 +156,7 @@ function entryProblem(name, value) {
150
156
  if (typeof value === 'string') {
151
157
  if (SWITCH_WORDS.test(value.trim())) return switchWord(`services.${name}`, name, value)
152
158
  if (!value.trim()) return `\`services.${name}\` is empty — write true, false, an address, or a map.`
153
- if (HOST_ONLY.has(name)) return `\`services.${name}\` has no address of its own — your host provides it. Write \`${name}: true\`.`
159
+ if (HOST_ONLY.has(name)) return `\`services.${name}\` has no address of its own — your host provides it. Write ${HOST_ONLY.get(name)(value.trim())}.`
154
160
  return null
155
161
  }
156
162
  if (!isMap(value)) return `\`services.${name}\` is true, false, an address, or a map — not ${described(value)}.`
@@ -165,6 +171,45 @@ function entryProblem(name, value) {
165
171
  if (HOST_ONLY.has(name) && addressOf(value)) {
166
172
  return `\`services.${name}\` has no address of its own — your host provides it. Remove \`endpoint\`.`
167
173
  }
174
+ if (name === 'tracking') return conversionsProblem(value.conversions)
175
+ return null
176
+ }
177
+
178
+ /**
179
+ * What is wrong with `services.tracking.conversions`, or null.
180
+ *
181
+ * ⛔ Stopped here rather than ignored, for the reason `entryProblem` stops anything: at a
182
+ * visitor's browser a misread entry counts nothing, which looks exactly like a site where
183
+ * nobody converted.
184
+ *
185
+ * A link is a whole address because it is compared with where a click goes, and a path of
186
+ * the site's own is a `page`, whose rule already handles the base and the language.
187
+ *
188
+ * @param {*} list
189
+ * @returns {string|null}
190
+ */
191
+ function conversionsProblem(list) {
192
+ if (list === undefined) return null
193
+ const path = '`services.tracking.conversions`'
194
+ if (!Array.isArray(list)) {
195
+ return `${path} is a list, each entry a name and a link or a page: \`- { name: booked, page: /thanks }\`.`
196
+ }
197
+ for (const [i, entry] of list.entries()) {
198
+ const at = `${path}[${i}]`
199
+ if (!isMap(entry) || typeof entry.name !== 'string' || !entry.name.trim()) {
200
+ return `${at} needs a \`name\`, which is what your reports show.`
201
+ }
202
+ const { link, page } = entry
203
+ if ((link === undefined) === (page === undefined)) {
204
+ return `${at} names one \`link\` or one \`page\`.`
205
+ }
206
+ if (page !== undefined && (typeof page !== 'string' || !page.startsWith('/'))) {
207
+ return `${at}: \`page\` is a path of this site, like \`/thanks\` — not ${described(page)}.`
208
+ }
209
+ if (link !== undefined && (typeof link !== 'string' || !/^[a-z][a-z0-9+.-]*:/i.test(link.trim()))) {
210
+ return `${at}: \`link\` is a whole address, like \`https://example.com/signup\` or \`tel:+15551234\` — not ${described(link)}. For a page of this site, use \`page\`.`
211
+ }
212
+ }
168
213
  return null
169
214
  }
170
215