uniweb 1.24.7 → 1.24.8

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.8",
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/core": "~1.5.1",
46
+ "@uniweb/schemas": "~1.6.7",
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.4",
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, replace the entry with the new translation as a plain string, or with the same words as a plain string if they still hold. 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
  ```
@@ -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,
@@ -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,
@@ -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-31T13:54:14.240Z",
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.4"
10
10
  },
11
11
  "@uniweb/content-reader": {
12
12
  "version": "1.5.7"