@uniweb/build 0.63.3 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "0.63.3",
3
+ "version": "0.63.4",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -57,11 +57,11 @@
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
60
  "@uniweb/content-writer": "^0.3.4",
62
- "@uniweb/semantic-parser": "^1.4.1",
63
61
  "@uniweb/projections": "^0.7.3",
64
62
  "@uniweb/schemas": "^0.7.0",
63
+ "@uniweb/content-reader": "^1.2.5",
64
+ "@uniweb/semantic-parser": "^1.4.1",
65
65
  "@uniweb/theming": "^0.1.15"
66
66
  },
67
67
  "optionalDependencies": {
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, readdir } from 'fs/promises'
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
- if (!existsSync(localesPath)) {
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
- // Explicit list of locales
158
- if (Array.isArray(configLocales) && configLocales.length > 0) {
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
+ }
@@ -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 || []) {
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
- const targetLocales = (Array.isArray(siteYml.languages) ? siteYml.languages : []).filter(
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