@uniweb/build 1.15.0 → 1.15.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.15.0",
3
+ "version": "1.15.2",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -58,13 +58,13 @@
58
58
  "yaml": "^2.5.0",
59
59
  "@uniweb/content-reader": "~1.5.8",
60
60
  "@uniweb/schemas": "~1.6.7",
61
- "@uniweb/projections": "~1.2.10",
61
+ "@uniweb/content-writer": "~1.3.1",
62
62
  "@uniweb/semantic-parser": "~1.13.2",
63
63
  "@uniweb/theming": "~1.2.1",
64
- "@uniweb/content-writer": "~1.3.1"
64
+ "@uniweb/projections": "~1.2.11"
65
65
  },
66
66
  "optionalDependencies": {
67
- "@uniweb/runtime": "~1.4.0"
67
+ "@uniweb/runtime": "~1.4.2"
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.1",
77
- "@uniweb/runtime": "~1.4.0"
76
+ "@uniweb/core": "~1.6.3",
77
+ "@uniweb/runtime": "~1.4.2"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "vite": {
@@ -139,8 +139,10 @@ export function mountDevApi(server, { root }) {
139
139
  const response = await handler(new Request(new URL(inner, origin), init))
140
140
  res.statusCode = response.status
141
141
  response.headers.forEach((value, key) => res.setHeader(key, value))
142
- const text = await response.text()
143
- res.end(text || undefined)
142
+ // Bytes, never text: a handler may answer an image or a file, and reading it as
143
+ // text decodes it as UTF-8, turning every byte above 127 into U+FFFD.
144
+ const bytes = Buffer.from(await response.arrayBuffer())
145
+ res.end(bytes.length ? bytes : undefined)
144
146
  } catch (err) {
145
147
  res.statusCode = 500
146
148
  res.setHeader('content-type', 'application/json')
package/src/prerender.js CHANGED
@@ -23,7 +23,7 @@ import {
23
23
  deriveCacheKey,
24
24
  evaluateQuery,
25
25
  } from '@uniweb/core'
26
- import { recordTitle, recordImage, routePatternToRegex, routeFieldOf } from '@uniweb/core/route-match'
26
+ import { isDynamicRoute, recordTitle, recordImage, routePatternToRegex, routeFieldOf } from '@uniweb/core/route-match'
27
27
  import DataStore from '@uniweb/core/datastore'
28
28
  import { executeFetch, mergeDataIntoContent, toFetchList } from './site/data-fetcher.js'
29
29
  import { createFileTransport } from './site/file-transport.js'
@@ -1031,7 +1031,7 @@ export async function prerenderSite(siteDir, options = {}) {
1031
1031
  for (const page of website.pages) {
1032
1032
  // Skip dynamic template pages — they exist in the content for runtime
1033
1033
  // route matching but can't be pre-rendered (no concrete route)
1034
- if (page.route.includes(':')) continue
1034
+ if (isDynamicRoute(page.route)) continue
1035
1035
 
1036
1036
  // Build the output route with locale prefix
1037
1037
  // For non-default locales, translate route slugs (e.g., /about → /acerca-de)
@@ -119,6 +119,48 @@ function extractRouteParam(folderName) {
119
119
  return match ? match[1] : null
120
120
  }
121
121
 
122
+ /** `?` starts a URL's query, `#` its fragment and `%` an escape. */
123
+ const URL_CHARACTER = /[?#%]/
124
+
125
+ /**
126
+ * A route holds none of a URL's own characters [Diego, 2026-11-02]. Without them a route goes into
127
+ * a link as it is, whoever writes the link: kit, the runtime, or a foundation's own
128
+ * `href={page.route}`. With one, the page still answered and the links to it broke:
129
+ * `/What-is-this?` was linked as `/What-is-this`, and `/C#-guide` as `/C` and a fragment.
130
+ *
131
+ * Every place a route is made asks this, on a build and on a push: a folder's name
132
+ * (`assertRouteFolder`), a page file's name (`folderModePageFiles`), a page's `slug:`
133
+ * (`buildRouteTranslations`, and the push's `localizeRouteSlugs`) and `site.yml`'s
134
+ * `i18n.routeTranslations` (`collectSiteContent`, and the push's `localizeRouteSlugs`).
135
+ *
136
+ * @param {string} value - the name, slug or route
137
+ * @param {string} what - says where it is, with the value, e.g. "a folder named `faq?`"
138
+ */
139
+ export function refuseUrlCharacters(value, what) {
140
+ const found = typeof value === 'string' ? value.match(URL_CHARACTER) : null
141
+ if (!found) return
142
+ throw new Error(
143
+ `[uniweb] pages: ${what} holds \`${found[0]}\`, and a route can't hold \`?\`, \`#\` or \`%\`: ` +
144
+ `a URL reads them as its own, so every link to the page would break. Rename it without them.`
145
+ )
146
+ }
147
+
148
+ /**
149
+ * `site.yml`'s `i18n.routeTranslations`, `{ <locale>: { <canonical route>: <its route there> } }`,
150
+ * refused when a route in it holds `?`, `#` or `%` (`refuseUrlCharacters`).
151
+ *
152
+ * @param {*} map
153
+ */
154
+ export function refuseUrlCharactersInTranslations(map) {
155
+ if (!map || typeof map !== 'object' || Array.isArray(map)) return
156
+ for (const [locale, table] of Object.entries(map)) {
157
+ if (!table || typeof table !== 'object' || Array.isArray(table)) continue
158
+ for (const [canonical, shown] of Object.entries(table)) {
159
+ refuseUrlCharacters(shown, `\`site.yml\`'s \`i18n.routeTranslations.${locale}\` gives ${canonical} the route \`${shown}\`, which`)
160
+ }
161
+ }
162
+ }
163
+
122
164
  /**
123
165
  * Folders the build refuses on a route, ruled 2026-09-11 [Diego]:
124
166
  *
@@ -139,6 +181,7 @@ function extractRouteParam(folderName) {
139
181
  * @param {string} parentRoute - the route of the folder it sits in
140
182
  */
141
183
  function assertRouteFolder(name, parentRoute) {
184
+ refuseUrlCharacters(name, `a folder named \`${name}\``)
142
185
  if (name === '[dir]' || name === '[path]') {
143
186
  const hint = name === '[path]' ? ' Did you mean `[...path]`, which captures a path of any depth?' : ''
144
187
  throw new Error(
@@ -743,6 +786,7 @@ export function layerMountedFolder(name, local, mounted, contentMode) {
743
786
  export function folderModePageFiles(entries, orderConfig) {
744
787
  const items = entries.filter(isMarkdownFile).sort(compareFilenames).map((file) => {
745
788
  const { name } = parse(file)
789
+ refuseUrlCharacters(name, `a page file named \`${file}\``)
746
790
  return { file, name: parseNumericPrefix(name).name || name }
747
791
  })
748
792
  const parsed = Array.isArray(orderConfig?.pages) ? parseWildcardArray(orderConfig.pages) : null
@@ -2812,6 +2856,7 @@ export async function collectSiteContent(sitePath, options = {}) {
2812
2856
  // keeps the canonical (folder-based) route. Strip the build-time `slug` from
2813
2857
  // pages afterward — the runtime hydrates the precomputed map, not per-page
2814
2858
  // slugs (see "Minimize Runtime Payload").
2859
+ refuseUrlCharactersInTranslations(siteConfig?.i18n?.routeTranslations)
2815
2860
  const defaultLocale = resolveDefaultLocale(siteConfig)
2816
2861
  const langValidation = validateLanguageConfig(siteConfig)
2817
2862
  for (const { message } of langValidation.warnings) {
@@ -3064,6 +3109,7 @@ function buildRouteTranslations(pages, { defaultLocale = 'en', languages = null
3064
3109
  )
3065
3110
  continue
3066
3111
  }
3112
+ refuseUrlCharacters(segment, `\`slug.${locale}\` of the page at ${canonicalRoute}, \`${segment}\`,`)
3067
3113
  if (!isValidSlugSegment(segment)) {
3068
3114
  console.warn(
3069
3115
  `[content-collector] invalid slug '${segment}' for '${canonicalRoute}' (${locale}) — must be a single URL-safe path segment`
@@ -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', 'conversions']),
65
+ tracking: Object.freeze(['enabled', 'endpoint', 'emit', 'consent', 'scripts', 'flushIntervalMs', 'debug', 'conversions', 'landing']),
66
66
  backend: Object.freeze(['enabled', 'endpoint'])
67
67
  })
68
68
 
@@ -94,9 +94,20 @@ const RENAMED_SITE_KEYS = Object.freeze({ $devApi: '$devBackend' })
94
94
  */
95
95
  const HOST_ONLY = new Map([
96
96
  ['records', () => '`records: true`'],
97
- ['google', (value) => `\`google: { id: ${value} }\``]
97
+ ['google', (value) => `\`google: { id: ${value} }\``],
98
+ ['meta', (value) => `\`meta: { pixel: '${value}' }\``],
99
+ ['x', (value) => `\`x: { pixel: '${value}' }\``]
98
100
  ])
99
101
 
102
+ /**
103
+ * Ad platforms a host tells of a site's conversions, server-side: `pixel` is the platform's
104
+ * public ID for the site, `events` names each conversion the site reports
105
+ * (`services.tracking.conversions`, a foundation's `block.track('conversion', …)`) to the
106
+ * platform's own event. The platform's token is a secret, set where secrets are set and never
107
+ * in this file — `token` here is a credential key, which a push never sends.
108
+ */
109
+ const AD_PLATFORMS = new Set(['meta', 'x'])
110
+
100
111
  /**
101
112
  * Credential-shaped keys, mirroring the set the delivery edge strips on the reading
102
113
  * side — deliberately the SAME list, so the two guards are visibly twins. Never sent
@@ -171,7 +182,39 @@ function entryProblem(name, value) {
171
182
  if (HOST_ONLY.has(name) && addressOf(value)) {
172
183
  return `\`services.${name}\` has no address of its own — your host provides it. Remove \`endpoint\`.`
173
184
  }
174
- if (name === 'tracking') return conversionsProblem(value.conversions)
185
+ if (name === 'tracking') return conversionsProblem(value.conversions) || landingProblem(value.landing)
186
+ if (AD_PLATFORMS.has(name)) return adPlatformProblem(name, value)
187
+ return null
188
+ }
189
+
190
+ /**
191
+ * What is wrong with an ad platform's entry, or null.
192
+ *
193
+ * ⛔ A pixel written as a bare number is refused, and not echoed back. YAML reads a long ID as a
194
+ * number, and an ID past 2^53 — a 16-digit dataset ID can be — is already a different number by
195
+ * the time this sees it, so repeating it would hand the author the wrong digits. Neither mistake
196
+ * shows anywhere a visitor goes: the platform hears nothing, which looks like no conversions.
197
+ *
198
+ * @param {string} name
199
+ * @param {object} value
200
+ * @returns {string|null}
201
+ */
202
+ function adPlatformProblem(name, { pixel, events }) {
203
+ if (pixel !== undefined && typeof pixel !== 'string') {
204
+ return typeof pixel === 'number'
205
+ ? `\`services.${name}.pixel\` is a number, and YAML can change the last digits of a long one. Copy the ID from the platform again and write it in quotes: \`pixel: '…'\`.`
206
+ : `\`services.${name}.pixel\` is the platform's ID, in quotes — not ${described(pixel)}.`
207
+ }
208
+ if (typeof pixel === 'string' && !pixel.trim()) return `\`services.${name}.pixel\` is empty.`
209
+ if (events === undefined) return null
210
+ if (!isMap(events)) {
211
+ return `\`services.${name}.events\` names each conversion to the platform's event — \`events: { signup: <event> }\` — not ${described(events)}.`
212
+ }
213
+ for (const [conversion, event] of Object.entries(events)) {
214
+ if (typeof event !== 'string' || !event.trim()) {
215
+ return `\`services.${name}.events.${conversion}\` is the platform's event for \`${conversion}\` — not ${described(event)}.`
216
+ }
217
+ }
175
218
  return null
176
219
  }
177
220
 
@@ -213,6 +256,28 @@ function conversionsProblem(list) {
213
256
  return null
214
257
  }
215
258
 
259
+ /**
260
+ * What is wrong with `services.tracking.landing`, or null: the query keys of the address a
261
+ * visitor arrived at that each conversion carries. Stopped here for the same reason as a
262
+ * conversion: at a visitor's browser a misread list carries nothing, and nothing says so.
263
+ *
264
+ * @param {*} list
265
+ * @returns {string|null}
266
+ */
267
+ function landingProblem(list) {
268
+ if (list === undefined) return null
269
+ const path = '`services.tracking.landing`'
270
+ if (!Array.isArray(list)) {
271
+ return `${path} is a list of the landing address's query keys a conversion carries: \`[utm_source, utm_campaign]\` — not ${described(list)}.`
272
+ }
273
+ for (const [i, key] of list.entries()) {
274
+ if (typeof key !== 'string' || !key.trim()) {
275
+ return `${path}[${i}] is a query key, like \`utm_campaign\` — not ${described(key)}.`
276
+ }
277
+ }
278
+ return null
279
+ }
280
+
216
281
  /**
217
282
  * Every entry of `site.yml::services` that neither a build nor a push can read, each said
218
283
  * with its fix — [] when there is none.
package/src/uwx/site.js CHANGED
@@ -71,6 +71,8 @@ import {
71
71
  rootOrderConfig,
72
72
  composeLocalizedRoute,
73
73
  isValidSlugSegment,
74
+ refuseUrlCharacters,
75
+ refuseUrlCharactersInTranslations,
74
76
  authoredId,
75
77
  } from '../site/content-collector.js'
76
78
  import { carrySectionFile, rewriteFileLinks } from '../site/file-links.js'
@@ -145,8 +147,9 @@ function localizeRouteSlugs(pages, siteYml, sourceLocale) {
145
147
  let ownForm = false
146
148
  visit(pages, '/', (record) => { if (record[AUTHORED_SLUG]) ownForm = true })
147
149
  if (ownForm) {
148
- visit(pages, '/', (record) => {
150
+ visit(pages, '/', (record, route) => {
149
151
  for (const [locale, segment] of Object.entries(record[AUTHORED_SLUG] || {})) {
152
+ refuseUrlCharacters(segment, `\`slug.${locale}\` of the page at ${route}, \`${segment}\`,`)
150
153
  if (carried(locale, segment)) record.slug[locale] = segment
151
154
  }
152
155
  })
@@ -154,6 +157,7 @@ function localizeRouteSlugs(pages, siteYml, sourceLocale) {
154
157
  }
155
158
  const map = siteYml?.i18n?.routeTranslations
156
159
  if (!isPlainRecord(map)) return
160
+ refuseUrlCharactersInTranslations(map)
157
161
  const segments = new Map() // canonical route → { locale: segment }, as the build composes them
158
162
  visit(pages, '/', (record, route, parentRoute) => {
159
163
  if (record.is_dynamic || record.is_index) return