@verbaly/compiler 0.74.0 → 0.75.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 +3 -1
- package/dist/{claude-Baoc6pYL.js → claude-DcV4YBbO.js} +2 -2
- package/dist/{claude-Baoc6pYL.js.map → claude-DcV4YBbO.js.map} +1 -1
- package/dist/cli.js +39 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -15
- package/dist/index.js.map +1 -1
- package/dist/{text-BMBWE8tL.js → text-BtTS6qL7.js} +40 -4
- package/dist/text-BtTS6qL7.js.map +1 -0
- package/package.json +3 -2
- package/dist/text-BMBWE8tL.js.map +0 -1
|
@@ -138,6 +138,17 @@ function defaultTypesPath(root, host = detectHost(root)?.name) {
|
|
|
138
138
|
return existsSync(join(root, "src")) ? join(root, "src", "verbaly.d.ts") : join(root, "verbaly.d.ts");
|
|
139
139
|
}
|
|
140
140
|
//#endregion
|
|
141
|
+
//#region src/warn.ts
|
|
142
|
+
const warned = /* @__PURE__ */ new Set();
|
|
143
|
+
function warnOnce(message, dedupeKey = message) {
|
|
144
|
+
if (warned.has(dedupeKey)) return;
|
|
145
|
+
warned.add(dedupeKey);
|
|
146
|
+
console.warn(`[verbaly] ${message}`);
|
|
147
|
+
}
|
|
148
|
+
function warnParseError(file, message) {
|
|
149
|
+
warnOnce(`${file}: could not be parsed (${message}), its messages were not extracted`);
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
141
152
|
//#region src/config.ts
|
|
142
153
|
const SOURCE_EXTENSIONS = "{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}";
|
|
143
154
|
function resolveConfig(config = {}) {
|
|
@@ -217,12 +228,37 @@ function isModuleNotFound(error, name) {
|
|
|
217
228
|
function targetLocales(cfg, override) {
|
|
218
229
|
return (override ?? cfg.locales).filter((locale) => locale !== cfg.sourceLocale && cfg.locales.includes(locale));
|
|
219
230
|
}
|
|
220
|
-
async function loadConfig(root, overrides = {}) {
|
|
231
|
+
async function loadConfig(root, overrides = {}, from = {}) {
|
|
232
|
+
const fileConfig = await loadConfigFile(root);
|
|
233
|
+
if (from.plugin) warnPluginOnly(root, fileConfig, overrides);
|
|
221
234
|
return resolveConfig({
|
|
222
|
-
...
|
|
235
|
+
...fileConfig,
|
|
236
|
+
...definedOnly(overrides),
|
|
237
|
+
root
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
const READ_BY_CLI = [
|
|
241
|
+
"sourceLocale",
|
|
242
|
+
"locales",
|
|
243
|
+
"dir",
|
|
244
|
+
"include",
|
|
245
|
+
"exclude"
|
|
246
|
+
];
|
|
247
|
+
function warnPluginOnly(root, file, overrides) {
|
|
248
|
+
const cli = resolveConfig({
|
|
249
|
+
...file,
|
|
250
|
+
root
|
|
251
|
+
});
|
|
252
|
+
const build = resolveConfig({
|
|
253
|
+
...file,
|
|
223
254
|
...definedOnly(overrides),
|
|
224
255
|
root
|
|
225
256
|
});
|
|
257
|
+
const keys = READ_BY_CLI.filter((key) => overrides[key] !== void 0 && JSON.stringify(cli[key]) !== JSON.stringify(build[key]));
|
|
258
|
+
if (keys.length === 0) return;
|
|
259
|
+
const names = keys.length > 1 ? `${keys.slice(0, -1).join(", ")} and ${keys.at(-1)}` : keys[0];
|
|
260
|
+
const [verb, pronoun] = keys.length > 1 ? ["are", "them"] : ["is", "it"];
|
|
261
|
+
warnOnce(`${names} ${verb} set in the plugin options, which \`verbaly check\` and \`verbaly extract\` never read: move ${pronoun} to verbaly.config so the command line checks what the build ships`, `plugin-only:${root}`);
|
|
226
262
|
}
|
|
227
263
|
function definedOnly(config) {
|
|
228
264
|
return Object.fromEntries(Object.entries(config).filter(([, value]) => value !== void 0));
|
|
@@ -239,6 +275,6 @@ function byCodeUnit(a, b) {
|
|
|
239
275
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
240
276
|
}
|
|
241
277
|
//#endregion
|
|
242
|
-
export { findConfigFile as a, loadConfigFile as c,
|
|
278
|
+
export { findConfigFile as a, loadConfigFile as c, warnOnce as d, warnParseError as f, readDependencies as g, installCommand as h, SOURCE_EXTENSIONS as i, resolveConfig as l, detectHost as m, counted as n, isModuleNotFound as o, WIRING_PACKAGES as p, truncate as r, loadConfig as s, byCodeUnit as t, targetLocales as u };
|
|
243
279
|
|
|
244
|
-
//# sourceMappingURL=text-
|
|
280
|
+
//# sourceMappingURL=text-BtTS6qL7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-BtTS6qL7.js","names":[],"sources":["../src/host.ts","../src/pseudo.ts","../src/warn.ts","../src/config.ts","../src/text.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\n\nexport type Host =\n 'nuxt' | 'next' | 'sveltekit' | 'astro' | 'vite' | 'webpack' | 'rspack' | 'rollup' | 'esbuild';\n\nexport interface HostSetup {\n name: Host;\n // the package that wires the build, which is how doctor tells the setup is done\n pkg: string;\n // what that package's README installs, so init and doctor never contradict it\n install: string[];\n wire: string;\n}\n\nconst HOSTS: (HostSetup & { dep: string })[] = [\n {\n name: 'nuxt',\n dep: 'nuxt',\n pkg: '@verbaly/nuxt',\n install: ['verbaly', '@verbaly/nuxt', '@verbaly/vue'],\n wire: \"add '@verbaly/nuxt' to the modules in nuxt.config\",\n },\n {\n name: 'next',\n dep: 'next',\n pkg: '@verbaly/next',\n install: ['verbaly', '@verbaly/next', '@verbaly/react'],\n wire: 'wrap the export of next.config with withVerbaly',\n },\n {\n name: 'sveltekit',\n dep: '@sveltejs/kit',\n pkg: '@verbaly/vite',\n install: ['verbaly', '@verbaly/sveltekit', '@verbaly/svelte', '@verbaly/vite'],\n wire: 'add verbaly() to the plugins in vite.config (per-request locale: @verbaly/sveltekit)',\n },\n {\n name: 'astro',\n dep: 'astro',\n pkg: '@verbaly/astro',\n install: ['verbaly', '@verbaly/astro'],\n wire: 'add verbaly() to the integrations in astro.config',\n },\n {\n name: 'vite',\n dep: 'vite',\n pkg: '@verbaly/vite',\n install: ['verbaly', '@verbaly/vite'],\n wire: 'add verbaly() to the plugins in vite.config',\n },\n {\n name: 'webpack',\n dep: 'webpack',\n pkg: '@verbaly/unplugin',\n install: ['verbaly', '@verbaly/unplugin'],\n wire: 'add the verbaly webpack plugin to your build config',\n },\n {\n name: 'rspack',\n dep: '@rspack/core',\n pkg: '@verbaly/unplugin',\n install: ['verbaly', '@verbaly/unplugin'],\n wire: 'add the verbaly rspack plugin to your build config',\n },\n {\n name: 'rollup',\n dep: 'rollup',\n pkg: '@verbaly/unplugin',\n install: ['verbaly', '@verbaly/unplugin'],\n wire: 'add the verbaly rollup plugin to your build config',\n },\n {\n name: 'esbuild',\n dep: 'esbuild',\n pkg: '@verbaly/unplugin',\n install: ['verbaly', '@verbaly/unplugin'],\n wire: 'add the verbaly esbuild plugin to your build config',\n },\n];\n\n// any of these wires the build; the detected host only decides which one we recommend\nexport const WIRING_PACKAGES = [...new Set(HOSTS.map((host) => host.pkg))];\n\nexport function readDependencies(root: string): Record<string, string> {\n const path = join(root, 'package.json');\n if (!existsSync(path)) return {};\n try {\n const pkg = JSON.parse(readFileSync(path, 'utf8')) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n return { ...pkg.dependencies, ...pkg.devDependencies };\n } catch {\n return {};\n }\n}\n\nexport function detectHost(root: string): HostSetup | undefined {\n const deps = readDependencies(root);\n return HOSTS.find((host) => deps[host.dep]);\n}\n\nexport type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';\n\nconst LOCKFILES: [string, PackageManager][] = [\n ['pnpm-lock.yaml', 'pnpm'],\n ['yarn.lock', 'yarn'],\n ['bun.lock', 'bun'],\n ['bun.lockb', 'bun'],\n ['package-lock.json', 'npm'],\n];\n\n// the project's own manager: packageManager first, then the nearest lockfile (a workspace root)\nexport function packageManager(root: string): PackageManager {\n try {\n const declared = (\n JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as {\n packageManager?: unknown;\n }\n ).packageManager;\n const name = typeof declared === 'string' ? declared.split('@')[0] : undefined;\n if (name === 'pnpm' || name === 'npm' || name === 'yarn' || name === 'bun') return name;\n } catch {\n // no package.json, or one that does not parse: the lockfiles still answer\n }\n for (let dir = root; ; dir = dirname(dir)) {\n const found = LOCKFILES.find(([file]) => existsSync(join(dir, file)));\n if (found) return found[1];\n if (dirname(dir) === dir) return 'npm';\n }\n}\n\nexport function installCommand(root: string, packages: string[], dev = false): string {\n const manager = packageManager(root);\n const verb = manager === 'npm' ? 'install' : 'add';\n const flag = dev ? (manager === 'bun' ? ' -d' : ' -D') : '';\n return `${manager} ${verb}${flag} ${packages.join(' ')}`;\n}\n\n// where each framework keeps generated types; .verbaly/ is ours, and tsconfig needs its line\nconst TYPE_SLOTS: Partial<Record<Host, string[]>> = {\n next: ['.verbaly', 'types.d.ts'],\n astro: ['.astro', 'integrations', '_verbaly_astro', 'verbaly.d.ts'],\n nuxt: ['.nuxt', 'verbaly.d.ts'],\n};\n\n// the framework's slot, else src/ (the folder every app template's tsconfig includes), else root\nexport function defaultTypesPath(root: string, host = detectHost(root)?.name): string {\n const slot = host && TYPE_SLOTS[host];\n if (slot) return join(root, ...slot);\n return existsSync(join(root, 'src'))\n ? join(root, 'src', 'verbaly.d.ts')\n : join(root, 'verbaly.d.ts');\n}\n","import { emptyCatalog, type 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 = emptyCatalog();\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","const warned = new Set<string>();\n\n// one warn-once for the whole compiler: dedupe by static content, never by a value being edited\nexport function warnOnce(message: string, dedupeKey = message): void {\n if (warned.has(dedupeKey)) return;\n warned.add(dedupeKey);\n console.warn(`[verbaly] ${message}`);\n}\n\n// bundler paths only: the CLI reports its own run, so a file is never announced twice\nexport function warnParseError(file: string, message: string): void {\n warnOnce(`${file}: could not be parsed (${message}), its messages were not extracted`);\n}\n","import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { RichLink, Routing } from 'verbaly';\nimport { defaultTypesPath } from './host';\nimport { PSEUDO_LOCALE } from './pseudo';\nimport { warnOnce } from './warn';\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\n// the extensions extract reads, shared by the default include and every pattern we suggest\nexport const SOURCE_EXTENSIONS = '{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}';\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 exclude?: string[];\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 inlineCatalog?: 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;\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}/**/*.${SOURCE_EXTENSIONS}`],\n exclude: config.exclude ?? ['**/node_modules/**', '**/dist/**'],\n // decided once here, so every writer and doctor look in the same place\n dts:\n typeof config.dts === 'string'\n ? resolve(root, config.dts)\n : config.dts === false\n ? false\n : defaultTypesPath(root),\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 // Node caches a module by url: without the mtime, a long-lived process keeps the old config\n const url = `${pathToFileURL(path).href}?mtime=${statSync(path).mtimeMs}`;\n // a CommonJS config is cached by its full file name instead, which no query reaches\n delete createRequire(import.meta.url).cache[resolve(path)];\n const mod = (await import(url)) 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)) return readJsonConfig(jsonPath);\n return {};\n}\n\n// same BOM rule as a catalog, and a parse error that names the file it came from\nfunction readJsonConfig(path: string): VerbalyConfig {\n const content = readFileSync(path, 'utf8');\n const body = content.charCodeAt(0) === 0xfeff ? content.slice(1) : content;\n try {\n return JSON.parse(body) as VerbalyConfig;\n } catch (error) {\n throw new Error(`[verbaly] ${path} is not valid JSON: ${(error as Error).message}`, {\n cause: error,\n });\n }\n}\n\n// jiti reads TypeScript and extensionless imports like a bundler, and installs no build script\nasync function loadTsConfig(path: string): Promise<VerbalyConfig> {\n const { createJiti } = await import('jiti');\n // no caches: nothing is written to disk, and a dev server reads an edited config and its imports\n const jiti = createJiti(import.meta.url, {\n fsCache: false,\n moduleCache: false,\n interopDefault: false,\n });\n const mod = await jiti.import<VerbalyConfig & { default?: VerbalyConfig; __esModule?: true }>(\n path,\n );\n // an ES module without a default export holds no config; module.exports is the config itself\n return mod.__esModule ? (mod.default ?? {}) : mod;\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 from: { plugin?: boolean } = {},\n): Promise<ResolvedConfig> {\n const fileConfig = await loadConfigFile(root);\n if (from.plugin) warnPluginOnly(root, fileConfig, overrides);\n return resolveConfig({ ...fileConfig, ...definedOnly(overrides), root });\n}\n\n// what verbaly check and extract read: set only in a plugin, the build and the CLI disagree\nconst READ_BY_CLI = ['sourceLocale', 'locales', 'dir', 'include', 'exclude'] as const;\n\nfunction warnPluginOnly(root: string, file: VerbalyConfig, overrides: VerbalyConfig): void {\n // resolved on both sides: a default or a path written another way is what the CLI reads too\n const cli = resolveConfig({ ...file, root });\n const build = resolveConfig({ ...file, ...definedOnly(overrides), root });\n const keys = READ_BY_CLI.filter(\n (key) =>\n overrides[key] !== undefined && JSON.stringify(cli[key]) !== JSON.stringify(build[key]),\n );\n if (keys.length === 0) return;\n const names = keys.length > 1 ? `${keys.slice(0, -1).join(', ')} and ${keys.at(-1)}` : keys[0];\n const [verb, pronoun] = keys.length > 1 ? ['are', 'them'] : ['is', 'it'];\n warnOnce(\n `${names} ${verb} set in the plugin options, which \\`verbaly check\\` and \\`verbaly extract\\` ` +\n `never read: move ${pronoun} to verbaly.config so the command line checks what the build ships`,\n `plugin-only:${root}`,\n );\n}\n\nfunction definedOnly(config: VerbalyConfig): VerbalyConfig {\n return Object.fromEntries(\n Object.entries(config).filter(([, value]) => value !== undefined),\n ) as VerbalyConfig;\n}\n","// counts read like text, so the tool that translates apps never prints \"1 messages\"\nexport function counted(count: number, noun: string, many = `${noun}s`): string {\n return `${count} ${count === 1 ? noun : many}`;\n}\n\nexport function truncate(text: string, max: number): string {\n return text.length > max ? text.slice(0, max - 1) + '…' : text;\n}\n\n// code unit order: localeCompare follows the machine's language, and two machines would disagree\nexport function byCodeUnit(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n"],"mappings":";;;;;AAeA,MAAM,QAAyC;CAC7C;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS;GAAC;GAAW;GAAiB;EAAc;EACpD,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS;GAAC;GAAW;GAAiB;EAAgB;EACtD,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS;GAAC;GAAW;GAAsB;GAAmB;EAAe;EAC7E,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,gBAAgB;EACrC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,eAAe;EACpC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,mBAAmB;EACxC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,mBAAmB;EACxC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,mBAAmB;EACxC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,mBAAmB;EACxC,MAAM;CACR;AACF;AAGA,MAAa,kBAAkB,CAAC,GAAG,IAAI,IAAI,MAAM,KAAK,SAAS,KAAK,GAAG,CAAC,CAAC;AAEzE,SAAgB,iBAAiB,MAAsC;CACrE,MAAM,OAAO,KAAK,MAAM,cAAc;CACtC,IAAI,CAAC,WAAW,IAAI,GAAG,OAAO,CAAC;CAC/B,IAAI;EACF,MAAM,MAAM,KAAK,MAAM,aAAa,MAAM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O,KAAK,GAAG,EAAE,MAAM,KAAK;CAC5F,MAAM,CAAC,MAAM,WAAW,KAAK,SAAS,IAAI,CAAC,OAAO,MAAM,IAAI,CAAC,MAAM,IAAI;CACvE,SACE,GAAG,MAAM,GAAG,KAAK,+FACK,QAAQ,qEAC9B,eAAe,MACjB;AACF;AAEA,SAAS,YAAY,QAAsC;CACzD,OAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CAClE;AACF;;;AC5OA,SAAgB,QAAQ,OAAe,MAAc,OAAO,GAAG,KAAK,IAAY;CAC9E,OAAO,GAAG,MAAM,GAAG,UAAU,IAAI,OAAO;AAC1C;AAEA,SAAgB,SAAS,MAAc,KAAqB;CAC1D,OAAO,KAAK,SAAS,MAAM,KAAK,MAAM,GAAG,MAAM,CAAC,IAAI,MAAM;AAC5D;AAGA,SAAgB,WAAW,GAAW,GAAmB;CACvD,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbaly/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.75.0",
|
|
4
4
|
"description": "Message extraction and type-safe codegen for Verbaly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"magic-string": "^1.4.3",
|
|
49
49
|
"picomatch": "^4.0.7",
|
|
50
50
|
"tinyglobby": "^0.2.17",
|
|
51
|
-
"verbaly": "0.
|
|
51
|
+
"verbaly": "0.75.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@anthropic-ai/sdk": ">=0.110.0"
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"@anthropic-ai/sdk": "^0.135.0",
|
|
63
63
|
"@types/picomatch": "^4.0.3",
|
|
64
64
|
"esbuild": "^0.28.2",
|
|
65
|
+
"fast-check": "^4.10.2",
|
|
65
66
|
"happy-dom": "^21.0.3"
|
|
66
67
|
},
|
|
67
68
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text-BMBWE8tL.js","names":[],"sources":["../src/host.ts","../src/pseudo.ts","../src/config.ts","../src/text.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\n\nexport type Host =\n 'nuxt' | 'next' | 'sveltekit' | 'astro' | 'vite' | 'webpack' | 'rspack' | 'rollup' | 'esbuild';\n\nexport interface HostSetup {\n name: Host;\n // the package that wires the build, which is how doctor tells the setup is done\n pkg: string;\n // what that package's README installs, so init and doctor never contradict it\n install: string[];\n wire: string;\n}\n\nconst HOSTS: (HostSetup & { dep: string })[] = [\n {\n name: 'nuxt',\n dep: 'nuxt',\n pkg: '@verbaly/nuxt',\n install: ['verbaly', '@verbaly/nuxt', '@verbaly/vue'],\n wire: \"add '@verbaly/nuxt' to the modules in nuxt.config\",\n },\n {\n name: 'next',\n dep: 'next',\n pkg: '@verbaly/next',\n install: ['verbaly', '@verbaly/next', '@verbaly/react'],\n wire: 'wrap the export of next.config with withVerbaly',\n },\n {\n name: 'sveltekit',\n dep: '@sveltejs/kit',\n pkg: '@verbaly/vite',\n install: ['verbaly', '@verbaly/sveltekit', '@verbaly/svelte', '@verbaly/vite'],\n wire: 'add verbaly() to the plugins in vite.config (per-request locale: @verbaly/sveltekit)',\n },\n {\n name: 'astro',\n dep: 'astro',\n pkg: '@verbaly/astro',\n install: ['verbaly', '@verbaly/astro'],\n wire: 'add verbaly() to the integrations in astro.config',\n },\n {\n name: 'vite',\n dep: 'vite',\n pkg: '@verbaly/vite',\n install: ['verbaly', '@verbaly/vite'],\n wire: 'add verbaly() to the plugins in vite.config',\n },\n {\n name: 'webpack',\n dep: 'webpack',\n pkg: '@verbaly/unplugin',\n install: ['verbaly', '@verbaly/unplugin'],\n wire: 'add the verbaly webpack plugin to your build config',\n },\n {\n name: 'rspack',\n dep: '@rspack/core',\n pkg: '@verbaly/unplugin',\n install: ['verbaly', '@verbaly/unplugin'],\n wire: 'add the verbaly rspack plugin to your build config',\n },\n {\n name: 'rollup',\n dep: 'rollup',\n pkg: '@verbaly/unplugin',\n install: ['verbaly', '@verbaly/unplugin'],\n wire: 'add the verbaly rollup plugin to your build config',\n },\n {\n name: 'esbuild',\n dep: 'esbuild',\n pkg: '@verbaly/unplugin',\n install: ['verbaly', '@verbaly/unplugin'],\n wire: 'add the verbaly esbuild plugin to your build config',\n },\n];\n\n// any of these wires the build; the detected host only decides which one we recommend\nexport const WIRING_PACKAGES = [...new Set(HOSTS.map((host) => host.pkg))];\n\nexport function readDependencies(root: string): Record<string, string> {\n const path = join(root, 'package.json');\n if (!existsSync(path)) return {};\n try {\n const pkg = JSON.parse(readFileSync(path, 'utf8')) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n return { ...pkg.dependencies, ...pkg.devDependencies };\n } catch {\n return {};\n }\n}\n\nexport function detectHost(root: string): HostSetup | undefined {\n const deps = readDependencies(root);\n return HOSTS.find((host) => deps[host.dep]);\n}\n\nexport type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';\n\nconst LOCKFILES: [string, PackageManager][] = [\n ['pnpm-lock.yaml', 'pnpm'],\n ['yarn.lock', 'yarn'],\n ['bun.lock', 'bun'],\n ['bun.lockb', 'bun'],\n ['package-lock.json', 'npm'],\n];\n\n// the project's own manager: packageManager first, then the nearest lockfile (a workspace root)\nexport function packageManager(root: string): PackageManager {\n try {\n const declared = (\n JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as {\n packageManager?: unknown;\n }\n ).packageManager;\n const name = typeof declared === 'string' ? declared.split('@')[0] : undefined;\n if (name === 'pnpm' || name === 'npm' || name === 'yarn' || name === 'bun') return name;\n } catch {\n // no package.json, or one that does not parse: the lockfiles still answer\n }\n for (let dir = root; ; dir = dirname(dir)) {\n const found = LOCKFILES.find(([file]) => existsSync(join(dir, file)));\n if (found) return found[1];\n if (dirname(dir) === dir) return 'npm';\n }\n}\n\nexport function installCommand(root: string, packages: string[], dev = false): string {\n const manager = packageManager(root);\n const verb = manager === 'npm' ? 'install' : 'add';\n const flag = dev ? (manager === 'bun' ? ' -d' : ' -D') : '';\n return `${manager} ${verb}${flag} ${packages.join(' ')}`;\n}\n\n// where each framework keeps generated types; .verbaly/ is ours, and tsconfig needs its line\nconst TYPE_SLOTS: Partial<Record<Host, string[]>> = {\n next: ['.verbaly', 'types.d.ts'],\n astro: ['.astro', 'integrations', '_verbaly_astro', 'verbaly.d.ts'],\n nuxt: ['.nuxt', 'verbaly.d.ts'],\n};\n\n// the framework's slot, else src/ (the folder every app template's tsconfig includes), else root\nexport function defaultTypesPath(root: string, host = detectHost(root)?.name): string {\n const slot = host && TYPE_SLOTS[host];\n if (slot) return join(root, ...slot);\n return existsSync(join(root, 'src'))\n ? join(root, 'src', 'verbaly.d.ts')\n : join(root, 'verbaly.d.ts');\n}\n","import { emptyCatalog, type 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 = emptyCatalog();\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, statSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { RichLink, Routing } from 'verbaly';\nimport { defaultTypesPath } from './host';\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\n// the extensions extract reads, shared by the default include and every pattern we suggest\nexport const SOURCE_EXTENSIONS = '{js,jsx,ts,tsx,mjs,mts,svelte,vue,astro}';\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 exclude?: string[];\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 inlineCatalog?: 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;\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}/**/*.${SOURCE_EXTENSIONS}`],\n exclude: config.exclude ?? ['**/node_modules/**', '**/dist/**'],\n // decided once here, so every writer and doctor look in the same place\n dts:\n typeof config.dts === 'string'\n ? resolve(root, config.dts)\n : config.dts === false\n ? false\n : defaultTypesPath(root),\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 // Node caches a module by url: without the mtime, a long-lived process keeps the old config\n const url = `${pathToFileURL(path).href}?mtime=${statSync(path).mtimeMs}`;\n // a CommonJS config is cached by its full file name instead, which no query reaches\n delete createRequire(import.meta.url).cache[resolve(path)];\n const mod = (await import(url)) 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)) return readJsonConfig(jsonPath);\n return {};\n}\n\n// same BOM rule as a catalog, and a parse error that names the file it came from\nfunction readJsonConfig(path: string): VerbalyConfig {\n const content = readFileSync(path, 'utf8');\n const body = content.charCodeAt(0) === 0xfeff ? content.slice(1) : content;\n try {\n return JSON.parse(body) as VerbalyConfig;\n } catch (error) {\n throw new Error(`[verbaly] ${path} is not valid JSON: ${(error as Error).message}`, {\n cause: error,\n });\n }\n}\n\n// jiti reads TypeScript and extensionless imports like a bundler, and installs no build script\nasync function loadTsConfig(path: string): Promise<VerbalyConfig> {\n const { createJiti } = await import('jiti');\n // no caches: nothing is written to disk, and a dev server reads an edited config and its imports\n const jiti = createJiti(import.meta.url, {\n fsCache: false,\n moduleCache: false,\n interopDefault: false,\n });\n const mod = await jiti.import<VerbalyConfig & { default?: VerbalyConfig; __esModule?: true }>(\n path,\n );\n // an ES module without a default export holds no config; module.exports is the config itself\n return mod.__esModule ? (mod.default ?? {}) : mod;\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","// counts read like text, so the tool that translates apps never prints \"1 messages\"\nexport function counted(count: number, noun: string, many = `${noun}s`): string {\n return `${count} ${count === 1 ? noun : many}`;\n}\n\nexport function truncate(text: string, max: number): string {\n return text.length > max ? text.slice(0, max - 1) + '…' : text;\n}\n\n// code unit order: localeCompare follows the machine's language, and two machines would disagree\nexport function byCodeUnit(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n"],"mappings":";;;;;AAeA,MAAM,QAAyC;CAC7C;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS;GAAC;GAAW;GAAiB;EAAc;EACpD,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS;GAAC;GAAW;GAAiB;EAAgB;EACtD,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS;GAAC;GAAW;GAAsB;GAAmB;EAAe;EAC7E,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,gBAAgB;EACrC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,eAAe;EACpC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,mBAAmB;EACxC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,mBAAmB;EACxC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,mBAAmB;EACxC,MAAM;CACR;CACA;EACE,MAAM;EACN,KAAK;EACL,KAAK;EACL,SAAS,CAAC,WAAW,mBAAmB;EACxC,MAAM;CACR;AACF;AAGA,MAAa,kBAAkB,CAAC,GAAG,IAAI,IAAI,MAAM,KAAK,SAAS,KAAK,GAAG,CAAC,CAAC;AAEzE,SAAgB,iBAAiB,MAAsC;CACrE,MAAM,OAAO,KAAK,MAAM,cA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