@verbaly/compiler 0.68.0 → 0.69.1

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/dist/index.d.ts CHANGED
@@ -198,7 +198,7 @@ interface ResolvedConfig {
198
198
  relative: boolean | undefined;
199
199
  include: string[];
200
200
  exclude: string[];
201
- dts: string | false | undefined;
201
+ dts: string | false;
202
202
  translate: TranslateConfig;
203
203
  render: RenderConfig;
204
204
  bundle: BundleConfig;
@@ -357,9 +357,14 @@ export declare function generateRuntimeModule(cfg: ResolvedConfig, options?: Run
357
357
  export declare function generateLocaleModule(catalog: Catalog): string;
358
358
  interface DtsOptions {
359
359
  inlineCatalog?: boolean;
360
+ locales?: string[];
360
361
  }
361
362
  export declare function generateDts(catalog: Catalog, options?: DtsOptions): string;
362
- export declare function writeDts(cfg: ResolvedConfig, catalog: Catalog, file?: string | false): void;
363
+ interface DtsWrite {
364
+ file: string;
365
+ changed: boolean;
366
+ }
367
+ export declare function writeDts(cfg: ResolvedConfig, catalog: Catalog, file?: string | false): DtsWrite | undefined;
363
368
  //#endregion
364
369
  //#region src/transform.d.ts
365
370
  interface TransformResult {
@@ -385,6 +390,9 @@ export declare function transformSource(code: string, id: string, registry: Mess
385
390
  };
386
391
  export declare function runBuildGate(cfg: ResolvedConfig, registry: MessageRegistry, failOnMissing?: boolean): void;
387
392
  //#endregion
393
+ //#region src/scope.d.ts
394
+ export declare function reportOutsideInclude(cfg: ResolvedConfig): Promise<void>;
395
+ //#endregion
388
396
  //#region src/validate.d.ts
389
397
  type IssueSeverity = 'error' | 'warning';
390
398
  interface StructureIssue {
@@ -486,6 +494,9 @@ interface DoctorResult {
486
494
  export declare function formatDoctorEntry(entry: DoctorEntry): string;
487
495
  export declare function doctor(cfg: ResolvedConfig): Promise<DoctorResult>;
488
496
  //#endregion
497
+ //#region src/host.d.ts
498
+ type Host = 'nuxt' | 'next' | 'sveltekit' | 'astro' | 'vite' | 'webpack' | 'rspack' | 'rollup' | 'esbuild';
499
+ //#endregion
489
500
  //#region src/init.d.ts
490
501
  interface InitOptions {
491
502
  root?: string;
@@ -505,7 +516,6 @@ interface InitResult {
505
516
  }[];
506
517
  refused: string[];
507
518
  }
508
- type Host = 'nuxt' | 'next' | 'sveltekit' | 'astro' | 'vite' | 'webpack' | 'rspack' | 'rollup' | 'esbuild';
509
519
  export declare function init(input?: InitOptions): Promise<InitResult>;
510
520
  //#endregion
511
521
  //#region src/wrap.d.ts
package/dist/index.js CHANGED
@@ -1,12 +1,19 @@
1
- import { a as loadConfig, c as targetLocales, n as truncate, o as loadConfigFile, r as findConfigFile, s as resolveConfig, t as counted } from "./text-SqXoYAIB.js";
1
+ import { a as findConfigFile, c as loadConfigFile, d as WIRING_PACKAGES, f as detectHost, i as SOURCE_EXTENSIONS, l as resolveConfig, m as readDependencies, n as counted, p as installCommand, r as truncate, s as loadConfig, t as byCodeUnit, u as targetLocales } from "./text-Bh96y7ik.js";
2
2
  import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, rmSync, watch, writeFileSync } from "node:fs";
3
- import { dirname, join, relative } from "node:path";
3
+ import { dirname, join, relative, resolve, sep } from "node:path";
4
4
  import { CATALOG_SCRIPT, LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, createVerbaly, flatten, localeDirection, normalizeLink, parse, parseIcu, parseTags, safeAttribute } from "verbaly";
5
5
  import { glob } from "tinyglobby";
6
6
  import { parse as parse$1 } from "@babel/parser";
7
7
  import { createHash } from "node:crypto";
8
+ import { applyEdits, modify, parse as parse$2 } from "jsonc-parser";
8
9
  import picomatch from "picomatch";
9
10
  import MagicString from "magic-string";
11
+ //#region src/eol.ts
12
+ function withLineEndings(text, existing) {
13
+ const first = existing?.indexOf("\n") ?? -1;
14
+ return first > 0 && existing[first - 1] === "\r" ? text.replace(/\r?\n/g, "\r\n") : text;
15
+ }
16
+ //#endregion
10
17
  //#region src/catalog.ts
11
18
  function emptyCatalog() {
12
19
  return Object.create(null);
@@ -130,7 +137,7 @@ function writeCatalog(cfg, locale, catalog) {
130
137
  }
131
138
  const parsed = existing === void 0 ? void 0 : parseTree(existing);
132
139
  const previous = isTree(parsed) ? parsed : void 0;
133
- const serialized = serializeCatalog(catalog, wantsNesting(cfg, locale, existing, previous), previous);
140
+ const serialized = withLineEndings(serializeCatalog(catalog, wantsNesting(cfg, locale, existing, previous), previous), existing);
134
141
  if (existing === serialized) return serialized;
135
142
  writeFileSync(path, serialized);
136
143
  return serialized;
@@ -1222,6 +1229,78 @@ function renderParamType(types) {
1222
1229
  ]) members.add(m);
1223
1230
  return [...members].join(" | ");
1224
1231
  }
1232
+ //#endregion
1233
+ //#region src/tsconfig.ts
1234
+ function readTsconfig(root) {
1235
+ const path = join(root, "tsconfig.json");
1236
+ let text;
1237
+ try {
1238
+ text = readFileSync(path, "utf8");
1239
+ } catch {
1240
+ return "no-tsconfig";
1241
+ }
1242
+ const errors = [];
1243
+ const json = parse$2(text, errors, { allowTrailingComma: true });
1244
+ if (errors.length > 0 || typeof json !== "object" || json === null || Array.isArray(json)) return "unreadable";
1245
+ return {
1246
+ path,
1247
+ text,
1248
+ json
1249
+ };
1250
+ }
1251
+ function covered(list, entry) {
1252
+ if (!Array.isArray(list)) return false;
1253
+ return list.some((item) => {
1254
+ if (typeof item !== "string") return false;
1255
+ const pattern = item.replace(/^\.\//, "").replace(/\/+$/, "");
1256
+ return picomatch(pattern)(entry) || picomatch(`${pattern}/**/*`)(entry);
1257
+ });
1258
+ }
1259
+ function formatting(text) {
1260
+ const indent = /\n([ \t]+)\S/.exec(text)?.[1] ?? " ";
1261
+ return {
1262
+ insertSpaces: !indent.startsWith(" "),
1263
+ tabSize: indent.startsWith(" ") ? 1 : indent.length,
1264
+ eol: text.includes("\r\n") ? "\r\n" : "\n"
1265
+ };
1266
+ }
1267
+ function typesIncluded(root, file) {
1268
+ const read = readTsconfig(root);
1269
+ if (typeof read === "string") return read;
1270
+ const entry = relative(root, file).replaceAll("\\", "/");
1271
+ const { include, files } = read.json;
1272
+ if (covered(include, entry) || covered(files, entry)) return "present";
1273
+ return "missing";
1274
+ }
1275
+ function includeTypes(root, file) {
1276
+ const read = readTsconfig(root);
1277
+ if (typeof read === "string") return read;
1278
+ const entry = relative(root, file).replaceAll("\\", "/");
1279
+ const { include, files } = read.json;
1280
+ if (covered(include, entry) || covered(files, entry)) return "present";
1281
+ const options = { formattingOptions: formatting(read.text) };
1282
+ const edits = Array.isArray(include) ? modify(read.text, ["include", -1], entry, {
1283
+ ...options,
1284
+ isArrayInsertion: true
1285
+ }) : Array.isArray(files) && include === void 0 ? modify(read.text, ["files", -1], entry, {
1286
+ ...options,
1287
+ isArrayInsertion: true
1288
+ }) : modify(read.text, ["include"], ["**/*", entry], options);
1289
+ writeFileSync(read.path, applyEdits(read.text, edits));
1290
+ return "added";
1291
+ }
1292
+ //#endregion
1293
+ //#region src/warn.ts
1294
+ const warned = /* @__PURE__ */ new Set();
1295
+ function warnOnce(message, dedupeKey = message) {
1296
+ if (warned.has(dedupeKey)) return;
1297
+ warned.add(dedupeKey);
1298
+ console.warn(`[verbaly] ${message}`);
1299
+ }
1300
+ function warnParseError(file, message) {
1301
+ warnOnce(`${file}: could not be parsed (${message}), its messages were not extracted`);
1302
+ }
1303
+ const DTS_HEADER = "// generated by verbaly: do not edit";
1225
1304
  const SLICE_HELPERS = `function readSlice(root, path) {
1226
1305
  const locale = readPath({ supported: locales, path });
1227
1306
  if (!locale || locale === sourceLocale) return undefined;
@@ -1332,7 +1411,8 @@ function generateLocaleModule(catalog) {
1332
1411
  }
1333
1412
  function generateDts(catalog, options = {}) {
1334
1413
  const lines = [];
1335
- for (const [key, message] of Object.entries(catalog).sort(([a], [b]) => a.localeCompare(b))) {
1414
+ const locales = options.locales?.length ? [...options.locales].sort(byCodeUnit).map((locale) => JSON.stringify(locale)).join(" | ") : "string";
1415
+ for (const [key, message] of Object.entries(catalog).sort(([a], [b]) => byCodeUnit(a, b))) {
1336
1416
  const params = collectParams(message);
1337
1417
  if (params.size === 0) lines.push(` ${JSON.stringify(key)}: never;`);
1338
1418
  else {
@@ -1340,19 +1420,20 @@ function generateDts(catalog, options = {}) {
1340
1420
  lines.push(` ${JSON.stringify(key)}: { ${fields} };`);
1341
1421
  }
1342
1422
  }
1343
- return `// generated by verbaly: do not edit
1423
+ return `${DTS_HEADER}
1344
1424
  declare module 'virtual:verbaly' {
1345
1425
  export interface VerbalyMessages {
1346
1426
  ${lines.join("\n")}
1347
1427
  }
1348
1428
  export type VerbalyKey = keyof VerbalyMessages & string;
1429
+ export type VerbalyLocale = ${locales};
1349
1430
 
1350
1431
  export type VerbalyKeyTree = VerbalyKey | { readonly [name: string]: VerbalyKeyTree };
1351
1432
  export function defineKeys<const T extends VerbalyKeyTree>(keys: T): T;
1352
1433
 
1353
- export const verbaly: import('verbaly').Verbaly<VerbalyKey>;
1434
+ export const verbaly: import('verbaly').Verbaly;
1354
1435
 
1355
- export const sourceLocale: string;
1436
+ export const sourceLocale: VerbalyLocale;
1356
1437
  export const locales: string[];
1357
1438
  export const routing: import('verbaly').Routing;
1358
1439
  export function localePath(
@@ -1365,17 +1446,27 @@ ${lines.join("\n")}
1365
1446
  }): string | undefined;
1366
1447
  export function loadMessages(locale: string): Promise<Record<string, string>>;${options.inlineCatalog ? "\n export function adoptPage(options?: {\n root?: ParentNode;\n path?: string;\n }): string | undefined;" : ""}
1367
1448
  export function createInstance(
1368
- options?: import('verbaly').VerbalyOptions<VerbalyKey>,
1369
- ): import('verbaly').Verbaly<VerbalyKey>;
1370
- export function createRequestInstance(
1371
- locale: string,
1372
- ): Promise<import('verbaly').Verbaly<VerbalyKey>>;
1449
+ options?: import('verbaly').VerbalyOptions,
1450
+ ): import('verbaly').Verbaly;
1451
+ export function createRequestInstance(locale: string): Promise<import('verbaly').Verbaly>;
1373
1452
 
1374
- export function t<K extends VerbalyKey>(
1375
- key: K,
1376
- ...args: [VerbalyMessages[K]] extends [never] ? [] : [VerbalyMessages[K]]
1453
+ // a key written as a literal must exist; string, or a template with a part from data, is data
1454
+ export function t<K extends VerbalyKey | TemplateStringsArray | (string & {})>(
1455
+ first: K extends TemplateStringsArray
1456
+ ? K
1457
+ : {} extends Record<K & string, 1>
1458
+ ? K
1459
+ : K extends VerbalyKey ? K : VerbalyKey,
1460
+ ...rest: [K] extends [never]
1461
+ ? [params?: import('verbaly').Params]
1462
+ : K extends TemplateStringsArray
1463
+ ? unknown[]
1464
+ : {} extends Record<K & string, 1>
1465
+ ? [params?: import('verbaly').Params]
1466
+ : K extends VerbalyKey
1467
+ ? [VerbalyMessages[K]] extends [never] ? [] : [VerbalyMessages[K]]
1468
+ : unknown[]
1377
1469
  ): string;
1378
- export function t(strings: TemplateStringsArray, ...values: unknown[]): string;
1379
1470
  export namespace t {
1380
1471
  export function id(
1381
1472
  key: string,
@@ -1392,6 +1483,14 @@ ${lines.join("\n")}
1392
1483
  ): Promise<void>;
1393
1484
  export function getLocale(): string;
1394
1485
  export function subscribe(listener: () => void): () => void;
1486
+
1487
+ // nested, so it augments verbaly: at the top of a script it would replace the real module
1488
+ module 'verbaly' {
1489
+ interface Register {
1490
+ t: typeof t;
1491
+ locale: VerbalyLocale;
1492
+ }
1493
+ }
1395
1494
  }
1396
1495
 
1397
1496
  declare module 'virtual:verbaly/locale/*' {
@@ -1400,16 +1499,51 @@ declare module 'virtual:verbaly/locale/*' {
1400
1499
  }
1401
1500
  `;
1402
1501
  }
1502
+ function projectDtsOptions(cfg) {
1503
+ return {
1504
+ inlineCatalog: cfg.render.inlineCatalog === true,
1505
+ locales: cfg.locales
1506
+ };
1507
+ }
1403
1508
  function writeDts(cfg, catalog, file) {
1404
1509
  const target = file === void 0 ? cfg.dts : file;
1405
- if (target === false) return;
1406
- file = target ?? join(cfg.root, "verbaly.d.ts");
1407
- const content = generateDts(catalog, { inlineCatalog: cfg.render.inlineCatalog === true });
1510
+ if (target === false) return void 0;
1511
+ let existing;
1408
1512
  try {
1409
- if (readFileSync(file, "utf8") === content) return;
1513
+ existing = readFileSync(target, "utf8");
1410
1514
  } catch {}
1411
- mkdirSync(dirname(file), { recursive: true });
1412
- writeFileSync(file, content);
1515
+ const content = withLineEndings(generateDts(catalog, projectDtsOptions(cfg)), existing);
1516
+ const changed = existing !== content;
1517
+ if (changed) {
1518
+ mkdirSync(dirname(target), { recursive: true });
1519
+ writeFileSync(target, content);
1520
+ }
1521
+ removeRootDts(cfg, target);
1522
+ if (resolve(target).startsWith(resolve(cfg.root, ".verbaly") + sep)) {
1523
+ const ignore = join(cfg.root, ".verbaly", ".gitignore");
1524
+ if (!existsSync(ignore)) writeFileSync(ignore, "*\n");
1525
+ const state = includeTypes(cfg.root, target);
1526
+ const entry = relative(cfg.root, target).replaceAll("\\", "/");
1527
+ if (state === "added") warnOnce(`added "${entry}" to the include of tsconfig.json, so TypeScript reads the types`);
1528
+ else if (state === "unreadable") warnOnce(`tsconfig.json could not be read, so add "${entry}" to its include yourself`);
1529
+ }
1530
+ return {
1531
+ file: target,
1532
+ changed
1533
+ };
1534
+ }
1535
+ function removeRootDts(cfg, target) {
1536
+ const old = join(cfg.root, "verbaly.d.ts");
1537
+ if (resolve(target) === resolve(old)) return;
1538
+ let head;
1539
+ try {
1540
+ head = readFileSync(old, "utf8").slice(0, 36);
1541
+ } catch {
1542
+ return;
1543
+ }
1544
+ if (head !== "// generated by verbaly: do not edit") return;
1545
+ rmSync(old);
1546
+ warnOnce(`the types live in ${relative(cfg.root, target).replaceAll("\\", "/")} now, so the verbaly.d.ts Verbaly wrote at the root was removed`);
1413
1547
  }
1414
1548
  //#endregion
1415
1549
  //#region src/findings.ts
@@ -1563,10 +1697,10 @@ function readState(cfg) {
1563
1697
  }
1564
1698
  }
1565
1699
  function saveState(cfg, state) {
1566
- const serialized = serializeState(state);
1700
+ const fresh = serializeState(state);
1567
1701
  const path = statePath(cfg);
1568
1702
  const legacy = statePath(cfg, LEGACY_DRAFTS_FILE);
1569
- if (serialized === void 0) {
1703
+ if (fresh === void 0) {
1570
1704
  rmSync(path, { force: true });
1571
1705
  rmSync(legacy, { force: true });
1572
1706
  return;
@@ -1577,6 +1711,7 @@ function saveState(cfg, state) {
1577
1711
  } catch {
1578
1712
  mkdirSync(cfg.dir, { recursive: true });
1579
1713
  }
1714
+ const serialized = withLineEndings(fresh, existing);
1580
1715
  if (existing !== serialized) writeFileSync(path, serialized);
1581
1716
  if (existsSync(legacy)) rmSync(legacy);
1582
1717
  }
@@ -1689,7 +1824,7 @@ function outdatedTranslations(cfg, catalogs, fingerprints) {
1689
1824
  });
1690
1825
  }
1691
1826
  }
1692
- return out.sort((a, b) => a.locale.localeCompare(b.locale) || a.key.localeCompare(b.key));
1827
+ return out.sort((a, b) => byCodeUnit(a.locale, b.locale) || byCodeUnit(a.key, b.key));
1693
1828
  }
1694
1829
  function sourceOf(stamped) {
1695
1830
  return stamped.slice(0, stamped.indexOf("."));
@@ -1822,85 +1957,11 @@ function suggestTag(tag) {
1822
1957
  }
1823
1958
  //#endregion
1824
1959
  //#region src/init.ts
1825
- const HOSTS = [
1826
- {
1827
- name: "nuxt",
1828
- dep: "nuxt",
1829
- pkg: "@verbaly/nuxt",
1830
- wire: "add '@verbaly/nuxt' to the modules in nuxt.config"
1831
- },
1832
- {
1833
- name: "next",
1834
- dep: "next",
1835
- pkg: "@verbaly/next",
1836
- wire: "wrap the export of next.config with withVerbaly"
1837
- },
1838
- {
1839
- name: "sveltekit",
1840
- dep: "@sveltejs/kit",
1841
- pkg: "@verbaly/vite",
1842
- wire: "add verbaly() to the plugins in vite.config (per-request locale: @verbaly/sveltekit)"
1843
- },
1844
- {
1845
- name: "astro",
1846
- dep: "astro",
1847
- pkg: "@verbaly/astro",
1848
- wire: "add verbaly() to the integrations in astro.config"
1849
- },
1850
- {
1851
- name: "vite",
1852
- dep: "vite",
1853
- pkg: "@verbaly/vite",
1854
- wire: "add verbaly() to the plugins in vite.config"
1855
- },
1856
- {
1857
- name: "webpack",
1858
- dep: "webpack",
1859
- pkg: "@verbaly/unplugin",
1860
- wire: "add the verbaly webpack plugin to your build config"
1861
- },
1862
- {
1863
- name: "rspack",
1864
- dep: "@rspack/core",
1865
- pkg: "@verbaly/unplugin",
1866
- wire: "add the verbaly rspack plugin to your build config"
1867
- },
1868
- {
1869
- name: "rollup",
1870
- dep: "rollup",
1871
- pkg: "@verbaly/unplugin",
1872
- wire: "add the verbaly rollup plugin to your build config"
1873
- },
1874
- {
1875
- name: "esbuild",
1876
- dep: "esbuild",
1877
- pkg: "@verbaly/unplugin",
1878
- wire: "add the verbaly esbuild plugin to your build config"
1879
- }
1880
- ];
1881
- const WIRING_PACKAGES = [...new Set(HOSTS.map((host) => host.pkg))];
1882
- function readDependencies(root) {
1883
- const path = join(root, "package.json");
1884
- if (!existsSync(path)) return {};
1885
- try {
1886
- const pkg = JSON.parse(readFileSync(path, "utf8"));
1887
- return {
1888
- ...pkg.dependencies,
1889
- ...pkg.devDependencies
1890
- };
1891
- } catch {
1892
- return {};
1893
- }
1894
- }
1895
1960
  function cliReachable(root) {
1896
1961
  const bin = join(root, "node_modules", ".bin");
1897
1962
  return existsSync(join(bin, "verbaly")) || existsSync(join(bin, "verbaly.CMD"));
1898
1963
  }
1899
1964
  const CLI_INSTALL_FIX = "add `@verbaly/compiler` to your dev dependencies, then `npx verbaly` resolves";
1900
- function detectHost(root) {
1901
- const deps = readDependencies(root);
1902
- return HOSTS.find((host) => deps[host.dep]);
1903
- }
1904
1965
  function configSource(options, typescript) {
1905
1966
  const fields = [` sourceLocale: '${options.sourceLocale ?? "en"}',`];
1906
1967
  if (options.locales?.length) fields.push(` locales: [${options.locales.map((l) => `'${l}'`).join(", ")}],`);
@@ -1967,7 +2028,7 @@ async function init(input = {}) {
1967
2028
  }
1968
2029
  }
1969
2030
  const host = detectHost(root);
1970
- const next = host ? [`pnpm add -D ${host.pkg}`, host.wire] : ["run \"verbaly extract\" after writing your first t`…` message"];
2031
+ const next = host ? [installCommand(root, host.install), host.wire] : ["run \"verbaly extract\" after writing your first t`…` message"];
1971
2032
  return {
1972
2033
  created,
1973
2034
  skipped,
@@ -2113,17 +2174,6 @@ function formatCheckWarnings(result, root, options = {}) {
2113
2174
  return lines.join("\n");
2114
2175
  }
2115
2176
  //#endregion
2116
- //#region src/warn.ts
2117
- const warned = /* @__PURE__ */ new Set();
2118
- function warnOnce(message, dedupeKey = message) {
2119
- if (warned.has(dedupeKey)) return;
2120
- warned.add(dedupeKey);
2121
- console.warn(`[verbaly] ${message}`);
2122
- }
2123
- function warnParseError(file, message) {
2124
- warnOnce(`${file}: could not be parsed (${message}), its messages were not extracted`);
2125
- }
2126
- //#endregion
2127
2177
  //#region src/transform.ts
2128
2178
  function quote(text, single) {
2129
2179
  if (!single) return JSON.stringify(text);
@@ -2212,6 +2262,65 @@ function buildFingerprints(cfg) {
2212
2262
  return state.fingerprints;
2213
2263
  }
2214
2264
  //#endregion
2265
+ //#region src/scope.ts
2266
+ const TAGGED_HINT = /(?<![\w$.])\$?t(?:\.id\s*\([^)]*\))?\s*`/;
2267
+ const NOT_SOURCE = [
2268
+ "**/node_modules/**",
2269
+ "**/dist/**",
2270
+ "**/build/**",
2271
+ "**/out/**",
2272
+ "**/coverage/**"
2273
+ ];
2274
+ function relativeId(cfg, id) {
2275
+ return relative(cfg.root, id).replaceAll("\\", "/");
2276
+ }
2277
+ function suggestedPattern(rel) {
2278
+ const slash = rel.indexOf("/");
2279
+ return slash < 0 ? rel : `${rel.slice(0, slash)}/**/*.${SOURCE_EXTENSIONS}`;
2280
+ }
2281
+ function createOutsideCheck(cfg) {
2282
+ if (cfg.include.length === 0) return () => void 0;
2283
+ const included = picomatch(cfg.include);
2284
+ const excluded = picomatch(cfg.exclude);
2285
+ return (code, id) => {
2286
+ const rel = relativeId(cfg, id);
2287
+ if (rel.startsWith("..") || included(rel) || excluded(rel)) return void 0;
2288
+ if (!TAGGED_HINT.test(code)) return void 0;
2289
+ if (analyzeFile(code, id).tagged.length === 0) return void 0;
2290
+ return {
2291
+ file: id,
2292
+ pattern: suggestedPattern(rel)
2293
+ };
2294
+ };
2295
+ }
2296
+ function formatOutside(cfg, found) {
2297
+ return `${relativeId(cfg, found.file)} uses t\`…\` outside the include of your verbaly config, so its texts are never extracted and show in ${cfg.sourceLocale} in every language: add "${found.pattern}" to include (or the file to exclude, if it is not app code)`;
2298
+ }
2299
+ async function reportOutsideInclude(cfg) {
2300
+ for (const found of await filesOutsideInclude(cfg)) warnOnce(formatOutside(cfg, found), `outside:${found.file}`);
2301
+ }
2302
+ async function filesOutsideInclude(cfg) {
2303
+ if (cfg.include.length === 0) return [];
2304
+ const check = createOutsideCheck(cfg);
2305
+ const files = await glob([`**/*.${SOURCE_EXTENSIONS}`], {
2306
+ cwd: cfg.root,
2307
+ ignore: [...NOT_SOURCE, ...cfg.exclude],
2308
+ absolute: true
2309
+ });
2310
+ const found = [];
2311
+ for (const file of files.sort()) {
2312
+ let code;
2313
+ try {
2314
+ code = readFileSync(file, "utf8");
2315
+ } catch {
2316
+ continue;
2317
+ }
2318
+ const outside = check(code, file);
2319
+ if (outside) found.push(outside);
2320
+ }
2321
+ return found;
2322
+ }
2323
+ //#endregion
2215
2324
  //#region src/drafts.ts
2216
2325
  function loadDrafts(cfg) {
2217
2326
  return loadState(cfg).drafts;
@@ -2385,14 +2494,23 @@ async function doctor(cfg) {
2385
2494
  const installed = WIRING_PACKAGES.find((pkg) => deps[pkg]);
2386
2495
  if (!host) ok("plugin", "no framework or bundler detected, the CLI flow (extract/check) applies");
2387
2496
  else if (installed) ok("plugin", `${installed} installed for ${host.name}`);
2388
- else warn("plugin", `${host.name} detected but ${host.pkg} is not installed`, `pnpm add -D ${host.pkg} and ${host.wire}`);
2497
+ else warn("plugin", `${host.name} detected but ${host.pkg} is not installed`, `${installCommand(cfg.root, host.install)}, then ${host.wire}`);
2389
2498
  const scanning = cfg.include.length > 0;
2390
2499
  if (!scanning) ok("sources", "source scanning is off (include: []), the catalogs are the source of truth");
2391
2500
  if (source && scanning && cfg.dts !== false) {
2392
- const dtsPath = cfg.dts ?? join(cfg.root, "verbaly.d.ts");
2393
- if (!existsSync(dtsPath)) warn("types", "verbaly.d.ts has not been generated", "run `npx verbaly extract`");
2394
- else if (readFileSync(dtsPath, "utf8") !== generateDts(source, { inlineCatalog: cfg.render.inlineCatalog === true })) warn("types", "verbaly.d.ts is stale", "run `npx verbaly extract`");
2395
- else ok("types", "verbaly.d.ts is up to date");
2501
+ const dtsPath = cfg.dts;
2502
+ const shown = rel(dtsPath);
2503
+ const regenerate = host?.name === "astro" ? "run `npx astro sync`, which writes the types and links them" : host?.name === "nuxt" ? "run `npx nuxi prepare`, which writes the types and links them" : "run `npx verbaly typegen`";
2504
+ const expected = generateDts(source, projectDtsOptions(cfg));
2505
+ if (!existsSync(dtsPath)) warn("types", `${shown} has not been generated`, regenerate);
2506
+ else if (readFileSync(dtsPath, "utf8").replace(/\r\n/g, "\n") !== expected) warn("types", `${shown} is stale`, "run `npx verbaly typegen`");
2507
+ else ok("types", `${shown} is up to date`);
2508
+ if (dtsPath.startsWith(join(cfg.root, ".verbaly"))) {
2509
+ const state = typesIncluded(cfg.root, dtsPath);
2510
+ if (state === "missing" || state === "unreadable") warn("types", state === "missing" ? `tsconfig.json does not include ${shown}, so TypeScript never reads the types` : `tsconfig.json could not be read, so it may not include ${shown}`, `run \`npx verbaly typegen\`, which adds the line, or add "${shown}" to include`);
2511
+ }
2512
+ const old = join(cfg.root, "verbaly.d.ts");
2513
+ if (dtsPath !== old && existsSync(old) && readFileSync(old, "utf8").startsWith("// generated by verbaly: do not edit")) warn("types", `the verbaly.d.ts Verbaly wrote at the root is still there next to ${shown}, and they declare the same module twice`, "run `npx verbaly typegen`, which removes it");
2396
2514
  }
2397
2515
  const registry = await extractProject(cfg);
2398
2516
  if (scanning) {
@@ -2401,6 +2519,12 @@ async function doctor(cfg) {
2401
2519
  const first = unreadable[0];
2402
2520
  warn("sources", `could not parse ${counted(unreadable.length, "file")}, so the messages inside are not extracted (${rel(first.file)}: ${first.message})`, "fix the syntax error, or exclude the file in your config if it is not source");
2403
2521
  }
2522
+ const outside = await filesOutsideInclude(cfg);
2523
+ if (outside.length > 0) {
2524
+ const files = outside.map((entry) => rel(entry.file));
2525
+ const patterns = [...new Set(outside.map((entry) => `"${entry.pattern}"`))];
2526
+ warn("sources", `t\`…\` is written in ${counted(outside.length, "file")} outside include, and those texts are never extracted or translated (${preview(files)})`, `add ${patterns.join(" and ")} to include in your verbaly config, or the files to exclude if they are not app code`);
2527
+ }
2404
2528
  const stray = registry.strayImports();
2405
2529
  if (stray.length > 0) {
2406
2530
  const files = [...new Set(stray.map((entry) => rel(entry.file)))];
@@ -2596,11 +2720,11 @@ async function translateCatalogs(cfg, catalogs, provider, options = {}) {
2596
2720
  });
2597
2721
  for (const locale of Object.keys(result.translated)) result.translated[locale].sort();
2598
2722
  for (const locale of Object.keys(result.invalid)) result.invalid[locale].sort();
2599
- result.failed.sort((a, b) => a.locale.localeCompare(b.locale) || compare(a.keys, b.keys));
2723
+ result.failed.sort((a, b) => byCodeUnit(a.locale, b.locale) || compare(a.keys, b.keys));
2600
2724
  return result;
2601
2725
  }
2602
2726
  function compare(a, b) {
2603
- return (a[0] ?? "").localeCompare(b[0] ?? "");
2727
+ return byCodeUnit(a[0] ?? "", b[0] ?? "");
2604
2728
  }
2605
2729
  function mergeTranslations(cfg, locale, translated, keys) {
2606
2730
  const source = readCatalog(cfg, cfg.sourceLocale);
@@ -2666,7 +2790,7 @@ function formatTranslateFailures(failed) {
2666
2790
  async function resolveProvider(cfg, model) {
2667
2791
  const configured = cfg.translate.provider;
2668
2792
  if (typeof configured === "function") return configured;
2669
- const { claudeProvider } = await import("./claude-BFIWiu_4.js");
2793
+ const { claudeProvider } = await import("./claude-mvcniUPN.js");
2670
2794
  return claudeProvider({ model: model ?? cfg.translate.model });
2671
2795
  }
2672
2796
  function structureMatches(source, translated) {
@@ -2975,7 +3099,7 @@ async function renderSite(cfg, options = {}) {
2975
3099
  base,
2976
3100
  storageKey: redirect.storageKey
2977
3101
  };
2978
- const catalogs = loadCatalogs(cfg);
3102
+ const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), await extractProject(cfg));
2979
3103
  const instances = new Map(locales.map((locale) => [locale, localeInstance(catalogs, locale, cfg.sourceLocale)]));
2980
3104
  if (clean) {
2981
3105
  for (const locale of locales) if (locale !== cfg.sourceLocale) rmSync(join(site, locale), {
@@ -3468,6 +3592,6 @@ function formatCliError(error) {
3468
3592
  return message.startsWith("[verbaly]") ? message : `[verbaly] ${message}`;
3469
3593
  }
3470
3594
  //#endregion
3471
- export { 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, 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, resolveConfig, resolveProvider, resolveVirtualId, runBuildGate, saveDrafts, shippedCatalogs, stableKey, status, syncCatalogs, syncProject, targetLocales, transformCode, transformSource, translateCatalogs, updateState, validateMessage, validatePair, watchTree, wrapProject, writeCatalog, writeDrafts, writeDts };
3595
+ export { 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, 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, writeCatalog, writeDrafts, writeDts };
3472
3596
 
3473
3597
  //# sourceMappingURL=index.js.map