@uniweb/build 1.13.4 → 1.13.6
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 +6 -6
- package/src/content/index.js +1 -1
- package/src/i18n/audit.js +7 -2
- package/src/i18n/index.js +5 -2
- package/src/i18n/outdated.js +27 -1
- package/src/prerender.js +3 -2
- package/src/site/content-collector.js +25 -0
- package/src/site/plugin.js +10 -1
- package/src/uwx/locale-sync.js +47 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.6",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -59,12 +59,12 @@
|
|
|
59
59
|
"@uniweb/content-reader": "~1.5.7",
|
|
60
60
|
"@uniweb/content-writer": "~1.3.1",
|
|
61
61
|
"@uniweb/schemas": "~1.6.7",
|
|
62
|
-
"@uniweb/
|
|
63
|
-
"@uniweb/
|
|
64
|
-
"@uniweb/
|
|
62
|
+
"@uniweb/semantic-parser": "~1.13.0",
|
|
63
|
+
"@uniweb/projections": "~1.2.9",
|
|
64
|
+
"@uniweb/theming": "~1.2.1"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@uniweb/runtime": "~1.3.
|
|
67
|
+
"@uniweb/runtime": "~1.3.4"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
|
|
75
75
|
"vite-plugin-svgr": "^4.0.0",
|
|
76
76
|
"@uniweb/core": "~1.5.1",
|
|
77
|
-
"@uniweb/runtime": "~1.3.
|
|
77
|
+
"@uniweb/runtime": "~1.3.4"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"vite": {
|
package/src/content/index.js
CHANGED
|
@@ -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)
|
package/src/i18n/audit.js
CHANGED
|
@@ -11,6 +11,8 @@ import { readFile, writeFile } from 'fs/promises'
|
|
|
11
11
|
import { existsSync } from 'node:fs'
|
|
12
12
|
import { join } from 'node:path'
|
|
13
13
|
import { translationKeepsMarkup } from './merge.js'
|
|
14
|
+
import { KEPT_FILE } from './locales.js'
|
|
15
|
+
import { standingFlags } from '../uwx/locale-sync.js'
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Audit a locale file against the manifest
|
|
@@ -42,6 +44,8 @@ export async function auditLocale(localesPath, locale) {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
const translations = JSON.parse(await readFile(localePath, 'utf-8'))
|
|
47
|
+
const keptPath = join(localesPath, KEPT_FILE)
|
|
48
|
+
const kept = existsSync(keptPath) ? JSON.parse(await readFile(keptPath, 'utf-8')) : {}
|
|
45
49
|
const translationHashes = new Set(Object.keys(translations))
|
|
46
50
|
|
|
47
51
|
const valid = []
|
|
@@ -57,8 +61,9 @@ export async function auditLocale(localesPath, locale) {
|
|
|
57
61
|
const source = unit.source
|
|
58
62
|
const translation = getTranslationText(translations[hash])
|
|
59
63
|
// Made from an older source text (`locale-sync.js::settleEntry`). It still shows.
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
const standing = standingFlags(translations[hash], translations, locale, kept)
|
|
65
|
+
if (Object.keys(standing).length) {
|
|
66
|
+
outdated.push({ hash, source, translation, was: [...new Set(Object.values(standing))] })
|
|
62
67
|
continue
|
|
63
68
|
}
|
|
64
69
|
valid.push({ hash, source, translation })
|
package/src/i18n/index.js
CHANGED
|
@@ -16,7 +16,8 @@ import { availableLocales, resolveLocaleList, localesToBuild } from './locales.j
|
|
|
16
16
|
import { extractTranslatableContent } from './extract.js'
|
|
17
17
|
import { dataBlockModels } from './data-models.js'
|
|
18
18
|
import { syncManifests, formatSyncReport, formatKeptTranslations } from './sync.js'
|
|
19
|
-
import { keepEditedTranslations, rowsWantTranslation, manifestRows } from './outdated.js'
|
|
19
|
+
import { keepEditedTranslations, rowsWantTranslation, manifestRows, settleFlags } from './outdated.js'
|
|
20
|
+
import { readKept, standingFlags } from '../uwx/locale-sync.js'
|
|
20
21
|
import { mergeTranslations, generateAllLocales } from './merge.js'
|
|
21
22
|
import { auditLocale, cleanLocale, formatAuditReport } from './audit.js'
|
|
22
23
|
import {
|
|
@@ -186,6 +187,7 @@ export async function extractManifest(siteRoot, siteContent, options = {}) {
|
|
|
186
187
|
// Generate sync report
|
|
187
188
|
const report = syncManifests(previousManifest, manifest)
|
|
188
189
|
|
|
190
|
+
settleFlags(siteRoot, { sourceLocale: manifest.defaultLocale, dryRun })
|
|
189
191
|
// What the manifest is about to forget says what an edited text's translation was made from.
|
|
190
192
|
report.kept = keepEditedTranslations(siteRoot, manifestRows(previousManifest), manifestRows(manifest), {
|
|
191
193
|
sourceLocale: manifest.defaultLocale,
|
|
@@ -272,6 +274,7 @@ export async function getTranslationStatus(siteRoot, options = {}) {
|
|
|
272
274
|
const totalUnits = Object.keys(manifest.units).length
|
|
273
275
|
|
|
274
276
|
const status = {}
|
|
277
|
+
const kept = readKept(siteRoot)
|
|
275
278
|
|
|
276
279
|
for (const locale of locales) {
|
|
277
280
|
const localePath = join(localesPath, `${locale}.json`)
|
|
@@ -296,7 +299,7 @@ export async function getTranslationStatus(siteRoot, options = {}) {
|
|
|
296
299
|
|
|
297
300
|
for (const hash of Object.keys(manifest.units)) {
|
|
298
301
|
// An entry flagged `outdated` still renders, and is not this text's translation.
|
|
299
|
-
if (translations[hash]
|
|
302
|
+
if (Object.keys(standingFlags(translations[hash], translations, locale, kept)).length) {
|
|
300
303
|
outdated++
|
|
301
304
|
} else if (translatedHashes.has(hash)) {
|
|
302
305
|
translated++
|
package/src/i18n/outdated.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { computeHash } from './hash.js'
|
|
18
18
|
import { toPlainText } from './merge.js'
|
|
19
19
|
import { isSmallEdit, wordOverlap } from './word-overlap.js'
|
|
20
|
-
import { discoverLocales, loadLocaleTranslations, translationFor, addTranslationEntries } from '../uwx/locale-sync.js'
|
|
20
|
+
import { discoverLocales, loadLocaleTranslations, translationFor, addTranslationEntries, readKept, standingFlags } from '../uwx/locale-sync.js'
|
|
21
21
|
|
|
22
22
|
// A language's words for a text here. Not an empty one, nor the text's own: `uniweb i18n init` starts a
|
|
23
23
|
// language's file with each text's source, and that is nothing to keep.
|
|
@@ -144,3 +144,29 @@ export function keepEditedTranslations(siteRoot, previous, current, { sourceLoca
|
|
|
144
144
|
}
|
|
145
145
|
return kept
|
|
146
146
|
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Take out of each language's file a flag whose entry has been written over (`standingFlags`), so the file
|
|
150
|
+
* says what a push and `uniweb i18n status` already read. On a site with no backend nothing else would.
|
|
151
|
+
*
|
|
152
|
+
* @param {string} siteRoot
|
|
153
|
+
* @param {object} [o]
|
|
154
|
+
* @param {string} [o.sourceLocale]
|
|
155
|
+
* @param {boolean} [o.dryRun]
|
|
156
|
+
*/
|
|
157
|
+
export function settleFlags(siteRoot, { sourceLocale = null, dryRun = false } = {}) {
|
|
158
|
+
if (dryRun) return
|
|
159
|
+
const kept = readKept(siteRoot)
|
|
160
|
+
for (const [locale, table] of Object.entries(languageTables(siteRoot, sourceLocale))) {
|
|
161
|
+
const settled = {}
|
|
162
|
+
for (const [hash, entry] of Object.entries(table)) {
|
|
163
|
+
if (!entry?.outdated) continue
|
|
164
|
+
const standing = standingFlags(entry, table, locale, kept)
|
|
165
|
+
if (Object.keys(standing).length === Object.keys(entry.outdated).length) continue
|
|
166
|
+
const { outdated: _flags, ...rest } = entry
|
|
167
|
+
if (Object.keys(standing).length) settled[hash] = { ...rest, outdated: standing }
|
|
168
|
+
else settled[hash] = Object.keys(rest).length === 1 && typeof rest.default === 'string' ? rest.default : rest
|
|
169
|
+
}
|
|
170
|
+
if (Object.keys(settled).length) addTranslationEntries(siteRoot, locale, settled)
|
|
171
|
+
}
|
|
172
|
+
}
|
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,
|
|
@@ -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
|
package/src/site/plugin.js
CHANGED
|
@@ -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>
|
package/src/uwx/locale-sync.js
CHANGED
|
@@ -180,6 +180,44 @@ export function restoreKept(localized, held, files = null) {
|
|
|
180
180
|
return out
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
* ⭐ WORDS WRITTEN OVER A FLAGGED TRANSLATION END ITS FLAG, as an edit in the app's cell does: whoever typed
|
|
185
|
+
* them reviewed it, whatever they left beside them in the file. What the flag was made with is what the app
|
|
186
|
+
* keeps for the older text, else that text's own entry, which a file edit's flag leaves in place. With
|
|
187
|
+
* neither left to compare, it holds. ⛔ Until 2026-10-31 a new `default` beside `outdated` stayed flagged: a
|
|
188
|
+
* push wrote the map's entry from it.
|
|
189
|
+
*
|
|
190
|
+
* @param {string} words - what the row reads
|
|
191
|
+
* @param {string} older - the text the flag names
|
|
192
|
+
* @param {Array} [held] - the inline content the app keeps for that text in this language
|
|
193
|
+
* @param {object} table - the language's translation file
|
|
194
|
+
* @param {object} context - the row's translation context
|
|
195
|
+
* @returns {boolean}
|
|
196
|
+
*/
|
|
197
|
+
function flagHolds(words, older, held, table, context) {
|
|
198
|
+
const made = Array.isArray(held) ? elementText({ content: held }) : toPlainText(translationFor(table[computeHash(older)], context))
|
|
199
|
+
return typeof made !== 'string' || computeHash(made) === computeHash(words)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* An entry's flags that still hold, by place (`flagHolds`): what it is outdated in, whatever else it says.
|
|
204
|
+
*
|
|
205
|
+
* @param {*} entry - a translation file's entry
|
|
206
|
+
* @param {object} table - the language's translation file
|
|
207
|
+
* @param {string} locale
|
|
208
|
+
* @param {object} [kept] - what `readKept` gives
|
|
209
|
+
* @returns {{ [place: string]: string }}
|
|
210
|
+
*/
|
|
211
|
+
export function standingFlags(entry, table, locale, kept = {}) {
|
|
212
|
+
return Object.fromEntries(
|
|
213
|
+
Object.entries(entry?.outdated || {}).filter(([place, older]) => {
|
|
214
|
+
const context = { key: place }
|
|
215
|
+
const words = toPlainText(translationFor(entry, context))
|
|
216
|
+
return typeof words === 'string' && flagHolds(words, older, kept[place]?.['@']?.translations?.[older]?.[locale], table, context)
|
|
217
|
+
}),
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
183
221
|
/**
|
|
184
222
|
* ⭐ WHICH ROWS ARE OUTDATED IS THE TRANSLATION FILES' TO SAY, and the app reads it from `@.translations`:
|
|
185
223
|
* a row is outdated when its translation is kept there under a similar text (`olderSourceOf`). So a flagged
|
|
@@ -206,14 +244,17 @@ function mapWithFlags(at, localized, { sourceLocale, translations, context, free
|
|
|
206
244
|
const read = blockElements(localized[locale])
|
|
207
245
|
if (read.length !== rows.length) continue
|
|
208
246
|
const keys = rows.map((row) => elementText(row))
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
247
|
+
const flagged = keys.map((key, i) => {
|
|
248
|
+
const older = key ? table[computeHash(key)]?.outdated?.[place] : undefined
|
|
249
|
+
if (typeof older !== 'string' || older === key) return null
|
|
250
|
+
return flagHolds(elementText(read[i]), older, map?.[older]?.[locale], table, context) ? older : null
|
|
251
|
+
})
|
|
252
|
+
const claimed = new Set(flagged)
|
|
253
|
+
flagged.forEach((older, i) => {
|
|
254
|
+
if (older && !map?.[older]?.[locale]) (writable()[older] ||= {})[locale] = read[i].content
|
|
214
255
|
})
|
|
215
256
|
keys.forEach((key, i) => {
|
|
216
|
-
if (!key ||
|
|
257
|
+
if (!key || flagged[i] || translationFor(table[computeHash(key)], context) === undefined) return
|
|
217
258
|
const says = elementText(read[i])
|
|
218
259
|
for (const [older, byLocale] of Object.entries(map || {})) {
|
|
219
260
|
if (older === key || claimed.has(older) || !Array.isArray(byLocale?.[locale]) || !isSmallEdit(older, key)) continue
|