@uniweb/build 1.22.0 → 1.23.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 +6 -6
- package/src/foundation/library-mappings.js +109 -0
- package/src/foundation/mappings.js +64 -4
- package/src/foundation/shared-types.js +22 -2
- package/src/i18n/data-strings.js +0 -5
- package/src/i18n/index.js +12 -7
- package/src/i18n/records.js +21 -251
- package/src/index.js +2 -1
- package/src/resolve-data-schema.js +4 -3
- package/src/schema.js +34 -2
- package/src/site/build-site-data.js +17 -57
- package/src/site/content-collector.js +34 -7
- package/src/site/entity-pool.js +10 -0
- package/src/site/index.js +0 -1
- package/src/site/plugin.js +28 -17
- package/src/site/queries-config.js +35 -9
- package/src/site/query-processor.js +63 -13
- package/src/site/standard-type-for.js +22 -0
- package/src/utils/classify-package.js +9 -6
- package/src/uwx/blueprint-file.js +22 -4
- package/src/uwx/blueprint.js +46 -25
- package/src/uwx/index.js +1 -0
- package/src/uwx/records-project.js +49 -9
- package/src/uwx/records.js +42 -40
- package/src/uwx/registry-package.js +32 -20
- package/src/uwx/shown-records.js +2 -2
- package/src/uwx/site-project.js +7 -5
- package/src/uwx/site.js +7 -13
- package/src/uwx/sync-package.js +7 -10
- package/src/validate-data.js +53 -3
- package/src/site/schemaless-data.js +0 -185
package/src/i18n/records.js
CHANGED
|
@@ -4,17 +4,18 @@
|
|
|
4
4
|
* Extract translatable strings from collection items and merge translations.
|
|
5
5
|
* Collections are separate from page content (stored in public/data/*.json).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* A record is translated as its data schema says: by the model a push sends it as, which marks
|
|
8
|
+
* the fields that travel per language (`extractByModel`, `translateByModel`). Every record has a
|
|
9
|
+
* data schema [Diego, 2026-11-11]; where this build cannot read it — a site whose foundation is
|
|
10
|
+
* not in the project, such as a clone — a heuristic walk reads the record instead (`extractHeuristic`).
|
|
11
|
+
* ⛔ Until 2026-11-11 a record with no data schema was read by a companion `records/<query>.schema.js`,
|
|
12
|
+
* or by a standard schema guessed from the query's name made singular (`events` → `@std/event`).
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
import { readFile, writeFile, readdir, mkdir, rm } from 'fs/promises'
|
|
14
16
|
import { RESERVED_LOCALE_FILES } from './locales.js'
|
|
15
17
|
import { existsSync } from 'node:fs'
|
|
16
18
|
import { join, resolve, sep } from 'node:path'
|
|
17
|
-
import { pathToFileURL } from 'node:url'
|
|
18
19
|
import { DATA_DIR, resolveDefaultLocale } from '@uniweb/core'
|
|
19
20
|
import yaml from 'js-yaml'
|
|
20
21
|
import { YAML_OPTIONS } from '../utils/yaml-schema.js'
|
|
@@ -30,7 +31,7 @@ import { toDeliveredRecord, contentBodyField, misplacedFields, mergedFromStored,
|
|
|
30
31
|
import { resolveDocForLocale } from './merge.js'
|
|
31
32
|
import { extractUnitsFromDoc } from './extract.js'
|
|
32
33
|
import { flatFormRefusal, extractExcerpt } from '../site/query-processor.js'
|
|
33
|
-
import { poolDirsForSchema, schemaForPoolDirs,
|
|
34
|
+
import { poolDirsForSchema, schemaForPoolDirs, readEntityPool, groupPoolBySchema } from '../site/entity-pool.js'
|
|
34
35
|
import { readRecordsConfig, resolveFolder } from '../site/records-config.js'
|
|
35
36
|
import { labelIn } from '../site/entry-label.js'
|
|
36
37
|
// The heuristic judgement about which strings inside structured data are prose.
|
|
@@ -39,7 +40,6 @@ import { labelIn } from '../site/entry-label.js'
|
|
|
39
40
|
// is not, wherever the value came from. Moved rather than copied: two tuned
|
|
40
41
|
// denylists would drift, and drift here is silent.
|
|
41
42
|
import {
|
|
42
|
-
NON_TRANSLATABLE_TYPES,
|
|
43
43
|
HEURISTIC_SKIP_FIELDS,
|
|
44
44
|
MAX_HEURISTIC_DEPTH,
|
|
45
45
|
isStructuralString,
|
|
@@ -57,113 +57,6 @@ import {
|
|
|
57
57
|
// `locales/records/` — two directories, one word, so the constant says which.
|
|
58
58
|
export const RECORD_LOCALES_DIR = 'records'
|
|
59
59
|
|
|
60
|
-
// ---------------------------------------------------------------------------
|
|
61
|
-
// Schema resolution
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
|
|
64
|
-
/** Cache for resolved schemas (query name → schema or null) */
|
|
65
|
-
const schemaCache = new Map()
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Resolve schema for a collection.
|
|
69
|
-
*
|
|
70
|
-
* Discovery order:
|
|
71
|
-
* 1. Companion file: public/data/<name>.schema.js (ESM default export)
|
|
72
|
-
* 2. Standard schema: @uniweb/schemas by collection name (with naive singularization)
|
|
73
|
-
* 3. null (no schema found → heuristic fallback)
|
|
74
|
-
*
|
|
75
|
-
* @param {string} queryName
|
|
76
|
-
* @param {string} siteRoot
|
|
77
|
-
* @returns {Promise<Object|null>}
|
|
78
|
-
*/
|
|
79
|
-
async function resolveSchema(queryName, siteRoot) {
|
|
80
|
-
if (schemaCache.has(queryName)) {
|
|
81
|
-
return schemaCache.get(queryName)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let schema = null
|
|
85
|
-
|
|
86
|
-
// 1. Companion schema file, beside the collection it describes.
|
|
87
|
-
//
|
|
88
|
-
// This used to be looked up in `public/<DATA_DIR>/` — next to the compiled
|
|
89
|
-
// output rather than the source. That directory is the build's, and asking
|
|
90
|
-
// an author to write into it was the one remaining place the framework
|
|
91
|
-
// contradicted its own rule that `collections/` is the only way to provide
|
|
92
|
-
// structured data. The schema describes the source, so it lives with it.
|
|
93
|
-
const companionPath = join(resolveRecordsDir(siteRoot).abs, `${queryName}.schema.js`)
|
|
94
|
-
if (existsSync(companionPath)) {
|
|
95
|
-
try {
|
|
96
|
-
const mod = await import(pathToFileURL(companionPath).href)
|
|
97
|
-
schema = mod.default || mod
|
|
98
|
-
schemaCache.set(queryName, schema)
|
|
99
|
-
return schema
|
|
100
|
-
} catch (err) {
|
|
101
|
-
console.warn(`[i18n] Failed to load companion schema ${companionPath}: ${err.message}`)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// 2. Standard schema from @uniweb/schemas (try exact name + singularized)
|
|
106
|
-
const schemasModule = await import('@uniweb/schemas')
|
|
107
|
-
const names = [queryName, singularize(queryName)]
|
|
108
|
-
|
|
109
|
-
for (const name of names) {
|
|
110
|
-
if (schemasModule.schemas[name]) {
|
|
111
|
-
schema = schemasModule.schemas[name]
|
|
112
|
-
break
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
schemaCache.set(queryName, schema)
|
|
117
|
-
return schema
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Naive singularization for schema lookup.
|
|
122
|
-
* Handles common plural suffixes: articles→article, opportunities→opportunity
|
|
123
|
-
*/
|
|
124
|
-
function singularize(name) {
|
|
125
|
-
if (name.endsWith('ies')) return name.slice(0, -3) + 'y'
|
|
126
|
-
if (name.endsWith('ses') || name.endsWith('xes') || name.endsWith('zes')) return name.slice(0, -2)
|
|
127
|
-
if (name.endsWith('s') && !name.endsWith('ss')) return name.slice(0, -1)
|
|
128
|
-
return name
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ---------------------------------------------------------------------------
|
|
132
|
-
// Field translatability
|
|
133
|
-
// ---------------------------------------------------------------------------
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Determine if a schema field should be extracted for translation.
|
|
137
|
-
*
|
|
138
|
-
* @param {Object} fieldDef - Schema field definition
|
|
139
|
-
* @returns {'yes'|'no'|'recurse'} Whether the field is translatable
|
|
140
|
-
*/
|
|
141
|
-
function isFieldTranslatable(fieldDef) {
|
|
142
|
-
// Explicit override always wins
|
|
143
|
-
if (fieldDef.translatable === true) return 'yes'
|
|
144
|
-
if (fieldDef.translatable === false) return 'no'
|
|
145
|
-
|
|
146
|
-
const type = fieldDef.type
|
|
147
|
-
|
|
148
|
-
// Types that are never translatable
|
|
149
|
-
if (NON_TRANSLATABLE_TYPES.has(type)) return 'no'
|
|
150
|
-
|
|
151
|
-
// Markdown is always translatable
|
|
152
|
-
if (type === 'markdown') return 'yes'
|
|
153
|
-
|
|
154
|
-
// Strings with enum default to NOT translatable (status codes, types)
|
|
155
|
-
if (type === 'string' && fieldDef.enum) return 'no'
|
|
156
|
-
|
|
157
|
-
// Plain strings default to translatable
|
|
158
|
-
if (type === 'string') return 'yes'
|
|
159
|
-
|
|
160
|
-
// Objects and arrays: recurse into their nested definitions
|
|
161
|
-
if (type === 'object' || type === 'array') return 'recurse'
|
|
162
|
-
|
|
163
|
-
// Unknown types: skip
|
|
164
|
-
return 'no'
|
|
165
|
-
}
|
|
166
|
-
|
|
167
60
|
// ---------------------------------------------------------------------------
|
|
168
61
|
// A record's model — what a push sends it as
|
|
169
62
|
// ---------------------------------------------------------------------------
|
|
@@ -393,74 +286,14 @@ function translateDocs(value, context, translations, depth = 0) {
|
|
|
393
286
|
// Schema-guided extraction
|
|
394
287
|
// ---------------------------------------------------------------------------
|
|
395
288
|
|
|
396
|
-
/**
|
|
397
|
-
* Extract translatable fields from an item using a schema.
|
|
398
|
-
*
|
|
399
|
-
* @param {Object} item - Data item
|
|
400
|
-
* @param {Object} schema - Schema with `fields`
|
|
401
|
-
* @param {string} queryName
|
|
402
|
-
* @param {Object} units - Accumulator
|
|
403
|
-
*/
|
|
404
|
-
function extractWithSchema(item, schema, recordDir, units) {
|
|
405
|
-
const context = { record: `${recordDir}/${recordHandle(item)}` }
|
|
406
|
-
|
|
407
|
-
extractFromItemWithSchema(item, schema.fields, '', context, units)
|
|
408
|
-
|
|
409
|
-
// Also extract the record's ProseMirror documents (not covered by schema fields)
|
|
410
|
-
for (const { path, doc } of proseMirrorDocs(item)) extractFromProseMirrorDoc(doc, context, units, path)
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Recursively extract translatable fields guided by schema.
|
|
415
|
-
*/
|
|
416
|
-
function extractFromItemWithSchema(data, fields, pathPrefix, context, units) {
|
|
417
|
-
if (!data || typeof data !== 'object') return
|
|
418
|
-
|
|
419
|
-
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
420
|
-
if (isRecordSystemField(fieldName, !pathPrefix)) continue
|
|
421
|
-
const value = data[fieldName]
|
|
422
|
-
if (value === undefined || value === null) continue
|
|
423
|
-
|
|
424
|
-
const fieldPath = pathPrefix ? `${pathPrefix}.${fieldName}` : fieldName
|
|
425
|
-
const translatable = isFieldTranslatable(fieldDef)
|
|
426
|
-
|
|
427
|
-
if (translatable === 'yes') {
|
|
428
|
-
if (typeof value === 'string' && value.trim()) {
|
|
429
|
-
addUnit(units, value, fieldPath, context)
|
|
430
|
-
}
|
|
431
|
-
} else if (translatable === 'recurse') {
|
|
432
|
-
if (fieldDef.type === 'object' && fieldDef.fields && typeof value === 'object' && !Array.isArray(value)) {
|
|
433
|
-
extractFromItemWithSchema(value, fieldDef.fields, fieldPath, context, units)
|
|
434
|
-
} else if (fieldDef.type === 'array' && Array.isArray(value)) {
|
|
435
|
-
const itemDef = fieldDef.items
|
|
436
|
-
if (itemDef) {
|
|
437
|
-
value.forEach((elem, i) => {
|
|
438
|
-
const elemPath = `${fieldPath}[${i}]`
|
|
439
|
-
if (itemDef.type === 'object' && itemDef.fields && typeof elem === 'object') {
|
|
440
|
-
extractFromItemWithSchema(elem, itemDef.fields, elemPath, context, units)
|
|
441
|
-
} else if (itemDef.type === 'string') {
|
|
442
|
-
// Array of strings — check item-level translatable
|
|
443
|
-
const itemTranslatable = isFieldTranslatable(itemDef)
|
|
444
|
-
if (itemTranslatable === 'yes' && typeof elem === 'string' && elem.trim()) {
|
|
445
|
-
addUnit(units, elem, elemPath, context)
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
})
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
// translatable === 'no' → skip
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
289
|
// ---------------------------------------------------------------------------
|
|
457
|
-
// Heuristic extraction (
|
|
290
|
+
// Heuristic extraction (a data schema this build cannot read)
|
|
458
291
|
// ---------------------------------------------------------------------------
|
|
459
292
|
|
|
460
293
|
/**
|
|
461
|
-
* Extract translatable fields from an item using heuristics — a record
|
|
462
|
-
*
|
|
463
|
-
* human-readable text.
|
|
294
|
+
* Extract translatable fields from an item using heuristics — a record whose data schema this
|
|
295
|
+
* build cannot read (a foundation not in the project, such as a clone's). Recursively walks the
|
|
296
|
+
* data, extracting strings that look like human-readable text.
|
|
464
297
|
*
|
|
465
298
|
* @param {Set<string>|null} skip - fields of the record's own level to leave out (`EXCERPT`)
|
|
466
299
|
*/
|
|
@@ -516,59 +349,7 @@ function extractFromItemHeuristic(data, pathPrefix, context, units, depth, skip
|
|
|
516
349
|
}
|
|
517
350
|
|
|
518
351
|
// ---------------------------------------------------------------------------
|
|
519
|
-
//
|
|
520
|
-
// ---------------------------------------------------------------------------
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Translate item fields using schema guidance.
|
|
524
|
-
*/
|
|
525
|
-
function translateWithSchema(item, schema, context, translations) {
|
|
526
|
-
const translated = translateDocs(item, context, translations)
|
|
527
|
-
translateItemWithSchema(translated, schema.fields, context, translations)
|
|
528
|
-
return translated
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
/**
|
|
532
|
-
* Recursively translate fields guided by schema.
|
|
533
|
-
*/
|
|
534
|
-
function translateItemWithSchema(data, fields, context, translations, topLevel = true) {
|
|
535
|
-
if (!data || typeof data !== 'object') return
|
|
536
|
-
|
|
537
|
-
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
538
|
-
if (isRecordSystemField(fieldName, topLevel)) continue
|
|
539
|
-
const value = data[fieldName]
|
|
540
|
-
if (value === undefined || value === null) continue
|
|
541
|
-
|
|
542
|
-
const translatable = isFieldTranslatable(fieldDef)
|
|
543
|
-
|
|
544
|
-
if (translatable === 'yes') {
|
|
545
|
-
if (typeof value === 'string') {
|
|
546
|
-
data[fieldName] = lookupTranslation(value, context, translations)
|
|
547
|
-
}
|
|
548
|
-
} else if (translatable === 'recurse') {
|
|
549
|
-
if (fieldDef.type === 'object' && fieldDef.fields && typeof value === 'object' && !Array.isArray(value)) {
|
|
550
|
-
translateItemWithSchema(value, fieldDef.fields, context, translations, false)
|
|
551
|
-
} else if (fieldDef.type === 'array' && Array.isArray(value)) {
|
|
552
|
-
const itemDef = fieldDef.items
|
|
553
|
-
if (itemDef) {
|
|
554
|
-
value.forEach((elem, i) => {
|
|
555
|
-
if (itemDef.type === 'object' && itemDef.fields && typeof elem === 'object') {
|
|
556
|
-
translateItemWithSchema(elem, itemDef.fields, context, translations, false)
|
|
557
|
-
} else if (itemDef.type === 'string') {
|
|
558
|
-
const itemTranslatable = isFieldTranslatable(itemDef)
|
|
559
|
-
if (itemTranslatable === 'yes' && typeof elem === 'string') {
|
|
560
|
-
value[i] = lookupTranslation(elem, context, translations)
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
})
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// ---------------------------------------------------------------------------
|
|
571
|
-
// Heuristic translation (no schema)
|
|
352
|
+
// Heuristic translation (a data schema this build cannot read)
|
|
572
353
|
// ---------------------------------------------------------------------------
|
|
573
354
|
|
|
574
355
|
/**
|
|
@@ -774,8 +555,6 @@ export async function extractRecordContent(siteRoot, options = {}) {
|
|
|
774
555
|
|
|
775
556
|
if (!Array.isArray(items)) continue
|
|
776
557
|
|
|
777
|
-
// Resolve schema once per collection
|
|
778
|
-
const schema = await resolveSchema(queryName, siteRoot)
|
|
779
558
|
const recordDir = poolDirs.get(queryName) ?? queryName
|
|
780
559
|
const model = models.get(queryName) ?? null
|
|
781
560
|
// ⭐ AND THE QUERY'S PER-RECORD FILES. A query with `deferred:` fields writes each
|
|
@@ -788,8 +567,6 @@ export async function extractRecordContent(siteRoot, options = {}) {
|
|
|
788
567
|
const skip = derivesExcerpt(item, whole, dataSchemas.get(queryName), excerpts.get(queryName)) ? EXCERPT : null
|
|
789
568
|
if (model) {
|
|
790
569
|
extractByModel(item, model, { record: `${recordDir}/${recordHandle(item)}` }, units, skip)
|
|
791
|
-
} else if (schema?.fields) {
|
|
792
|
-
extractWithSchema(item, schema, recordDir, units)
|
|
793
570
|
} else {
|
|
794
571
|
extractHeuristic(item, recordDir, units, skip)
|
|
795
572
|
}
|
|
@@ -1007,8 +784,6 @@ export async function buildLocalizedRecords(siteRoot, options = {}) {
|
|
|
1007
784
|
continue
|
|
1008
785
|
}
|
|
1009
786
|
|
|
1010
|
-
// Resolve schema once per collection
|
|
1011
|
-
const schema = await resolveSchema(queryName, siteRoot)
|
|
1012
787
|
const recordDir = poolDirs.get(queryName) ?? queryName
|
|
1013
788
|
const recordOptions = {
|
|
1014
789
|
locale,
|
|
@@ -1040,7 +815,7 @@ export async function buildLocalizedRecords(siteRoot, options = {}) {
|
|
|
1040
815
|
const { dataSchema } = recordOptions
|
|
1041
816
|
const record = dataSchema && isPlainObject(stored) ? mergedFromStored(dataSchema, stored) : stored
|
|
1042
817
|
const translatedRecord = isPlainObject(record)
|
|
1043
|
-
? await translateItemAsync(record, recordDir, translations,
|
|
818
|
+
? await translateItemAsync(record, recordDir, translations, recordOptions)
|
|
1044
819
|
: record
|
|
1045
820
|
if (isPlainObject(record)) wholes.set(recordHandle(record), { source: record, translated: translatedRecord })
|
|
1046
821
|
const written = relabel(
|
|
@@ -1062,7 +837,7 @@ export async function buildLocalizedRecords(siteRoot, options = {}) {
|
|
|
1062
837
|
// Translate each item (with free-form support)
|
|
1063
838
|
const translatedItems = await Promise.all(
|
|
1064
839
|
items.map((item) =>
|
|
1065
|
-
translateItemAsync(item, recordDir, translations,
|
|
840
|
+
translateItemAsync(item, recordDir, translations, { ...recordOptions, whole: wholes.get(recordHandle(item)) })
|
|
1066
841
|
)
|
|
1067
842
|
)
|
|
1068
843
|
|
|
@@ -1110,10 +885,10 @@ export async function buildLocalizedRecords(siteRoot, options = {}) {
|
|
|
1110
885
|
* @param {{ source: Object, translated: Object }} [options.whole] - for an item of a lean list, its
|
|
1111
886
|
* record whole and translated, whose body a derived excerpt is derived from
|
|
1112
887
|
*/
|
|
1113
|
-
async function translateItemAsync(item, recordDir, translations,
|
|
888
|
+
async function translateItemAsync(item, recordDir, translations, options = {}) {
|
|
1114
889
|
const { locale, localesDir, freeformEnabled, dataSchema = null, model = null, targets = null, excerpt = null, whole = null } = options
|
|
1115
890
|
const derived = derivesExcerpt(item, whole?.source, dataSchema, excerpt)
|
|
1116
|
-
let translated = translateItemSync(item, recordDir, translations,
|
|
891
|
+
let translated = translateItemSync(item, recordDir, translations, { model, targets, skip: derived ? EXCERPT : null })
|
|
1117
892
|
if (freeformEnabled && locale && localesDir) translated = await applyFreeformFile(translated, item, recordDir, locale, localesDir, dataSchema)
|
|
1118
893
|
if (!derived) return translated
|
|
1119
894
|
return { ...translated, excerpt: derivedExcerptOf(whole ? whole.translated : translated, dataSchema, excerpt) }
|
|
@@ -1170,17 +945,13 @@ function applyFreeform(record, freeform, dataSchema, schemaRef) {
|
|
|
1170
945
|
|
|
1171
946
|
/**
|
|
1172
947
|
* Apply translations to a collection item (sync, hash-based only) — by the model it is pushed as
|
|
1173
|
-
*
|
|
948
|
+
* (`translateByModel`), or by the heuristic where this build cannot read its data schema.
|
|
1174
949
|
*/
|
|
1175
|
-
function translateItemSync(item, recordDir, translations,
|
|
950
|
+
function translateItemSync(item, recordDir, translations, { model = null, targets = null, skip = null } = {}) {
|
|
1176
951
|
const context = { record: `${recordDir}/${recordHandle(item)}` }
|
|
1177
952
|
|
|
1178
953
|
if (model) return translateByModel(item, model, context, translations, targets, skip)
|
|
1179
|
-
|
|
1180
|
-
if (schema?.fields) {
|
|
1181
|
-
return translateWithSchema(translated, schema, context, translations)
|
|
1182
|
-
}
|
|
1183
|
-
return translateHeuristic(translated, context, translations, skip)
|
|
954
|
+
return translateHeuristic({ ...item }, context, translations, skip)
|
|
1184
955
|
}
|
|
1185
956
|
|
|
1186
957
|
// ---------------------------------------------------------------------------
|
|
@@ -1264,7 +1035,6 @@ export async function translateRecordData(items, queryName, siteRoot, options =
|
|
|
1264
1035
|
const one = !!items && typeof items === 'object' && !Array.isArray(items)
|
|
1265
1036
|
if (!Array.isArray(items) && !one) return items
|
|
1266
1037
|
|
|
1267
|
-
const schema = await resolveSchema(queryName, siteRoot)
|
|
1268
1038
|
const { poolDirs, schemas: dataSchemas, models, targets, excerpts, labels, defaultLocale } = await recordQueries(siteRoot)
|
|
1269
1039
|
const recordDir = poolDirs.get(queryName) ?? queryName
|
|
1270
1040
|
const recordOptions = {
|
|
@@ -1285,11 +1055,11 @@ export async function translateRecordData(items, queryName, siteRoot, options =
|
|
|
1285
1055
|
const wholes = new Map()
|
|
1286
1056
|
if (!one) {
|
|
1287
1057
|
for (const [handle, record] of await wholeRecords(join(siteRoot, 'public', DATA_DIR), queryName, dataSchema)) {
|
|
1288
|
-
wholes.set(handle, { source: record, translated: await translateItemAsync(record, recordDir, translations,
|
|
1058
|
+
wholes.set(handle, { source: record, translated: await translateItemAsync(record, recordDir, translations, recordOptions) })
|
|
1289
1059
|
}
|
|
1290
1060
|
}
|
|
1291
1061
|
const translated = await Promise.all(
|
|
1292
|
-
records.map((item) => translateItemAsync(item, recordDir, translations,
|
|
1062
|
+
records.map((item) => translateItemAsync(item, recordDir, translations, { ...recordOptions, whole: wholes.get(recordHandle(item)) }))
|
|
1293
1063
|
)
|
|
1294
1064
|
|
|
1295
1065
|
const labelsOf = labels.get(queryName)
|
package/src/index.js
CHANGED
|
@@ -98,7 +98,8 @@ export { classifyPackage, isExtensionPackage, isSchemasPackage } from './utils/c
|
|
|
98
98
|
export { collectStandaloneSchemas, routedSchema } from './resolve-data-schema.js'
|
|
99
99
|
|
|
100
100
|
// One name in a scope is one type: the names a workspace's packages define twice
|
|
101
|
-
export { typesDefinedTwice, packageTypeScope, workspaceTypeFiles } from './foundation/shared-types.js'
|
|
101
|
+
export { typesDefinedTwice, packageTypeScope, workspaceTypeFiles, workspaceMappingFiles } from './foundation/shared-types.js'
|
|
102
|
+
export { buildMappingMap, ownMappingFiles, loadMappingFile } from './foundation/mappings.js'
|
|
102
103
|
|
|
103
104
|
// Default export is the combined Vite plugin
|
|
104
105
|
export { default } from './vite-foundation-plugin.js'
|
|
@@ -82,9 +82,10 @@ export {
|
|
|
82
82
|
const SCOPE_PACKAGE = { std: '@uniweb/schemas' }
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
|
-
* The `code` of the error a
|
|
86
|
-
*
|
|
87
|
-
*
|
|
85
|
+
* The `code` of the error a ref raises when nothing this foundation reads defines it — the
|
|
86
|
+
* one failure that is an answer rather than a fault. For a `@/name` a folder or a query
|
|
87
|
+
* named, it is the answer a build refuses with: every record has a data schema
|
|
88
|
+
* (`site/query-processor.js::refuseRecordsWithoutSchema`).
|
|
88
89
|
*/
|
|
89
90
|
export const SCHEMA_NOT_FOUND = 'SCHEMA_NOT_FOUND'
|
|
90
91
|
const RESERVED_SYSTEM_SCOPE = 'uniweb'
|
package/src/schema.js
CHANGED
|
@@ -19,7 +19,7 @@ import { pathToFileURL } from 'node:url'
|
|
|
19
19
|
import { jsxInJsMessage } from './jsx-extension.js'
|
|
20
20
|
import { areaNames, describeChildren, describePlacement, describeVisuals, lowerChildren } from '@uniweb/schemas/component'
|
|
21
21
|
import { describeContent, lowerData } from '@uniweb/schemas/content'
|
|
22
|
-
import { normalizeData, schemaDeclarationOf } from '@uniweb/schemas/foundation'
|
|
22
|
+
import { normalizeData, normalizePlaceholders, schemaDeclarationOf } from '@uniweb/schemas/foundation'
|
|
23
23
|
import { rootListSection } from '@uniweb/schemas/conform'
|
|
24
24
|
import { SECTION_PARAMS, SECTION_KEYS, stickyDeclaration, underHeaderDeclaration, heightDeclaration } from '@uniweb/schemas/section'
|
|
25
25
|
import { collectSchemaRefs, buildDataSchemaMap, ownSchemaRefs } from './resolve-data-schema.js'
|
|
@@ -1254,6 +1254,25 @@ export function reportUnregistrableData(components, layouts = {}, foundationConf
|
|
|
1254
1254
|
stopOrWarn(problems, strict)
|
|
1255
1255
|
}
|
|
1256
1256
|
|
|
1257
|
+
/**
|
|
1258
|
+
* The site values the foundation reads, as `main.js` declares them in `placeholders:`: one field
|
|
1259
|
+
* map in the shape an inline `data:` map takes, checked as `register` will normalize it
|
|
1260
|
+
* (`normalizePlaceholders`), and carried in `_self` as written. An editor shows a site's
|
|
1261
|
+
* placeholders as the fields it declares; a page reads them at `website.config.placeholders`, and
|
|
1262
|
+
* the runtime fills no `default`, so a declaration never reaches a page.
|
|
1263
|
+
*
|
|
1264
|
+
* @param {*} placeholders - `main.js`'s `placeholders`, as written
|
|
1265
|
+
* @param {{ strict: boolean }} options - stop, or warn as a site reading its foundation does
|
|
1266
|
+
*/
|
|
1267
|
+
function checkPlaceholders(placeholders, { strict }) {
|
|
1268
|
+
if (placeholders === undefined) return
|
|
1269
|
+
try {
|
|
1270
|
+
normalizePlaceholders(placeholders)
|
|
1271
|
+
} catch (err) {
|
|
1272
|
+
stopOrWarn([err.message], strict)
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1257
1276
|
/**
|
|
1258
1277
|
* One error naming every declaration problem the build found, so a developer fixes them in one
|
|
1259
1278
|
* pass rather than one build at a time.
|
|
@@ -1371,6 +1390,7 @@ export async function buildSchema(srcDir, sectionPaths, derivedSupports = null,
|
|
|
1371
1390
|
const foundationConfig = await loadFoundationConfig(srcDir)
|
|
1372
1391
|
|
|
1373
1392
|
refuseDataDeclarations('the foundation (main.js)', lowerData(foundationConfig.data))
|
|
1393
|
+
checkPlaceholders(foundationConfig.placeholders, { strict })
|
|
1374
1394
|
|
|
1375
1395
|
// Discover section types
|
|
1376
1396
|
const components = await discoverComponents(srcDir, sectionPaths)
|
|
@@ -1389,6 +1409,17 @@ export async function buildSchema(srcDir, sectionPaths, derivedSupports = null,
|
|
|
1389
1409
|
// The mappings it defines — every file in its `mappings/` folder (`foundation/mappings.js`),
|
|
1390
1410
|
// registered beside its data schemas. Editor-time: `_mappings`, never on a page.
|
|
1391
1411
|
const mappings = await buildMappingMap(srcDir, { ownTypes: ownSchemaRefs(srcDir) })
|
|
1412
|
+
// And the library mappings its main.js carries (`mappings: ['@acme/x']`), in full — imported
|
|
1413
|
+
// here, not above, since what finds them reads foundations' names through this module.
|
|
1414
|
+
if (foundationConfig.mappings !== undefined) {
|
|
1415
|
+
const { resolveLibraryMappings } = await import('./foundation/library-mappings.js')
|
|
1416
|
+
const { map, warnings } = await resolveLibraryMappings(foundationConfig.mappings, {
|
|
1417
|
+
srcDir,
|
|
1418
|
+
ownScope: splitFoundationName(foundationNameOf({ config: foundationConfig, pkg: identity }).name || '').scope,
|
|
1419
|
+
})
|
|
1420
|
+
for (const warning of warnings) console.warn(`[uniweb] ${warning}`)
|
|
1421
|
+
Object.assign(mappings, map)
|
|
1422
|
+
}
|
|
1392
1423
|
|
|
1393
1424
|
// Discover layouts from src/layouts/
|
|
1394
1425
|
const layouts = await discoverLayoutsInPath(srcDir)
|
|
@@ -1422,7 +1453,8 @@ export async function buildSchema(srcDir, sectionPaths, derivedSupports = null,
|
|
|
1422
1453
|
|
|
1423
1454
|
// Build _self, stripping the raw extension boolean in favor of normalized role, and the
|
|
1424
1455
|
// declared `defaultLayout` in favor of the resolved one (`resolveDefaultLayout`)
|
|
1425
|
-
|
|
1456
|
+
// `mappings` goes to `_mappings` with the foundation's own, each fact once.
|
|
1457
|
+
const { extension: _ext, defaultLayout: _declaredLayout, mappings: _libraryMappings, ...configWithoutExtension } = foundationConfig
|
|
1426
1458
|
|
|
1427
1459
|
// `supports` is the one identity field the build knows better than the file.
|
|
1428
1460
|
// `identity.supports` is already normalized (absent stays absent, `[]` stays
|
|
@@ -17,25 +17,20 @@
|
|
|
17
17
|
* path (where the static-host extras — sitemap, robots, search-index,
|
|
18
18
|
* `llms.txt` and the `.md` projections, `_pages/*` for split content — are
|
|
19
19
|
* actually consumed). Both paths use
|
|
20
|
-
* the same underlying building blocks (`collectSiteContent`,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* the same underlying building blocks (`collectSiteContent`, etc.), so behavior
|
|
21
|
+
* stays consistent without forcing one path through the other's lifecycle. Media
|
|
22
|
+
* processing — WebP copies and video posters — and the records' compiled query
|
|
23
|
+
* files are the bundle path's alone (below).
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import { writeFile, mkdir
|
|
27
|
-
import { existsSync } from 'node:fs'
|
|
26
|
+
import { writeFile, mkdir } from 'node:fs/promises'
|
|
28
27
|
import { join, resolve } from 'node:path'
|
|
29
28
|
|
|
30
|
-
import { resolveDefaultLocale, DATA_DIR } from '@uniweb/core'
|
|
31
29
|
import { collectSiteContent } from './content-collector.js'
|
|
32
|
-
import { processQueries, writeQueryFiles } from './query-processor.js'
|
|
33
|
-
import { resolveRecordsDir } from './entity-pool.js'
|
|
34
30
|
|
|
35
31
|
/**
|
|
36
32
|
* Build the site data for `uniweb build --link`, which `uniweb publish` runs.
|
|
37
|
-
* `publish` reads
|
|
38
|
-
* have no data schema, which it uploads, and the languages to make live.
|
|
33
|
+
* `publish` reads one thing back from `distDir`: the languages to make live.
|
|
39
34
|
*
|
|
40
35
|
* Emits to `distDir`:
|
|
41
36
|
* - `site-content.json` — full content tree, sections always inlined.
|
|
@@ -60,13 +55,13 @@ import { resolveRecordsDir } from './entity-pool.js'
|
|
|
60
55
|
*
|
|
61
56
|
* ⇒ The rule stands on its own: we do not know which consumers
|
|
62
57
|
* re-derive, so we always ship enough for the ones that do.
|
|
63
|
-
* - `data/<query>.json` (+ each record's own file, `data/<query>/<$name>.json`) —
|
|
64
|
-
* same shape `processQueries` produces today. `publish` uploads the files of
|
|
65
|
-
* the queries that have no data schema (`collectSchemalessData`).
|
|
66
|
-
* - `records/<path under the records directory>` — the records' co-located assets, where
|
|
67
|
-
* the compiled records point.
|
|
68
58
|
*
|
|
69
59
|
* Does NOT emit:
|
|
60
|
+
* - `data/<query>.json` and each record's own file — the compiled queries. Every
|
|
61
|
+
* record has a data schema [Diego, 2026-11-11], so a push sends it as an entity and
|
|
62
|
+
* a host's records service answers its queries. ⛔ *Until 2026-11-11 this lane
|
|
63
|
+
* compiled them, with the records' co-located assets, for `publish` to upload the
|
|
64
|
+
* files of a query with no data schema.*
|
|
70
65
|
* - `assets/<media>` — no media is processed here, and a media ref in
|
|
71
66
|
* `site-content.json` stays the site's own path. `publish` uploads a
|
|
72
67
|
* site's media from the site's own files (the CLI's `uploadSiteMedia`), so
|
|
@@ -122,42 +117,7 @@ export async function buildSiteData({
|
|
|
122
117
|
// `blueprint.yml` (`uwx/blueprint.js`); said here too, a publish said it twice.
|
|
123
118
|
let siteContent = await collectSiteContent(resolvedSiteRoot, { foundationPath, dropUnpublished: true, base: basePath, strict: true, warnBlueprint: false })
|
|
124
119
|
|
|
125
|
-
// 2.
|
|
126
|
-
// `writeQueryFiles` lands them under `<siteRoot>/public/data/`;
|
|
127
|
-
// in the vite plugin path that's fine because vite copies
|
|
128
|
-
// `public/` into `dist/` at build time. The link-mode pipeline
|
|
129
|
-
// has no vite, so we mirror that copy ourselves into
|
|
130
|
-
// `<distDir>/data/` — the set the CLI's `site-data-upload` lane walks at
|
|
131
|
-
// publish time. (This named `uniweb deploy::collectDataFiles` until
|
|
132
|
-
// 2026-08-18; no such function has existed for some time.) Same output bytes, same paths, just
|
|
133
|
-
// without the vite intermediary.
|
|
134
|
-
if (siteContent.config?.queries) {
|
|
135
|
-
const byQuery = await processQueries(
|
|
136
|
-
resolvedSiteRoot,
|
|
137
|
-
siteContent.config.queries,
|
|
138
|
-
resolveRecordsDir(resolvedSiteRoot, siteContent.config?.paths).rel,
|
|
139
|
-
basePath,
|
|
140
|
-
{ locale: resolveDefaultLocale(siteContent.config) ?? null }
|
|
141
|
-
)
|
|
142
|
-
await writeQueryFiles(resolvedSiteRoot, byQuery, siteContent.config.queries)
|
|
143
|
-
|
|
144
|
-
const publicDataDir = join(resolvedSiteRoot, 'public', DATA_DIR)
|
|
145
|
-
const distDataDir = join(resolvedDistDir, DATA_DIR)
|
|
146
|
-
if (existsSync(publicDataDir)) {
|
|
147
|
-
await cp(publicDataDir, distDataDir, { recursive: true })
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// ⭐ AND THE RECORDS' CO-LOCATED ASSETS — `public/records/<path under records/>`,
|
|
151
|
-
// where the compiled records point (`/records/…`), mirrored the way vite mirrors
|
|
152
|
-
// all of `public/` on the bundle lane. ⛔ Until 2026-09-14 only `public/data` was
|
|
153
|
-
// copied, so a record's image URL named a file this lane's `dist/` did not have.
|
|
154
|
-
const publicRecordsDir = join(resolvedSiteRoot, 'public', 'records')
|
|
155
|
-
if (existsSync(publicRecordsDir)) {
|
|
156
|
-
await cp(publicRecordsDir, join(resolvedDistDir, 'records'), { recursive: true })
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// 3. No media processing (header, "Does NOT emit"). The collector's asset
|
|
120
|
+
// 2. No media processing (header, "Does NOT emit"). The collector's asset
|
|
161
121
|
// manifest is internal, so it is dropped — as the vite plugin drops it
|
|
162
122
|
// when processing is off.
|
|
163
123
|
let finalContent = { ...siteContent }
|
|
@@ -196,7 +156,7 @@ export async function buildSiteData({
|
|
|
196
156
|
finalContent = { ...finalContent, config: configWithoutIcons }
|
|
197
157
|
}
|
|
198
158
|
|
|
199
|
-
//
|
|
159
|
+
// 3. Write `dist/site-content.json` with FULL sections inlined.
|
|
200
160
|
// Important: do NOT strip sections per the split-content rule here.
|
|
201
161
|
// Stripping would silently break split-mode sites on any consumer that
|
|
202
162
|
// re-derives split content from the full payload. See the header for
|
|
@@ -204,7 +164,7 @@ export async function buildSiteData({
|
|
|
204
164
|
const contentPath = join(resolvedDistDir, 'site-content.json')
|
|
205
165
|
await writeFile(contentPath, JSON.stringify(finalContent, null, 2))
|
|
206
166
|
|
|
207
|
-
//
|
|
167
|
+
// (removed 2026-08-01) This lane used to emit a search index — the split
|
|
208
168
|
// `_search/{locale}/*.json` for a server, and `search-index.json` for the
|
|
209
169
|
// browser — gated by `features: [search]`.
|
|
210
170
|
//
|
|
@@ -216,7 +176,7 @@ export async function buildSiteData({
|
|
|
216
176
|
// identically on both lanes.
|
|
217
177
|
//
|
|
218
178
|
// The browser one was doubly dead: nothing ever uploaded it. `dist/` on
|
|
219
|
-
// this lane
|
|
179
|
+
// this lane reached a backend only through the data ball and the media
|
|
220
180
|
// refs, and the ball read `dist/data` and `dist/_search` — never the dist
|
|
221
181
|
// root. So it was serialized on every publish and dropped.
|
|
222
182
|
//
|
|
@@ -225,9 +185,9 @@ export async function buildSiteData({
|
|
|
225
185
|
// That is what GitHub Pages and every other static target serve, and the
|
|
226
186
|
// framework has more targets than one backend.
|
|
227
187
|
|
|
228
|
-
//
|
|
188
|
+
// (removed 2026-10-25) This lane wrote `llms.txt` and a `.md` per page, for the default
|
|
229
189
|
// language only, on the ground that both lanes publish a site. Nothing read them: `publish`
|
|
230
|
-
// reads the
|
|
190
|
+
// reads the languages, and a host that serves the site
|
|
231
191
|
// derives its projections from the content, as it derives its search. The static host’s are
|
|
232
192
|
// the bundle lane’s, in every language (`./projections.js`).
|
|
233
193
|
|