@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/index.d.ts CHANGED
@@ -211,7 +211,9 @@ export declare function loadConfig(root: string, overrides?: VerbalyConfig): Pro
211
211
  export declare function clientCatalogs(cfg: ResolvedConfig, catalogs: Catalogs): Catalogs;
212
212
  //#endregion
213
213
  //#region src/extract.d.ts
214
- export declare function extractProject(cfg: ResolvedConfig): Promise<MessageRegistry>;
214
+ export declare function extractProject(cfg: ResolvedConfig, options?: {
215
+ keepSource?: boolean;
216
+ }): Promise<MessageRegistry>;
215
217
  export declare function collectOrigins(cfg: ResolvedConfig, reuse?: MessageRegistry): Promise<Record<string, string[]>>;
216
218
  interface ReplacedText {
217
219
  key: string;
@@ -228,7 +230,7 @@ export declare function shippedCatalogs(cfg: ResolvedConfig, catalogs: Catalogs,
228
230
  export declare function pruneCatalogs(cfg: ResolvedConfig, catalogs: Catalogs, registry: MessageRegistry): Record<string, string[]>;
229
231
  //#endregion
230
232
  //#region src/state.d.ts
231
- export declare const STATE_FILE = ".verbaly-state.json";
233
+ export declare const STATE_FILE = "verbaly.lock";
232
234
  type Drafts = Record<string, string[]>;
233
235
  type Fingerprints = Record<string, Record<string, string>>;
234
236
  interface State {
@@ -243,6 +245,7 @@ interface OutdatedEntry {
243
245
  interface StateRead {
244
246
  state: State;
245
247
  problem?: string;
248
+ conflict?: true;
246
249
  }
247
250
  interface WrittenTranslation {
248
251
  key: string;
@@ -254,6 +257,11 @@ interface TranslationWrite {
254
257
  entries: WrittenTranslation[];
255
258
  draft?: boolean;
256
259
  }
260
+ interface LockEntry {
261
+ file: string;
262
+ from?: string;
263
+ merged?: true;
264
+ }
257
265
  export declare function loadState(cfg: ResolvedConfig): State;
258
266
  export declare function readState(cfg: ResolvedConfig): StateRead;
259
267
  export declare function updateState(cfg: ResolvedConfig, catalogs: Catalogs): State;
@@ -311,7 +319,9 @@ type Finding = ({
311
319
  kind: 'unparsed';
312
320
  } & UnparsedEntry) | ({
313
321
  kind: 'outdated';
314
- } & OutdatedEntry);
322
+ } & OutdatedEntry) | ({
323
+ kind: 'lock';
324
+ } & LockEntry);
315
325
  export declare function collisionEntries(registry: MessageRegistry): CollisionEntry[];
316
326
  export declare function formatCollision({ key, sites }: CollisionEntry, root?: string): string;
317
327
  export declare function formatFinding(finding: Finding, root?: string): string;
@@ -385,7 +395,7 @@ export declare function resolveVirtualId(id: string): string | undefined;
385
395
  export declare function loadVirtualModule(id: string, cfg: ResolvedConfig, catalogs: Catalogs): string | undefined;
386
396
  export declare function isTransformTarget(id: string): boolean;
387
397
  export declare function createSourceFilter(cfg: ResolvedConfig): (id: string) => boolean;
388
- export declare function transformSource(code: string, id: string, registry: MessageRegistry): {
398
+ export declare function transformSource(code: string, id: string, registry: MessageRegistry, scan?: MessageRegistry): {
389
399
  messages: Catalog;
390
400
  result: TransformResult | null;
391
401
  };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as findConfigFile, c as loadConfigFile, d as WIRING_PACKAGES, f as detectHost, i as SOURCE_EXTENSIONS, l as resolveConfig, m as readDependencies, n as counted, p as installCommand, r as truncate, s as loadConfig, t as byCodeUnit, u as targetLocales } from "./text-dwjJ8ZDb.js";
1
+ import { a as findConfigFile, c as loadConfigFile, d as WIRING_PACKAGES, f as detectHost, i as SOURCE_EXTENSIONS, l as resolveConfig, m as readDependencies, n as counted, p as installCommand, r as truncate, s as loadConfig, t as byCodeUnit, u as targetLocales } from "./text-BMBWE8tL.js";
2
2
  import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, rmSync, watch, writeFileSync } from "node:fs";
3
3
  import { dirname, join, relative, resolve, sep } from "node:path";
4
4
  import { CATALOG_SCRIPT, LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseIcu, parseTags, safeAttribute } from "verbaly";
@@ -954,16 +954,34 @@ function stringEnd(code, start) {
954
954
  }
955
955
  //#endregion
956
956
  //#region src/extract.ts
957
- async function extractProject(cfg) {
957
+ const kept = /* @__PURE__ */ new WeakMap();
958
+ async function extractProject(cfg, options = {}) {
958
959
  const files = await glob(cfg.include, {
959
960
  cwd: cfg.root,
960
961
  ignore: cfg.exclude,
961
962
  absolute: true
962
963
  });
963
964
  const registry = new MessageRegistry();
964
- for (const file of files.sort()) registry.update(file, analyzeFile(readFileSync(file, "utf8"), file));
965
+ const read = options.keepSource ? /* @__PURE__ */ new Map() : null;
966
+ for (const file of files.sort()) {
967
+ const code = readFileSync(file, "utf8");
968
+ const analysis = analyzeFile(code, file);
969
+ registry.update(file, analysis);
970
+ read?.set(file.replaceAll("\\", "/"), {
971
+ code,
972
+ analysis
973
+ });
974
+ }
975
+ if (read) kept.set(registry, read);
965
976
  return registry;
966
977
  }
978
+ function scannedAnalysis(scan, file, code) {
979
+ const read = kept.get(scan);
980
+ const key = file.replaceAll("\\", "/");
981
+ const entry = read?.get(key);
982
+ read?.delete(key);
983
+ return entry?.code === code ? entry.analysis : void 0;
984
+ }
967
985
  async function collectOrigins(cfg, reuse) {
968
986
  const registry = reuse ?? await extractProject(cfg);
969
987
  const origins = Object.create(null);
@@ -1060,15 +1078,20 @@ function collect(nodes, out) {
1060
1078
  if (node.variants) for (const [, body] of node.variants) collect(body, out);
1061
1079
  }
1062
1080
  }
1063
- const TAG = /<(\/?)([a-zA-Z][\w-]*)(\/?)>/g;
1081
+ const TAG = /<(\/?)([a-zA-Z][\w-]*)\s*(\/?)>/g;
1082
+ const BREAK = /^(?:br|wbr)$/;
1064
1083
  function markupNames(message) {
1065
1084
  const out = /* @__PURE__ */ new Set();
1066
- for (const match of message.matchAll(TAG)) if (match[1] || match[3]) out.add(match[2]);
1085
+ for (const match of message.matchAll(TAG)) if (match[1] || match[3] || BREAK.test(match[2])) out.add(match[2]);
1067
1086
  return out;
1068
1087
  }
1069
1088
  function tagTokens(message, markup) {
1070
1089
  const out = [];
1071
- for (const match of message.matchAll(TAG)) if (markup.has(match[2])) out.push(`${match[1]}${match[2]}${match[3]}`);
1090
+ for (const [, closing, name, selfClose] of message.matchAll(TAG)) {
1091
+ if (!markup.has(name)) continue;
1092
+ if (!BREAK.test(name)) out.push(`${closing}${name}${selfClose}`);
1093
+ else if (!closing) out.push(`${name}/`);
1094
+ }
1072
1095
  return out.sort();
1073
1096
  }
1074
1097
  function surplus(a, b) {
@@ -1635,6 +1658,11 @@ function formatFinding(finding, root) {
1635
1658
  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)`;
1636
1659
  case "unparsed": return `${sourcePlace(finding, root)}: could not be parsed (${finding.message}), its messages were not extracted`;
1637
1660
  case "outdated": return `[${finding.locale}] ${finding.key}: translated from an older source text, update it or keep it with \`npx verbaly review --approve\``;
1661
+ case "lock": {
1662
+ const lock = sourcePlace(finding, root);
1663
+ 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`;
1664
+ 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`;
1665
+ }
1638
1666
  }
1639
1667
  }
1640
1668
  function findingId(finding) {
@@ -1646,6 +1674,7 @@ function findingId(finding) {
1646
1674
  case "positional": return `positional:${finding.site.file}:${finding.params.join(",")}`;
1647
1675
  case "escaped": return `escaped:${finding.site.file}:${finding.slice}`;
1648
1676
  case "unparsed": return `unparsed:${finding.file}`;
1677
+ case "lock": return `lock:${finding.merged ? "merged:" : ""}${finding.file}`;
1649
1678
  }
1650
1679
  }
1651
1680
  function createDevReporter(root, print = (line) => console.warn(`[verbaly] ${line}`), cap = 5) {
@@ -1667,58 +1696,114 @@ function createDevReporter(root, print = (line) => console.warn(`[verbaly] ${lin
1667
1696
  }
1668
1697
  //#endregion
1669
1698
  //#region src/state.ts
1670
- const STATE_FILE = ".verbaly-state.json";
1699
+ const STATE_FILE = "verbaly.lock";
1700
+ const LOCK_VERSION = 1;
1701
+ 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.";
1702
+ const LEGACY_STATE_FILE = ".verbaly-state.json";
1671
1703
  const LEGACY_DRAFTS_FILE = ".verbaly-drafts.json";
1672
- function statePath(cfg, file = STATE_FILE) {
1673
- return join(cfg.dir, file);
1704
+ const resolved = /* @__PURE__ */ new Set();
1705
+ function statePath(cfg) {
1706
+ return join(cfg.root, STATE_FILE);
1707
+ }
1708
+ function legacyPaths(cfg) {
1709
+ return [join(cfg.dir, LEGACY_STATE_FILE), join(cfg.dir, LEGACY_DRAFTS_FILE)];
1674
1710
  }
1675
1711
  function loadState(cfg) {
1676
- const current = readJson(statePath(cfg));
1677
- if (current !== void 0 && !isObject(current)) throw corrupt(statePath(cfg));
1678
- const legacy = readJson(statePath(cfg, LEGACY_DRAFTS_FILE));
1679
- if (legacy !== void 0 && !isObject(legacy)) throw corrupt(statePath(cfg, LEGACY_DRAFTS_FILE));
1680
- const state = isObject(current) ? {
1681
- drafts: readDrafts(current.drafts),
1682
- fingerprints: readFingerprints(current.fingerprints),
1683
- migrated: readMigrated(current.migrated)
1684
- } : {
1712
+ const lock = readSides(statePath(cfg)) ?? [];
1713
+ for (const side of lock) checkVersion(statePath(cfg), side.version);
1714
+ const [legacyState = [], legacyDrafts = []] = legacyPaths(cfg).map((path) => readSides(path) ?? []);
1715
+ const state = {
1685
1716
  drafts: {},
1686
1717
  fingerprints: {}
1687
1718
  };
1688
- if (legacy !== void 0) for (const [locale, keys] of Object.entries(readDrafts(legacy))) markDrafts(state.drafts, locale, keys);
1719
+ const kept = lock.length > 1 ? keptStamp(cfg) : void 0;
1720
+ [...lock, ...legacyState].forEach((source, index) => {
1721
+ for (const [locale, keys] of Object.entries(readDrafts(source.drafts))) markDrafts(state.drafts, locale, keys);
1722
+ for (const [locale, stamps] of Object.entries(readFingerprints(source.fingerprints))) {
1723
+ const into = state.fingerprints[locale] ??= emptyCatalog();
1724
+ for (const [key, stamped] of Object.entries(stamps)) {
1725
+ const held = own(into, key);
1726
+ if (held === void 0) into[key] = stamped;
1727
+ else if (index < lock.length && held !== stamped && kept?.(locale, key, stamped)) into[key] = stamped;
1728
+ }
1729
+ }
1730
+ const migrated = readMigrated(source.migrated);
1731
+ if (migrated) state.migrated = [.../* @__PURE__ */ new Set([...state.migrated ?? [], ...migrated])];
1732
+ });
1733
+ for (const side of legacyDrafts) for (const [locale, keys] of Object.entries(readDrafts(side))) markDrafts(state.drafts, locale, keys);
1689
1734
  return state;
1690
1735
  }
1736
+ function keptStamp(cfg) {
1737
+ const read = /* @__PURE__ */ new Map();
1738
+ return (locale, key, stamped) => {
1739
+ if (!read.has(locale)) try {
1740
+ read.set(locale, readCatalog(cfg, locale));
1741
+ } catch {
1742
+ read.set(locale, void 0);
1743
+ }
1744
+ const translated = own(read.get(locale) ?? {}, key);
1745
+ return translated !== void 0 && translationOf(stamped) === fingerprint(translated);
1746
+ };
1747
+ }
1748
+ function stateFile(cfg) {
1749
+ return [statePath(cfg), ...legacyPaths(cfg)].find((path) => existsSync(path));
1750
+ }
1751
+ function lockNews(cfg, before) {
1752
+ const lock = statePath(cfg);
1753
+ if (resolved.delete(lock)) return {
1754
+ file: lock,
1755
+ merged: true
1756
+ };
1757
+ if (before === lock || !existsSync(lock)) return void 0;
1758
+ return before ? {
1759
+ file: lock,
1760
+ from: before
1761
+ } : { file: lock };
1762
+ }
1763
+ function checkVersion(path, version) {
1764
+ 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`);
1765
+ }
1691
1766
  function readState(cfg) {
1767
+ const marked = (readText(statePath(cfg))?.split(/\r?\n/) ?? []).some((line) => CONFLICT.start.test(line)) ? { conflict: true } : {};
1692
1768
  try {
1693
- return { state: loadState(cfg) };
1769
+ return {
1770
+ state: loadState(cfg),
1771
+ ...marked
1772
+ };
1694
1773
  } catch (error) {
1695
1774
  return {
1696
1775
  state: {
1697
1776
  drafts: {},
1698
1777
  fingerprints: {}
1699
1778
  },
1700
- problem: error.message.replace(/^\[verbaly\] /, "")
1779
+ problem: error.message.replace(/^\[verbaly\] /, ""),
1780
+ ...marked
1701
1781
  };
1702
1782
  }
1703
1783
  }
1704
1784
  function saveState(cfg, state) {
1705
1785
  const fresh = serializeState(state);
1706
1786
  const path = statePath(cfg);
1707
- const legacy = statePath(cfg, LEGACY_DRAFTS_FILE);
1787
+ const legacy = legacyPaths(cfg);
1708
1788
  if (fresh === void 0) {
1709
- rmSync(path, { force: true });
1710
- rmSync(legacy, { force: true });
1789
+ for (const file of [path, ...legacy]) rmSync(file, { force: true });
1711
1790
  return;
1712
1791
  }
1713
- let existing;
1792
+ const existing = readText(path);
1793
+ if (existing === void 0) mkdirSync(cfg.root, { recursive: true });
1794
+ const serialized = withLineEndings(fresh, existing ?? legacy.map(readText).find((text) => text !== void 0));
1795
+ if (existing !== serialized) {
1796
+ if (existing !== void 0 && conflictSides(existing)) resolved.add(path);
1797
+ writeFileSync(path, serialized);
1798
+ }
1799
+ for (const file of legacy) rmSync(file, { force: true });
1800
+ }
1801
+ function readText(path) {
1714
1802
  try {
1715
- existing = readFileSync(path, "utf8");
1803
+ return readFileSync(path, "utf8");
1716
1804
  } catch {
1717
- mkdirSync(cfg.dir, { recursive: true });
1805
+ return;
1718
1806
  }
1719
- const serialized = withLineEndings(fresh, existing);
1720
- if (existing !== serialized) writeFileSync(path, serialized);
1721
- if (existsSync(legacy)) rmSync(legacy);
1722
1807
  }
1723
1808
  function updateState(cfg, catalogs) {
1724
1809
  const next = refreshState(cfg, catalogs, loadState(cfg));
@@ -1857,28 +1942,57 @@ function serializeState(state) {
1857
1942
  fingerprints[locale] = Object.fromEntries(keys.map((key) => [key, entries[key]]));
1858
1943
  }
1859
1944
  const migrated = [...new Set(state.migrated ?? [])].sort();
1860
- const out = {};
1945
+ if (!Object.keys(drafts).length && !Object.keys(fingerprints).length && !migrated.length) return;
1946
+ const out = {
1947
+ _readme: README,
1948
+ version: LOCK_VERSION
1949
+ };
1861
1950
  if (Object.keys(drafts).length) out.drafts = drafts;
1862
1951
  if (Object.keys(fingerprints).length) out.fingerprints = fingerprints;
1863
1952
  if (migrated.length) out.migrated = migrated;
1864
- if (!out.drafts && !out.fingerprints && !out.migrated) return void 0;
1865
1953
  return JSON.stringify(out, null, 2) + "\n";
1866
1954
  }
1867
- function readJson(path) {
1868
- let content;
1869
- try {
1870
- content = readFileSync(path, "utf8");
1871
- } catch {
1872
- return;
1873
- }
1955
+ function readSides(path) {
1956
+ const content = readText(path);
1957
+ if (content === void 0) return void 0;
1958
+ const body = content.charCodeAt(0) === 65279 ? content.slice(1) : content;
1959
+ const sides = conflictSides(body);
1960
+ return (sides ?? [body]).map((text) => parseObject(path, text, sides !== void 0));
1961
+ }
1962
+ function parseObject(path, text, conflicted) {
1963
+ let value;
1874
1964
  try {
1875
- return JSON.parse(content.charCodeAt(0) === 65279 ? content.slice(1) : content);
1965
+ value = JSON.parse(text);
1876
1966
  } catch (error) {
1877
- throw corrupt(path, error);
1967
+ throw corrupt(path, conflicted, error);
1878
1968
  }
1969
+ if (!isObject(value)) throw corrupt(path, conflicted);
1970
+ return value;
1879
1971
  }
1880
- function corrupt(path, cause) {
1881
- return new Error(`[verbaly] ${path} is not valid JSON: restore it from git or fix it (deleting it approves every draft)`, { cause });
1972
+ const CONFLICT = {
1973
+ start: /^<{7}(?: |$)/,
1974
+ base: /^\|{7}(?: |$)/,
1975
+ split: /^={7}$/,
1976
+ end: /^>{7}(?: |$)/
1977
+ };
1978
+ function conflictSides(text) {
1979
+ const lines = text.split(/\r?\n/);
1980
+ if (!lines.some((line) => CONFLICT.start.test(line))) return void 0;
1981
+ const ours = [];
1982
+ const theirs = [];
1983
+ let at = "both";
1984
+ for (const line of lines) if (at === "both" && CONFLICT.start.test(line)) at = "ours";
1985
+ else if (at === "ours" && CONFLICT.base.test(line)) at = "base";
1986
+ else if ((at === "ours" || at === "base") && CONFLICT.split.test(line)) at = "theirs";
1987
+ else if (at === "theirs" && CONFLICT.end.test(line)) at = "both";
1988
+ else if (at !== "base") {
1989
+ if (at !== "theirs") ours.push(line);
1990
+ if (at !== "ours") theirs.push(line);
1991
+ }
1992
+ return at === "both" ? [ours.join("\n"), theirs.join("\n")] : void 0;
1993
+ }
1994
+ function corrupt(path, conflicted, cause) {
1995
+ 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 });
1882
1996
  }
1883
1997
  function isObject(value) {
1884
1998
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -1932,11 +2046,17 @@ async function syncProject(cfg, options = {}) {
1932
2046
  result.written[locale] = writeCatalog(cfg, locale, catalogs[locale] ?? {});
1933
2047
  }
1934
2048
  writeDts(cfg, catalogs[cfg.sourceLocale] ?? {});
2049
+ const before = stateFile(cfg);
1935
2050
  try {
1936
2051
  result.state = updateState(cfg, catalogs);
1937
2052
  } catch (error) {
1938
2053
  result.stateProblem = error.message.replace(/^\[verbaly\] /, "");
1939
2054
  }
2055
+ const news = lockNews(cfg, before);
2056
+ if (news) result.findings.push({
2057
+ kind: "lock",
2058
+ ...news
2059
+ });
1940
2060
  return result;
1941
2061
  }
1942
2062
  function confirmFromDisk(cfg, catalogs, registry) {
@@ -2122,10 +2242,10 @@ async function init(input = {}) {
2122
2242
  //#endregion
2123
2243
  //#region src/check.ts
2124
2244
  function gatePasses(result) {
2125
- return result.missing.length === 0 && result.unknown.length === 0 && !result.broken.some((entry) => entry.severity === "error");
2245
+ return result.missing.length === 0 && result.unknown.length === 0 && result.collisions.length === 0 && !result.broken.some((entry) => entry.severity === "error");
2126
2246
  }
2127
2247
  function warningCount(result) {
2128
- return result.broken.filter((entry) => entry.severity === "warning").length + result.extra.length + result.collisions.length + result.divergent.length + result.outdated.length;
2248
+ return result.broken.filter((entry) => entry.severity === "warning").length + result.extra.length + result.divergent.length + result.outdated.length;
2129
2249
  }
2130
2250
  function check(cfg, catalogs, registry, fingerprints = {}) {
2131
2251
  const extracted = registry.messages();
@@ -2195,17 +2315,19 @@ function check(cfg, catalogs, registry, fingerprints = {}) {
2195
2315
  });
2196
2316
  }
2197
2317
  }
2318
+ const collisions = collisionEntries(registry);
2198
2319
  return {
2199
2320
  ok: gatePasses({
2200
2321
  missing,
2201
2322
  unknown,
2202
- broken
2323
+ broken,
2324
+ collisions
2203
2325
  }),
2204
2326
  missing,
2205
2327
  unknown,
2206
2328
  broken,
2207
2329
  extra,
2208
- collisions: collisionEntries(registry),
2330
+ collisions,
2209
2331
  divergent,
2210
2332
  outdated: outdatedTranslations(cfg, shipped, fingerprints)
2211
2333
  };
@@ -2229,6 +2351,10 @@ function formatCheckResult(result, root) {
2229
2351
  lines.push("broken translations:");
2230
2352
  for (const entry of errors) lines.push(` [${entry.locale}] ${entry.key}: ${entry.issue}`);
2231
2353
  }
2354
+ if (result.collisions.length > 0) {
2355
+ lines.push("keys written with more than one text:");
2356
+ for (const entry of result.collisions) lines.push(` ${formatCollision(entry, root)}`);
2357
+ }
2232
2358
  return lines.join("\n");
2233
2359
  }
2234
2360
  function formatBuildReport(result, sourceLocale, root, cap = 5) {
@@ -2243,6 +2369,10 @@ function formatBuildReport(result, sourceLocale, root, cap = 5) {
2243
2369
  lines.push(`✗ the build goes on with ${counted(broken.length, "broken translation")}, each rendering differently from its source:`);
2244
2370
  list(broken, (entry) => `[${entry.locale}] ${entry.key}: ${entry.issue}`);
2245
2371
  }
2372
+ if (result.collisions.length > 0) {
2373
+ lines.push(`✗ the build goes on with ${counted(result.collisions.length, "key")} written with more than one text:`);
2374
+ list(result.collisions, (entry) => formatCollision(entry, root));
2375
+ }
2246
2376
  const quoted = (entry) => entry.source ? `: "${truncate(entry.source, 40)}"` : "";
2247
2377
  const untranslated = result.missing.filter((entry) => entry.locale !== sourceLocale);
2248
2378
  if (untranslated.length > 0) {
@@ -2262,16 +2392,13 @@ function checkNextSteps(result, cliReachable = true) {
2262
2392
  if (result.missing.length > 0) steps.push("missing: run `npx verbaly extract` to scaffold the keys, then fill them (or run `npx verbaly translate`)");
2263
2393
  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`");
2264
2394
  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");
2395
+ 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");
2265
2396
  if (steps.length > 0 && !cliReachable) steps.push(`the verbaly command is not linked in this project: ${CLI_INSTALL_FIX}`);
2266
2397
  return steps.join("\n");
2267
2398
  }
2268
2399
  function formatCheckWarnings(result, root, options = {}) {
2269
2400
  const lines = result.broken.filter((entry) => entry.severity === "warning").map((entry) => ` [${entry.locale}] ${entry.key}: ${entry.issue}`);
2270
2401
  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`);
2271
- for (const entry of result.collisions) lines.push(` ${formatFinding({
2272
- kind: "collision",
2273
- ...entry
2274
- }, root)}`);
2275
2402
  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)`);
2276
2403
  if (!options.outdatedFails) for (const entry of result.outdated) lines.push(` ${formatFinding({
2277
2404
  kind: "outdated",
@@ -2338,8 +2465,8 @@ function createSourceFilter(cfg) {
2338
2465
  return !rel.startsWith("..") && matches(rel);
2339
2466
  };
2340
2467
  }
2341
- function transformSource(code, id, registry) {
2342
- const analysis = analyzeFile(code, id);
2468
+ function transformSource(code, id, registry, scan) {
2469
+ const analysis = (scan && scannedAnalysis(scan, id, code)) ?? analyzeFile(code, id);
2343
2470
  registry.update(id, analysis);
2344
2471
  if (analysis.parseError) warnParseError(id, analysis.parseError);
2345
2472
  const messages = emptyCatalog();
@@ -2370,7 +2497,8 @@ function reportGate(cfg, found) {
2370
2497
  const report = {
2371
2498
  broken: fresh(found.broken.filter((entry) => entry.severity === "error"), (entry) => `broken:${entry.locale}:${entry.key}:${entry.issue}`),
2372
2499
  missing: fresh(found.missing, (entry) => `missing:${entry.locale}:${entry.key}`),
2373
- unknown: fresh(found.unknown, (entry) => `unknown:${entry.key}`)
2500
+ unknown: fresh(found.unknown, (entry) => `unknown:${entry.key}`),
2501
+ collisions: fresh(found.collisions, (entry) => `collision:${entry.key}`)
2374
2502
  };
2375
2503
  reported.set(cfg.root, now);
2376
2504
  const lines = formatBuildReport(report, cfg.sourceLocale, cfg.root);
@@ -2696,8 +2824,9 @@ async function doctor(cfg) {
2696
2824
  for (const issue of issues) warn("bundle", formatBundleIssue(issue), issue.fix);
2697
2825
  if (issues.length === 0) ok("bundle", `${counted(excluded.length, "group")} kept out of the client (${preview(excluded)})`);
2698
2826
  }
2699
- const { state, problem } = readState(cfg);
2700
- if (problem) warn("state", problem, `restore ${STATE_FILE} from git: deleting it would mark every machine draft as reviewed`);
2827
+ const { state, problem, conflict } = readState(cfg);
2828
+ 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`);
2829
+ 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");
2701
2830
  if (catalogsHealthy) {
2702
2831
  const stale = Object.entries(state.drafts).flatMap(([locale, keys]) => {
2703
2832
  const live = new Set(effectiveDrafts({ [locale]: keys }, catalogs)[locale] ?? []);
@@ -2725,7 +2854,7 @@ async function doctor(cfg) {
2725
2854
  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");
2726
2855
  if (result.collisions.length > 0) {
2727
2856
  const first = result.collisions[0];
2728
- 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)");
2857
+ 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)");
2729
2858
  }
2730
2859
  if (result.divergent.length > 0) {
2731
2860
  const first = result.divergent[0];
@@ -2926,7 +3055,7 @@ function formatTranslateFailures(failed) {
2926
3055
  async function resolveProvider(cfg, model) {
2927
3056
  const configured = cfg.translate.provider;
2928
3057
  if (typeof configured === "function") return configured;
2929
- const { claudeProvider } = await import("./claude-CusgBHrv.js");
3058
+ const { claudeProvider } = await import("./claude-Baoc6pYL.js");
2930
3059
  return claudeProvider({ model: model ?? cfg.translate.model });
2931
3060
  }
2932
3061
  function structureMatches(source, translated) {