@uniweb/build 0.63.2 → 0.63.4
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 +5 -5
- package/src/i18n/index.js +5 -32
- package/src/i18n/locales.js +51 -0
- package/src/uwx/index.js +3 -0
- package/src/uwx/record-identity.js +46 -0
- package/src/uwx/records-project.js +32 -5
- package/src/uwx/site.js +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "0.63.
|
|
3
|
+
"version": "0.63.4",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -57,12 +57,12 @@
|
|
|
57
57
|
"js-yaml": "^4.1.0",
|
|
58
58
|
"sharp": "^0.35.3",
|
|
59
59
|
"yaml": "^2.5.0",
|
|
60
|
-
"@uniweb/content-reader": "^1.2.5",
|
|
61
|
-
"@uniweb/projections": "^0.7.3",
|
|
62
60
|
"@uniweb/content-writer": "^0.3.4",
|
|
61
|
+
"@uniweb/projections": "^0.7.3",
|
|
63
62
|
"@uniweb/schemas": "^0.7.0",
|
|
64
|
-
"@uniweb/
|
|
65
|
-
"@uniweb/semantic-parser": "^1.4.1"
|
|
63
|
+
"@uniweb/content-reader": "^1.2.5",
|
|
64
|
+
"@uniweb/semantic-parser": "^1.4.1",
|
|
65
|
+
"@uniweb/theming": "^0.1.15"
|
|
66
66
|
},
|
|
67
67
|
"optionalDependencies": {
|
|
68
68
|
"@uniweb/runtime": "^0.27.4"
|
package/src/i18n/index.js
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* import { extractManifest, syncManifest, mergeLocale } from '@uniweb/build/i18n'
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { readFile, writeFile, mkdir
|
|
10
|
+
import { readFile, writeFile, mkdir } from 'fs/promises'
|
|
11
11
|
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
16
|
import { extractTranslatableContent } from './extract.js'
|
|
16
17
|
import { syncManifests, formatSyncReport } from './sync.js'
|
|
17
18
|
import { mergeTranslations, generateAllLocales } from './merge.js'
|
|
@@ -118,7 +119,6 @@ const DEFAULTS = {
|
|
|
118
119
|
/**
|
|
119
120
|
* Reserved files in the locales directory (not locale translation files)
|
|
120
121
|
*/
|
|
121
|
-
const RESERVED_FILES = new Set(['manifest.json', '_memory.json'])
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
124
|
* Get available locales by scanning the locales directory for *.json files
|
|
@@ -126,19 +126,7 @@ const RESERVED_FILES = new Set(['manifest.json', '_memory.json'])
|
|
|
126
126
|
* @returns {Promise<string[]>} Array of locale codes found
|
|
127
127
|
*/
|
|
128
128
|
async function getAvailableLocales(localesPath) {
|
|
129
|
-
|
|
130
|
-
return []
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
const files = await readdir(localesPath)
|
|
135
|
-
return files
|
|
136
|
-
.filter(f => f.endsWith('.json') && !RESERVED_FILES.has(f))
|
|
137
|
-
.map(f => f.replace('.json', ''))
|
|
138
|
-
.sort()
|
|
139
|
-
} catch {
|
|
140
|
-
return []
|
|
141
|
-
}
|
|
129
|
+
return availableLocales(localesPath)
|
|
142
130
|
}
|
|
143
131
|
|
|
144
132
|
/**
|
|
@@ -154,23 +142,8 @@ async function getAvailableLocales(localesPath) {
|
|
|
154
142
|
* @returns {Promise<string[]>} Resolved array of locale codes
|
|
155
143
|
*/
|
|
156
144
|
async function resolveLocales(configLocales, localesPath) {
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
// Check for '*' in array (e.g., locales: ['*'])
|
|
160
|
-
if (configLocales.includes('*')) {
|
|
161
|
-
return getAvailableLocales(localesPath)
|
|
162
|
-
}
|
|
163
|
-
// Normalize: support both string codes and objects ({code, label})
|
|
164
|
-
return configLocales.map(l => typeof l === 'string' ? l : l.code)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// String value '*' means all available
|
|
168
|
-
if (configLocales === '*') {
|
|
169
|
-
return getAvailableLocales(localesPath)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// undefined, null, or empty array → all available
|
|
173
|
-
return getAvailableLocales(localesPath)
|
|
145
|
+
// The one rule, shared with the push (`uwx/site.js`) — see `./locales.js`.
|
|
146
|
+
return resolveLocaleList(configLocales, localesPath)
|
|
174
147
|
}
|
|
175
148
|
|
|
176
149
|
/**
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// ⭐ WHICH LOCALES A SITE HAS — one rule, for the build and for the push.
|
|
2
|
+
//
|
|
3
|
+
// An explicit `languages:` list is the set, as written. `'*'`, or no `languages:` at all, is every
|
|
4
|
+
// translation file in the locales directory. ⛔ Until 2026-09-25 the push read an explicit
|
|
5
|
+
// `languages:` alone, so a site whose set comes from its files — the `international` template,
|
|
6
|
+
// which has none — was pushed as a one-language site, and none of its translations left the
|
|
7
|
+
// machine, while the build of the same site produced every one of them.
|
|
8
|
+
//
|
|
9
|
+
// A leaf, with nothing but `node:fs` beneath it, so the sync lane can use it without pulling in
|
|
10
|
+
// the rest of the i18n module.
|
|
11
|
+
|
|
12
|
+
import { existsSync, readdirSync } from 'node:fs'
|
|
13
|
+
|
|
14
|
+
// Files in the locales directory that are not a locale's translations.
|
|
15
|
+
export const RESERVED_LOCALE_FILES = new Set(['manifest.json', '_memory.json'])
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The locales a directory holds translations for — one per `<locale>.json` — sorted.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} localesPath
|
|
21
|
+
* @returns {string[]}
|
|
22
|
+
*/
|
|
23
|
+
export function availableLocales(localesPath) {
|
|
24
|
+
if (!existsSync(localesPath)) return []
|
|
25
|
+
try {
|
|
26
|
+
return readdirSync(localesPath)
|
|
27
|
+
.filter((f) => f.endsWith('.json') && !RESERVED_LOCALE_FILES.has(f))
|
|
28
|
+
.map((f) => f.slice(0, -'.json'.length))
|
|
29
|
+
.sort()
|
|
30
|
+
} catch {
|
|
31
|
+
return []
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A site's locales, from its `languages:` and its locales directory.
|
|
37
|
+
*
|
|
38
|
+
* - `['es', 'fr']` → those, as written (an entry may be `{ code, label }`)
|
|
39
|
+
* - `'*'`, a list holding `'*'`, or nothing → every locale the directory holds
|
|
40
|
+
*
|
|
41
|
+
* @param {string[]|string|undefined} configLocales - `site.yml::languages`
|
|
42
|
+
* @param {string} localesPath
|
|
43
|
+
* @returns {string[]}
|
|
44
|
+
*/
|
|
45
|
+
export function resolveLocaleList(configLocales, localesPath) {
|
|
46
|
+
if (Array.isArray(configLocales) && configLocales.length > 0) {
|
|
47
|
+
if (configLocales.includes('*')) return availableLocales(localesPath)
|
|
48
|
+
return configLocales.map((l) => (typeof l === 'string' ? l : l.code))
|
|
49
|
+
}
|
|
50
|
+
return availableLocales(localesPath)
|
|
51
|
+
}
|
package/src/uwx/index.js
CHANGED
|
@@ -71,7 +71,10 @@ export {
|
|
|
71
71
|
declarationsToQueriesYml,
|
|
72
72
|
folderToFolderYml,
|
|
73
73
|
findRecordFileByUuid,
|
|
74
|
+
indexFolder,
|
|
74
75
|
} from './records-project.js'
|
|
76
|
+
// Which stored record each of a copy's records is, when its map lost the answer.
|
|
77
|
+
export { matchStoredRecords } from './record-identity.js'
|
|
75
78
|
// The scope a site's `@/x` refs resolve into — its foundation's. A pull resolves it
|
|
76
79
|
// up front and hands it to the synchronous projections above.
|
|
77
80
|
export { siteSelfScope } from './self-scope.js'
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// ⭐ WHICH STORED RECORD EACH OF A COPY'S RECORDS IS — recovered from what the backend holds.
|
|
2
|
+
//
|
|
3
|
+
// A push sends a record with the uuid THIS backend minted for it: `sync.json`'s `records` map,
|
|
4
|
+
// the record's own id (its file's `$uuid`) → theirs. A copy bound to the site whose map lost an
|
|
5
|
+
// entry sends that record with none, and the backend mints a second entity for it — silently,
|
|
6
|
+
// since a new record is never refused. The folder that places it is refused instead, because its
|
|
7
|
+
// placements then carry no identity while the stored ones do (`identity_required`, measured
|
|
8
|
+
// 2026-09-25 on a blog site whose binding held neither map).
|
|
9
|
+
//
|
|
10
|
+
// ⭐ MATCHED THE WAY A PULL PLACES THEM: a record whose own id IS a stored uuid is that record —
|
|
11
|
+
// the first backend a record reaches mints the id its file keeps. Otherwise it is the stored
|
|
12
|
+
// record the folder places under the same Model and slug. ⛔ A Model and slug two stored records
|
|
13
|
+
// share names neither, and a stored record already mapped to another is not taken again: a wrong
|
|
14
|
+
// match would overwrite a record the author did not edit, where no match only re-creates one.
|
|
15
|
+
|
|
16
|
+
import { indexFolder } from './records-project.js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The stored uuid of each record the map does not name, where the backend's folder says which.
|
|
20
|
+
*
|
|
21
|
+
* @param {object} params
|
|
22
|
+
* @param {Array<{ ownId?: string|null, model?: string, slug?: string }>} params.index - the
|
|
23
|
+
* records a push is about to send (`emitSyncPackages().records.index`)
|
|
24
|
+
* @param {Object<string,string>} [params.recordMap] - this backend's map: own id → its uuid
|
|
25
|
+
* @param {object} params.folderDoc - the backend's `@uniweb/folder` document for the site
|
|
26
|
+
* @returns {Object<string,string>} own id → the stored uuid, for the records recovered
|
|
27
|
+
*/
|
|
28
|
+
export function matchStoredRecords({ index, recordMap = {}, folderDoc }) {
|
|
29
|
+
const placed = indexFolder(folderDoc)
|
|
30
|
+
const byName = new Map()
|
|
31
|
+
for (const [theirs, { slug, schema }] of placed) {
|
|
32
|
+
if (!slug || !schema) continue
|
|
33
|
+
const key = `${schema} ${slug}`
|
|
34
|
+
byName.set(key, byName.has(key) ? null : theirs)
|
|
35
|
+
}
|
|
36
|
+
const taken = new Set(Object.values(recordMap))
|
|
37
|
+
const learned = {}
|
|
38
|
+
for (const e of index || []) {
|
|
39
|
+
if (!e?.ownId || recordMap[e.ownId] || learned[e.ownId]) continue
|
|
40
|
+
const theirs = placed.has(e.ownId) ? e.ownId : byName.get(`${e.model} ${e.slug}`)
|
|
41
|
+
if (!theirs || taken.has(theirs)) continue
|
|
42
|
+
taken.add(theirs)
|
|
43
|
+
learned[e.ownId] = theirs
|
|
44
|
+
}
|
|
45
|
+
return learned
|
|
46
|
+
}
|
|
@@ -41,7 +41,7 @@ import yaml from 'js-yaml'
|
|
|
41
41
|
import { YAML_OPTIONS } from '../utils/yaml-schema.js'
|
|
42
42
|
import { parseFrontmatter } from './entity-source.js'
|
|
43
43
|
import { writeRecordFile, writeQueriesConfig, writeRecordsConfig } from './project-writer.js'
|
|
44
|
-
import { defaultSchema, deferredFromSchema, foundationDataSchemas, foundationSchemaJson } from './queries-config.js'
|
|
44
|
+
import { defaultSchema, deferredFromSchema, foundationDataSchemas, foundationSchemaJson, QUERIES_YML_RELPATH } from './queries-config.js'
|
|
45
45
|
import { dataKeyTypes } from './data-key-types.js'
|
|
46
46
|
import { poolDirsForSchema, schemaForPoolDirs, resolveRecordsDir } from '../site/entity-pool.js'
|
|
47
47
|
import { folderYmlPath } from '../site/records-config.js'
|
|
@@ -125,7 +125,7 @@ function defaultFormat(poolDir, declaration) {
|
|
|
125
125
|
// are walked; the collection is the NEAREST enclosing branch segment (correct for
|
|
126
126
|
// the default one-branch-per-collection org; a deeply nested virtual org may
|
|
127
127
|
// differ — see the module header).
|
|
128
|
-
function indexFolder(folderDoc) {
|
|
128
|
+
export function indexFolder(folderDoc) {
|
|
129
129
|
const byUuid = new Map()
|
|
130
130
|
const walk = (nodes, folderPath) => {
|
|
131
131
|
for (const node of nodes || []) {
|
|
@@ -283,7 +283,7 @@ function isDerivedDeferred(d, dataSchemas) {
|
|
|
283
283
|
return d.deferred.every((f) => a.has(f))
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
function declToFileShape(wire, dataSchemas = null, scope = null, own = null, keyTypes = null) {
|
|
286
|
+
function declToFileShape(wire, dataSchemas = null, scope = null, own = null, keyTypes = null, authored = null) {
|
|
287
287
|
// ⛔ UNDO THE PRODUCER'S QUALIFICATION FIRST, before anything compares against
|
|
288
288
|
// `schema`. The push qualifies a foundation-relative `@/x` to `@scope/x`
|
|
289
289
|
// (`site.js::queriesNested`), and both checks below are keyed by the author's
|
|
@@ -317,8 +317,14 @@ function declToFileShape(wire, dataSchemas = null, scope = null, own = null, key
|
|
|
317
317
|
// The default is the query's name — or, when no data schema has that name, the type the
|
|
318
318
|
// foundation declares for the data key of that name (`data-key-types.js`), which is what a
|
|
319
319
|
// push sent in its place. Either one stays unwritten, so the terse file stays terse.
|
|
320
|
+
// ⛔ UNLESS THE AUTHOR WROTE IT: a `schema:` the local file already states for this query is
|
|
321
|
+
// written back as it is. Until 2026-09-25 a pull into a working copy dropped international's
|
|
322
|
+
// `articles: { schema: '@std/article' }`, because a section types `articles` as `@std/article`.
|
|
320
323
|
const keyDefault = name && !own?.has(name) ? keyTypes?.get(name) : null
|
|
321
|
-
|
|
324
|
+
const written = name ? authored?.get(name) : undefined
|
|
325
|
+
if (d.schema && (d.schema === written || (d.schema !== defaultSchema(name) && d.schema !== keyDefault))) {
|
|
326
|
+
decl.schema = d.schema
|
|
327
|
+
}
|
|
322
328
|
setIf(decl, 'sort', d.sort)
|
|
323
329
|
setIf(decl, 'where', d.where)
|
|
324
330
|
setIf(decl, 'limit', d.limit)
|
|
@@ -383,6 +389,26 @@ function declToFileShape(wire, dataSchemas = null, scope = null, own = null, key
|
|
|
383
389
|
* (`info.foundation`, the pinned `@org/name@version`), which is that scope.
|
|
384
390
|
* @returns {{ collections?: 'updated'|'unchanged' }}
|
|
385
391
|
*/
|
|
392
|
+
// The `schema:` each query's author wrote, by query name — `queries.yml` over `site.yml::queries`,
|
|
393
|
+
// the precedence the build reads them in. A query written without one is absent.
|
|
394
|
+
function authoredQuerySchemas(siteRoot, siteYml) {
|
|
395
|
+
let file = null
|
|
396
|
+
try {
|
|
397
|
+
file = yaml.load(readFileSync(join(siteRoot, QUERIES_YML_RELPATH), 'utf8'), YAML_OPTIONS)
|
|
398
|
+
} catch {
|
|
399
|
+
file = null
|
|
400
|
+
}
|
|
401
|
+
const out = new Map()
|
|
402
|
+
for (const decls of [siteYml?.queries, file]) {
|
|
403
|
+
if (!decls || typeof decls !== 'object') continue
|
|
404
|
+
for (const [name, decl] of Object.entries(decls)) {
|
|
405
|
+
if (typeof decl?.schema === 'string') out.set(name, decl.schema)
|
|
406
|
+
else if (out.has(name)) out.delete(name)
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return out
|
|
410
|
+
}
|
|
411
|
+
|
|
386
412
|
export function declarationsToQueriesYml({ document, siteRoot, scope, ...rest }) {
|
|
387
413
|
refuseOrgOption(rest, 'declarationsToQueriesYml')
|
|
388
414
|
const decls = Array.isArray(document?.queries) ? document.queries : []
|
|
@@ -408,10 +434,11 @@ export function declarationsToQueriesYml({ document, siteRoot, scope, ...rest })
|
|
|
408
434
|
// (`unresolveSelfScope`) — and the types of its data keys.
|
|
409
435
|
const own = ownSchemaNames(dataSchemas)
|
|
410
436
|
const keyTypes = siteYml ? dataKeyTypes(foundationSchemaJson(siteRoot, siteYml)) : null
|
|
437
|
+
const authored = authoredQuerySchemas(siteRoot, siteYml)
|
|
411
438
|
|
|
412
439
|
const queries = {}
|
|
413
440
|
for (const d of decls) {
|
|
414
|
-
const { name, decl } = declToFileShape(d, dataSchemas, selfScope, own, keyTypes)
|
|
441
|
+
const { name, decl } = declToFileShape(d, dataSchemas, selfScope, own, keyTypes, authored)
|
|
415
442
|
if (!name) continue
|
|
416
443
|
queries[name] = decl
|
|
417
444
|
}
|
package/src/uwx/site.js
CHANGED
|
@@ -74,6 +74,7 @@ import { emitEntitySyncPackage } from './entity-document.js'
|
|
|
74
74
|
import { loadLocaleTranslations, localizeScalar, localizeScalarList, localizeContentDoc, localesDir, isLocalizedContent } from './locale-sync.js'
|
|
75
75
|
import { unwrapLocalized } from './backfill.js'
|
|
76
76
|
import { loadFreeformTranslation } from '../i18n/freeform.js'
|
|
77
|
+
import { resolveLocaleList } from '../i18n/locales.js'
|
|
77
78
|
import { updateBackendState, readBackendState } from './sync-store.js'
|
|
78
79
|
import { upsertYamlScalar } from './yaml-upsert.js'
|
|
79
80
|
import { resolveQueriesConfig } from './queries-config.js'
|
|
@@ -1287,7 +1288,10 @@ export async function siteProjectToDocument(siteRoot, opts = {}) {
|
|
|
1287
1288
|
// Target-locale translations (locales/{locale}.json) for wrapping localized
|
|
1288
1289
|
// scalars back into per-locale form. Source-locale-only when no target locales /
|
|
1289
1290
|
// no locale files exist (single-locale sites are unaffected).
|
|
1290
|
-
|
|
1291
|
+
// ⭐ The site's locales by the build's own rule (`i18n/locales.js`): an explicit
|
|
1292
|
+
// `languages:` list, else every translation file. ⛔ Until 2026-09-25 only an explicit list
|
|
1293
|
+
// counted, so a site with none — the `international` template — pushed no translations.
|
|
1294
|
+
const targetLocales = resolveLocaleList(siteYml.languages, localesDir(siteRoot)).filter(
|
|
1291
1295
|
(l) => l !== sourceLocale
|
|
1292
1296
|
)
|
|
1293
1297
|
const translations = targetLocales.length > 0 ? loadLocaleTranslations(siteRoot, targetLocales) : null
|