@verbaly/compiler 0.71.0 → 0.73.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/README.md +21 -19
- package/dist/{claude-CusgBHrv.js → claude-Baoc6pYL.js} +2 -2
- package/dist/{claude-CusgBHrv.js.map → claude-Baoc6pYL.js.map} +1 -1
- package/dist/cli.js +182 -40
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +185 -36
- package/dist/index.js.map +1 -1
- package/dist/{text-dwjJ8ZDb.js → text-BMBWE8tL.js} +8 -9
- package/dist/{text-dwjJ8ZDb.js.map → text-BMBWE8tL.js.map} +1 -1
- package/package.json +7 -11
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
|
|
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;
|
|
@@ -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;
|
|
@@ -257,6 +260,7 @@ interface TranslationWrite {
|
|
|
257
260
|
interface LockEntry {
|
|
258
261
|
file: string;
|
|
259
262
|
from?: string;
|
|
263
|
+
merged?: true;
|
|
260
264
|
}
|
|
261
265
|
export declare function loadState(cfg: ResolvedConfig): State;
|
|
262
266
|
export declare function readState(cfg: ResolvedConfig): StateRead;
|
|
@@ -391,7 +395,7 @@ export declare function resolveVirtualId(id: string): string | undefined;
|
|
|
391
395
|
export declare function loadVirtualModule(id: string, cfg: ResolvedConfig, catalogs: Catalogs): string | undefined;
|
|
392
396
|
export declare function isTransformTarget(id: string): boolean;
|
|
393
397
|
export declare function createSourceFilter(cfg: ResolvedConfig): (id: string) => boolean;
|
|
394
|
-
export declare function transformSource(code: string, id: string, registry: MessageRegistry): {
|
|
398
|
+
export declare function transformSource(code: string, id: string, registry: MessageRegistry, scan?: MessageRegistry): {
|
|
395
399
|
messages: Catalog;
|
|
396
400
|
result: TransformResult | null;
|
|
397
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-
|
|
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";
|
|
@@ -147,7 +147,7 @@ function wantsNesting(cfg, locale, existing, previous) {
|
|
|
147
147
|
if (locale === cfg.sourceLocale) return false;
|
|
148
148
|
return isNested(readTree(cfg, cfg.sourceLocale));
|
|
149
149
|
}
|
|
150
|
-
const ICU_ARG =
|
|
150
|
+
const ICU_ARG = /(^|[^{])\{\s*[a-zA-Z0-9_]+\s*,\s*(?:plural|selectordinal|select|number|date|time)\b/;
|
|
151
151
|
function needsIcu(catalogs) {
|
|
152
152
|
for (const catalog of Object.values(catalogs)) for (const message of Object.values(flatten(catalog))) if (ICU_ARG.test(message)) return true;
|
|
153
153
|
return false;
|
|
@@ -698,13 +698,19 @@ function isTReference(node, names) {
|
|
|
698
698
|
}
|
|
699
699
|
return false;
|
|
700
700
|
}
|
|
701
|
+
const BLOCK_TAIL = /^(?:\s*\|\s*[^\s|{}:]+\s*:|:[A-Za-z_][\w-]*)/;
|
|
701
702
|
function buildMessage(code, quasi, names) {
|
|
702
703
|
const quasis = quasi.quasis;
|
|
703
704
|
const expressions = quasi.expressions;
|
|
705
|
+
const texts = quasis.map(cookedValue);
|
|
704
706
|
const params = [];
|
|
705
707
|
const taken = /* @__PURE__ */ new Map();
|
|
706
|
-
|
|
707
|
-
for (let i = 0; i <
|
|
708
|
+
const tokens = [];
|
|
709
|
+
for (let i = 0; i < texts.length; i++) {
|
|
710
|
+
const chunk = texts[i];
|
|
711
|
+
const head = i < expressions.length && chunk.endsWith("{") && BLOCK_TAIL.test(texts[i + 1]);
|
|
712
|
+
for (const char of head ? chunk.slice(0, -1) : chunk) tokens.push(char);
|
|
713
|
+
if (i === expressions.length) break;
|
|
708
714
|
const expr = expressions[i];
|
|
709
715
|
if (!expr) return void 0;
|
|
710
716
|
if (containsTaggedT(expr, names)) return void 0;
|
|
@@ -715,13 +721,50 @@ function buildMessage(code, quasi, names) {
|
|
|
715
721
|
start: expr.start,
|
|
716
722
|
end: expr.end
|
|
717
723
|
});
|
|
718
|
-
|
|
724
|
+
tokens.push({
|
|
725
|
+
name,
|
|
726
|
+
head
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
let text = "";
|
|
730
|
+
for (let k = 0; k < tokens.length; k++) {
|
|
731
|
+
const token = tokens[k];
|
|
732
|
+
if (typeof token === "string") text += token === "{" || token === "}" ? token + token : token;
|
|
733
|
+
else if (!token.head) text += `{${token.name}}`;
|
|
734
|
+
else {
|
|
735
|
+
const end = blockEnd(tokens, k, false) ?? blockEnd(tokens, k, true);
|
|
736
|
+
if (end === void 0) return {
|
|
737
|
+
text: texts.map((chunk, i) => escapeText(chunk) + (params[i] ? `{${params[i].name}}` : "")).join(""),
|
|
738
|
+
params
|
|
739
|
+
};
|
|
740
|
+
for (let m = k; m <= end; m++) text += tokenText(tokens[m]);
|
|
741
|
+
k = end;
|
|
742
|
+
}
|
|
719
743
|
}
|
|
720
744
|
return {
|
|
721
745
|
text,
|
|
722
746
|
params
|
|
723
747
|
};
|
|
724
748
|
}
|
|
749
|
+
function tokenText(token) {
|
|
750
|
+
if (typeof token === "string") return token;
|
|
751
|
+
return token.head ? `{${token.name}` : `{${token.name}}`;
|
|
752
|
+
}
|
|
753
|
+
function blockEnd(tokens, start, pairs) {
|
|
754
|
+
let depth = 0;
|
|
755
|
+
for (let k = start; k < tokens.length; k++) {
|
|
756
|
+
const token = tokens[k];
|
|
757
|
+
if (typeof token !== "string") {
|
|
758
|
+
if (token.head) depth += 1;
|
|
759
|
+
} else if (token === "{" || token === "}") {
|
|
760
|
+
if (tokens[k + 1] === token && (token === "{" || !(pairs && depth > 1))) k += 1;
|
|
761
|
+
else {
|
|
762
|
+
depth += token === "{" ? 1 : -1;
|
|
763
|
+
if (depth === 0) return k;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
725
768
|
function cookedValue(element) {
|
|
726
769
|
if (!element) return "";
|
|
727
770
|
const value = element.value;
|
|
@@ -954,16 +997,34 @@ function stringEnd(code, start) {
|
|
|
954
997
|
}
|
|
955
998
|
//#endregion
|
|
956
999
|
//#region src/extract.ts
|
|
957
|
-
|
|
1000
|
+
const kept = /* @__PURE__ */ new WeakMap();
|
|
1001
|
+
async function extractProject(cfg, options = {}) {
|
|
958
1002
|
const files = await glob(cfg.include, {
|
|
959
1003
|
cwd: cfg.root,
|
|
960
1004
|
ignore: cfg.exclude,
|
|
961
1005
|
absolute: true
|
|
962
1006
|
});
|
|
963
1007
|
const registry = new MessageRegistry();
|
|
964
|
-
|
|
1008
|
+
const read = options.keepSource ? /* @__PURE__ */ new Map() : null;
|
|
1009
|
+
for (const file of files.sort()) {
|
|
1010
|
+
const code = readFileSync(file, "utf8");
|
|
1011
|
+
const analysis = analyzeFile(code, file);
|
|
1012
|
+
registry.update(file, analysis);
|
|
1013
|
+
read?.set(file.replaceAll("\\", "/"), {
|
|
1014
|
+
code,
|
|
1015
|
+
analysis
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
if (read) kept.set(registry, read);
|
|
965
1019
|
return registry;
|
|
966
1020
|
}
|
|
1021
|
+
function scannedAnalysis(scan, file, code) {
|
|
1022
|
+
const read = kept.get(scan);
|
|
1023
|
+
const key = file.replaceAll("\\", "/");
|
|
1024
|
+
const entry = read?.get(key);
|
|
1025
|
+
read?.delete(key);
|
|
1026
|
+
return entry?.code === code ? entry.analysis : void 0;
|
|
1027
|
+
}
|
|
967
1028
|
async function collectOrigins(cfg, reuse) {
|
|
968
1029
|
const registry = reuse ?? await extractProject(cfg);
|
|
969
1030
|
const origins = Object.create(null);
|
|
@@ -1060,15 +1121,20 @@ function collect(nodes, out) {
|
|
|
1060
1121
|
if (node.variants) for (const [, body] of node.variants) collect(body, out);
|
|
1061
1122
|
}
|
|
1062
1123
|
}
|
|
1063
|
-
const TAG = /<(\/?)([a-zA-Z][\w-]*)(\/?)>/g;
|
|
1124
|
+
const TAG = /<(\/?)([a-zA-Z][\w-]*)\s*(\/?)>/g;
|
|
1125
|
+
const BREAK = /^(?:br|wbr)$/;
|
|
1064
1126
|
function markupNames(message) {
|
|
1065
1127
|
const out = /* @__PURE__ */ new Set();
|
|
1066
|
-
for (const match of message.matchAll(TAG)) if (match[1] || match[3]) out.add(match[2]);
|
|
1128
|
+
for (const match of message.matchAll(TAG)) if (match[1] || match[3] || BREAK.test(match[2])) out.add(match[2]);
|
|
1067
1129
|
return out;
|
|
1068
1130
|
}
|
|
1069
1131
|
function tagTokens(message, markup) {
|
|
1070
1132
|
const out = [];
|
|
1071
|
-
for (const
|
|
1133
|
+
for (const [, closing, name, selfClose] of message.matchAll(TAG)) {
|
|
1134
|
+
if (!markup.has(name)) continue;
|
|
1135
|
+
if (!BREAK.test(name)) out.push(`${closing}${name}${selfClose}`);
|
|
1136
|
+
else if (!closing) out.push(`${name}/`);
|
|
1137
|
+
}
|
|
1072
1138
|
return out.sort();
|
|
1073
1139
|
}
|
|
1074
1140
|
function surplus(a, b) {
|
|
@@ -1084,10 +1150,35 @@ function surplus(a, b) {
|
|
|
1084
1150
|
function list(items) {
|
|
1085
1151
|
return items.length > 1 ? `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}` : items[0];
|
|
1086
1152
|
}
|
|
1087
|
-
const ESCAPED_SYNTAX = /(?<!\{)\{\{\s*[\w.]
|
|
1153
|
+
const ESCAPED_SYNTAX = /(?<!\{)\{\{\s*([\w.]+)(\s*[|:][^{}]*)\}\}/;
|
|
1154
|
+
const ESCAPED_ICU = /(?<!\{)\{\{\s*([\w.]+)\s*,\s*(plural|selectordinal|select|number|date|time)\b/;
|
|
1155
|
+
const ICU_SLICE = /^\{\{([\w.]+), (\w+), …\}\}$/;
|
|
1156
|
+
const ESCAPED_OPEN = /(?<!\{)\{\{\{([\w.]+)\}(\s*\|\s*[^\s|{}:]+\s*:|:[A-Za-z_][\w-]*)/;
|
|
1088
1157
|
function escapedSyntax(message) {
|
|
1158
|
+
const icu = ESCAPED_ICU.exec(message);
|
|
1159
|
+
if (icu) return `{{${icu[1]}, ${icu[2]}, …}}`;
|
|
1160
|
+
const open = ESCAPED_OPEN.exec(message);
|
|
1161
|
+
if (open) return `{\${${open[1]}}${open[2]}…`;
|
|
1089
1162
|
return ESCAPED_SYNTAX.exec(message)?.[0];
|
|
1090
1163
|
}
|
|
1164
|
+
function shownSlice(slice) {
|
|
1165
|
+
return slice.startsWith("{{") ? slice.slice(1, -1) : slice;
|
|
1166
|
+
}
|
|
1167
|
+
function inlineBlock(slice) {
|
|
1168
|
+
if (slice.startsWith("{${")) return "the same block with its closing }";
|
|
1169
|
+
const icu = ICU_SLICE.exec(slice);
|
|
1170
|
+
if (icu) {
|
|
1171
|
+
const [, name = "", type = ""] = icu;
|
|
1172
|
+
if (type === "plural") return `{\${${name}} | one: … | other: …}`;
|
|
1173
|
+
if (type === "select") return `{\${${name}} | …: … | other: …}`;
|
|
1174
|
+
if (type === "selectordinal") return "t(key, params), with the ICU message in the catalog";
|
|
1175
|
+
return `{\${${name}}:${type}}`;
|
|
1176
|
+
}
|
|
1177
|
+
const match = ESCAPED_SYNTAX.exec(slice);
|
|
1178
|
+
if (!match) return slice;
|
|
1179
|
+
const [, name = "", tail = ""] = match;
|
|
1180
|
+
return `{\${${name}}${tail.trimStart().startsWith(":") ? `:${tail.trimStart().slice(1).trimStart()}` : tail}}`;
|
|
1181
|
+
}
|
|
1091
1182
|
function validateMessage(message, locale) {
|
|
1092
1183
|
const issues = [];
|
|
1093
1184
|
for (const [name, shape] of shapes(message)) {
|
|
@@ -1632,11 +1723,12 @@ function formatFinding(finding, root) {
|
|
|
1632
1723
|
const names = finding.params.map((name) => `{${name}}`).join(", ");
|
|
1633
1724
|
return `${sourcePlace(finding.site, root)}: ${names} in "${truncate(finding.site.message, 60)}" reaches the translator without a name, put the value in a named variable first`;
|
|
1634
1725
|
}
|
|
1635
|
-
case "escaped": return `${sourcePlace(finding.site, root)}: ${finding.slice} renders as literal text
|
|
1726
|
+
case "escaped": return `${sourcePlace(finding.site, root)}: ${shownSlice(finding.slice)} renders as literal text: write ${inlineBlock(finding.slice)}`;
|
|
1636
1727
|
case "unparsed": return `${sourcePlace(finding, root)}: could not be parsed (${finding.message}), its messages were not extracted`;
|
|
1637
1728
|
case "outdated": return `[${finding.locale}] ${finding.key}: translated from an older source text, update it or keep it with \`npx verbaly review --approve\``;
|
|
1638
1729
|
case "lock": {
|
|
1639
1730
|
const lock = sourcePlace(finding, root);
|
|
1731
|
+
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`;
|
|
1640
1732
|
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`;
|
|
1641
1733
|
}
|
|
1642
1734
|
}
|
|
@@ -1650,7 +1742,7 @@ function findingId(finding) {
|
|
|
1650
1742
|
case "positional": return `positional:${finding.site.file}:${finding.params.join(",")}`;
|
|
1651
1743
|
case "escaped": return `escaped:${finding.site.file}:${finding.slice}`;
|
|
1652
1744
|
case "unparsed": return `unparsed:${finding.file}`;
|
|
1653
|
-
case "lock": return `lock:${finding.file}`;
|
|
1745
|
+
case "lock": return `lock:${finding.merged ? "merged:" : ""}${finding.file}`;
|
|
1654
1746
|
}
|
|
1655
1747
|
}
|
|
1656
1748
|
function createDevReporter(root, print = (line) => console.warn(`[verbaly] ${line}`), cap = 5) {
|
|
@@ -1677,6 +1769,7 @@ const LOCK_VERSION = 1;
|
|
|
1677
1769
|
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.";
|
|
1678
1770
|
const LEGACY_STATE_FILE = ".verbaly-state.json";
|
|
1679
1771
|
const LEGACY_DRAFTS_FILE = ".verbaly-drafts.json";
|
|
1772
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
1680
1773
|
function statePath(cfg) {
|
|
1681
1774
|
return join(cfg.root, STATE_FILE);
|
|
1682
1775
|
}
|
|
@@ -1684,31 +1777,51 @@ function legacyPaths(cfg) {
|
|
|
1684
1777
|
return [join(cfg.dir, LEGACY_STATE_FILE), join(cfg.dir, LEGACY_DRAFTS_FILE)];
|
|
1685
1778
|
}
|
|
1686
1779
|
function loadState(cfg) {
|
|
1687
|
-
const lock =
|
|
1688
|
-
|
|
1689
|
-
const [legacyState, legacyDrafts] = legacyPaths(cfg).map(
|
|
1780
|
+
const lock = readSides(statePath(cfg)) ?? [];
|
|
1781
|
+
for (const side of lock) checkVersion(statePath(cfg), side.version);
|
|
1782
|
+
const [legacyState = [], legacyDrafts = []] = legacyPaths(cfg).map((path) => readSides(path) ?? []);
|
|
1690
1783
|
const state = {
|
|
1691
1784
|
drafts: {},
|
|
1692
1785
|
fingerprints: {}
|
|
1693
1786
|
};
|
|
1694
|
-
|
|
1695
|
-
|
|
1787
|
+
const kept = lock.length > 1 ? keptStamp(cfg) : void 0;
|
|
1788
|
+
[...lock, ...legacyState].forEach((source, index) => {
|
|
1696
1789
|
for (const [locale, keys] of Object.entries(readDrafts(source.drafts))) markDrafts(state.drafts, locale, keys);
|
|
1697
1790
|
for (const [locale, stamps] of Object.entries(readFingerprints(source.fingerprints))) {
|
|
1698
1791
|
const into = state.fingerprints[locale] ??= emptyCatalog();
|
|
1699
|
-
for (const [key, stamped] of Object.entries(stamps))
|
|
1792
|
+
for (const [key, stamped] of Object.entries(stamps)) {
|
|
1793
|
+
const held = own(into, key);
|
|
1794
|
+
if (held === void 0) into[key] = stamped;
|
|
1795
|
+
else if (index < lock.length && held !== stamped && kept?.(locale, key, stamped)) into[key] = stamped;
|
|
1796
|
+
}
|
|
1700
1797
|
}
|
|
1701
1798
|
const migrated = readMigrated(source.migrated);
|
|
1702
1799
|
if (migrated) state.migrated = [.../* @__PURE__ */ new Set([...state.migrated ?? [], ...migrated])];
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1800
|
+
});
|
|
1801
|
+
for (const side of legacyDrafts) for (const [locale, keys] of Object.entries(readDrafts(side))) markDrafts(state.drafts, locale, keys);
|
|
1705
1802
|
return state;
|
|
1706
1803
|
}
|
|
1804
|
+
function keptStamp(cfg) {
|
|
1805
|
+
const read = /* @__PURE__ */ new Map();
|
|
1806
|
+
return (locale, key, stamped) => {
|
|
1807
|
+
if (!read.has(locale)) try {
|
|
1808
|
+
read.set(locale, readCatalog(cfg, locale));
|
|
1809
|
+
} catch {
|
|
1810
|
+
read.set(locale, void 0);
|
|
1811
|
+
}
|
|
1812
|
+
const translated = own(read.get(locale) ?? {}, key);
|
|
1813
|
+
return translated !== void 0 && translationOf(stamped) === fingerprint(translated);
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1707
1816
|
function stateFile(cfg) {
|
|
1708
1817
|
return [statePath(cfg), ...legacyPaths(cfg)].find((path) => existsSync(path));
|
|
1709
1818
|
}
|
|
1710
1819
|
function lockNews(cfg, before) {
|
|
1711
1820
|
const lock = statePath(cfg);
|
|
1821
|
+
if (resolved.delete(lock)) return {
|
|
1822
|
+
file: lock,
|
|
1823
|
+
merged: true
|
|
1824
|
+
};
|
|
1712
1825
|
if (before === lock || !existsSync(lock)) return void 0;
|
|
1713
1826
|
return before ? {
|
|
1714
1827
|
file: lock,
|
|
@@ -1719,15 +1832,20 @@ function checkVersion(path, version) {
|
|
|
1719
1832
|
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`);
|
|
1720
1833
|
}
|
|
1721
1834
|
function readState(cfg) {
|
|
1835
|
+
const marked = (readText(statePath(cfg))?.split(/\r?\n/) ?? []).some((line) => CONFLICT.start.test(line)) ? { conflict: true } : {};
|
|
1722
1836
|
try {
|
|
1723
|
-
return {
|
|
1837
|
+
return {
|
|
1838
|
+
state: loadState(cfg),
|
|
1839
|
+
...marked
|
|
1840
|
+
};
|
|
1724
1841
|
} catch (error) {
|
|
1725
1842
|
return {
|
|
1726
1843
|
state: {
|
|
1727
1844
|
drafts: {},
|
|
1728
1845
|
fingerprints: {}
|
|
1729
1846
|
},
|
|
1730
|
-
problem: error.message.replace(/^\[verbaly\] /, "")
|
|
1847
|
+
problem: error.message.replace(/^\[verbaly\] /, ""),
|
|
1848
|
+
...marked
|
|
1731
1849
|
};
|
|
1732
1850
|
}
|
|
1733
1851
|
}
|
|
@@ -1742,7 +1860,10 @@ function saveState(cfg, state) {
|
|
|
1742
1860
|
const existing = readText(path);
|
|
1743
1861
|
if (existing === void 0) mkdirSync(cfg.root, { recursive: true });
|
|
1744
1862
|
const serialized = withLineEndings(fresh, existing ?? legacy.map(readText).find((text) => text !== void 0));
|
|
1745
|
-
if (existing !== serialized)
|
|
1863
|
+
if (existing !== serialized) {
|
|
1864
|
+
if (existing !== void 0 && conflictSides(existing)) resolved.add(path);
|
|
1865
|
+
writeFileSync(path, serialized);
|
|
1866
|
+
}
|
|
1746
1867
|
for (const file of legacy) rmSync(file, { force: true });
|
|
1747
1868
|
}
|
|
1748
1869
|
function readText(path) {
|
|
@@ -1899,20 +2020,47 @@ function serializeState(state) {
|
|
|
1899
2020
|
if (migrated.length) out.migrated = migrated;
|
|
1900
2021
|
return JSON.stringify(out, null, 2) + "\n";
|
|
1901
2022
|
}
|
|
1902
|
-
function
|
|
2023
|
+
function readSides(path) {
|
|
1903
2024
|
const content = readText(path);
|
|
1904
2025
|
if (content === void 0) return void 0;
|
|
2026
|
+
const body = content.charCodeAt(0) === 65279 ? content.slice(1) : content;
|
|
2027
|
+
const sides = conflictSides(body);
|
|
2028
|
+
return (sides ?? [body]).map((text) => parseObject(path, text, sides !== void 0));
|
|
2029
|
+
}
|
|
2030
|
+
function parseObject(path, text, conflicted) {
|
|
1905
2031
|
let value;
|
|
1906
2032
|
try {
|
|
1907
|
-
value = JSON.parse(
|
|
2033
|
+
value = JSON.parse(text);
|
|
1908
2034
|
} catch (error) {
|
|
1909
|
-
throw corrupt(path, error);
|
|
2035
|
+
throw corrupt(path, conflicted, error);
|
|
1910
2036
|
}
|
|
1911
|
-
if (!isObject(value)) throw corrupt(path);
|
|
2037
|
+
if (!isObject(value)) throw corrupt(path, conflicted);
|
|
1912
2038
|
return value;
|
|
1913
2039
|
}
|
|
1914
|
-
|
|
1915
|
-
|
|
2040
|
+
const CONFLICT = {
|
|
2041
|
+
start: /^<{7}(?: |$)/,
|
|
2042
|
+
base: /^\|{7}(?: |$)/,
|
|
2043
|
+
split: /^={7}$/,
|
|
2044
|
+
end: /^>{7}(?: |$)/
|
|
2045
|
+
};
|
|
2046
|
+
function conflictSides(text) {
|
|
2047
|
+
const lines = text.split(/\r?\n/);
|
|
2048
|
+
if (!lines.some((line) => CONFLICT.start.test(line))) return void 0;
|
|
2049
|
+
const ours = [];
|
|
2050
|
+
const theirs = [];
|
|
2051
|
+
let at = "both";
|
|
2052
|
+
for (const line of lines) if (at === "both" && CONFLICT.start.test(line)) at = "ours";
|
|
2053
|
+
else if (at === "ours" && CONFLICT.base.test(line)) at = "base";
|
|
2054
|
+
else if ((at === "ours" || at === "base") && CONFLICT.split.test(line)) at = "theirs";
|
|
2055
|
+
else if (at === "theirs" && CONFLICT.end.test(line)) at = "both";
|
|
2056
|
+
else if (at !== "base") {
|
|
2057
|
+
if (at !== "theirs") ours.push(line);
|
|
2058
|
+
if (at !== "ours") theirs.push(line);
|
|
2059
|
+
}
|
|
2060
|
+
return at === "both" ? [ours.join("\n"), theirs.join("\n")] : void 0;
|
|
2061
|
+
}
|
|
2062
|
+
function corrupt(path, conflicted, cause) {
|
|
2063
|
+
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 });
|
|
1916
2064
|
}
|
|
1917
2065
|
function isObject(value) {
|
|
1918
2066
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -2385,8 +2533,8 @@ function createSourceFilter(cfg) {
|
|
|
2385
2533
|
return !rel.startsWith("..") && matches(rel);
|
|
2386
2534
|
};
|
|
2387
2535
|
}
|
|
2388
|
-
function transformSource(code, id, registry) {
|
|
2389
|
-
const analysis = analyzeFile(code, id);
|
|
2536
|
+
function transformSource(code, id, registry, scan) {
|
|
2537
|
+
const analysis = (scan && scannedAnalysis(scan, id, code)) ?? analyzeFile(code, id);
|
|
2390
2538
|
registry.update(id, analysis);
|
|
2391
2539
|
if (analysis.parseError) warnParseError(id, analysis.parseError);
|
|
2392
2540
|
const messages = emptyCatalog();
|
|
@@ -2728,7 +2876,7 @@ async function doctor(cfg) {
|
|
|
2728
2876
|
file: rel(msg.file),
|
|
2729
2877
|
slice: escapedSyntax(msg.message)
|
|
2730
2878
|
})).filter((entry) => entry.slice !== void 0);
|
|
2731
|
-
if (escaped.length > 0) warn("messages", `a block ships as literal text in ${counted(escaped.length, "extracted message")} (${escaped[0].file}: ${escaped[0].slice})`,
|
|
2879
|
+
if (escaped.length > 0) warn("messages", `a block ships as literal text in ${counted(escaped.length, "extracted message")} (${escaped[0].file}: ${shownSlice(escaped[0].slice)})`, `in a tagged template, write ${inlineBlock(escaped[0].slice)}`);
|
|
2732
2880
|
}
|
|
2733
2881
|
if (source && scanning) {
|
|
2734
2882
|
const extracted = registry.messages();
|
|
@@ -2744,8 +2892,9 @@ async function doctor(cfg) {
|
|
|
2744
2892
|
for (const issue of issues) warn("bundle", formatBundleIssue(issue), issue.fix);
|
|
2745
2893
|
if (issues.length === 0) ok("bundle", `${counted(excluded.length, "group")} kept out of the client (${preview(excluded)})`);
|
|
2746
2894
|
}
|
|
2747
|
-
const { state, problem } = readState(cfg);
|
|
2748
|
-
if (problem) warn("state", problem, `restore ${STATE_FILE} from git: deleting it would mark every machine draft as reviewed`);
|
|
2895
|
+
const { state, problem, conflict } = readState(cfg);
|
|
2896
|
+
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`);
|
|
2897
|
+
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");
|
|
2749
2898
|
if (catalogsHealthy) {
|
|
2750
2899
|
const stale = Object.entries(state.drafts).flatMap(([locale, keys]) => {
|
|
2751
2900
|
const live = new Set(effectiveDrafts({ [locale]: keys }, catalogs)[locale] ?? []);
|
|
@@ -2974,7 +3123,7 @@ function formatTranslateFailures(failed) {
|
|
|
2974
3123
|
async function resolveProvider(cfg, model) {
|
|
2975
3124
|
const configured = cfg.translate.provider;
|
|
2976
3125
|
if (typeof configured === "function") return configured;
|
|
2977
|
-
const { claudeProvider } = await import("./claude-
|
|
3126
|
+
const { claudeProvider } = await import("./claude-Baoc6pYL.js");
|
|
2978
3127
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
2979
3128
|
}
|
|
2980
3129
|
function structureMatches(source, translated) {
|