@verbaly/compiler 0.82.0 → 0.83.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 -0
- package/dist/{claude-D31sQLmS.js → claude-DvjHi7np.js} +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +19 -19
- package/dist/index.js +145 -1
- package/dist/{run-We8xWd57.js → run-BBxX6CcL.js} +889 -987
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
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://github.com/AronSoto/verbaly/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/AronSoto/verbaly/ci.yml?logo=github&label=CI" alt="CI" /></a>
|
|
11
|
+
<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>
|
|
12
|
+
<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
13
|
<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
14
|
</p>
|
|
11
15
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as counted, St as isModuleNotFound } from "./run-BBxX6CcL.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;
|
|
@@ -264,6 +247,24 @@ export declare function shippedCatalogs(cfg: ResolvedConfig, catalogs: Catalogs,
|
|
|
264
247
|
newKeys?: boolean;
|
|
265
248
|
}): Catalogs;
|
|
266
249
|
export declare function pruneCatalogs(cfg: ResolvedConfig, catalogs: Catalogs, registry: MessageRegistry): Record<string, string[]>;
|
|
250
|
+
interface OutdatedEntry {
|
|
251
|
+
locale: string;
|
|
252
|
+
key: string;
|
|
253
|
+
}
|
|
254
|
+
interface WrittenTranslation {
|
|
255
|
+
key: string;
|
|
256
|
+
text: string;
|
|
257
|
+
source?: string;
|
|
258
|
+
}
|
|
259
|
+
interface TranslationWrite {
|
|
260
|
+
locale: string;
|
|
261
|
+
entries: WrittenTranslation[];
|
|
262
|
+
draft?: boolean;
|
|
263
|
+
}
|
|
264
|
+
export declare function updateState(cfg: ResolvedConfig, catalogs: Catalogs): State;
|
|
265
|
+
export declare function recordTranslations(cfg: ResolvedConfig, source: Catalog, writes: TranslationWrite[]): State;
|
|
266
|
+
export declare function effectiveDrafts(drafts: Drafts, catalogs: Catalogs): Drafts;
|
|
267
|
+
export declare function outdatedTranslations(cfg: ResolvedConfig, catalogs: Catalogs, fingerprints: Fingerprints): OutdatedEntry[];
|
|
267
268
|
interface SourceSite {
|
|
268
269
|
file: string;
|
|
269
270
|
line?: number;
|
|
@@ -402,7 +403,6 @@ interface PluginOptions extends VerbalyConfig {
|
|
|
402
403
|
}
|
|
403
404
|
export declare const RESOLVED_VIRTUAL_ID: string;
|
|
404
405
|
export declare const LOCALE_MODULE_PREFIX = "\0virtual:verbaly/locale/";
|
|
405
|
-
export declare const SOURCE_FILE_RE: RegExp;
|
|
406
406
|
export declare function resolveVirtualId(id: string): string | undefined;
|
|
407
407
|
interface ClientModules {
|
|
408
408
|
runtime(): string;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,148 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as collectOrigins, A as collisionEntries, At as counted, B as loadState, C as translateProject, Ct as loadConfig, D as translateCatalogs, Dt as warnOnce, E as resolveProvider, Et as targetLocales, 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 warnParseError, P as effectiveDrafts, Q as syncCatalogs, R as STATE_FILE, S as warningCount, T as mergeTranslations, Tt as resolveConfig, U as saveState, V as markDrafts, W as generateDts, X as pruneCatalogs, Y as validatePair, Z as shippedCatalogs, _ as formatCheckResult, _t as own, a as formatRenderWarnings, at as APP_ID, b as gatePasses, bt as writeCatalog, c as watchTree, ct as isAppModule, d as formatDoctorHealth, dt as clientCatalogs, et as extractProject, f as formatStatusResult, ft as formatBundleIssue, g as formatBuildReport, gt as needsRelative, h as checkNextSteps, ht as needsIcu, i as wrapProject, it as stableKey, j as createDevReporter, jt as singleQuoted, k as syncProject, kt as cliReachable, l as doctor, lt as MessageRegistry, m as reportOutsideInclude, mt as loadCatalogs, nt as relativePath, o as renderSite, ot as LOCALE_IMPORT, p as status, pt as emptyCatalog, q as writeDts, r as formatWrapResult, rt as analyzeFile, s as init, st as VIRTUAL_ID, t as formatCliError, tt as scannedAnalysis, u as formatDoctorEntry, ut as auditBundle, v as formatCheckWarnings, vt as parseCatalog, w as formatTranslateFailures, wt as pluginOnlyOptions, x as relativeCheck, xt as SOURCE_FILE_RE, y as check, yt as readCatalog, z as clearDrafts } from "./run-BBxX6CcL.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;
|