@verbaly/compiler 0.68.0 → 0.69.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/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,16 @@ ${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
+ export function t<K extends VerbalyKey | TemplateStringsArray>(
1454
+ first: K,
1455
+ ...rest: K extends VerbalyKey
1456
+ ? [VerbalyMessages[K]] extends [never] ? [] : [VerbalyMessages[K]]
1457
+ : unknown[]
1377
1458
  ): string;
1378
- export function t(strings: TemplateStringsArray, ...values: unknown[]): string;
1379
1459
  export namespace t {
1380
1460
  export function id(
1381
1461
  key: string,
@@ -1392,6 +1472,14 @@ ${lines.join("\n")}
1392
1472
  ): Promise<void>;
1393
1473
  export function getLocale(): string;
1394
1474
  export function subscribe(listener: () => void): () => void;
1475
+
1476
+ // nested, so it augments verbaly: at the top of a script it would replace the real module
1477
+ module 'verbaly' {
1478
+ interface Register {
1479
+ t: typeof t;
1480
+ locale: VerbalyLocale;
1481
+ }
1482
+ }
1395
1483
  }
1396
1484
 
1397
1485
  declare module 'virtual:verbaly/locale/*' {
@@ -1400,16 +1488,51 @@ declare module 'virtual:verbaly/locale/*' {
1400
1488
  }
1401
1489
  `;
1402
1490
  }
1491
+ function projectDtsOptions(cfg) {
1492
+ return {
1493
+ inlineCatalog: cfg.render.inlineCatalog === true,
1494
+ locales: cfg.locales
1495
+ };
1496
+ }
1403
1497
  function writeDts(cfg, catalog, file) {
1404
1498
  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 });
1499
+ if (target === false) return void 0;
1500
+ let existing;
1408
1501
  try {
1409
- if (readFileSync(file, "utf8") === content) return;
1502
+ existing = readFileSync(target, "utf8");
1410
1503
  } catch {}
1411
- mkdirSync(dirname(file), { recursive: true });
1412
- writeFileSync(file, content);
1504
+ const content = withLineEndings(generateDts(catalog, projectDtsOptions(cfg)), existing);
1505
+ const changed = existing !== content;
1506
+ if (changed) {
1507
+ mkdirSync(dirname(target), { recursive: true });
1508
+ writeFileSync(target, content);
1509
+ }
1510
+ removeRootDts(cfg, target);
1511
+ if (resolve(target).startsWith(resolve(cfg.root, ".verbaly") + sep)) {
1512
+ const ignore = join(cfg.root, ".verbaly", ".gitignore");
1513
+ if (!existsSync(ignore)) writeFileSync(ignore, "*\n");
1514
+ const state = includeTypes(cfg.root, target);
1515
+ const entry = relative(cfg.root, target).replaceAll("\\", "/");
1516
+ if (state === "added") warnOnce(`added "${entry}" to the include of tsconfig.json, so TypeScript reads the types`);
1517
+ else if (state === "unreadable") warnOnce(`tsconfig.json could not be read, so add "${entry}" to its include yourself`);
1518
+ }
1519
+ return {
1520
+ file: target,
1521
+ changed
1522
+ };
1523
+ }
1524
+ function removeRootDts(cfg, target) {
1525
+ const old = join(cfg.root, "verbaly.d.ts");
1526
+ if (resolve(target) === resolve(old)) return;
1527
+ let head;
1528
+ try {
1529
+ head = readFileSync(old, "utf8").slice(0, 36);
1530
+ } catch {
1531
+ return;
1532
+ }
1533
+ if (head !== "// generated by verbaly: do not edit") return;
1534
+ rmSync(old);
1535
+ warnOnce(`the types live in ${relative(cfg.root, target).replaceAll("\\", "/")} now, so the verbaly.d.ts Verbaly wrote at the root was removed`);
1413
1536
  }
1414
1537
  //#endregion
1415
1538
  //#region src/findings.ts
@@ -1563,10 +1686,10 @@ function readState(cfg) {
1563
1686
  }
1564
1687
  }
1565
1688
  function saveState(cfg, state) {
1566
- const serialized = serializeState(state);
1689
+ const fresh = serializeState(state);
1567
1690
  const path = statePath(cfg);
1568
1691
  const legacy = statePath(cfg, LEGACY_DRAFTS_FILE);
1569
- if (serialized === void 0) {
1692
+ if (fresh === void 0) {
1570
1693
  rmSync(path, { force: true });
1571
1694
  rmSync(legacy, { force: true });
1572
1695
  return;
@@ -1577,6 +1700,7 @@ function saveState(cfg, state) {
1577
1700
  } catch {
1578
1701
  mkdirSync(cfg.dir, { recursive: true });
1579
1702
  }
1703
+ const serialized = withLineEndings(fresh, existing);
1580
1704
  if (existing !== serialized) writeFileSync(path, serialized);
1581
1705
  if (existsSync(legacy)) rmSync(legacy);
1582
1706
  }
@@ -1689,7 +1813,7 @@ function outdatedTranslations(cfg, catalogs, fingerprints) {
1689
1813
  });
1690
1814
  }
1691
1815
  }
1692
- return out.sort((a, b) => a.locale.localeCompare(b.locale) || a.key.localeCompare(b.key));
1816
+ return out.sort((a, b) => byCodeUnit(a.locale, b.locale) || byCodeUnit(a.key, b.key));
1693
1817
  }
1694
1818
  function sourceOf(stamped) {
1695
1819
  return stamped.slice(0, stamped.indexOf("."));
@@ -1822,85 +1946,11 @@ function suggestTag(tag) {
1822
1946
  }
1823
1947
  //#endregion
1824
1948
  //#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
1949
  function cliReachable(root) {
1896
1950
  const bin = join(root, "node_modules", ".bin");
1897
1951
  return existsSync(join(bin, "verbaly")) || existsSync(join(bin, "verbaly.CMD"));
1898
1952
  }
1899
1953
  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
1954
  function configSource(options, typescript) {
1905
1955
  const fields = [` sourceLocale: '${options.sourceLocale ?? "en"}',`];
1906
1956
  if (options.locales?.length) fields.push(` locales: [${options.locales.map((l) => `'${l}'`).join(", ")}],`);
@@ -1967,7 +2017,7 @@ async function init(input = {}) {
1967
2017
  }
1968
2018
  }
1969
2019
  const host = detectHost(root);
1970
- const next = host ? [`pnpm add -D ${host.pkg}`, host.wire] : ["run \"verbaly extract\" after writing your first t`…` message"];
2020
+ const next = host ? [installCommand(root, host.install), host.wire] : ["run \"verbaly extract\" after writing your first t`…` message"];
1971
2021
  return {
1972
2022
  created,
1973
2023
  skipped,
@@ -2113,17 +2163,6 @@ function formatCheckWarnings(result, root, options = {}) {
2113
2163
  return lines.join("\n");
2114
2164
  }
2115
2165
  //#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
2166
  //#region src/transform.ts
2128
2167
  function quote(text, single) {
2129
2168
  if (!single) return JSON.stringify(text);
@@ -2212,6 +2251,65 @@ function buildFingerprints(cfg) {
2212
2251
  return state.fingerprints;
2213
2252
  }
2214
2253
  //#endregion
2254
+ //#region src/scope.ts
2255
+ const TAGGED_HINT = /(?<![\w$.])\$?t(?:\.id\s*\([^)]*\))?\s*`/;
2256
+ const NOT_SOURCE = [
2257
+ "**/node_modules/**",
2258
+ "**/dist/**",
2259
+ "**/build/**",
2260
+ "**/out/**",
2261
+ "**/coverage/**"
2262
+ ];
2263
+ function relativeId(cfg, id) {
2264
+ return relative(cfg.root, id).replaceAll("\\", "/");
2265
+ }
2266
+ function suggestedPattern(rel) {
2267
+ const slash = rel.indexOf("/");
2268
+ return slash < 0 ? rel : `${rel.slice(0, slash)}/**/*.${SOURCE_EXTENSIONS}`;
2269
+ }
2270
+ function createOutsideCheck(cfg) {
2271
+ if (cfg.include.length === 0) return () => void 0;
2272
+ const included = picomatch(cfg.include);
2273
+ const excluded = picomatch(cfg.exclude);
2274
+ return (code, id) => {
2275
+ const rel = relativeId(cfg, id);
2276
+ if (rel.startsWith("..") || included(rel) || excluded(rel)) return void 0;
2277
+ if (!TAGGED_HINT.test(code)) return void 0;
2278
+ if (analyzeFile(code, id).tagged.length === 0) return void 0;
2279
+ return {
2280
+ file: id,
2281
+ pattern: suggestedPattern(rel)
2282
+ };
2283
+ };
2284
+ }
2285
+ function formatOutside(cfg, found) {
2286
+ 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)`;
2287
+ }
2288
+ async function reportOutsideInclude(cfg) {
2289
+ for (const found of await filesOutsideInclude(cfg)) warnOnce(formatOutside(cfg, found), `outside:${found.file}`);
2290
+ }
2291
+ async function filesOutsideInclude(cfg) {
2292
+ if (cfg.include.length === 0) return [];
2293
+ const check = createOutsideCheck(cfg);
2294
+ const files = await glob([`**/*.${SOURCE_EXTENSIONS}`], {
2295
+ cwd: cfg.root,
2296
+ ignore: [...NOT_SOURCE, ...cfg.exclude],
2297
+ absolute: true
2298
+ });
2299
+ const found = [];
2300
+ for (const file of files.sort()) {
2301
+ let code;
2302
+ try {
2303
+ code = readFileSync(file, "utf8");
2304
+ } catch {
2305
+ continue;
2306
+ }
2307
+ const outside = check(code, file);
2308
+ if (outside) found.push(outside);
2309
+ }
2310
+ return found;
2311
+ }
2312
+ //#endregion
2215
2313
  //#region src/drafts.ts
2216
2314
  function loadDrafts(cfg) {
2217
2315
  return loadState(cfg).drafts;
@@ -2385,14 +2483,23 @@ async function doctor(cfg) {
2385
2483
  const installed = WIRING_PACKAGES.find((pkg) => deps[pkg]);
2386
2484
  if (!host) ok("plugin", "no framework or bundler detected, the CLI flow (extract/check) applies");
2387
2485
  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}`);
2486
+ else warn("plugin", `${host.name} detected but ${host.pkg} is not installed`, `${installCommand(cfg.root, host.install)}, then ${host.wire}`);
2389
2487
  const scanning = cfg.include.length > 0;
2390
2488
  if (!scanning) ok("sources", "source scanning is off (include: []), the catalogs are the source of truth");
2391
2489
  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");
2490
+ const dtsPath = cfg.dts;
2491
+ const shown = rel(dtsPath);
2492
+ 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`";
2493
+ const expected = generateDts(source, projectDtsOptions(cfg));
2494
+ if (!existsSync(dtsPath)) warn("types", `${shown} has not been generated`, regenerate);
2495
+ else if (readFileSync(dtsPath, "utf8").replace(/\r\n/g, "\n") !== expected) warn("types", `${shown} is stale`, "run `npx verbaly typegen`");
2496
+ else ok("types", `${shown} is up to date`);
2497
+ if (dtsPath.startsWith(join(cfg.root, ".verbaly"))) {
2498
+ const state = typesIncluded(cfg.root, dtsPath);
2499
+ 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`);
2500
+ }
2501
+ const old = join(cfg.root, "verbaly.d.ts");
2502
+ 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
2503
  }
2397
2504
  const registry = await extractProject(cfg);
2398
2505
  if (scanning) {
@@ -2401,6 +2508,12 @@ async function doctor(cfg) {
2401
2508
  const first = unreadable[0];
2402
2509
  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
2510
  }
2511
+ const outside = await filesOutsideInclude(cfg);
2512
+ if (outside.length > 0) {
2513
+ const files = outside.map((entry) => rel(entry.file));
2514
+ const patterns = [...new Set(outside.map((entry) => `"${entry.pattern}"`))];
2515
+ 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`);
2516
+ }
2404
2517
  const stray = registry.strayImports();
2405
2518
  if (stray.length > 0) {
2406
2519
  const files = [...new Set(stray.map((entry) => rel(entry.file)))];
@@ -2596,11 +2709,11 @@ async function translateCatalogs(cfg, catalogs, provider, options = {}) {
2596
2709
  });
2597
2710
  for (const locale of Object.keys(result.translated)) result.translated[locale].sort();
2598
2711
  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));
2712
+ result.failed.sort((a, b) => byCodeUnit(a.locale, b.locale) || compare(a.keys, b.keys));
2600
2713
  return result;
2601
2714
  }
2602
2715
  function compare(a, b) {
2603
- return (a[0] ?? "").localeCompare(b[0] ?? "");
2716
+ return byCodeUnit(a[0] ?? "", b[0] ?? "");
2604
2717
  }
2605
2718
  function mergeTranslations(cfg, locale, translated, keys) {
2606
2719
  const source = readCatalog(cfg, cfg.sourceLocale);
@@ -2666,7 +2779,7 @@ function formatTranslateFailures(failed) {
2666
2779
  async function resolveProvider(cfg, model) {
2667
2780
  const configured = cfg.translate.provider;
2668
2781
  if (typeof configured === "function") return configured;
2669
- const { claudeProvider } = await import("./claude-BFIWiu_4.js");
2782
+ const { claudeProvider } = await import("./claude-mvcniUPN.js");
2670
2783
  return claudeProvider({ model: model ?? cfg.translate.model });
2671
2784
  }
2672
2785
  function structureMatches(source, translated) {
@@ -2975,7 +3088,7 @@ async function renderSite(cfg, options = {}) {
2975
3088
  base,
2976
3089
  storageKey: redirect.storageKey
2977
3090
  };
2978
- const catalogs = loadCatalogs(cfg);
3091
+ const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), await extractProject(cfg));
2979
3092
  const instances = new Map(locales.map((locale) => [locale, localeInstance(catalogs, locale, cfg.sourceLocale)]));
2980
3093
  if (clean) {
2981
3094
  for (const locale of locales) if (locale !== cfg.sourceLocale) rmSync(join(site, locale), {
@@ -3468,6 +3581,6 @@ function formatCliError(error) {
3468
3581
  return message.startsWith("[verbaly]") ? message : `[verbaly] ${message}`;
3469
3582
  }
3470
3583
  //#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 };
3584
+ 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
3585
 
3473
3586
  //# sourceMappingURL=index.js.map