@verbaly/compiler 0.44.0 → 0.45.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 +25 -2
- package/dist/{claude-BspJ1dOt.js → claude-DAzXUvmS.js} +2 -2
- package/dist/{claude-BspJ1dOt.js.map → claude-DAzXUvmS.js.map} +1 -1
- package/dist/cli.js +46 -6
- package/dist/cli.js.map +1 -1
- package/dist/{config-cXLsNoMP.js → config-ByO-vjIC.js} +3 -2
- package/dist/config-ByO-vjIC.js.map +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +65 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/config-cXLsNoMP.js.map +0 -1
|
@@ -23,7 +23,8 @@ function resolveConfig(config = {}) {
|
|
|
23
23
|
exclude: config.exclude ?? ["**/node_modules/**", "**/dist/**"],
|
|
24
24
|
dts: typeof config.dts === "string" ? resolve(root, config.dts) : config.dts,
|
|
25
25
|
translate: config.translate ?? {},
|
|
26
|
-
render: config.render ?? {}
|
|
26
|
+
render: config.render ?? {},
|
|
27
|
+
bundle: config.bundle ?? {}
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
const CONFIG_FILES = [
|
|
@@ -78,4 +79,4 @@ function definedOnly(config) {
|
|
|
78
79
|
//#endregion
|
|
79
80
|
export { targetLocales as a, resolveConfig as i, isModuleNotFound as n, loadConfig as r, findConfigFile as t };
|
|
80
81
|
|
|
81
|
-
//# sourceMappingURL=config-
|
|
82
|
+
//# sourceMappingURL=config-ByO-vjIC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-ByO-vjIC.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 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 locales = new Set<string>([sourceLocale, ...(config.locales ?? [])]);\n if (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 // 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":";;;;;ACyEA,SAAgB,cAAc,SAAwB,CAAC,GAAmB;CACxE,MAAM,OAAO,QAAQ,OAAO,QAAQ,QAAQ,IAAI,CAAC;CACjD,MAAM,MAAM,QAAQ,MAAM,OAAO,OAAO,SAAS;CACjD,MAAM,eAAe,OAAO,gBAAgB;CAE5C,MAAM,0BAAU,IAAI,IAAY,CAAC,cAAc,GAAI,OAAO,WAAW,CAAC,CAAE,CAAC;CACzE,IAAI,WAAW,GAAG,GACX;OAAA,MAAM,QAAQ,YAAY,GAAG,GAChC,IAAI,KAAK,SAAS,OAAO,KAAK,CAAC,KAAK,WAAW,GAAG,KAAK,SAAS,cAC9D,QAAQ,IAAI,KAAK,MAAM,GAAG,EAAE,CAAC;CAAA;CAKnC,OAAO;EACL;EACA;EACA;EAEA,SAAS,OAAO,YAAY,OAAO,SAAS,yBAAyB;EAErE,KAAK,OAAO;EACZ,UAAU,OAAO;EACjB,SAAS,CAAC,GAAG,OAAO;EACpB,SAAS,OAAO,WAAW,CAAC,yDAAyD;EACrF,SAAS,OAAO,WAAW,CAAC,sBAAsB,YAAY;EAC9D,KAAK,OAAO,OAAO,QAAQ,WAAW,QAAQ,MAAM,OAAO,GAAG,IAAI,OAAO;EACzE,WAAW,OAAO,aAAa,CAAC;EAChC,QAAQ,OAAO,UAAU,CAAC;EAC1B,QAAQ,OAAO,UAAU,CAAC;CAC5B;AACF;AAEA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;AACF;AAEA,SAAgB,eAAe,MAAkC;CAC/D,OAAO,aAAa,MAAM,SAAS,WAAW,KAAK,MAAM,IAAI,CAAC,CAAC;AACjE;AAEA,eAAsB,eAAe,MAAsC;CACzE,KAAK,MAAM,QAAQ,CAAC,qBAAqB,oBAAoB,GAAG;EAC9D,MAAM,OAAO,KAAK,MAAM,IAAI;EAC5B,IAAI,WAAW,IAAI,GAEjB,QAAO,MADY,OAAO,cAAc,IAAI,CAAC,CAAC,MAAA,CACnC,WAAW,CAAC;CAE3B;CACA,KAAK,MAAM,QAAQ,CAAC,qBAAqB,oBAAoB,GAAG;EAC9D,MAAM,OAAO,KAAK,MAAM,IAAI;EAC5B,IAAI,WAAW,IAAI,GAAG,OAAO,aAAa,IAAI;CAChD;CACA,MAAM,WAAW,KAAK,MAAM,qBAAqB;CACjD,IAAI,WAAW,QAAQ,GACrB,OAAO,KAAK,MAAM,aAAa,UAAU,MAAM,CAAC;CAElD,OAAO,CAAC;AACV;AAEA,eAAe,aAAa,MAAsC;CAChE,IAAI;EACF,MAAM,EAAE,kBAAkB,MAAM,OAAO;EACvC,MAAM,EAAE,QAAQ,MAAM,cAA2C,EAAE,UAAU,KAAK,CAAC;EACnF,OAAO,IAAI,WAAW,CAAC;CACzB,SAAS,OAAO;EACd,IAAI,iBAAiB,OAAO,SAAS,GACnC,MAAM,IAAI,MAAM,aAAa,KAAK,sDAAsD,EACtF,OAAO,MACT,CAAC;EAEH,MAAM;CACR;AACF;AAEA,SAAgB,iBAAiB,OAAgB,MAAuB;CACtE,OACE,iBAAiB,SAChB,MAA4B,SAAS,0BACtC,MAAM,QAAQ,SAAS,IAAI;AAE/B;AAGA,SAAgB,cAAc,KAAqB,UAA+B;CAChF,QAAQ,YAAY,IAAI,QAAA,CAAS,QAC9B,WAAW,WAAW,IAAI,gBAAgB,IAAI,QAAQ,SAAS,MAAM,CACxE;AACF;AAGA,eAAsB,WACpB,MACA,YAA2B,CAAC,GACH;CAEzB,OAAO,cAAc;EAAE,GAAG,MADD,eAAe,IAAI;EACN,GAAG,YAAY,SAAS;EAAG;CAAK,CAAC;AACzE;AAEA,SAAS,YAAY,QAAsC;CACzD,OAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CAClE;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -65,6 +65,9 @@ interface RedirectConfig {
|
|
|
65
65
|
on?: 'root' | 'all';
|
|
66
66
|
storageKey?: string | false;
|
|
67
67
|
}
|
|
68
|
+
interface BundleConfig {
|
|
69
|
+
exclude?: string[];
|
|
70
|
+
}
|
|
68
71
|
interface RenderConfig {
|
|
69
72
|
links?: Record<string, RichLink>;
|
|
70
73
|
site?: string;
|
|
@@ -89,6 +92,7 @@ interface VerbalyConfig {
|
|
|
89
92
|
dts?: string | false;
|
|
90
93
|
translate?: TranslateConfig;
|
|
91
94
|
render?: RenderConfig;
|
|
95
|
+
bundle?: BundleConfig;
|
|
92
96
|
}
|
|
93
97
|
interface ResolvedConfig {
|
|
94
98
|
root: string;
|
|
@@ -103,6 +107,7 @@ interface ResolvedConfig {
|
|
|
103
107
|
dts: string | false | undefined;
|
|
104
108
|
translate: TranslateConfig;
|
|
105
109
|
render: RenderConfig;
|
|
110
|
+
bundle: BundleConfig;
|
|
106
111
|
}
|
|
107
112
|
declare function resolveConfig(config?: VerbalyConfig): ResolvedConfig;
|
|
108
113
|
declare function loadConfig(root: string, overrides?: VerbalyConfig): Promise<ResolvedConfig>;
|
|
@@ -163,6 +168,9 @@ declare class MessageRegistry {
|
|
|
163
168
|
origins(): Map<string, string[]>;
|
|
164
169
|
}
|
|
165
170
|
//#endregion
|
|
171
|
+
//#region src/bundle.d.ts
|
|
172
|
+
declare function clientCatalogs(cfg: ResolvedConfig, catalogs: Catalogs): Catalogs;
|
|
173
|
+
//#endregion
|
|
166
174
|
//#region src/extract.d.ts
|
|
167
175
|
declare function extractProject(cfg: ResolvedConfig): Promise<MessageRegistry>;
|
|
168
176
|
declare function collectOrigins(cfg: ResolvedConfig): Promise<Record<string, string[]>>;
|
|
@@ -328,5 +336,5 @@ interface RenderSiteResult {
|
|
|
328
336
|
declare function renderSite(cfg: ResolvedConfig, options?: RenderSiteOptions): Promise<RenderSiteResult>;
|
|
329
337
|
declare function formatRenderWarnings(result: RenderSiteResult, sourceLocale: string): string[];
|
|
330
338
|
//#endregion
|
|
331
|
-
export { type BrokenEntry, 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, 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 };
|
|
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 };
|
|
332
340
|
//# 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-
|
|
1
|
+
import { a as targetLocales, i as resolveConfig, r as loadConfig, t as findConfigFile } from "./config-ByO-vjIC.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";
|
|
@@ -112,6 +112,55 @@ function needsRelative(catalogs) {
|
|
|
112
112
|
return false;
|
|
113
113
|
}
|
|
114
114
|
//#endregion
|
|
115
|
+
//#region src/text.ts
|
|
116
|
+
function counted(count, noun, many = `${noun}s`) {
|
|
117
|
+
return `${count} ${count === 1 ? noun : many}`;
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/bundle.ts
|
|
121
|
+
function isExcluded(key, prefixes) {
|
|
122
|
+
return prefixes.some((prefix) => key === prefix || key.startsWith(`${prefix}.`));
|
|
123
|
+
}
|
|
124
|
+
function clientCatalogs(cfg, catalogs) {
|
|
125
|
+
const prefixes = cfg.bundle.exclude ?? [];
|
|
126
|
+
if (prefixes.length === 0) return catalogs;
|
|
127
|
+
const out = {};
|
|
128
|
+
for (const [locale, catalog] of Object.entries(catalogs)) {
|
|
129
|
+
const kept = {};
|
|
130
|
+
for (const [key, message] of Object.entries(catalog)) if (!isExcluded(key, prefixes)) kept[key] = message;
|
|
131
|
+
out[locale] = kept;
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function auditBundle(cfg, catalogs, registry) {
|
|
136
|
+
const prefixes = cfg.bundle.exclude ?? [];
|
|
137
|
+
if (prefixes.length === 0) return [];
|
|
138
|
+
const source = Object.keys(catalogs[cfg.sourceLocale] ?? {});
|
|
139
|
+
const used = registry.usedKeys();
|
|
140
|
+
const issues = [];
|
|
141
|
+
for (const prefix of prefixes) {
|
|
142
|
+
if (!source.some((key) => isExcluded(key, [prefix]))) {
|
|
143
|
+
issues.push({
|
|
144
|
+
prefix,
|
|
145
|
+
problem: `matches no key in ${cfg.sourceLocale}.json, so it excludes nothing`,
|
|
146
|
+
fix: "check the spelling against your catalog, or drop it from bundle.exclude"
|
|
147
|
+
});
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const files = /* @__PURE__ */ new Set();
|
|
151
|
+
for (const [key, where] of used) if (isExcluded(key, [prefix])) for (const file of where) files.add(file);
|
|
152
|
+
if (files.size > 0) issues.push({
|
|
153
|
+
prefix,
|
|
154
|
+
problem: `is read by t() in ${counted(files.size, "file")}, where it resolves to the key itself`,
|
|
155
|
+
fix: "pre-render those pages with render, load the group with addMessages, or stop excluding it"
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return issues;
|
|
159
|
+
}
|
|
160
|
+
function formatBundleIssue(issue) {
|
|
161
|
+
return `bundle.exclude "${issue.prefix}" ${issue.problem}`;
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
115
164
|
//#region src/warn.ts
|
|
116
165
|
const warned = /* @__PURE__ */ new Set();
|
|
117
166
|
function warnOnce(message, dedupeKey = message) {
|
|
@@ -1166,11 +1215,12 @@ function resolveVirtualId(id) {
|
|
|
1166
1215
|
if (id === "virtual:verbaly" || id.startsWith(`virtual:verbaly/`)) return "\0" + id;
|
|
1167
1216
|
}
|
|
1168
1217
|
function loadVirtualModule(id, cfg, catalogs) {
|
|
1218
|
+
const client = clientCatalogs(cfg, catalogs);
|
|
1169
1219
|
if (id === RESOLVED_VIRTUAL_ID) return generateRuntimeModule(cfg, {
|
|
1170
|
-
icu: cfg.icu ?? needsIcu(
|
|
1171
|
-
relative: cfg.relative ?? needsRelative(
|
|
1220
|
+
icu: cfg.icu ?? needsIcu(client),
|
|
1221
|
+
relative: cfg.relative ?? needsRelative(client)
|
|
1172
1222
|
});
|
|
1173
|
-
if (id.startsWith(LOCALE_MODULE_PREFIX)) return generateLocaleModule(
|
|
1223
|
+
if (id.startsWith(LOCALE_MODULE_PREFIX)) return generateLocaleModule(client[id.slice(LOCALE_MODULE_PREFIX.length)] ?? {});
|
|
1174
1224
|
}
|
|
1175
1225
|
function isTransformTarget(id) {
|
|
1176
1226
|
return SOURCE_FILE_RE.test(id) && !id.includes("node_modules") && !id.startsWith("\0");
|
|
@@ -1195,7 +1245,9 @@ function transformSource(code, id, registry) {
|
|
|
1195
1245
|
};
|
|
1196
1246
|
}
|
|
1197
1247
|
function runBuildGate(cfg, registry, failOnMissing) {
|
|
1198
|
-
const
|
|
1248
|
+
const catalogs = loadCatalogs(cfg);
|
|
1249
|
+
for (const issue of auditBundle(cfg, catalogs, registry)) warnOnce(`${formatBundleIssue(issue)}\n fix: ${issue.fix}`, `bundle:${issue.prefix}`);
|
|
1250
|
+
const found = check(cfg, catalogs, registry);
|
|
1199
1251
|
const result = failOnMissing === false ? {
|
|
1200
1252
|
...found,
|
|
1201
1253
|
missing: []
|
|
@@ -1254,11 +1306,6 @@ function effectiveDrafts(drafts, catalogs) {
|
|
|
1254
1306
|
return out;
|
|
1255
1307
|
}
|
|
1256
1308
|
//#endregion
|
|
1257
|
-
//#region src/text.ts
|
|
1258
|
-
function counted(count, noun, many = `${noun}s`) {
|
|
1259
|
-
return `${count} ${count === 1 ? noun : many}`;
|
|
1260
|
-
}
|
|
1261
|
-
//#endregion
|
|
1262
1309
|
//#region src/status.ts
|
|
1263
1310
|
function status(cfg, catalogs, registry, drafts = {}) {
|
|
1264
1311
|
const extracted = registry.messages();
|
|
@@ -1439,7 +1486,7 @@ function formatTranslateFailures(failed) {
|
|
|
1439
1486
|
async function resolveProvider(cfg, model) {
|
|
1440
1487
|
const configured = cfg.translate.provider;
|
|
1441
1488
|
if (typeof configured === "function") return configured;
|
|
1442
|
-
const { claudeProvider } = await import("./claude-
|
|
1489
|
+
const { claudeProvider } = await import("./claude-DAzXUvmS.js");
|
|
1443
1490
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
1444
1491
|
}
|
|
1445
1492
|
function structureMatches(source, translated) {
|
|
@@ -1667,6 +1714,12 @@ async function doctor(cfg) {
|
|
|
1667
1714
|
if (orphans.length > 0) warn("orphans", `${counted(orphans.length, "catalog key")} no longer referenced in code (${preview(orphans)})`, "run `npx verbaly extract --prune` to drop them");
|
|
1668
1715
|
else ok("orphans", "no orphan keys");
|
|
1669
1716
|
}
|
|
1717
|
+
const excluded = cfg.bundle.exclude ?? [];
|
|
1718
|
+
if (excluded.length > 0 && catalogsHealthy) {
|
|
1719
|
+
const issues = auditBundle(cfg, catalogs, registry);
|
|
1720
|
+
for (const issue of issues) warn("bundle", formatBundleIssue(issue), issue.fix);
|
|
1721
|
+
if (issues.length === 0) ok("bundle", `${counted(excluded.length, "group")} kept out of the client (${preview(excluded)})`);
|
|
1722
|
+
}
|
|
1670
1723
|
if (catalogsHealthy) {
|
|
1671
1724
|
const result = check(cfg, catalogs, registry);
|
|
1672
1725
|
if (result.unknown.length > 0) error("keys", `${counted(result.unknown.length, "unknown key")} used in code (${preview(result.unknown.map((u) => u.key))})`, "fix the key or add it to the catalogs (`npx verbaly check` for details)");
|
|
@@ -2270,6 +2323,6 @@ function decodeEntities(text) {
|
|
|
2270
2323
|
return text.replace(/"/g, "\"").replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
2271
2324
|
}
|
|
2272
2325
|
//#endregion
|
|
2273
|
-
export { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, check, 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 };
|
|
2326
|
+
export { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, 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 };
|
|
2274
2327
|
|
|
2275
2328
|
//# sourceMappingURL=index.js.map
|