@verbaly/compiler 0.70.0 → 0.72.0

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/dist/cli.js CHANGED
@@ -899,14 +899,25 @@ function stringEnd(code, start) {
899
899
  }
900
900
  //#endregion
901
901
  //#region src/extract.ts
902
- async function extractProject(cfg) {
902
+ const kept = /* @__PURE__ */ new WeakMap();
903
+ async function extractProject(cfg, options = {}) {
903
904
  const files = await glob(cfg.include, {
904
905
  cwd: cfg.root,
905
906
  ignore: cfg.exclude,
906
907
  absolute: true
907
908
  });
908
909
  const registry = new MessageRegistry();
909
- for (const file of files.sort()) registry.update(file, analyzeFile(readFileSync(file, "utf8"), file));
910
+ const read = options.keepSource ? /* @__PURE__ */ new Map() : null;
911
+ for (const file of files.sort()) {
912
+ const code = readFileSync(file, "utf8");
913
+ const analysis = analyzeFile(code, file);
914
+ registry.update(file, analysis);
915
+ read?.set(file.replaceAll("\\", "/"), {
916
+ code,
917
+ analysis
918
+ });
919
+ }
920
+ if (read) kept.set(registry, read);
910
921
  return registry;
911
922
  }
912
923
  async function collectOrigins(cfg, reuse) {
@@ -1016,15 +1027,20 @@ function collect(nodes, out) {
1016
1027
  if (node.variants) for (const [, body] of node.variants) collect(body, out);
1017
1028
  }
1018
1029
  }
1019
- const TAG = /<(\/?)([a-zA-Z][\w-]*)(\/?)>/g;
1030
+ const TAG = /<(\/?)([a-zA-Z][\w-]*)\s*(\/?)>/g;
1031
+ const BREAK$1 = /^(?:br|wbr)$/;
1020
1032
  function markupNames(message) {
1021
1033
  const out = /* @__PURE__ */ new Set();
1022
- for (const match of message.matchAll(TAG)) if (match[1] || match[3]) out.add(match[2]);
1034
+ for (const match of message.matchAll(TAG)) if (match[1] || match[3] || BREAK$1.test(match[2])) out.add(match[2]);
1023
1035
  return out;
1024
1036
  }
1025
1037
  function tagTokens(message, markup) {
1026
1038
  const out = [];
1027
- for (const match of message.matchAll(TAG)) if (markup.has(match[2])) out.push(`${match[1]}${match[2]}${match[3]}`);
1039
+ for (const [, closing, name, selfClose] of message.matchAll(TAG)) {
1040
+ if (!markup.has(name)) continue;
1041
+ if (!BREAK$1.test(name)) out.push(`${closing}${name}${selfClose}`);
1042
+ else if (!closing) out.push(`${name}/`);
1043
+ }
1028
1044
  return out.sort();
1029
1045
  }
1030
1046
  function surplus(a, b) {
@@ -1225,6 +1241,11 @@ function formatFinding(finding, root) {
1225
1241
  case "escaped": return `${sourcePlace(finding.site, root)}: ${finding.slice} renders as literal text, a tagged template has no params (use t(key, params) for a plural or format block, or pass a \${…} value)`;
1226
1242
  case "unparsed": return `${sourcePlace(finding, root)}: could not be parsed (${finding.message}), its messages were not extracted`;
1227
1243
  case "outdated": return `[${finding.locale}] ${finding.key}: translated from an older source text, update it or keep it with \`npx verbaly review --approve\``;
1244
+ case "lock": {
1245
+ const lock = sourcePlace(finding, root);
1246
+ if (finding.merged) return `${lock} had a merge conflict and now holds both sides, drafts and stamps included: add it to the commit that resolves the merge`;
1247
+ return finding.from ? `${sourcePlace({ file: finding.from }, root)} moved to ${lock}, next to your config: commit both changes` : `${lock} now keeps the source text each translation was made for and which ones are drafts: commit it with your catalogs`;
1248
+ }
1228
1249
  }
1229
1250
  }
1230
1251
  function findingId(finding) {
@@ -1236,6 +1257,7 @@ function findingId(finding) {
1236
1257
  case "positional": return `positional:${finding.site.file}:${finding.params.join(",")}`;
1237
1258
  case "escaped": return `escaped:${finding.site.file}:${finding.slice}`;
1238
1259
  case "unparsed": return `unparsed:${finding.file}`;
1260
+ case "lock": return `lock:${finding.merged ? "merged:" : ""}${finding.file}`;
1239
1261
  }
1240
1262
  }
1241
1263
  function createDevReporter(root, print = (line) => console.warn(`[verbaly] ${line}`), cap = 5) {
@@ -1576,14 +1598,13 @@ function readJsonConfig(path) {
1576
1598
  }
1577
1599
  }
1578
1600
  async function loadTsConfig(path) {
1579
- try {
1580
- const { bundleRequire } = await import("bundle-require");
1581
- const { mod } = await bundleRequire({ filepath: path });
1582
- return mod.default ?? {};
1583
- } catch (error) {
1584
- if (isModuleNotFound(error, "esbuild")) throw new Error(`[verbaly] ${path} needs esbuild: install it with pnpm add -D esbuild`, { cause: error });
1585
- throw error;
1586
- }
1601
+ const { createJiti } = await import("jiti");
1602
+ const mod = await createJiti(import.meta.url, {
1603
+ fsCache: false,
1604
+ moduleCache: false,
1605
+ interopDefault: false
1606
+ }).import(path);
1607
+ return mod.__esModule ? mod.default ?? {} : mod;
1587
1608
  }
1588
1609
  function isModuleNotFound(error, name) {
1589
1610
  return error instanceof Error && error.code === "ERR_MODULE_NOT_FOUND" && error.message.includes(name);
@@ -1603,58 +1624,114 @@ function definedOnly(config) {
1603
1624
  }
1604
1625
  //#endregion
1605
1626
  //#region src/state.ts
1606
- const STATE_FILE = ".verbaly-state.json";
1627
+ const STATE_FILE = "verbaly.lock";
1628
+ const LOCK_VERSION = 1;
1629
+ const README = "Written by Verbaly: the source text each translation was made for, which ones are drafts, and which languages migrate converted. Commit it with your catalogs and never edit it: deleting it marks every draft as reviewed.";
1630
+ const LEGACY_STATE_FILE = ".verbaly-state.json";
1607
1631
  const LEGACY_DRAFTS_FILE = ".verbaly-drafts.json";
1608
- function statePath(cfg, file = STATE_FILE) {
1609
- return join(cfg.dir, file);
1632
+ const resolved = /* @__PURE__ */ new Set();
1633
+ function statePath(cfg) {
1634
+ return join(cfg.root, STATE_FILE);
1635
+ }
1636
+ function legacyPaths(cfg) {
1637
+ return [join(cfg.dir, LEGACY_STATE_FILE), join(cfg.dir, LEGACY_DRAFTS_FILE)];
1610
1638
  }
1611
1639
  function loadState(cfg) {
1612
- const current = readJson(statePath(cfg));
1613
- if (current !== void 0 && !isObject(current)) throw corrupt(statePath(cfg));
1614
- const legacy = readJson(statePath(cfg, LEGACY_DRAFTS_FILE));
1615
- if (legacy !== void 0 && !isObject(legacy)) throw corrupt(statePath(cfg, LEGACY_DRAFTS_FILE));
1616
- const state = isObject(current) ? {
1617
- drafts: readDrafts(current.drafts),
1618
- fingerprints: readFingerprints(current.fingerprints),
1619
- migrated: readMigrated(current.migrated)
1620
- } : {
1640
+ const lock = readSides(statePath(cfg)) ?? [];
1641
+ for (const side of lock) checkVersion(statePath(cfg), side.version);
1642
+ const [legacyState = [], legacyDrafts = []] = legacyPaths(cfg).map((path) => readSides(path) ?? []);
1643
+ const state = {
1621
1644
  drafts: {},
1622
1645
  fingerprints: {}
1623
1646
  };
1624
- if (legacy !== void 0) for (const [locale, keys] of Object.entries(readDrafts(legacy))) markDrafts(state.drafts, locale, keys);
1647
+ const kept = lock.length > 1 ? keptStamp(cfg) : void 0;
1648
+ [...lock, ...legacyState].forEach((source, index) => {
1649
+ for (const [locale, keys] of Object.entries(readDrafts(source.drafts))) markDrafts(state.drafts, locale, keys);
1650
+ for (const [locale, stamps] of Object.entries(readFingerprints(source.fingerprints))) {
1651
+ const into = state.fingerprints[locale] ??= emptyCatalog();
1652
+ for (const [key, stamped] of Object.entries(stamps)) {
1653
+ const held = own(into, key);
1654
+ if (held === void 0) into[key] = stamped;
1655
+ else if (index < lock.length && held !== stamped && kept?.(locale, key, stamped)) into[key] = stamped;
1656
+ }
1657
+ }
1658
+ const migrated = readMigrated(source.migrated);
1659
+ if (migrated) state.migrated = [.../* @__PURE__ */ new Set([...state.migrated ?? [], ...migrated])];
1660
+ });
1661
+ for (const side of legacyDrafts) for (const [locale, keys] of Object.entries(readDrafts(side))) markDrafts(state.drafts, locale, keys);
1625
1662
  return state;
1626
1663
  }
1664
+ function keptStamp(cfg) {
1665
+ const read = /* @__PURE__ */ new Map();
1666
+ return (locale, key, stamped) => {
1667
+ if (!read.has(locale)) try {
1668
+ read.set(locale, readCatalog(cfg, locale));
1669
+ } catch {
1670
+ read.set(locale, void 0);
1671
+ }
1672
+ const translated = own(read.get(locale) ?? {}, key);
1673
+ return translated !== void 0 && translationOf(stamped) === fingerprint(translated);
1674
+ };
1675
+ }
1676
+ function stateFile(cfg) {
1677
+ return [statePath(cfg), ...legacyPaths(cfg)].find((path) => existsSync(path));
1678
+ }
1679
+ function lockNews(cfg, before) {
1680
+ const lock = statePath(cfg);
1681
+ if (resolved.delete(lock)) return {
1682
+ file: lock,
1683
+ merged: true
1684
+ };
1685
+ if (before === lock || !existsSync(lock)) return void 0;
1686
+ return before ? {
1687
+ file: lock,
1688
+ from: before
1689
+ } : { file: lock };
1690
+ }
1691
+ function checkVersion(path, version) {
1692
+ if (typeof version === "number" && version > LOCK_VERSION) throw new Error(`[verbaly] ${path} was written by a newer Verbaly (format ${version}): update @verbaly/compiler to read it`);
1693
+ }
1627
1694
  function readState(cfg) {
1695
+ const marked = (readText(statePath(cfg))?.split(/\r?\n/) ?? []).some((line) => CONFLICT.start.test(line)) ? { conflict: true } : {};
1628
1696
  try {
1629
- return { state: loadState(cfg) };
1697
+ return {
1698
+ state: loadState(cfg),
1699
+ ...marked
1700
+ };
1630
1701
  } catch (error) {
1631
1702
  return {
1632
1703
  state: {
1633
1704
  drafts: {},
1634
1705
  fingerprints: {}
1635
1706
  },
1636
- problem: error.message.replace(/^\[verbaly\] /, "")
1707
+ problem: error.message.replace(/^\[verbaly\] /, ""),
1708
+ ...marked
1637
1709
  };
1638
1710
  }
1639
1711
  }
1640
1712
  function saveState(cfg, state) {
1641
1713
  const fresh = serializeState(state);
1642
1714
  const path = statePath(cfg);
1643
- const legacy = statePath(cfg, LEGACY_DRAFTS_FILE);
1715
+ const legacy = legacyPaths(cfg);
1644
1716
  if (fresh === void 0) {
1645
- rmSync(path, { force: true });
1646
- rmSync(legacy, { force: true });
1717
+ for (const file of [path, ...legacy]) rmSync(file, { force: true });
1647
1718
  return;
1648
1719
  }
1649
- let existing;
1720
+ const existing = readText(path);
1721
+ if (existing === void 0) mkdirSync(cfg.root, { recursive: true });
1722
+ const serialized = withLineEndings(fresh, existing ?? legacy.map(readText).find((text) => text !== void 0));
1723
+ if (existing !== serialized) {
1724
+ if (existing !== void 0 && conflictSides(existing)) resolved.add(path);
1725
+ writeFileSync(path, serialized);
1726
+ }
1727
+ for (const file of legacy) rmSync(file, { force: true });
1728
+ }
1729
+ function readText(path) {
1650
1730
  try {
1651
- existing = readFileSync(path, "utf8");
1731
+ return readFileSync(path, "utf8");
1652
1732
  } catch {
1653
- mkdirSync(cfg.dir, { recursive: true });
1733
+ return;
1654
1734
  }
1655
- const serialized = withLineEndings(fresh, existing);
1656
- if (existing !== serialized) writeFileSync(path, serialized);
1657
- if (existsSync(legacy)) rmSync(legacy);
1658
1735
  }
1659
1736
  function updateState(cfg, catalogs) {
1660
1737
  const next = refreshState(cfg, catalogs, loadState(cfg));
@@ -1802,28 +1879,57 @@ function serializeState(state) {
1802
1879
  fingerprints[locale] = Object.fromEntries(keys.map((key) => [key, entries[key]]));
1803
1880
  }
1804
1881
  const migrated = [...new Set(state.migrated ?? [])].sort();
1805
- const out = {};
1882
+ if (!Object.keys(drafts).length && !Object.keys(fingerprints).length && !migrated.length) return;
1883
+ const out = {
1884
+ _readme: README,
1885
+ version: LOCK_VERSION
1886
+ };
1806
1887
  if (Object.keys(drafts).length) out.drafts = drafts;
1807
1888
  if (Object.keys(fingerprints).length) out.fingerprints = fingerprints;
1808
1889
  if (migrated.length) out.migrated = migrated;
1809
- if (!out.drafts && !out.fingerprints && !out.migrated) return void 0;
1810
1890
  return JSON.stringify(out, null, 2) + "\n";
1811
1891
  }
1812
- function readJson(path) {
1813
- let content;
1814
- try {
1815
- content = readFileSync(path, "utf8");
1816
- } catch {
1817
- return;
1818
- }
1892
+ function readSides(path) {
1893
+ const content = readText(path);
1894
+ if (content === void 0) return void 0;
1895
+ const body = content.charCodeAt(0) === 65279 ? content.slice(1) : content;
1896
+ const sides = conflictSides(body);
1897
+ return (sides ?? [body]).map((text) => parseObject(path, text, sides !== void 0));
1898
+ }
1899
+ function parseObject(path, text, conflicted) {
1900
+ let value;
1819
1901
  try {
1820
- return JSON.parse(content.charCodeAt(0) === 65279 ? content.slice(1) : content);
1902
+ value = JSON.parse(text);
1821
1903
  } catch (error) {
1822
- throw corrupt(path, error);
1904
+ throw corrupt(path, conflicted, error);
1823
1905
  }
1906
+ if (!isObject(value)) throw corrupt(path, conflicted);
1907
+ return value;
1824
1908
  }
1825
- function corrupt(path, cause) {
1826
- return new Error(`[verbaly] ${path} is not valid JSON: restore it from git or fix it (deleting it approves every draft)`, { cause });
1909
+ const CONFLICT = {
1910
+ start: /^<{7}(?: |$)/,
1911
+ base: /^\|{7}(?: |$)/,
1912
+ split: /^={7}$/,
1913
+ end: /^>{7}(?: |$)/
1914
+ };
1915
+ function conflictSides(text) {
1916
+ const lines = text.split(/\r?\n/);
1917
+ if (!lines.some((line) => CONFLICT.start.test(line))) return void 0;
1918
+ const ours = [];
1919
+ const theirs = [];
1920
+ let at = "both";
1921
+ for (const line of lines) if (at === "both" && CONFLICT.start.test(line)) at = "ours";
1922
+ else if (at === "ours" && CONFLICT.base.test(line)) at = "base";
1923
+ else if ((at === "ours" || at === "base") && CONFLICT.split.test(line)) at = "theirs";
1924
+ else if (at === "theirs" && CONFLICT.end.test(line)) at = "both";
1925
+ else if (at !== "base") {
1926
+ if (at !== "theirs") ours.push(line);
1927
+ if (at !== "ours") theirs.push(line);
1928
+ }
1929
+ return at === "both" ? [ours.join("\n"), theirs.join("\n")] : void 0;
1930
+ }
1931
+ function corrupt(path, conflicted, cause) {
1932
+ return new Error(conflicted ? `[verbaly] ${path} has a merge conflict Verbaly cannot read: resolve it by hand and keep the entries of both sides (dropping a side, or the file, approves its drafts)` : `[verbaly] ${path} is not valid JSON: restore it from git or fix it (deleting it approves every draft)`, { cause });
1827
1933
  }
1828
1934
  function isObject(value) {
1829
1935
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -2206,7 +2312,7 @@ async function init(input = {}) {
2206
2312
  //#endregion
2207
2313
  //#region src/check.ts
2208
2314
  function gatePasses(result) {
2209
- return result.missing.length === 0 && result.unknown.length === 0 && !result.broken.some((entry) => entry.severity === "error");
2315
+ return result.missing.length === 0 && result.unknown.length === 0 && result.collisions.length === 0 && !result.broken.some((entry) => entry.severity === "error");
2210
2316
  }
2211
2317
  function check(cfg, catalogs, registry, fingerprints = {}) {
2212
2318
  const extracted = registry.messages();
@@ -2276,17 +2382,19 @@ function check(cfg, catalogs, registry, fingerprints = {}) {
2276
2382
  });
2277
2383
  }
2278
2384
  }
2385
+ const collisions = collisionEntries(registry);
2279
2386
  return {
2280
2387
  ok: gatePasses({
2281
2388
  missing,
2282
2389
  unknown,
2283
- broken
2390
+ broken,
2391
+ collisions
2284
2392
  }),
2285
2393
  missing,
2286
2394
  unknown,
2287
2395
  broken,
2288
2396
  extra,
2289
- collisions: collisionEntries(registry),
2397
+ collisions,
2290
2398
  divergent,
2291
2399
  outdated: outdatedTranslations(cfg, shipped, fingerprints)
2292
2400
  };
@@ -2310,6 +2418,10 @@ function formatCheckResult(result, root) {
2310
2418
  lines.push("broken translations:");
2311
2419
  for (const entry of errors) lines.push(` [${entry.locale}] ${entry.key}: ${entry.issue}`);
2312
2420
  }
2421
+ if (result.collisions.length > 0) {
2422
+ lines.push("keys written with more than one text:");
2423
+ for (const entry of result.collisions) lines.push(` ${formatCollision(entry, root)}`);
2424
+ }
2313
2425
  return lines.join("\n");
2314
2426
  }
2315
2427
  function checkNextSteps(result, cliReachable = true) {
@@ -2317,16 +2429,13 @@ function checkNextSteps(result, cliReachable = true) {
2317
2429
  if (result.missing.length > 0) steps.push("missing: run `npx verbaly extract` to scaffold the keys, then fill them (or run `npx verbaly translate`)");
2318
2430
  if (result.unknown.length > 0) steps.push("unknown keys: the key used in the code is in no catalog, fix the key or run `npx verbaly extract`");
2319
2431
  if (result.broken.some((entry) => entry.severity === "error")) steps.push("broken: a translation has to keep the params, tags and plural cases of its source message");
2432
+ if (result.collisions.length > 0) steps.push("collisions: give each text its own key in t.id(…), or write the same text in every place");
2320
2433
  if (steps.length > 0 && !cliReachable) steps.push(`the verbaly command is not linked in this project: ${CLI_INSTALL_FIX}`);
2321
2434
  return steps.join("\n");
2322
2435
  }
2323
2436
  function formatCheckWarnings(result, root, options = {}) {
2324
2437
  const lines = result.broken.filter((entry) => entry.severity === "warning").map((entry) => ` [${entry.locale}] ${entry.key}: ${entry.issue}`);
2325
2438
  for (const entry of result.extra) lines.push(entry.files.length > 0 ? ` [${entry.locale}] ${entry.key}: only this translation has it, so the source language shows the key itself` : ` [${entry.locale}] ${entry.key}: only this translation has it, and no code reads it`);
2326
- for (const entry of result.collisions) lines.push(` ${formatFinding({
2327
- kind: "collision",
2328
- ...entry
2329
- }, root)}`);
2330
2439
  for (const { key, catalog, code } of result.divergent) lines.push(` ${key}: the source catalog says "${truncate(catalog, 40)}" and the code says "${truncate(code.message, 40)}" (${sourcePlace(code, root)}): the code wins, so edit the text there (extract writes it into the catalog)`);
2331
2440
  if (!options.outdatedFails) for (const entry of result.outdated) lines.push(` ${formatFinding({
2332
2441
  kind: "outdated",
@@ -2378,7 +2487,7 @@ function githubCheckAnnotations(result, registry, cfg, options = {}) {
2378
2487
  for (const { key, sites } of result.collisions) {
2379
2488
  const texts = new Set(sites.map((place) => place.message)).size;
2380
2489
  const text = escapeData(`"${key}" has ${counted(texts, "text")}, and every place shows the first one`);
2381
- for (const place of sites) lines.push(`::warning ${at(place.file, place.line)}::${text}`);
2490
+ for (const place of sites) lines.push(`::error ${at(place.file, place.line)}::${text}`);
2382
2491
  }
2383
2492
  for (const { key, code } of result.divergent) {
2384
2493
  const text = escapeData(`"${key}": the source catalog has another text, the code's one ships`);
@@ -2911,8 +3020,9 @@ async function doctor(cfg) {
2911
3020
  for (const issue of issues) warn("bundle", formatBundleIssue(issue), issue.fix);
2912
3021
  if (issues.length === 0) ok("bundle", `${counted(excluded.length, "group")} kept out of the client (${preview(excluded)})`);
2913
3022
  }
2914
- const { state, problem } = readState(cfg);
2915
- if (problem) warn("state", problem, `restore ${STATE_FILE} from git: deleting it would mark every machine draft as reviewed`);
3023
+ const { state, problem, conflict } = readState(cfg);
3024
+ if (problem) warn("state", problem, conflict ? "resolve it by hand, keeping the entries of both sides: taking one side approves the drafts of the other" : `restore ${STATE_FILE} from git: deleting it would mark every machine draft as reviewed`);
3025
+ else if (conflict) warn("state", `${STATE_FILE} has a merge conflict, and both sides were read`, "run `npx verbaly extract`, which writes both sides into it, then commit it");
2916
3026
  if (catalogsHealthy) {
2917
3027
  const stale = Object.entries(state.drafts).flatMap(([locale, keys]) => {
2918
3028
  const live = new Set(effectiveDrafts({ [locale]: keys }, catalogs)[locale] ?? []);
@@ -2940,7 +3050,7 @@ async function doctor(cfg) {
2940
3050
  if (warnings.length > 0) warn("translations", `${counted(warnings.length, "structural warning")} (plural forms a language asks for)`, "run `npx verbaly check` to read them, they never fail the build");
2941
3051
  if (result.collisions.length > 0) {
2942
3052
  const first = result.collisions[0];
2943
- warn("keys", `${counted(result.collisions.length, "key")} written with more than one text, and every place shows the first (${first.key}: ${first.sites.map((at) => sourcePlace(at, cfg.root)).join(", ")})`, "give each text its own key (`npx verbaly check` lists every place)");
3053
+ error("keys", `${counted(result.collisions.length, "key")} written with more than one text, and every place shows the first (${first.key}: ${first.sites.map((at) => sourcePlace(at, cfg.root)).join(", ")})`, "give each text its own key (`npx verbaly check` lists every place)");
2944
3054
  }
2945
3055
  if (result.divergent.length > 0) {
2946
3056
  const first = result.divergent[0];
@@ -2964,6 +3074,7 @@ function preview(keys) {
2964
3074
  //#endregion
2965
3075
  //#region src/inline.ts
2966
3076
  const OPEN_TAG = /^<([a-zA-Z][a-zA-Z0-9-]*)\s*(\/?)>/;
3077
+ const BREAK = /^(?:br|wbr)$/;
2967
3078
  function messageToInline(text) {
2968
3079
  return renderParts(parseParts(text, 0).parts, /* @__PURE__ */ new Map());
2969
3080
  }
@@ -3069,7 +3180,7 @@ function parseParts(text, pos, closeTag) {
3069
3180
  const open = OPEN_TAG.exec(text.slice(i));
3070
3181
  if (open) {
3071
3182
  const [openSrc, name, selfClose] = open;
3072
- if (selfClose) {
3183
+ if (selfClose || BREAK.test(name)) {
3073
3184
  flush();
3074
3185
  parts.push({
3075
3186
  kind: "ph",
@@ -3774,11 +3885,17 @@ async function syncProject(cfg, options = {}) {
3774
3885
  result.written[locale] = writeCatalog(cfg, locale, catalogs[locale] ?? {});
3775
3886
  }
3776
3887
  writeDts(cfg, catalogs[cfg.sourceLocale] ?? {});
3888
+ const before = stateFile(cfg);
3777
3889
  try {
3778
3890
  result.state = updateState(cfg, catalogs);
3779
3891
  } catch (error) {
3780
3892
  result.stateProblem = error.message.replace(/^\[verbaly\] /, "");
3781
3893
  }
3894
+ const news = lockNews(cfg, before);
3895
+ if (news) result.findings.push({
3896
+ kind: "lock",
3897
+ ...news
3898
+ });
3782
3899
  return result;
3783
3900
  }
3784
3901
  function confirmFromDisk(cfg, catalogs, registry) {
@@ -4817,7 +4934,7 @@ async function runCli(args = process.argv.slice(2)) {
4817
4934
  console.log(`[verbaly] ${counted(total, "message")} · locales: ${cfg.locales.join(", ")}${dryRun ? " (dry run, nothing written)" : ""}`);
4818
4935
  for (const [locale, keys] of Object.entries(result.added)) console.log(` ${locale}: ${dryRun ? `would add ${keys.length}` : `+${keys.length}`}`);
4819
4936
  const warnings = result.findings.filter((finding) => {
4820
- if (finding.kind !== "replaced") return true;
4937
+ if (finding.kind !== "replaced" && finding.kind !== "lock") return true;
4821
4938
  console.log(` ${formatFinding(finding, cfg.root)}`);
4822
4939
  return false;
4823
4940
  });
@@ -4846,6 +4963,7 @@ async function runCli(args = process.argv.slice(2)) {
4846
4963
  return;
4847
4964
  }
4848
4965
  if (command === "migrate") {
4966
+ const lockBefore = stateFile(cfg);
4849
4967
  const result = migrateCatalogs(cfg, {
4850
4968
  write: values.write,
4851
4969
  plurals: values.plurals
@@ -4868,6 +4986,7 @@ async function runCli(args = process.argv.slice(2)) {
4868
4986
  for (const entry of result.skipped) console.log(` ${entry.locale} ${entry.key} ${entry.reason}`);
4869
4987
  }
4870
4988
  if (values.write && result.braces.length > 0) console.log(` ${STATE_FILE} remembers the converted languages, so a later run never reads them as i18next again`);
4989
+ sayLockNews(cfg, lockBefore);
4871
4990
  if (values.write) console.log(" next: run verbaly check");
4872
4991
  return;
4873
4992
  }
@@ -4936,7 +5055,7 @@ async function runCli(args = process.argv.slice(2)) {
4936
5055
  }
4937
5056
  if (!result.ok) {
4938
5057
  const brokenCount = result.broken.filter((entry) => entry.severity === "error").length;
4939
- const report = reporter === "github" ? `[verbaly] check failed: ${result.missing.length} missing, ${result.unknown.length} unknown, ${brokenCount} broken` : `[verbaly] check failed\n${formatCheckResult(result, cfg.root)}`;
5058
+ const report = reporter === "github" ? `[verbaly] check failed: ${result.missing.length} missing, ${result.unknown.length} unknown, ${brokenCount} broken, ${counted(result.collisions.length, "collision")}` : `[verbaly] check failed\n${formatCheckResult(result, cfg.root)}`;
4940
5059
  console.error(`${report}\n${checkNextSteps(result)}`);
4941
5060
  }
4942
5061
  if (awaiting.length > 0) {
@@ -4985,7 +5104,9 @@ async function runCli(args = process.argv.slice(2)) {
4985
5104
  const kept = keys.length - written.length;
4986
5105
  if (kept > 0) console.log(` ${locale}: ${counted(kept, "message")} kept as written while this ran`);
4987
5106
  }
5107
+ const lockBefore = stateFile(cfg);
4988
5108
  if (writes.length > 0) recordTranslations(cfg, source, writes);
5109
+ sayLockNews(cfg, lockBefore);
4989
5110
  for (const [locale, keys] of Object.entries(result.invalid)) console.warn(` ${locale}: ${keys.length} rejected (params/tags not preserved): ${keys.join(", ")}`);
4990
5111
  for (const line of formatTranslateFailures(result.failed)) console.error(line);
4991
5112
  if (result.failed.length > 0) process.exitCode = 1;
@@ -5015,7 +5136,9 @@ async function runCli(args = process.argv.slice(2)) {
5015
5136
  }
5016
5137
  acceptOutdated(cfg, shipped, state.fingerprints, outdated);
5017
5138
  for (const [locale, keys] of byLocale(outdated)) console.log(` ${locale}: ${keys.length} kept for the new source text`);
5139
+ const lockBefore = stateFile(cfg);
5018
5140
  saveState(cfg, state);
5141
+ sayLockNews(cfg, lockBefore);
5019
5142
  const reviewed = new Set([...drafts, ...outdated].map(({ locale, key }) => `${locale}:${key}`));
5020
5143
  console.log(`[verbaly] ${counted(reviewed.size, "translation")} marked reviewed ✓`);
5021
5144
  return;
@@ -5119,7 +5242,9 @@ async function runCli(args = process.argv.slice(2)) {
5119
5242
  const verb = values["dry-run"] ? "would import" : "imported";
5120
5243
  console.log(` ${locale}: +${keys.length} ${verb}${values.draft ? " (draft)" : ""}`);
5121
5244
  }
5245
+ const lockBefore = stateFile(cfg);
5122
5246
  if (writes.length > 0) recordTranslations(cfg, catalogs[cfg.sourceLocale] ?? {}, writes);
5247
+ sayLockNews(cfg, lockBefore);
5123
5248
  for (const [locale, keys] of Object.entries(result.skipped)) console.log(` ${locale}: ${keys.length} already translated, kept (use --overwrite to replace)`);
5124
5249
  for (const [locale, keys] of Object.entries(result.rejected)) console.warn(` ${locale}: ${keys.length} rejected (params/tags not preserved): ${keys.join(", ")}`);
5125
5250
  for (const [locale, keys] of Object.entries(result.unknown)) console.warn(` ${locale}: ${counted(keys.length, "unknown key")} ignored (not in the source catalog): ${keys.join(", ")}`);
@@ -5170,6 +5295,13 @@ function checkState(cfg, gating) {
5170
5295
  if (problem) console.warn(`[verbaly] ${problem}, so outdated translations are not reported`);
5171
5296
  return state;
5172
5297
  }
5298
+ function sayLockNews(cfg, before) {
5299
+ const news = lockNews(cfg, before);
5300
+ if (news) console.log(` ${formatFinding({
5301
+ kind: "lock",
5302
+ ...news
5303
+ }, cfg.root)}`);
5304
+ }
5173
5305
  function byLocale(entries) {
5174
5306
  const out = /* @__PURE__ */ new Map();
5175
5307
  for (const { locale, key } of entries) {