@verbaly/compiler 0.81.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 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
 
@@ -42,6 +46,8 @@ npx verbaly render # pre-fill data-verbaly HTML per locale (SSG, kills t
42
46
 
43
47
  Reads `verbaly.config.{js,mjs,ts,mts,json}` (a TypeScript config is read as written, including imports without an extension, and needs nothing installed for it). Generates `locales/<locale>.json` (portable JSON, flat or nested, whichever the file already is) and the TypeScript types of your messages, [where your framework looks for them](#-typed-keys-and-where-the-types-live).
44
48
 
49
+ `--locales es,pt` narrows a command to those languages. It picks among the ones the project has: a language it does not have is an error that lists them and says how to start a new one, so a typo never reads as a language with nothing to do.
50
+
45
51
  ## 🚦 The gate: `check` in CI, a report in every build
46
52
 
47
53
  `verbaly check` is the only command that exits 1. Run it in CI: it is the strict gate, and it asks four questions.
@@ -160,9 +166,9 @@ In CI, write the types before you check them, since a fresh clone has none: `npx
160
166
 
161
167
  ## 🚚 Coming from i18next
162
168
 
163
- `npx verbaly init` keeps the catalogs a project already has: it points the config at `src/locales`, or wherever they are, instead of starting a second set, and its next steps name `migrate` when your dependencies have i18next. `npx verbaly migrate` reports what it would change in those catalogs, and `--write` applies it: `{{name}}` becomes `{name}`, and a brace i18next showed as text is doubled, so it stays text. A format, an unescape or a nesting is left to you, each with its reason. `verbaly.lock` remembers which languages were converted, so a later run, like `--plurals` to merge `_one` and `_other` into one message, never reads them as i18next again.
169
+ `npx verbaly init` keeps the catalogs a project already has: it points the config at `src/locales`, or wherever they are, instead of starting a second set, and its next steps name `migrate` when your dependencies have i18next. `npx verbaly migrate` reports what it would change in those catalogs, and `--write` applies it: `{{name}}` becomes `{name}`, and a brace i18next showed as text is doubled, so it stays text. A format, an unescape or a nesting is left to you, each with its reason, and every run lists the ones still waiting. `verbaly.lock` remembers which languages were converted, so a later run, like `--plurals` to merge `_one` and `_other` into one message, never reads them as i18next again.
164
170
 
165
- While i18next still serves some screens, give it `interpolation: { prefix: '{', suffix: '}' }` and both libraries read the converted files.
171
+ While i18next still serves some screens, give it `interpolation: { prefix: '{', suffix: '}' }` and both libraries read the converted files. A `t` or a `Trans` a component still takes from react-i18next, next-i18next, next-translate, ttag or Lingui is left exactly as written, so you can move one component at a time.
166
172
 
167
173
  ## 🤖 Machine translation
168
174
 
@@ -266,7 +272,7 @@ npx verbaly export --format po # gettext PO (msgctxt = key, works with an
266
272
  npx verbaly import verbaly-export/es.xlf # fill the catalog back
267
273
  ```
268
274
 
269
- `export` writes one file per target locale with the source text alongside the current translation (`--missing` exports only the untranslated entries). Every entry carries **where the text lives in your source** (XLIFF `location` notes, a `location` column in CSV, `#:` comments in PO), so translators and TMS tools see the context instead of guessing it. In XLIFF, `{params}` and rich tags travel as **protected inline codes with semantic ids** (`<ph id="name"/>`, `<pc id="em">`), so TMS editors show them as untouchable chips instead of editable raw syntax. `import` reads XLIFF 2.0/1.2, CSV or PO back (PO entries flagged `fuzzy` count as untranslated) and **validates every entry like `translate` does**: a translation that drops a `{param}`, a variant block or an `<em>` tag is rejected and reported, so a translator's typo can't break your UI. Existing translations are kept unless `--overwrite`; `--dry-run` previews everything.
275
+ `export` writes one file per target locale with the source text alongside the current translation (`--missing` exports only the untranslated entries). Every entry carries **where the text lives in your source** (XLIFF `location` notes, a `location` column in CSV, `#:` comments in PO), so translators and TMS tools see the context instead of guessing it. In XLIFF, `{params}` and rich tags travel as **protected inline codes with semantic ids** (`<ph id="name"/>`, `<pc id="em">`), so TMS editors show them as untouchable chips instead of editable raw syntax. `import` reads XLIFF 2.0/1.2, CSV or PO back (PO entries flagged `fuzzy` count as untranslated, and a CSV a spreadsheet saved with semicolons or tabs reads like one with commas) and **validates every entry like `translate` does**: a translation that drops a `{param}`, a variant block or an `<em>` tag is rejected and reported, so a translator's typo can't break your UI. Existing translations are kept unless `--overwrite`; `--dry-run` previews everything.
270
276
 
271
277
  A file names its language the way its tool writes it, so `import` reads that name as one of your locales: gettext's `pt_BR` (or a `PT-br`) fills the `pt-BR` you have. A file for a new language starts its catalog, under the tag's proper spelling, unless your config lists its `locales`: then a language outside that list is skipped with a warning and exit code 1, because the app would never load it. Add the locale to the list first, or pass `--locale`.
272
278
 
@@ -351,21 +357,21 @@ The package exports two layers, and **nothing else is public**. Anything you can
351
357
 
352
358
  **Building an integration.** This is exactly what `@verbaly/vite`, `@verbaly/unplugin`, `@verbaly/next`, `@verbaly/astro`, `@verbaly/nuxt`, `@verbaly/mcp` and `@verbaly/studio` consume, so a third one has everything they have:
353
359
 
354
- | Area | Exports |
355
- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
356
- | Setup | `init` · types `Host` `InitOptions` `InitResult` |
357
- | Config & catalogs | `loadConfig` `resolveConfig` `targetLocales` `loadCatalogs` `readCatalog` `parseCatalog` `writeCatalog` `clientCatalogs` `needsIcu` `needsRelative` · types `Catalog` `Catalogs` |
358
- | Extraction | `syncProject` `extractProject` `collectOrigins` `syncCatalogs` `shippedCatalogs` `pruneCatalogs` `MessageRegistry` `stableKey` `watchTree` · types `SyncProjectResult` `SyncResult` `TreeOptions` |
359
- | Codegen | `generateDts` `writeDts` `generateRuntimeModule` `generateLocaleModule` · types `DtsOptions` `RuntimeModuleOptions` |
360
- | Bundler plumbing | `transformSource` `transformCode` `runBuildGate` `writeBuildTypes` `createSourceFilter` `reportOutsideInclude` `isTransformTarget` `resolveVirtualId` `loadVirtualModule` `APP_ID` `LOCALE_IMPORT` `RESOLVED_VIRTUAL_ID` `LOCALE_MODULE_PREFIX` `SOURCE_FILE_RE` · types `PluginOptions` `TransformResult` |
361
- | The gate | `check` `validateMessage` `validatePair` `formatCheckResult` `formatCheckWarnings` `collisionEntries` `formatCollision` `formatFinding` `createDevReporter` · types `Finding` `DevReporter` `CheckResult` `MissingEntry` `UnknownEntry` `BrokenEntry` `ExtraEntry` `CollisionEntry` `DivergentEntry` `OutdatedEntry` `SourceSite` `StructureIssue` `IssueSeverity` |
362
- | Coverage | `status` `formatStatusResult` `counted` · types `StatusResult` `LocaleStatus` |
363
- | Review state | `loadDrafts` `saveDrafts` `markDrafts` `clearDrafts` `effectiveDrafts` `loadState` `readState` `updateState` `recordTranslations` `outdatedTranslations` `STATE_FILE` · types `Drafts` `State` `Fingerprints` `TranslationWrite` |
364
- | Translation | `translateCatalogs` `mergeTranslations` `writeDrafts` `resolveProvider` `formatTranslateFailures` · types `DraftEntry` `WriteDraftsResult` |
365
- | Diagnosis | `doctor` `formatDoctorEntry` `formatDoctorHealth` · types `DoctorResult` `DoctorEntry` |
366
- | Onboarding | `wrapProject` · types `WrapResult` `WrapEntry` `WrapSkip` `WrapBlocked` `WrapOptions` |
367
- | Static rendering | `renderSite` `formatRenderWarnings` · types `RenderSiteOptions` `RenderSiteResult` |
368
- | Error output | `formatCliError` |
360
+ | Area | Exports |
361
+ | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
362
+ | Setup | `init` · types `Host` `InitOptions` `InitResult` |
363
+ | Config & catalogs | `loadConfig` `resolveConfig` `targetLocales` `loadCatalogs` `readCatalog` `parseCatalog` `writeCatalog` `clientCatalogs` `needsIcu` `needsRelative` · types `Catalog` `Catalogs` |
364
+ | Extraction | `syncProject` `extractProject` `collectOrigins` `syncCatalogs` `shippedCatalogs` `pruneCatalogs` `MessageRegistry` `stableKey` `watchTree` · types `SyncProjectResult` `SyncResult` `TreeOptions` |
365
+ | Codegen | `generateDts` `writeDts` `generateRuntimeModule` `generateLocaleModule` · types `DtsOptions` `RuntimeModuleOptions` |
366
+ | Bundler plumbing | `transformSource` `transformCode` `runBuildGate` `writeBuildTypes` `createSourceFilter` `reportOutsideInclude` `isTransformTarget` `resolveVirtualId` `loadVirtualModule` `clientModules` `APP_ID` `LOCALE_IMPORT` `RESOLVED_VIRTUAL_ID` `LOCALE_MODULE_PREFIX` `SOURCE_FILE_RE` · types `PluginOptions` `TransformResult` |
367
+ | The gate | `check` `relativeCheck` `validateMessage` `validatePair` `formatCheckResult` `formatCheckWarnings` `collisionEntries` `formatCollision` `formatFinding` `createDevReporter` · types `Finding` `DevReporter` `CheckResult` `MissingEntry` `UnknownEntry` `BrokenEntry` `ExtraEntry` `CollisionEntry` `DivergentEntry` `OutdatedEntry` `SourceSite` `StructureIssue` `IssueSeverity` |
368
+ | Coverage | `status` `formatStatusResult` `counted` · types `StatusResult` `LocaleStatus` |
369
+ | Review state | `loadDrafts` `saveDrafts` `markDrafts` `clearDrafts` `effectiveDrafts` `loadState` `readState` `updateState` `recordTranslations` `outdatedTranslations` `STATE_FILE` · types `Drafts` `State` `Fingerprints` `TranslationWrite` |
370
+ | Translation | `translateProject` `translateCatalogs` `mergeTranslations` `writeDrafts` `resolveProvider` `formatTranslateFailures` · types `TranslateProjectOptions` `TranslateProjectResult` `DraftEntry` `WriteDraftsResult` |
371
+ | Diagnosis | `doctor` `formatDoctorEntry` `formatDoctorHealth` · types `DoctorResult` `DoctorEntry` |
372
+ | Onboarding | `wrapProject` `formatWrapResult` · types `WrapResult` `WrapEntry` `WrapSkip` `WrapBlocked` `WrapOptions` |
373
+ | Static rendering | `renderSite` `formatRenderWarnings` · types `RenderSiteOptions` `RenderSiteResult` |
374
+ | Error output | `formatCliError` |
369
375
 
370
376
  A minimal plugin is `loadConfig` + `loadCatalogs` once, then `transformSource` per file and `runBuildGate` at the end:
371
377
 
@@ -1,11 +1,12 @@
1
- import { _t as isModuleNotFound, ut as counted } from "./run-DitFmP5s.js";
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([
5
5
  "claude-sonnet-5-5",
6
6
  "claude-opus-5-5",
7
7
  "claude-opus-5",
8
- "claude-fable-5-1"
8
+ "claude-fable-5-1",
9
+ "claude-fable-5-2"
9
10
  ]);
10
11
  const FALLBACK_BETA = "server-side-fallback-2026-07-01";
11
12
  function thinkingFor(model) {
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-DitFmP5s.js";
2
+ import { n as runCli, t as formatCliError } from "./run-BBxX6CcL.js";
3
3
  // src/cli.ts
4
4
  runCli().catch((error) => {
5
5
  console.error(formatCliError(error));
package/dist/index.d.ts CHANGED
@@ -80,6 +80,28 @@ export declare class MessageRegistry {
80
80
  origins(): Map<string, string[]>;
81
81
  private inOrder;
82
82
  }
83
+ export declare const STATE_FILE = "verbaly.lock";
84
+ type Drafts = Record<string, string[]>;
85
+ type Fingerprints = Record<string, Record<string, string>>;
86
+ interface State {
87
+ drafts: Drafts;
88
+ fingerprints: Fingerprints;
89
+ migrated?: string[];
90
+ }
91
+ interface StateRead {
92
+ state: State;
93
+ problem?: string;
94
+ conflict?: true;
95
+ }
96
+ interface LockEntry {
97
+ file: string;
98
+ from?: string;
99
+ merged?: true;
100
+ }
101
+ export declare function loadState(cfg: ResolvedConfig): State;
102
+ export declare function readState(cfg: ResolvedConfig): StateRead;
103
+ export declare function markDrafts(drafts: Drafts, locale: string, keys: string[]): void;
104
+ export declare function clearDrafts(drafts: Drafts, locale: string, keys?: string[]): void;
83
105
  interface TranslateRequest {
84
106
  sourceLocale: string;
85
107
  targetLocale: string;
@@ -128,6 +150,7 @@ interface WriteDraftsResult {
128
150
  kept: string[];
129
151
  invalid: string[];
130
152
  unknown: string[];
153
+ lock?: LockEntry;
131
154
  }
132
155
  interface WriteDraftsOptions {
133
156
  overwrite?: boolean;
@@ -137,6 +160,7 @@ export declare function writeDrafts(cfg: ResolvedConfig, locale: string, entries
137
160
  export declare function formatTranslateFailures(failed: TranslateFailure[]): string[];
138
161
  export declare function resolveProvider(cfg: ResolvedConfig, model?: string): Promise<TranslateProvider>;
139
162
  type GlossaryEntry = string | Record<string, string>;
163
+ export declare const SOURCE_FILE_RE: RegExp;
140
164
  interface TranslateConfig {
141
165
  provider?: 'claude' | TranslateProvider;
142
166
  model?: string;
@@ -223,23 +247,10 @@ export declare function shippedCatalogs(cfg: ResolvedConfig, catalogs: Catalogs,
223
247
  newKeys?: boolean;
224
248
  }): Catalogs;
225
249
  export declare function pruneCatalogs(cfg: ResolvedConfig, catalogs: Catalogs, registry: MessageRegistry): Record<string, string[]>;
226
- export declare const STATE_FILE = "verbaly.lock";
227
- type Drafts = Record<string, string[]>;
228
- type Fingerprints = Record<string, Record<string, string>>;
229
- interface State {
230
- drafts: Drafts;
231
- fingerprints: Fingerprints;
232
- migrated?: string[];
233
- }
234
250
  interface OutdatedEntry {
235
251
  locale: string;
236
252
  key: string;
237
253
  }
238
- interface StateRead {
239
- state: State;
240
- problem?: string;
241
- conflict?: true;
242
- }
243
254
  interface WrittenTranslation {
244
255
  key: string;
245
256
  text: string;
@@ -250,18 +261,9 @@ interface TranslationWrite {
250
261
  entries: WrittenTranslation[];
251
262
  draft?: boolean;
252
263
  }
253
- interface LockEntry {
254
- file: string;
255
- from?: string;
256
- merged?: true;
257
- }
258
- export declare function loadState(cfg: ResolvedConfig): State;
259
- export declare function readState(cfg: ResolvedConfig): StateRead;
260
264
  export declare function updateState(cfg: ResolvedConfig, catalogs: Catalogs): State;
261
265
  export declare function recordTranslations(cfg: ResolvedConfig, source: Catalog, writes: TranslationWrite[]): State;
262
266
  export declare function effectiveDrafts(drafts: Drafts, catalogs: Catalogs): Drafts;
263
- export declare function markDrafts(drafts: Drafts, locale: string, keys: string[]): void;
264
- export declare function clearDrafts(drafts: Drafts, locale: string, keys?: string[]): void;
265
267
  export declare function outdatedTranslations(cfg: ResolvedConfig, catalogs: Catalogs, fingerprints: Fingerprints): OutdatedEntry[];
266
268
  interface SourceSite {
267
269
  file: string;
@@ -316,8 +318,15 @@ type Finding = ({
316
318
  export declare function collisionEntries(registry: MessageRegistry): CollisionEntry[];
317
319
  export declare function formatCollision({ key, sites }: CollisionEntry, root?: string): string;
318
320
  export declare function formatFinding(finding: Finding, root?: string): string;
321
+ interface DevSync {
322
+ findings: Finding[];
323
+ catalogs: Catalogs;
324
+ state?: State;
325
+ stateProblem?: string;
326
+ }
319
327
  interface DevReporter {
320
328
  report(channel: string, findings: Finding[]): void;
329
+ sync(cfg: ResolvedConfig, result: DevSync, edited: (finding: ReplacedEntry) => boolean | undefined): void;
321
330
  }
322
331
  export declare function createDevReporter(root: string, print?: (line: string) => void, cap?: number): DevReporter;
323
332
  interface SyncProjectOptions {
@@ -343,6 +352,22 @@ interface SyncProjectResult {
343
352
  stateProblem?: string;
344
353
  }
345
354
  export declare function syncProject(cfg: ResolvedConfig, options?: SyncProjectOptions): Promise<SyncProjectResult>;
355
+ interface TranslateProjectOptions {
356
+ locales?: string[];
357
+ dryRun?: boolean;
358
+ model?: string;
359
+ provider?: TranslateProvider;
360
+ onProgress?: (progress: TranslateProgress) => void;
361
+ }
362
+ interface TranslateProjectResult {
363
+ pending: Record<string, string[]>;
364
+ written: Record<string, string[]>;
365
+ kept: Record<string, string[]>;
366
+ invalid: Record<string, string[]>;
367
+ failed: TranslateFailure[];
368
+ lock?: LockEntry;
369
+ }
370
+ export declare function translateProject(cfg: ResolvedConfig, options?: TranslateProjectOptions): Promise<TranslateProjectResult>;
346
371
  export declare function stableKey(message: string): string;
347
372
  interface RuntimeModuleOptions {
348
373
  localeImport?: (locale: string) => string;
@@ -378,8 +403,12 @@ interface PluginOptions extends VerbalyConfig {
378
403
  }
379
404
  export declare const RESOLVED_VIRTUAL_ID: string;
380
405
  export declare const LOCALE_MODULE_PREFIX = "\0virtual:verbaly/locale/";
381
- export declare const SOURCE_FILE_RE: RegExp;
382
406
  export declare function resolveVirtualId(id: string): string | undefined;
407
+ interface ClientModules {
408
+ runtime(): string;
409
+ locale(locale: string): string;
410
+ }
411
+ export declare function clientModules(cfg: ResolvedConfig, catalogs: Catalogs, options?: Pick<RuntimeModuleOptions, 'localeImport' | 'extraExports'>): ClientModules;
383
412
  export declare function loadVirtualModule(id: string, cfg: ResolvedConfig, catalogs: Catalogs): string | undefined;
384
413
  export declare function isTransformTarget(id: string): boolean;
385
414
  export declare function createSourceFilter(cfg: ResolvedConfig): (id: string) => boolean;
@@ -432,6 +461,7 @@ interface CheckResult {
432
461
  divergent: DivergentEntry[];
433
462
  outdated: OutdatedEntry[];
434
463
  }
464
+ export declare function relativeCheck(root: string, result: CheckResult): CheckResult;
435
465
  export declare function check(cfg: ResolvedConfig, catalogs: Catalogs, registry: MessageRegistry, fingerprints?: Fingerprints): CheckResult;
436
466
  export declare function formatCheckResult(result: CheckResult, root?: string): string;
437
467
  interface CheckReportOptions {
@@ -526,6 +556,12 @@ interface WrapOptions {
526
556
  write?: boolean;
527
557
  }
528
558
  export declare function wrapProject(cfg: ResolvedConfig, options?: WrapOptions): Promise<WrapResult>;
559
+ interface WrapReport {
560
+ counts: string;
561
+ lines: string[];
562
+ files: number;
563
+ }
564
+ export declare function formatWrapResult(result: WrapResult, write: boolean): WrapReport;
529
565
  interface RenderSiteOptions {
530
566
  site?: string;
531
567
  locales?: string[];
@@ -548,4 +584,4 @@ interface RenderSiteResult {
548
584
  }
549
585
  export declare function renderSite(cfg: ResolvedConfig, options?: RenderSiteOptions): Promise<RenderSiteResult>;
550
586
  export declare function formatRenderWarnings(result: RenderSiteResult, sourceLocale: string): string[];
551
- export type { BrokenEntry, BundleConfig, Catalog, Catalogs, CheckResult, CollisionEntry, DevReporter, DivergentEntry, DoctorEntry, DoctorResult, DraftEntry, Drafts, DtsOptions, ExtraEntry, Finding, Fingerprints, GlossaryEntry, Host, InitOptions, InitResult, IssueSeverity, LocaleStatus, MissingEntry, OutdatedEntry, PluginOptions, RedirectConfig, RenderConfig, RenderSiteOptions, RenderSiteResult, ResolvedConfig, RuntimeModuleOptions, SourceSite, State, StatusResult, StructureIssue, SyncProjectResult, SyncResult, TransformResult, TranslateConfig, TranslateFailure, TranslateOptions, TranslateProgress, TranslateProvider, TranslateRequest, TranslateResult, TranslationWrite, TreeOptions, UnknownEntry, VerbalyConfig, WrapBlocked, WrapEntry, WrapOptions, WrapResult, WrapSkip, WriteDraftsResult };
587
+ export type { BrokenEntry, BundleConfig, Catalog, Catalogs, CheckResult, ClientModules, CollisionEntry, DevReporter, DivergentEntry, DoctorEntry, DoctorResult, DraftEntry, Drafts, DtsOptions, ExtraEntry, Finding, Fingerprints, GlossaryEntry, Host, InitOptions, InitResult, IssueSeverity, LocaleStatus, MissingEntry, OutdatedEntry, PluginOptions, RedirectConfig, RenderConfig, RenderSiteOptions, RenderSiteResult, ResolvedConfig, RuntimeModuleOptions, SourceSite, State, StatusResult, StructureIssue, SyncProjectResult, SyncResult, TransformResult, TranslateConfig, TranslateFailure, TranslateOptions, TranslateProgress, TranslateProjectOptions, TranslateProjectResult, TranslateProvider, TranslateRequest, TranslateResult, TranslationWrite, TreeOptions, UnknownEntry, VerbalyConfig, WrapBlocked, WrapEntry, WrapOptions, WrapResult, WrapSkip, WriteDraftsResult };
package/dist/index.js CHANGED
@@ -1,4 +1,148 @@
1
- import { $ as validatePair, A as check, B as readState, C as isTransformTarget, D as transformSource, E as runBuildGate, F as clearDrafts, G as createDevReporter, H as saveState, I as effectiveDrafts, J as generateDts, K as formatCollision, L as loadState, M as formatCheckWarnings, N as syncProject, O as writeBuildTypes, P as STATE_FILE, Q as validateMessage, R as markDrafts, S as createSourceFilter, T as resolveVirtualId, U as updateState, V as recordTranslations, W as collisionEntries, X as generateRuntimeModule, Y as generateLocaleModule, Z as writeDts, _ as status, a as renderSite, at as stableKey, b as RESOLVED_VIRTUAL_ID, bt as targetLocales, c as formatTranslateFailures, ct as MessageRegistry, d as translateCatalogs, dt as loadCatalogs, et as collectOrigins, f as writeDrafts, ft as needsIcu, g as formatStatusResult, gt as writeCatalog, h as formatDoctorHealth, ht as readCatalog, i as formatRenderWarnings, it as syncCatalogs, j as formatCheckResult, k as transformCode, l as mergeTranslations, lt as clientCatalogs, m as formatDoctorEntry, mt as parseCatalog, nt as pruneCatalogs, o as init, ot as APP_ID, p as doctor, pt as needsRelative, q as formatFinding, r as wrapProject, rt as shippedCatalogs, s as watchTree, st as LOCALE_IMPORT, t as formatCliError, tt as extractProject, u as resolveProvider, ut as counted, v as reportOutsideInclude, vt as loadConfig, w as loadVirtualModule, x as SOURCE_FILE_RE, y as LOCALE_MODULE_PREFIX, yt as resolveConfig, z as outdatedTranslations } from "./run-DitFmP5s.js";
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;
@@ -10,4 +154,4 @@ function saveDrafts(cfg, drafts) {
10
154
  drafts
11
155
  });
12
156
  }
13
- export { APP_ID, LOCALE_IMPORT, 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, writeBuildTypes, writeCatalog, writeDrafts, writeDts };
157
+ export { APP_ID, LOCALE_IMPORT, LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, STATE_FILE, check, clearDrafts, clientCatalogs, clientModules, collectOrigins, collisionEntries, counted, createDevReporter, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatCliError, formatCollision, formatDoctorEntry, formatDoctorHealth, formatFinding, formatRenderWarnings, formatStatusResult, formatTranslateFailures, formatWrapResult, generateDts, generateLocaleModule, generateRuntimeModule, init, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadState, loadVirtualModule, markDrafts, mergeTranslations, needsIcu, needsRelative, outdatedTranslations, parseCatalog, pruneCatalogs, readCatalog, readState, recordTranslations, relativeCheck, renderSite, reportOutsideInclude, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, shippedCatalogs, stableKey, status, syncCatalogs, syncProject, targetLocales, transformCode, transformSource, translateCatalogs, translateProject, updateState, validateMessage, validatePair, watchTree, wrapProject, writeBuildTypes, writeCatalog, writeDrafts, writeDts };