@i18n-micro/types-generator 1.1.5 → 1.1.7

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.
@@ -3,6 +3,12 @@ export interface GeneratorOptions {
3
3
  translationDir: string;
4
4
  outputFile?: string;
5
5
  }
6
+ /**
7
+ * Emit a TS property name from a translation key.
8
+ * JSON.stringify covers quotes/newlines/null bytes; U+2028/U+2029 need an extra escape
9
+ * so the .d.ts stays safe when embedded in older JS tooling.
10
+ */
11
+ export declare function formatKeyProperty(key: string): string;
6
12
  /**
7
13
  * Generates a string with TypeScript types for translation keys.
8
14
  * Does not write a file, only returns content.
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4C/E;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiB9E"}
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAOD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIrD;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgD/E;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiB9E"}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * True for plain objects suitable as translation maps (not arrays, Date, null, etc.).
3
+ */
4
+ export declare function isPlainTranslationObject(value: unknown): value is Record<string, unknown>;
1
5
  /**
2
6
  * Recursively traverses a JSON object and creates a flat list of dot-separated keys.
3
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/core/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,SAAK,GAAG,MAAM,EAAE,CAqB/E"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/core/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,SAAK,GAAG,MAAM,EAAE,CAwB/E"}
@@ -0,0 +1,14 @@
1
+ let e=require("node:fs"),t=require("node:path"),n=require("globby");function r(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Object.prototype}function i(e,t=``){if(!r(e))return[];let n=[];for(let a in e){if(!Object.hasOwn(e,a))continue;let o=e[a],s=t?`${t}.${a}`:a;r(o)?n.push(...i(o,s)):n.push(s)}return n}function a(e){return e.charCodeAt(0)===65279?e.slice(1):e}function o(e){return JSON.stringify(e).replace(/\u2028/g,`\\u2028`).replace(/\u2029/g,`\\u2029`)}async function s(s){let c=(0,t.resolve)(s.srcDir,s.translationDir),l=await(0,n.globby)(`**/*.json`,{cwd:c,absolute:!0,ignore:[`node_modules/**`,`dist/**`,`.nuxt/**`]}),u=new Set;for(let t of l)try{let n=JSON.parse(a((0,e.readFileSync)(t,`utf-8`)));if(!r(n)){console.warn(`[i18n-types] Skipping ${t}: root value must be a plain JSON object`);continue}let o=i(n);for(let e of o)u.add(e)}catch(e){console.warn(`[i18n-types] Failed to parse ${t}:`,e)}return`/* prettier-ignore */
2
+ // @ts-nocheck
3
+ // Generated by @i18n-micro/types-generator
4
+ // DO NOT EDIT THIS FILE MANUALLY
5
+
6
+ import '@i18n-micro/types';
7
+
8
+ declare module '@i18n-micro/types' {
9
+ export interface DefineLocaleMessage {
10
+ ${Array.from(u).sort().map(e=>` ${o(e)}: string;`).join(`
11
+ `)}
12
+ }
13
+ }
14
+ `}async function c(n){let r=await s(n),i=n.outputFile||(0,t.resolve)(n.srcDir,`i18n-micro.d.ts`),a=(0,t.dirname)(i);try{(0,e.mkdirSync)(a,{recursive:!0})}catch{}return(0,e.writeFileSync)(i,r,`utf-8`),i}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
@@ -0,0 +1,69 @@
1
+ import { mkdirSync as e, readFileSync as t, writeFileSync as n } from "node:fs";
2
+ import { dirname as r, resolve as i } from "node:path";
3
+ import { globby as a } from "globby";
4
+ //#region src/core/parser.ts
5
+ function o(e) {
6
+ return typeof e == "object" && !!e && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype;
7
+ }
8
+ function s(e, t = "") {
9
+ if (!o(e)) return [];
10
+ let n = [];
11
+ for (let r in e) {
12
+ if (!Object.hasOwn(e, r)) continue;
13
+ let i = e[r], a = t ? `${t}.${r}` : r;
14
+ o(i) ? n.push(...s(i, a)) : n.push(a);
15
+ }
16
+ return n;
17
+ }
18
+ //#endregion
19
+ //#region src/core/generator.ts
20
+ function c(e) {
21
+ return e.charCodeAt(0) === 65279 ? e.slice(1) : e;
22
+ }
23
+ function l(e) {
24
+ return JSON.stringify(e).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
25
+ }
26
+ async function u(e) {
27
+ let n = i(e.srcDir, e.translationDir), r = await a("**/*.json", {
28
+ cwd: n,
29
+ absolute: !0,
30
+ ignore: [
31
+ "node_modules/**",
32
+ "dist/**",
33
+ ".nuxt/**"
34
+ ]
35
+ }), u = /* @__PURE__ */ new Set();
36
+ for (let e of r) try {
37
+ let n = JSON.parse(c(t(e, "utf-8")));
38
+ if (!o(n)) {
39
+ console.warn(`[i18n-types] Skipping ${e}: root value must be a plain JSON object`);
40
+ continue;
41
+ }
42
+ let r = s(n);
43
+ for (let e of r) u.add(e);
44
+ } catch (t) {
45
+ console.warn(`[i18n-types] Failed to parse ${e}:`, t);
46
+ }
47
+ return `/* prettier-ignore */
48
+ // @ts-nocheck
49
+ // Generated by @i18n-micro/types-generator
50
+ // DO NOT EDIT THIS FILE MANUALLY
51
+
52
+ import '@i18n-micro/types';
53
+
54
+ declare module '@i18n-micro/types' {
55
+ export interface DefineLocaleMessage {
56
+ ${Array.from(u).sort().map((e) => ` ${l(e)}: string;`).join("\n")}
57
+ }
58
+ }
59
+ `;
60
+ }
61
+ async function d(t) {
62
+ let a = await u(t), o = t.outputFile || i(t.srcDir, "i18n-micro.d.ts"), s = r(o);
63
+ try {
64
+ e(s, { recursive: !0 });
65
+ } catch {}
66
+ return n(o, a, "utf-8"), o;
67
+ }
68
+ //#endregion
69
+ export { o as a, s as i, d as n, u as r, l as t };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./generator-CAQjf5De.cjs"),l=require("node:path"),c=require("chokidar"),u=require("unplugin");let i=null,e=null;function y(t,r){return function(...n){const a=()=>{e&&clearTimeout(e),e=null,t(...n)};e&&clearTimeout(e),e=setTimeout(a,r)}}const g=u.createUnplugin(t=>({name:"i18n-micro-types-generator",async buildStart(){try{await o.generateTypes(t)}catch(r){console.warn("[i18n-types] Failed to generate types:",r)}if(process.env.NODE_ENV==="development"||process.env.NODE_ENV!=="production"){const r=l.resolve(t.srcDir,t.translationDir),s=y(async()=>{try{await o.generateTypes(t)}catch(n){console.warn("[i18n-types] Failed to regenerate types:",n)}},300);i=c.watch(r,{ignoreInitial:!0,ignored:n=>/(?:^|[/\\])(?:node_modules|dist|\.nuxt)(?:[/\\]|$)/.test(n)}),i.on("all",async(n,a)=>{a.endsWith(".json")&&s()})}},buildEnd(){i&&(i.close(),i=null),e&&(clearTimeout(e),e=null)}}));exports.flattenKeys=o.flattenKeys;exports.generateTypes=o.generateTypes;exports.getTypesString=o.getTypesString;exports.I18nTypesPlugin=g;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./generator-BonabDld.cjs");let t=require("node:path"),n=require("chokidar"),r=require("unplugin");var i=null,a=null;function o(e,t){return function(...n){a&&clearTimeout(a),a=setTimeout(()=>{a&&clearTimeout(a),a=null,e(...n)},t)}}var s=(0,r.createUnplugin)(r=>({name:`i18n-micro-types-generator`,async buildStart(){try{await e.n(r)}catch(e){console.warn(`[i18n-types] Failed to generate types:`,e)}if(process.env.NODE_ENV===`development`||process.env.NODE_ENV!==`production`){let a=(0,t.resolve)(r.srcDir,r.translationDir),s=o(async()=>{try{await e.n(r)}catch(e){console.warn(`[i18n-types] Failed to regenerate types:`,e)}},300);i=(0,n.watch)(a,{ignoreInitial:!0,ignored:e=>/(?:^|[/\\])(?:node_modules|dist|\.nuxt)(?:[/\\]|$)/.test(e)}),i.on(`all`,async(e,t)=>{t.endsWith(`.json`)&&s()})}},buildEnd(){i&&=(i.close(),null),a&&=(clearTimeout(a),null)}}));exports.I18nTypesPlugin=s,exports.flattenKeys=e.i,exports.formatKeyProperty=e.t,exports.generateTypes=e.n,exports.getTypesString=e.r,exports.isPlainTranslationObject=e.a;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { GeneratorOptions } from './core/generator';
2
- export { generateTypes, getTypesString } from './core/generator';
3
- export { flattenKeys } from './core/parser';
2
+ export { formatKeyProperty, generateTypes, getTypesString } from './core/generator';
3
+ export { flattenKeys, isPlainTranslationObject } from './core/parser';
4
4
  export { I18nTypesPlugin } from './unplugin';
5
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { GeneratorOptions } from './core/generator';
2
- export { generateTypes, getTypesString } from './core/generator';
3
- export { flattenKeys } from './core/parser';
2
+ export { formatKeyProperty, generateTypes, getTypesString } from './core/generator';
3
+ export { flattenKeys, isPlainTranslationObject } from './core/parser';
4
4
  export { I18nTypesPlugin } from './unplugin';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACnF,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA"}
package/dist/index.mjs CHANGED
@@ -1,48 +1,43 @@
1
- import { g as l } from "./generator-CSjBe25p.js";
2
- import { f as h, a as v } from "./generator-CSjBe25p.js";
3
- import { resolve as s } from "node:path";
4
- import { watch as c } from "chokidar";
5
- import { createUnplugin as u } from "unplugin";
6
- let o = null, e = null;
7
- function m(t, r) {
8
- return function(...n) {
9
- const i = () => {
10
- e && clearTimeout(e), e = null, t(...n);
11
- };
12
- e && clearTimeout(e), e = setTimeout(i, r);
13
- };
1
+ import { a as e, i as t, n, r, t as i } from "./generator-CWXsEVLn.js";
2
+ import { resolve as a } from "node:path";
3
+ import { watch as o } from "chokidar";
4
+ import { createUnplugin as s } from "unplugin";
5
+ //#region src/unplugin.ts
6
+ var c = null, l = null;
7
+ function u(e, t) {
8
+ return function(...n) {
9
+ l && clearTimeout(l), l = setTimeout(() => {
10
+ l && clearTimeout(l), l = null, e(...n);
11
+ }, t);
12
+ };
14
13
  }
15
- const g = u((t) => ({
16
- name: "i18n-micro-types-generator",
17
- async buildStart() {
18
- try {
19
- await l(t);
20
- } catch (r) {
21
- console.warn("[i18n-types] Failed to generate types:", r);
22
- }
23
- if (process.env.NODE_ENV === "development" || process.env.NODE_ENV !== "production") {
24
- const r = s(t.srcDir, t.translationDir), a = m(async () => {
25
- try {
26
- await l(t);
27
- } catch (n) {
28
- console.warn("[i18n-types] Failed to regenerate types:", n);
29
- }
30
- }, 300);
31
- o = c(r, {
32
- ignoreInitial: !0,
33
- ignored: (n) => /(?:^|[/\\])(?:node_modules|dist|\.nuxt)(?:[/\\]|$)/.test(n)
34
- }), o.on("all", async (n, i) => {
35
- i.endsWith(".json") && a();
36
- });
37
- }
38
- },
39
- buildEnd() {
40
- o && (o.close(), o = null), e && (clearTimeout(e), e = null);
41
- }
14
+ var d = s((e) => ({
15
+ name: "i18n-micro-types-generator",
16
+ async buildStart() {
17
+ try {
18
+ await n(e);
19
+ } catch (e) {
20
+ console.warn("[i18n-types] Failed to generate types:", e);
21
+ }
22
+ if (process.env.NODE_ENV === "development" || process.env.NODE_ENV !== "production") {
23
+ let t = a(e.srcDir, e.translationDir), r = u(async () => {
24
+ try {
25
+ await n(e);
26
+ } catch (e) {
27
+ console.warn("[i18n-types] Failed to regenerate types:", e);
28
+ }
29
+ }, 300);
30
+ c = o(t, {
31
+ ignoreInitial: !0,
32
+ ignored: (e) => /(?:^|[/\\])(?:node_modules|dist|\.nuxt)(?:[/\\]|$)/.test(e)
33
+ }), c.on("all", async (e, t) => {
34
+ t.endsWith(".json") && r();
35
+ });
36
+ }
37
+ },
38
+ buildEnd() {
39
+ c &&= (c.close(), null), l &&= (clearTimeout(l), null);
40
+ }
42
41
  }));
43
- export {
44
- g as I18nTypesPlugin,
45
- h as flattenKeys,
46
- l as generateTypes,
47
- v as getTypesString
48
- };
42
+ //#endregion
43
+ export { d as I18nTypesPlugin, t as flattenKeys, i as formatKeyProperty, n as generateTypes, r as getTypesString, e as isPlainTranslationObject };
package/dist/nuxt.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("@nuxt/kit"),c=require("./generator-CAQjf5De.cjs"),d=a.defineNuxtModule({meta:{name:"@i18n-micro/types-generator",configKey:"i18nTypes"},defaults:{translationDir:"locales"},async setup(o,t){const i=t.options.i18n,n=o.translationDir||i?.translationDir||"locales";a.addTypeTemplate({filename:"types/i18n-micro.d.ts",getContents:async()=>{try{return await c.getTypesString({srcDir:t.options.rootDir,translationDir:n})}catch(e){return console.warn("[i18n-types] Failed to generate types:",e),`// Failed to generate types: ${e instanceof Error?e.message:String(e)}`}}}),t.hook("builder:watch",async(e,s)=>{const r=s.replace(/\\/g,"/"),l=n.replace(/\\/g,"/");r.includes(l)&&r.endsWith(".json")&&await t.callHook("builder:generateApp")})}});exports.default=d;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./generator-BonabDld.cjs");let t=require("@nuxt/kit");var n=(0,t.defineNuxtModule)({meta:{name:`@i18n-micro/types-generator`,configKey:`i18nTypes`},defaults:{translationDir:`locales`},async setup(n,r){let i=r.options.i18n,a=n.translationDir||i?.translationDir||`locales`,o=n.outputFile;typeof o==`string`&&o.length>0&&console.warn("[i18n-types] `i18nTypes.outputFile` is ignored in Nuxt; generated types are written to `.nuxt/types/i18n-micro.d.ts`."),r.options.typescript.hoist||=[],r.options.typescript.hoist.includes(`@i18n-micro/types`)||r.options.typescript.hoist.push(`@i18n-micro/types`),(0,t.addTypeTemplate)({filename:`types/i18n-micro.d.ts`,getContents:async()=>{try{return await e.r({srcDir:r.options.rootDir,translationDir:a})}catch(e){return console.warn(`[i18n-types] Failed to generate types:`,e),`// Failed to generate types: ${e instanceof Error?e.message:String(e)}`}}}),r.hook(`builder:watch`,async(e,t)=>{let n=t.replace(/\\/g,`/`),i=a.replace(/\\/g,`/`);n.includes(i)&&n.endsWith(`.json`)&&await r.callHook(`builder:generateApp`)})}});exports.default=n;
package/dist/nuxt.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  export interface I18nTypesGeneratorOptions {
2
+ /** Translation directory relative to the project root. Defaults to `i18n.translationDir` or `'locales'`. */
2
3
  translationDir?: string;
3
- outputFile?: string;
4
4
  }
5
5
  declare const _default: import('@nuxt/schema').NuxtModule<I18nTypesGeneratorOptions, I18nTypesGeneratorOptions, false>;
6
6
  export default _default;
package/dist/nuxt.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export interface I18nTypesGeneratorOptions {
2
+ /** Translation directory relative to the project root. Defaults to `i18n.translationDir` or `'locales'`. */
2
3
  translationDir?: string;
3
- outputFile?: string;
4
4
  }
5
5
  declare const _default: import('@nuxt/schema').NuxtModule<I18nTypesGeneratorOptions, I18nTypesGeneratorOptions, false>;
6
6
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../src/nuxt.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,yBAAyB;IACxC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;;AAED,wBA+CE"}
1
+ {"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../src/nuxt.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,yBAAyB;IACxC,4GAA4G;IAC5G,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;;AAED,wBA2DE"}
package/dist/nuxt.mjs CHANGED
@@ -1,33 +1,31 @@
1
- import { defineNuxtModule as l, addTypeTemplate as c } from "@nuxt/kit";
2
- import { a as p } from "./generator-CSjBe25p.js";
3
- const g = l({
4
- meta: {
5
- name: "@i18n-micro/types-generator",
6
- configKey: "i18nTypes"
7
- },
8
- defaults: {
9
- translationDir: "locales"
10
- },
11
- async setup(r, t) {
12
- const o = t.options.i18n, n = r.translationDir || o?.translationDir || "locales";
13
- c({
14
- filename: "types/i18n-micro.d.ts",
15
- getContents: async () => {
16
- try {
17
- return await p({
18
- srcDir: t.options.rootDir,
19
- translationDir: n
20
- });
21
- } catch (e) {
22
- return console.warn("[i18n-types] Failed to generate types:", e), `// Failed to generate types: ${e instanceof Error ? e.message : String(e)}`;
23
- }
24
- }
25
- }), t.hook("builder:watch", async (e, i) => {
26
- const a = i.replace(/\\/g, "/"), s = n.replace(/\\/g, "/");
27
- a.includes(s) && a.endsWith(".json") && await t.callHook("builder:generateApp");
28
- });
29
- }
1
+ import { r as e } from "./generator-CWXsEVLn.js";
2
+ import { addTypeTemplate as t, defineNuxtModule as n } from "@nuxt/kit";
3
+ //#region src/nuxt.ts
4
+ var r = n({
5
+ meta: {
6
+ name: "@i18n-micro/types-generator",
7
+ configKey: "i18nTypes"
8
+ },
9
+ defaults: { translationDir: "locales" },
10
+ async setup(n, r) {
11
+ let i = r.options.i18n, a = n.translationDir || i?.translationDir || "locales", o = n.outputFile;
12
+ typeof o == "string" && o.length > 0 && console.warn("[i18n-types] `i18nTypes.outputFile` is ignored in Nuxt; generated types are written to `.nuxt/types/i18n-micro.d.ts`."), r.options.typescript.hoist ||= [], r.options.typescript.hoist.includes("@i18n-micro/types") || r.options.typescript.hoist.push("@i18n-micro/types"), t({
13
+ filename: "types/i18n-micro.d.ts",
14
+ getContents: async () => {
15
+ try {
16
+ return await e({
17
+ srcDir: r.options.rootDir,
18
+ translationDir: a
19
+ });
20
+ } catch (e) {
21
+ return console.warn("[i18n-types] Failed to generate types:", e), `// Failed to generate types: ${e instanceof Error ? e.message : String(e)}`;
22
+ }
23
+ }
24
+ }), r.hook("builder:watch", async (e, t) => {
25
+ let n = t.replace(/\\/g, "/"), i = a.replace(/\\/g, "/");
26
+ n.includes(i) && n.endsWith(".json") && await r.callHook("builder:generateApp");
27
+ });
28
+ }
30
29
  });
31
- export {
32
- g as default
33
- };
30
+ //#endregion
31
+ export { r as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/types-generator",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Type generator for i18n-micro translation keys",
5
5
  "keywords": [
6
6
  "i18n",
@@ -68,14 +68,14 @@
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/node": "^20.19.26",
71
- "publint": "^0.3.17",
72
- "typescript": "^5.9.3",
73
- "vite": "^7.3.6",
74
- "vite-plugin-dts": "^4.5.4",
75
- "vitest": "^4.1.10"
71
+ "publint": "^0.3.24",
72
+ "typescript": "^6.0.3",
73
+ "vite": "^8.2.2",
74
+ "vite-plugin-dts": "^5.1.0",
75
+ "vitest": "^4.1.11"
76
76
  },
77
77
  "peerDependencies": {
78
- "@nuxt/kit": "^3.18.1 || ^4.0.0"
78
+ "@nuxt/kit": "^3.18.1 || ^4.5.2"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=18.17.0"
@@ -1,14 +0,0 @@
1
- "use strict";const i=require("node:fs"),a=require("node:path"),p=require("globby");function y(e,s=""){const t=[];for(const n in e){if(!Object.hasOwn(e,n))continue;const o=e[n],r=s?`${s}.${n}`:n;typeof o=="object"&&o!==null&&!Array.isArray(o)?t.push(...y(o,r)):t.push(r)}return t}async function u(e){const s=a.resolve(e.srcDir,e.translationDir),t=await p.globby("**/*.json",{cwd:s,absolute:!0,ignore:["node_modules/**","dist/**",".nuxt/**"]}),n=new Set;for(const r of t)try{const c=JSON.parse(i.readFileSync(r,"utf-8")),l=y(c);for(const f of l)n.add(f)}catch(c){console.warn(`[i18n-types] Failed to parse ${r}:`,c)}return`/* prettier-ignore */
2
- // @ts-nocheck
3
- // Generated by @i18n-micro/types-generator
4
- // DO NOT EDIT THIS FILE MANUALLY
5
-
6
- import '@i18n-micro/types';
7
-
8
- declare module '@i18n-micro/types' {
9
- export interface DefineLocaleMessage {
10
- ${Array.from(n).sort().map(r=>` '${r}': string;`).join(`
11
- `)}
12
- }
13
- }
14
- `}async function d(e){const s=await u(e),t=e.outputFile||a.resolve(e.srcDir,"i18n-micro.d.ts"),n=a.dirname(t);try{i.mkdirSync(n,{recursive:!0})}catch{}return i.writeFileSync(t,s,"utf-8"),t}exports.flattenKeys=y;exports.generateTypes=d;exports.getTypesString=u;
@@ -1,54 +0,0 @@
1
- import { readFileSync as l, mkdirSync as f, writeFileSync as p } from "node:fs";
2
- import { resolve as i, dirname as m } from "node:path";
3
- import { globby as d } from "globby";
4
- function a(e, o = "") {
5
- const t = [];
6
- for (const n in e) {
7
- if (!Object.hasOwn(e, n)) continue;
8
- const s = e[n], r = o ? `${o}.${n}` : n;
9
- typeof s == "object" && s !== null && !Array.isArray(s) ? t.push(...a(s, r)) : t.push(r);
10
- }
11
- return t;
12
- }
13
- async function g(e) {
14
- const o = i(e.srcDir, e.translationDir), t = await d("**/*.json", {
15
- cwd: o,
16
- absolute: !0,
17
- ignore: ["node_modules/**", "dist/**", ".nuxt/**"]
18
- }), n = /* @__PURE__ */ new Set();
19
- for (const r of t)
20
- try {
21
- const c = JSON.parse(l(r, "utf-8")), y = a(c);
22
- for (const u of y)
23
- n.add(u);
24
- } catch (c) {
25
- console.warn(`[i18n-types] Failed to parse ${r}:`, c);
26
- }
27
- return `/* prettier-ignore */
28
- // @ts-nocheck
29
- // Generated by @i18n-micro/types-generator
30
- // DO NOT EDIT THIS FILE MANUALLY
31
-
32
- import '@i18n-micro/types';
33
-
34
- declare module '@i18n-micro/types' {
35
- export interface DefineLocaleMessage {
36
- ${Array.from(n).sort().map((r) => ` '${r}': string;`).join(`
37
- `)}
38
- }
39
- }
40
- `;
41
- }
42
- async function h(e) {
43
- const o = await g(e), t = e.outputFile || i(e.srcDir, "i18n-micro.d.ts"), n = m(t);
44
- try {
45
- f(n, { recursive: !0 });
46
- } catch {
47
- }
48
- return p(t, o, "utf-8"), t;
49
- }
50
- export {
51
- g as a,
52
- a as f,
53
- h as g
54
- };