@verbaly/compiler 0.51.0 → 0.53.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
@@ -215,7 +215,9 @@ export default {
215
215
  };
216
216
  ```
217
217
 
218
- `render` keeps reading the full catalogs, so those pages still publish translated; the browser just stops fetching that text. Entries are key prefixes matched whole segment by whole segment, so `nav` never takes `navbar` with it, and `changelog.v1` excludes one version instead of the group. Measured on this project's own docs site: the file every page loads went from **46.3 KB to 33.5 KB brotli** with nothing lost on screen.
218
+ `render` keeps reading the full catalogs, so those pages still publish translated; the browser just stops fetching that text. Entries are key prefixes matched whole segment by whole segment, so `nav` never takes `navbar` with it, and `changelog.v1` excludes one version instead of the group. Measured on this project's own docs site: the locale chunk goes from **55.6 KB to 39.3 KB brotli** with nothing lost on screen.
219
+
220
+ **It composes with `render.inlineCatalog`, it is not replaced by it.** With both on, a mirrored page ships only the messages it renders (**2.86 KB brotli** on that site's home) and fetches no chunk at all, while the exclusion caps what a visitor would download on the day something does need the catalog.
219
221
 
220
222
  **Use it for text `render` covers.** A key that is excluded and then asked for at runtime resolves to itself, like any absent key, and `bindDom` leaves the pre-rendered text alone rather than painting the key over it. The build says so when a prefix matches nothing, and when your code reads an excluded key through `t()`. To use an excluded group at runtime anyway, load it yourself:
221
223
 
@@ -244,21 +246,23 @@ The package exports two layers, and **nothing else is public**. Anything you can
244
246
 
245
247
  `VerbalyConfig` · `ResolvedConfig` · `RenderConfig` · `RedirectConfig` · `BundleConfig` · `TranslateConfig` · `GlossaryEntry` · `TranslateProvider` · `TranslateRequest` · `TranslateResult` · `TranslateOptions` · `TranslateProgress` · `TranslateFailure`
246
248
 
247
- **Building an integration.** This is exactly what `@verbaly/vite`, `@verbaly/unplugin`, `@verbaly/next`, `@verbaly/astro`, `@verbaly/nuxt` and `@verbaly/mcp` consume, so a third one has everything they have:
249
+ **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:
248
250
 
249
251
  | Area | Exports |
250
252
  | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
251
- | Config & catalogs | `loadConfig` `resolveConfig` `loadCatalogs` `writeCatalog` `clientCatalogs` `needsIcu` `needsRelative` · types `Catalog` `Catalogs` |
253
+ | Setup | `init` · types `Host` `InitOptions` `InitResult` |
254
+ | Config & catalogs | `loadConfig` `resolveConfig` `targetLocales` `loadCatalogs` `readCatalog` `writeCatalog` `clientCatalogs` `needsIcu` `needsRelative` · types `Catalog` `Catalogs` |
252
255
  | Extraction | `extractProject` `collectOrigins` `syncCatalogs` `pruneCatalogs` `MessageRegistry` `stableKey` · type `SyncResult` |
253
- | Codegen | `generateDts` `writeDts` `generateRuntimeModule` `generateLocaleModule` · type `RuntimeModuleOptions` |
256
+ | Codegen | `generateDts` `writeDts` `generateRuntimeModule` `generateLocaleModule` · types `DtsOptions` `RuntimeModuleOptions` |
254
257
  | Bundler plumbing | `transformSource` `transformCode` `runBuildGate` `createSourceFilter` `isTransformTarget` `resolveVirtualId` `loadVirtualModule` `RESOLVED_VIRTUAL_ID` `LOCALE_MODULE_PREFIX` `SOURCE_FILE_RE` · types `PluginOptions` `TransformResult` |
255
- | The gate | `check` `formatCheckResult` `formatCheckWarnings` · types `CheckResult` `MissingEntry` `UnknownEntry` `BrokenEntry` `IssueSeverity` |
258
+ | The gate | `check` `validateMessage` `validatePair` `formatCheckResult` `formatCheckWarnings` · types `CheckResult` `MissingEntry` `UnknownEntry` `BrokenEntry` `StructureIssue` `IssueSeverity` |
256
259
  | Coverage | `status` `formatStatusResult` `counted` · types `StatusResult` `LocaleStatus` |
257
- | Draft review | `loadDrafts` `saveDrafts` `markDrafts` `effectiveDrafts` · type `Drafts` |
260
+ | Draft review | `loadDrafts` `saveDrafts` `markDrafts` `clearDrafts` `effectiveDrafts` `DRAFTS_FILE` · type `Drafts` |
258
261
  | Translation | `translateCatalogs` `resolveProvider` `formatTranslateFailures` |
259
262
  | Diagnosis | `doctor` `formatDoctorEntry` · types `DoctorResult` `DoctorEntry` |
260
- | Onboarding | `wrapProject` · types `WrapResult` `WrapEntry` `WrapSkip` `WrapOptions` |
261
- | Static rendering | `renderSite` `formatRenderWarnings` · types `RenderSiteOptions` `RenderSiteResult` |
263
+ | Onboarding | `wrapProject` · types `WrapResult` `WrapEntry` `WrapSkip` `WrapBlocked` `WrapOptions` |
264
+ | Static rendering | `renderSite` `formatRenderWarnings` · types `RenderSiteOptions` `RenderSiteResult` |
265
+ | Error output | `formatCliError` |
262
266
 
263
267
  A minimal plugin is `loadConfig` + `loadCatalogs` once, then `transformSource` per file and `runBuildGate` at the end:
264
268
 
package/dist/cli.js CHANGED
@@ -520,7 +520,7 @@ function validatePair(source, translated) {
520
520
  const newParams = surplus(paramNames(translated), paramNames(source));
521
521
  if (lostParams.length > 0) issues.push({
522
522
  severity: "error",
523
- message: `${list(lostParams.map((name) => `{${name}}`))} ${lostParams.length > 1 ? "are" : "is"} missing, so ${lostParams.length > 1 ? "their values" : "its value"} never reaches the text`
523
+ message: `${list(lostParams.map((name) => `{${name}}`))} ${lostParams.length > 1 ? "are" : "is"} missing, so ${lostParams.length > 1 ? "their values never reach" : "its value never reaches"} the text`
524
524
  });
525
525
  if (newParams.length > 0) issues.push({
526
526
  severity: "error",
@@ -1448,8 +1448,8 @@ async function extractProject(cfg) {
1448
1448
  for (const file of files) registry.update(file, analyzeFile(readFileSync(file, "utf8"), file));
1449
1449
  return registry;
1450
1450
  }
1451
- async function collectOrigins(cfg) {
1452
- const registry = await extractProject(cfg);
1451
+ async function collectOrigins(cfg, reuse) {
1452
+ const registry = reuse ?? await extractProject(cfg);
1453
1453
  const origins = {};
1454
1454
  for (const [key, files] of registry.origins()) origins[key] = files.map((file) => relative(cfg.root, file).replaceAll("\\", "/"));
1455
1455
  return origins;
@@ -2487,6 +2487,10 @@ function renderHtml(html, options) {
2487
2487
  if (tagName === "a" || tagName === "area") {
2488
2488
  const inside = mirroredHref(attrs.get("href"), mirror);
2489
2489
  if (inside) setAttribute(ms, html, chunkStart, openEnd, attrChunk, "href", inside);
2490
+ } else if (tagName === "form" || tagName === "button" || tagName === "input") {
2491
+ const name = tagName === "form" ? "action" : "formaction";
2492
+ const inside = mirroredHref(attrs.get(name), mirror);
2493
+ if (inside) setAttribute(ms, html, chunkStart, openEnd, attrChunk, name, inside);
2490
2494
  } else if (tagName === "meta" && attrs.get("http-equiv")?.toLowerCase() === "refresh") {
2491
2495
  const content = attrs.get("content") ?? "";
2492
2496
  const url = /^([^;]*;\s*url\s*=\s*)(.*)$/i.exec(decodeEntities(content));
@@ -2506,11 +2510,17 @@ function renderHtml(html, options) {
2506
2510
  if (close) {
2507
2511
  const text = t(key, args);
2508
2512
  const own = parseArgs$1(attrs.get(linksAttr));
2509
- const links = own ? globalLinks ? {
2513
+ const merged = own ? globalLinks ? {
2510
2514
  ...globalLinks,
2511
2515
  ...own
2512
2516
  } : own : globalLinks;
2513
- const content = attrs.has(richAttr) ? richToHtml(parseTags(text), richTags, links) : escapeHtml(text);
2517
+ const links = mirror ? mirroredLinks(merged, mirror) : merged;
2518
+ const nodes = attrs.has(richAttr) ? parseTags(text) : [];
2519
+ if (mirror && links) {
2520
+ const carried = usedLinks(nodes, links);
2521
+ if (carried && JSON.stringify(carried) !== JSON.stringify(own)) setAttribute(ms, html, chunkStart, openEnd, attrChunk, linksAttr, JSON.stringify(carried));
2522
+ }
2523
+ const content = attrs.has(richAttr) ? richToHtml(nodes, richTags, links) : escapeHtml(text);
2514
2524
  if (html.slice(openEnd, close.contentEnd) !== content) {
2515
2525
  if (openEnd === close.contentEnd) ms.appendLeft(openEnd, content);
2516
2526
  else ms.overwrite(openEnd, close.contentEnd, content);
@@ -2557,6 +2567,31 @@ function publicPath(rel) {
2557
2567
  const path = `/${rel.replace(/(^|\/)index\.html$/, "$1")}`;
2558
2568
  return path.length > 1 ? path.replace(/\/+$/, "") : path;
2559
2569
  }
2570
+ function usedLinks(nodes, links) {
2571
+ const out = {};
2572
+ const walk = (list) => {
2573
+ for (const node of list) {
2574
+ if (typeof node === "string") continue;
2575
+ if (links[node.name] !== void 0) out[node.name] = links[node.name];
2576
+ walk(node.children);
2577
+ }
2578
+ };
2579
+ walk(nodes);
2580
+ return Object.keys(out).length > 0 ? out : void 0;
2581
+ }
2582
+ function mirroredLinks(links, mirror) {
2583
+ if (!links) return links;
2584
+ const out = {};
2585
+ for (const [name, link] of Object.entries(links)) {
2586
+ const inside = mirroredHref(typeof link === "string" ? link : link.href, mirror);
2587
+ if (inside === void 0) out[name] = link;
2588
+ else out[name] = typeof link === "string" ? inside : {
2589
+ ...link,
2590
+ href: inside
2591
+ };
2592
+ }
2593
+ return out;
2594
+ }
2560
2595
  function mirroredHref(raw, mirror) {
2561
2596
  if (raw === void 0) return void 0;
2562
2597
  const href = decodeEntities(raw);