@intlayer/babel 9.5.12 → 9.7.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.
@@ -28,12 +28,13 @@ const getOutput = (configuration, locale) => {
28
28
  * Resolves the paths for the content files associated with a component.
29
29
  * Checks for existing dictionaries first.
30
30
  */
31
- const resolveContentFilePaths = async (filePath, componentKey, configuration, locale) => {
31
+ const resolveContentFilePaths = async (filePath, componentKey, configuration, locale, format) => {
32
32
  const { baseDir } = configuration.system;
33
33
  const { defaultLocale } = configuration.internationalization;
34
34
  const existingDicts = ((0, _intlayer_dictionaries_entry_unmerged.getUnmergedDictionaries)(configuration) ?? {})[componentKey]?.filter((dictionary) => dictionary.location !== "remote").filter((dictionary) => dictionary.locale === void 0 || dictionary.locale === (locale ?? defaultLocale));
35
- if (existingDicts?.[0]?.filePath) {
36
- const existingPath = existingDicts[0].filePath;
35
+ const matchingExistingDict = format ? existingDicts?.find((d) => d.filePath && (0, _intlayer_engine_utils.getFormatFromExtension)((0, node_path.extname)(d.filePath)) === format) : existingDicts?.[0];
36
+ if (matchingExistingDict?.filePath) {
37
+ const existingPath = matchingExistingDict.filePath;
37
38
  const resolvedAbsolutePath = (0, node_path.resolve)(baseDir, existingPath);
38
39
  (0, _intlayer_config_utils.assertPathWithin)(resolvedAbsolutePath, baseDir);
39
40
  return {
@@ -49,6 +50,8 @@ const resolveContentFilePaths = async (filePath, componentKey, configuration, lo
49
50
  const uncapitalizedName = componentName.charAt(0).toLowerCase() + componentName.slice(1);
50
51
  const componentFormat = (0, _intlayer_engine_utils.getFormatFromExtension)(extension);
51
52
  const targetLocale = locale ?? defaultLocale;
53
+ const targetFormatExtension = format ? (0, _intlayer_engine_utils.getExtensionFromFormat)(format) : void 0;
54
+ const targetExtension = targetFormatExtension ? configuration.content?.fileExtensions?.find((ext) => ext.endsWith(targetFormatExtension)) ?? targetFormatExtension : configuration.content?.fileExtensions?.[0] ?? ".ts";
52
55
  const context = {
53
56
  key: componentKey,
54
57
  componentDirPath: (0, node_path.relative)(baseDir, (0, node_path.dirname)(filePath)),
@@ -56,9 +59,9 @@ const resolveContentFilePaths = async (filePath, componentKey, configuration, lo
56
59
  fileName: uncapitalizedName,
57
60
  componentFormat,
58
61
  componentExtension: extension,
59
- format: componentFormat,
62
+ format: format ?? componentFormat,
60
63
  locale: targetLocale,
61
- extension: configuration.content.fileExtensions[0] ?? ".ts"
64
+ extension: targetExtension
62
65
  };
63
66
  if (isObjectOutput) {
64
67
  const pattern = getOutput(configuration, targetLocale);
@@ -92,11 +95,11 @@ const resolveContentFilePaths = async (filePath, componentKey, configuration, lo
92
95
  /**
93
96
  * Extracts the dictionary key and dictionary file path for a given component file.
94
97
  */
95
- const extractDictionaryInfo = async (filePath, fileText, configuration) => {
98
+ const extractDictionaryInfo = async (filePath, fileText, configuration, format) => {
96
99
  const dictionaryKey = require_extractContent_utils_extractDictionaryKey.extractDictionaryKey(filePath, fileText);
97
100
  return {
98
101
  dictionaryKey,
99
- ...await resolveContentFilePaths(filePath, dictionaryKey, configuration)
102
+ ...await resolveContentFilePaths(filePath, dictionaryKey, configuration, void 0, format)
100
103
  };
101
104
  };
102
105
 
@@ -1 +1 @@
1
- {"version":3,"file":"extractDictionaryInfo.cjs","names":["colorize","ANSIColors","parseStringPattern","getUnmergedDictionaries","resolve","relative","extname","basename","getFormatFromExtension","dirname","resolveRelativePath","extractDictionaryKey"],"sources":["../../../../src/extractContent/utils/extractDictionaryInfo.ts"],"sourcesContent":["import { basename, dirname, extname, relative, resolve } from 'node:path';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize } from '@intlayer/config/logger';\nimport { assertPathWithin, parseStringPattern } from '@intlayer/config/utils';\nimport { getUnmergedDictionaries } from '@intlayer/dictionaries-entry/unmerged';\nimport {\n getFormatFromExtension,\n resolveRelativePath,\n} from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Fill } from '@intlayer/types/dictionary';\nimport type {\n FilePathPattern,\n FilePathPatternContext,\n FilePathPatternFunction,\n} from '@intlayer/types/filePathPattern';\nimport { extractDictionaryKey } from './extractDictionaryKey';\n\nexport const getOutput = (\n configuration: IntlayerConfig,\n locale?: Locale\n): FilePathPatternFunction | false => {\n const output = configuration.compiler?.output as Fill | undefined;\n\n if (output === undefined || output === null) {\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n }\n\n if (output === false) return false;\n\n // Object per-locale record: look up the entry for the given locale\n if (typeof output === 'object' && typeof output !== 'function') {\n const entry = locale\n ? (output as Record<string, boolean | FilePathPattern>)[locale]\n : undefined;\n if (entry === false) return false;\n if (entry === undefined || entry === true) {\n throw new Error(\n `No output pattern configured for locale \"${locale}\" in compiler.output.`\n );\n }\n return typeof entry === 'string'\n ? (context: FilePathPatternContext) =>\n parseStringPattern(entry as string, context)\n : (entry as FilePathPatternFunction);\n }\n\n if (typeof output === 'string') {\n return (context: FilePathPatternContext) =>\n parseStringPattern(output, context);\n }\n\n if (typeof output === 'function') {\n return output as FilePathPatternFunction;\n }\n\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n};\n\nexport type ResolveContentFilePaths = {\n absolutePath: string;\n relativePath: string;\n isPerLocale: boolean;\n};\n\n/**\n * Resolves the paths for the content files associated with a component.\n * Checks for existing dictionaries first.\n */\nexport const resolveContentFilePaths = async (\n filePath: string,\n componentKey: string,\n configuration: IntlayerConfig,\n locale?: Locale\n): Promise<ResolveContentFilePaths> => {\n const { baseDir } = configuration.system;\n const { defaultLocale } = configuration.internationalization;\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration) ?? {};\n const existingDicts = unmergedDictionaries[componentKey]\n ?.filter(\n (dictionary) =>\n // Remove remote dictionaries (Fix: Check for !== instead of ===)\n dictionary.location !== 'remote'\n )\n .filter(\n (dictionary) =>\n // Check for first locale dictionary sorted by priority that include the targeted locale\n dictionary.locale === undefined ||\n dictionary.locale === (locale ?? defaultLocale)\n );\n\n if (existingDicts?.[0]?.filePath) {\n const existingPath = existingDicts[0].filePath;\n const resolvedAbsolutePath = resolve(baseDir, existingPath);\n\n assertPathWithin(resolvedAbsolutePath, baseDir);\n\n return {\n absolutePath: resolvedAbsolutePath,\n relativePath: relative(baseDir, resolvedAbsolutePath),\n isPerLocale: false,\n };\n }\n\n const output = configuration.compiler?.output as Fill | undefined;\n const isObjectOutput =\n typeof output === 'object' &&\n output !== null &&\n typeof output !== 'function';\n\n // Build shared context (used for both object and scalar output paths)\n const extension = extname(\n filePath\n ) as FilePathPatternContext['componentExtension'];\n const componentName = basename(filePath, extension);\n const uncapitalizedName =\n componentName.charAt(0).toLowerCase() + componentName.slice(1);\n const componentFormat = getFormatFromExtension(\n extension!\n ) as FilePathPatternContext['componentFormat'];\n\n const targetLocale = (locale ?? defaultLocale) as Locale;\n\n const context: FilePathPatternContext = {\n key: componentKey,\n componentDirPath: relative(baseDir, dirname(filePath)),\n componentFileName: componentName,\n fileName: uncapitalizedName,\n componentFormat,\n componentExtension: extension,\n format: componentFormat!,\n locale: targetLocale,\n extension: configuration.content.fileExtensions[0] ?? '.ts',\n };\n\n // Object output: each locale has its own pattern → always per-locale\n if (isObjectOutput) {\n const pattern = getOutput(configuration, targetLocale);\n if (pattern === false) {\n throw new Error(\n `compiler.output is disabled for locale \"${targetLocale}\".`\n );\n }\n const rawAbsolutePath = await pattern(context);\n const absolutePath = resolveRelativePath(\n rawAbsolutePath,\n filePath,\n baseDir\n );\n return {\n absolutePath,\n relativePath: relative(baseDir, absolutePath),\n isPerLocale: true,\n };\n }\n\n // Scalar string/function output: detect per-locale via dummy locale probe\n const pattern = getOutput(configuration);\n if (pattern === false) {\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n }\n\n const rawAbsolutePath = await pattern({ ...context, locale: defaultLocale });\n\n // Apply the resolution rules\n const absolutePath = resolveRelativePath(rawAbsolutePath, filePath, baseDir);\n\n const localeIdentifier = '###########locale###########' as Locale;\n\n const rawPerLocalePath = await pattern({\n ...context,\n locale: localeIdentifier,\n });\n const isPerLocale = rawPerLocalePath.includes(localeIdentifier);\n\n return {\n absolutePath,\n relativePath: relative(baseDir, absolutePath),\n isPerLocale,\n };\n};\n\nexport type ExtractDictionaryInfoOptions = {\n configuration?: IntlayerConfig;\n};\n\n/**\n * Extracts the dictionary key and dictionary file path for a given component file.\n */\nexport const extractDictionaryInfo = async (\n filePath: string,\n fileText: string,\n configuration: IntlayerConfig\n): Promise<\n {\n dictionaryKey: string;\n } & ResolveContentFilePaths\n> => {\n const dictionaryKey = extractDictionaryKey(filePath, fileText);\n\n const resolvedPaths = await resolveContentFilePaths(\n filePath,\n dictionaryKey,\n configuration\n );\n\n return {\n dictionaryKey,\n ...resolvedPaths,\n };\n};\n"],"mappings":";;;;;;;;;;;;AAmBA,MAAa,aACX,eACA,WACoC;CACpC,MAAM,SAAS,cAAc,UAAU;CAEvC,IAAI,WAAW,UAAa,WAAW,MACrC,MAAM,IAAI,MACR,4CAAwCA,kCAAS,mBAAmBC,wBAAW,IAAI,EAAE,wBACvF;CAGF,IAAI,WAAW,OAAO,OAAO;CAG7B,IAAI,OAAO,WAAW,YAAY,OAAO,WAAW,YAAY;EAC9D,MAAM,QAAQ,SACT,OAAqD,UACtD;EACJ,IAAI,UAAU,OAAO,OAAO;EAC5B,IAAI,UAAU,UAAa,UAAU,MACnC,MAAM,IAAI,MACR,4CAA4C,OAAO,sBACrD;EAEF,OAAO,OAAO,UAAU,YACnB,gBACCC,2CAAmB,OAAiB,OAAO,IAC5C;CACP;CAEA,IAAI,OAAO,WAAW,UACpB,QAAQ,gBACNA,2CAAmB,QAAQ,OAAO;CAGtC,IAAI,OAAO,WAAW,YACpB,OAAO;CAGT,MAAM,IAAI,MACR,4CAAwCF,kCAAS,mBAAmBC,wBAAW,IAAI,EAAE,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ACL;GACA,kBAAcL,oBAAS,SAAS,YAAY;GAC5C,aAAa;EACf;CACF;CAGA,MAAM,UAAU,UAAU,aAAa;CACvC,IAAI,YAAY,OACd,MAAM,IAAI,MACR,4CAAwCL,kCAAS,mBAAmBC,wBAAW,IAAI,EAAE,wBACvF;CAGF,MAAM,kBAAkB,MAAM,QAAQ;EAAE,GAAG;EAAS,QAAQ;CAAc,CAAC;CAG3E,MAAM,mBAAeS,4CAAoB,iBAAiB,UAAU,OAAO;CAE3E,MAAM,mBAAmB;CAMzB,MAAM,eAAc,MAJW,QAAQ;EACrC,GAAG;EACH,QAAQ;CACV,CAAC,EACmC,CAAC,SAAS,gBAAgB;CAE9D,OAAO;EACL;EACA,kBAAcL,oBAAS,SAAS,YAAY;EAC5C;CACF;AACF;;;;AASA,MAAa,wBAAwB,OACnC,UACA,UACA,kBAKG;CACH,MAAM,gBAAgBM,uEAAqB,UAAU,QAAQ;CAQ7D,OAAO;EACL;EACA,GAAG,MARuB,wBAC1B,UACA,eACA,aACF;CAKA;AACF"}
1
+ {"version":3,"file":"extractDictionaryInfo.cjs","names":["colorize","ANSIColors","parseStringPattern","getUnmergedDictionaries","getFormatFromExtension","extname","resolve","relative","basename","getExtensionFromFormat","dirname","resolveRelativePath","extractDictionaryKey"],"sources":["../../../../src/extractContent/utils/extractDictionaryInfo.ts"],"sourcesContent":["import { basename, dirname, extname, relative, resolve } from 'node:path';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize } from '@intlayer/config/logger';\nimport { assertPathWithin, parseStringPattern } from '@intlayer/config/utils';\nimport { getUnmergedDictionaries } from '@intlayer/dictionaries-entry/unmerged';\nimport {\n type Format,\n getExtensionFromFormat,\n getFormatFromExtension,\n resolveRelativePath,\n} from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Fill } from '@intlayer/types/dictionary';\nimport type {\n FilePathPattern,\n FilePathPatternContext,\n FilePathPatternFunction,\n} from '@intlayer/types/filePathPattern';\nimport { extractDictionaryKey } from './extractDictionaryKey';\n\nexport const getOutput = (\n configuration: IntlayerConfig,\n locale?: Locale\n): FilePathPatternFunction | false => {\n const output = configuration.compiler?.output as Fill | undefined;\n\n if (output === undefined || output === null) {\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n }\n\n if (output === false) return false;\n\n // Object per-locale record: look up the entry for the given locale\n if (typeof output === 'object' && typeof output !== 'function') {\n const entry = locale\n ? (output as Record<string, boolean | FilePathPattern>)[locale]\n : undefined;\n if (entry === false) return false;\n if (entry === undefined || entry === true) {\n throw new Error(\n `No output pattern configured for locale \"${locale}\" in compiler.output.`\n );\n }\n return typeof entry === 'string'\n ? (context: FilePathPatternContext) =>\n parseStringPattern(entry as string, context)\n : (entry as FilePathPatternFunction);\n }\n\n if (typeof output === 'string') {\n return (context: FilePathPatternContext) =>\n parseStringPattern(output, context);\n }\n\n if (typeof output === 'function') {\n return output as FilePathPatternFunction;\n }\n\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n};\n\nexport type ResolveContentFilePaths = {\n absolutePath: string;\n relativePath: string;\n isPerLocale: boolean;\n};\n\n/**\n * Resolves the paths for the content files associated with a component.\n * Checks for existing dictionaries first.\n */\nexport const resolveContentFilePaths = async (\n filePath: string,\n componentKey: string,\n configuration: IntlayerConfig,\n locale?: Locale,\n format?: Format\n): Promise<ResolveContentFilePaths> => {\n const { baseDir } = configuration.system;\n const { defaultLocale } = configuration.internationalization;\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration) ?? {};\n const existingDicts = unmergedDictionaries[componentKey]\n ?.filter(\n (dictionary) =>\n // Remove remote dictionaries (Fix: Check for !== instead of ===)\n dictionary.location !== 'remote'\n )\n .filter(\n (dictionary) =>\n // Check for first locale dictionary sorted by priority that include the targeted locale\n dictionary.locale === undefined ||\n dictionary.locale === (locale ?? defaultLocale)\n );\n\n const matchingExistingDict = format\n ? existingDicts?.find(\n (d) =>\n d.filePath && getFormatFromExtension(extname(d.filePath)) === format\n )\n : existingDicts?.[0];\n\n if (matchingExistingDict?.filePath) {\n const existingPath = matchingExistingDict.filePath;\n const resolvedAbsolutePath = resolve(baseDir, existingPath);\n\n assertPathWithin(resolvedAbsolutePath, baseDir);\n\n return {\n absolutePath: resolvedAbsolutePath,\n relativePath: relative(baseDir, resolvedAbsolutePath),\n isPerLocale: false,\n };\n }\n\n const output = configuration.compiler?.output as Fill | undefined;\n const isObjectOutput =\n typeof output === 'object' &&\n output !== null &&\n typeof output !== 'function';\n\n // Build shared context (used for both object and scalar output paths)\n const extension = extname(\n filePath\n ) as FilePathPatternContext['componentExtension'];\n const componentName = basename(filePath, extension);\n const uncapitalizedName =\n componentName.charAt(0).toLowerCase() + componentName.slice(1);\n const componentFormat = getFormatFromExtension(\n extension!\n ) as FilePathPatternContext['componentFormat'];\n\n const targetLocale = (locale ?? defaultLocale) as Locale;\n const targetFormatExtension = format\n ? getExtensionFromFormat(format)\n : undefined;\n const targetExtension = targetFormatExtension\n ? (configuration.content?.fileExtensions?.find((ext) =>\n ext.endsWith(targetFormatExtension)\n ) ?? targetFormatExtension)\n : (configuration.content?.fileExtensions?.[0] ?? '.ts');\n\n const context: FilePathPatternContext = {\n key: componentKey,\n componentDirPath: relative(baseDir, dirname(filePath)),\n componentFileName: componentName,\n fileName: uncapitalizedName,\n componentFormat,\n componentExtension: extension,\n format: format ?? componentFormat!,\n locale: targetLocale,\n extension: targetExtension,\n };\n\n // Object output: each locale has its own pattern → always per-locale\n if (isObjectOutput) {\n const pattern = getOutput(configuration, targetLocale);\n if (pattern === false) {\n throw new Error(\n `compiler.output is disabled for locale \"${targetLocale}\".`\n );\n }\n const rawAbsolutePath = await pattern(context);\n const absolutePath = resolveRelativePath(\n rawAbsolutePath,\n filePath,\n baseDir\n );\n return {\n absolutePath,\n relativePath: relative(baseDir, absolutePath),\n isPerLocale: true,\n };\n }\n\n // Scalar string/function output: detect per-locale via dummy locale probe\n const pattern = getOutput(configuration);\n if (pattern === false) {\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n }\n\n const rawAbsolutePath = await pattern({ ...context, locale: defaultLocale });\n\n // Apply the resolution rules\n const absolutePath = resolveRelativePath(rawAbsolutePath, filePath, baseDir);\n\n const localeIdentifier = '###########locale###########' as Locale;\n\n const rawPerLocalePath = await pattern({\n ...context,\n locale: localeIdentifier,\n });\n const isPerLocale = rawPerLocalePath.includes(localeIdentifier);\n\n return {\n absolutePath,\n relativePath: relative(baseDir, absolutePath),\n isPerLocale,\n };\n};\n\nexport type ExtractDictionaryInfoOptions = {\n configuration?: IntlayerConfig;\n};\n\n/**\n * Extracts the dictionary key and dictionary file path for a given component file.\n */\nexport const extractDictionaryInfo = async (\n filePath: string,\n fileText: string,\n configuration: IntlayerConfig,\n format?: Format\n): Promise<\n {\n dictionaryKey: string;\n } & ResolveContentFilePaths\n> => {\n const dictionaryKey = extractDictionaryKey(filePath, fileText);\n\n const resolvedPaths = await resolveContentFilePaths(\n filePath,\n dictionaryKey,\n configuration,\n undefined,\n format\n );\n\n return {\n dictionaryKey,\n ...resolvedPaths,\n };\n};\n"],"mappings":";;;;;;;;;;;;AAqBA,MAAa,aACX,eACA,WACoC;CACpC,MAAM,SAAS,cAAc,UAAU;CAEvC,IAAI,WAAW,UAAa,WAAW,MACrC,MAAM,IAAI,MACR,4CAAwCA,kCAAS,mBAAmBC,wBAAW,IAAI,EAAE,wBACvF;CAGF,IAAI,WAAW,OAAO,OAAO;CAG7B,IAAI,OAAO,WAAW,YAAY,OAAO,WAAW,YAAY;EAC9D,MAAM,QAAQ,SACT,OAAqD,UACtD;EACJ,IAAI,UAAU,OAAO,OAAO;EAC5B,IAAI,UAAU,UAAa,UAAU,MACnC,MAAM,IAAI,MACR,4CAA4C,OAAO,sBACrD;EAEF,OAAO,OAAO,UAAU,YAC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SAAS,gBAAgB,MAAM,QAC5C,IAAI,SAAS,qBAAqB,CACpC,KAAK,wBACJ,cAAc,SAAS,iBAAiB,MAAM;CAEnD,MAAM,UAAkC;EACtC,KAAK;EACL,sBAAkBF,oBAAS,aAASG,mBAAQ,QAAQ,CAAC;EACrD,mBAAmB;EACnB,UAAU;EACV;EACA,oBAAoB;EACpB,QAAQ,UAAU;EAClB,QAAQ;EACR,WAAW;CACb;CAGA,IAAI,gBAAgB;EAClB,MAAM,UAAU,UAAU,eAAe,YAAY;EACrD,IAAI,YAAY,OACd,MAAM,IAAI,MACR,2CAA2C,aAAa,GAC1D;EAEF,MAAM,kBAAkB,MAAM,QAAQ,OAAO;EAC7C,MAAM,mBAAeC,4CACnB,iBACA,UACA,OACF;EACA,OAAO;GACL;GACA,kBAAcJ,oBAAS,SAAS,YAAY;GAC5C,aAAa;EACf;CACF;CAGA,MAAM,UAAU,UAAU,aAAa;CACvC,IAAI,YAAY,OACd,MAAM,IAAI,MACR,4CAAwCP,kCAAS,mBAAmBC,wBAAW,IAAI,EAAE,wBACvF;CAGF,MAAM,kBAAkB,MAAM,QAAQ;EAAE,GAAG;EAAS,QAAQ;CAAc,CAAC;CAG3E,MAAM,mBAAeU,4CAAoB,iBAAiB,UAAU,OAAO;CAE3E,MAAM,mBAAmB;CAMzB,MAAM,eAAc,MAJW,QAAQ;EACrC,GAAG;EACH,QAAQ;CACV,CAAC,EACmC,CAAC,SAAS,gBAAgB;CAE9D,OAAO;EACL;EACA,kBAAcJ,oBAAS,SAAS,YAAY;EAC5C;CACF;AACF;;;;AASA,MAAa,wBAAwB,OACnC,UACA,UACA,eACA,WAKG;CACH,MAAM,gBAAgBK,uEAAqB,UAAU,QAAQ;CAU7D,OAAO;EACL;EACA,GAAG,MAVuB,wBAC1B,UACA,eACA,eACA,QACA,MACF;CAKA;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { extractDictionaryKey } from "./extractDictionaryKey.mjs";
2
- import { getFormatFromExtension, resolveRelativePath } from "@intlayer/engine/utils";
2
+ import { getExtensionFromFormat, getFormatFromExtension, resolveRelativePath } from "@intlayer/engine/utils";
3
3
  import { basename, dirname, extname, relative, resolve } from "node:path";
4
4
  import * as ANSIColors from "@intlayer/config/colors";
5
5
  import { colorize } from "@intlayer/config/logger";
@@ -25,12 +25,13 @@ const getOutput = (configuration, locale) => {
25
25
  * Resolves the paths for the content files associated with a component.
26
26
  * Checks for existing dictionaries first.
27
27
  */
28
- const resolveContentFilePaths = async (filePath, componentKey, configuration, locale) => {
28
+ const resolveContentFilePaths = async (filePath, componentKey, configuration, locale, format) => {
29
29
  const { baseDir } = configuration.system;
30
30
  const { defaultLocale } = configuration.internationalization;
31
31
  const existingDicts = (getUnmergedDictionaries(configuration) ?? {})[componentKey]?.filter((dictionary) => dictionary.location !== "remote").filter((dictionary) => dictionary.locale === void 0 || dictionary.locale === (locale ?? defaultLocale));
32
- if (existingDicts?.[0]?.filePath) {
33
- const existingPath = existingDicts[0].filePath;
32
+ const matchingExistingDict = format ? existingDicts?.find((d) => d.filePath && getFormatFromExtension(extname(d.filePath)) === format) : existingDicts?.[0];
33
+ if (matchingExistingDict?.filePath) {
34
+ const existingPath = matchingExistingDict.filePath;
34
35
  const resolvedAbsolutePath = resolve(baseDir, existingPath);
35
36
  assertPathWithin(resolvedAbsolutePath, baseDir);
36
37
  return {
@@ -46,6 +47,8 @@ const resolveContentFilePaths = async (filePath, componentKey, configuration, lo
46
47
  const uncapitalizedName = componentName.charAt(0).toLowerCase() + componentName.slice(1);
47
48
  const componentFormat = getFormatFromExtension(extension);
48
49
  const targetLocale = locale ?? defaultLocale;
50
+ const targetFormatExtension = format ? getExtensionFromFormat(format) : void 0;
51
+ const targetExtension = targetFormatExtension ? configuration.content?.fileExtensions?.find((ext) => ext.endsWith(targetFormatExtension)) ?? targetFormatExtension : configuration.content?.fileExtensions?.[0] ?? ".ts";
49
52
  const context = {
50
53
  key: componentKey,
51
54
  componentDirPath: relative(baseDir, dirname(filePath)),
@@ -53,9 +56,9 @@ const resolveContentFilePaths = async (filePath, componentKey, configuration, lo
53
56
  fileName: uncapitalizedName,
54
57
  componentFormat,
55
58
  componentExtension: extension,
56
- format: componentFormat,
59
+ format: format ?? componentFormat,
57
60
  locale: targetLocale,
58
- extension: configuration.content.fileExtensions[0] ?? ".ts"
61
+ extension: targetExtension
59
62
  };
60
63
  if (isObjectOutput) {
61
64
  const pattern = getOutput(configuration, targetLocale);
@@ -89,11 +92,11 @@ const resolveContentFilePaths = async (filePath, componentKey, configuration, lo
89
92
  /**
90
93
  * Extracts the dictionary key and dictionary file path for a given component file.
91
94
  */
92
- const extractDictionaryInfo = async (filePath, fileText, configuration) => {
95
+ const extractDictionaryInfo = async (filePath, fileText, configuration, format) => {
93
96
  const dictionaryKey = extractDictionaryKey(filePath, fileText);
94
97
  return {
95
98
  dictionaryKey,
96
- ...await resolveContentFilePaths(filePath, dictionaryKey, configuration)
99
+ ...await resolveContentFilePaths(filePath, dictionaryKey, configuration, void 0, format)
97
100
  };
98
101
  };
99
102
 
@@ -1 +1 @@
1
- {"version":3,"file":"extractDictionaryInfo.mjs","names":[],"sources":["../../../../src/extractContent/utils/extractDictionaryInfo.ts"],"sourcesContent":["import { basename, dirname, extname, relative, resolve } from 'node:path';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize } from '@intlayer/config/logger';\nimport { assertPathWithin, parseStringPattern } from '@intlayer/config/utils';\nimport { getUnmergedDictionaries } from '@intlayer/dictionaries-entry/unmerged';\nimport {\n getFormatFromExtension,\n resolveRelativePath,\n} from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Fill } from '@intlayer/types/dictionary';\nimport type {\n FilePathPattern,\n FilePathPatternContext,\n FilePathPatternFunction,\n} from '@intlayer/types/filePathPattern';\nimport { extractDictionaryKey } from './extractDictionaryKey';\n\nexport const getOutput = (\n configuration: IntlayerConfig,\n locale?: Locale\n): FilePathPatternFunction | false => {\n const output = configuration.compiler?.output as Fill | undefined;\n\n if (output === undefined || output === null) {\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n }\n\n if (output === false) return false;\n\n // Object per-locale record: look up the entry for the given locale\n if (typeof output === 'object' && typeof output !== 'function') {\n const entry = locale\n ? (output as Record<string, boolean | FilePathPattern>)[locale]\n : undefined;\n if (entry === false) return false;\n if (entry === undefined || entry === true) {\n throw new Error(\n `No output pattern configured for locale \"${locale}\" in compiler.output.`\n );\n }\n return typeof entry === 'string'\n ? (context: FilePathPatternContext) =>\n parseStringPattern(entry as string, context)\n : (entry as FilePathPatternFunction);\n }\n\n if (typeof output === 'string') {\n return (context: FilePathPatternContext) =>\n parseStringPattern(output, context);\n }\n\n if (typeof output === 'function') {\n return output as FilePathPatternFunction;\n }\n\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n};\n\nexport type ResolveContentFilePaths = {\n absolutePath: string;\n relativePath: string;\n isPerLocale: boolean;\n};\n\n/**\n * Resolves the paths for the content files associated with a component.\n * Checks for existing dictionaries first.\n */\nexport const resolveContentFilePaths = async (\n filePath: string,\n componentKey: string,\n configuration: IntlayerConfig,\n locale?: Locale\n): Promise<ResolveContentFilePaths> => {\n const { baseDir } = configuration.system;\n const { defaultLocale } = configuration.internationalization;\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration) ?? {};\n const existingDicts = unmergedDictionaries[componentKey]\n ?.filter(\n (dictionary) =>\n // Remove remote dictionaries (Fix: Check for !== instead of ===)\n dictionary.location !== 'remote'\n )\n .filter(\n (dictionary) =>\n // Check for first locale dictionary sorted by priority that include the targeted locale\n dictionary.locale === undefined ||\n dictionary.locale === (locale ?? defaultLocale)\n );\n\n if (existingDicts?.[0]?.filePath) {\n const existingPath = existingDicts[0].filePath;\n const resolvedAbsolutePath = resolve(baseDir, existingPath);\n\n assertPathWithin(resolvedAbsolutePath, baseDir);\n\n return {\n absolutePath: resolvedAbsolutePath,\n relativePath: relative(baseDir, resolvedAbsolutePath),\n isPerLocale: false,\n };\n }\n\n const output = configuration.compiler?.output as Fill | undefined;\n const isObjectOutput =\n typeof output === 'object' &&\n output !== null &&\n typeof output !== 'function';\n\n // Build shared context (used for both object and scalar output paths)\n const extension = extname(\n filePath\n ) as FilePathPatternContext['componentExtension'];\n const componentName = basename(filePath, extension);\n const uncapitalizedName =\n componentName.charAt(0).toLowerCase() + componentName.slice(1);\n const componentFormat = getFormatFromExtension(\n extension!\n ) as FilePathPatternContext['componentFormat'];\n\n const targetLocale = (locale ?? defaultLocale) as Locale;\n\n const context: FilePathPatternContext = {\n key: componentKey,\n componentDirPath: relative(baseDir, dirname(filePath)),\n componentFileName: componentName,\n fileName: uncapitalizedName,\n componentFormat,\n componentExtension: extension,\n format: componentFormat!,\n locale: targetLocale,\n extension: configuration.content.fileExtensions[0] ?? '.ts',\n };\n\n // Object output: each locale has its own pattern → always per-locale\n if (isObjectOutput) {\n const pattern = getOutput(configuration, targetLocale);\n if (pattern === false) {\n throw new Error(\n `compiler.output is disabled for locale \"${targetLocale}\".`\n );\n }\n const rawAbsolutePath = await pattern(context);\n const absolutePath = resolveRelativePath(\n rawAbsolutePath,\n filePath,\n baseDir\n );\n return {\n absolutePath,\n relativePath: relative(baseDir, absolutePath),\n isPerLocale: true,\n };\n }\n\n // Scalar string/function output: detect per-locale via dummy locale probe\n const pattern = getOutput(configuration);\n if (pattern === false) {\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n }\n\n const rawAbsolutePath = await pattern({ ...context, locale: defaultLocale });\n\n // Apply the resolution rules\n const absolutePath = resolveRelativePath(rawAbsolutePath, filePath, baseDir);\n\n const localeIdentifier = '###########locale###########' as Locale;\n\n const rawPerLocalePath = await pattern({\n ...context,\n locale: localeIdentifier,\n });\n const isPerLocale = rawPerLocalePath.includes(localeIdentifier);\n\n return {\n absolutePath,\n relativePath: relative(baseDir, absolutePath),\n isPerLocale,\n };\n};\n\nexport type ExtractDictionaryInfoOptions = {\n configuration?: IntlayerConfig;\n};\n\n/**\n * Extracts the dictionary key and dictionary file path for a given component file.\n */\nexport const extractDictionaryInfo = async (\n filePath: string,\n fileText: string,\n configuration: IntlayerConfig\n): Promise<\n {\n dictionaryKey: string;\n } & ResolveContentFilePaths\n> => {\n const dictionaryKey = extractDictionaryKey(filePath, fileText);\n\n const resolvedPaths = await resolveContentFilePaths(\n filePath,\n dictionaryKey,\n configuration\n );\n\n return {\n dictionaryKey,\n ...resolvedPaths,\n };\n};\n"],"mappings":";;;;;;;;;AAmBA,MAAa,aACX,eACA,WACoC;CACpC,MAAM,SAAS,cAAc,UAAU;CAEvC,IAAI,WAAW,UAAa,WAAW,MACrC,MAAM,IAAI,MACR,wCAAwC,SAAS,mBAAmB,WAAW,IAAI,EAAE,wBACvF;CAGF,IAAI,WAAW,OAAO,OAAO;CAG7B,IAAI,OAAO,WAAW,YAAY,OAAO,WAAW,YAAY;EAC9D,MAAM,QAAQ,SACT,OAAqD,UACtD;EACJ,IAAI,UAAU,OAAO,OAAO;EAC5B,IAAI,UAAU,UAAa,UAAU,MACnC,MAAM,IAAI,MACR,4CAA4C,OAAO,sBACrD;EAEF,OAAO,OAAO,UAAU,YACnB,YACC,mBAAmB,OAAiB,OAAO,IAC5C;CACP;CAEA,IAAI,OAAO,WAAW,UACpB,QAAQ,YACN,mBAAmB,QAAQ,OAAO;CAGtC,IAAI,OAAO,WAAW,YACpB,OAAO;CAGT,MAAM,IAAI,MACR,wCAAwC,SAAS,mBAAmB,WAAW,IAAI,EAAE,wBACvF;AACF;;;;;AAYA,MAAa,0BAA0B,OACrC,UACA,cACA,eACA,WACqC;CACrC,MAAM,EAAE,YAAY,cAAc;CAClC,MAAM,EAAE,kBAAkB,cAAc;CAGxC,MAAM,iBADuB,wBAAwB,aAAa,KAAK,CAAC,EAC9B,CAAC,aAAa,EACpD,QACC,e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QAAQ;CAAc,CAAC;CAG3E,MAAM,eAAe,oBAAoB,iBAAiB,UAAU,OAAO;CAE3E,MAAM,mBAAmB;CAMzB,MAAM,eAAc,MAJW,QAAQ;EACrC,GAAG;EACH,QAAQ;CACV,CAAC,EACmC,CAAC,SAAS,gBAAgB;CAE9D,OAAO;EACL;EACA,cAAc,SAAS,SAAS,YAAY;EAC5C;CACF;AACF;;;;AASA,MAAa,wBAAwB,OACnC,UACA,UACA,kBAKG;CACH,MAAM,gBAAgB,qBAAqB,UAAU,QAAQ;CAQ7D,OAAO;EACL;EACA,GAAG,MARuB,wBAC1B,UACA,eACA,aACF;CAKA;AACF"}
1
+ {"version":3,"file":"extractDictionaryInfo.mjs","names":[],"sources":["../../../../src/extractContent/utils/extractDictionaryInfo.ts"],"sourcesContent":["import { basename, dirname, extname, relative, resolve } from 'node:path';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize } from '@intlayer/config/logger';\nimport { assertPathWithin, parseStringPattern } from '@intlayer/config/utils';\nimport { getUnmergedDictionaries } from '@intlayer/dictionaries-entry/unmerged';\nimport {\n type Format,\n getExtensionFromFormat,\n getFormatFromExtension,\n resolveRelativePath,\n} from '@intlayer/engine/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Fill } from '@intlayer/types/dictionary';\nimport type {\n FilePathPattern,\n FilePathPatternContext,\n FilePathPatternFunction,\n} from '@intlayer/types/filePathPattern';\nimport { extractDictionaryKey } from './extractDictionaryKey';\n\nexport const getOutput = (\n configuration: IntlayerConfig,\n locale?: Locale\n): FilePathPatternFunction | false => {\n const output = configuration.compiler?.output as Fill | undefined;\n\n if (output === undefined || output === null) {\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n }\n\n if (output === false) return false;\n\n // Object per-locale record: look up the entry for the given locale\n if (typeof output === 'object' && typeof output !== 'function') {\n const entry = locale\n ? (output as Record<string, boolean | FilePathPattern>)[locale]\n : undefined;\n if (entry === false) return false;\n if (entry === undefined || entry === true) {\n throw new Error(\n `No output pattern configured for locale \"${locale}\" in compiler.output.`\n );\n }\n return typeof entry === 'string'\n ? (context: FilePathPatternContext) =>\n parseStringPattern(entry as string, context)\n : (entry as FilePathPatternFunction);\n }\n\n if (typeof output === 'string') {\n return (context: FilePathPatternContext) =>\n parseStringPattern(output, context);\n }\n\n if (typeof output === 'function') {\n return output as FilePathPatternFunction;\n }\n\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n};\n\nexport type ResolveContentFilePaths = {\n absolutePath: string;\n relativePath: string;\n isPerLocale: boolean;\n};\n\n/**\n * Resolves the paths for the content files associated with a component.\n * Checks for existing dictionaries first.\n */\nexport const resolveContentFilePaths = async (\n filePath: string,\n componentKey: string,\n configuration: IntlayerConfig,\n locale?: Locale,\n format?: Format\n): Promise<ResolveContentFilePaths> => {\n const { baseDir } = configuration.system;\n const { defaultLocale } = configuration.internationalization;\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration) ?? {};\n const existingDicts = unmergedDictionaries[componentKey]\n ?.filter(\n (dictionary) =>\n // Remove remote dictionaries (Fix: Check for !== instead of ===)\n dictionary.location !== 'remote'\n )\n .filter(\n (dictionary) =>\n // Check for first locale dictionary sorted by priority that include the targeted locale\n dictionary.locale === undefined ||\n dictionary.locale === (locale ?? defaultLocale)\n );\n\n const matchingExistingDict = format\n ? existingDicts?.find(\n (d) =>\n d.filePath && getFormatFromExtension(extname(d.filePath)) === format\n )\n : existingDicts?.[0];\n\n if (matchingExistingDict?.filePath) {\n const existingPath = matchingExistingDict.filePath;\n const resolvedAbsolutePath = resolve(baseDir, existingPath);\n\n assertPathWithin(resolvedAbsolutePath, baseDir);\n\n return {\n absolutePath: resolvedAbsolutePath,\n relativePath: relative(baseDir, resolvedAbsolutePath),\n isPerLocale: false,\n };\n }\n\n const output = configuration.compiler?.output as Fill | undefined;\n const isObjectOutput =\n typeof output === 'object' &&\n output !== null &&\n typeof output !== 'function';\n\n // Build shared context (used for both object and scalar output paths)\n const extension = extname(\n filePath\n ) as FilePathPatternContext['componentExtension'];\n const componentName = basename(filePath, extension);\n const uncapitalizedName =\n componentName.charAt(0).toLowerCase() + componentName.slice(1);\n const componentFormat = getFormatFromExtension(\n extension!\n ) as FilePathPatternContext['componentFormat'];\n\n const targetLocale = (locale ?? defaultLocale) as Locale;\n const targetFormatExtension = format\n ? getExtensionFromFormat(format)\n : undefined;\n const targetExtension = targetFormatExtension\n ? (configuration.content?.fileExtensions?.find((ext) =>\n ext.endsWith(targetFormatExtension)\n ) ?? targetFormatExtension)\n : (configuration.content?.fileExtensions?.[0] ?? '.ts');\n\n const context: FilePathPatternContext = {\n key: componentKey,\n componentDirPath: relative(baseDir, dirname(filePath)),\n componentFileName: componentName,\n fileName: uncapitalizedName,\n componentFormat,\n componentExtension: extension,\n format: format ?? componentFormat!,\n locale: targetLocale,\n extension: targetExtension,\n };\n\n // Object output: each locale has its own pattern → always per-locale\n if (isObjectOutput) {\n const pattern = getOutput(configuration, targetLocale);\n if (pattern === false) {\n throw new Error(\n `compiler.output is disabled for locale \"${targetLocale}\".`\n );\n }\n const rawAbsolutePath = await pattern(context);\n const absolutePath = resolveRelativePath(\n rawAbsolutePath,\n filePath,\n baseDir\n );\n return {\n absolutePath,\n relativePath: relative(baseDir, absolutePath),\n isPerLocale: true,\n };\n }\n\n // Scalar string/function output: detect per-locale via dummy locale probe\n const pattern = getOutput(configuration);\n if (pattern === false) {\n throw new Error(\n `No output configuration found. Add a ${colorize('compiler.output', ANSIColors.BLUE)} in your configuration.`\n );\n }\n\n const rawAbsolutePath = await pattern({ ...context, locale: defaultLocale });\n\n // Apply the resolution rules\n const absolutePath = resolveRelativePath(rawAbsolutePath, filePath, baseDir);\n\n const localeIdentifier = '###########locale###########' as Locale;\n\n const rawPerLocalePath = await pattern({\n ...context,\n locale: localeIdentifier,\n });\n const isPerLocale = rawPerLocalePath.includes(localeIdentifier);\n\n return {\n absolutePath,\n relativePath: relative(baseDir, absolutePath),\n isPerLocale,\n };\n};\n\nexport type ExtractDictionaryInfoOptions = {\n configuration?: IntlayerConfig;\n};\n\n/**\n * Extracts the dictionary key and dictionary file path for a given component file.\n */\nexport const extractDictionaryInfo = async (\n filePath: string,\n fileText: string,\n configuration: IntlayerConfig,\n format?: Format\n): Promise<\n {\n dictionaryKey: string;\n } & ResolveContentFilePaths\n> => {\n const dictionaryKey = extractDictionaryKey(filePath, fileText);\n\n const resolvedPaths = await resolveContentFilePaths(\n filePath,\n dictionaryKey,\n configuration,\n undefined,\n format\n );\n\n return {\n dictionaryKey,\n ...resolvedPaths,\n };\n};\n"],"mappings":";;;;;;;;;AAqBA,MAAa,aACX,eACA,WACoC;CACpC,MAAM,SAAS,cAAc,UAAU;CAEvC,IAAI,WAAW,UAAa,WAAW,MACrC,MAAM,IAAI,MACR,wCAAwC,SAAS,mBAAmB,WAAW,IAAI,EAAE,wBACvF;CAGF,IAAI,WAAW,OAAO,OAAO;CAG7B,IAAI,OAAO,WAAW,YAAY,OAAO,WAAW,YAAY;EAC9D,MAAM,QAAQ,SACT,OAAqD,UACtD;EACJ,IAAI,UAAU,OAAO,OAAO;EAC5B,IAAI,UAAU,UAAa,UAAU,MACnC,MAAM,IAAI,MACR,4CAA4C,OAAO,sBACrD;EAEF,OAAO,OAAO,UAAU,YACnB,YACC,mBAAmB,OAAiB,OAAO,IAC5C;CACP;CAEA,IAAI,OAAO,WAAW,UACpB,QAAQ,YACN,mBAAmB,QAAQ,OAAO;CAGtC,IAAI,OAAO,WAAW,YACpB,OAAO;CAGT,MAAM,IAAI,MACR,wCAAwC,SAAS,mBAAmB,WAAW,IAAI,EAAE,wBACvF;AACF;;;;;AAYA,MAAa,0BAA0B,OACrC,UACA,cACA,eACA,QACA,WACqC;CACrC,MAAM,EAAE,YAAY,cAAc;CAClC,MAAM,EAAE,kBAAkB,cAAc;CAGxC,MAAM,iBAD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F,MAAM,kBAAkB,MAAM,QAAQ,OAAO;EAC7C,MAAM,eAAe,oBACnB,iBACA,UACA,OACF;EACA,OAAO;GACL;GACA,cAAc,SAAS,SAAS,YAAY;GAC5C,aAAa;EACf;CACF;CAGA,MAAM,UAAU,UAAU,aAAa;CACvC,IAAI,YAAY,OACd,MAAM,IAAI,MACR,wCAAwC,SAAS,mBAAmB,WAAW,IAAI,EAAE,wBACvF;CAGF,MAAM,kBAAkB,MAAM,QAAQ;EAAE,GAAG;EAAS,QAAQ;CAAc,CAAC;CAG3E,MAAM,eAAe,oBAAoB,iBAAiB,UAAU,OAAO;CAE3E,MAAM,mBAAmB;CAMzB,MAAM,eAAc,MAJW,QAAQ;EACrC,GAAG;EACH,QAAQ;CACV,CAAC,EACmC,CAAC,SAAS,gBAAgB;CAE9D,OAAO;EACL;EACA,cAAc,SAAS,SAAS,YAAY;EAC5C;CACF;AACF;;;;AASA,MAAa,wBAAwB,OACnC,UACA,UACA,eACA,WAKG;CACH,MAAM,gBAAgB,qBAAqB,UAAU,QAAQ;CAU7D,OAAO;EACL;EACA,GAAG,MAVuB,wBAC1B,UACA,eACA,eACA,QACA,MACF;CAKA;AACF"}
@@ -1,6 +1,7 @@
1
1
  import { Locale } from "@intlayer/types/allLocales";
2
2
  import { IntlayerConfig } from "@intlayer/types/config";
3
3
  import { FilePathPatternFunction } from "@intlayer/types/filePathPattern";
4
+ import { Format } from "@intlayer/engine/utils";
4
5
  //#region src/extractContent/utils/extractDictionaryInfo.d.ts
5
6
  export declare const getOutput: (configuration: IntlayerConfig, locale?: Locale) => FilePathPatternFunction | false;
6
7
  export type ResolveContentFilePaths = {
@@ -12,14 +13,14 @@ export type ResolveContentFilePaths = {
12
13
  * Resolves the paths for the content files associated with a component.
13
14
  * Checks for existing dictionaries first.
14
15
  */
15
- export declare const resolveContentFilePaths: (filePath: string, componentKey: string, configuration: IntlayerConfig, locale?: Locale) => Promise<ResolveContentFilePaths>;
16
+ export declare const resolveContentFilePaths: (filePath: string, componentKey: string, configuration: IntlayerConfig, locale?: Locale, format?: Format) => Promise<ResolveContentFilePaths>;
16
17
  export type ExtractDictionaryInfoOptions = {
17
18
  configuration?: IntlayerConfig;
18
19
  };
19
20
  /**
20
21
  * Extracts the dictionary key and dictionary file path for a given component file.
21
22
  */
22
- export declare const extractDictionaryInfo: (filePath: string, fileText: string, configuration: IntlayerConfig) => Promise<{
23
+ export declare const extractDictionaryInfo: (filePath: string, fileText: string, configuration: IntlayerConfig, format?: Format) => Promise<{
23
24
  dictionaryKey: string;
24
25
  } & ResolveContentFilePaths>;
25
26
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"extractDictionaryInfo.d.ts","names":[],"sources":["../../../../src/extractContent/utils/extractDictionaryInfo.ts"],"mappings":";;;;qBAmBa,YAAS,eACL,gBAAc,SACpB,WACR;YA0CS;EACV;EACA;EACA;;;;;;qBAOW,0BAAuB,kBAClB,sBACI,eACL,gBAAc,SACpB,WACR,QAAQ;YA+GC;EACV,gBAAgB;;;;;qBAML,wBAAqB,kBAChB,kBACA,eACD,mBACd;EAEC;IACE"}
1
+ {"version":3,"file":"extractDictionaryInfo.d.ts","names":[],"sources":["../../../../src/extractContent/utils/extractDictionaryInfo.ts"],"mappings":";;;;;qBAqBa,YAAS,eACL,gBAAc,SACpB,WACR;YA0CS;EACV;EACA;EACA;;;;;;qBAOW,0BAAuB,kBAClB,sBACI,eACL,gBAAc,SACpB,QAAM,SACN,WACR,QAAQ;YA8HC;EACV,gBAAgB;;;;;qBAML,wBAAqB,kBAChB,kBACA,eACD,gBAAc,SACpB,WACR;EAEC;IACE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/babel",
3
- "version": "9.5.12",
3
+ "version": "9.7.0",
4
4
  "private": false,
5
5
  "description": "A Babel plugin for Intlayer that transforms declaration files and provides internationalization features during the build process according to the Intlayer configuration.",
6
6
  "keywords": [
@@ -84,36 +84,36 @@
84
84
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
85
85
  },
86
86
  "dependencies": {
87
- "@babel/core": "8.0.5",
88
- "@babel/generator": "8.0.5",
89
- "@babel/parser": "8.0.5",
87
+ "@babel/core": "8.0.6",
88
+ "@babel/generator": "8.0.6",
89
+ "@babel/parser": "7.29.9",
90
90
  "@babel/plugin-syntax-jsx": "8.0.1",
91
- "@babel/traverse": "8.0.5",
92
- "@babel/types": "8.0.5",
93
- "@intlayer/config": "9.5.12",
94
- "@intlayer/core": "9.5.12",
95
- "@intlayer/dictionaries-entry": "9.5.12",
96
- "@intlayer/engine": "9.5.12",
97
- "@intlayer/types": "9.5.12"
91
+ "@babel/traverse": "8.0.6",
92
+ "@babel/types": "8.0.6",
93
+ "@intlayer/config": "9.7.0",
94
+ "@intlayer/core": "9.7.0",
95
+ "@intlayer/dictionaries-entry": "9.7.0",
96
+ "@intlayer/engine": "9.7.0",
97
+ "@intlayer/types": "9.7.0"
98
98
  },
99
99
  "devDependencies": {
100
100
  "@babel/plugin-syntax-jsx": "8.0.1",
101
101
  "@types/babel__core": "7.20.5",
102
102
  "@types/babel__generator": "7.27.0",
103
103
  "@types/babel__traverse": "7.28.0",
104
- "@types/node": "^22",
104
+ "@types/node": "^26",
105
105
  "@utils/ts-config": "1.0.4",
106
106
  "@utils/ts-config-types": "1.0.4",
107
107
  "@utils/tsdown-config": "1.0.4",
108
- "@vitejs/plugin-react": "6.1.1",
108
+ "@vitejs/plugin-react": "6.1.2",
109
109
  "rimraf": "6.1.3",
110
110
  "tsdown": "0.23.0",
111
111
  "typescript": "7.0.2",
112
- "vitest": "5.0.2"
112
+ "vitest": "5.0.3"
113
113
  },
114
114
  "peerDependencies": {
115
- "@intlayer/svelte-compiler": "9.5.12",
116
- "@intlayer/vue-compiler": "9.5.12"
115
+ "@intlayer/svelte-compiler": "9.7.0",
116
+ "@intlayer/vue-compiler": "9.7.0"
117
117
  },
118
118
  "peerDependenciesMeta": {
119
119
  "@intlayer/svelte-compiler": {