@verbaly/compiler 0.69.1 → 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 +30 -8
- 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 +487 -377
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +192 -56
- 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,28 +1453,28 @@ ${lines.join("\n")}
|
|
|
1450
1453
|
): import('verbaly').Verbaly;
|
|
1451
1454
|
export function createRequestInstance(locale: string): Promise<import('verbaly').Verbaly>;
|
|
1452
1455
|
|
|
1453
|
-
// a key
|
|
1454
|
-
export
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
: {} extends Record<K & string, 1>
|
|
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
|
|
1458
1460
|
? K
|
|
1459
|
-
: K extends VerbalyKey ? K : VerbalyKey,
|
|
1460
|
-
...rest: [K] extends [never]
|
|
1461
|
-
? [params?: import('verbaly').Params]
|
|
1462
|
-
: K extends TemplateStringsArray
|
|
1463
|
-
? unknown[]
|
|
1464
1461
|
: {} extends Record<K & string, 1>
|
|
1465
|
-
?
|
|
1466
|
-
: K extends VerbalyKey
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
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
|
+
};
|
|
1475
1478
|
|
|
1476
1479
|
export function setLocale(locale: string): Promise<void>;
|
|
1477
1480
|
export function switchLocale(
|
|
@@ -1493,6 +1496,7 @@ ${lines.join("\n")}
|
|
|
1493
1496
|
}
|
|
1494
1497
|
}
|
|
1495
1498
|
|
|
1499
|
+
// prettier-ignore
|
|
1496
1500
|
declare module 'virtual:verbaly/locale/*' {
|
|
1497
1501
|
const messages: Record<string, string>;
|
|
1498
1502
|
export default messages;
|
|
@@ -1675,7 +1679,8 @@ function loadState(cfg) {
|
|
|
1675
1679
|
if (legacy !== void 0 && !isObject(legacy)) throw corrupt(statePath(cfg, LEGACY_DRAFTS_FILE));
|
|
1676
1680
|
const state = isObject(current) ? {
|
|
1677
1681
|
drafts: readDrafts(current.drafts),
|
|
1678
|
-
fingerprints: readFingerprints(current.fingerprints)
|
|
1682
|
+
fingerprints: readFingerprints(current.fingerprints),
|
|
1683
|
+
migrated: readMigrated(current.migrated)
|
|
1679
1684
|
} : {
|
|
1680
1685
|
drafts: {},
|
|
1681
1686
|
fingerprints: {}
|
|
@@ -1741,7 +1746,8 @@ function refreshState(cfg, catalogs, previous) {
|
|
|
1741
1746
|
}
|
|
1742
1747
|
return {
|
|
1743
1748
|
drafts,
|
|
1744
|
-
fingerprints
|
|
1749
|
+
fingerprints,
|
|
1750
|
+
migrated: previous.migrated
|
|
1745
1751
|
};
|
|
1746
1752
|
}
|
|
1747
1753
|
function refreshStamps(source, catalog, before) {
|
|
@@ -1850,10 +1856,12 @@ function serializeState(state) {
|
|
|
1850
1856
|
if (!keys.length) continue;
|
|
1851
1857
|
fingerprints[locale] = Object.fromEntries(keys.map((key) => [key, entries[key]]));
|
|
1852
1858
|
}
|
|
1859
|
+
const migrated = [...new Set(state.migrated ?? [])].sort();
|
|
1853
1860
|
const out = {};
|
|
1854
1861
|
if (Object.keys(drafts).length) out.drafts = drafts;
|
|
1855
1862
|
if (Object.keys(fingerprints).length) out.fingerprints = fingerprints;
|
|
1856
|
-
if (
|
|
1863
|
+
if (migrated.length) out.migrated = migrated;
|
|
1864
|
+
if (!out.drafts && !out.fingerprints && !out.migrated) return void 0;
|
|
1857
1865
|
return JSON.stringify(out, null, 2) + "\n";
|
|
1858
1866
|
}
|
|
1859
1867
|
function readJson(path) {
|
|
@@ -1881,6 +1889,11 @@ function readDrafts(value) {
|
|
|
1881
1889
|
for (const [locale, keys] of Object.entries(value)) if (Array.isArray(keys)) out[locale] = keys.filter((key) => typeof key === "string");
|
|
1882
1890
|
return out;
|
|
1883
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
|
+
}
|
|
1884
1897
|
function readFingerprints(value) {
|
|
1885
1898
|
const out = {};
|
|
1886
1899
|
if (!isObject(value)) return out;
|
|
@@ -1942,6 +1955,42 @@ function confirmFromDisk(cfg, catalogs, registry) {
|
|
|
1942
1955
|
}
|
|
1943
1956
|
}
|
|
1944
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
|
|
1945
1994
|
//#region src/tag.ts
|
|
1946
1995
|
function isLocaleTag(tag) {
|
|
1947
1996
|
try {
|
|
@@ -1957,6 +2006,27 @@ function suggestTag(tag) {
|
|
|
1957
2006
|
}
|
|
1958
2007
|
//#endregion
|
|
1959
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
|
+
}
|
|
1960
2030
|
function cliReachable(root) {
|
|
1961
2031
|
const bin = join(root, "node_modules", ".bin");
|
|
1962
2032
|
return existsSync(join(bin, "verbaly")) || existsSync(join(bin, "verbaly.CMD"));
|
|
@@ -2005,14 +2075,19 @@ async function init(input = {}) {
|
|
|
2005
2075
|
const existing = findConfigFile(root);
|
|
2006
2076
|
const typescript = existsSync(join(root, "tsconfig.json"));
|
|
2007
2077
|
const configFile = existing ?? (typescript ? "verbaly.config.ts" : "verbaly.config.mjs");
|
|
2078
|
+
const found = existing || options.dir ? void 0 : existingCatalogs(root);
|
|
2008
2079
|
if (existing) skipped.push(existing);
|
|
2009
2080
|
else {
|
|
2010
|
-
|
|
2081
|
+
const dir = found === "locales" ? void 0 : found;
|
|
2082
|
+
writeFileSync(join(root, configFile), configSource({
|
|
2083
|
+
...options,
|
|
2084
|
+
dir: options.dir ?? dir
|
|
2085
|
+
}, typescript));
|
|
2011
2086
|
created.push(configFile);
|
|
2012
2087
|
}
|
|
2013
2088
|
const fromFile = existing ? await loadConfigFile(root) : {};
|
|
2014
2089
|
const scaffold = {
|
|
2015
|
-
dir: options.dir ?? fromFile.dir,
|
|
2090
|
+
dir: options.dir ?? fromFile.dir ?? found,
|
|
2016
2091
|
sourceLocale: options.sourceLocale ?? fromFile.sourceLocale,
|
|
2017
2092
|
locales: options.locales ?? fromFile.locales
|
|
2018
2093
|
};
|
|
@@ -2028,7 +2103,11 @@ async function init(input = {}) {
|
|
|
2028
2103
|
}
|
|
2029
2104
|
}
|
|
2030
2105
|
const host = detectHost(root);
|
|
2031
|
-
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`);
|
|
2032
2111
|
return {
|
|
2033
2112
|
created,
|
|
2034
2113
|
skipped,
|
|
@@ -2036,7 +2115,8 @@ async function init(input = {}) {
|
|
|
2036
2115
|
configFile,
|
|
2037
2116
|
next,
|
|
2038
2117
|
renamed,
|
|
2039
|
-
refused
|
|
2118
|
+
refused,
|
|
2119
|
+
found
|
|
2040
2120
|
};
|
|
2041
2121
|
}
|
|
2042
2122
|
//#endregion
|
|
@@ -2151,6 +2231,32 @@ function formatCheckResult(result, root) {
|
|
|
2151
2231
|
}
|
|
2152
2232
|
return lines.join("\n");
|
|
2153
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
|
+
}
|
|
2154
2260
|
function checkNextSteps(result, cliReachable = true) {
|
|
2155
2261
|
const steps = [];
|
|
2156
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`)");
|
|
@@ -2247,14 +2353,39 @@ function runBuildGate(cfg, registry, failOnMissing) {
|
|
|
2247
2353
|
const catalogs = loadCatalogs(cfg);
|
|
2248
2354
|
for (const issue of auditBundle(cfg, catalogs, registry)) warnOnce(`${formatBundleIssue(issue)}\n fix: ${issue.fix}`, `bundle:${issue.prefix}`);
|
|
2249
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);
|
|
2250
2358
|
const warnings = warningCount(found);
|
|
2251
2359
|
if (warnings > 0) warnOnce(`check has ${counted(warnings, "warning")}, and the build still passes: run \`npx verbaly check\` to read them`, "gate:warnings");
|
|
2252
|
-
|
|
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({
|
|
2253
2379
|
...found,
|
|
2254
|
-
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
|
-
|
|
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"));
|
|
2258
2389
|
}
|
|
2259
2390
|
function buildFingerprints(cfg) {
|
|
2260
2391
|
const { state, problem } = readState(cfg);
|
|
@@ -2414,6 +2545,11 @@ function formatDoctorEntry(entry) {
|
|
|
2414
2545
|
return entry.fix ? `${head}
|
|
2415
2546
|
fix: ${entry.fix}` : head;
|
|
2416
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
|
+
}
|
|
2417
2553
|
async function doctor(cfg) {
|
|
2418
2554
|
const entries = [];
|
|
2419
2555
|
const ok = (name, message) => entries.push({
|
|
@@ -2790,7 +2926,7 @@ function formatTranslateFailures(failed) {
|
|
|
2790
2926
|
async function resolveProvider(cfg, model) {
|
|
2791
2927
|
const configured = cfg.translate.provider;
|
|
2792
2928
|
if (typeof configured === "function") return configured;
|
|
2793
|
-
const { claudeProvider } = await import("./claude-
|
|
2929
|
+
const { claudeProvider } = await import("./claude-CusgBHrv.js");
|
|
2794
2930
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
2795
2931
|
}
|
|
2796
2932
|
function structureMatches(source, translated) {
|
|
@@ -3592,6 +3728,6 @@ function formatCliError(error) {
|
|
|
3592
3728
|
return message.startsWith("[verbaly]") ? message : `[verbaly] ${message}`;
|
|
3593
3729
|
}
|
|
3594
3730
|
//#endregion
|
|
3595
|
-
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 };
|
|
3596
3732
|
|
|
3597
3733
|
//# sourceMappingURL=index.js.map
|