@intlayer/chokidar 5.0.2 → 5.0.4

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n type ContentNode,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nextDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst {\n internationalization: { locales },\n} = getConfiguration();\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (content: ContentNode, locale: Locales): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const contentState = (content as TranslationContent)[NodeType.Translation];\n const result = contentState[locale as keyof typeof contentState];\n\n return buildDictionary(result as ContentNode, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(\n (content as EnumerationContent<unknown>)[NodeType.Enumeration]\n ).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as ContentNode,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object' &&\n Array.isArray(content)\n ) {\n const result: unknown[] = [];\n\n Object.keys(content).forEach((dictionaryValue) => {\n result.push(\n buildDictionary(\n content[dictionaryValue as keyof typeof content] as ContentNode,\n locale\n )\n );\n });\n\n return result;\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content as Record<string, unknown>).forEach(\n (dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content?.[dictionaryValue as keyof typeof content] as ContentNode,\n locale\n );\n }\n );\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nextDictionaries = (\n content: ContentNode\n): I18nextDictionariesOutput => {\n // Map dictionaries for each locale\n const result: I18nextDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,kBAMO;AACP,kCAAqC;AAKrC,MAAM;AAAA,EACJ,sBAAsB,EAAE,QAAQ;AAClC,QAAI,gCAAiB;AAErB,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eACrB,OAAO,MAAM,UAAU,eACvB,OAAO,MAAM,SAAS;AAGxB,MAAM,kBAAkB,CAAC,SAAsB,WAA6B;AAC1E;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,qBAAS;AAAA,IAC7C;AACA,UAAM,eAAgB,QAA+B,qBAAS,WAAW;AACzE,UAAM,SAAS,aAAa,MAAmC;AAE/D,WAAO,gBAAgB,QAAuB,MAAM;AAAA,EACtD;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,qBAAS;AAAA,IAC7C;AACA,UAAM,UAAmC,CAAC;AAE1C,WAAO;AAAA,MACJ,QAAwC,qBAAS,WAAW;AAAA,IAC/D,EAAE,QAAQ,CAAC,aAAa;AACtB,YAAM,mBAAe,kDAAqB,QAAQ;AAElD,YAAM,QAAS,QACb,QACF;AAEA,cAAQ,GAAG,YAAY,IAAI,YAAY,EAAE,IAAI;AAAA,QAC3C;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA,IAEE,YAAY,OAAkC;AAAA,IAC9C;AACA,WAAO,KAAK,UAAU,OAAO;AAAA,EAC/B;AAAA;AAAA,IAEE,OAAO,YAAY,YACnB,MAAM,QAAQ,OAAO;AAAA,IACrB;AACA,UAAM,SAAoB,CAAC;AAE3B,WAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,oBAAoB;AAChD,aAAO;AAAA,QACL;AAAA,UACE,QAAQ,eAAuC;AAAA,UAC/C;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AAAA;AAAA,IAEE,OAAO,YAAY;AAAA,IACnB;AACA,UAAM,SAAkC,CAAC;AAEzC,WAAO,KAAK,OAAkC,EAAE;AAAA,MAC9C,CAAC,oBAAoB;AACnB,eAAO,eAAe,IAAI;AAAA,UACxB,UAAU,eAAuC;AAAA,UACjD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,4BAA4B,CACvC,YAC8B;AAE9B,QAAM,SAAoC,QAAQ;AAAA,IAChD,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,CAAC,MAAM,GAAG,gBAAgB,SAAS,MAAM;AAAA,IAC3C;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n type ContentNode,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nextDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst {\n internationalization: { locales },\n} = getConfiguration();\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (content: ContentNode, locale: Locales): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const contentState = (content as TranslationContent)[NodeType.Translation];\n const result = contentState[locale as keyof typeof contentState];\n\n return buildDictionary(result as ContentNode, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(\n (content as EnumerationContent<unknown>)[NodeType.Enumeration]\n ).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as ContentNode,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object' &&\n Array.isArray(content)\n ) {\n const result: unknown[] = [];\n\n Object.keys(content).forEach((dictionaryValue) => {\n result.push(\n buildDictionary(\n content[dictionaryValue as keyof typeof content] as ContentNode,\n locale\n )\n );\n });\n\n return result;\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content as Record<string, unknown>).forEach(\n (dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content?.[\n dictionaryValue as keyof typeof content\n ] as unknown as ContentNode,\n locale\n );\n }\n );\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nextDictionaries = (\n content: ContentNode\n): I18nextDictionariesOutput => {\n // Map dictionaries for each locale\n const result: I18nextDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n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B;AACA,UAAM,SAAkC,CAAC;AAEzC,WAAO,KAAK,OAAkC,EAAE;AAAA,MAC9C,CAAC,oBAAoB;AACnB,eAAO,eAAe,IAAI;AAAA,UACxB,UACE,eACF;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,4BAA4B,CACvC,YAC8B;AAE9B,QAAM,SAAoC,QAAQ;AAAA,IAChD,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,CAAC,MAAM,GAAG,gBAAgB,SAAS,MAAM;AAAA,IAC3C;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
@@ -74,9 +74,6 @@ ${formattedDictionaryMap}
74
74
  content2 += ` type ConfigLocales = ${formatLocales};
75
75
  `;
76
76
  content2 += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;
77
- `;
78
- content2 += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;
79
-
80
77
  `;
81
78
  content2 += ` ${strictModeRecord}
82
79
  `;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, kebabCaseToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { moduleAugmentationDir, typesDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionariesTypesDefinitions: string[] = fg.sync(`${typesDir}/*.ts`, {\n ignore: ['**/*.d.ts'],\n });\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAkD;AAClD,oBAA0C;AAC1C,uBAAe;AACf,mBAAkD;AAElD,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,uBAAuB,SAAS,IAAI;AAC5C,MAAM,EAAE,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,QAC1B,OAAG,mCAAqB,GAAG,CAAC;AAK9B,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAK,sBAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,0BAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,IAAAA,YAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AAAA,EACvE,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,aAAa,WAAW,IAAI,GAAG,EACxE,KAAK,IAAI;AAEZ,QAAM,gBAAgB,QACnB,IAAI,CAAC,WAAW;AACf,eAAW,OAAO,uBAAS;AACzB,UAAI,sBAAQ,GAA2B,MAAM,QAAQ;AACnD,eAAO,WAAW,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF,CAAC,EACA,KAAK,KAAK;AAEb,QAAM,mBACJ,eAAe,WACX,mFACA,eAAe,kBACb,8HACA;AAuBR,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACpF,EAAAA,YAAW,0BAA0B,aAAa;AAAA;AAClD,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA;AAAA;AACX,EAAAA,YAAW,KAAK,gBAAgB;AAAA;AAChC,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,KAAC,sBAAW,qBAAqB,GAAG;AACtC,6BAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,+BAAyC,iBAAAC,QAAG,KAAK,GAAG,QAAQ,SAAS;AAAA,IACzE,QAAQ,CAAC,WAAW;AAAA,EACtB,CAAC;AAGD,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content","fg"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, kebabCaseToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { moduleAugmentationDir, typesDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionariesTypesDefinitions: string[] = fg.sync(`${typesDir}/*.ts`, {\n ignore: ['**/*.d.ts'],\n });\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqD;AACrD,kBAAkD;AAClD,oBAA0C;AAC1C,uBAAe;AACf,mBAAkD;AAElD,MAAM,EAAE,SAAS,qBAAqB,QAAI,gCAAiB;AAC3D,MAAM,EAAE,uBAAuB,SAAS,IAAI;AAC5C,MAAM,EAAE,SAAS,WAAW,IAAI;AAEzB,MAAM,cAAc,CAAC,QAC1B,OAAG,mCAAqB,GAAG,CAAC;AAK9B,MAAM,2BAA2B,CAAC,cAAgC;AAChE,MAAIA,WAAU;AAEd,QAAM,kBAAkB,UAAU,IAAI,CAAC,oBAAoB;AAAA,IACzD,cAAc,SAAK,sBAAS,uBAAuB,cAAc,CAAC;AAAA,IAClE,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,0BAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,IAAAA,YAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AAAA,EACvE,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,QAAQ,WAAW,EAAE,aAAa,WAAW,IAAI,GAAG,EACxE,KAAK,IAAI;AAEZ,QAAM,gBAAgB,QACnB,IAAI,CAAC,WAAW;AACf,eAAW,OAAO,uBAAS;AACzB,UAAI,sBAAQ,GAA2B,MAAM,QAAQ;AACnD,eAAO,WAAW,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF,CAAC,EACA,KAAK,KAAK;AAEb,QAAM,mBACJ,eAAe,WACX,mFACA,eAAe,kBACb,8HACA;AAsBR,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW;AAAA,EAAmD,sBAAsB;AAAA;AAAA;AAAA;AACpF,EAAAA,YAAW,0BAA0B,aAAa;AAAA;AAClD,EAAAA,YAAW;AAAA;AACX,EAAAA,YAAW,KAAK,gBAAgB;AAAA;AAChC,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,KAAC,sBAAW,qBAAqB,GAAG;AACtC,6BAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,+BAAyC,iBAAAC,QAAG,KAAK,GAAG,QAAQ,SAAS;AAAA,IACzE,QAAQ,CAAC,WAAW;AAAA,EACtB,CAAC;AAGD,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,mCAAc,kBAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content","fg"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n type ContentNode,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nextDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst {\n internationalization: { locales },\n} = getConfiguration();\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (content: ContentNode, locale: Locales): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const contentState = (content as TranslationContent)[NodeType.Translation];\n const result = contentState[locale as keyof typeof contentState];\n\n return buildDictionary(result as ContentNode, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(\n (content as EnumerationContent<unknown>)[NodeType.Enumeration]\n ).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as ContentNode,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object' &&\n Array.isArray(content)\n ) {\n const result: unknown[] = [];\n\n Object.keys(content).forEach((dictionaryValue) => {\n result.push(\n buildDictionary(\n content[dictionaryValue as keyof typeof content] as ContentNode,\n locale\n )\n );\n });\n\n return result;\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content as Record<string, unknown>).forEach(\n (dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content?.[dictionaryValue as keyof typeof content] as ContentNode,\n locale\n );\n }\n );\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nextDictionaries = (\n content: ContentNode\n): I18nextDictionariesOutput => {\n // Map dictionaries for each locale\n const result: I18nextDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result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AAC;AAEzC,WAAO,KAAK,OAAkC,EAAE;AAAA,MAC9C,CAAC,oBAAoB;AACnB,eAAO,eAAe,IAAI;AAAA,UACxB,UAAU,eAAuC;AAAA,UACjD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,4BAA4B,CACvC,YAC8B;AAE9B,QAAM,SAAoC,QAAQ;AAAA,IAChD,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,CAAC,MAAM,GAAG,gBAAgB,SAAS,MAAM;AAAA,IAC3C;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config';\nimport {\n NodeType,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n type ContentNode,\n} from '@intlayer/core';\nimport { convertPluralsValues } from './convertPluralsValues';\n\ntype Dictionary = Record<string, unknown>;\nexport type I18nextDictionariesOutput = Partial<Record<Locales, Dictionary>>;\n\nconst {\n internationalization: { locales },\n} = getConfiguration();\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' &&\n typeof node?.props !== 'undefined' &&\n typeof node?.type !== 'undefined';\n\n// Build dictionary for a specific locale\nconst buildDictionary = (content: ContentNode, locale: Locales): unknown => {\n if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Translation\n ) {\n const contentState = (content as TranslationContent)[NodeType.Translation];\n const result = contentState[locale as keyof typeof contentState];\n\n return buildDictionary(result as ContentNode, locale);\n } else if (\n // Translation node\n content &&\n (content as TypedNode).nodeType === NodeType.Enumeration\n ) {\n const plurals: Record<string, unknown> = {};\n\n Object.keys(\n (content as EnumerationContent<unknown>)[NodeType.Enumeration]\n ).forEach((quantity) => {\n const letterNumber = convertPluralsValues(quantity);\n\n const value = (content as EnumerationContent<unknown>)[\n quantity as keyof EnumerationContent<unknown>\n ];\n\n plurals[`${letterNumber}_${letterNumber}`] = buildDictionary(\n value as ContentNode,\n locale\n );\n });\n\n return plurals;\n } else if (\n // React element node\n isReactNode(content as Record<string, unknown>)\n ) {\n return JSON.stringify(content);\n } else if (\n // Nested object\n typeof content === 'object' &&\n Array.isArray(content)\n ) {\n const result: unknown[] = [];\n\n Object.keys(content).forEach((dictionaryValue) => {\n result.push(\n buildDictionary(\n content[dictionaryValue as keyof typeof content] as ContentNode,\n locale\n )\n );\n });\n\n return result;\n } else if (\n // Nested object\n typeof content === 'object'\n ) {\n const result: Record<string, unknown> = {};\n\n Object.keys(content as Record<string, unknown>).forEach(\n (dictionaryValue) => {\n result[dictionaryValue] = buildDictionary(\n content?.[\n dictionaryValue as keyof typeof content\n ] as unknown as ContentNode,\n locale\n );\n }\n );\n\n return result;\n }\n\n return content;\n};\n\nexport const createI18nextDictionaries = (\n content: ContentNode\n): I18nextDictionariesOutput => {\n // Map dictionaries for each locale\n const result: I18nextDictionariesOutput = locales.reduce(\n (acc, locale) => ({\n ...acc,\n [locale]: buildDictionary(content, locale),\n }),\n {}\n );\n\n return result;\n};\n"],"mappings":"AAAA,SAAS,wBAAsC;AAC/C;AAAA,EACE;AAAA,OAKK;AACP,SAAS,4BAA4B;AAKrC,MAAM;AAAA,EACJ,sBAAsB,EAAE,QAAQ;AAClC,IAAI,iBAAiB;AAErB,MAAM,cAAc,CAAC,SACnB,OAAO,MAAM,QAAQ,eACrB,OAAO,MAAM,UAAU,eACvB,OAAO,MAAM,SAAS;AAGxB,MAAM,kBAAkB,CAAC,SAAsB,WAA6B;AAC1E;AAAA;AAAA,IAEE,WACC,QAAsB,aAAa,SAAS;AAAA,IAC7C;AACA,UAAM,eAAgB,QAA+B,SAAS,WAAW;AACzE,UAAM,SAAS,aAAa,MAAmC;AAE/D,WAAO,gBAAgB,QAAuB,MAAM;AAAA,EACtD;AAAA;AA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${formatLocales};
41
41
  `;
42
42
  content2 += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;
43
- `;
44
- content2 += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;
45
-
46
43
  `;
47
44
  content2 += ` ${strictModeRecord}
48
45
  `;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, kebabCaseToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { moduleAugmentationDir, typesDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n * type ExcludedLocales = Exclude<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` type ExcludedLocales = Exclude<Locales, ConfigLocales>;\\n\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionariesTypesDefinitions: string[] = fg.sync(`${typesDir}/*.ts`, {\n ignore: ['**/*.d.ts'],\n });\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,MAAM,gBAAgB;AAClD,SAAS,SAAS,wBAAwB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AOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,+BAAyC,GAAG,KAAK,GAAG,QAAQ,SAAS;AAAA,IACzE,QAAQ,CAAC,WAAW;AAAA,EACtB,CAAC;AAGD,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
1
+ {"version":3,"sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, join, relative } from 'path';\nimport { Locales, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { getFileHash, kebabCaseToCamelCase } from '../../utils';\n\nconst { content, internationalization } = getConfiguration();\nconst { moduleAugmentationDir, typesDir } = content;\nconst { locales, strictMode } = internationalization;\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\n/**\n * This function generates the content of the module augmentation file\n */\nconst generateTypeIndexContent = (typeFiles: string[]): string => {\n let content = \"/* eslint-disable */\\nimport { Locales } from 'intlayer';\\n\";\n\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id (without the extension)\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n const formatLocales = locales\n .map((locale) => {\n for (const key in Locales) {\n if (Locales[key as keyof typeof Locales] === locale) {\n return `Locales.${key}`;\n }\n }\n })\n .join(' | ');\n\n const strictModeRecord =\n strictMode === 'strict'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content> {}`\n : strictMode === 'required_only'\n ? `interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}`\n : `interface IConfigLocales<Content> extends Partial<Record<Locales, Content>> {}`;\n\n /**\n * Write the module augmentation to extend the intlayer module with the dictionaries types\n * Will suggest the type resulting of the dictionaries\n *\n * declare module 'intlayer' {\n * interface IntlayerDictionaryTypesConnector = {\n * dictionaries: {\n * id: DictionaryType;\n * }\n * }\n *\n * type ConfigLocales = Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH;\n * type ExtractedLocales = Extract<Locales, ConfigLocales>;\n *\n * interface IConfigLocales<Content> extends Record<ExtractedLocales, Content>, Partial<Record<ExcludedLocales, Content>> {}\n *\n *\n * }\n * See https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation\n */\n content += `declare module 'intlayer' {\\n`;\n content += ` interface IntlayerDictionaryTypesConnector {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n content += ` type ConfigLocales = ${formatLocales};\\n`;\n content += ` type ExtractedLocales = Extract<Locales, ConfigLocales>;\\n`;\n content += ` ${strictModeRecord}\\n`;\n content += `}`;\n\n return content;\n};\n\n/**\n * This function generates a index file merging all the types\n */\nexport const createModuleAugmentation = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(moduleAugmentationDir)) {\n mkdirSync(moduleAugmentationDir, { recursive: true });\n }\n\n const dictionariesTypesDefinitions: string[] = fg.sync(`${typesDir}/*.ts`, {\n ignore: ['**/*.d.ts'],\n });\n // Create the dictionary list file\n\n const tsContent = generateTypeIndexContent(dictionariesTypesDefinitions);\n writeFileSync(join(moduleAugmentationDir, 'intlayer.d.ts'), tsContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACr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A;AAChC,EAAAA,YAAW;AAEX,SAAOA;AACT;AAKO,MAAM,2BAA2B,MAAM;AAE5C,MAAI,CAAC,WAAW,qBAAqB,GAAG;AACtC,cAAU,uBAAuB,EAAE,WAAW,KAAK,CAAC;AAAA,EACtD;AAEA,QAAM,+BAAyC,GAAG,KAAK,GAAG,QAAQ,SAAS;AAAA,IACzE,QAAQ,CAAC,WAAW;AAAA,EACtB,CAAC;AAGD,QAAM,YAAY,yBAAyB,4BAA4B;AACvE,gBAAc,KAAK,uBAAuB,eAAe,GAAG,SAAS;AACvE;","names":["content"]}
@@ -1 +1 @@
1
- {"version":3,"file":"convertContentDeclarationInto18nDictionaries.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AAGxB,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1C,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAwF7E,eAAO,MAAM,yBAAyB,YAC3B,WAAW,KACnB,yBAWF,CAAC"}
1
+ {"version":3,"file":"convertContentDeclarationInto18nDictionaries.d.ts","sourceRoot":"","sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/convertContentDeclarationInto18nDictionaries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AAGxB,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1C,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AA0F7E,eAAO,MAAM,yBAAyB,YAC3B,WAAW,KACnB,yBAWF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createModuleAugmentation.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,MACH,CAAC;AA2ExC;;GAEG;AACH,eAAO,MAAM,wBAAwB,YAapC,CAAC"}
1
+ {"version":3,"file":"createModuleAugmentation.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/dictionary_to_type/createModuleAugmentation.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,MACH,CAAC;AAyExC;;GAEG;AACH,eAAO,MAAM,wBAAwB,YAapC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/chokidar",
3
- "version": "5.0.2",
3
+ "version": "5.0.4",
4
4
  "private": false,
5
5
  "description": "Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.",
6
6
  "keywords": [
@@ -62,10 +62,10 @@
62
62
  "esbuild": "^0.24.2",
63
63
  "fast-glob": "^3.3.3",
64
64
  "p-limit": "^3.1.0",
65
- "@intlayer/api": "5.0.2",
66
- "@intlayer/core": "5.0.2",
67
- "intlayer": "5.0.2",
68
- "@intlayer/config": "5.0.2"
65
+ "@intlayer/api": "5.0.4",
66
+ "intlayer": "5.0.4",
67
+ "@intlayer/core": "5.0.4",
68
+ "@intlayer/config": "5.0.4"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@changesets/cli": "2.27.12",
@@ -79,19 +79,19 @@
79
79
  "tsc-alias": "^1.8.10",
80
80
  "tsup": "^8.3.5",
81
81
  "typescript": "^5.7.3",
82
- "@intlayer/backend": "5.0.2",
82
+ "@intlayer/backend": "5.0.4",
83
83
  "@utils/eslint-config": "1.0.4",
84
+ "@utils/ts-config": "1.0.4",
84
85
  "@utils/ts-config-types": "1.0.4",
85
- "@utils/tsup-config": "1.0.4",
86
- "@utils/ts-config": "1.0.4"
86
+ "@utils/tsup-config": "1.0.4"
87
87
  },
88
88
  "peerDependencies": {
89
89
  "fast-glob": "^3.3.3",
90
90
  "react": ">=16.0.0",
91
- "@intlayer/api": "5.0.2",
92
- "@intlayer/config": "5.0.2",
93
- "intlayer": "^5.0.2",
94
- "@intlayer/core": "5.0.2"
91
+ "@intlayer/core": "5.0.4",
92
+ "intlayer": "^5.0.4",
93
+ "@intlayer/api": "5.0.4",
94
+ "@intlayer/config": "5.0.4"
95
95
  },
96
96
  "engines": {
97
97
  "node": ">=14.18"