@verbaly/compiler 0.86.2 → 0.87.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 CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="https://raw.githubusercontent.com/verbaly-i18n/verbaly/develop/assets/logo.png" alt="Verbaly" width="300" />
2
+ <img src="https://raw.githubusercontent.com/verbaly-i18n/verbaly/develop/assets/lockup-light.svg" alt="Verbaly" height="64" />
3
3
  </p>
4
4
 
5
5
  <p align="center"><em>Message extraction, type-safe codegen and CLI for Verbaly.</em></p>
@@ -400,7 +400,7 @@ Your plugin's options go second and `{ plugin: true }` third: when one the comma
400
400
 
401
401
  A build that scans first, as the Vite plugin does to sync the catalogs, keeps that scan with `extractProject(cfg, { keepSource: true })` and passes it as the fourth argument of `transformSource`: a file it read unchanged is not parsed a second time. Call `reportOutsideInclude(cfg)` once when your build starts: it names every file outside `include` that writes a `` t`…` ``, which no build translates. It reads the project itself, so a cached transform never hides one. `writeDts(cfg, catalog)` writes the types where the config resolves them and returns the file and whether it changed. A build calls `writeBuildTypes(cfg, catalogs)` once it has synced the catalogs: it writes the same file, and a checkout it cannot write gets a warning instead of a failed build.
402
402
 
403
- A dev server that writes the catalogs goes through `syncProject`, the same path `extract`, the MCP server and Studio take: it scans (or takes the registry you hold), syncs, writes the catalogs and the types, and keeps `verbaly.lock` in step, in that order; its `findings` say once when that file first appears. Pass `confirm: true` when your registry is built file by file, so a file that changed on disk unseen is read again before its text is written back. `createDevReporter` then says each of its findings once, says it again if it goes away and comes back, and keeps a long list to a few lines.
403
+ A dev server that writes the catalogs goes through `syncProject`, the same path `extract`, the MCP server and Studio take: it scans (or takes the registry you hold), syncs, writes the catalogs and the types, and keeps `verbaly.lock` in step, in that order; its `findings` say once when that file first appears. Pass `confirm: true` when your registry is built file by file, so a file that changed on disk unseen is read again before its text is written back. Another process may write a catalog while it runs, like the MCP server saving drafts beside your dev server: each file is read again right before it is written, and only what this run changed goes on top, so a translation saved meanwhile stays. The `catalogs` you pass are where the sync starts, not text it writes back, and the `catalogs` it returns are what the files hold now. `createDevReporter` then says each of its findings once, says it again if it goes away and comes back, and keeps a long list to a few lines.
404
404
 
405
405
  ## License
406
406
 
@@ -1,4 +1,4 @@
1
- import { kt as counted, xt as isModuleNotFound } from "./run-1p0TD3d7.js";
1
+ import { kt as counted, xt as isModuleNotFound } from "./run--z69VbcL.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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as runCli, t as formatCliError } from "./run-1p0TD3d7.js";
2
+ import { n as runCli, t as formatCliError } from "./run--z69VbcL.js";
3
3
  // src/cli.ts
4
4
  runCli().catch((error) => {
5
5
  console.error(formatCliError(error));
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
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-1p0TD3d7.js";
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--z69VbcL.js";
2
2
  import picomatch from "picomatch";
3
3
  import MagicString from "magic-string";
4
4
  // src/scan/transform.ts
@@ -1,16 +1,16 @@
1
+ import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
1
2
  import { createRequire } from "node:module";
2
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
3
3
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
4
4
  import { pathToFileURL } from "node:url";
5
+ import { parseArgs as parseArgs$1 } from "node:util";
5
6
  import { CATALOG_SCRIPT, LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseIcu, parseTags, safeAttribute } from "verbaly";
7
+ import { createHash } from "node:crypto";
6
8
  import { readFile } from "node:fs/promises";
7
9
  import { glob } from "tinyglobby";
8
10
  import { parse as parse$1 } from "@babel/parser";
9
- import { createHash } from "node:crypto";
10
11
  import { applyEdits, modify, parse as parse$2 } from "jsonc-parser";
11
12
  import picomatch from "picomatch";
12
13
  import MagicString from "magic-string";
13
- import { parseArgs as parseArgs$1 } from "node:util";
14
14
  // src/util/path.ts
15
15
  function slashed(path) {
16
16
  return path.replaceAll("\\", "/");
@@ -365,6 +365,56 @@ function withLineEndings(text, existing) {
365
365
  const first = existing?.indexOf("\n") ?? -1;
366
366
  return first > 0 && existing[first - 1] === "\r" ? text.replace(/\r?\n/g, "\r\n") : text;
367
367
  }
368
+ // src/util/write.ts
369
+ const BUSY = new Set(process.platform === "win32" ? [
370
+ "EPERM",
371
+ "EBUSY",
372
+ "EACCES"
373
+ ] : ["EBUSY"]);
374
+ const TRIES = 5;
375
+ function writeAtomic(path, text) {
376
+ const target = realTarget(path);
377
+ const unique = `${process.pid}.${Math.random().toString(36).slice(2, 10)}`;
378
+ const temp = join(dirname(target), `.${basename(target)}.${unique}.tmp`);
379
+ try {
380
+ writeFileSync(temp, text);
381
+ keepMode(target, temp);
382
+ replace(temp, target);
383
+ } catch (error) {
384
+ rmSync(temp, { force: true });
385
+ throw new Error(`[verbaly] could not save ${path}: ${error.message}`, { cause: error });
386
+ }
387
+ }
388
+ function keepMode(target, temp) {
389
+ let mode;
390
+ try {
391
+ mode = statSync(target).mode;
392
+ } catch {
393
+ return;
394
+ }
395
+ chmodSync(temp, mode & 4095);
396
+ }
397
+ function realTarget(path) {
398
+ try {
399
+ return realpathSync(path);
400
+ } catch {
401
+ return path;
402
+ }
403
+ }
404
+ function replace(from, to) {
405
+ for (let attempt = 1;; attempt++) try {
406
+ renameSync(from, to);
407
+ return;
408
+ } catch (error) {
409
+ const code = error.code ?? "";
410
+ if (!BUSY.has(code)) throw error;
411
+ if (attempt === TRIES) throw new Error(`it is read-only or another program keeps it open (${code}).`, { cause: error });
412
+ pause(attempt * 20);
413
+ }
414
+ }
415
+ function pause(ms) {
416
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
417
+ }
368
418
  // src/catalog/catalog.ts
369
419
  function emptyCatalog() {
370
420
  return Object.create(null);
@@ -509,7 +559,7 @@ function writeCatalog(cfg, locale, catalog) {
509
559
  const shape = shapeFor(cfg, locale, existing, previous);
510
560
  const serialized = withLineEndings(serializeCatalog(catalog, shape !== void 0 && isNested(shape), previous, shape), existing);
511
561
  if (existing === serialized) return serialized;
512
- writeFileSync(path, serialized);
562
+ writeAtomic(path, serialized);
513
563
  return serialized;
514
564
  }
515
565
  function shapeFor(cfg, locale, existing, previous) {
@@ -726,8 +776,7 @@ function analyzeScript(code, file, options = {}) {
726
776
  });
727
777
  return;
728
778
  }
729
- const quasi = node.quasi;
730
- const message = buildMessage(code, quasi, names);
779
+ const message = buildMessage(code, node.quasi, names);
731
780
  if (!message) return;
732
781
  tagged.push({
733
782
  key: explicit ? explicit.key : stableKey(message.text),
@@ -1023,8 +1072,7 @@ function handleTrans(code, node, file, tagged, usedKeys, names) {
1023
1072
  }
1024
1073
  });
1025
1074
  if (idAttr) {
1026
- const value = idAttr.value;
1027
- const id = staticString(value);
1075
+ const id = staticString(idAttr.value);
1028
1076
  if (id === void 0) return;
1029
1077
  if (attrs.length === 1 && children?.length) {
1030
1078
  const built = buildTransMessage(code, children, names);
@@ -2304,7 +2352,7 @@ function saveState(cfg, state) {
2304
2352
  const serialized = withLineEndings(fresh, existing ?? legacy.map(readText).find((text) => text !== void 0));
2305
2353
  if (existing !== serialized) {
2306
2354
  if (existing !== void 0 && conflictSides(existing)) resolved.add(path);
2307
- writeFileSync(path, serialized);
2355
+ writeAtomic(path, serialized);
2308
2356
  }
2309
2357
  for (const file of legacy) rmSync(file, { force: true });
2310
2358
  }
@@ -2431,10 +2479,56 @@ function readFingerprints(value) {
2431
2479
  }
2432
2480
  // src/catalog/state.ts
2433
2481
  function updateState(cfg, catalogs) {
2434
- const next = refreshState(cfg, catalogs, loadState(cfg));
2482
+ const read = loadState(cfg);
2483
+ const next = keepTheirs(refreshState(cfg, catalogs, read), read, loadState(cfg));
2435
2484
  saveState(cfg, next);
2436
2485
  return next;
2437
2486
  }
2487
+ function keepTheirs(mine, base, theirs) {
2488
+ const drafts = emptyCatalog();
2489
+ for (const locale of localesOf(mine.drafts, base.drafts, theirs.drafts)) {
2490
+ const keys = merged(own(mine.drafts, locale), own(base.drafts, locale), own(theirs.drafts, locale));
2491
+ if (keys.length) drafts[locale] = keys;
2492
+ }
2493
+ const fingerprints = emptyCatalog();
2494
+ const prints = [
2495
+ mine.fingerprints,
2496
+ base.fingerprints,
2497
+ theirs.fingerprints
2498
+ ];
2499
+ for (const locale of localesOf(...prints)) {
2500
+ const [m = {}, b = {}, t = {}] = prints.map((each) => own(each, locale));
2501
+ const stamps = emptyCatalog();
2502
+ for (const key of /* @__PURE__ */ new Set([
2503
+ ...Object.keys(m),
2504
+ ...Object.keys(b),
2505
+ ...Object.keys(t)
2506
+ ])) {
2507
+ const value = own(m, key) !== own(b, key) ? own(m, key) : own(t, key);
2508
+ if (value !== void 0) stamps[key] = value;
2509
+ }
2510
+ if (Object.keys(stamps).length) fingerprints[locale] = stamps;
2511
+ }
2512
+ const migrated = merged(mine.migrated, base.migrated, theirs.migrated);
2513
+ return migrated.length ? {
2514
+ drafts,
2515
+ fingerprints,
2516
+ migrated
2517
+ } : {
2518
+ drafts,
2519
+ fingerprints
2520
+ };
2521
+ }
2522
+ function localesOf(...maps) {
2523
+ return new Set(maps.flatMap((map) => Object.keys(map)));
2524
+ }
2525
+ function merged(mine = [], base = [], theirs = []) {
2526
+ const before = new Set(base);
2527
+ const now = new Set(theirs);
2528
+ const out = new Set(mine.filter((entry) => !before.has(entry) || now.has(entry)));
2529
+ for (const entry of theirs) if (!before.has(entry)) out.add(entry);
2530
+ return [...out];
2531
+ }
2438
2532
  function refreshState(cfg, catalogs, previous) {
2439
2533
  const flat = flatCatalogs(catalogs);
2440
2534
  const source = flat[cfg.sourceLocale] ?? {};
@@ -2603,8 +2697,7 @@ function quoted(at, root) {
2603
2697
  }
2604
2698
  function formatCollision({ key, sites }, root) {
2605
2699
  const [kept, ...others] = sites;
2606
- const texts = new Set(sites.map((at) => at.message)).size;
2607
- return `${key}: one key with ${counted(texts, "text")}, and every place shows ${quoted(kept, root)}, never ${others.map((at) => quoted(at, root)).join(" or ")}: give each text its own key`;
2700
+ return `${key}: one key with ${counted(new Set(sites.map((at) => at.message)).size, "text")}, and every place shows ${quoted(kept, root)}, never ${others.map((at) => quoted(at, root)).join(" or ")}: give each text its own key`;
2608
2701
  }
2609
2702
  function formatFinding(finding, root) {
2610
2703
  switch (finding.kind) {
@@ -2708,10 +2801,17 @@ async function syncProject(cfg, options = {}) {
2708
2801
  if (options.dryRun) return result;
2709
2802
  const changed = /* @__PURE__ */ new Set([...Object.keys(added), ...Object.keys(pruned)]);
2710
2803
  if (replaced.length > 0) changed.add(cfg.sourceLocale);
2804
+ const run = {
2805
+ added,
2806
+ pruned,
2807
+ replaced
2808
+ };
2711
2809
  for (const locale of cfg.locales) {
2810
+ catalogs[locale] = onDiskNow(cfg, locale, catalogs[locale] ?? emptyCatalog(), run);
2712
2811
  if (options.write === "changed" && !changed.has(locale)) continue;
2713
- result.written[locale] = writeCatalog(cfg, locale, catalogs[locale] ?? emptyCatalog());
2812
+ result.written[locale] = writeCatalog(cfg, locale, catalogs[locale]);
2714
2813
  }
2814
+ result.messages = Object.keys(catalogs[cfg.sourceLocale] ?? emptyCatalog()).length;
2715
2815
  writeDts(cfg, catalogs[cfg.sourceLocale] ?? emptyCatalog());
2716
2816
  const before = stateFile(cfg);
2717
2817
  try {
@@ -2726,6 +2826,20 @@ async function syncProject(cfg, options = {}) {
2726
2826
  });
2727
2827
  return result;
2728
2828
  }
2829
+ function onDiskNow(cfg, locale, mine, run) {
2830
+ if (!existsSync(catalogPath(cfg, locale))) return mine;
2831
+ const now = readCatalog(cfg, locale);
2832
+ for (const key of own(run.pruned, locale) ?? []) delete now[key];
2833
+ const source = locale === cfg.sourceLocale;
2834
+ const keys = [...own(run.added, locale) ?? []];
2835
+ if (source) keys.push(...run.replaced.map((entry) => entry.key));
2836
+ for (const key of keys) {
2837
+ const text = own(mine, key);
2838
+ if (text === void 0) continue;
2839
+ if (source || own(now, key) === void 0) now[key] = text;
2840
+ }
2841
+ return now;
2842
+ }
2729
2843
  function confirmFromDisk(cfg, catalogs, registry) {
2730
2844
  const source = catalogs[cfg.sourceLocale] ?? emptyCatalog();
2731
2845
  const stale = /* @__PURE__ */ new Set();
@@ -2952,7 +3066,7 @@ function formatTranslateFailures(failed) {
2952
3066
  async function resolveProvider(cfg, model) {
2953
3067
  const configured = cfg.translate.provider;
2954
3068
  if (typeof configured === "function") return configured;
2955
- const { claudeProvider } = await import("./claude-Cf5p2nJo.js");
3069
+ const { claudeProvider } = await import("./claude-BdHVi-s6.js");
2956
3070
  return claudeProvider({ model: model ?? cfg.translate.model });
2957
3071
  }
2958
3072
  function progressOf(job) {
@@ -3009,7 +3123,7 @@ async function translateProject(cfg, options = {}) {
3009
3123
  if (left.length > 0) kept[locale] = left;
3010
3124
  } catch (error) {
3011
3125
  const why = error instanceof Error ? error.message : String(error);
3012
- throw new Error(`could not be saved: ${why}`, { cause: error });
3126
+ throw new Error(`could not be saved: ${why.replace(/^\[verbaly\] /, "")}`, { cause: error });
3013
3127
  }
3014
3128
  };
3015
3129
  const run = await translateCatalogs(cfg, catalogs, provider, {
@@ -3288,8 +3402,7 @@ function githubCheckAnnotations(result, registry, cfg, options = {}) {
3288
3402
  lines.push(file ? `::warning file=${rel(file)}::${text}` : `::warning::${text}`);
3289
3403
  }
3290
3404
  for (const { key, sites } of result.collisions) {
3291
- const texts = new Set(sites.map((place) => place.message)).size;
3292
- const text = escapeData(`"${key}" has ${counted(texts, "text")}, and every place shows the first one`);
3405
+ const text = escapeData(`"${key}" has ${counted(new Set(sites.map((place) => place.message)).size, "text")}, and every place shows the first one`);
3293
3406
  for (const place of sites) lines.push(`::error ${at(place.file, place.line)}::${text}`);
3294
3407
  }
3295
3408
  for (const { key, code } of result.divergent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbaly/compiler",
3
- "version": "0.86.2",
3
+ "version": "0.87.0",
4
4
  "description": "Message extraction and type-safe codegen for Verbaly.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -46,13 +46,13 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@babel/parser": "^8.1.2",
49
+ "@babel/parser": "^8.1.3",
50
50
  "jiti": "^2.7.0",
51
51
  "jsonc-parser": "^3.3.1",
52
52
  "magic-string": "^1.4.5",
53
53
  "picomatch": "^4.0.7",
54
54
  "tinyglobby": "^0.2.17",
55
- "verbaly": "0.86.2"
55
+ "verbaly": "0.87.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@anthropic-ai/sdk": ">=0.110.0"
@@ -63,11 +63,11 @@
63
63
  }
64
64
  },
65
65
  "devDependencies": {
66
- "@anthropic-ai/sdk": "^1.8.0",
67
- "@babel/types": "^8.1.2",
66
+ "@anthropic-ai/sdk": "^1.14.0",
67
+ "@babel/types": "^8.1.3",
68
68
  "@types/picomatch": "^4.0.3",
69
69
  "esbuild": "^0.28.2",
70
- "fast-check": "^4.10.2",
70
+ "fast-check": "^4.11.0",
71
71
  "happy-dom": "^21.0.4"
72
72
  },
73
73
  "scripts": {