@verbaly/compiler 0.82.0 → 0.84.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 +4 -1
- package/dist/{claude-D31sQLmS.js → claude-BSLi4_54.js} +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +24 -19
- package/dist/index.js +145 -1
- package/dist/{run-We8xWd57.js → run-D5AlqnUA.js} +914 -1001
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/@verbaly/compiler"><img src="https://img.shields.io/npm/v/@verbaly/compiler?logo=npm&color=cb3837" alt="npm version" /></a>
|
|
9
|
+
<img src="https://img.shields.io/node/v/@verbaly/compiler?logo=nodedotjs&logoColor=white&color=5fa04e" alt="supported Node.js versions" />
|
|
10
|
+
<a href="https://scorecard.dev/viewer/?uri=github.com/AronSoto/verbaly"><img src="https://api.scorecard.dev/projects/github.com/AronSoto/verbaly/badge" alt="OpenSSF Scorecard" /></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@verbaly/compiler#provenance"><img src="https://img.shields.io/badge/provenance-SLSA%20v1-3fb950?logo=npm" alt="published with npm provenance" /></a>
|
|
9
12
|
<a href="https://github.com/AronSoto/verbaly/blob/develop/LICENSE"><img src="https://img.shields.io/npm/l/@verbaly/compiler?color=blue" alt="MIT" /></a>
|
|
10
13
|
</p>
|
|
11
14
|
|
|
@@ -76,7 +79,7 @@ Two more warnings name things that used to happen in silence, each with the file
|
|
|
76
79
|
|
|
77
80
|
```text
|
|
78
81
|
[verbaly] ✗ the build goes on with 1 broken translation, each rendering differently from its source:
|
|
79
|
-
[es] cart.total: {amount}
|
|
82
|
+
[es] cart.total: the translation lost {amount}, so the value never reaches the text
|
|
80
83
|
[verbaly] ⚠ the build goes on without 1 translation, shown in en instead:
|
|
81
84
|
[es] home.lead: "Pick a language"
|
|
82
85
|
[verbaly] ⚠ the build goes on with 1 key no catalog has, so the key itself shows:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { kt as counted, xt as isModuleNotFound } from "./run-D5AlqnUA.js";
|
|
2
2
|
// src/exchange/providers/claude.ts
|
|
3
3
|
const DEFAULT_MODEL = "claude-sonnet-5-5";
|
|
4
4
|
const FALLBACK_MODELS = /* @__PURE__ */ new Set([
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -88,25 +88,11 @@ interface State {
|
|
|
88
88
|
fingerprints: Fingerprints;
|
|
89
89
|
migrated?: string[];
|
|
90
90
|
}
|
|
91
|
-
interface OutdatedEntry {
|
|
92
|
-
locale: string;
|
|
93
|
-
key: string;
|
|
94
|
-
}
|
|
95
91
|
interface StateRead {
|
|
96
92
|
state: State;
|
|
97
93
|
problem?: string;
|
|
98
94
|
conflict?: true;
|
|
99
95
|
}
|
|
100
|
-
interface WrittenTranslation {
|
|
101
|
-
key: string;
|
|
102
|
-
text: string;
|
|
103
|
-
source?: string;
|
|
104
|
-
}
|
|
105
|
-
interface TranslationWrite {
|
|
106
|
-
locale: string;
|
|
107
|
-
entries: WrittenTranslation[];
|
|
108
|
-
draft?: boolean;
|
|
109
|
-
}
|
|
110
96
|
interface LockEntry {
|
|
111
97
|
file: string;
|
|
112
98
|
from?: string;
|
|
@@ -114,12 +100,8 @@ interface LockEntry {
|
|
|
114
100
|
}
|
|
115
101
|
export declare function loadState(cfg: ResolvedConfig): State;
|
|
116
102
|
export declare function readState(cfg: ResolvedConfig): StateRead;
|
|
117
|
-
export declare function updateState(cfg: ResolvedConfig, catalogs: Catalogs): State;
|
|
118
|
-
export declare function recordTranslations(cfg: ResolvedConfig, source: Catalog, writes: TranslationWrite[]): State;
|
|
119
|
-
export declare function effectiveDrafts(drafts: Drafts, catalogs: Catalogs): Drafts;
|
|
120
103
|
export declare function markDrafts(drafts: Drafts, locale: string, keys: string[]): void;
|
|
121
104
|
export declare function clearDrafts(drafts: Drafts, locale: string, keys?: string[]): void;
|
|
122
|
-
export declare function outdatedTranslations(cfg: ResolvedConfig, catalogs: Catalogs, fingerprints: Fingerprints): OutdatedEntry[];
|
|
123
105
|
interface TranslateRequest {
|
|
124
106
|
sourceLocale: string;
|
|
125
107
|
targetLocale: string;
|
|
@@ -178,6 +160,7 @@ export declare function writeDrafts(cfg: ResolvedConfig, locale: string, entries
|
|
|
178
160
|
export declare function formatTranslateFailures(failed: TranslateFailure[]): string[];
|
|
179
161
|
export declare function resolveProvider(cfg: ResolvedConfig, model?: string): Promise<TranslateProvider>;
|
|
180
162
|
type GlossaryEntry = string | Record<string, string>;
|
|
163
|
+
export declare const SOURCE_FILE_RE: RegExp;
|
|
181
164
|
interface TranslateConfig {
|
|
182
165
|
provider?: 'claude' | TranslateProvider;
|
|
183
166
|
model?: string;
|
|
@@ -230,6 +213,7 @@ interface ResolvedConfig {
|
|
|
230
213
|
locales: string[];
|
|
231
214
|
localesDeclared: boolean;
|
|
232
215
|
routing: Routing;
|
|
216
|
+
routingDeclared: boolean;
|
|
233
217
|
icu: boolean | undefined;
|
|
234
218
|
relative: boolean | undefined;
|
|
235
219
|
include: string[];
|
|
@@ -264,6 +248,24 @@ export declare function shippedCatalogs(cfg: ResolvedConfig, catalogs: Catalogs,
|
|
|
264
248
|
newKeys?: boolean;
|
|
265
249
|
}): Catalogs;
|
|
266
250
|
export declare function pruneCatalogs(cfg: ResolvedConfig, catalogs: Catalogs, registry: MessageRegistry): Record<string, string[]>;
|
|
251
|
+
interface OutdatedEntry {
|
|
252
|
+
locale: string;
|
|
253
|
+
key: string;
|
|
254
|
+
}
|
|
255
|
+
interface WrittenTranslation {
|
|
256
|
+
key: string;
|
|
257
|
+
text: string;
|
|
258
|
+
source?: string;
|
|
259
|
+
}
|
|
260
|
+
interface TranslationWrite {
|
|
261
|
+
locale: string;
|
|
262
|
+
entries: WrittenTranslation[];
|
|
263
|
+
draft?: boolean;
|
|
264
|
+
}
|
|
265
|
+
export declare function updateState(cfg: ResolvedConfig, catalogs: Catalogs): State;
|
|
266
|
+
export declare function recordTranslations(cfg: ResolvedConfig, source: Catalog, writes: TranslationWrite[]): State;
|
|
267
|
+
export declare function effectiveDrafts(drafts: Drafts, catalogs: Catalogs): Drafts;
|
|
268
|
+
export declare function outdatedTranslations(cfg: ResolvedConfig, catalogs: Catalogs, fingerprints: Fingerprints): OutdatedEntry[];
|
|
267
269
|
interface SourceSite {
|
|
268
270
|
file: string;
|
|
269
271
|
line?: number;
|
|
@@ -402,7 +404,6 @@ interface PluginOptions extends VerbalyConfig {
|
|
|
402
404
|
}
|
|
403
405
|
export declare const RESOLVED_VIRTUAL_ID: string;
|
|
404
406
|
export declare const LOCALE_MODULE_PREFIX = "\0virtual:verbaly/locale/";
|
|
405
|
-
export declare const SOURCE_FILE_RE: RegExp;
|
|
406
407
|
export declare function resolveVirtualId(id: string): string | undefined;
|
|
407
408
|
interface ClientModules {
|
|
408
409
|
runtime(): string;
|
|
@@ -581,6 +582,10 @@ interface RenderSiteResult {
|
|
|
581
582
|
locales: string[];
|
|
582
583
|
missing: Record<string, string[]>;
|
|
583
584
|
untranslatedHead: string[];
|
|
585
|
+
sourceFolder?: {
|
|
586
|
+
folder: string;
|
|
587
|
+
pages: number;
|
|
588
|
+
};
|
|
584
589
|
}
|
|
585
590
|
export declare function renderSite(cfg: ResolvedConfig, options?: RenderSiteOptions): Promise<RenderSiteResult>;
|
|
586
591
|
export declare function formatRenderWarnings(result: RenderSiteResult, sourceLocale: string): string[];
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,148 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as collectOrigins, A as collisionEntries, At as singleQuoted, B as loadState, C as translateProject, Ct as pluginOnlyOptions, D as translateCatalogs, Dt as warnParseError, E as resolveProvider, Et as warnOnce, F as outdatedTranslations, G as generateLocaleModule, H as readState, I as recordTranslations, J as validateMessage, K as generateRuntimeModule, L as updateState, M as formatCollision, N as formatFinding, O as writeDrafts, Ot as cliReachable, P as effectiveDrafts, Q as syncCatalogs, R as STATE_FILE, S as warningCount, St as loadConfig, T as mergeTranslations, Tt as targetLocales, U as saveState, V as markDrafts, W as generateDts, X as pruneCatalogs, Y as validatePair, Z as shippedCatalogs, _ as formatCheckResult, _t as parseCatalog, a as formatRenderWarnings, at as LOCALE_IMPORT, b as gatePasses, bt as SOURCE_FILE_RE, c as watchTree, ct as MessageRegistry, d as formatDoctorHealth, dt as formatBundleIssue, et as extractProject, f as formatStatusResult, ft as emptyCatalog, g as formatBuildReport, gt as own, h as checkNextSteps, ht as needsRelative, i as wrapProject, it as APP_ID, j as createDevReporter, jt as relativePath, k as syncProject, kt as counted, l as doctor, lt as auditBundle, m as reportOutsideInclude, mt as needsIcu, nt as analyzeFile, o as renderSite, ot as VIRTUAL_ID, p as status, pt as loadCatalogs, q as writeDts, r as formatWrapResult, rt as stableKey, s as init, st as isAppModule, t as formatCliError, tt as scannedAnalysis, u as formatDoctorEntry, ut as clientCatalogs, v as formatCheckWarnings, vt as readCatalog, w as formatTranslateFailures, wt as resolveConfig, x as relativeCheck, y as check, yt as writeCatalog, z as clearDrafts } from "./run-D5AlqnUA.js";
|
|
2
|
+
import picomatch from "picomatch";
|
|
3
|
+
import MagicString from "magic-string";
|
|
4
|
+
// src/scan/transform.ts
|
|
5
|
+
function quote(text, single) {
|
|
6
|
+
return single ? singleQuoted(text) : JSON.stringify(text);
|
|
7
|
+
}
|
|
8
|
+
function transformCode(code, file, analysis, options = {}) {
|
|
9
|
+
const own = analysis ?? analyzeFile(code, file);
|
|
10
|
+
if (!analysis && own.parseError) warnParseError(file, own.parseError);
|
|
11
|
+
const { tagged } = own;
|
|
12
|
+
const appAt = options.appImport && !own.appImported ? own.adapterImport : void 0;
|
|
13
|
+
if (tagged.length === 0 && appAt === void 0) return null;
|
|
14
|
+
const s = new MagicString(code);
|
|
15
|
+
if (appAt !== void 0) s.appendLeft(appAt, `import '${APP_ID}'; `);
|
|
16
|
+
for (const msg of tagged) {
|
|
17
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18
|
+
const entries = msg.params.filter((p) => !seen.has(p.name) && seen.add(p.name));
|
|
19
|
+
const pairs = entries.map((p) => `${quote(p.name, msg.singleQuote)}: ${code.slice(p.start, p.end)}`).join(", ");
|
|
20
|
+
if (msg.jsx) {
|
|
21
|
+
const values = entries.length ? ` values={{ ${pairs} }}` : "";
|
|
22
|
+
const components = msg.jsx.components.length ? ` components={{ ${msg.jsx.components.map((c) => `${JSON.stringify(c.name)}: ${c.source}`).join(", ")} }}` : "";
|
|
23
|
+
const quoted = JSON.stringify(msg.key);
|
|
24
|
+
const id = quoted === `"${msg.key}"` ? quoted : `{${quoted}}`;
|
|
25
|
+
s.overwrite(msg.start, msg.end, `<${msg.jsx.name} id=${id}${values}${components} />`);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const tagSource = code.slice(msg.tagStart, msg.tagEnd);
|
|
29
|
+
const args = entries.length ? `, { ${pairs} }` : "";
|
|
30
|
+
s.overwrite(msg.start, msg.end, `${tagSource}(${quote(msg.key, msg.singleQuote)}${args})`);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
code: s.toString(),
|
|
34
|
+
map: s.generateMap({ hires: true })
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// src/emit/plugin.ts
|
|
38
|
+
const RESOLVED_VIRTUAL_ID = "\0" + VIRTUAL_ID;
|
|
39
|
+
const LOCALE_MODULE_PREFIX = `${RESOLVED_VIRTUAL_ID}/locale/`;
|
|
40
|
+
function resolveVirtualId(id) {
|
|
41
|
+
if (isAppModule(id)) return RESOLVED_VIRTUAL_ID;
|
|
42
|
+
if (id.startsWith("@verbaly/app/locale/")) return LOCALE_MODULE_PREFIX + id.slice(LOCALE_IMPORT.length);
|
|
43
|
+
if (id.startsWith(`virtual:verbaly/`)) return "\0" + id;
|
|
44
|
+
}
|
|
45
|
+
function clientModules(cfg, catalogs, options = {}) {
|
|
46
|
+
const client = clientCatalogs(cfg, catalogs);
|
|
47
|
+
return {
|
|
48
|
+
runtime: () => generateRuntimeModule(cfg, {
|
|
49
|
+
...options,
|
|
50
|
+
icu: cfg.icu ?? needsIcu(client),
|
|
51
|
+
relative: cfg.relative ?? needsRelative(client),
|
|
52
|
+
inlineCatalog: cfg.render.inlineCatalog === true
|
|
53
|
+
}),
|
|
54
|
+
locale: (locale) => generateLocaleModule(own(client, locale) ?? {})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function loadVirtualModule(id, cfg, catalogs) {
|
|
58
|
+
if (id === RESOLVED_VIRTUAL_ID) return clientModules(cfg, catalogs).runtime();
|
|
59
|
+
if (id.startsWith(LOCALE_MODULE_PREFIX)) return clientModules(cfg, catalogs).locale(id.slice(LOCALE_MODULE_PREFIX.length));
|
|
60
|
+
}
|
|
61
|
+
function isTransformTarget(id) {
|
|
62
|
+
return SOURCE_FILE_RE.test(id) && !id.includes("node_modules") && !id.startsWith("\0");
|
|
63
|
+
}
|
|
64
|
+
function createSourceFilter(cfg) {
|
|
65
|
+
if (cfg.include.length === 0) return () => false;
|
|
66
|
+
const matches = picomatch(cfg.include, { ignore: cfg.exclude });
|
|
67
|
+
return (id) => {
|
|
68
|
+
const rel = relativePath(cfg.root, id);
|
|
69
|
+
return !rel.startsWith("..") && matches(rel);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function transformSource(code, id, registry, scan) {
|
|
73
|
+
const analysis = (scan && scannedAnalysis(scan, id, code)) ?? analyzeFile(code, id);
|
|
74
|
+
registry.update(id, analysis);
|
|
75
|
+
if (analysis.parseError) warnParseError(id, analysis.parseError);
|
|
76
|
+
const messages = emptyCatalog();
|
|
77
|
+
for (const msg of analysis.tagged) messages[msg.key] ??= msg.message;
|
|
78
|
+
return {
|
|
79
|
+
messages,
|
|
80
|
+
result: transformCode(code, id, analysis, { appImport: true }) ?? null
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function writeBuildTypes(cfg, catalogs) {
|
|
84
|
+
try {
|
|
85
|
+
writeDts(cfg, catalogs[cfg.sourceLocale] ?? {});
|
|
86
|
+
} catch (error) {
|
|
87
|
+
const code = error?.code;
|
|
88
|
+
if (typeof code !== "string") throw error;
|
|
89
|
+
const file = cfg.dts === false ? "" : relativePath(cfg.root, cfg.dts);
|
|
90
|
+
warnOnce(`could not write the types to ${file} (${code}): run \`npx verbaly typegen\` where the project can be written`, `types:${cfg.root}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function runBuildGate(cfg, registry, failOnMissing) {
|
|
94
|
+
const catalogs = loadCatalogs(cfg);
|
|
95
|
+
for (const issue of auditBundle(cfg, catalogs, registry)) warnOnce(`${formatBundleIssue(issue)}\n fix: ${issue.fix}`, `bundle:${issue.prefix}`);
|
|
96
|
+
const found = check(cfg, catalogs, registry, buildFingerprints(cfg));
|
|
97
|
+
if (failOnMissing === true && !gatePasses(found)) throw new Error(`[verbaly] build blocked\n${formatCheckResult(found, cfg.root)}\n${checkNextSteps(found, cliReachable(cfg.root))}`);
|
|
98
|
+
reportGate(cfg, found);
|
|
99
|
+
const warnings = warningCount(found);
|
|
100
|
+
if (warnings > 0) {
|
|
101
|
+
const once = onceMoved(cfg.root);
|
|
102
|
+
const read = once ? `\`npx verbaly check\` reads them${once}` : "run `npx verbaly check` to read them";
|
|
103
|
+
warnOnce(`check has ${counted(warnings, "warning")}, and the build still passes: ${read}`, "gate:warnings");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function onceMoved(root) {
|
|
107
|
+
const moved = pluginOnlyOptions(root);
|
|
108
|
+
if (!moved) return "";
|
|
109
|
+
return ` once ${moved} ${moved.includes(" and ") ? "move" : "moves"} to verbaly.config`;
|
|
110
|
+
}
|
|
111
|
+
const reported = /* @__PURE__ */ new Map();
|
|
112
|
+
function reportGate(cfg, found) {
|
|
113
|
+
const before = reported.get(cfg.root) ?? /* @__PURE__ */ new Set();
|
|
114
|
+
const now = /* @__PURE__ */ new Set();
|
|
115
|
+
const fresh = (entries, id) => entries.filter((entry) => {
|
|
116
|
+
const key = id(entry);
|
|
117
|
+
now.add(key);
|
|
118
|
+
return !before.has(key);
|
|
119
|
+
});
|
|
120
|
+
const report = {
|
|
121
|
+
broken: fresh(found.broken.filter((entry) => entry.severity === "error"), (entry) => `broken:${entry.locale}:${entry.key}:${entry.issue}`),
|
|
122
|
+
missing: fresh(found.missing, (entry) => `missing:${entry.locale}:${entry.key}`),
|
|
123
|
+
unknown: fresh(found.unknown, (entry) => `unknown:${entry.key}`),
|
|
124
|
+
collisions: fresh(found.collisions, (entry) => `collision:${entry.key}`)
|
|
125
|
+
};
|
|
126
|
+
reported.set(cfg.root, now);
|
|
127
|
+
const lines = formatBuildReport(report, cfg.sourceLocale, cfg.root);
|
|
128
|
+
if (lines.length === 0) return;
|
|
129
|
+
const steps = checkNextSteps({
|
|
130
|
+
...found,
|
|
131
|
+
...report
|
|
132
|
+
}, cliReachable(cfg.root));
|
|
133
|
+
const block = [
|
|
134
|
+
...lines.map((line) => line.startsWith(" ") ? line : `[verbaly] ${line}`),
|
|
135
|
+
"[verbaly] to fix them:",
|
|
136
|
+
...steps.split("\n").map((step) => ` ${step}`),
|
|
137
|
+
`[verbaly] \`npx verbaly check\` lists every one${onceMoved(cfg.root)}, and in your CI it stops a release on them`
|
|
138
|
+
];
|
|
139
|
+
console.warn(block.join("\n"));
|
|
140
|
+
}
|
|
141
|
+
function buildFingerprints(cfg) {
|
|
142
|
+
const { state, problem } = readState(cfg);
|
|
143
|
+
if (problem) warnOnce(`${problem}, so outdated translations are not reported`, "gate:state");
|
|
144
|
+
return state.fingerprints;
|
|
145
|
+
}
|
|
2
146
|
// src/catalog/drafts.ts
|
|
3
147
|
function loadDrafts(cfg) {
|
|
4
148
|
return loadState(cfg).drafts;
|