@verbaly/compiler 0.45.0 → 0.46.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.
@@ -7,14 +7,16 @@ function resolveConfig(config = {}) {
7
7
  const root = resolve(config.root ?? process.cwd());
8
8
  const dir = resolve(root, config.dir ?? "locales");
9
9
  const sourceLocale = config.sourceLocale ?? "en";
10
+ const localesDeclared = config.locales !== void 0;
10
11
  const locales = /* @__PURE__ */ new Set([sourceLocale, ...config.locales ?? []]);
11
- if (existsSync(dir)) {
12
+ if (!localesDeclared && existsSync(dir)) {
12
13
  for (const file of readdirSync(dir)) if (file.endsWith(".json") && !file.startsWith(".") && file !== `en-XA.json`) locales.add(file.slice(0, -5));
13
14
  }
14
15
  return {
15
16
  root,
16
17
  dir,
17
18
  sourceLocale,
19
+ localesDeclared,
18
20
  routing: config.routing ?? (config.render ? "prefix-except-source" : "no-prefix"),
19
21
  icu: config.icu,
20
22
  relative: config.relative,
@@ -79,4 +81,4 @@ function definedOnly(config) {
79
81
  //#endregion
80
82
  export { targetLocales as a, resolveConfig as i, isModuleNotFound as n, loadConfig as r, findConfigFile as t };
81
83
 
82
- //# sourceMappingURL=config-ByO-vjIC.js.map
84
+ //# sourceMappingURL=config-iLrfRYDB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-iLrfRYDB.js","names":[],"sources":["../src/pseudo.ts","../src/config.ts"],"sourcesContent":["import type { Catalog, Catalogs } from './catalog';\nimport type { ResolvedConfig } from './config';\n\nexport const PSEUDO_LOCALE = 'en-XA';\n\nconst ACCENTS: Record<string, string> = {\n a: 'á',\n b: 'ƀ',\n c: 'ç',\n d: 'đ',\n e: 'é',\n f: 'ƒ',\n g: 'ğ',\n h: 'ĥ',\n i: 'í',\n j: 'ĵ',\n k: 'ķ',\n l: 'ĺ',\n m: 'ɱ',\n n: 'ñ',\n o: 'ó',\n p: 'þ',\n q: 'ǫ',\n r: 'ŕ',\n s: 'š',\n t: 'ţ',\n u: 'ú',\n v: 'ṽ',\n w: 'ŵ',\n x: 'ẋ',\n y: 'ý',\n z: 'ž',\n A: 'Á',\n B: 'Ɓ',\n C: 'Ç',\n D: 'Đ',\n E: 'É',\n F: 'Ƒ',\n G: 'Ğ',\n H: 'Ĥ',\n I: 'Í',\n J: 'Ĵ',\n K: 'Ķ',\n L: 'Ĺ',\n M: 'Ḿ',\n N: 'Ñ',\n O: 'Ó',\n P: 'Þ',\n Q: 'Ǫ',\n R: 'Ŕ',\n S: 'Š',\n T: 'Ţ',\n U: 'Ú',\n V: 'Ṽ',\n W: 'Ŵ',\n X: 'Ẍ',\n Y: 'Ý',\n Z: 'Ž',\n};\n\nconst TAG_AT = /<\\/?[a-zA-Z][\\w-]*\\/?>/y;\n\n// params, variant blocks, tags and escapes survive verbatim\nexport function pseudoLocalize(message: string): string {\n let out = '';\n let letters = 0;\n let i = 0;\n while (i < message.length) {\n const two = message.slice(i, i + 2);\n if (two === '{{' || two === '}}' || two === '||' || two === '##') {\n out += two;\n i += 2;\n continue;\n }\n const ch = message[i]!;\n if (ch === '{') {\n const end = matchBrace(message, i);\n out += message.slice(i, end);\n i = end;\n continue;\n }\n if (ch === '<') {\n TAG_AT.lastIndex = i;\n const m = TAG_AT.exec(message);\n if (m) {\n out += m[0];\n i += m[0].length;\n continue;\n }\n }\n const mapped = ACCENTS[ch];\n if (mapped) {\n out += mapped;\n letters += 1;\n } else {\n out += ch;\n }\n i += 1;\n }\n const pad = '~'.repeat(Math.ceil(letters / 3));\n return `⟦${out}${pad ? ' ' + pad : ''}⟧`;\n}\n\nfunction matchBrace(message: string, start: number): number {\n let depth = 0;\n for (let i = start; i < message.length; i++) {\n const two = message.slice(i, i + 2);\n if (two === '{{' || two === '}}') {\n i += 1;\n continue;\n }\n const ch = message[i];\n if (ch === '{') depth += 1;\n else if (ch === '}') {\n depth -= 1;\n if (depth === 0) return i + 1;\n }\n }\n return message.length; // unbalanced → verbatim\n}\n\n// regenerates the whole pseudo catalog from the source catalog\nexport function pseudoCatalogs(\n cfg: ResolvedConfig,\n catalogs: Catalogs,\n locale: string = PSEUDO_LOCALE,\n): string[] {\n const source = catalogs[cfg.sourceLocale] ?? {};\n const target: Catalog = {};\n for (const [key, msg] of Object.entries(source)) {\n target[key] = msg ? pseudoLocalize(msg) : '';\n }\n catalogs[locale] = target;\n return Object.keys(target).filter((key) => target[key]);\n}\n","import { existsSync, readFileSync, readdirSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { RichLink, Routing } from 'verbaly';\nimport { PSEUDO_LOCALE } from './pseudo';\nimport type { TranslateProvider } from './translate';\n\n// a term maps to how it must come out: one rendering for every locale, or one per locale\nexport type GlossaryEntry = string | Record<string, string>;\n\nexport interface TranslateConfig {\n provider?: 'claude' | TranslateProvider;\n model?: string;\n batchSize?: number;\n concurrency?: number;\n retries?: number;\n instructions?: string;\n glossary?: Record<string, GlossaryEntry>;\n}\n\nexport interface RedirectConfig {\n on?: 'root' | 'all';\n storageKey?: string | false;\n}\n\nexport interface BundleConfig {\n exclude?: string[];\n}\n\nexport interface RenderConfig {\n links?: Record<string, RichLink>;\n site?: string;\n attribute?: string;\n base?: string;\n baseUrl?: string;\n hreflang?: boolean;\n sitemap?: boolean | string;\n redirect?: boolean | RedirectConfig;\n clean?: boolean;\n}\n\nexport interface VerbalyConfig {\n root?: string;\n dir?: string;\n sourceLocale?: string;\n locales?: string[];\n routing?: Routing;\n icu?: boolean;\n relative?: boolean;\n include?: string[];\n exclude?: string[];\n dts?: string | false;\n translate?: TranslateConfig;\n render?: RenderConfig;\n bundle?: BundleConfig;\n}\n\nexport interface ResolvedConfig {\n root: string;\n dir: string;\n sourceLocale: string;\n locales: string[];\n localesDeclared: boolean;\n routing: Routing;\n icu: boolean | undefined;\n relative: boolean | undefined;\n include: string[];\n exclude: string[];\n dts: string | false | undefined;\n translate: TranslateConfig;\n render: RenderConfig;\n bundle: BundleConfig;\n}\n\nexport function resolveConfig(config: VerbalyConfig = {}): ResolvedConfig {\n const root = resolve(config.root ?? process.cwd());\n const dir = resolve(root, config.dir ?? 'locales');\n const sourceLocale = config.sourceLocale ?? 'en';\n\n const localesDeclared = config.locales !== undefined;\n const locales = new Set<string>([sourceLocale, ...(config.locales ?? [])]);\n // a declared list is the list: discovery is for a project that never wrote one down\n if (!localesDeclared && existsSync(dir)) {\n for (const file of readdirSync(dir)) {\n if (file.endsWith('.json') && !file.startsWith('.') && file !== `${PSEUDO_LOCALE}.json`) {\n locales.add(file.slice(0, -5));\n }\n }\n }\n\n return {\n root,\n dir,\n sourceLocale,\n localesDeclared,\n // the mode follows the surface: render is what builds a url tree per locale, so it is the tell\n routing: config.routing ?? (config.render ? 'prefix-except-source' : 'no-prefix'),\n // the catalogs decide on their own; these only force it for messages that land after the build\n icu: config.icu,\n relative: config.relative,\n locales: [...locales],\n include: config.include ?? ['{src,app}/**/*.{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}'],\n exclude: config.exclude ?? ['**/node_modules/**', '**/dist/**'],\n dts: typeof config.dts === 'string' ? resolve(root, config.dts) : config.dts,\n translate: config.translate ?? {},\n render: config.render ?? {},\n bundle: config.bundle ?? {},\n };\n}\n\nconst CONFIG_FILES = [\n 'verbaly.config.js',\n 'verbaly.config.mjs',\n 'verbaly.config.ts',\n 'verbaly.config.mts',\n 'verbaly.config.json',\n];\n\nexport function findConfigFile(root: string): string | undefined {\n return CONFIG_FILES.find((name) => existsSync(join(root, name)));\n}\n\nexport async function loadConfigFile(root: string): Promise<VerbalyConfig> {\n for (const name of ['verbaly.config.js', 'verbaly.config.mjs']) {\n const path = join(root, name);\n if (existsSync(path)) {\n const mod = (await import(pathToFileURL(path).href)) as { default?: VerbalyConfig };\n return mod.default ?? {};\n }\n }\n for (const name of ['verbaly.config.ts', 'verbaly.config.mts']) {\n const path = join(root, name);\n if (existsSync(path)) return loadTsConfig(path);\n }\n const jsonPath = join(root, 'verbaly.config.json');\n if (existsSync(jsonPath)) {\n return JSON.parse(readFileSync(jsonPath, 'utf8')) as VerbalyConfig;\n }\n return {};\n}\n\nasync function loadTsConfig(path: string): Promise<VerbalyConfig> {\n try {\n const { bundleRequire } = await import('bundle-require');\n const { mod } = await bundleRequire<{ default?: VerbalyConfig }>({ filepath: path });\n return mod.default ?? {};\n } catch (error) {\n if (isModuleNotFound(error, 'esbuild')) {\n throw new Error(`[verbaly] ${path} needs esbuild: install it with pnpm add -D esbuild`, {\n cause: error,\n });\n }\n throw error;\n }\n}\n\nexport function isModuleNotFound(error: unknown, name: string): boolean {\n return (\n error instanceof Error &&\n (error as { code?: string }).code === 'ERR_MODULE_NOT_FOUND' &&\n error.message.includes(name)\n );\n}\n\n// non-source locales a command may write to (optional CLI override, always config-bounded)\nexport function targetLocales(cfg: ResolvedConfig, override?: string[]): string[] {\n return (override ?? cfg.locales).filter(\n (locale) => locale !== cfg.sourceLocale && cfg.locales.includes(locale),\n );\n}\n\n// file config + inline overrides\nexport async function loadConfig(\n root: string,\n overrides: VerbalyConfig = {},\n): Promise<ResolvedConfig> {\n const fileConfig = await loadConfigFile(root);\n return resolveConfig({ ...fileConfig, ...definedOnly(overrides), root });\n}\n\nfunction definedOnly(config: VerbalyConfig): VerbalyConfig {\n return Object.fromEntries(\n Object.entries(config).filter(([, value]) => value !== undefined),\n ) as VerbalyConfig;\n}\n"],"mappings":"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"}
package/dist/index.d.ts CHANGED
@@ -99,6 +99,7 @@ interface ResolvedConfig {
99
99
  dir: string;
100
100
  sourceLocale: string;
101
101
  locales: string[];
102
+ localesDeclared: boolean;
102
103
  routing: Routing;
103
104
  icu: boolean | undefined;
104
105
  relative: boolean | undefined;
@@ -302,11 +303,17 @@ interface WrapSkip {
302
303
  text: string;
303
304
  reason: string;
304
305
  }
306
+ interface WrapBlocked {
307
+ file: string;
308
+ texts: number;
309
+ client: boolean;
310
+ }
305
311
  interface WrapResult {
306
312
  files: number;
307
313
  changed: string[];
308
314
  wrapped: WrapEntry[];
309
315
  skipped: WrapSkip[];
316
+ blocked: WrapBlocked[];
310
317
  }
311
318
  interface WrapOptions {
312
319
  write?: boolean;
@@ -336,5 +343,5 @@ interface RenderSiteResult {
336
343
  declare function renderSite(cfg: ResolvedConfig, options?: RenderSiteOptions): Promise<RenderSiteResult>;
337
344
  declare function formatRenderWarnings(result: RenderSiteResult, sourceLocale: string): string[];
338
345
  //#endregion
339
- export { type BrokenEntry, type BundleConfig, type Catalog, type Catalogs, type CheckResult, type DoctorEntry, type DoctorResult, type Drafts, type GlossaryEntry, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type PluginOptions, RESOLVED_VIRTUAL_ID, type RedirectConfig, type RenderConfig, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SOURCE_FILE_RE, type StatusResult, type SyncResult, type TransformResult, type TranslateConfig, type TranslateFailure, type TranslateOptions, type TranslateProgress, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type VerbalyConfig, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, check, clientCatalogs, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatDoctorEntry, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, needsIcu, needsRelative, pruneCatalogs, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, transformCode, transformSource, translateCatalogs, wrapProject, writeCatalog, writeDts };
346
+ export { type BrokenEntry, type BundleConfig, type Catalog, type Catalogs, type CheckResult, type DoctorEntry, type DoctorResult, type Drafts, type GlossaryEntry, type IssueSeverity, LOCALE_MODULE_PREFIX, type LocaleStatus, MessageRegistry, type MissingEntry, type PluginOptions, RESOLVED_VIRTUAL_ID, type RedirectConfig, type RenderConfig, type RenderSiteOptions, type RenderSiteResult, type ResolvedConfig, type RuntimeModuleOptions, SOURCE_FILE_RE, type StatusResult, type SyncResult, type TransformResult, type TranslateConfig, type TranslateFailure, type TranslateOptions, type TranslateProgress, type TranslateProvider, type TranslateRequest, type TranslateResult, type UnknownEntry, type VerbalyConfig, type WrapBlocked, type WrapEntry, type WrapOptions, type WrapResult, type WrapSkip, check, clientCatalogs, collectOrigins, counted, createSourceFilter, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatDoctorEntry, formatRenderWarnings, formatStatusResult, formatTranslateFailures, generateDts, generateLocaleModule, generateRuntimeModule, isTransformTarget, loadCatalogs, loadConfig, loadDrafts, loadVirtualModule, markDrafts, needsIcu, needsRelative, pruneCatalogs, renderSite, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, stableKey, status, syncCatalogs, transformCode, transformSource, translateCatalogs, wrapProject, writeCatalog, writeDts };
340
347
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as targetLocales, i as resolveConfig, r as loadConfig, t as findConfigFile } from "./config-ByO-vjIC.js";
1
+ import { a as targetLocales, i as resolveConfig, r as loadConfig, t as findConfigFile } from "./config-iLrfRYDB.js";
2
2
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { dirname, join, relative } from "node:path";
4
4
  import { LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseTags, safeAttribute } from "verbaly";
@@ -1081,6 +1081,87 @@ function writeDts(cfg, catalog, file) {
1081
1081
  writeFileSync(file, content);
1082
1082
  }
1083
1083
  //#endregion
1084
+ //#region src/init.ts
1085
+ const HOSTS = [
1086
+ {
1087
+ name: "nuxt",
1088
+ dep: "nuxt",
1089
+ pkg: "@verbaly/nuxt",
1090
+ wire: "add '@verbaly/nuxt' to the modules in nuxt.config"
1091
+ },
1092
+ {
1093
+ name: "next",
1094
+ dep: "next",
1095
+ pkg: "@verbaly/next",
1096
+ wire: "wrap the export of next.config with withVerbaly"
1097
+ },
1098
+ {
1099
+ name: "sveltekit",
1100
+ dep: "@sveltejs/kit",
1101
+ pkg: "@verbaly/vite",
1102
+ wire: "add verbaly() to the plugins in vite.config (per-request locale: @verbaly/sveltekit)"
1103
+ },
1104
+ {
1105
+ name: "astro",
1106
+ dep: "astro",
1107
+ pkg: "@verbaly/astro",
1108
+ wire: "add verbaly() to the integrations in astro.config"
1109
+ },
1110
+ {
1111
+ name: "vite",
1112
+ dep: "vite",
1113
+ pkg: "@verbaly/vite",
1114
+ wire: "add verbaly() to the plugins in vite.config"
1115
+ },
1116
+ {
1117
+ name: "webpack",
1118
+ dep: "webpack",
1119
+ pkg: "@verbaly/unplugin",
1120
+ wire: "add the verbaly webpack plugin to your build config"
1121
+ },
1122
+ {
1123
+ name: "rspack",
1124
+ dep: "@rspack/core",
1125
+ pkg: "@verbaly/unplugin",
1126
+ wire: "add the verbaly rspack plugin to your build config"
1127
+ },
1128
+ {
1129
+ name: "rollup",
1130
+ dep: "rollup",
1131
+ pkg: "@verbaly/unplugin",
1132
+ wire: "add the verbaly rollup plugin to your build config"
1133
+ },
1134
+ {
1135
+ name: "esbuild",
1136
+ dep: "esbuild",
1137
+ pkg: "@verbaly/unplugin",
1138
+ wire: "add the verbaly esbuild plugin to your build config"
1139
+ }
1140
+ ];
1141
+ const WIRING_PACKAGES = [...new Set(HOSTS.map((host) => host.pkg))];
1142
+ function readDependencies(root) {
1143
+ const path = join(root, "package.json");
1144
+ if (!existsSync(path)) return {};
1145
+ try {
1146
+ const pkg = JSON.parse(readFileSync(path, "utf8"));
1147
+ return {
1148
+ ...pkg.dependencies,
1149
+ ...pkg.devDependencies
1150
+ };
1151
+ } catch {
1152
+ return {};
1153
+ }
1154
+ }
1155
+ function cliReachable(root) {
1156
+ const bin = join(root, "node_modules", ".bin");
1157
+ return existsSync(join(bin, "verbaly")) || existsSync(join(bin, "verbaly.CMD"));
1158
+ }
1159
+ const CLI_INSTALL_FIX = "add `@verbaly/compiler` to your dev dependencies, then `npx verbaly` resolves";
1160
+ function detectHost(root) {
1161
+ const deps = readDependencies(root);
1162
+ return HOSTS.find((host) => deps[host.dep]);
1163
+ }
1164
+ //#endregion
1084
1165
  //#region src/check.ts
1085
1166
  function gatePasses(result) {
1086
1167
  return result.missing.length === 0 && result.unknown.length === 0 && !result.broken.some((entry) => entry.severity === "error");
@@ -1162,11 +1243,12 @@ function formatCheckResult(result) {
1162
1243
  }
1163
1244
  return lines.join("\n");
1164
1245
  }
1165
- function checkNextSteps(result) {
1246
+ function checkNextSteps(result, cliReachable = true) {
1166
1247
  const steps = [];
1167
1248
  if (result.missing.length > 0) steps.push("missing: run `npx verbaly extract` to scaffold the keys, then fill them (or run `npx verbaly translate`)");
1168
1249
  if (result.unknown.length > 0) steps.push("unknown keys: the key used in the code is in no catalog, fix the key or run `npx verbaly extract`");
1169
1250
  if (result.broken.some((entry) => entry.severity === "error")) steps.push("broken: a translation has to keep the params, tags and plural cases of its source message");
1251
+ if (steps.length > 0 && !cliReachable) steps.push(`the verbaly command is not linked in this project: ${CLI_INSTALL_FIX}`);
1170
1252
  return steps.join("\n");
1171
1253
  }
1172
1254
  function formatCheckWarnings(result) {
@@ -1253,7 +1335,7 @@ function runBuildGate(cfg, registry, failOnMissing) {
1253
1335
  missing: []
1254
1336
  } : found;
1255
1337
  if (gatePasses(result)) return;
1256
- throw new Error(`[verbaly] build blocked\n${formatCheckResult(result)}\n${checkNextSteps(result)}`);
1338
+ throw new Error(`[verbaly] build blocked\n${formatCheckResult(result)}\n${checkNextSteps(result, cliReachable(cfg.root))}`);
1257
1339
  }
1258
1340
  //#endregion
1259
1341
  //#region src/drafts.ts
@@ -1486,7 +1568,7 @@ function formatTranslateFailures(failed) {
1486
1568
  async function resolveProvider(cfg, model) {
1487
1569
  const configured = cfg.translate.provider;
1488
1570
  if (typeof configured === "function") return configured;
1489
- const { claudeProvider } = await import("./claude-DAzXUvmS.js");
1571
+ const { claudeProvider } = await import("./claude-B-vethK9.js");
1490
1572
  return claudeProvider({ model: model ?? cfg.translate.model });
1491
1573
  }
1492
1574
  function structureMatches(source, translated) {
@@ -1517,82 +1599,6 @@ function glossaryFor(cfg, locale, messages) {
1517
1599
  return Object.keys(out).length > 0 ? out : void 0;
1518
1600
  }
1519
1601
  //#endregion
1520
- //#region src/init.ts
1521
- const HOSTS = [
1522
- {
1523
- name: "nuxt",
1524
- dep: "nuxt",
1525
- pkg: "@verbaly/nuxt",
1526
- wire: "add '@verbaly/nuxt' to the modules in nuxt.config"
1527
- },
1528
- {
1529
- name: "next",
1530
- dep: "next",
1531
- pkg: "@verbaly/next",
1532
- wire: "wrap the export of next.config with withVerbaly"
1533
- },
1534
- {
1535
- name: "sveltekit",
1536
- dep: "@sveltejs/kit",
1537
- pkg: "@verbaly/vite",
1538
- wire: "add verbaly() to the plugins in vite.config (per-request locale: @verbaly/sveltekit)"
1539
- },
1540
- {
1541
- name: "astro",
1542
- dep: "astro",
1543
- pkg: "@verbaly/astro",
1544
- wire: "add verbaly() to the integrations in astro.config"
1545
- },
1546
- {
1547
- name: "vite",
1548
- dep: "vite",
1549
- pkg: "@verbaly/vite",
1550
- wire: "add verbaly() to the plugins in vite.config"
1551
- },
1552
- {
1553
- name: "webpack",
1554
- dep: "webpack",
1555
- pkg: "@verbaly/unplugin",
1556
- wire: "add the verbaly webpack plugin to your build config"
1557
- },
1558
- {
1559
- name: "rspack",
1560
- dep: "@rspack/core",
1561
- pkg: "@verbaly/unplugin",
1562
- wire: "add the verbaly rspack plugin to your build config"
1563
- },
1564
- {
1565
- name: "rollup",
1566
- dep: "rollup",
1567
- pkg: "@verbaly/unplugin",
1568
- wire: "add the verbaly rollup plugin to your build config"
1569
- },
1570
- {
1571
- name: "esbuild",
1572
- dep: "esbuild",
1573
- pkg: "@verbaly/unplugin",
1574
- wire: "add the verbaly esbuild plugin to your build config"
1575
- }
1576
- ];
1577
- const WIRING_PACKAGES = [...new Set(HOSTS.map((host) => host.pkg))];
1578
- function readDependencies(root) {
1579
- const path = join(root, "package.json");
1580
- if (!existsSync(path)) return {};
1581
- try {
1582
- const pkg = JSON.parse(readFileSync(path, "utf8"));
1583
- return {
1584
- ...pkg.dependencies,
1585
- ...pkg.devDependencies
1586
- };
1587
- } catch {
1588
- return {};
1589
- }
1590
- }
1591
- function detectHost(root) {
1592
- const deps = readDependencies(root);
1593
- return HOSTS.find((host) => deps[host.dep]);
1594
- }
1595
- //#endregion
1596
1602
  //#region src/doctor.ts
1597
1603
  const PREVIEW = 5;
1598
1604
  function readRoutingChoice(root, configFile) {
@@ -1640,6 +1646,8 @@ async function doctor(cfg) {
1640
1646
  const configFile = findConfigFile(cfg.root);
1641
1647
  if (configFile) ok("config", `${configFile} found`);
1642
1648
  else warn("config", "no config file, running on defaults", "run `npx verbaly init`");
1649
+ if (cliReachable(cfg.root)) ok("cli", "the verbaly command is available in this project");
1650
+ else warn("cli", "the verbaly command is not linked in node_modules/.bin", CLI_INSTALL_FIX);
1643
1651
  const catalogs = {};
1644
1652
  let catalogsHealthy = true;
1645
1653
  if (!existsSync(cfg.dir)) {
@@ -1665,7 +1673,10 @@ async function doctor(cfg) {
1665
1673
  error(`locale ${locale}`, `${rel(file)} is not valid JSON`, "repair the file (or delete it and run `npx verbaly extract`)");
1666
1674
  }
1667
1675
  }
1668
- if (catalogsHealthy) ok("catalogs", `${counted(cfg.locales.length, "locale")} (${cfg.locales.join(", ")}) in ${rel(cfg.dir)}/`);
1676
+ if (catalogsHealthy) {
1677
+ const how = cfg.localesDeclared ? "" : ", no locales set, so the catalog files decide";
1678
+ ok("catalogs", `${counted(cfg.locales.length, "locale")} (${cfg.locales.join(", ")}) in ${rel(cfg.dir)}/${how}`);
1679
+ }
1669
1680
  }
1670
1681
  const source = catalogs[cfg.sourceLocale];
1671
1682
  if (source && Object.keys(source).length === 0) warn("source", `source catalog ${cfg.sourceLocale}.json is empty`, "write your first t`…` message and run `npx verbaly extract`");
@@ -1753,8 +1764,16 @@ const WRAP_ATTRS = /* @__PURE__ */ new Set([
1753
1764
  "placeholder",
1754
1765
  "aria-label"
1755
1766
  ]);
1767
+ const CODE_TAGS = /* @__PURE__ */ new Set([
1768
+ "code",
1769
+ "pre",
1770
+ "kbd",
1771
+ "samp",
1772
+ "var"
1773
+ ]);
1756
1774
  const T_NAMES = /* @__PURE__ */ new Set(["t"]);
1757
1775
  const LETTER = /\p{L}/u;
1776
+ const WHITESPACE = /\s/;
1758
1777
  async function wrapProject(cfg, options = {}) {
1759
1778
  const files = (await glob(cfg.include, {
1760
1779
  cwd: cfg.root,
@@ -1765,7 +1784,8 @@ async function wrapProject(cfg, options = {}) {
1765
1784
  files: files.length,
1766
1785
  changed: [],
1767
1786
  wrapped: [],
1768
- skipped: []
1787
+ skipped: [],
1788
+ blocked: []
1769
1789
  };
1770
1790
  for (const file of files) {
1771
1791
  const code = readFileSync(file, "utf8");
@@ -1773,10 +1793,17 @@ async function wrapProject(cfg, options = {}) {
1773
1793
  const out = wrapCode(code, label);
1774
1794
  result.wrapped.push(...out.wrapped);
1775
1795
  result.skipped.push(...out.skipped);
1776
- if (out.code !== void 0) {
1777
- result.changed.push(label);
1778
- if (options.write) writeFileSync(file, out.code);
1796
+ if (out.code === void 0) continue;
1797
+ result.changed.push(label);
1798
+ if (!out.hasT) {
1799
+ result.blocked.push({
1800
+ file: label,
1801
+ texts: out.wrapped.length,
1802
+ client: out.client
1803
+ });
1804
+ continue;
1779
1805
  }
1806
+ if (options.write) writeFileSync(file, out.code);
1780
1807
  }
1781
1808
  return result;
1782
1809
  }
@@ -1793,9 +1820,13 @@ function wrapCode(code, file) {
1793
1820
  } catch {
1794
1821
  return {
1795
1822
  wrapped,
1796
- skipped
1823
+ skipped,
1824
+ hasT: false,
1825
+ client: false
1797
1826
  };
1798
1827
  }
1828
+ const hasT = declaresT(ast);
1829
+ const client = hasDirective(ast, "use client");
1799
1830
  const s = new MagicString(code);
1800
1831
  const visited = /* @__PURE__ */ new Set();
1801
1832
  let changed = false;
@@ -1807,10 +1838,14 @@ function wrapCode(code, file) {
1807
1838
  return changed ? {
1808
1839
  code: s.toString(),
1809
1840
  wrapped,
1810
- skipped
1841
+ skipped,
1842
+ hasT,
1843
+ client
1811
1844
  } : {
1812
1845
  wrapped,
1813
- skipped
1846
+ skipped,
1847
+ hasT,
1848
+ client
1814
1849
  };
1815
1850
  function processElement(node) {
1816
1851
  visited.add(node);
@@ -1819,6 +1854,7 @@ function wrapCode(code, file) {
1819
1854
  const name = opening.name;
1820
1855
  if (name.type === "JSXIdentifier" && name.name === "Trans") return markSubtree(node);
1821
1856
  if (hasVerbalyAttr(opening)) return markSubtree(node);
1857
+ if (name.type === "JSXIdentifier" && CODE_TAGS.has(name.name)) return markSubtree(node);
1822
1858
  wrapAttributes(opening);
1823
1859
  }
1824
1860
  const children = node.children ?? [];
@@ -1839,6 +1875,10 @@ function wrapCode(code, file) {
1839
1875
  if (meaningful.length === 0) return;
1840
1876
  const first = meaningful[0];
1841
1877
  const last = meaningful[meaningful.length - 1];
1878
+ if (first.type === "JSXExpressionContainer" && meaningful.length > 1) {
1879
+ skip(parent, snippet(children), "starts with an interpolation: wrap the sentence by hand");
1880
+ return;
1881
+ }
1842
1882
  let template = "";
1843
1883
  let report = "";
1844
1884
  for (let i = children.indexOf(first); i <= children.indexOf(last); i++) {
@@ -1872,6 +1912,7 @@ function wrapCode(code, file) {
1872
1912
  } else return;
1873
1913
  }
1874
1914
  if (!LETTER.test(report)) return;
1915
+ if (isIdentifierLike(report)) return;
1875
1916
  const start = first.type === "JSXText" ? first.start + leadingWs(first.value) : first.start;
1876
1917
  const end = last.type === "JSXText" ? last.end - trailingWs(last.value) : last.end;
1877
1918
  s.overwrite(start, end, "{t`" + template + "`}");
@@ -1891,7 +1932,7 @@ function wrapCode(code, file) {
1891
1932
  const value = attr.value;
1892
1933
  if (value?.type !== "StringLiteral") continue;
1893
1934
  const raw = value.value;
1894
- if (!LETTER.test(raw)) continue;
1935
+ if (!LETTER.test(raw) || isIdentifierLike(raw)) continue;
1895
1936
  s.overwrite(value.start, value.end, "{t`" + escapeTemplate(raw) + "`}");
1896
1937
  changed = true;
1897
1938
  wrapped.push({
@@ -1923,6 +1964,40 @@ function wrapCode(code, file) {
1923
1964
  });
1924
1965
  }
1925
1966
  }
1967
+ function isIdentifierLike(text) {
1968
+ const trimmed = text.trim();
1969
+ if (WHITESPACE.test(trimmed)) return false;
1970
+ const first = [...trimmed].find((char) => LETTER.test(char));
1971
+ return first !== void 0 && first !== first.toUpperCase();
1972
+ }
1973
+ function hasDirective(program, value) {
1974
+ return (program.directives ?? []).some((d) => d.value?.value === value);
1975
+ }
1976
+ function declaresT(program) {
1977
+ let found = false;
1978
+ walk$1(program, (node) => {
1979
+ if (found) return;
1980
+ if (node.type === "ImportDeclaration") {
1981
+ for (const spec of node.specifiers) if (isTName(spec.local?.name)) found = true;
1982
+ return;
1983
+ }
1984
+ if (node.type === "VariableDeclarator" && bindsT(node.id)) found = true;
1985
+ if (node.type === "FunctionDeclaration" && isTName(node.id?.name)) found = true;
1986
+ if (node.params?.some((param) => bindsT(param))) found = true;
1987
+ });
1988
+ return found;
1989
+ }
1990
+ function bindsT(pattern) {
1991
+ if (!pattern) return false;
1992
+ if (pattern.type === "Identifier") return isTName(pattern.name);
1993
+ if (pattern.type === "AssignmentPattern") return bindsT(pattern.left);
1994
+ if (pattern.type === "ObjectPattern") return pattern.properties.some((prop) => prop.type === "RestElement" ? bindsT(prop.argument) : bindsT(prop.value));
1995
+ if (pattern.type === "ArrayPattern") return pattern.elements.some((el) => bindsT(el ?? void 0));
1996
+ return false;
1997
+ }
1998
+ function isTName(name) {
1999
+ return typeof name === "string" && T_NAMES.has(name);
2000
+ }
1926
2001
  function hasVerbalyAttr(opening) {
1927
2002
  return opening.attributes.some((attr) => {
1928
2003
  if (attr.type !== "JSXAttribute") return false;