uniweb 1.24.7 → 1.24.9

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",
3
- "version": "1.24.7",
3
+ "version": "1.24.9",
4
4
  "description": "Create structured Vite + React sites with content/code separation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,15 +41,15 @@
41
41
  "js-yaml": "^4.3.2",
42
42
  "prompts": "^2.4.2",
43
43
  "tar": "^7.5.21",
44
- "@uniweb/core": "~1.5.1",
45
- "@uniweb/semantic-parser": "~1.13.0",
46
44
  "@uniweb/content-writer": "~1.3.1",
47
- "@uniweb/schemas": "~1.6.7"
45
+ "@uniweb/schemas": "~1.6.7",
46
+ "@uniweb/core": "~1.5.1",
47
+ "@uniweb/semantic-parser": "~1.13.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "@uniweb/build": "~1.13.3",
51
- "@uniweb/semantic-parser": "~1.13.0",
52
- "@uniweb/content-reader": "~1.5.7"
50
+ "@uniweb/build": "~1.13.5",
51
+ "@uniweb/content-reader": "~1.5.7",
52
+ "@uniweb/semantic-parser": "~1.13.0"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@uniweb/build": {
@@ -3078,6 +3078,8 @@ Running `extract` before a build is the usual first mistake — it reads the com
3078
3078
 
3079
3079
  An override key is the page's route and the section's id (`cta` for `2-cta.md`); a page's own title, label, description and keywords are `/pricing:_meta`, and in `locales/records/` a record is named by its manifest context (`std/article/launch`).
3080
3080
 
3081
+ **An entry can be flagged `outdated`:** `{ "default": "Acerca de PandaWatch", "outdated": { "/about:hero": "About PandaWatch" } }`. The source was edited a little, and the old translation stays until someone reviews it, so it still shows, and `uniweb i18n status` lists it. An edit in the Uniweb app does this, and so does one in a file, at `uniweb i18n sync` or at the push. To finish it, write the new translation in the entry: new words end the flag, whatever is left beside them. If the words still hold, make the entry a plain string of them. An edit that shares under half its words with the old text keeps nothing, and neither does a page title, an image's alt text or a data block's string: those show the source until they are translated. **`locales/_kept.json`** holds what the app keeps for a section that no file has a place for. A pull writes it and a push sends it back, so commit it and leave it alone.
3082
+
3081
3083
  *Free-form bodies* — when a language needs different structure, different images, or copy rewritten rather than translated. The file replaces one section's content:
3082
3084
 
3083
3085
  ```
@@ -834,6 +834,22 @@ export class BackendClient {
834
834
  })
835
835
  }
836
836
 
837
+ /**
838
+ * Whether this backend serves a file at a path of its own origin. The question is put to the host
839
+ * rather than read from the path's shape, since its routes are its own to lay out.
840
+ *
841
+ * @param {string} path - leading-slash path
842
+ * @returns {Promise<boolean>}
843
+ */
844
+ async servesFile(path) {
845
+ try {
846
+ const res = await this.request(path, { method: 'HEAD' })
847
+ return res.ok && !String(res.headers?.get?.('content-type') || '').startsWith('text/html')
848
+ } catch {
849
+ return false
850
+ }
851
+ }
852
+
837
853
  /**
838
854
  * GET /dev/site/content/pull/{uuid} — the content lane document. Pass the
839
855
  * last-seen ETag (opaque) to make it conditional: a match returns 304 (empty body).
@@ -31,13 +31,17 @@ import { humanBytes } from '../utils/bytes.js'
31
31
  * `siteUuid` is the owner the uploaded bytes are charged to. Callers create the
32
32
  * site before uploading precisely so this is set — an unowned upload is charged
33
33
  * and cannot be freed, because freeing means deleting the owning entity.
34
- * @returns {Promise<{ map: Record<string,string>, ids: Record<string,{id:string,ext:string}>, missing: string[], failed: Array<{path:string,status:number,detail?:string}> }>}
34
+ * @returns {Promise<{ map: Record<string,string>, ids: Record<string,{id:string,ext:string}>, missing: string[], served: string[], failed: Array<{path:string,status:number,detail?:string}> }>}
35
35
  * `map` is ref → serve URL for refs that resolved AND uploaded. The two failure
36
36
  * kinds are reported SEPARATELY because callers must treat them differently:
37
37
  * `missing` is a ref with no file under the site — an authoring mistake, already
38
38
  * broken before us, worth a warning; `failed` is a ref whose bytes we could not
39
39
  * store — a transport or QUOTA refusal, and shipping content that still points at
40
40
  * the local path would publish a broken image while only warning about it.
41
+ * ⭐ `served` is neither: an address the backend serves itself, which stays as written.
42
+ * A pull writes one where it has no file to put back, as a clone's favicon or a record's
43
+ * image on a backend whose addresses are paths of its own origin. ⛔ Until 2026-10-31
44
+ * these were warned about as missing files.
41
45
  */
42
46
  export async function uploadSiteMedia(
43
47
  client,
@@ -45,10 +49,11 @@ export async function uploadSiteMedia(
45
49
  refs,
46
50
  { siteUuid = null, onProgress, warn } = {}
47
51
  ) {
48
- if (!refs?.length) return { map: {}, ids: {}, missing: [], failed: [] }
52
+ if (!refs?.length) return { map: {}, ids: {}, missing: [], served: [], failed: [] }
49
53
 
50
54
  const files = []
51
55
  const missing = []
56
+ const served = []
52
57
  // ⭐ A ref is a site-root media path (`/images/x.png`), resolved under the site — or a file the
53
58
  // caller already located, `{ ref, path, contentType? }`: a file record's file and its preview, which
54
59
  // live in the records directory and declare their own type (`@uniweb/file`, 2026-09-28), and a
@@ -60,6 +65,10 @@ export async function uploadSiteMedia(
60
65
  keys.push(ref)
61
66
  const resolved = typeof item === 'string' ? resolveAssetPath(ref, siteDir, siteDir).resolved : item.path
62
67
  if (!resolved || !existsSync(resolved)) {
68
+ if (typeof item === 'string' && (await client.servesFile(ref))) {
69
+ served.push(ref)
70
+ continue
71
+ }
63
72
  warn?.(`local-media: ${ref} not found under the site (skipped)`)
64
73
  missing.push(ref)
65
74
  continue
@@ -74,7 +83,7 @@ export async function uploadSiteMedia(
74
83
  diskPath: resolved
75
84
  })
76
85
  }
77
- if (!files.length) return { map: {}, ids: {}, missing, failed: [] }
86
+ if (!files.length) return { map: {}, ids: {}, missing, served, failed: [] }
78
87
 
79
88
  const result = await client.uploadSiteAssets({ files, siteUuid, onProgress })
80
89
  const failed = [...(result.failed || [])]
@@ -123,7 +132,7 @@ export async function uploadSiteMedia(
123
132
  }
124
133
  map[ref] = entry.serveUrl
125
134
  }
126
- return { map, ids, missing, failed }
135
+ return { map, ids, missing, served, failed }
127
136
  }
128
137
 
129
138
  // ─── Asset-plan refusals ──────────────────────────────────────────────────────
@@ -70,8 +70,12 @@ import {
70
70
  siteContentRemovals,
71
71
  recordRemovals,
72
72
  cleanedRecord,
73
+ documentRows,
74
+ documentSourceLocale,
75
+ sectionsChangedSince,
73
76
  SYNC_STORE_FILE
74
77
  } from '@uniweb/build/uwx'
78
+ import { keepEditedTranslations, rowsWantTranslation, formatKeptTranslations } from '@uniweb/build/i18n'
75
79
 
76
80
  // First entity `$`-document out of a `.uwx` we produced or the backend served.
77
81
  // Deliberately NOT pull.js's `readPullDocuments`: that one is tolerant of JSON
@@ -1729,7 +1733,7 @@ export function refuseUnsendableRecords(refusals, { error, note }) {
1729
1733
  if (!refusals?.length) return false
1730
1734
  const n = refusals.length
1731
1735
  error(
1732
- `${n === 1 ? 'A record' : `${n} records`} cannot be pushed as written — no content was sent.`
1736
+ `${n === 1 ? 'One item' : `${n} items`} cannot be pushed as written — no content was sent.`
1733
1737
  )
1734
1738
  for (const r of refusals) note(` ${r}`)
1735
1739
  return true
@@ -1845,6 +1849,38 @@ export async function recoverUnbankedIdentity({ client, siteDir, pkg, note }) {
1845
1849
  return again
1846
1850
  }
1847
1851
 
1852
+ /**
1853
+ * ⭐ A SOURCE EDIT IN A FILE KEEPS ITS TRANSLATION UNTIL SOMEONE REVIEWS IT, as one in the app does
1854
+ * (`keepEditedTranslations`), and the package goes again with it. The text it was made from is in the
1855
+ * document the push is about to change: one read, made only when a section this copy changed has a row
1856
+ * with no translation. What it finds goes into the translation files, where the next push reads it and a
1857
+ * person sees it, and `commitWriteBacks` commits it.
1858
+ *
1859
+ * Best-effort: with nothing read, the row falls back to the source as any row with no translation does.
1860
+ *
1861
+ * @returns {Promise<boolean>} whether to build the package again
1862
+ */
1863
+ export async function keepTranslationsOfEdits({ client, siteDir, pkg, note }) {
1864
+ const uuid = readBackendState(siteDir, client.origin).site?.uuid
1865
+ const local = uuid && pkg?.siteContent ? entityDocFromUwx(pkg.siteContent.buffer) : null
1866
+ if (!local) return false
1867
+ const sourceLocale = documentSourceLocale(local)
1868
+ const changed = sectionsChangedSince(local, readUnitBases(siteDir, client.origin).local, sourceLocale)
1869
+ const current = documentRows(local, sourceLocale, (record) => changed.has(record))
1870
+ if (!rowsWantTranslation(siteDir, current, { sourceLocale })) return false
1871
+ try {
1872
+ const res = await client.pullSiteContent(uuid)
1873
+ if (!res?.ok) return false
1874
+ const stored = entityDocFromUwx(Buffer.from(await res.arrayBuffer()))
1875
+ if (!stored) return false
1876
+ const said = formatKeptTranslations(keepEditedTranslations(siteDir, documentRows(stored, sourceLocale), current, { sourceLocale }))
1877
+ for (const line of said) note(line)
1878
+ return said.length > 0
1879
+ } catch {
1880
+ return false
1881
+ }
1882
+ }
1883
+
1848
1884
  export function readUnitBases(siteDir, backend) {
1849
1885
  const v = readMap(siteDir, backend, 'unitBases')
1850
1886
  return { local: v.local || {}, remote: v.remote || {} }
@@ -889,6 +889,7 @@ async function runStatusMissing(siteRoot, config, locale, options = {}) {
889
889
 
890
890
  // Collect missing strings from all requested locales
891
891
  const allMissing = []
892
+ const allOutdated = []
892
893
  const byLocale = {}
893
894
 
894
895
  for (const loc of localesToCheck) {
@@ -897,11 +898,13 @@ async function runStatusMissing(siteRoot, config, locale, options = {}) {
897
898
  total: result.total,
898
899
  translated: result.valid.length,
899
900
  missing: result.missing.length,
901
+ outdated: result.outdated?.length ?? 0,
900
902
  coverage:
901
903
  result.total > 0
902
904
  ? Math.round((result.valid.length / result.total) * 100)
903
905
  : 100
904
906
  }
907
+ for (const entry of result.outdated || []) allOutdated.push({ locale: loc, ...entry })
905
908
 
906
909
  // Add locale info to each missing entry
907
910
  for (const entry of result.missing) {
@@ -916,7 +919,8 @@ async function runStatusMissing(siteRoot, config, locale, options = {}) {
916
919
  if (outputJson) {
917
920
  const output = {
918
921
  locales: byLocale,
919
- missing: allMissing
922
+ missing: allMissing,
923
+ outdated: allOutdated
920
924
  }
921
925
  log(JSON.stringify(output, null, 2))
922
926
  return
@@ -927,11 +931,21 @@ async function runStatusMissing(siteRoot, config, locale, options = {}) {
927
931
 
928
932
  // Show summary per locale
929
933
  for (const [loc, info] of Object.entries(byLocale)) {
930
- log(`${loc}: ${info.missing} missing (${info.coverage}% coverage)`)
934
+ log(`${loc}: ${info.missing} missing${info.outdated ? `, ${info.outdated} outdated` : ''} (${info.coverage}% coverage)`)
935
+ }
936
+
937
+ // The old translation still shows. Replace the entry with a string once it is reviewed.
938
+ if (allOutdated.length > 0) {
939
+ log(`\n${colors.bright}Outdated${colors.reset} ${colors.dim}(its source has changed; the old translation still shows)${colors.reset}`)
940
+ for (const entry of allOutdated) {
941
+ log(` ${entry.locale} ${entry.source}`)
942
+ log(` ${colors.dim} was: ${entry.was.join(' | ')}${colors.reset}`)
943
+ log(` ${colors.dim} now: ${entry.translation}${colors.reset}`)
944
+ }
931
945
  }
932
946
 
933
947
  if (allMissing.length === 0) {
934
- log(`\n${colors.green}All strings are translated!${colors.reset}`)
948
+ if (allOutdated.length === 0) log(`\n${colors.green}All strings are translated!${colors.reset}`)
935
949
  return
936
950
  }
937
951
 
@@ -103,6 +103,7 @@ import {
103
103
  deploymentFields,
104
104
  ensureRegisteredFoundation,
105
105
  recoverUnbankedIdentity,
106
+ keepTranslationsOfEdits,
106
107
  ensureSiteExists,
107
108
  refuseUnsendableRecords,
108
109
  clearRemoteSyncStateIfUnbound,
@@ -716,7 +717,7 @@ export async function publish(args = []) {
716
717
  if (mediaRefs.length) {
717
718
  say.info('Uploading media…')
718
719
  try {
719
- const { map, ids, failed } = await uploadSiteMedia(
720
+ const { map, ids, served, failed } = await uploadSiteMedia(
720
721
  client,
721
722
  siteDir,
722
723
  mediaRefs,
@@ -749,7 +750,7 @@ export async function publish(args = []) {
749
750
  }
750
751
  if (ballAssets.length) ball = rewriteSchemalessDataAssets(ball, map)
751
752
  say.dim(
752
- `Media : ${Object.keys(map).length}/${mediaRefs.length} ref(s) → serve URL`
753
+ `Media : ${Object.keys(map).length}/${mediaRefs.length - served.length} ref(s) → serve URL`
753
754
  )
754
755
  } catch (err) {
755
756
  // A typed plan refusal gets its own account (quota, per-file cap, plan caps);
@@ -964,6 +965,9 @@ export async function publish(args = []) {
964
965
  // Identity the backend holds and this copy lacks — see `uniweb push`.
965
966
  const again = await recoverUnbankedIdentity({ client, siteDir, pkg, note: (m) => say.dim(m) })
966
967
  if (again) pkg = await emitSyncPackages(siteDir, { ...emitOptions, ...again })
968
+ if (await keepTranslationsOfEdits({ client, siteDir, pkg, note: (m) => say.dim(m) })) {
969
+ pkg = await emitSyncPackages(siteDir, { ...emitOptions, ...again })
970
+ }
967
971
  } catch (err) {
968
972
  say.err(`Could not build the sync package: ${err.message}`)
969
973
  return { exitCode: 1 }
@@ -243,7 +243,10 @@ function pullCachePath(siteDir) {
243
243
  // content it never took. Every later pull then answered 304 and the file never caught up.
244
244
  // Ignoring those once costs one full pull. (In a repository an ETag is echoed only while
245
245
  // the sync point it was banked with is in the history — see `cacheHolds` below.)
246
- const PULL_CACHE_VERSION = 2
246
+ // ⛔ VERSION 3 DISOWNS THOSE OF A PULL THAT READ NOTHING OF `@`. Before 2026-10-31 a pull took a
247
+ // translation the app had flagged for current, and kept nothing of `@`. A site that has not moved
248
+ // since would answer 304, and its next push would remove what the app keeps there.
249
+ const PULL_CACHE_VERSION = 3
247
250
  export function readPullCache(siteDir) {
248
251
  try {
249
252
  const obj = JSON.parse(readFileSync(pullCachePath(siteDir), 'utf8'))
@@ -1462,14 +1465,15 @@ export async function pull(args = [], deps = {}) {
1462
1465
  'An edit made to one in the app does not come back here, and the next push sends the file.'
1463
1466
  )
1464
1467
  }
1465
- // ⭐ Said, because a push of those sections removes the text. A translation file would make the
1466
- // language the site's, and the next publish would ask to serve it (`uwx/source-locale.js`).
1468
+ // ⭐ Said, because the text is not in a translation file: one would make the language the site's,
1469
+ // and the next publish would ask to serve it (`uwx/source-locale.js`). It is kept for the push to
1470
+ // send back (`locales/_kept.json`), since a language removed in the app keeps its translations.
1467
1471
  if (outsideLanguages.length) {
1468
1472
  info(
1469
- `The app holds text in ${outsideLanguages.join(', ')}, which this site does not list among its languages. ` +
1470
- 'It is not in your files, and your next push of those sections removes it.'
1473
+ `The app holds text in ${outsideLanguages.join(', ')}, which this site does not list among its languages, ` +
1474
+ 'so it is not published. It is kept, and your translation files leave it out.'
1471
1475
  )
1472
- note('To keep it, add the language in the app (the language button in the editor), then pull again.')
1476
+ note('To use it, add the language in the app (Site ▸ Languages), then pull again.')
1473
1477
  }
1474
1478
  if (repo && !notTaken) {
1475
1479
  // ⭐ What the pull changed in the files — not the backend's content against the base,
@@ -99,6 +99,7 @@ import {
99
99
  ensureSiteExists,
100
100
  clearRemoteSyncStateIfUnbound,
101
101
  untakenBase,
102
+ keepTranslationsOfEdits,
102
103
  unsettledFiles,
103
104
  commitWriteBacks,
104
105
  reportWriteBacks,
@@ -505,7 +506,7 @@ export async function push(args = [], deps = {}) {
505
506
  }
506
507
  info('Uploading media…')
507
508
  try {
508
- const { map, ids, failed } = await uploadSiteMedia(
509
+ const { map, ids, served, failed } = await uploadSiteMedia(
509
510
  client,
510
511
  siteDir,
511
512
  mediaRefs,
@@ -530,7 +531,7 @@ export async function push(args = [], deps = {}) {
530
531
  if (Object.keys(map).length) assetRewrite = map
531
532
  if (Object.keys(ids).length) assetIds = ids
532
533
  note(
533
- `${Object.keys(map).length}/${mediaRefs.length} media ref(s) → serve URL`
534
+ `${Object.keys(map).length}/${mediaRefs.length - served.length} media ref(s) → serve URL`
534
535
  )
535
536
  // Record identity in the COMMITTED map. Merge, never replace: this push
536
537
  // carries only the refs its content touched.
@@ -622,6 +623,9 @@ export async function push(args = [], deps = {}) {
622
623
  const again =
623
624
  output || dryRun ? null : await recoverUnbankedIdentity({ client, siteDir, pkg, note })
624
625
  if (again) pkg = await emitSyncPackages(siteDir, { ...emitOptions, ...again })
626
+ if (!output && !dryRun && (await keepTranslationsOfEdits({ client, siteDir, pkg, note }))) {
627
+ pkg = await emitSyncPackages(siteDir, { ...emitOptions, ...again })
628
+ }
625
629
  } catch (err) {
626
630
  error(`Could not build the sync package: ${err.message}`)
627
631
  return { exitCode: 2 }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-10-31T04:15:22.597Z",
3
+ "generatedAt": "2026-10-31T14:53:03.601Z",
4
4
  "packages": {
5
5
  "@uniweb/api": {
6
6
  "version": "1.6.7"
7
7
  },
8
8
  "@uniweb/build": {
9
- "version": "1.13.3"
9
+ "version": "1.13.5"
10
10
  },
11
11
  "@uniweb/content-reader": {
12
12
  "version": "1.5.7"