@i18n-micro/vitepress 1.0.1 → 1.1.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.
Files changed (49) hide show
  1. package/README.md +73 -39
  2. package/client.d.ts +1 -0
  3. package/dist/adapter-BJ-0ltIc.cjs +2 -0
  4. package/dist/adapter-BJ-0ltIc.cjs.map +1 -0
  5. package/dist/adapter-BnsyIKhp.js +128 -0
  6. package/dist/adapter-BnsyIKhp.js.map +1 -0
  7. package/dist/config.cjs +64 -1
  8. package/dist/config.cjs.map +1 -1
  9. package/dist/config.d.cts +113 -111
  10. package/dist/config.d.ts +113 -111
  11. package/dist/config.mjs +393 -9
  12. package/dist/config.mjs.map +1 -1
  13. package/dist/create-BgMbe0w1.cjs +2 -0
  14. package/dist/create-BgMbe0w1.cjs.map +1 -0
  15. package/dist/create-Dev8Q66O.js +80 -0
  16. package/dist/create-Dev8Q66O.js.map +1 -0
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +87 -141
  20. package/dist/index.d.ts +87 -141
  21. package/dist/index.mjs +28 -249
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/node.cjs +1 -1
  24. package/dist/node.cjs.map +1 -1
  25. package/dist/node.d.cts +56 -116
  26. package/dist/node.d.ts +56 -116
  27. package/dist/node.mjs +23 -7
  28. package/dist/node.mjs.map +1 -1
  29. package/dist/{virtual-stubs → plugin/virtual-stubs}/config.d.cts +2 -1
  30. package/dist/runtime/define-theme.d.cts +39 -0
  31. package/dist/theme.cjs +2 -0
  32. package/dist/theme.cjs.map +1 -0
  33. package/dist/theme.d.cts +58 -0
  34. package/dist/theme.d.ts +58 -0
  35. package/dist/theme.mjs +35 -0
  36. package/dist/theme.mjs.map +1 -0
  37. package/dist/vitepress-locales-6msv22Sn.js +27 -0
  38. package/dist/vitepress-locales-6msv22Sn.js.map +1 -0
  39. package/dist/vitepress-locales-Cz4AutfI.cjs +2 -0
  40. package/dist/vitepress-locales-Cz4AutfI.cjs.map +1 -0
  41. package/package.json +18 -6
  42. package/dist/i18n-routing-CcppCuuS.js +0 -64
  43. package/dist/i18n-routing-CcppCuuS.js.map +0 -1
  44. package/dist/i18n-routing-D9iYAKDq.cjs +0 -46
  45. package/dist/i18n-routing-D9iYAKDq.cjs.map +0 -1
  46. package/dist/with-i18n-micro-01q-vPO9.cjs +0 -15
  47. package/dist/with-i18n-micro-01q-vPO9.cjs.map +0 -1
  48. package/dist/with-i18n-micro-DIAoqY71.js +0 -216
  49. package/dist/with-i18n-micro-DIAoqY71.js.map +0 -1
@@ -1,216 +0,0 @@
1
- import { existsSync as p, readdirSync as v, statSync as w, readFileSync as T } from "node:fs";
2
- import { resolve as M, join as P, relative as b, sep as L } from "node:path";
3
- import { mergeRouteTranslationsWithRoot as I, classifyTranslationRelativePath as j } from "@i18n-micro/utils/parse-path";
4
- import { deepMergeTranslations as x } from "@i18n-micro/utils/deep-merge";
5
- function k(e) {
6
- return e !== null && typeof e == "object" && !Array.isArray(e);
7
- }
8
- function S(e, s) {
9
- if (p(e))
10
- for (const r of v(e)) {
11
- const t = P(e, r);
12
- if (w(t).isDirectory()) {
13
- S(t, s);
14
- continue;
15
- }
16
- r.endsWith(".json") && s(t);
17
- }
18
- }
19
- function R(e) {
20
- const s = e.rootDir ?? process.cwd(), r = M(s, e.translationDir), t = [];
21
- return S(r, (i) => {
22
- t.push({
23
- absolutePath: i,
24
- relativePath: b(r, i).split(L).join("/")
25
- });
26
- }), t.sort((i, c) => i.relativePath.localeCompare(c.relativePath));
27
- }
28
- function D(e) {
29
- const s = e.rootDir ?? process.cwd(), r = M(s, e.translationDir), t = { root: {}, routes: {} }, i = e.disablePageLocales === !0;
30
- return p(r) && S(r, (c) => {
31
- const a = b(r, c).split(L).join("/");
32
- try {
33
- const l = JSON.parse(T(c, "utf-8"));
34
- if (!k(l)) {
35
- console.error(
36
- `[i18n-micro/vitepress] Skipping ${a}: expected a JSON object, got ${Array.isArray(l) ? "array" : typeof l}`
37
- );
38
- return;
39
- }
40
- const f = l, u = j(a, i);
41
- if (u.type === "page") {
42
- const n = t.routes[u.pageName] ?? (t.routes[u.pageName] = {});
43
- n[u.locale] = f;
44
- return;
45
- }
46
- if (u.type === "root") {
47
- const n = t.root[u.locale];
48
- t.root[u.locale] = n ? x(n, f) : f;
49
- }
50
- } catch (l) {
51
- console.error(`[i18n-micro/vitepress] Failed to load ${a}:`, l);
52
- }
53
- }), t;
54
- }
55
- function B(e) {
56
- return D(e).root;
57
- }
58
- function K(e, s) {
59
- for (const [r, t] of Object.entries(s.root))
60
- e.addTranslations(r, t, !1);
61
- for (const [r, t] of Object.entries(s.routes))
62
- for (const [i, c] of Object.entries(t))
63
- e.addRouteTranslations(
64
- i,
65
- r,
66
- I(s.root[i], c),
67
- !1
68
- );
69
- }
70
- const N = "virtual:i18n-micro/config", $ = `\0${N}`, O = "virtual:i18n-micro/messages", h = `\0${O}`;
71
- function W(e) {
72
- return e.replace(/\\/g, "/");
73
- }
74
- function E(e, s, r) {
75
- const t = R({ rootDir: e, translationDir: s });
76
- if (t.length === 0)
77
- return `export const messages = {}
78
- export const routeMessages = {}
79
- `;
80
- const i = [], c = [], a = /* @__PURE__ */ new Map();
81
- let l = 0;
82
- for (const u of t) {
83
- const n = j(u.relativePath, r);
84
- if (n.type === "ignore") continue;
85
- const d = `__i18n_${l++}`;
86
- if (i.push(`import ${d} from ${JSON.stringify(W(u.absolutePath))}`), n.type === "root") {
87
- c.push(` ${JSON.stringify(n.locale)}: ${d}`);
88
- continue;
89
- }
90
- let o = a.get(n.pageName);
91
- o || (o = /* @__PURE__ */ new Map(), a.set(n.pageName, o)), o.set(n.locale, d);
92
- }
93
- const f = [];
94
- for (const [u, n] of a) {
95
- const d = [...n.entries()].map(([o, m]) => ` ${JSON.stringify(o)}: ${m}`).join(`,
96
- `);
97
- f.push(` ${JSON.stringify(u)}: {
98
- ${d}
99
- }`);
100
- }
101
- return [
102
- ...i,
103
- `export const messages = {
104
- ${c.join(`,
105
- `)}
106
- }`,
107
- `export const routeMessages = {
108
- ${f.join(`,
109
- `)}
110
- }`,
111
- ""
112
- ].join(`
113
- `);
114
- }
115
- function _(e, s) {
116
- return [
117
- `export const messages = ${JSON.stringify(e)}`,
118
- `export const routeMessages = ${JSON.stringify(s)}`,
119
- ""
120
- ].join(`
121
- `);
122
- }
123
- function A(e) {
124
- const s = e.defaultLocale || e.locale, r = e.translationDir ?? "locales", t = e.disablePageLocales === !0, i = {
125
- defaultLocale: s,
126
- fallbackLocale: e.fallbackLocale || s,
127
- locales: e.locales || [],
128
- localeCodes: (e.locales || []).map((o) => o.code),
129
- missingWarn: e.missingWarn ?? !0,
130
- syncWithVitePress: e.syncWithVitePress !== !1,
131
- translationDir: r,
132
- disablePageLocales: t,
133
- localeKeyToCode: e.localeKeyToCode ?? {}
134
- };
135
- let c = process.cwd(), a = !!(e.messages || e.routeMessages), l = e.messages ?? {}, f = e.routeMessages ?? {}, u;
136
- const n = () => !e.messages || !e.routeMessages, d = () => {
137
- if (!n()) return;
138
- const o = D({
139
- rootDir: c,
140
- translationDir: r,
141
- disablePageLocales: t
142
- });
143
- e.messages || (l = o.root), e.routeMessages || (f = o.routes);
144
- };
145
- return {
146
- name: "vite-plugin-i18n-micro-vitepress",
147
- configResolved(o) {
148
- c = o.root, a = !!(e.messages || e.routeMessages), a && (e.messages && (l = e.messages), e.routeMessages && (f = e.routeMessages), n() && d(), e.messages && (l = e.messages), e.routeMessages && (f = e.routeMessages));
149
- },
150
- configureServer(o) {
151
- if (a && !n()) return;
152
- const m = M(c, r);
153
- if (!p(m)) return;
154
- o.watcher.add(m);
155
- const y = () => {
156
- u && clearTimeout(u), u = setTimeout(() => {
157
- a && d();
158
- const g = o.moduleGraph.getModuleById(h);
159
- g && (o.moduleGraph.invalidateModule(g), o.ws.send({ type: "full-reload" }));
160
- }, 50);
161
- };
162
- o.watcher.on("add", (g) => {
163
- g.startsWith(m) && g.endsWith(".json") && y();
164
- }), o.watcher.on("unlink", (g) => {
165
- g.startsWith(m) && g.endsWith(".json") && y();
166
- }), a && n() && o.watcher.on("change", (g) => {
167
- g.startsWith(m) && g.endsWith(".json") && y();
168
- });
169
- },
170
- resolveId(o) {
171
- if (o === N) return $;
172
- if (o === O) return h;
173
- },
174
- load(o) {
175
- if (o === $)
176
- return `export const config = ${JSON.stringify(i)}`;
177
- if (o === h)
178
- return a ? _(l, f) : E(c, r, t);
179
- }
180
- };
181
- }
182
- function J(e, s) {
183
- if (s.warnOnLocaleMismatch === !1) return;
184
- const r = e.locales;
185
- if (!r || !s.locales?.length) return;
186
- const t = s.defaultLocale || s.locale, i = Object.keys(r), c = new Set(s.locales.map((a) => a.code));
187
- for (const a of i) {
188
- const l = a === "root" ? t : s.localeKeyToCode?.[a] ?? a;
189
- c.has(l) || console.warn(
190
- `[i18n-micro/vitepress] VitePress locale key "${a}" maps to "${l}", which is not in i18n locales (${[...c].join(", ")}).`
191
- );
192
- }
193
- }
194
- function U(e, s) {
195
- J(e, s);
196
- const r = e.vite?.plugins, t = [
197
- ...Array.isArray(r) ? r.flat() : [],
198
- A(s)
199
- ];
200
- return {
201
- ...e,
202
- vite: {
203
- ...e.vite,
204
- plugins: t
205
- }
206
- };
207
- }
208
- export {
209
- K as a,
210
- B as b,
211
- D as c,
212
- U as d,
213
- R as l,
214
- J as w
215
- };
216
- //# sourceMappingURL=with-i18n-micro-DIAoqY71.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"with-i18n-micro-DIAoqY71.js","sources":["../src/load-messages.ts","../src/with-i18n-micro.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'\nimport { join, relative, resolve, sep } from 'node:path'\nimport type { Translations } from '@i18n-micro/types'\nimport { deepMergeTranslations } from '@i18n-micro/utils/deep-merge'\nimport {\n classifyTranslationRelativePath,\n mergeRouteTranslationsWithRoot,\n type TranslationFileBuckets,\n} from '@i18n-micro/utils/parse-path'\n\nexport interface LoadMessagesOptions {\n /** Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …). */\n translationDir: string\n rootDir?: string\n /**\n * When true, treat `pages/**` files as root-level dictionaries.\n * @default false\n */\n disablePageLocales?: boolean\n}\n\nexport type LoadedTranslations = TranslationFileBuckets<Translations>\n\nexport interface TranslationFileRef {\n /** Path relative to `translationDir` using `/` separators. */\n relativePath: string\n absolutePath: string\n}\n\nfunction isTranslationsObject(value: unknown): value is Translations {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction walkTranslationFiles(dir: string, onFile: (fullPath: string) => void): void {\n if (!existsSync(dir)) return\n\n for (const entry of readdirSync(dir)) {\n const fullPath = join(dir, entry)\n const stat = statSync(fullPath)\n if (stat.isDirectory()) {\n walkTranslationFiles(fullPath, onFile)\n continue\n }\n if (entry.endsWith('.json')) {\n onFile(fullPath)\n }\n }\n}\n\n/**\n * List JSON translation files under `translationDir` (absolute + relative paths).\n */\nexport function listTranslationFiles(options: LoadMessagesOptions): TranslationFileRef[] {\n const rootDir = options.rootDir ?? process.cwd()\n const dir = resolve(rootDir, options.translationDir)\n const files: TranslationFileRef[] = []\n\n walkTranslationFiles(dir, (fullPath) => {\n files.push({\n absolutePath: fullPath,\n relativePath: relative(dir, fullPath).split(sep).join('/'),\n })\n })\n\n return files.sort((a, b) => a.relativePath.localeCompare(b.relativePath))\n}\n\n/**\n * Load root + page-scoped dictionaries (`pages/** /xx.json`).\n * Node.js-only (`node:fs`).\n */\nexport function loadTranslationBuckets(options: LoadMessagesOptions): LoadedTranslations {\n const rootDir = options.rootDir ?? process.cwd()\n const dir = resolve(rootDir, options.translationDir)\n const buckets: LoadedTranslations = { root: {}, routes: {} }\n const disablePageLocales = options.disablePageLocales === true\n\n if (!existsSync(dir)) {\n return buckets\n }\n\n walkTranslationFiles(dir, (fullPath) => {\n const relativePath = relative(dir, fullPath).split(sep).join('/')\n try {\n const parsed: unknown = JSON.parse(readFileSync(fullPath, 'utf-8'))\n if (!isTranslationsObject(parsed)) {\n console.error(\n `[i18n-micro/vitepress] Skipping ${relativePath}: expected a JSON object, got ${Array.isArray(parsed) ? 'array' : typeof parsed}`,\n )\n return\n }\n const translations = parsed\n const classified = classifyTranslationRelativePath(relativePath, disablePageLocales)\n\n if (classified.type === 'page') {\n const routeBucket = buckets.routes[classified.pageName]\n ?? (buckets.routes[classified.pageName] = {})\n routeBucket[classified.locale] = translations\n return\n }\n\n if (classified.type === 'root') {\n const existing = buckets.root[classified.locale]\n buckets.root[classified.locale] = existing\n ? deepMergeTranslations(existing as Record<string, unknown>, translations as Record<string, unknown>) as Translations\n : translations\n }\n }\n catch (error) {\n console.error(`[i18n-micro/vitepress] Failed to load ${relativePath}:`, error)\n }\n })\n\n return buckets\n}\n\n/**\n * Load root-level locale JSON only (`en.json`, `fr.json`, …).\n * Prefer `loadTranslationBuckets` when page locales are needed.\n *\n * Node.js-only (`node:fs`). For bundler-friendly loading prefer\n * `withI18nMicro` virtual modules or `messagesFromGlob` in the theme.\n */\nexport function loadMessages(options: LoadMessagesOptions): Record<string, Translations> {\n return loadTranslationBuckets(options).root\n}\n\n/**\n * Apply page dictionaries onto an i18n instance (merged with root).\n */\nexport function applyLoadedTranslations(\n i18n: {\n addTranslations: (locale: string, translations: Translations, merge?: boolean) => void\n addRouteTranslations: (locale: string, routeName: string, translations: Translations, merge?: boolean) => void\n },\n loaded: LoadedTranslations,\n): void {\n for (const [locale, translations] of Object.entries(loaded.root)) {\n i18n.addTranslations(locale, translations, false)\n }\n for (const [routeName, byLocale] of Object.entries(loaded.routes)) {\n for (const [locale, translations] of Object.entries(byLocale)) {\n i18n.addRouteTranslations(\n locale,\n routeName,\n mergeRouteTranslationsWithRoot(loaded.root[locale], translations),\n false,\n )\n }\n }\n}\n","import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport type { Locale, Translations } from '@i18n-micro/types'\nimport { classifyTranslationRelativePath } from '@i18n-micro/utils/parse-path'\nimport type { Plugin } from 'vite'\nimport type { VitePressI18nOptions } from './create'\nimport { listTranslationFiles, loadTranslationBuckets } from './load-messages'\n\nexport interface WithI18nMicroOptions extends VitePressI18nOptions {\n /**\n * Directory with locale JSON (`en.json`, `pages/guide/demo/en.json`, …), relative to Vite root\n * (VitePress content / docs root). Used by `virtual:i18n-micro/messages`.\n * @default 'locales'\n */\n translationDir?: string\n /**\n * When true, treat `pages/**` as root-level dictionaries.\n * @default false\n */\n disablePageLocales?: boolean\n /**\n * When true, logs a warning if VitePress `locales` keys do not align with\n * configured i18n locale codes.\n * @default true\n */\n warnOnLocaleMismatch?: boolean\n}\n\n/**\n * Minimal VitePress / Vite user config shape we merge into.\n * Avoid importing `vitepress` types so the package stays usable as a pure library dep.\n */\nexport interface VitePressUserConfigLike {\n locales?: Record<string, unknown>\n vite?: {\n plugins?: Plugin[] | Plugin[][]\n [key: string]: unknown\n }\n [key: string]: unknown\n}\n\nexport interface VirtualI18nConfig {\n defaultLocale: string\n fallbackLocale: string\n locales: Locale[]\n localeCodes: string[]\n missingWarn: boolean\n syncWithVitePress: boolean\n translationDir: string\n disablePageLocales: boolean\n localeKeyToCode: Record<string, string>\n}\n\nconst VIRTUAL_CONFIG_ID = 'virtual:i18n-micro/config'\nconst RESOLVED_CONFIG_ID = `\\0${VIRTUAL_CONFIG_ID}`\nconst VIRTUAL_MESSAGES_ID = 'virtual:i18n-micro/messages'\nconst RESOLVED_MESSAGES_ID = `\\0${VIRTUAL_MESSAGES_ID}`\n\nfunction toPosix(path: string): string {\n return path.replace(/\\\\/g, '/')\n}\n\nfunction generateImportMessagesModule(\n rootDir: string,\n translationDir: string,\n disablePageLocales: boolean,\n): string {\n const files = listTranslationFiles({ rootDir, translationDir })\n if (files.length === 0) {\n return 'export const messages = {}\\nexport const routeMessages = {}\\n'\n }\n\n const imports: string[] = []\n const rootEntries: string[] = []\n const routeVarNames = new Map<string, Map<string, string>>()\n let i = 0\n\n for (const file of files) {\n const parsed = classifyTranslationRelativePath(file.relativePath, disablePageLocales)\n if (parsed.type === 'ignore') continue\n\n const varName = `__i18n_${i++}`\n imports.push(`import ${varName} from ${JSON.stringify(toPosix(file.absolutePath))}`)\n\n if (parsed.type === 'root') {\n rootEntries.push(` ${JSON.stringify(parsed.locale)}: ${varName}`)\n continue\n }\n\n let byLocale = routeVarNames.get(parsed.pageName)\n if (!byLocale) {\n byLocale = new Map()\n routeVarNames.set(parsed.pageName, byLocale)\n }\n byLocale.set(parsed.locale, varName)\n }\n\n const routeEntries: string[] = []\n for (const [routeName, byLocale] of routeVarNames) {\n const localeEntries = [...byLocale.entries()]\n .map(([locale, varName]) => ` ${JSON.stringify(locale)}: ${varName}`)\n .join(',\\n')\n routeEntries.push(` ${JSON.stringify(routeName)}: {\\n${localeEntries}\\n }`)\n }\n\n return [\n ...imports,\n `export const messages = {\\n${rootEntries.join(',\\n')}\\n}`,\n `export const routeMessages = {\\n${routeEntries.join(',\\n')}\\n}`,\n '',\n ].join('\\n')\n}\n\nfunction generateInlineMessagesModule(\n messages: Record<string, Translations>,\n routeMessages: Record<string, Record<string, Translations>>,\n): string {\n return [\n `export const messages = ${JSON.stringify(messages)}`,\n `export const routeMessages = ${JSON.stringify(routeMessages)}`,\n '',\n ].join('\\n')\n}\n\nfunction createI18nMicroVitePlugin(options: WithI18nMicroOptions): Plugin {\n const defaultLocale = options.defaultLocale || options.locale\n const translationDir = options.translationDir ?? 'locales'\n const disablePageLocales = options.disablePageLocales === true\n const configData: VirtualI18nConfig = {\n defaultLocale,\n fallbackLocale: options.fallbackLocale || defaultLocale,\n locales: options.locales || [],\n localeCodes: (options.locales || []).map((l) => l.code),\n missingWarn: options.missingWarn ?? true,\n syncWithVitePress: options.syncWithVitePress !== false,\n translationDir,\n disablePageLocales,\n localeKeyToCode: options.localeKeyToCode ?? {},\n }\n\n let rootDir = process.cwd()\n let useInline = Boolean(options.messages || options.routeMessages)\n let inlineRoot = options.messages ?? {}\n let inlineRoutes = options.routeMessages ?? {}\n let debounceTimer: ReturnType<typeof setTimeout> | undefined\n const needsDiskReload = () => !options.messages || !options.routeMessages\n\n const reloadInlineFromDisk = () => {\n // Fully inline config: skip disk I/O (and avoid spurious JSON parse errors).\n if (!needsDiskReload()) return\n const loaded = loadTranslationBuckets({\n rootDir,\n translationDir,\n disablePageLocales,\n })\n if (!options.messages) {\n inlineRoot = loaded.root\n }\n if (!options.routeMessages) {\n inlineRoutes = loaded.routes\n }\n }\n\n return {\n name: 'vite-plugin-i18n-micro-vitepress',\n configResolved(config) {\n rootDir = config.root\n // Inline when caller passed messages and/or routeMessages.\n // routeMessages alone still loads root dictionaries from translationDir.\n useInline = Boolean(options.messages || options.routeMessages)\n if (useInline) {\n if (options.messages) inlineRoot = options.messages\n if (options.routeMessages) inlineRoutes = options.routeMessages\n if (needsDiskReload()) {\n reloadInlineFromDisk()\n }\n if (options.messages) inlineRoot = options.messages\n if (options.routeMessages) inlineRoutes = options.routeMessages\n }\n },\n configureServer(server) {\n // Both maps provided inline — nothing to watch on disk.\n if (useInline && !needsDiskReload()) return\n\n const dir = resolve(rootDir, translationDir)\n if (!existsSync(dir)) return\n\n server.watcher.add(dir)\n\n const invalidate = () => {\n if (debounceTimer) clearTimeout(debounceTimer)\n debounceTimer = setTimeout(() => {\n if (useInline) reloadInlineFromDisk()\n const mod = server.moduleGraph.getModuleById(RESOLVED_MESSAGES_ID)\n if (mod) {\n server.moduleGraph.invalidateModule(mod)\n server.ws.send({ type: 'full-reload' })\n }\n }, 50)\n }\n\n // add/unlink need virtual module regen; change is usually handled by JSON import HMR,\n // but we still invalidate when using inline payload that still reads disk.\n server.watcher.on('add', (file) => {\n if (file.startsWith(dir) && file.endsWith('.json')) invalidate()\n })\n server.watcher.on('unlink', (file) => {\n if (file.startsWith(dir) && file.endsWith('.json')) invalidate()\n })\n if (useInline && needsDiskReload()) {\n server.watcher.on('change', (file) => {\n if (file.startsWith(dir) && file.endsWith('.json')) invalidate()\n })\n }\n },\n resolveId(id) {\n if (id === VIRTUAL_CONFIG_ID) return RESOLVED_CONFIG_ID\n if (id === VIRTUAL_MESSAGES_ID) return RESOLVED_MESSAGES_ID\n },\n load(id) {\n if (id === RESOLVED_CONFIG_ID) {\n return `export const config = ${JSON.stringify(configData)}`\n }\n if (id === RESOLVED_MESSAGES_ID) {\n if (useInline) {\n return generateInlineMessagesModule(inlineRoot, inlineRoutes)\n }\n return generateImportMessagesModule(rootDir, translationDir, disablePageLocales)\n }\n },\n }\n}\n\nexport function warnLocaleMismatch(config: VitePressUserConfigLike, options: WithI18nMicroOptions): void {\n if (options.warnOnLocaleMismatch === false) return\n const vpLocales = config.locales\n if (!vpLocales || !options.locales?.length) return\n\n const defaultLocale = options.defaultLocale || options.locale\n const vpKeys = Object.keys(vpLocales)\n const codes = new Set(options.locales.map((l) => l.code))\n\n for (const key of vpKeys) {\n const expectedCode = key === 'root' ? defaultLocale : (options.localeKeyToCode?.[key] ?? key)\n if (!codes.has(expectedCode)) {\n console.warn(\n `[i18n-micro/vitepress] VitePress locale key \"${key}\" maps to \"${expectedCode}\", `\n + `which is not in i18n locales (${[...codes].join(', ')}).`,\n )\n }\n }\n}\n\n/**\n * Config helper (like `withMermaid`). Name is `withI18nMicro` on purpose —\n * `withI18n` is already used by the unrelated `vitepress-i18n` package.\n *\n * Registers virtual modules:\n * - `virtual:i18n-micro/config`\n * - `virtual:i18n-micro/messages` (from `translationDir`, default `locales/`)\n *\n * Pair with `defineI18nTheme(DefaultTheme)` — no manual `import.meta.glob` in the theme.\n *\n * Import from `@i18n-micro/vitepress/config` (Node / config files only).\n */\nexport function withI18nMicro<T extends VitePressUserConfigLike>(\n config: T,\n options: WithI18nMicroOptions,\n): T {\n warnLocaleMismatch(config, options)\n\n const existingPlugins = config.vite?.plugins\n const plugins = [\n ...(Array.isArray(existingPlugins) ? existingPlugins.flat() : []),\n createI18nMicroVitePlugin(options),\n ]\n\n return {\n ...config,\n vite: {\n ...config.vite,\n plugins,\n },\n }\n}\n"],"names":["isTranslationsObject","value","walkTranslationFiles","dir","onFile","existsSync","entry","readdirSync","fullPath","join","statSync","listTranslationFiles","options","rootDir","resolve","files","relative","sep","a","b","loadTranslationBuckets","buckets","disablePageLocales","relativePath","parsed","readFileSync","translations","classified","classifyTranslationRelativePath","routeBucket","existing","deepMergeTranslations","error","loadMessages","applyLoadedTranslations","i18n","loaded","locale","routeName","byLocale","mergeRouteTranslationsWithRoot","VIRTUAL_CONFIG_ID","RESOLVED_CONFIG_ID","VIRTUAL_MESSAGES_ID","RESOLVED_MESSAGES_ID","toPosix","path","generateImportMessagesModule","translationDir","imports","rootEntries","routeVarNames","i","file","varName","routeEntries","localeEntries","generateInlineMessagesModule","messages","routeMessages","createI18nMicroVitePlugin","defaultLocale","configData","l","useInline","inlineRoot","inlineRoutes","debounceTimer","needsDiskReload","reloadInlineFromDisk","config","server","invalidate","mod","id","warnLocaleMismatch","vpLocales","vpKeys","codes","key","expectedCode","withI18nMicro","existingPlugins","plugins"],"mappings":";;;;AA6BA,SAASA,EAAqBC,GAAuC;AACnE,SAAOA,MAAU,QAAQ,OAAOA,KAAU,YAAY,CAAC,MAAM,QAAQA,CAAK;AAC5E;AAEA,SAASC,EAAqBC,GAAaC,GAA0C;AACnF,MAAKC,EAAWF,CAAG;AAEnB,eAAWG,KAASC,EAAYJ,CAAG,GAAG;AACpC,YAAMK,IAAWC,EAAKN,GAAKG,CAAK;AAEhC,UADaI,EAASF,CAAQ,EACrB,eAAe;AACtB,QAAAN,EAAqBM,GAAUJ,CAAM;AACrC;AAAA,MACF;AACA,MAAIE,EAAM,SAAS,OAAO,KACxBF,EAAOI,CAAQ;AAAA,IAEnB;AACF;AAKO,SAASG,EAAqBC,GAAoD;AACvF,QAAMC,IAAUD,EAAQ,WAAW,QAAQ,IAAA,GACrCT,IAAMW,EAAQD,GAASD,EAAQ,cAAc,GAC7CG,IAA8B,CAAA;AAEpC,SAAAb,EAAqBC,GAAK,CAACK,MAAa;AACtC,IAAAO,EAAM,KAAK;AAAA,MACT,cAAcP;AAAA,MACd,cAAcQ,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