@verbaly/compiler 0.69.0 → 0.70.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 +32 -9
- package/dist/{claude-mvcniUPN.js → claude-CusgBHrv.js} +2 -2
- package/dist/{claude-mvcniUPN.js.map → claude-CusgBHrv.js.map} +1 -1
- package/dist/cli.js +489 -368
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +194 -47
- package/dist/index.js.map +1 -1
- package/dist/{text-Bh96y7ik.js → text-dwjJ8ZDb.js} +7 -2
- package/dist/text-dwjJ8ZDb.js.map +1 -0
- package/package.json +2 -2
- package/dist/text-Bh96y7ik.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -234,6 +234,7 @@ type Fingerprints = Record<string, Record<string, string>>;
|
|
|
234
234
|
interface State {
|
|
235
235
|
drafts: Drafts;
|
|
236
236
|
fingerprints: Fingerprints;
|
|
237
|
+
migrated?: string[];
|
|
237
238
|
}
|
|
238
239
|
interface OutdatedEntry {
|
|
239
240
|
locale: string;
|
|
@@ -492,6 +493,7 @@ interface DoctorResult {
|
|
|
492
493
|
entries: DoctorEntry[];
|
|
493
494
|
}
|
|
494
495
|
export declare function formatDoctorEntry(entry: DoctorEntry): string;
|
|
496
|
+
export declare function formatDoctorHealth(result: DoctorResult): string;
|
|
495
497
|
export declare function doctor(cfg: ResolvedConfig): Promise<DoctorResult>;
|
|
496
498
|
//#endregion
|
|
497
499
|
//#region src/host.d.ts
|
|
@@ -515,6 +517,7 @@ interface InitResult {
|
|
|
515
517
|
to: string;
|
|
516
518
|
}[];
|
|
517
519
|
refused: string[];
|
|
520
|
+
found?: string;
|
|
518
521
|
}
|
|
519
522
|
export declare function init(input?: InitOptions): Promise<InitResult>;
|
|
520
523
|
//#endregion
|
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-dwjJ8ZDb.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";
|
|
@@ -356,7 +356,10 @@ function analyzeScript(code, file, options = {}) {
|
|
|
356
356
|
return;
|
|
357
357
|
}
|
|
358
358
|
const key = staticString(args[0]);
|
|
359
|
-
if (key !== void 0) usedKeys.push(
|
|
359
|
+
if (key !== void 0) usedKeys.push({
|
|
360
|
+
key,
|
|
361
|
+
file
|
|
362
|
+
});
|
|
360
363
|
} else if (node.type === "JSXElement") handleTrans(code, node, file, tagged, usedKeys, names);
|
|
361
364
|
});
|
|
362
365
|
const renamed = bindings.renamed(options.renamed);
|
|
@@ -365,8 +368,7 @@ function analyzeScript(code, file, options = {}) {
|
|
|
365
368
|
if (candidate.kind === "call") {
|
|
366
369
|
if (renamed.has(candidate.name)) usedKeys.push({
|
|
367
370
|
key: candidate.key,
|
|
368
|
-
file
|
|
369
|
-
loose: true
|
|
371
|
+
file
|
|
370
372
|
});
|
|
371
373
|
continue;
|
|
372
374
|
}
|
|
@@ -508,8 +510,7 @@ function missedKey(code, node, names) {
|
|
|
508
510
|
const tag = node.tag;
|
|
509
511
|
if (tag.type === "CallExpression") {
|
|
510
512
|
const args = tag.arguments;
|
|
511
|
-
|
|
512
|
-
return args.length === 1 && first?.type === "StringLiteral" ? first.value : void 0;
|
|
513
|
+
return args.length === 1 ? staticString(args[0]) : void 0;
|
|
513
514
|
}
|
|
514
515
|
const message = buildMessage(code, node.quasi, names);
|
|
515
516
|
return message ? stableKey(message.text) : void 0;
|
|
@@ -521,20 +522,13 @@ function collectDeclaredKeys(node, file, out) {
|
|
|
521
522
|
const value = property.value;
|
|
522
523
|
const key = staticString(value);
|
|
523
524
|
if (key !== void 0) {
|
|
524
|
-
if (key !== "") out.push(
|
|
525
|
+
if (key !== "") out.push({
|
|
526
|
+
key,
|
|
527
|
+
file
|
|
528
|
+
});
|
|
525
529
|
} else if (value.type === "ObjectExpression") collectDeclaredKeys(value, file, out);
|
|
526
530
|
}
|
|
527
531
|
}
|
|
528
|
-
function usedKey(key, file, node) {
|
|
529
|
-
return node?.type === "StringLiteral" ? {
|
|
530
|
-
key,
|
|
531
|
-
file
|
|
532
|
-
} : {
|
|
533
|
-
key,
|
|
534
|
-
file,
|
|
535
|
-
loose: true
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
532
|
function staticString(node) {
|
|
539
533
|
if (!node) return void 0;
|
|
540
534
|
if (node.type === "StringLiteral") return node.value;
|
|
@@ -583,14 +577,17 @@ function handleTrans(code, node, file, tagged, usedKeys, names) {
|
|
|
583
577
|
const value = idAttr.value;
|
|
584
578
|
const id = staticString(value);
|
|
585
579
|
if (id === void 0) return;
|
|
586
|
-
if (
|
|
580
|
+
if (attrs.length === 1 && children?.length) {
|
|
587
581
|
const built = buildTransMessage(code, children, names);
|
|
588
582
|
if (built?.text.trim()) {
|
|
589
583
|
push(id, built);
|
|
590
584
|
return;
|
|
591
585
|
}
|
|
592
586
|
}
|
|
593
|
-
usedKeys.push(
|
|
587
|
+
usedKeys.push({
|
|
588
|
+
key: id,
|
|
589
|
+
file
|
|
590
|
+
});
|
|
594
591
|
return;
|
|
595
592
|
}
|
|
596
593
|
if (attrs.length > 0) return;
|
|
@@ -608,10 +605,10 @@ function explicitId(tag, names) {
|
|
|
608
605
|
const obj = callee.object;
|
|
609
606
|
if (!isTReference(obj, names)) return void 0;
|
|
610
607
|
const args = tag.arguments;
|
|
611
|
-
const
|
|
612
|
-
if (
|
|
608
|
+
const key = args.length === 1 ? staticString(args[0]) : void 0;
|
|
609
|
+
if (key === void 0) return void 0;
|
|
613
610
|
return {
|
|
614
|
-
key
|
|
611
|
+
key,
|
|
615
612
|
refStart: obj.start,
|
|
616
613
|
refEnd: obj.end
|
|
617
614
|
};
|
|
@@ -1389,6 +1386,9 @@ export async function createRequestInstance(locale) {
|
|
|
1389
1386
|
|
|
1390
1387
|
const v = createInstance();
|
|
1391
1388
|
|
|
1389
|
+
// a hook with no provider above it (a test, a story) reads this one; a server never registers it
|
|
1390
|
+
if (typeof document !== 'undefined') globalThis[Symbol.for('verbaly.app')] = v;
|
|
1391
|
+
|
|
1392
1392
|
export const verbaly = v;
|
|
1393
1393
|
export const t = v.t;
|
|
1394
1394
|
|
|
@@ -1421,6 +1421,9 @@ function generateDts(catalog, options = {}) {
|
|
|
1421
1421
|
}
|
|
1422
1422
|
}
|
|
1423
1423
|
return `${DTS_HEADER}
|
|
1424
|
+
// biome-ignore-all lint: generated by verbaly
|
|
1425
|
+
// biome-ignore-all format: generated by verbaly
|
|
1426
|
+
// prettier-ignore
|
|
1424
1427
|
declare module 'virtual:verbaly' {
|
|
1425
1428
|
export interface VerbalyMessages {
|
|
1426
1429
|
${lines.join("\n")}
|
|
@@ -1450,17 +1453,28 @@ ${lines.join("\n")}
|
|
|
1450
1453
|
): import('verbaly').Verbaly;
|
|
1451
1454
|
export function createRequestInstance(locale: string): Promise<import('verbaly').Verbaly>;
|
|
1452
1455
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1456
|
+
// a literal key must exist; a string, a template with data in it or a union of keys is data
|
|
1457
|
+
export const t: {
|
|
1458
|
+
<K extends VerbalyKey | TemplateStringsArray | (string & {})>(
|
|
1459
|
+
first: K extends TemplateStringsArray
|
|
1460
|
+
? K
|
|
1461
|
+
: {} extends Record<K & string, 1>
|
|
1462
|
+
? K
|
|
1463
|
+
: K extends VerbalyKey ? K : VerbalyKey,
|
|
1464
|
+
...rest: [K] extends [never]
|
|
1465
|
+
? [params?: import('verbaly').Params]
|
|
1466
|
+
: [K] extends [(K extends unknown ? (key: K) => void : never) extends (key: infer One) => void ? One : never]
|
|
1467
|
+
? K extends TemplateStringsArray
|
|
1468
|
+
? unknown[]
|
|
1469
|
+
: {} extends Record<K & string, 1>
|
|
1470
|
+
? [params?: import('verbaly').Params]
|
|
1471
|
+
: K extends VerbalyKey
|
|
1472
|
+
? [VerbalyMessages[K]] extends [never] ? [] : [VerbalyMessages[K]]
|
|
1473
|
+
: unknown[]
|
|
1474
|
+
: [params?: import('verbaly').Params]
|
|
1475
|
+
): string;
|
|
1476
|
+
id(key: string): (strings: TemplateStringsArray, ...values: unknown[]) => string;
|
|
1477
|
+
};
|
|
1464
1478
|
|
|
1465
1479
|
export function setLocale(locale: string): Promise<void>;
|
|
1466
1480
|
export function switchLocale(
|
|
@@ -1482,6 +1496,7 @@ ${lines.join("\n")}
|
|
|
1482
1496
|
}
|
|
1483
1497
|
}
|
|
1484
1498
|
|
|
1499
|
+
// prettier-ignore
|
|
1485
1500
|
declare module 'virtual:verbaly/locale/*' {
|
|
1486
1501
|
const messages: Record<string, string>;
|
|
1487
1502
|
export default messages;
|
|
@@ -1664,7 +1679,8 @@ function loadState(cfg) {
|
|
|
1664
1679
|
if (legacy !== void 0 && !isObject(legacy)) throw corrupt(statePath(cfg, LEGACY_DRAFTS_FILE));
|
|
1665
1680
|
const state = isObject(current) ? {
|
|
1666
1681
|
drafts: readDrafts(current.drafts),
|
|
1667
|
-
fingerprints: readFingerprints(current.fingerprints)
|
|
1682
|
+
fingerprints: readFingerprints(current.fingerprints),
|
|
1683
|
+
migrated: readMigrated(current.migrated)
|
|
1668
1684
|
} : {
|
|
1669
1685
|
drafts: {},
|
|
1670
1686
|
fingerprints: {}
|
|
@@ -1730,7 +1746,8 @@ function refreshState(cfg, catalogs, previous) {
|
|
|
1730
1746
|
}
|
|
1731
1747
|
return {
|
|
1732
1748
|
drafts,
|
|
1733
|
-
fingerprints
|
|
1749
|
+
fingerprints,
|
|
1750
|
+
migrated: previous.migrated
|
|
1734
1751
|
};
|
|
1735
1752
|
}
|
|
1736
1753
|
function refreshStamps(source, catalog, before) {
|
|
@@ -1839,10 +1856,12 @@ function serializeState(state) {
|
|
|
1839
1856
|
if (!keys.length) continue;
|
|
1840
1857
|
fingerprints[locale] = Object.fromEntries(keys.map((key) => [key, entries[key]]));
|
|
1841
1858
|
}
|
|
1859
|
+
const migrated = [...new Set(state.migrated ?? [])].sort();
|
|
1842
1860
|
const out = {};
|
|
1843
1861
|
if (Object.keys(drafts).length) out.drafts = drafts;
|
|
1844
1862
|
if (Object.keys(fingerprints).length) out.fingerprints = fingerprints;
|
|
1845
|
-
if (
|
|
1863
|
+
if (migrated.length) out.migrated = migrated;
|
|
1864
|
+
if (!out.drafts && !out.fingerprints && !out.migrated) return void 0;
|
|
1846
1865
|
return JSON.stringify(out, null, 2) + "\n";
|
|
1847
1866
|
}
|
|
1848
1867
|
function readJson(path) {
|
|
@@ -1870,6 +1889,11 @@ function readDrafts(value) {
|
|
|
1870
1889
|
for (const [locale, keys] of Object.entries(value)) if (Array.isArray(keys)) out[locale] = keys.filter((key) => typeof key === "string");
|
|
1871
1890
|
return out;
|
|
1872
1891
|
}
|
|
1892
|
+
function readMigrated(value) {
|
|
1893
|
+
if (!Array.isArray(value)) return void 0;
|
|
1894
|
+
const locales = value.filter((locale) => typeof locale === "string");
|
|
1895
|
+
return locales.length ? locales : void 0;
|
|
1896
|
+
}
|
|
1873
1897
|
function readFingerprints(value) {
|
|
1874
1898
|
const out = {};
|
|
1875
1899
|
if (!isObject(value)) return out;
|
|
@@ -1931,6 +1955,42 @@ function confirmFromDisk(cfg, catalogs, registry) {
|
|
|
1931
1955
|
}
|
|
1932
1956
|
}
|
|
1933
1957
|
//#endregion
|
|
1958
|
+
//#region src/migrate.ts
|
|
1959
|
+
const KNOWN = [
|
|
1960
|
+
"i18next",
|
|
1961
|
+
"react-i18next",
|
|
1962
|
+
"vue-i18n",
|
|
1963
|
+
"react-intl",
|
|
1964
|
+
"next-intl",
|
|
1965
|
+
"svelte-i18n"
|
|
1966
|
+
];
|
|
1967
|
+
function detectLibraries(root) {
|
|
1968
|
+
const path = join(root, "package.json");
|
|
1969
|
+
if (!existsSync(path)) return [];
|
|
1970
|
+
let manifest;
|
|
1971
|
+
try {
|
|
1972
|
+
manifest = JSON.parse(readFileSync(path, "utf8"));
|
|
1973
|
+
} catch {
|
|
1974
|
+
return [];
|
|
1975
|
+
}
|
|
1976
|
+
const deps = {
|
|
1977
|
+
...manifest.dependencies,
|
|
1978
|
+
...manifest.devDependencies
|
|
1979
|
+
};
|
|
1980
|
+
return KNOWN.filter((name) => deps[name] !== void 0);
|
|
1981
|
+
}
|
|
1982
|
+
const PLAIN = /\{\{\s*([A-Za-z_$][\w$]*)\s*\}\}/g;
|
|
1983
|
+
new RegExp(/\{\{[^{}]*\}\}/.source, "g");
|
|
1984
|
+
new RegExp(`^${PLAIN.source}$`);
|
|
1985
|
+
new RegExp(`^(.*)_(${[...[
|
|
1986
|
+
"zero",
|
|
1987
|
+
"one",
|
|
1988
|
+
"two",
|
|
1989
|
+
"few",
|
|
1990
|
+
"many",
|
|
1991
|
+
"other"
|
|
1992
|
+
], "plural"].join("|")})$`);
|
|
1993
|
+
//#endregion
|
|
1934
1994
|
//#region src/tag.ts
|
|
1935
1995
|
function isLocaleTag(tag) {
|
|
1936
1996
|
try {
|
|
@@ -1946,6 +2006,27 @@ function suggestTag(tag) {
|
|
|
1946
2006
|
}
|
|
1947
2007
|
//#endregion
|
|
1948
2008
|
//#region src/init.ts
|
|
2009
|
+
const CATALOG_DIRS = [
|
|
2010
|
+
"locales",
|
|
2011
|
+
"src/locales",
|
|
2012
|
+
"src/i18n/locales",
|
|
2013
|
+
"src/i18n",
|
|
2014
|
+
"i18n",
|
|
2015
|
+
"lang",
|
|
2016
|
+
"src/lang",
|
|
2017
|
+
"translations",
|
|
2018
|
+
"src/translations",
|
|
2019
|
+
"messages"
|
|
2020
|
+
];
|
|
2021
|
+
function existingCatalogs(root) {
|
|
2022
|
+
return CATALOG_DIRS.find((dir) => {
|
|
2023
|
+
try {
|
|
2024
|
+
return readdirSync(join(root, dir)).some((file) => file.endsWith(".json") && isLocaleTag(file.slice(0, -5)));
|
|
2025
|
+
} catch {
|
|
2026
|
+
return false;
|
|
2027
|
+
}
|
|
2028
|
+
});
|
|
2029
|
+
}
|
|
1949
2030
|
function cliReachable(root) {
|
|
1950
2031
|
const bin = join(root, "node_modules", ".bin");
|
|
1951
2032
|
return existsSync(join(bin, "verbaly")) || existsSync(join(bin, "verbaly.CMD"));
|
|
@@ -1994,14 +2075,19 @@ async function init(input = {}) {
|
|
|
1994
2075
|
const existing = findConfigFile(root);
|
|
1995
2076
|
const typescript = existsSync(join(root, "tsconfig.json"));
|
|
1996
2077
|
const configFile = existing ?? (typescript ? "verbaly.config.ts" : "verbaly.config.mjs");
|
|
2078
|
+
const found = existing || options.dir ? void 0 : existingCatalogs(root);
|
|
1997
2079
|
if (existing) skipped.push(existing);
|
|
1998
2080
|
else {
|
|
1999
|
-
|
|
2081
|
+
const dir = found === "locales" ? void 0 : found;
|
|
2082
|
+
writeFileSync(join(root, configFile), configSource({
|
|
2083
|
+
...options,
|
|
2084
|
+
dir: options.dir ?? dir
|
|
2085
|
+
}, typescript));
|
|
2000
2086
|
created.push(configFile);
|
|
2001
2087
|
}
|
|
2002
2088
|
const fromFile = existing ? await loadConfigFile(root) : {};
|
|
2003
2089
|
const scaffold = {
|
|
2004
|
-
dir: options.dir ?? fromFile.dir,
|
|
2090
|
+
dir: options.dir ?? fromFile.dir ?? found,
|
|
2005
2091
|
sourceLocale: options.sourceLocale ?? fromFile.sourceLocale,
|
|
2006
2092
|
locales: options.locales ?? fromFile.locales
|
|
2007
2093
|
};
|
|
@@ -2017,7 +2103,11 @@ async function init(input = {}) {
|
|
|
2017
2103
|
}
|
|
2018
2104
|
}
|
|
2019
2105
|
const host = detectHost(root);
|
|
2020
|
-
const
|
|
2106
|
+
const deps = readDependencies(root);
|
|
2107
|
+
const missing = host?.install.filter((pkg) => !deps[pkg]) ?? [];
|
|
2108
|
+
const next = host ? [...missing.length ? [installCommand(root, missing)] : [], host.wire] : ["run \"verbaly extract\" after writing your first t`…` message"];
|
|
2109
|
+
const others = detectLibraries(root);
|
|
2110
|
+
if (found && others.length) next.push(`port the ${others.join(" and ")} catalogs: npx verbaly migrate reports, --write applies`);
|
|
2021
2111
|
return {
|
|
2022
2112
|
created,
|
|
2023
2113
|
skipped,
|
|
@@ -2025,7 +2115,8 @@ async function init(input = {}) {
|
|
|
2025
2115
|
configFile,
|
|
2026
2116
|
next,
|
|
2027
2117
|
renamed,
|
|
2028
|
-
refused
|
|
2118
|
+
refused,
|
|
2119
|
+
found
|
|
2029
2120
|
};
|
|
2030
2121
|
}
|
|
2031
2122
|
//#endregion
|
|
@@ -2140,6 +2231,32 @@ function formatCheckResult(result, root) {
|
|
|
2140
2231
|
}
|
|
2141
2232
|
return lines.join("\n");
|
|
2142
2233
|
}
|
|
2234
|
+
function formatBuildReport(result, sourceLocale, root, cap = 5) {
|
|
2235
|
+
const show = (file) => root ? relative(root, file).replaceAll("\\", "/") : file;
|
|
2236
|
+
const lines = [];
|
|
2237
|
+
const list = (entries, line) => {
|
|
2238
|
+
for (const entry of entries.slice(0, cap)) lines.push(` ${line(entry)}`);
|
|
2239
|
+
if (entries.length > cap) lines.push(` and ${entries.length - cap} more`);
|
|
2240
|
+
};
|
|
2241
|
+
const broken = result.broken.filter((entry) => entry.severity === "error");
|
|
2242
|
+
if (broken.length > 0) {
|
|
2243
|
+
lines.push(`✗ the build goes on with ${counted(broken.length, "broken translation")}, each rendering differently from its source:`);
|
|
2244
|
+
list(broken, (entry) => `[${entry.locale}] ${entry.key}: ${entry.issue}`);
|
|
2245
|
+
}
|
|
2246
|
+
const quoted = (entry) => entry.source ? `: "${truncate(entry.source, 40)}"` : "";
|
|
2247
|
+
const untranslated = result.missing.filter((entry) => entry.locale !== sourceLocale);
|
|
2248
|
+
if (untranslated.length > 0) {
|
|
2249
|
+
lines.push(`⚠ the build goes on without ${counted(untranslated.length, "translation")}, shown in ${sourceLocale} instead:`);
|
|
2250
|
+
list(untranslated, (entry) => `[${entry.locale}] ${entry.key}${quoted(entry)}`);
|
|
2251
|
+
}
|
|
2252
|
+
if (result.unknown.length > 0) {
|
|
2253
|
+
lines.push(`⚠ the build goes on with ${counted(result.unknown.length, "key")} no catalog has, so the key itself shows:`);
|
|
2254
|
+
list(result.unknown, (entry) => `${entry.key} (used in ${entry.files.map(show).join(", ")})`);
|
|
2255
|
+
}
|
|
2256
|
+
const unsynced = result.missing.filter((entry) => entry.locale === sourceLocale);
|
|
2257
|
+
if (unsynced.length > 0) lines.push(`⚠ the build goes on with ${counted(unsynced.length, "text")} the ${sourceLocale} catalog does not have yet, taken from the code`);
|
|
2258
|
+
return lines;
|
|
2259
|
+
}
|
|
2143
2260
|
function checkNextSteps(result, cliReachable = true) {
|
|
2144
2261
|
const steps = [];
|
|
2145
2262
|
if (result.missing.length > 0) steps.push("missing: run `npx verbaly extract` to scaffold the keys, then fill them (or run `npx verbaly translate`)");
|
|
@@ -2236,14 +2353,39 @@ function runBuildGate(cfg, registry, failOnMissing) {
|
|
|
2236
2353
|
const catalogs = loadCatalogs(cfg);
|
|
2237
2354
|
for (const issue of auditBundle(cfg, catalogs, registry)) warnOnce(`${formatBundleIssue(issue)}\n fix: ${issue.fix}`, `bundle:${issue.prefix}`);
|
|
2238
2355
|
const found = check(cfg, catalogs, registry, buildFingerprints(cfg));
|
|
2356
|
+
if (failOnMissing === true && !gatePasses(found)) throw new Error(`[verbaly] build blocked\n${formatCheckResult(found, cfg.root)}\n${checkNextSteps(found, cliReachable(cfg.root))}`);
|
|
2357
|
+
reportGate(cfg, found);
|
|
2239
2358
|
const warnings = warningCount(found);
|
|
2240
2359
|
if (warnings > 0) warnOnce(`check has ${counted(warnings, "warning")}, and the build still passes: run \`npx verbaly check\` to read them`, "gate:warnings");
|
|
2241
|
-
|
|
2360
|
+
}
|
|
2361
|
+
const reported = /* @__PURE__ */ new Map();
|
|
2362
|
+
function reportGate(cfg, found) {
|
|
2363
|
+
const before = reported.get(cfg.root) ?? /* @__PURE__ */ new Set();
|
|
2364
|
+
const now = /* @__PURE__ */ new Set();
|
|
2365
|
+
const fresh = (entries, id) => entries.filter((entry) => {
|
|
2366
|
+
const key = id(entry);
|
|
2367
|
+
now.add(key);
|
|
2368
|
+
return !before.has(key);
|
|
2369
|
+
});
|
|
2370
|
+
const report = {
|
|
2371
|
+
broken: fresh(found.broken.filter((entry) => entry.severity === "error"), (entry) => `broken:${entry.locale}:${entry.key}:${entry.issue}`),
|
|
2372
|
+
missing: fresh(found.missing, (entry) => `missing:${entry.locale}:${entry.key}`),
|
|
2373
|
+
unknown: fresh(found.unknown, (entry) => `unknown:${entry.key}`)
|
|
2374
|
+
};
|
|
2375
|
+
reported.set(cfg.root, now);
|
|
2376
|
+
const lines = formatBuildReport(report, cfg.sourceLocale, cfg.root);
|
|
2377
|
+
if (lines.length === 0) return;
|
|
2378
|
+
const steps = checkNextSteps({
|
|
2242
2379
|
...found,
|
|
2243
|
-
|
|
2244
|
-
}
|
|
2245
|
-
|
|
2246
|
-
|
|
2380
|
+
...report
|
|
2381
|
+
}, cliReachable(cfg.root));
|
|
2382
|
+
const block = [
|
|
2383
|
+
...lines.map((line) => line.startsWith(" ") ? line : `[verbaly] ${line}`),
|
|
2384
|
+
"[verbaly] to fix them:",
|
|
2385
|
+
...steps.split("\n").map((step) => ` ${step}`),
|
|
2386
|
+
"[verbaly] `npx verbaly check` lists every one, and in your CI it stops a release on them"
|
|
2387
|
+
];
|
|
2388
|
+
console.warn(block.join("\n"));
|
|
2247
2389
|
}
|
|
2248
2390
|
function buildFingerprints(cfg) {
|
|
2249
2391
|
const { state, problem } = readState(cfg);
|
|
@@ -2403,6 +2545,11 @@ function formatDoctorEntry(entry) {
|
|
|
2403
2545
|
return entry.fix ? `${head}
|
|
2404
2546
|
fix: ${entry.fix}` : head;
|
|
2405
2547
|
}
|
|
2548
|
+
function formatDoctorHealth(result) {
|
|
2549
|
+
if (!result.ok) return "problems found";
|
|
2550
|
+
const warnings = result.entries.filter((entry) => entry.level === "warn").length;
|
|
2551
|
+
return warnings > 0 ? `setup works, with ${counted(warnings, "warning")} to read` : "setup looks healthy";
|
|
2552
|
+
}
|
|
2406
2553
|
async function doctor(cfg) {
|
|
2407
2554
|
const entries = [];
|
|
2408
2555
|
const ok = (name, message) => entries.push({
|
|
@@ -2779,7 +2926,7 @@ function formatTranslateFailures(failed) {
|
|
|
2779
2926
|
async function resolveProvider(cfg, model) {
|
|
2780
2927
|
const configured = cfg.translate.provider;
|
|
2781
2928
|
if (typeof configured === "function") return configured;
|
|
2782
|
-
const { claudeProvider } = await import("./claude-
|
|
2929
|
+
const { claudeProvider } = await import("./claude-CusgBHrv.js");
|
|
2783
2930
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
2784
2931
|
}
|
|
2785
2932
|
function structureMatches(source, translated) {
|
|
@@ -3581,6 +3728,6 @@ function formatCliError(error) {
|
|
|
3581
3728
|
return message.startsWith("[verbaly]") ? message : `[verbaly] ${message}`;
|
|
3582
3729
|
}
|
|
3583
3730
|
//#endregion
|
|
3584
|
-
export { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, STATE_FILE, check, clearDrafts, clientCatalogs, collectOrigins, collisionEntries, counted, createDevReporter, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatCliError, formatCollision, formatDoctorEntry, formatFinding, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, init, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadState, loadVirtualModule, markDrafts, mergeTranslations, needsIcu, needsRelative, outdatedTranslations, parseCatalog, pruneCatalogs, readCatalog, readState, recordTranslations, renderSite, reportOutsideInclude, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, shippedCatalogs, stableKey, status, syncCatalogs, syncProject, targetLocales, transformCode, transformSource, translateCatalogs, updateState, validateMessage, validatePair, watchTree, wrapProject, writeCatalog, writeDrafts, writeDts };
|
|
3731
|
+
export { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, STATE_FILE, check, clearDrafts, clientCatalogs, collectOrigins, collisionEntries, counted, createDevReporter, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatCliError, formatCollision, formatDoctorEntry, formatDoctorHealth, formatFinding, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, init, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadState, loadVirtualModule, markDrafts, mergeTranslations, needsIcu, needsRelative, outdatedTranslations, parseCatalog, pruneCatalogs, readCatalog, readState, recordTranslations, renderSite, reportOutsideInclude, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, shippedCatalogs, stableKey, status, syncCatalogs, syncProject, targetLocales, transformCode, transformSource, translateCatalogs, updateState, validateMessage, validatePair, watchTree, wrapProject, writeCatalog, writeDrafts, writeDts };
|
|
3585
3732
|
|
|
3586
3733
|
//# sourceMappingURL=index.js.map
|