@uniweb/build 1.11.0 → 1.11.1
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 +7 -7
- package/src/i18n/index.js +24 -5
- package/src/i18n/locales.js +28 -2
- package/src/prerender.js +3 -0
- package/src/site/assets.js +70 -0
- package/src/site/plugin.js +42 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"js-yaml": "^4.3.2",
|
|
57
57
|
"sharp": "^0.35.5",
|
|
58
58
|
"yaml": "^2.5.0",
|
|
59
|
+
"@uniweb/content-writer": "~1.3.1",
|
|
59
60
|
"@uniweb/schemas": "~1.6.5",
|
|
60
|
-
"@uniweb/content-reader": "~1.5.7",
|
|
61
61
|
"@uniweb/theming": "~1.2.1",
|
|
62
|
-
"@uniweb/
|
|
63
|
-
"@uniweb/
|
|
64
|
-
"@uniweb/
|
|
62
|
+
"@uniweb/content-reader": "~1.5.7",
|
|
63
|
+
"@uniweb/projections": "~1.2.7",
|
|
64
|
+
"@uniweb/semantic-parser": "~1.13.0"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
67
|
"@uniweb/runtime": "~1.2.13"
|
|
@@ -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/
|
|
77
|
-
"@uniweb/
|
|
76
|
+
"@uniweb/runtime": "~1.2.13",
|
|
77
|
+
"@uniweb/core": "~1.4.12"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"vite": {
|
package/src/i18n/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { existsSync } from 'node:fs'
|
|
|
12
12
|
import { join, dirname } from 'node:path'
|
|
13
13
|
|
|
14
14
|
import { computeHash, normalizeText } from './hash.js'
|
|
15
|
-
import { availableLocales, resolveLocaleList } from './locales.js'
|
|
15
|
+
import { availableLocales, resolveLocaleList, localesToBuild } from './locales.js'
|
|
16
16
|
import { extractTranslatableContent } from './extract.js'
|
|
17
17
|
import { dataBlockModels } from './data-models.js'
|
|
18
18
|
import { syncManifests, formatSyncReport } from './sync.js'
|
|
@@ -82,6 +82,7 @@ export {
|
|
|
82
82
|
// Locale resolution
|
|
83
83
|
getAvailableLocales,
|
|
84
84
|
resolveLocales,
|
|
85
|
+
localesToBuild,
|
|
85
86
|
|
|
86
87
|
// Free-form translation functions
|
|
87
88
|
loadFreeformTranslation,
|
|
@@ -444,15 +445,21 @@ export async function buildLocalizedContent(siteRoot, options = {}) {
|
|
|
444
445
|
// What each section type declares its data blocks are, so a block translates what extraction offered.
|
|
445
446
|
const dataModel = await dataBlockModels(siteRoot)
|
|
446
447
|
|
|
448
|
+
// ⭐ Where the bundle put each file a page names, a translation's among them (`site/plugin.js::
|
|
449
|
+
// generateBundle`, `collectTranslatedAssets`): a language's page shows the build's copy of the
|
|
450
|
+
// file its translation names, as the default language's page does. The bundle's note to this
|
|
451
|
+
// step, taken out of the payload here, since no page reads it.
|
|
452
|
+
const builtAssets = siteContent.builtAssets
|
|
453
|
+
delete siteContent.builtAssets
|
|
454
|
+
|
|
447
455
|
// ⭐ The DEFAULT locale's payload needs the same stamp. It is not written in
|
|
448
456
|
// this loop — it is the source this function reads — but a visitor landing on
|
|
449
457
|
// `/` gets a Website built from it, and without the set that page loses its
|
|
450
458
|
// language switcher while every translated page has one.
|
|
451
459
|
const stampedLanguages = declaredLanguages(siteContent.config, defaultLocale, locales)
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
460
|
+
const restamp = JSON.stringify(siteContent.config?.languages) !== JSON.stringify(stampedLanguages)
|
|
461
|
+
if (restamp) siteContent.config = { ...siteContent.config, languages: stampedLanguages }
|
|
462
|
+
if (restamp || builtAssets) await writeFile(siteContentPath, JSON.stringify(siteContent, null, 2))
|
|
456
463
|
|
|
457
464
|
// The paths the site's source holds a section at, drafts included — read once, and only
|
|
458
465
|
// when a translation translates nothing this build publishes (`warnAboutFreeformIssues`).
|
|
@@ -513,6 +520,8 @@ export async function buildLocalizedContent(siteRoot, options = {}) {
|
|
|
513
520
|
})
|
|
514
521
|
}
|
|
515
522
|
|
|
523
|
+
if (builtAssets) translated = await builtCopies(translated, builtAssets)
|
|
524
|
+
|
|
516
525
|
// Mark the active locale in the translated content, and stamp the resolved
|
|
517
526
|
// locale set so the runtime does not have to re-derive it — see
|
|
518
527
|
// `declaredLanguages`.
|
|
@@ -537,6 +546,16 @@ export async function buildLocalizedContent(siteRoot, options = {}) {
|
|
|
537
546
|
return outputs
|
|
538
547
|
}
|
|
539
548
|
|
|
549
|
+
/**
|
|
550
|
+
* A language's content with each file its translations name pointed at the build's copy
|
|
551
|
+
* (`builtAssets`, `{ paths, files }` by the reference as written). The bundle's own rewrite, loaded
|
|
552
|
+
* only on the lane that processed media, which is the one that left the note.
|
|
553
|
+
*/
|
|
554
|
+
async function builtCopies(content, builtAssets) {
|
|
555
|
+
const { rewriteSiteContentPaths } = await import('../site/asset-processor.js')
|
|
556
|
+
return rewriteSiteContentPaths(content, builtAssets.paths || {}, builtAssets.files || null)
|
|
557
|
+
}
|
|
558
|
+
|
|
540
559
|
/**
|
|
541
560
|
* Check for stale/orphaned free-form translations and emit warnings
|
|
542
561
|
* @param {string} locale - Locale code
|
package/src/i18n/locales.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
// which has none — was pushed as a one-language site, and none of its translations left the
|
|
7
7
|
// machine, while the build of the same site produced every one of them.
|
|
8
8
|
//
|
|
9
|
-
// A leaf, with nothing but `node:fs`
|
|
10
|
-
// the rest of the i18n module.
|
|
9
|
+
// A leaf, with nothing but `node:fs` and core's locale rules (a leaf too) beneath it, so the sync
|
|
10
|
+
// lane can use it without pulling in the rest of the i18n module.
|
|
11
11
|
|
|
12
12
|
import { existsSync, readdirSync } from 'node:fs'
|
|
13
|
+
import { normalizeLanguageList, resolveDefaultLocale } from '@uniweb/core/locale-config'
|
|
13
14
|
|
|
14
15
|
// Files in the locales directory that are not a locale's translations.
|
|
15
16
|
export const RESERVED_LOCALE_FILES = new Set(['manifest.json', '_memory.json'])
|
|
@@ -49,3 +50,28 @@ export function resolveLocaleList(configLocales, localesPath) {
|
|
|
49
50
|
}
|
|
50
51
|
return availableLocales(localesPath)
|
|
51
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The languages a build makes pages in besides its default: the site's locales
|
|
56
|
+
* (`resolveLocaleList`), only those `publishLanguages:` lists when it lists any, never the default,
|
|
57
|
+
* which is the root tree. One rule for `uniweb build`, which makes each one's pages, and for the
|
|
58
|
+
* bundle, which processes the files their translations name (`site/plugin.js`), so the second
|
|
59
|
+
* never processes for a language the first does not make, nor misses one it does.
|
|
60
|
+
*
|
|
61
|
+
* @param {Object} siteConfig - `site.yml`, as written
|
|
62
|
+
* @param {string} localesPath - the locales directory
|
|
63
|
+
* @returns {{ locales: string[], skipped: string[], defaultLocale: string }} the languages a build
|
|
64
|
+
* makes, and those `publishLanguages:` leaves out
|
|
65
|
+
*/
|
|
66
|
+
export function localesToBuild(siteConfig, localesPath) {
|
|
67
|
+
const config = siteConfig || {}
|
|
68
|
+
let locales = resolveLocaleList(config.languages, localesPath)
|
|
69
|
+
let skipped = []
|
|
70
|
+
if (config.publishLanguages != null) {
|
|
71
|
+
const publish = new Set(normalizeLanguageList(config.publishLanguages))
|
|
72
|
+
skipped = locales.filter((l) => !publish.has(l))
|
|
73
|
+
locales = locales.filter((l) => publish.has(l))
|
|
74
|
+
}
|
|
75
|
+
const defaultLocale = resolveDefaultLocale(config)
|
|
76
|
+
return { locales: locales.filter((l) => l !== defaultLocale), skipped, defaultLocale }
|
|
77
|
+
}
|
package/src/prerender.js
CHANGED
|
@@ -721,6 +721,9 @@ export function injectBuildData(html, siteContent, { splitContent = false, curre
|
|
|
721
721
|
// Inject site content as JSON for hydration
|
|
722
722
|
// Strip CSS and font links from theme (both are already in <head>)
|
|
723
723
|
let contentForJson = { ...siteContent }
|
|
724
|
+
// The bundle's note to the step that makes each other language's pages, which takes it out
|
|
725
|
+
// (`i18n/index.js::buildLocalizedContent`) — and no page's, if that step failed.
|
|
726
|
+
delete contentForJson.builtAssets
|
|
724
727
|
if (contentForJson.theme?.css || contentForJson.theme?.links) {
|
|
725
728
|
contentForJson.theme = { ...contentForJson.theme }
|
|
726
729
|
delete contentForJson.theme.css
|
package/src/site/assets.js
CHANGED
|
@@ -480,3 +480,73 @@ export function mergeAssetCollections(...collections) {
|
|
|
480
480
|
|
|
481
481
|
return merged
|
|
482
482
|
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* The files each language's pages name that the site's own content does not: what its
|
|
486
|
+
* translations brought, such as an image's file in that language or a free-form section's media.
|
|
487
|
+
*
|
|
488
|
+
* ⭐ A TRANSLATION'S FILE GOES THROUGH THE IMAGE STEP, AS THE CONTENT'S DOES (2026-10-28). A
|
|
489
|
+
* translation names an image's file in its language as `` (`i18n/merge.js::
|
|
490
|
+
* translatedImage`), and a language's pages are made after the build has processed the site's
|
|
491
|
+
* media, from what it wrote. So a translated page showed that file as `public/` holds it, a PNG
|
|
492
|
+
* where the default language's page had the build's WebP. The bundle collects them here, from each
|
|
493
|
+
* language's merged content, and processes them with the site's own (`site/plugin.js::
|
|
494
|
+
* generateBundle`); a language's pages take the address the build gave each one
|
|
495
|
+
* (`i18n/index.js::buildLocalizedContent`).
|
|
496
|
+
*
|
|
497
|
+
* Only a `/x` names a file here. A translation is written in no folder, so a `./x` it holds has
|
|
498
|
+
* nowhere to resolve from: it comes back in `unplaced`, to be said, never guessed.
|
|
499
|
+
*
|
|
500
|
+
* @param {Array<{ locale: string, content: Object }>} languages - each language's content: its
|
|
501
|
+
* translations merged into the site's content as collected (`mergeTranslations`)
|
|
502
|
+
* @param {Object} known - the site's own manifest, by reference as written (`siteContent.assets`)
|
|
503
|
+
* @param {string} siteRoot - Site root directory
|
|
504
|
+
* @param {string} localesDir - the translations' folder; a refusal names `<locale>.json` in it
|
|
505
|
+
* @returns {{ assets: Object, unplaced: Array<{ locale: string, ref: string }> }} a manifest of the
|
|
506
|
+
* files, in `collectSectionAssets`'s shape, and each reference no folder places
|
|
507
|
+
* @throws {Error} `code: ASSETS_FOLDER_RETIRED` — a `/x` that only `assets/` holds
|
|
508
|
+
*/
|
|
509
|
+
export function collectTranslatedAssets(languages, known, siteRoot, localesDir) {
|
|
510
|
+
const assets = {}
|
|
511
|
+
const unplaced = []
|
|
512
|
+
for (const { locale, content } of languages) {
|
|
513
|
+
const table = join(localesDir, `${locale}.json`)
|
|
514
|
+
const seen = new Set()
|
|
515
|
+
const visit = (ref) => {
|
|
516
|
+
if (typeof ref !== 'string' || !ref || isExternalUrl(ref)) return
|
|
517
|
+
if (known?.[ref] || assets[ref] || seen.has(ref)) return
|
|
518
|
+
seen.add(ref)
|
|
519
|
+
if (!ref.startsWith('/')) {
|
|
520
|
+
unplaced.push({ locale, ref })
|
|
521
|
+
return
|
|
522
|
+
}
|
|
523
|
+
const result = resolveAssetPath(ref, table, siteRoot)
|
|
524
|
+
if (result.external || !result.resolved) return
|
|
525
|
+
assets[ref] = {
|
|
526
|
+
original: ref,
|
|
527
|
+
resolved: result.resolved,
|
|
528
|
+
isImage: result.isImage,
|
|
529
|
+
isVideo: result.isVideo,
|
|
530
|
+
isPdf: result.isPdf
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
eachSectionDoc(content, (doc) => {
|
|
534
|
+
walkContentAssets(doc, (node) => visit(node.attrs.src))
|
|
535
|
+
walkDataBlockAssets(doc, (path) => visit(path))
|
|
536
|
+
})
|
|
537
|
+
}
|
|
538
|
+
return { assets, unplaced }
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** Each section's content in a site's content, as `rewriteSiteContentPaths` walks it: pages, layout areas, subsections. */
|
|
542
|
+
function eachSectionDoc(siteContent, visit) {
|
|
543
|
+
const section = (s) => {
|
|
544
|
+
if (s?.content) visit(s.content)
|
|
545
|
+
s?.subsections?.forEach(section)
|
|
546
|
+
}
|
|
547
|
+
const page = (p) => p?.sections?.forEach(section)
|
|
548
|
+
siteContent?.pages?.forEach(page)
|
|
549
|
+
for (const areas of Object.values(siteContent?.layouts || {})) {
|
|
550
|
+
for (const area of Object.values(areas || {})) page(area)
|
|
551
|
+
}
|
|
552
|
+
}
|
package/src/site/plugin.js
CHANGED
|
@@ -33,6 +33,7 @@ import { resolveDefaultLocale, resolveFetchConfigs, DATA_DIR } from '@uniweb/cor
|
|
|
33
33
|
import { partitionKnowledgePages, INDEX_FILENAME } from '@uniweb/projections'
|
|
34
34
|
import { collectSiteContent, mountEntriesOf } from './content-collector.js'
|
|
35
35
|
import { processAssets, rewriteSiteContentPaths } from './asset-processor.js'
|
|
36
|
+
import { collectTranslatedAssets } from './assets.js'
|
|
36
37
|
import { processAdvancedAssets } from './advanced-processors.js'
|
|
37
38
|
import { devMediaPaths } from './dev-media.js'
|
|
38
39
|
import { processQueries, writeQueryFiles } from './query-processor.js'
|
|
@@ -238,6 +239,7 @@ async function processDevSectionFetches(sections, fetchOptions, resolve) {
|
|
|
238
239
|
import { compiledData, recordProjections, routeOnDisk } from './record-projections.js'
|
|
239
240
|
import { agentFiles, describeProjections, projectionFiles, searchFiles } from './projections.js'
|
|
240
241
|
import { mergeTranslations } from '../i18n/merge.js'
|
|
242
|
+
import { localesToBuild } from '../i18n/locales.js'
|
|
241
243
|
import { dataBlockModels, NO_DATA_MODELS } from '../i18n/data-models.js'
|
|
242
244
|
import { refuseSearchOption } from './search-declared.js'
|
|
243
245
|
import { mountDevApi } from '../dev/api-mount.js'
|
|
@@ -533,6 +535,34 @@ export function siteContentPlugin(options = {}) {
|
|
|
533
535
|
})
|
|
534
536
|
}
|
|
535
537
|
|
|
538
|
+
/**
|
|
539
|
+
* The files the languages this build makes pages in name and the site's own content does not
|
|
540
|
+
* (`collectTranslatedAssets`), each language's translations merged as its pages will be. The
|
|
541
|
+
* languages are `uniweb build`'s (`localesToBuild`), so a file is processed for exactly the pages
|
|
542
|
+
* that show it.
|
|
543
|
+
*
|
|
544
|
+
* @returns {Promise<{ assets: Object, languages: number }>} a manifest of those files, and how
|
|
545
|
+
* many languages the build makes besides its default
|
|
546
|
+
*/
|
|
547
|
+
async function translatedAssets() {
|
|
548
|
+
const { readSiteConfig } = await import('./config.js')
|
|
549
|
+
const localesPath = join(resolvedSitePath, localesDir)
|
|
550
|
+
const { locales } = localesToBuild(readSiteConfig(resolvedSitePath), localesPath)
|
|
551
|
+
const languages = []
|
|
552
|
+
for (const locale of locales) {
|
|
553
|
+
const content = await getTranslatedContent(locale)
|
|
554
|
+
if (content) languages.push({ locale, content })
|
|
555
|
+
}
|
|
556
|
+
const { assets, unplaced } = collectTranslatedAssets(languages, siteContent.assets, resolvedSitePath, localesPath)
|
|
557
|
+
for (const { locale, ref } of unplaced) {
|
|
558
|
+
console.warn(
|
|
559
|
+
`[site-content] A ${locale} translation names ${ref}, and a translation sits in no folder for ` +
|
|
560
|
+
`a relative path to start from. Name the file from public/, as /<its path there>.`
|
|
561
|
+
)
|
|
562
|
+
}
|
|
563
|
+
return { assets, languages: locales.length }
|
|
564
|
+
}
|
|
565
|
+
|
|
536
566
|
/**
|
|
537
567
|
* The site's content in `locale`, as a page in that language gets it — or null when the site has
|
|
538
568
|
* no translation for it (`getTranslatedContent`).
|
|
@@ -1156,13 +1186,18 @@ export function siteContentPlugin(options = {}) {
|
|
|
1156
1186
|
|
|
1157
1187
|
// Process assets in production builds
|
|
1158
1188
|
if (isProduction && assetsOptions.process && siteContent?.assets) {
|
|
1159
|
-
|
|
1189
|
+
// ⭐ With the files a translation names (`translatedAssets`): one step for both, so a
|
|
1190
|
+
// translated page shows the build's copy of its file as the default language's page does.
|
|
1191
|
+
const translated = await translatedAssets()
|
|
1192
|
+
const fromTranslations = Object.keys(translated.assets).length
|
|
1193
|
+
const manifest = { ...siteContent.assets, ...translated.assets }
|
|
1194
|
+
const assetCount = Object.keys(manifest).length
|
|
1160
1195
|
|
|
1161
1196
|
if (assetCount > 0) {
|
|
1162
1197
|
console.log(`[site-content] Processing ${assetCount} assets...`)
|
|
1163
1198
|
|
|
1164
1199
|
// Process standard assets (images)
|
|
1165
|
-
const { pathMapping, results, files } = await processAssets(
|
|
1200
|
+
const { pathMapping, results, files } = await processAssets(manifest, {
|
|
1166
1201
|
outputDir: resolvedOutDir,
|
|
1167
1202
|
assetsSubdir: assetsOptions.outputDir,
|
|
1168
1203
|
convertToWebp: assetsOptions.convertToWebp,
|
|
@@ -1202,9 +1237,14 @@ export function siteContentPlugin(options = {}) {
|
|
|
1202
1237
|
finalContent = rewriteSiteContentPaths(siteContent, pathMapping, files)
|
|
1203
1238
|
}
|
|
1204
1239
|
|
|
1240
|
+
// Where the build put each file, for the step that makes each other language's pages from
|
|
1241
|
+
// this payload, and takes it out (`i18n/index.js::buildLocalizedContent`).
|
|
1242
|
+
if (translated.languages > 0) finalContent.builtAssets = { paths: pathMapping, files }
|
|
1243
|
+
|
|
1205
1244
|
// Log results
|
|
1206
1245
|
const sizeKB = (results.totalSize / 1024).toFixed(1)
|
|
1207
1246
|
console.log(`[site-content] Processed ${results.processed} assets (${results.converted} converted to WebP, ${sizeKB}KB total)`)
|
|
1247
|
+
if (fromTranslations > 0) console.log(`[site-content] ${fromTranslations} of them named by a translation`)
|
|
1208
1248
|
|
|
1209
1249
|
if (results.failed > 0) {
|
|
1210
1250
|
console.warn(`[site-content] ${results.failed} assets failed to process`)
|