@intlayer/babel 8.4.0-canary.0 → 8.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/cjs/babel-plugin-intlayer-extract.cjs +1 -1
  2. package/dist/cjs/babel-plugin-intlayer-extract.cjs.map +1 -1
  3. package/dist/cjs/babel-plugin-intlayer-optimize.cjs +1 -1
  4. package/dist/cjs/babel-plugin-intlayer-optimize.cjs.map +1 -1
  5. package/dist/cjs/{_virtual/_rolldown/runtime.cjs → chunk-Bmb41Sf3.cjs} +1 -1
  6. package/dist/cjs/extractContent/babelProcessor.cjs +1 -1
  7. package/dist/cjs/extractContent/babelProcessor.cjs.map +1 -1
  8. package/dist/cjs/extractContent/contentWriter.cjs +1 -1
  9. package/dist/cjs/extractContent/contentWriter.cjs.map +1 -1
  10. package/dist/cjs/extractContent/extractContent.cjs +1 -1
  11. package/dist/cjs/extractContent/extractContent.cjs.map +1 -1
  12. package/dist/cjs/extractContent/processTsxFile.cjs +1 -1
  13. package/dist/cjs/extractContent/processTsxFile.cjs.map +1 -1
  14. package/dist/cjs/extractContent/utils/detectPackageName.cjs +1 -1
  15. package/dist/cjs/extractContent/utils/detectPackageName.cjs.map +1 -1
  16. package/dist/cjs/extractContent/utils/extractDictionaryInfo.cjs +1 -1
  17. package/dist/cjs/extractContent/utils/extractDictionaryInfo.cjs.map +1 -1
  18. package/dist/cjs/extractContent/utils/extractDictionaryKey.cjs +1 -1
  19. package/dist/cjs/extractContent/utils/extractDictionaryKey.cjs.map +1 -1
  20. package/dist/cjs/extractContent/utils/getComponentName.cjs +1 -1
  21. package/dist/cjs/extractContent/utils/getComponentName.cjs.map +1 -1
  22. package/dist/cjs/extractContent/utils/getExistingIntlayerInfo.cjs +1 -1
  23. package/dist/cjs/extractContent/utils/getExistingIntlayerInfo.cjs.map +1 -1
  24. package/dist/cjs/extractContent/utils/resolveDictionaryKey.cjs +1 -1
  25. package/dist/cjs/extractContent/utils/resolveDictionaryKey.cjs.map +1 -1
  26. package/dist/cjs/getExtractPluginOptions.cjs +1 -1
  27. package/dist/cjs/getExtractPluginOptions.cjs.map +1 -1
  28. package/dist/cjs/getOptimizePluginOptions.cjs +1 -1
  29. package/dist/cjs/getOptimizePluginOptions.cjs.map +1 -1
  30. package/dist/cjs/index.cjs +1 -1
  31. package/dist/esm/getOptimizePluginOptions-BAFPfVq5.mjs +2 -0
  32. package/dist/esm/getOptimizePluginOptions-BAFPfVq5.mjs.map +1 -0
  33. package/dist/esm/getOptimizePluginOptions.mjs +1 -2
  34. package/dist/esm/index.mjs +1 -1
  35. package/dist/types/babel-plugin-intlayer-extract.d.ts +1 -1
  36. package/dist/types/constants-BLArAqsA.d.ts +20 -0
  37. package/dist/types/constants-BLArAqsA.d.ts.map +1 -0
  38. package/dist/types/contentWriter-I2Ch5yQY.d.ts +36 -0
  39. package/dist/types/contentWriter-I2Ch5yQY.d.ts.map +1 -0
  40. package/dist/types/detectPackageName-C0TfbHa3.d.ts +10 -0
  41. package/dist/types/detectPackageName-C0TfbHa3.d.ts.map +1 -0
  42. package/dist/types/extractContent/contentWriter.d.ts +2 -36
  43. package/dist/types/extractContent/extractContent.d.ts +2 -37
  44. package/dist/types/extractContent/index.d.ts +8 -8
  45. package/dist/types/extractContent/processTsxFile.d.ts +1 -1
  46. package/dist/types/extractContent/processTsxFile.d.ts.map +1 -1
  47. package/dist/types/extractContent/utils/constants.d.ts +2 -20
  48. package/dist/types/extractContent/utils/detectPackageName.d.ts +2 -10
  49. package/dist/types/extractContent/utils/extractDictionaryInfo.d.ts +2 -28
  50. package/dist/types/extractContent/utils/extractDictionaryKey.d.ts +2 -11
  51. package/dist/types/extractContent/utils/generateKey.d.ts +2 -5
  52. package/dist/types/extractContent/utils/getComponentName.d.ts +2 -10
  53. package/dist/types/extractContent/utils/getExistingIntlayerInfo.d.ts +2 -19
  54. package/dist/types/extractContent/utils/getOrGenerateKey.d.ts +2 -8
  55. package/dist/types/extractContent/utils/index.d.ts +10 -10
  56. package/dist/types/extractContent/utils/resolveDictionaryKey.d.ts +2 -12
  57. package/dist/types/extractContent/utils/shouldExtract.d.ts +2 -14
  58. package/dist/types/extractContent-AFk68B7L.d.ts +37 -0
  59. package/dist/types/extractContent-AFk68B7L.d.ts.map +1 -0
  60. package/dist/types/extractDictionaryInfo-5GLZsA_I.d.ts +28 -0
  61. package/dist/types/extractDictionaryInfo-5GLZsA_I.d.ts.map +1 -0
  62. package/dist/types/extractDictionaryKey-CHgfwRo6.d.ts +11 -0
  63. package/dist/types/extractDictionaryKey-CHgfwRo6.d.ts.map +1 -0
  64. package/dist/types/generateKey-Cgdh6seq.d.ts +5 -0
  65. package/dist/types/generateKey-Cgdh6seq.d.ts.map +1 -0
  66. package/dist/types/getComponentName-DGlmJa-F.d.ts +10 -0
  67. package/dist/types/getComponentName-DGlmJa-F.d.ts.map +1 -0
  68. package/dist/types/getExistingIntlayerInfo-Cy6Vpcfb.d.ts +19 -0
  69. package/dist/types/getExistingIntlayerInfo-Cy6Vpcfb.d.ts.map +1 -0
  70. package/dist/types/getOrGenerateKey-DtIR0WeU.d.ts +8 -0
  71. package/dist/types/getOrGenerateKey-DtIR0WeU.d.ts.map +1 -0
  72. package/dist/types/index-DK_kKFOF.d.ts +1 -0
  73. package/dist/types/index.d.ts +8 -8
  74. package/dist/types/resolveDictionaryKey-CcbieIfX.d.ts +12 -0
  75. package/dist/types/resolveDictionaryKey-CcbieIfX.d.ts.map +1 -0
  76. package/dist/types/shouldExtract-BRaeB9eg.d.ts +14 -0
  77. package/dist/types/shouldExtract-BRaeB9eg.d.ts.map +1 -0
  78. package/package.json +9 -9
  79. package/dist/esm/_virtual/_rolldown/runtime.mjs +0 -1
  80. package/dist/esm/getOptimizePluginOptions.mjs.map +0 -1
  81. package/dist/types/extractContent/contentWriter.d.ts.map +0 -1
  82. package/dist/types/extractContent/extractContent.d.ts.map +0 -1
  83. package/dist/types/extractContent/utils/constants.d.ts.map +0 -1
  84. package/dist/types/extractContent/utils/detectPackageName.d.ts.map +0 -1
  85. package/dist/types/extractContent/utils/extractDictionaryInfo.d.ts.map +0 -1
  86. package/dist/types/extractContent/utils/extractDictionaryKey.d.ts.map +0 -1
  87. package/dist/types/extractContent/utils/generateKey.d.ts.map +0 -1
  88. package/dist/types/extractContent/utils/getComponentName.d.ts.map +0 -1
  89. package/dist/types/extractContent/utils/getExistingIntlayerInfo.d.ts.map +0 -1
  90. package/dist/types/extractContent/utils/getOrGenerateKey.d.ts.map +0 -1
  91. package/dist/types/extractContent/utils/resolveDictionaryKey.d.ts.map +0 -1
  92. package/dist/types/extractContent/utils/shouldExtract.d.ts.map +0 -1
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./extractContent/utils/detectPackageName.cjs`),t=require(`./extractContent/extractContent.cjs`);let n=require(`@intlayer/config/logger`),r=require(`node:path`),i=require(`@babel/parser`);const a=a=>({name:`babel-plugin-intlayer-extract`,visitor:{Program:{enter(a,o){let s=o.opts;if(s.enabled===!1)return;let c=o.file.opts.filename;if(!c||s.filesList&&!s.filesList.includes(c))return;let l=o.file.code??``;if(!l)return;let u=(0,n.getAppLogger)(s.configuration),d=s.packageName??e.detectPackageName(c),{saveComponents:f}=s.configuration.compiler,p=t.extractContentSync(c,d,{configuration:s.configuration,code:l,onExtract:e=>{s.onExtract&&s.onExtract({dictionaryKey:e.key,filePath:c,content:e.content,locale:s.configuration.internationalization.defaultLocale})},declarationOnly:!f});if(!p)return;let{transformedCode:m}=p;if(m)try{let e=(0,i.parse)(m,{sourceType:`module`,plugins:[`jsx`,`typescript`]});a.node.body=e.program.body,a.node.directives=e.program.directives,u(`${(0,n.colorize)(`Compiler:`,n.ANSIColors.GREY_DARK)} Extracted content from ${(0,n.colorizePath)((0,r.relative)(s.configuration.system.baseDir,c))}`,{level:`debug`})}catch(e){u([`Failed to parse transformed code for ${(0,n.colorizePath)((0,r.relative)(s.configuration.system.baseDir,c))}:`,e],{level:`error`})}}}}});exports.intlayerExtractBabelPlugin=a;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunk-Bmb41Sf3.cjs`);const e=require(`./extractContent/utils/detectPackageName.cjs`),t=require(`./extractContent/extractContent.cjs`);let n=require(`@intlayer/config/logger`),r=require(`node:path`),i=require(`@babel/parser`);const a=a=>({name:`babel-plugin-intlayer-extract`,visitor:{Program:{enter(a,o){let s=o.opts;if(s.enabled===!1)return;let c=o.file.opts.filename;if(!c||s.filesList&&!s.filesList.includes(c))return;let l=o.file.code??``;if(!l)return;let u=(0,n.getAppLogger)(s.configuration),d=s.packageName??e.detectPackageName(c),{saveComponents:f}=s.configuration.compiler,p=t.extractContentSync(c,d,{configuration:s.configuration,code:l,onExtract:e=>{s.onExtract&&s.onExtract({dictionaryKey:e.key,filePath:c,content:e.content,locale:s.configuration.internationalization.defaultLocale})},declarationOnly:!f});if(!p)return;let{transformedCode:m}=p;if(m)try{let e=(0,i.parse)(m,{sourceType:`module`,plugins:[`jsx`,`typescript`]});a.node.body=e.program.body,a.node.directives=e.program.directives,u(`${(0,n.colorize)(`Compiler:`,n.ANSIColors.GREY_DARK)} Extracted content from ${(0,n.colorizePath)((0,r.relative)(s.configuration.system.baseDir,c))}`,{level:`debug`})}catch(e){u([`Failed to parse transformed code for ${(0,n.colorizePath)((0,r.relative)(s.configuration.system.baseDir,c))}:`,e],{level:`error`})}}}}});exports.intlayerExtractBabelPlugin=a;
2
2
  //# sourceMappingURL=babel-plugin-intlayer-extract.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-extract.cjs","names":["detectPackageName","extractContentSync","ANSIColors"],"sources":["../../src/babel-plugin-intlayer-extract.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport type { PluginObj, PluginPass } from '@babel/core';\nimport { parse } from '@babel/parser';\nimport type * as BabelTypes from '@babel/types';\nimport {\n ANSIColors,\n colorize,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { FilePathPattern } from '@intlayer/types/filePathPattern';\nimport { extractContentSync } from './extractContent/extractContent';\nimport type { PackageName } from './extractContent/utils/constants';\nimport { detectPackageName } from './extractContent/utils/detectPackageName';\n\nexport type ExtractResult = {\n dictionaryKey: string;\n filePath: string;\n content: Record<string, string>;\n locale: Locale;\n};\n\nexport type ExtractPluginOptions = {\n packageName?: PackageName;\n filesList: string[];\n enabled: boolean;\n\n shouldExtract?: (text: string) => boolean;\n configuration: IntlayerConfig;\n /**\n * Callback invoked for each extracted dictionary key/content pair.\n * Used by `getExtractPluginOptions` to write dictionaries to disk.\n * May be async — the plugin will fire-and-forget (Babel transforms are sync).\n */\n onExtract?: (result: ExtractResult) => void | Promise<void>;\n /**\n * Defines the output files path.\n */\n output?: FilePathPattern;\n};\n\ntype State = PluginPass & { opts: ExtractPluginOptions };\n\n/**\n * Babel plugin that extracts translatable content from source files and\n * injects Intlayer hooks (`useIntlayer` / `getIntlayer`) automatically.\n *\n * Designed for use with Babel-based build tools such as Next.js and Webpack.\n *\n * @example babel.config.js\n * ```js\n * const { intlayerExtractBabelPlugin, getExtractPluginOptions } = require('@intlayer/babel');\n * module.exports = {\n * presets: ['next/babel'],\n * plugins: [\n * [intlayerExtractBabelPlugin, getExtractPluginOptions()],\n * ],\n * };\n * ```\n */\nexport const intlayerExtractBabelPlugin = (_babel: {\n types: typeof BabelTypes;\n}): PluginObj<State> => {\n return {\n name: 'babel-plugin-intlayer-extract',\n\n visitor: {\n Program: {\n enter(programPath, state) {\n const opts = state.opts;\n\n // Merge plugin options with the unified compiler config\n const isEnabled = opts.enabled;\n\n if (isEnabled === false) return;\n\n const filename = state.file.opts.filename;\n\n if (!filename) return;\n\n if (opts.filesList && !opts.filesList.includes(filename)) return;\n\n const fileCode: string = state.file.code ?? '';\n if (!fileCode) return;\n\n const appLogger = getAppLogger(opts.configuration);\n const packageName = opts.packageName ?? detectPackageName(filename);\n\n const { saveComponents } = opts.configuration.compiler;\n\n const result = extractContentSync(filename, packageName, {\n configuration: opts.configuration,\n code: fileCode,\n onExtract: (extractResult: {\n key: string;\n content: Record<string, string>;\n }) => {\n if (opts.onExtract) {\n opts.onExtract({\n dictionaryKey: extractResult.key,\n filePath: filename,\n content: extractResult.content,\n locale: opts.configuration.internationalization.defaultLocale,\n });\n }\n },\n declarationOnly: !saveComponents,\n });\n\n if (!result) return;\n\n const { transformedCode: modifiedCode } = result;\n\n if (!modifiedCode) return;\n\n // Replace the Babel AST with the transformed code by re-parsing it.\n // This lets Babel serialise the injected hooks/imports through its\n // own code generator, preserving compatibility with other plugins.\n try {\n const newAst = parse(modifiedCode, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript'],\n });\n\n programPath.node.body = newAst.program.body;\n programPath.node.directives = newAst.program.directives;\n\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Extracted content from ${colorizePath(relative(opts.configuration.system.baseDir, filename))}`,\n { level: 'debug' }\n );\n } catch (error) {\n appLogger(\n [\n `Failed to parse transformed code for ${colorizePath(relative(opts.configuration.system.baseDir, filename))}:`,\n error,\n ],\n { level: 'error' }\n );\n }\n },\n },\n },\n };\n};\n"],"mappings":"2TA8DA,MAAa,EAA8B,IAGlC,CACL,KAAM,gCAEN,QAAS,CACP,QAAS,CACP,MAAM,EAAa,EAAO,CACxB,IAAM,EAAO,EAAM,KAKnB,GAFkB,EAAK,UAEL,GAAO,OAEzB,IAAM,EAAW,EAAM,KAAK,KAAK,SAIjC,GAFI,CAAC,GAED,EAAK,WAAa,CAAC,EAAK,UAAU,SAAS,EAAS,CAAE,OAE1D,IAAM,EAAmB,EAAM,KAAK,MAAQ,GAC5C,GAAI,CAAC,EAAU,OAEf,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAK,cAAc,CAC5C,EAAc,EAAK,aAAeA,EAAAA,kBAAkB,EAAS,CAE7D,CAAE,kBAAmB,EAAK,cAAc,SAExC,EAASC,EAAAA,mBAAmB,EAAU,EAAa,CACvD,cAAe,EAAK,cACpB,KAAM,EACN,UAAY,GAGN,CACA,EAAK,WACP,EAAK,UAAU,CACb,cAAe,EAAc,IAC7B,SAAU,EACV,QAAS,EAAc,QACvB,OAAQ,EAAK,cAAc,qBAAqB,cACjD,CAAC,EAGN,gBAAiB,CAAC,EACnB,CAAC,CAEF,GAAI,CAAC,EAAQ,OAEb,GAAM,CAAE,gBAAiB,GAAiB,EAErC,KAKL,GAAI,CACF,IAAM,GAAA,EAAA,EAAA,OAAe,EAAc,CACjC,WAAY,SACZ,QAAS,CAAC,MAAO,aAAa,CAC/B,CAAC,CAEF,EAAY,KAAK,KAAO,EAAO,QAAQ,KACvC,EAAY,KAAK,WAAa,EAAO,QAAQ,WAE7C,EACE,IAAA,EAAA,EAAA,UAAY,YAAaC,EAAAA,WAAW,UAAU,CAAC,2BAAA,EAAA,EAAA,eAAA,EAAA,EAAA,UAAgD,EAAK,cAAc,OAAO,QAAS,EAAS,CAAC,GAC5I,CAAE,MAAO,QAAS,CACnB,OACM,EAAO,CACd,EACE,CACE,yCAAA,EAAA,EAAA,eAAA,EAAA,EAAA,UAA8D,EAAK,cAAc,OAAO,QAAS,EAAS,CAAC,CAAC,GAC5G,EACD,CACD,CAAE,MAAO,QAAS,CACnB,GAGN,CACF,CACF"}
1
+ {"version":3,"file":"babel-plugin-intlayer-extract.cjs","names":["detectPackageName","extractContentSync","ANSIColors"],"sources":["../../src/babel-plugin-intlayer-extract.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport type { PluginObj, PluginPass } from '@babel/core';\nimport { parse } from '@babel/parser';\nimport type * as BabelTypes from '@babel/types';\nimport {\n ANSIColors,\n colorize,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { FilePathPattern } from '@intlayer/types/filePathPattern';\nimport { extractContentSync } from './extractContent/extractContent';\nimport type { PackageName } from './extractContent/utils/constants';\nimport { detectPackageName } from './extractContent/utils/detectPackageName';\n\nexport type ExtractResult = {\n dictionaryKey: string;\n filePath: string;\n content: Record<string, string>;\n locale: Locale;\n};\n\nexport type ExtractPluginOptions = {\n packageName?: PackageName;\n filesList: string[];\n enabled: boolean;\n\n shouldExtract?: (text: string) => boolean;\n configuration: IntlayerConfig;\n /**\n * Callback invoked for each extracted dictionary key/content pair.\n * Used by `getExtractPluginOptions` to write dictionaries to disk.\n * May be async — the plugin will fire-and-forget (Babel transforms are sync).\n */\n onExtract?: (result: ExtractResult) => void | Promise<void>;\n /**\n * Defines the output files path.\n */\n output?: FilePathPattern;\n};\n\ntype State = PluginPass & { opts: ExtractPluginOptions };\n\n/**\n * Babel plugin that extracts translatable content from source files and\n * injects Intlayer hooks (`useIntlayer` / `getIntlayer`) automatically.\n *\n * Designed for use with Babel-based build tools such as Next.js and Webpack.\n *\n * @example babel.config.js\n * ```js\n * const { intlayerExtractBabelPlugin, getExtractPluginOptions } = require('@intlayer/babel');\n * module.exports = {\n * presets: ['next/babel'],\n * plugins: [\n * [intlayerExtractBabelPlugin, getExtractPluginOptions()],\n * ],\n * };\n * ```\n */\nexport const intlayerExtractBabelPlugin = (_babel: {\n types: typeof BabelTypes;\n}): PluginObj<State> => {\n return {\n name: 'babel-plugin-intlayer-extract',\n\n visitor: {\n Program: {\n enter(programPath, state) {\n const opts = state.opts;\n\n // Merge plugin options with the unified compiler config\n const isEnabled = opts.enabled;\n\n if (isEnabled === false) return;\n\n const filename = state.file.opts.filename;\n\n if (!filename) return;\n\n if (opts.filesList && !opts.filesList.includes(filename)) return;\n\n const fileCode: string = state.file.code ?? '';\n if (!fileCode) return;\n\n const appLogger = getAppLogger(opts.configuration);\n const packageName = opts.packageName ?? detectPackageName(filename);\n\n const { saveComponents } = opts.configuration.compiler;\n\n const result = extractContentSync(filename, packageName, {\n configuration: opts.configuration,\n code: fileCode,\n onExtract: (extractResult: {\n key: string;\n content: Record<string, string>;\n }) => {\n if (opts.onExtract) {\n opts.onExtract({\n dictionaryKey: extractResult.key,\n filePath: filename,\n content: extractResult.content,\n locale: opts.configuration.internationalization.defaultLocale,\n });\n }\n },\n declarationOnly: !saveComponents,\n });\n\n if (!result) return;\n\n const { transformedCode: modifiedCode } = result;\n\n if (!modifiedCode) return;\n\n // Replace the Babel AST with the transformed code by re-parsing it.\n // This lets Babel serialise the injected hooks/imports through its\n // own code generator, preserving compatibility with other plugins.\n try {\n const newAst = parse(modifiedCode, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript'],\n });\n\n programPath.node.body = newAst.program.body;\n programPath.node.directives = newAst.program.directives;\n\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Extracted content from ${colorizePath(relative(opts.configuration.system.baseDir, filename))}`,\n { level: 'debug' }\n );\n } catch (error) {\n appLogger(\n [\n `Failed to parse transformed code for ${colorizePath(relative(opts.configuration.system.baseDir, filename))}:`,\n error,\n ],\n { level: 'error' }\n );\n }\n },\n },\n },\n };\n};\n"],"mappings":"+SA8DA,MAAa,EAA8B,IAGlC,CACL,KAAM,gCAEN,QAAS,CACP,QAAS,CACP,MAAM,EAAa,EAAO,CACxB,IAAM,EAAO,EAAM,KAKnB,GAFkB,EAAK,UAEL,GAAO,OAEzB,IAAM,EAAW,EAAM,KAAK,KAAK,SAIjC,GAFI,CAAC,GAED,EAAK,WAAa,CAAC,EAAK,UAAU,SAAS,EAAS,CAAE,OAE1D,IAAM,EAAmB,EAAM,KAAK,MAAQ,GAC5C,GAAI,CAAC,EAAU,OAEf,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAK,cAAc,CAC5C,EAAc,EAAK,aAAeA,EAAAA,kBAAkB,EAAS,CAE7D,CAAE,kBAAmB,EAAK,cAAc,SAExC,EAASC,EAAAA,mBAAmB,EAAU,EAAa,CACvD,cAAe,EAAK,cACpB,KAAM,EACN,UAAY,GAGN,CACA,EAAK,WACP,EAAK,UAAU,CACb,cAAe,EAAc,IAC7B,SAAU,EACV,QAAS,EAAc,QACvB,OAAQ,EAAK,cAAc,qBAAqB,cACjD,CAAC,EAGN,gBAAiB,CAAC,EACnB,CAAC,CAEF,GAAI,CAAC,EAAQ,OAEb,GAAM,CAAE,gBAAiB,GAAiB,EAErC,KAKL,GAAI,CACF,IAAM,GAAA,EAAA,EAAA,OAAe,EAAc,CACjC,WAAY,SACZ,QAAS,CAAC,MAAO,aAAa,CAC/B,CAAC,CAEF,EAAY,KAAK,KAAO,EAAO,QAAQ,KACvC,EAAY,KAAK,WAAa,EAAO,QAAQ,WAE7C,EACE,IAAA,EAAA,EAAA,UAAY,YAAaC,EAAAA,WAAW,UAAU,CAAC,2BAAA,EAAA,EAAA,eAAA,EAAA,EAAA,UAAgD,EAAK,cAAc,OAAO,QAAS,EAAS,CAAC,GAC5I,CAAE,MAAO,QAAS,CACnB,OACM,EAAO,CACd,EACE,CACE,yCAAA,EAAA,EAAA,eAAA,EAAA,EAAA,UAA8D,EAAK,cAAc,OAAO,QAAS,EAAS,CAAC,CAAC,GAC5G,EACD,CACD,CAAE,MAAO,QAAS,CACnB,GAGN,CACF,CACF"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/chokidar/utils`),t=require(`node:path`),n=require(`@intlayer/config/utils`);const r=[`intlayer`,`@intlayer/core`,`react-intlayer`,`react-intlayer/client`,`react-intlayer/server`,`next-intlayer`,`next-intlayer/client`,`next-intlayer/server`,`svelte-intlayer`,`vue-intlayer`,`angular-intlayer`,`preact-intlayer`,`solid-intlayer`],i=[`useIntlayer`,`getIntlayer`],a=[`react-intlayer`,`react-intlayer/client`,`react-intlayer/server`,`next-intlayer`,`next-intlayer/client`,`next-intlayer/server`,`preact-intlayer`,`vue-intlayer`,`solid-intlayer`,`svelte-intlayer`,`angular-intlayer`],o={getIntlayer:`getDictionary`,useIntlayer:`useDictionary`},s={useIntlayer:`useDictionaryDynamic`},c=(t,n)=>{let r=(0,e.getPathHash)(t);return n.identifier(`_${r}`)},l=(e,r,i,a,o,s)=>{let c=(0,t.join)(r,`${o}.json`);s===`fetch`&&(c=(0,t.join)(a,`${o}.mjs`)),s===`dynamic`&&(c=(0,t.join)(i,`${o}.mjs`));let l=(0,t.relative)((0,t.dirname)(e),c);return l=(0,n.normalizePath)(l),!l.startsWith(`./`)&&!l.startsWith(`../`)&&(l=`./${l}`),l},u=t=>{let{types:n}=t;return{name:`babel-plugin-intlayer-transform`,pre(){if(this._newStaticImports=new Map,this._newDynamicImports=new Map,this._callerMap=new Map,this._isIncluded=!0,this._hasValidImport=!1,this._isDictEntry=!1,this._useDynamicHelpers=!1,this.opts.optimize===!1){this._isIncluded=!1;return}let e=this.file.opts.filename;if(this.opts.filesList&&e&&!this.opts.filesList.includes(e)){this._isIncluded=!1;return}},visitor:{Program:{enter(e,t){let r=t.file.opts.filename;t.opts.replaceDictionaryEntry&&r===t.opts.dictionariesEntryPath&&(t._isDictEntry=!0,e.traverse({ImportDeclaration(e){e.remove()},VariableDeclarator(e){n.isObjectExpression(e.node.init)&&(e.node.init.properties=[])}}))},exit(t,u){if(u._isDictEntry||!u._isIncluded)return;let d=!1;if(t.traverse({CallExpression(e){let t=e.node.callee;if(!n.isIdentifier(t)||u._callerMap?.get(t.name)!==`useIntlayer`)return;let r=e.node.arguments[0],i;if(r&&n.isStringLiteral(r)?i=r.value:r&&n.isTemplateLiteral(r)&&r.expressions.length===0&&r.quasis.length===1&&(i=r.quasis[0].value.cooked??r.quasis[0].value.raw),!i)return;let a=u.opts.dictionaryModeMap?.[i];(a===`dynamic`||a===`fetch`)&&(d=!0)}}),t.traverse({ImportDeclaration(e){let t=e.node.source.value;if(r.includes(t)){u._hasValidImport=!0;for(let r of e.node.specifiers){if(!n.isImportSpecifier(r))continue;let e=n.isIdentifier(r.imported)?r.imported.name:r.imported.value;i.includes(e)&&u._callerMap?.set(r.local.name,e);let c=u.opts.importMode,l=(c===`dynamic`||c===`fetch`||d)&&a.includes(t);l&&(u._useDynamicHelpers=!0);let f;f=l?{...o,...s}:o;let p=f[e];p&&(r.imported=n.identifier(p))}}},CallExpression(t){let r=t.node.callee;if(!n.isIdentifier(r))return;let i=u._callerMap?.get(r.name);if(!i)return;u._hasValidImport=!0;let a=t.node.arguments[0],o;if(a&&n.isStringLiteral(a)?o=a.value:a&&n.isTemplateLiteral(a)&&a.expressions.length===0&&a.quasis.length===1&&(o=a.quasis[0].value.cooked??a.quasis[0].value.raw),!o)return;let s=u.opts.importMode,l=i===`useIntlayer`,d=!!u._useDynamicHelpers,f=`static`,p=u.opts.dictionaryModeMap?.[o];l&&d?p?f=p:s===`dynamic`?f=`dynamic`:s===`fetch`&&(f=`fetch`):l&&!d&&(p===`dynamic`||p===`fetch`)&&(f=p);let m;if(f===`fetch`){let r=u._newDynamicImports?.get(o);if(!r){let t=(0,e.getPathHash)(o);r=n.identifier(`_${t}_fetch`),u._newDynamicImports?.set(o,r)}m=r,t.node.arguments=[n.identifier(m.name),...t.node.arguments]}else if(f===`dynamic`){let r=u._newDynamicImports?.get(o);if(!r){let t=(0,e.getPathHash)(o);r=n.identifier(`_${t}_dyn`),u._newDynamicImports?.set(o,r)}m=r,t.node.arguments=[n.identifier(m.name),...t.node.arguments]}else{let e=u._newStaticImports?.get(o);e||(e=c(o,n),u._newStaticImports?.set(o,e)),m=e,t.node.arguments[0]=n.identifier(m.name)}}}),!u._hasValidImport)return;let f=u.file.opts.filename,p=u.opts.dictionariesDir,m=u.opts.dynamicDictionariesDir,h=u.opts.fetchDictionariesDir,g=[];for(let[e,t]of u._newStaticImports){let r=l(f,p,m,h,e,`static`),i=n.importDeclaration([n.importDefaultSpecifier(n.identifier(t.name))],n.stringLiteral(r));i.attributes=[n.importAttribute(n.identifier(`type`),n.stringLiteral(`json`))],g.push(i)}for(let[e,t]of u._newDynamicImports){let r=l(f,p,m,h,e,t.name.endsWith(`_fetch`)?`fetch`:`dynamic`);g.push(n.importDeclaration([n.importDefaultSpecifier(n.identifier(t.name))],n.stringLiteral(r)))}if(!g.length)return;let _=t.get(`body`),v=0;for(let e of _){let t=e.node;if(n.isExpressionStatement(t)&&n.isStringLiteral(t.expression)&&!t.expression.value.startsWith(`import`)&&!t.expression.value.startsWith(`require`))v+=1;else break}t.node.body.splice(v,0,...g)}}}}};exports.intlayerOptimizeBabelPlugin=u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunk-Bmb41Sf3.cjs`);let e=require(`@intlayer/chokidar/utils`),t=require(`node:path`),n=require(`@intlayer/config/utils`);const r=[`intlayer`,`@intlayer/core`,`react-intlayer`,`react-intlayer/client`,`react-intlayer/server`,`next-intlayer`,`next-intlayer/client`,`next-intlayer/server`,`svelte-intlayer`,`vue-intlayer`,`angular-intlayer`,`preact-intlayer`,`solid-intlayer`],i=[`useIntlayer`,`getIntlayer`],a=[`react-intlayer`,`react-intlayer/client`,`react-intlayer/server`,`next-intlayer`,`next-intlayer/client`,`next-intlayer/server`,`preact-intlayer`,`vue-intlayer`,`solid-intlayer`,`svelte-intlayer`,`angular-intlayer`],o={getIntlayer:`getDictionary`,useIntlayer:`useDictionary`},s={useIntlayer:`useDictionaryDynamic`},c=(t,n)=>{let r=(0,e.getPathHash)(t);return n.identifier(`_${r}`)},l=(e,r,i,a,o,s)=>{let c=(0,t.join)(r,`${o}.json`);s===`fetch`&&(c=(0,t.join)(a,`${o}.mjs`)),s===`dynamic`&&(c=(0,t.join)(i,`${o}.mjs`));let l=(0,t.relative)((0,t.dirname)(e),c);return l=(0,n.normalizePath)(l),!l.startsWith(`./`)&&!l.startsWith(`../`)&&(l=`./${l}`),l},u=t=>{let{types:n}=t;return{name:`babel-plugin-intlayer-transform`,pre(){if(this._newStaticImports=new Map,this._newDynamicImports=new Map,this._callerMap=new Map,this._isIncluded=!0,this._hasValidImport=!1,this._isDictEntry=!1,this._useDynamicHelpers=!1,this.opts.optimize===!1){this._isIncluded=!1;return}let e=this.file.opts.filename;if(this.opts.filesList&&e&&!this.opts.filesList.includes(e)){this._isIncluded=!1;return}},visitor:{Program:{enter(e,t){let r=t.file.opts.filename;t.opts.replaceDictionaryEntry&&r===t.opts.dictionariesEntryPath&&(t._isDictEntry=!0,e.traverse({ImportDeclaration(e){e.remove()},VariableDeclarator(e){n.isObjectExpression(e.node.init)&&(e.node.init.properties=[])}}))},exit(t,u){if(u._isDictEntry||!u._isIncluded)return;let d=!1;if(t.traverse({CallExpression(e){let t=e.node.callee;if(!n.isIdentifier(t)||u._callerMap?.get(t.name)!==`useIntlayer`)return;let r=e.node.arguments[0],i;if(r&&n.isStringLiteral(r)?i=r.value:r&&n.isTemplateLiteral(r)&&r.expressions.length===0&&r.quasis.length===1&&(i=r.quasis[0].value.cooked??r.quasis[0].value.raw),!i)return;let a=u.opts.dictionaryModeMap?.[i];(a===`dynamic`||a===`fetch`)&&(d=!0)}}),t.traverse({ImportDeclaration(e){let t=e.node.source.value;if(r.includes(t)){u._hasValidImport=!0;for(let r of e.node.specifiers){if(!n.isImportSpecifier(r))continue;let e=n.isIdentifier(r.imported)?r.imported.name:r.imported.value;i.includes(e)&&u._callerMap?.set(r.local.name,e);let c=u.opts.importMode,l=(c===`dynamic`||c===`fetch`||d)&&a.includes(t);l&&(u._useDynamicHelpers=!0);let f;f=l?{...o,...s}:o;let p=f[e];p&&(r.imported=n.identifier(p))}}},CallExpression(t){let r=t.node.callee;if(!n.isIdentifier(r))return;let i=u._callerMap?.get(r.name);if(!i)return;u._hasValidImport=!0;let a=t.node.arguments[0],o;if(a&&n.isStringLiteral(a)?o=a.value:a&&n.isTemplateLiteral(a)&&a.expressions.length===0&&a.quasis.length===1&&(o=a.quasis[0].value.cooked??a.quasis[0].value.raw),!o)return;let s=u.opts.importMode,l=i===`useIntlayer`,d=!!u._useDynamicHelpers,f=`static`,p=u.opts.dictionaryModeMap?.[o];l&&d?p?f=p:s===`dynamic`?f=`dynamic`:s===`fetch`&&(f=`fetch`):l&&!d&&(p===`dynamic`||p===`fetch`)&&(f=p);let m;if(f===`fetch`){let r=u._newDynamicImports?.get(o);if(!r){let t=(0,e.getPathHash)(o);r=n.identifier(`_${t}_fetch`),u._newDynamicImports?.set(o,r)}m=r,t.node.arguments=[n.identifier(m.name),...t.node.arguments]}else if(f===`dynamic`){let r=u._newDynamicImports?.get(o);if(!r){let t=(0,e.getPathHash)(o);r=n.identifier(`_${t}_dyn`),u._newDynamicImports?.set(o,r)}m=r,t.node.arguments=[n.identifier(m.name),...t.node.arguments]}else{let e=u._newStaticImports?.get(o);e||(e=c(o,n),u._newStaticImports?.set(o,e)),m=e,t.node.arguments[0]=n.identifier(m.name)}}}),!u._hasValidImport)return;let f=u.file.opts.filename,p=u.opts.dictionariesDir,m=u.opts.dynamicDictionariesDir,h=u.opts.fetchDictionariesDir,g=[];for(let[e,t]of u._newStaticImports){let r=l(f,p,m,h,e,`static`),i=n.importDeclaration([n.importDefaultSpecifier(n.identifier(t.name))],n.stringLiteral(r));i.attributes=[n.importAttribute(n.identifier(`type`),n.stringLiteral(`json`))],g.push(i)}for(let[e,t]of u._newDynamicImports){let r=l(f,p,m,h,e,t.name.endsWith(`_fetch`)?`fetch`:`dynamic`);g.push(n.importDeclaration([n.importDefaultSpecifier(n.identifier(t.name))],n.stringLiteral(r)))}if(!g.length)return;let _=t.get(`body`),v=0;for(let e of _){let t=e.node;if(n.isExpressionStatement(t)&&n.isStringLiteral(t.expression)&&!t.expression.value.startsWith(`import`)&&!t.expression.value.startsWith(`require`))v+=1;else break}t.node.body.splice(v,0,...g)}}}}};exports.intlayerOptimizeBabelPlugin=u;
2
2
  //# sourceMappingURL=babel-plugin-intlayer-optimize.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-optimize.cjs","names":[],"sources":["../../src/babel-plugin-intlayer-optimize.ts"],"sourcesContent":["import { dirname, join, relative } from 'node:path';\nimport type { NodePath, PluginObj, PluginPass } from '@babel/core';\nimport type * as BabelTypes from '@babel/types';\nimport { getPathHash } from '@intlayer/chokidar/utils';\nimport { normalizePath } from '@intlayer/config/utils';\n\nconst PACKAGE_LIST = [\n 'intlayer',\n '@intlayer/core',\n 'react-intlayer',\n 'react-intlayer/client',\n 'react-intlayer/server',\n 'next-intlayer',\n 'next-intlayer/client',\n 'next-intlayer/server',\n 'svelte-intlayer',\n 'vue-intlayer',\n 'angular-intlayer',\n 'preact-intlayer',\n 'solid-intlayer',\n];\n\nconst CALLER_LIST = ['useIntlayer', 'getIntlayer'] as const;\n\n/**\n * Packages that support dynamic import\n */\nconst PACKAGE_LIST_DYNAMIC = [\n 'react-intlayer',\n 'react-intlayer/client',\n 'react-intlayer/server',\n 'next-intlayer',\n 'next-intlayer/client',\n 'next-intlayer/server',\n 'preact-intlayer',\n 'vue-intlayer',\n 'solid-intlayer',\n 'svelte-intlayer',\n 'angular-intlayer',\n] as const;\n\nconst STATIC_IMPORT_FUNCTION = {\n getIntlayer: 'getDictionary',\n useIntlayer: 'useDictionary',\n} as const;\n\nconst DYNAMIC_IMPORT_FUNCTION = {\n useIntlayer: 'useDictionaryDynamic',\n} as const;\n\n/**\n * Options for the optimization Babel plugin\n */\nexport type OptimizePluginOptions = {\n /**\n * If false, the plugin will not apply any transformation.\n */\n optimize?: boolean;\n /**\n * The path to the dictionaries directory.\n */\n dictionariesDir: string;\n /**\n * The path to the dictionaries entry file.\n */\n dictionariesEntryPath: string;\n /**\n * The path to the unmerged dictionaries entry file.\n */\n unmergedDictionariesEntryPath: string;\n /**\n * The path to the unmerged dictionaries directory.\n */\n unmergedDictionariesDir: string;\n /**\n * The path to the dictionaries directory.\n */\n dynamicDictionariesDir: string;\n /**\n * The path to the dynamic dictionaries entry file.\n */\n dynamicDictionariesEntryPath: string;\n /**\n * The path to the fetch dictionaries directory.\n */\n fetchDictionariesDir: string;\n /**\n * The path to the fetch dictionaries entry file.\n */\n fetchDictionariesEntryPath: string;\n /**\n * If true, the plugin will replace the dictionary entry file with `export default {}`.\n */\n replaceDictionaryEntry: boolean;\n /**\n * If true, the plugin will activate the dynamic import of the dictionaries. It will rely on Suspense to load the dictionaries.\n */\n importMode: 'static' | 'dynamic' | 'fetch' | undefined;\n /**\n * Map of dictionary keys to their specific import mode.\n */\n dictionaryModeMap?: Record<\n string,\n 'static' | 'dynamic' | 'fetch' | undefined\n >;\n /**\n * Files list to traverse.\n */\n filesList: string[];\n};\n\ntype State = PluginPass & {\n opts: OptimizePluginOptions;\n /** map key → generated ident (per-file) for static imports */\n _newStaticImports?: Map<string, BabelTypes.Identifier>;\n /** map key → generated ident (per-file) for dynamic imports */\n _newDynamicImports?: Map<string, BabelTypes.Identifier>;\n /** whether the current file imported *any* intlayer package */\n _hasValidImport?: boolean;\n /** map from local identifier name to the imported intlayer func name ('useIntlayer' | 'getIntlayer') */\n _callerMap?: Map<string, (typeof CALLER_LIST)[number]>;\n /** whether the current file *is* the dictionaries entry file */\n _isDictEntry?: boolean;\n /** whether dynamic helpers are active for this file */\n _useDynamicHelpers?: boolean;\n /** whether the current file is included in the filesList */\n _isIncluded?: boolean;\n};\n\n/**\n * Replicates the xxHash64 → Base-62 algorithm used by the SWC version\n * and prefixes an underscore so the generated identifiers never collide\n * with user-defined ones.\n */\nconst makeIdent = (\n key: string,\n t: typeof BabelTypes\n): BabelTypes.Identifier => {\n const hash = getPathHash(key);\n return t.identifier(`_${hash}`);\n};\n\nconst computeImport = (\n fromFile: string,\n dictionariesDir: string,\n dynamicDictionariesDir: string,\n fetchDictionariesDir: string,\n key: string,\n importMode: 'static' | 'dynamic' | 'fetch'\n): string => {\n let relativePath = join(dictionariesDir, `${key}.json`);\n\n if (importMode === 'fetch') {\n relativePath = join(fetchDictionariesDir, `${key}.mjs`);\n }\n\n if (importMode === 'dynamic') {\n relativePath = join(dynamicDictionariesDir, `${key}.mjs`);\n }\n\n let rel = relative(dirname(fromFile), relativePath);\n\n // Fix windows path\n rel = normalizePath(rel);\n\n // Fix relative path\n if (!rel.startsWith('./') && !rel.startsWith('../')) {\n rel = `./${rel}`;\n }\n\n return rel;\n};\n\n/**\n * Babel plugin that transforms Intlayer function calls and auto-imports dictionaries.\n *\n * This plugin transforms calls to `useIntlayer()` and `getIntlayer()` from various Intlayer\n * packages into optimized dictionary access patterns, automatically importing the required\n * dictionary files based on the configured import mode.\n *\n * ## Supported Input Patterns\n *\n * The plugin recognizes these function calls:\n *\n * ```ts\n * // useIntlayer\n * import { useIntlayer } from 'react-intlayer';\n * import { useIntlayer } from 'next-intlayer';\n *\n * // getIntlayer\n * import { getIntlayer } from 'intlayer';\n *\n * // Usage\n * const content = useIntlayer('app');\n * const content = getIntlayer('app');\n * ```\n *\n * ## Transformation Modes\n *\n * ### Static Mode (default: `importMode = \"static\"`)\n *\n * Imports JSON dictionaries directly and replaces function calls with dictionary access:\n *\n * **Output:**\n * ```ts\n * import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };\n * import { useDictionary as useIntlayer } from 'react-intlayer';\n * import { getDictionary as getIntlayer } from 'intlayer';\n *\n * const content1 = useIntlayer(_dicHash);\n * const content2 = getIntlayer(_dicHash);\n * ```\n *\n * ### Dynamic Mode (`importMode = \"dynamic\"`)\n *\n * Uses dynamic dictionary loading with Suspense support:\n *\n * **Output:**\n * ```ts\n * import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };\n * import _dicHash_dyn from '../../.intlayer/dynamic_dictionaries/app.mjs';\n * import { useDictionaryDynamic as useIntlayer } from 'react-intlayer';\n * import { getDictionary as getIntlayer } from 'intlayer';\n *\n * const content1 = useIntlayer(_dicHash_dyn, 'app');\n * const content2 = getIntlayer(_dicHash);\n * ```\n *\n * ### Live Mode (`importMode = \"live\"`)\n *\n * Uses live-based dictionary loading for remote dictionaries:\n *\n * **Output if `dictionaryModeMap` includes the key with \"live\" value:**\n * ```ts\n * import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };\n * import _dicHash_fetch from '../../.intlayer/fetch_dictionaries/app.mjs';\n * import { useDictionaryDynamic as useIntlayer } from 'react-intlayer';\n * import { getDictionary as getIntlayer } from 'intlayer';\n *\n * const content1 = useIntlayer(_dicHash_fetch, \"app\");\n * const content2 = getIntlayer(_dicHash);\n * ```\n *\n * > If `dictionaryModeMap` does not include the key with \"live\" value, the plugin will fallback to the dynamic impor\n *\n * ```ts\n * import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };\n * import _dicHash_dyn from '../../.intlayer/dynamic_dictionaries/app.mjs';\n * import { useDictionaryDynamic as useIntlayer } from 'react-intlayer';\n * import { getDictionary as getIntlayer } from 'intlayer';\n *\n * const content1 = useIntlayer(_dicHash_dyn, 'app');\n * const content2 = getIntlayer(_dicHash);\n * ```\n */\nexport const intlayerOptimizeBabelPlugin = (babel: {\n types: typeof BabelTypes;\n}): PluginObj<State> => {\n const { types: t } = babel;\n\n return {\n name: 'babel-plugin-intlayer-transform',\n\n pre() {\n this._newStaticImports = new Map();\n this._newDynamicImports = new Map();\n this._callerMap = new Map();\n this._isIncluded = true;\n this._hasValidImport = false;\n this._isDictEntry = false;\n this._useDynamicHelpers = false;\n\n // If optimize is false, skip processing entirely\n if (this.opts.optimize === false) {\n this._isIncluded = false;\n return;\n }\n\n // If filesList is provided, check if current file is included\n const filename = this.file.opts.filename;\n if (this.opts.filesList && filename) {\n const isIncluded = this.opts.filesList.includes(filename);\n\n if (!isIncluded) {\n // Force _isIncluded to false to skip processing\n this._isIncluded = false;\n return;\n }\n }\n },\n\n visitor: {\n /* If this file *is* the dictionaries entry, short-circuit: export {} */\n Program: {\n enter(programPath, state) {\n // Safe access to filename\n const filename = state.file.opts.filename;\n\n // Check if this is the correct file to transform\n\n if (\n state.opts.replaceDictionaryEntry &&\n filename === state.opts.dictionariesEntryPath\n ) {\n state._isDictEntry = true;\n\n // Traverse the program to surgically remove/edit specific parts\n programPath.traverse({\n // Remove all import statements (cleaning up 'sssss.json')\n ImportDeclaration(path) {\n path.remove();\n },\n\n // Find the variable definition and empty the object\n VariableDeclarator(path) {\n // We look for: const x = { ... }\n\n if (t.isObjectExpression(path.node.init)) {\n // Set the object properties to an empty array: {}\n path.node.init.properties = [];\n }\n },\n });\n\n // (Optional) Stop other plugins from processing this file further if needed\n // programPath.stop();\n }\n },\n\n /**\n * After full traversal, process imports and call expressions, then inject the JSON dictionary imports.\n *\n * We do the transformation in Program.exit (via a manual traverse) rather than using\n * top-level ImportDeclaration/CallExpression visitors. This ensures that if another plugin\n * (like babel-plugin-intlayer-extract) adds new useIntlayer calls in its Program.exit,\n * we will see and transform them here because our Program.exit runs after theirs.\n */\n exit(programPath, state) {\n if (state._isDictEntry) return; // nothing else to do – already replaced\n\n if (!state._isIncluded) return; // early-out if file is not included\n\n // Manual traversal to process imports and call expressions\n // This runs AFTER all other plugins' visitors have completed\n\n // Pre-pass to determine if we should use dynamic helpers\n let fileHasDynamicCall = false;\n programPath.traverse({\n CallExpression(path) {\n const callee = path.node.callee;\n\n if (!t.isIdentifier(callee)) return;\n\n const originalImportedName = state._callerMap?.get(callee.name);\n if (originalImportedName !== 'useIntlayer') return;\n\n const arg = path.node.arguments[0];\n\n let key: string | undefined;\n\n if (arg && t.isStringLiteral(arg)) {\n key = arg.value;\n } else if (\n arg &&\n t.isTemplateLiteral(arg) &&\n arg.expressions.length === 0 &&\n arg.quasis.length === 1\n ) {\n // If the bundler output is `breadcrumb` instead of 'breadcrumb'\n key = arg.quasis[0].value.cooked ?? arg.quasis[0].value.raw;\n }\n\n if (!key) return;\n const dictionaryOverrideMode =\n state.opts.dictionaryModeMap?.[key];\n\n if (\n dictionaryOverrideMode === 'dynamic' ||\n dictionaryOverrideMode === 'fetch'\n ) {\n fileHasDynamicCall = true;\n }\n },\n });\n\n programPath.traverse({\n /* Inspect every intlayer import */\n ImportDeclaration(path) {\n const src = path.node.source.value;\n\n if (!PACKAGE_LIST.includes(src)) return;\n\n // Mark that we do import from an intlayer package in this file\n state._hasValidImport = true;\n\n for (const spec of path.node.specifiers) {\n if (!t.isImportSpecifier(spec)) continue;\n\n const importedName = t.isIdentifier(spec.imported)\n ? spec.imported.name\n : (spec.imported as BabelTypes.StringLiteral).value;\n\n if (CALLER_LIST.includes(importedName as any)) {\n state._callerMap?.set(\n spec.local.name,\n importedName as (typeof CALLER_LIST)[number]\n );\n }\n\n const importMode = state.opts.importMode;\n // Determine whether this import should use the dynamic helpers.\n const shouldUseDynamicHelpers =\n (importMode === 'dynamic' ||\n importMode === 'fetch' ||\n fileHasDynamicCall) &&\n PACKAGE_LIST_DYNAMIC.includes(src as any);\n\n // Remember for later (CallExpression) whether we are using the dynamic helpers\n\n if (shouldUseDynamicHelpers) {\n state._useDynamicHelpers = true;\n }\n\n let helperMap: Record<string, string>;\n\n if (shouldUseDynamicHelpers) {\n // Use dynamic helpers for useIntlayer when dynamic mode is enabled\n helperMap = {\n ...STATIC_IMPORT_FUNCTION,\n ...DYNAMIC_IMPORT_FUNCTION,\n } as Record<string, string>;\n } else {\n // Use static helpers by default\n helperMap = STATIC_IMPORT_FUNCTION as Record<string, string>;\n }\n\n const newIdentifier = helperMap[importedName];\n\n // Only rewrite when we actually have a mapping for the imported\n // specifier (ignore unrelated named imports).\n\n if (newIdentifier) {\n // Keep the local alias intact (so calls remain `useIntlayer` /\n // `getIntlayer`), but rewrite the imported identifier so it\n // points to our helper implementation.\n spec.imported = t.identifier(newIdentifier);\n }\n }\n },\n\n /* Replace calls: useIntlayer(\"foo\") → useDictionary(_hash) or useDictionaryDynamic(_hash, \"foo\") */\n CallExpression(path) {\n const callee = path.node.callee;\n\n if (!t.isIdentifier(callee)) return;\n\n const originalImportedName = state._callerMap?.get(callee.name);\n if (!originalImportedName) return;\n\n // Ensure we ultimately emit helper imports for files that *invoke*\n // the hooks, even if they didn't import them directly (edge cases with\n // re-exports).\n state._hasValidImport = true;\n\n const arg = path.node.arguments[0];\n\n let key: string | undefined;\n\n if (arg && t.isStringLiteral(arg)) {\n key = arg.value;\n } else if (\n arg &&\n t.isTemplateLiteral(arg) &&\n arg.expressions.length === 0 &&\n arg.quasis.length === 1\n ) {\n // If the bundler output is `breadcrumb` instead of 'breadcrumb'\n key = arg.quasis[0].value.cooked ?? arg.quasis[0].value.raw;\n }\n\n if (!key) return; // must be a static literal\n const importMode = state.opts.importMode;\n const isUseIntlayer = originalImportedName === 'useIntlayer';\n const useDynamicHelpers = Boolean(state._useDynamicHelpers);\n\n // Decide per-call mode: 'static' | 'dynamic' | 'fetch'\n let perCallMode: 'static' | 'dynamic' | 'fetch' = 'static';\n\n const dictionaryOverrideMode =\n state.opts.dictionaryModeMap?.[key];\n\n if (isUseIntlayer && useDynamicHelpers) {\n if (dictionaryOverrideMode) {\n perCallMode = dictionaryOverrideMode;\n } else if (importMode === 'dynamic') {\n perCallMode = 'dynamic';\n } else if (importMode === 'fetch') {\n perCallMode = 'fetch';\n }\n } else if (isUseIntlayer && !useDynamicHelpers) {\n // If dynamic helpers are NOT active (global mode is static),\n // we STILL might want to force dynamic/live for this specific call\n\n if (\n dictionaryOverrideMode === 'dynamic' ||\n dictionaryOverrideMode === 'fetch'\n ) {\n perCallMode = dictionaryOverrideMode;\n }\n }\n\n let ident: BabelTypes.Identifier;\n\n if (perCallMode === 'fetch') {\n // Use fetch dictionaries entry (live mode for selected keys)\n let dynamicIdent = state._newDynamicImports?.get(key);\n\n if (!dynamicIdent) {\n const hash = getPathHash(key);\n dynamicIdent = t.identifier(`_${hash}_fetch`);\n state._newDynamicImports?.set(key, dynamicIdent);\n }\n ident = dynamicIdent;\n\n // Helper: first argument is the dictionary entry, second is the key\n path.node.arguments = [\n t.identifier(ident.name),\n ...path.node.arguments,\n ];\n } else if (perCallMode === 'dynamic') {\n // Use dynamic dictionaries entry\n let dynamicIdent = state._newDynamicImports?.get(key);\n\n if (!dynamicIdent) {\n // Create a unique identifier for dynamic imports by appending a suffix\n const hash = getPathHash(key);\n dynamicIdent = t.identifier(`_${hash}_dyn`);\n state._newDynamicImports?.set(key, dynamicIdent);\n }\n ident = dynamicIdent;\n\n // Dynamic helper: first argument is the dictionary, second is the key.\n path.node.arguments = [\n t.identifier(ident.name),\n ...path.node.arguments,\n ];\n } else {\n // Use static imports for getIntlayer or useIntlayer when not using dynamic helpers\n let staticIdent = state._newStaticImports?.get(key);\n\n if (!staticIdent) {\n staticIdent = makeIdent(key, t);\n state._newStaticImports?.set(key, staticIdent);\n }\n ident = staticIdent;\n\n // Static helper (useDictionary / getDictionary): replace key with iden\n path.node.arguments[0] = t.identifier(ident.name);\n }\n },\n });\n\n // Early-out if we touched nothing\n\n if (!state._hasValidImport) return;\n\n const file = state.file.opts.filename!;\n const dictionariesDir = state.opts.dictionariesDir;\n const dynamicDictionariesDir = state.opts.dynamicDictionariesDir;\n const fetchDictionariesDir = state.opts.fetchDictionariesDir;\n const imports: BabelTypes.ImportDeclaration[] = [];\n\n // Generate static JSON imports (getIntlayer always uses JSON dictionaries)\n for (const [key, ident] of state._newStaticImports!) {\n const rel = computeImport(\n file,\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n key,\n 'static'\n );\n\n const importDeclarationNode = t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(ident.name))],\n t.stringLiteral(rel)\n );\n\n // Add 'type: json' attribute for JSON files\n importDeclarationNode.attributes = [\n t.importAttribute(t.identifier('type'), t.stringLiteral('json')),\n ];\n\n imports.push(importDeclarationNode);\n }\n\n // Generate dynamic/fetch imports (for useIntlayer when using dynamic/live helpers)\n for (const [key, ident] of state._newDynamicImports!) {\n const modeForThisIdent: 'dynamic' | 'fetch' = ident.name.endsWith(\n '_fetch'\n )\n ? 'fetch'\n : 'dynamic';\n\n const rel = computeImport(\n file,\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n key,\n modeForThisIdent\n );\n imports.push(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(ident.name))],\n t.stringLiteral(rel)\n )\n );\n }\n\n if (!imports.length) return;\n\n /* Keep \"use client\" / \"use server\" directives at the very top. */\n const bodyPaths = programPath.get(\n 'body'\n ) as NodePath<BabelTypes.Statement>[];\n let insertPos = 0;\n for (const stmtPath of bodyPaths) {\n const stmt = stmtPath.node;\n\n if (\n t.isExpressionStatement(stmt) &&\n t.isStringLiteral(stmt.expression) &&\n !stmt.expression.value.startsWith('import') &&\n !stmt.expression.value.startsWith('require')\n ) {\n insertPos += 1;\n } else {\n break;\n }\n }\n\n programPath.node.body.splice(insertPos, 0, ...imports);\n },\n },\n },\n };\n};\n"],"mappings":"oNAMA,MAAM,EAAe,CACnB,WACA,iBACA,iBACA,wBACA,wBACA,gBACA,uBACA,uBACA,kBACA,eACA,mBACA,kBACA,iBACD,CAEK,EAAc,CAAC,cAAe,cAAc,CAK5C,EAAuB,CAC3B,iBACA,wBACA,wBACA,gBACA,uBACA,uBACA,kBACA,eACA,iBACA,kBACA,mBACD,CAEK,EAAyB,CAC7B,YAAa,gBACb,YAAa,gBACd,CAEK,EAA0B,CAC9B,YAAa,uBACd,CAsFK,GACJ,EACA,IAC0B,CAC1B,IAAM,GAAA,EAAA,EAAA,aAAmB,EAAI,CAC7B,OAAO,EAAE,WAAW,IAAI,IAAO,EAG3B,GACJ,EACA,EACA,EACA,EACA,EACA,IACW,CACX,IAAI,GAAA,EAAA,EAAA,MAAoB,EAAiB,GAAG,EAAI,OAAO,CAEnD,IAAe,UACjB,GAAA,EAAA,EAAA,MAAoB,EAAsB,GAAG,EAAI,MAAM,EAGrD,IAAe,YACjB,GAAA,EAAA,EAAA,MAAoB,EAAwB,GAAG,EAAI,MAAM,EAG3D,IAAI,GAAA,EAAA,EAAA,WAAA,EAAA,EAAA,SAAuB,EAAS,CAAE,EAAa,CAUnD,MAPA,IAAA,EAAA,EAAA,eAAoB,EAAI,CAGpB,CAAC,EAAI,WAAW,KAAK,EAAI,CAAC,EAAI,WAAW,MAAM,GACjD,EAAM,KAAK,KAGN,GAqFI,EAA+B,GAEpB,CACtB,GAAM,CAAE,MAAO,GAAM,EA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CAAC,EAAK,KAAU,EAAM,kBAAoB,CACnD,IAAM,EAAM,EACV,EACA,EACA,EACA,EACA,EACA,SACD,CAEK,EAAwB,EAAE,kBAC9B,CAAC,EAAE,uBAAuB,EAAE,WAAW,EAAM,KAAK,CAAC,CAAC,CACpD,EAAE,cAAc,EAAI,CACrB,CAGD,EAAsB,WAAa,CACjC,EAAE,gBAAgB,EAAE,WAAW,OAAO,CAAE,EAAE,cAAc,OAAO,CAAC,CACjE,CAED,EAAQ,KAAK,EAAsB,CAIrC,IAAK,GAAM,CAAC,EAAK,KAAU,EAAM,mBAAqB,CAOpD,IAAM,EAAM,EACV,EACA,EACA,EACA,EACA,EAX4C,EAAM,KAAK,SACvD,SACD,CACG,QACA,UASH,CACD,EAAQ,KACN,EAAE,kBACA,CAAC,EAAE,uBAAuB,EAAE,WAAW,EAAM,KAAK,CAAC,CAAC,CACpD,EAAE,cAAc,EAAI,CACrB,CACF,CAGH,GAAI,CAAC,EAAQ,OAAQ,OAGrB,IAAM,EAAY,EAAY,IAC5B,OACD,CACG,EAAY,EAChB,IAAK,IAAM,KAAY,EAAW,CAChC,IAAM,EAAO,EAAS,KAEtB,GACE,EAAE,sBAAsB,EAAK,EAC7B,EAAE,gBAAgB,EAAK,WAAW,EAClC,CAAC,EAAK,WAAW,MAAM,WAAW,SAAS,EAC3C,CAAC,EAAK,WAAW,MAAM,WAAW,UAAU,CAE5C,GAAa,OAEb,MAIJ,EAAY,KAAK,KAAK,OAAO,EAAW,EAAG,GAAG,EAAQ,EAEzD,CACF,CACF"}
1
+ {"version":3,"file":"babel-plugin-intlayer-optimize.cjs","names":[],"sources":["../../src/babel-plugin-intlayer-optimize.ts"],"sourcesContent":["import { dirname, join, relative } from 'node:path';\nimport type { NodePath, PluginObj, PluginPass } from '@babel/core';\nimport type * as BabelTypes from '@babel/types';\nimport { getPathHash } from '@intlayer/chokidar/utils';\nimport { normalizePath } from '@intlayer/config/utils';\n\nconst PACKAGE_LIST = [\n 'intlayer',\n '@intlayer/core',\n 'react-intlayer',\n 'react-intlayer/client',\n 'react-intlayer/server',\n 'next-intlayer',\n 'next-intlayer/client',\n 'next-intlayer/server',\n 'svelte-intlayer',\n 'vue-intlayer',\n 'angular-intlayer',\n 'preact-intlayer',\n 'solid-intlayer',\n];\n\nconst CALLER_LIST = ['useIntlayer', 'getIntlayer'] as const;\n\n/**\n * Packages that support dynamic import\n */\nconst PACKAGE_LIST_DYNAMIC = [\n 'react-intlayer',\n 'react-intlayer/client',\n 'react-intlayer/server',\n 'next-intlayer',\n 'next-intlayer/client',\n 'next-intlayer/server',\n 'preact-intlayer',\n 'vue-intlayer',\n 'solid-intlayer',\n 'svelte-intlayer',\n 'angular-intlayer',\n] as const;\n\nconst STATIC_IMPORT_FUNCTION = {\n getIntlayer: 'getDictionary',\n useIntlayer: 'useDictionary',\n} as const;\n\nconst DYNAMIC_IMPORT_FUNCTION = {\n useIntlayer: 'useDictionaryDynamic',\n} as const;\n\n/**\n * Options for the optimization Babel plugin\n */\nexport type OptimizePluginOptions = {\n /**\n * If false, the plugin will not apply any transformation.\n */\n optimize?: boolean;\n /**\n * The path to the dictionaries directory.\n */\n dictionariesDir: string;\n /**\n * The path to the dictionaries entry file.\n */\n dictionariesEntryPath: string;\n /**\n * The path to the unmerged dictionaries entry file.\n */\n unmergedDictionariesEntryPath: string;\n /**\n * The path to the unmerged dictionaries directory.\n */\n unmergedDictionariesDir: string;\n /**\n * The path to the dictionaries directory.\n */\n dynamicDictionariesDir: string;\n /**\n * The path to the dynamic dictionaries entry file.\n */\n dynamicDictionariesEntryPath: string;\n /**\n * The path to the fetch dictionaries directory.\n */\n fetchDictionariesDir: string;\n /**\n * The path to the fetch dictionaries entry file.\n */\n fetchDictionariesEntryPath: string;\n /**\n * If true, the plugin will replace the dictionary entry file with `export default {}`.\n */\n replaceDictionaryEntry: boolean;\n /**\n * If true, the plugin will activate the dynamic import of the dictionaries. It will rely on Suspense to load the dictionaries.\n */\n importMode: 'static' | 'dynamic' | 'fetch' | undefined;\n /**\n * Map of dictionary keys to their specific import mode.\n */\n dictionaryModeMap?: Record<\n string,\n 'static' | 'dynamic' | 'fetch' | undefined\n >;\n /**\n * Files list to traverse.\n */\n filesList: string[];\n};\n\ntype State = PluginPass & {\n opts: OptimizePluginOptions;\n /** map key → generated ident (per-file) for static imports */\n _newStaticImports?: Map<string, BabelTypes.Identifier>;\n /** map key → generated ident (per-file) for dynamic imports */\n _newDynamicImports?: Map<string, BabelTypes.Identifier>;\n /** whether the current file imported *any* intlayer package */\n _hasValidImport?: boolean;\n /** map from local identifier name to the imported intlayer func name ('useIntlayer' | 'getIntlayer') */\n _callerMap?: Map<string, (typeof CALLER_LIST)[number]>;\n /** whether the current file *is* the dictionaries entry file */\n _isDictEntry?: boolean;\n /** whether dynamic helpers are active for this file */\n _useDynamicHelpers?: boolean;\n /** whether the current file is included in the filesList */\n _isIncluded?: boolean;\n};\n\n/**\n * Replicates the xxHash64 → Base-62 algorithm used by the SWC version\n * and prefixes an underscore so the generated identifiers never collide\n * with user-defined ones.\n */\nconst makeIdent = (\n key: string,\n t: typeof BabelTypes\n): BabelTypes.Identifier => {\n const hash = getPathHash(key);\n return t.identifier(`_${hash}`);\n};\n\nconst computeImport = (\n fromFile: string,\n dictionariesDir: string,\n dynamicDictionariesDir: string,\n fetchDictionariesDir: string,\n key: string,\n importMode: 'static' | 'dynamic' | 'fetch'\n): string => {\n let relativePath = join(dictionariesDir, `${key}.json`);\n\n if (importMode === 'fetch') {\n relativePath = join(fetchDictionariesDir, `${key}.mjs`);\n }\n\n if (importMode === 'dynamic') {\n relativePath = join(dynamicDictionariesDir, `${key}.mjs`);\n }\n\n let rel = relative(dirname(fromFile), relativePath);\n\n // Fix windows path\n rel = normalizePath(rel);\n\n // Fix relative path\n if (!rel.startsWith('./') && !rel.startsWith('../')) {\n rel = `./${rel}`;\n }\n\n return rel;\n};\n\n/**\n * Babel plugin that transforms Intlayer function calls and auto-imports dictionaries.\n *\n * This plugin transforms calls to `useIntlayer()` and `getIntlayer()` from various Intlayer\n * packages into optimized dictionary access patterns, automatically importing the required\n * dictionary files based on the configured import mode.\n *\n * ## Supported Input Patterns\n *\n * The plugin recognizes these function calls:\n *\n * ```ts\n * // useIntlayer\n * import { useIntlayer } from 'react-intlayer';\n * import { useIntlayer } from 'next-intlayer';\n *\n * // getIntlayer\n * import { getIntlayer } from 'intlayer';\n *\n * // Usage\n * const content = useIntlayer('app');\n * const content = getIntlayer('app');\n * ```\n *\n * ## Transformation Modes\n *\n * ### Static Mode (default: `importMode = \"static\"`)\n *\n * Imports JSON dictionaries directly and replaces function calls with dictionary access:\n *\n * **Output:**\n * ```ts\n * import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };\n * import { useDictionary as useIntlayer } from 'react-intlayer';\n * import { getDictionary as getIntlayer } from 'intlayer';\n *\n * const content1 = useIntlayer(_dicHash);\n * const content2 = getIntlayer(_dicHash);\n * ```\n *\n * ### Dynamic Mode (`importMode = \"dynamic\"`)\n *\n * Uses dynamic dictionary loading with Suspense support:\n *\n * **Output:**\n * ```ts\n * import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };\n * import _dicHash_dyn from '../../.intlayer/dynamic_dictionaries/app.mjs';\n * import { useDictionaryDynamic as useIntlayer } from 'react-intlayer';\n * import { getDictionary as getIntlayer } from 'intlayer';\n *\n * const content1 = useIntlayer(_dicHash_dyn, 'app');\n * const content2 = getIntlayer(_dicHash);\n * ```\n *\n * ### Live Mode (`importMode = \"live\"`)\n *\n * Uses live-based dictionary loading for remote dictionaries:\n *\n * **Output if `dictionaryModeMap` includes the key with \"live\" value:**\n * ```ts\n * import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };\n * import _dicHash_fetch from '../../.intlayer/fetch_dictionaries/app.mjs';\n * import { useDictionaryDynamic as useIntlayer } from 'react-intlayer';\n * import { getDictionary as getIntlayer } from 'intlayer';\n *\n * const content1 = useIntlayer(_dicHash_fetch, \"app\");\n * const content2 = getIntlayer(_dicHash);\n * ```\n *\n * > If `dictionaryModeMap` does not include the key with \"live\" value, the plugin will fallback to the dynamic impor\n *\n * ```ts\n * import _dicHash from '../../.intlayer/dictionaries/app.json' with { type: 'json' };\n * import _dicHash_dyn from '../../.intlayer/dynamic_dictionaries/app.mjs';\n * import { useDictionaryDynamic as useIntlayer } from 'react-intlayer';\n * import { getDictionary as getIntlayer } from 'intlayer';\n *\n * const content1 = useIntlayer(_dicHash_dyn, 'app');\n * const content2 = getIntlayer(_dicHash);\n * ```\n */\nexport const intlayerOptimizeBabelPlugin = (babel: {\n types: typeof BabelTypes;\n}): PluginObj<State> => {\n const { types: t } = babel;\n\n return {\n name: 'babel-plugin-intlayer-transform',\n\n pre() {\n this._newStaticImports = new Map();\n this._newDynamicImports = new Map();\n this._callerMap = new Map();\n this._isIncluded = true;\n this._hasValidImport = false;\n this._isDictEntry = false;\n this._useDynamicHelpers = false;\n\n // If optimize is false, skip processing entirely\n if (this.opts.optimize === false) {\n this._isIncluded = false;\n return;\n }\n\n // If filesList is provided, check if current file is included\n const filename = this.file.opts.filename;\n if (this.opts.filesList && filename) {\n const isIncluded = this.opts.filesList.includes(filename);\n\n if (!isIncluded) {\n // Force _isIncluded to false to skip processing\n this._isIncluded = false;\n return;\n }\n }\n },\n\n visitor: {\n /* If this file *is* the dictionaries entry, short-circuit: export {} */\n Program: {\n enter(programPath, state) {\n // Safe access to filename\n const filename = state.file.opts.filename;\n\n // Check if this is the correct file to transform\n\n if (\n state.opts.replaceDictionaryEntry &&\n filename === state.opts.dictionariesEntryPath\n ) {\n state._isDictEntry = true;\n\n // Traverse the program to surgically remove/edit specific parts\n programPath.traverse({\n // Remove all import statements (cleaning up 'sssss.json')\n ImportDeclaration(path) {\n path.remove();\n },\n\n // Find the variable definition and empty the object\n VariableDeclarator(path) {\n // We look for: const x = { ... }\n\n if (t.isObjectExpression(path.node.init)) {\n // Set the object properties to an empty array: {}\n path.node.init.properties = [];\n }\n },\n });\n\n // (Optional) Stop other plugins from processing this file further if needed\n // programPath.stop();\n }\n },\n\n /**\n * After full traversal, process imports and call expressions, then inject the JSON dictionary imports.\n *\n * We do the transformation in Program.exit (via a manual traverse) rather than using\n * top-level ImportDeclaration/CallExpression visitors. This ensures that if another plugin\n * (like babel-plugin-intlayer-extract) adds new useIntlayer calls in its Program.exit,\n * we will see and transform them here because our Program.exit runs after theirs.\n */\n exit(programPath, state) {\n if (state._isDictEntry) return; // nothing else to do – already replaced\n\n if (!state._isIncluded) return; // early-out if file is not included\n\n // Manual traversal to process imports and call expressions\n // This runs AFTER all other plugins' visitors have completed\n\n // Pre-pass to determine if we should use dynamic helpers\n let fileHasDynamicCall = false;\n programPath.traverse({\n CallExpression(path) {\n const callee = path.node.callee;\n\n if (!t.isIdentifier(callee)) return;\n\n const originalImportedName = state._callerMap?.get(callee.name);\n if (originalImportedName !== 'useIntlayer') return;\n\n const arg = path.node.arguments[0];\n\n let key: string | undefined;\n\n if (arg && t.isStringLiteral(arg)) {\n key = arg.value;\n } else if (\n arg &&\n t.isTemplateLiteral(arg) &&\n arg.expressions.length === 0 &&\n arg.quasis.length === 1\n ) {\n // If the bundler output is `breadcrumb` instead of 'breadcrumb'\n key = arg.quasis[0].value.cooked ?? arg.quasis[0].value.raw;\n }\n\n if (!key) return;\n const dictionaryOverrideMode =\n state.opts.dictionaryModeMap?.[key];\n\n if (\n dictionaryOverrideMode === 'dynamic' ||\n dictionaryOverrideMode === 'fetch'\n ) {\n fileHasDynamicCall = true;\n }\n },\n });\n\n programPath.traverse({\n /* Inspect every intlayer import */\n ImportDeclaration(path) {\n const src = path.node.source.value;\n\n if (!PACKAGE_LIST.includes(src)) return;\n\n // Mark that we do import from an intlayer package in this file\n state._hasValidImport = true;\n\n for (const spec of path.node.specifiers) {\n if (!t.isImportSpecifier(spec)) continue;\n\n const importedName = t.isIdentifier(spec.imported)\n ? spec.imported.name\n : (spec.imported as BabelTypes.StringLiteral).value;\n\n if (CALLER_LIST.includes(importedName as any)) {\n state._callerMap?.set(\n spec.local.name,\n importedName as (typeof CALLER_LIST)[number]\n );\n }\n\n const importMode = state.opts.importMode;\n // Determine whether this import should use the dynamic helpers.\n const shouldUseDynamicHelpers =\n (importMode === 'dynamic' ||\n importMode === 'fetch' ||\n fileHasDynamicCall) &&\n PACKAGE_LIST_DYNAMIC.includes(src as any);\n\n // Remember for later (CallExpression) whether we are using the dynamic helpers\n\n if (shouldUseDynamicHelpers) {\n state._useDynamicHelpers = true;\n }\n\n let helperMap: Record<string, string>;\n\n if (shouldUseDynamicHelpers) {\n // Use dynamic helpers for useIntlayer when dynamic mode is enabled\n helperMap = {\n ...STATIC_IMPORT_FUNCTION,\n ...DYNAMIC_IMPORT_FUNCTION,\n } as Record<string, string>;\n } else {\n // Use static helpers by default\n helperMap = STATIC_IMPORT_FUNCTION as Record<string, string>;\n }\n\n const newIdentifier = helperMap[importedName];\n\n // Only rewrite when we actually have a mapping for the imported\n // specifier (ignore unrelated named imports).\n\n if (newIdentifier) {\n // Keep the local alias intact (so calls remain `useIntlayer` /\n // `getIntlayer`), but rewrite the imported identifier so it\n // points to our helper implementation.\n spec.imported = t.identifier(newIdentifier);\n }\n }\n },\n\n /* Replace calls: useIntlayer(\"foo\") → useDictionary(_hash) or useDictionaryDynamic(_hash, \"foo\") */\n CallExpression(path) {\n const callee = path.node.callee;\n\n if (!t.isIdentifier(callee)) return;\n\n const originalImportedName = state._callerMap?.get(callee.name);\n if (!originalImportedName) return;\n\n // Ensure we ultimately emit helper imports for files that *invoke*\n // the hooks, even if they didn't import them directly (edge cases with\n // re-exports).\n state._hasValidImport = true;\n\n const arg = path.node.arguments[0];\n\n let key: string | undefined;\n\n if (arg && t.isStringLiteral(arg)) {\n key = arg.value;\n } else if (\n arg &&\n t.isTemplateLiteral(arg) &&\n arg.expressions.length === 0 &&\n arg.quasis.length === 1\n ) {\n // If the bundler output is `breadcrumb` instead of 'breadcrumb'\n key = arg.quasis[0].value.cooked ?? arg.quasis[0].value.raw;\n }\n\n if (!key) return; // must be a static literal\n const importMode = state.opts.importMode;\n const isUseIntlayer = originalImportedName === 'useIntlayer';\n const useDynamicHelpers = Boolean(state._useDynamicHelpers);\n\n // Decide per-call mode: 'static' | 'dynamic' | 'fetch'\n let perCallMode: 'static' | 'dynamic' | 'fetch' = 'static';\n\n const dictionaryOverrideMode =\n state.opts.dictionaryModeMap?.[key];\n\n if (isUseIntlayer && useDynamicHelpers) {\n if (dictionaryOverrideMode) {\n perCallMode = dictionaryOverrideMode;\n } else if (importMode === 'dynamic') {\n perCallMode = 'dynamic';\n } else if (importMode === 'fetch') {\n perCallMode = 'fetch';\n }\n } else if (isUseIntlayer && !useDynamicHelpers) {\n // If dynamic helpers are NOT active (global mode is static),\n // we STILL might want to force dynamic/live for this specific call\n\n if (\n dictionaryOverrideMode === 'dynamic' ||\n dictionaryOverrideMode === 'fetch'\n ) {\n perCallMode = dictionaryOverrideMode;\n }\n }\n\n let ident: BabelTypes.Identifier;\n\n if (perCallMode === 'fetch') {\n // Use fetch dictionaries entry (live mode for selected keys)\n let dynamicIdent = state._newDynamicImports?.get(key);\n\n if (!dynamicIdent) {\n const hash = getPathHash(key);\n dynamicIdent = t.identifier(`_${hash}_fetch`);\n state._newDynamicImports?.set(key, dynamicIdent);\n }\n ident = dynamicIdent;\n\n // Helper: first argument is the dictionary entry, second is the key\n path.node.arguments = [\n t.identifier(ident.name),\n ...path.node.arguments,\n ];\n } else if (perCallMode === 'dynamic') {\n // Use dynamic dictionaries entry\n let dynamicIdent = state._newDynamicImports?.get(key);\n\n if (!dynamicIdent) {\n // Create a unique identifier for dynamic imports by appending a suffix\n const hash = getPathHash(key);\n dynamicIdent = t.identifier(`_${hash}_dyn`);\n state._newDynamicImports?.set(key, dynamicIdent);\n }\n ident = dynamicIdent;\n\n // Dynamic helper: first argument is the dictionary, second is the key.\n path.node.arguments = [\n t.identifier(ident.name),\n ...path.node.arguments,\n ];\n } else {\n // Use static imports for getIntlayer or useIntlayer when not using dynamic helpers\n let staticIdent = state._newStaticImports?.get(key);\n\n if (!staticIdent) {\n staticIdent = makeIdent(key, t);\n state._newStaticImports?.set(key, staticIdent);\n }\n ident = staticIdent;\n\n // Static helper (useDictionary / getDictionary): replace key with iden\n path.node.arguments[0] = t.identifier(ident.name);\n }\n },\n });\n\n // Early-out if we touched nothing\n\n if (!state._hasValidImport) return;\n\n const file = state.file.opts.filename!;\n const dictionariesDir = state.opts.dictionariesDir;\n const dynamicDictionariesDir = state.opts.dynamicDictionariesDir;\n const fetchDictionariesDir = state.opts.fetchDictionariesDir;\n const imports: BabelTypes.ImportDeclaration[] = [];\n\n // Generate static JSON imports (getIntlayer always uses JSON dictionaries)\n for (const [key, ident] of state._newStaticImports!) {\n const rel = computeImport(\n file,\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n key,\n 'static'\n );\n\n const importDeclarationNode = t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(ident.name))],\n t.stringLiteral(rel)\n );\n\n // Add 'type: json' attribute for JSON files\n importDeclarationNode.attributes = [\n t.importAttribute(t.identifier('type'), t.stringLiteral('json')),\n ];\n\n imports.push(importDeclarationNode);\n }\n\n // Generate dynamic/fetch imports (for useIntlayer when using dynamic/live helpers)\n for (const [key, ident] of state._newDynamicImports!) {\n const modeForThisIdent: 'dynamic' | 'fetch' = ident.name.endsWith(\n '_fetch'\n )\n ? 'fetch'\n : 'dynamic';\n\n const rel = computeImport(\n file,\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n key,\n modeForThisIdent\n );\n imports.push(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(ident.name))],\n t.stringLiteral(rel)\n )\n );\n }\n\n if (!imports.length) return;\n\n /* Keep \"use client\" / \"use server\" directives at the very top. */\n const bodyPaths = programPath.get(\n 'body'\n ) as NodePath<BabelTypes.Statement>[];\n let insertPos = 0;\n for (const stmtPath of bodyPaths) {\n const stmt = stmtPath.node;\n\n if (\n t.isExpressionStatement(stmt) &&\n t.isStringLiteral(stmt.expression) &&\n !stmt.expression.value.startsWith('import') &&\n !stmt.expression.value.startsWith('require')\n ) {\n insertPos += 1;\n } else {\n break;\n }\n }\n\n programPath.node.body.splice(insertPos, 0, ...imports);\n },\n },\n },\n };\n};\n"],"mappings":"wMAMA,MAAM,EAAe,CACnB,WACA,iBACA,iBACA,wBACA,wBACA,gBACA,uBACA,uBACA,kBACA,eACA,mBACA,kBACA,iBACD,CAEK,EAAc,CAAC,cAAe,cAAc,CAK5C,EAAuB,CAC3B,iBACA,wBACA,wBACA,gBACA,uBACA,uBACA,kBACA,eACA,iBACA,kBACA,mBACD,CAEK,EAAyB,CAC7B,YAAa,gBACb,YAAa,gBACd,CAEK,EAA0B,CAC9B,YAAa,uBACd,CAsFK,GACJ,EACA,IAC0B,CAC1B,IAAM,GAAA,EAAA,EAAA,aAAmB,EAAI,CAC7B,OAAO,EAAE,WAAW,IAAI,IAAO,EAG3B,GACJ,EACA,EACA,EACA,EACA,EACA,IACW,CACX,IAAI,GAAA,EAAA,EAAA,MAAoB,EAAiB,GAAG,EAAI,OAAO,CAEnD,IAAe,UACjB,GAAA,EAAA,EAAA,MAAoB,EAAsB,GAAG,EAAI,MAAM,EAGrD,IAAe,YACjB,GAAA,EAAA,EAAA,MAAoB,EAAwB,GAAG,EAAI,MAAM,EAG3D,IAAI,GAAA,EAAA,EAAA,WAAA,EAAA,EAAA,SAAuB,EAAS,CAAE,EAAa,CAUnD,MAPA,IAAA,EAAA,EAAA,eAAoB,EAAI,CAGpB,CAAC,EAAI,WAAW,KAAK,EAAI,CAAC,EAAI,WAAW,MAAM,GACjD,EAAM,KAAK,KAGN,GAqFI,EAA+B,GAEpB,CACtB,GAAM,CAAE,MAAO,GAAM,EAErB,MAAO,CACL,KAAM,kCAEN,KAAM,CAUJ,GATA,KAAK,kBAAoB,IAAI,IAC7B,KAAK,mBAAqB,IAAI,IAC9B,KAAK,WAAa,IAAI,IACtB,KAAK,YAAc,GACnB,KAAK,gBAAkB,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AAC,CAAC,CACpD,EAAE,cAAc,EAAI,CACrB,CAGD,EAAsB,WAAa,CACjC,EAAE,gBAAgB,EAAE,WAAW,OAAO,CAAE,EAAE,cAAc,OAAO,CAAC,CACjE,CAED,EAAQ,KAAK,EAAsB,CAIrC,IAAK,GAAM,CAAC,EAAK,KAAU,EAAM,mBAAqB,CAOpD,IAAM,EAAM,EACV,EACA,EACA,EACA,EACA,EAX4C,EAAM,KAAK,SACvD,SACD,CACG,QACA,UASH,CACD,EAAQ,KACN,EAAE,kBACA,CAAC,EAAE,uBAAuB,EAAE,WAAW,EAAM,KAAK,CAAC,CAAC,CACpD,EAAE,cAAc,EAAI,CACrB,CACF,CAGH,GAAI,CAAC,EAAQ,OAAQ,OAGrB,IAAM,EAAY,EAAY,IAC5B,OACD,CACG,EAAY,EAChB,IAAK,IAAM,KAAY,EAAW,CAChC,IAAM,EAAO,EAAS,KAEtB,GACE,EAAE,sBAAsB,EAAK,EAC7B,EAAE,gBAAgB,EAAK,WAAW,EAClC,CAAC,EAAK,WAAW,MAAM,WAAW,SAAS,EAC3C,CAAC,EAAK,WAAW,MAAM,WAAW,UAAU,CAE5C,GAAa,OAEb,MAIJ,EAAY,KAAK,KAAK,OAAO,EAAW,EAAG,GAAG,EAAQ,EAEzD,CACF,CACF"}
@@ -1 +1 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return s}});
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./utils/constants.cjs`),n=require(`./utils/getComponentName.cjs`),r=require(`./utils/getExistingIntlayerInfo.cjs`),i=require(`./utils/getOrGenerateKey.cjs`),a=require(`./utils/resolveDictionaryKey.cjs`),o=require(`./utils/shouldExtract.cjs`);let s=require(`@babel/traverse`);s=e.__toESM(s);let c=require(`@babel/types`);c=e.__toESM(c);const l=typeof s.default==`function`?s.default:s.default.default,u=(e,t,n,r,a,s,l)=>{let u=e.node.children;if(u.length<=1)return!1;let d=[],f=!1,p=!1;for(let e of u)if(c.isJSXText(e)){let t=e.value;t.trim().length>0&&(f=!0),d.push({type:`text`,value:t})}else if(c.isJSXExpressionContainer(e))if(c.isJSXEmptyExpression(e.expression))d.push({type:`text`,value:``});else{let n=e.expression;if(c.isIdentifier(n))d.push({type:`var`,value:n.name,originalExpr:n.name}),p=!0;else if(c.isMemberExpression(n)){let e=t.substring(n.start,n.end),r=c.isIdentifier(n.property)?n.property.name:`var`;d.push({type:`var`,value:r,originalExpr:e}),p=!0}else return!1}else return!1;if(!f)return!1;let m=``;for(let e of d)e.type===`var`?m+=`{{${e.value}}}`:m+=e.value;let h=m.replace(/\s+/g,` `).trim();if(o.shouldExtract(h)){let t=r(e),o=i.getOrGenerateKey(h,t,n,a),c=d.filter(e=>e.type===`var`).map(e=>`${e.value}: ${e.originalExpr}`),f=Array.from(new Set(c));return p?s.push({path:e,key:o,type:`jsx-insertion`,componentKey:t,childrenToReplace:u,variables:f}):s.push({path:e,key:o,type:`jsx-text-combined`,componentKey:t,childrenToReplace:u}),u.forEach(e=>{l.add(e)}),!0}return!1},d=(e,s,d,f=`default`,p,m,h={})=>{let g={},_=[],v=new Set,y=new Map,b=new Map,x=new Set,S,C=[];l(e,{FunctionDeclaration(e){C.push(e)},ArrowFunctionExpression(e){C.push(e)},FunctionExpression(e){C.push(e)}});for(let e of C){let t=r.getExistingIntlayerInfo(e);if(t)y.set(e.node,t.key),x.add(t.key),b.set(e.node,t.hook);else{S||(S=a.resolveDictionaryKey(f,m,p,h,x),x.add(S)),y.set(e.node,S);let t=n.getComponentName(e),r=t?/^[A-Z]/.test(t):!1;b.set(e.node,r?`useIntlayer`:`getIntlayer`)}}let w=e=>{let t=e;for(;t;){if(y.has(t.node))return y.get(t.node);t=t.parentPath}return S||f};l(e,{JSXElement(e){v.has(e.node)||u(e,s,d,w,g,_,v)},JSXFragment(e){v.has(e.node)||u(e,s,d,w,g,_,v)},JSXText(e){if(v.has(e.node))return;let t=e.node.value;if(o.shouldExtract(t)){let n=w(e),r=i.getOrGenerateKey(t.replace(/\s+/g,` `).trim(),n,d,g);_.push({path:e,key:r,type:`jsx-text`,componentKey:n})}},JSXAttribute(e){if(v.has(e.node))return;let n=e.node.name.name;if(typeof n!=`string`||!t.ATTRIBUTES_TO_EXTRACT.includes(n))return;let r=e.node.value;if(c.isStringLiteral(r)&&o.shouldExtract(r.value)){let t=w(e),n=i.getOrGenerateKey(r.value.trim(),t,d,g);_.push({path:e,key:n,type:`jsx-attribute`,componentKey:t})}},StringLiteral(e){if(v.has(e.node))return;let t=e.node.value;if(!o.shouldExtract(t))return;let n=e.parentPath;if(n.isImportDeclaration()||n.isImportSpecifier()||n.isExportDeclaration()||n.isJSXAttribute()||n.isCallExpression()&&c.isMemberExpression(n.node.callee)&&c.isIdentifier(n.node.callee.object)&&n.node.callee.object.name===`console`&&c.isIdentifier(n.node.callee.property)&&n.node.callee.property.name===`log`||n.isObjectProperty()&&n.node.key===e.node||n.isMemberExpression()&&n.node.property===e.node)return;let r=w(e),a=i.getOrGenerateKey(t.trim(),r,d,g);_.push({path:e,key:a,type:`string-literal`,componentKey:r})}});let T=new Set;for(let e of C)if(_.some(t=>{let n=t.path;for(;n;){if(n.node===e.node)return!0;n=n.parentPath}return!1})){let t=y.get(e.node),n=!1,i=e.parentPath;for(;i;){let e=C.find(e=>e.node===i?.node);if(e&&y.get(e.node)===t){let t=_.some(t=>{let n=t.path;for(;n;){if(n.node===e.node)return!0;n=n.parentPath}return!1}),i=r.getExistingIntlayerInfo(e);if(t||i){n=!0;break}}i=i.parentPath}n||T.add(e)}return{extractedContent:g,replacements:_,componentsNeedingHooks:T,componentKeyMap:y,componentPaths:C,hookMap:b,isSolid:!1}},f=(e,t,n,r,i,a={})=>{let{extractedContent:o,replacements:s}=d(e,t,n,`default`,r,i,a),c={};for(let e of Object.values(o))Object.assign(c,e);return{extractedContent:c,replacements:s}};exports.extractBabelContentForComponents=d,exports.extractTsContent=f,exports.handleJsxInsertionBabel=u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`./utils/constants.cjs`),n=require(`./utils/getComponentName.cjs`),r=require(`./utils/getExistingIntlayerInfo.cjs`),i=require(`./utils/getOrGenerateKey.cjs`),a=require(`./utils/resolveDictionaryKey.cjs`),o=require(`./utils/shouldExtract.cjs`);let s=require(`@babel/traverse`);s=e.t(s);let c=require(`@babel/types`);c=e.t(c);const l=typeof s.default==`function`?s.default:s.default.default,u=(e,t,n,r,a,s,l)=>{let u=e.node.children;if(u.length<=1)return!1;let d=[],f=!1,p=!1;for(let e of u)if(c.isJSXText(e)){let t=e.value;t.trim().length>0&&(f=!0),d.push({type:`text`,value:t})}else if(c.isJSXExpressionContainer(e))if(c.isJSXEmptyExpression(e.expression))d.push({type:`text`,value:``});else{let n=e.expression;if(c.isIdentifier(n))d.push({type:`var`,value:n.name,originalExpr:n.name}),p=!0;else if(c.isMemberExpression(n)){let e=t.substring(n.start,n.end),r=c.isIdentifier(n.property)?n.property.name:`var`;d.push({type:`var`,value:r,originalExpr:e}),p=!0}else return!1}else return!1;if(!f)return!1;let m=``;for(let e of d)e.type===`var`?m+=`{{${e.value}}}`:m+=e.value;let h=m.replace(/\s+/g,` `).trim();if(o.shouldExtract(h)){let t=r(e),o=i.getOrGenerateKey(h,t,n,a),c=d.filter(e=>e.type===`var`).map(e=>`${e.value}: ${e.originalExpr}`),f=Array.from(new Set(c));return p?s.push({path:e,key:o,type:`jsx-insertion`,componentKey:t,childrenToReplace:u,variables:f}):s.push({path:e,key:o,type:`jsx-text-combined`,componentKey:t,childrenToReplace:u}),u.forEach(e=>{l.add(e)}),!0}return!1},d=(e,s,d,f=`default`,p,m,h={})=>{let g={},_=[],v=new Set,y=new Map,b=new Map,x=new Set,S,C=[];l(e,{FunctionDeclaration(e){C.push(e)},ArrowFunctionExpression(e){C.push(e)},FunctionExpression(e){C.push(e)}});for(let e of C){let t=r.getExistingIntlayerInfo(e);if(t)y.set(e.node,t.key),x.add(t.key),b.set(e.node,t.hook);else{S||(S=a.resolveDictionaryKey(f,m,p,h,x),x.add(S)),y.set(e.node,S);let t=n.getComponentName(e),r=t?/^[A-Z]/.test(t):!1;b.set(e.node,r?`useIntlayer`:`getIntlayer`)}}let w=e=>{let t=e;for(;t;){if(y.has(t.node))return y.get(t.node);t=t.parentPath}return S||f};l(e,{JSXElement(e){v.has(e.node)||u(e,s,d,w,g,_,v)},JSXFragment(e){v.has(e.node)||u(e,s,d,w,g,_,v)},JSXText(e){if(v.has(e.node))return;let t=e.node.value;if(o.shouldExtract(t)){let n=w(e),r=i.getOrGenerateKey(t.replace(/\s+/g,` `).trim(),n,d,g);_.push({path:e,key:r,type:`jsx-text`,componentKey:n})}},JSXAttribute(e){if(v.has(e.node))return;let n=e.node.name.name;if(typeof n!=`string`||!t.ATTRIBUTES_TO_EXTRACT.includes(n))return;let r=e.node.value;if(c.isStringLiteral(r)&&o.shouldExtract(r.value)){let t=w(e),n=i.getOrGenerateKey(r.value.trim(),t,d,g);_.push({path:e,key:n,type:`jsx-attribute`,componentKey:t})}},StringLiteral(e){if(v.has(e.node))return;let t=e.node.value;if(!o.shouldExtract(t))return;let n=e.parentPath;if(n.isImportDeclaration()||n.isImportSpecifier()||n.isExportDeclaration()||n.isJSXAttribute()||n.isCallExpression()&&c.isMemberExpression(n.node.callee)&&c.isIdentifier(n.node.callee.object)&&n.node.callee.object.name===`console`&&c.isIdentifier(n.node.callee.property)&&n.node.callee.property.name===`log`||n.isObjectProperty()&&n.node.key===e.node||n.isMemberExpression()&&n.node.property===e.node)return;let r=w(e),a=i.getOrGenerateKey(t.trim(),r,d,g);_.push({path:e,key:a,type:`string-literal`,componentKey:r})}});let T=new Set;for(let e of C)if(_.some(t=>{let n=t.path;for(;n;){if(n.node===e.node)return!0;n=n.parentPath}return!1})){let t=y.get(e.node),n=!1,i=e.parentPath;for(;i;){let e=C.find(e=>e.node===i?.node);if(e&&y.get(e.node)===t){let t=_.some(t=>{let n=t.path;for(;n;){if(n.node===e.node)return!0;n=n.parentPath}return!1}),i=r.getExistingIntlayerInfo(e);if(t||i){n=!0;break}}i=i.parentPath}n||T.add(e)}return{extractedContent:g,replacements:_,componentsNeedingHooks:T,componentKeyMap:y,componentPaths:C,hookMap:b,isSolid:!1}},f=(e,t,n,r,i,a={})=>{let{extractedContent:o,replacements:s}=d(e,t,n,`default`,r,i,a),c={};for(let e of Object.values(o))Object.assign(c,e);return{extractedContent:c,replacements:s}};exports.extractBabelContentForComponents=d,exports.extractTsContent=f,exports.handleJsxInsertionBabel=u;
2
2
  //# sourceMappingURL=babelProcessor.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"babelProcessor.cjs","names":["_traverse","t","shouldExtract","getOrGenerateKey","getExistingIntlayerInfo","resolveDictionaryKey","getComponentName","ATTRIBUTES_TO_EXTRACT"],"sources":["../../../src/extractContent/babelProcessor.ts"],"sourcesContent":["import _traverse, { type NodePath } from '@babel/traverse';\nimport * as t from '@babel/types';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { resolveDictionaryKey } from '../extractContent/utils';\nimport {\n ATTRIBUTES_TO_EXTRACT,\n getComponentName,\n getExistingIntlayerInfo,\n getOrGenerateKey,\n shouldExtract,\n} from './utils';\n\nexport type BabelReplacement = {\n path: NodePath;\n key: string;\n type:\n | 'jsx-text'\n | 'jsx-attribute'\n | 'string-literal'\n | 'jsx-insertion'\n | 'jsx-text-combined';\n componentKey: string;\n childrenToReplace?: t.Node[];\n variables?: string[];\n};\n\n// CJS/ESM interop: @babel/traverse exports its function as `.default` in CJS bundles\nconst traverse = (\n typeof _traverse === 'function' ? _traverse : (_traverse as any).default\n) as typeof _traverse;\n\n/**\n * Handles JSX insertions (elements with multiple children, including expressions).\n * Replaces complex JSX structures with variable-based translations.\n */\nexport const handleJsxInsertionBabel = (\n path: NodePath<t.JSXElement | t.JSXFragment>,\n fileCode: string,\n existingKeys: Set<string>,\n getComponentKeyForPath: (path: NodePath) => string,\n extractedContent: Record<string, Record<string, string>>,\n replacements: BabelReplacement[],\n handledNodes: Set<t.Node>\n): boolean => {\n const children = path.node.children;\n\n if (children.length <= 1) return false;\n\n const parts: {\n type: 'text' | 'var';\n value: string;\n originalExpr?: string;\n }[] = [];\n let hasSignificantText = false;\n let hasVariables = false;\n\n for (const child of children) {\n if (t.isJSXText(child)) {\n const text = child.value;\n\n if (text.trim().length > 0) hasSignificantText = true;\n\n parts.push({ type: 'text', value: text });\n } else if (t.isJSXExpressionContainer(child)) {\n if (t.isJSXEmptyExpression(child.expression)) {\n parts.push({ type: 'text', value: '' });\n } else {\n const expr = child.expression;\n\n if (t.isIdentifier(expr)) {\n parts.push({\n type: 'var',\n value: expr.name,\n originalExpr: expr.name,\n });\n hasVariables = true;\n } else if (t.isMemberExpression(expr)) {\n const code = fileCode.substring(expr.start!, expr.end!);\n\n const varName = t.isIdentifier(expr.property)\n ? expr.property.name\n : 'var';\n\n parts.push({ type: 'var', value: varName, originalExpr: code });\n\n hasVariables = true;\n } else {\n return false;\n }\n }\n } else {\n return false;\n }\n }\n\n if (!hasSignificantText) return false;\n\n let combinedString = '';\n for (const part of parts) {\n if (part.type === 'var') combinedString += `{{${part.value}}}`;\n else combinedString += part.value;\n }\n\n const cleanString = combinedString.replace(/\\s+/g, ' ').trim();\n\n if (shouldExtract(cleanString)) {\n const componentKey = getComponentKeyForPath(path);\n const key = getOrGenerateKey(\n cleanString,\n componentKey,\n existingKeys,\n extractedContent\n );\n\n const varMap = parts\n .filter((part) => part.type === 'var')\n .map((part) => `${part.value}: ${part.originalExpr}`);\n const uniqueVars = Array.from(new Set(varMap));\n\n if (hasVariables) {\n replacements.push({\n path,\n key,\n type: 'jsx-insertion',\n componentKey,\n childrenToReplace: children,\n variables: uniqueVars,\n });\n } else {\n replacements.push({\n path,\n key,\n type: 'jsx-text-combined',\n componentKey,\n childrenToReplace: children,\n });\n }\n\n children.forEach((child) => {\n handledNodes.add(child);\n });\n return true;\n }\n\n return false;\n};\n\n/**\n * Traverses the AST to identify components and extract content.\n * Returns extraction results and metadata about which components need Intlayer hooks.\n */\nexport const extractBabelContentForComponents = (\n ast: t.File,\n fileCode: string,\n existingKeys: Set<string>,\n defaultKey: string = 'default',\n configuration: IntlayerConfig,\n filePath: string,\n unmergedDictionaries: Record<string, unknown> = {}\n): {\n extractedContent: Record<string, Record<string, string>>;\n replacements: BabelReplacement[];\n componentsNeedingHooks: Set<NodePath>;\n componentKeyMap: Map<t.Node, string>;\n componentPaths: NodePath[];\n hookMap: Map<t.Node, 'useIntlayer' | 'getIntlayer'>;\n isSolid: boolean;\n} => {\n const extractedContent: Record<string, Record<string, string>> = {};\n const replacements: BabelReplacement[] = [];\n const handledNodes = new Set<t.Node>();\n const componentKeyMap = new Map<t.Node, string>();\n const hookMap = new Map<t.Node, 'useIntlayer' | 'getIntlayer'>();\n const usedKeysInFile = new Set<string>();\n let globalFileKey: string | undefined;\n\n const componentPaths: NodePath[] = [];\n\n traverse(ast, {\n FunctionDeclaration(path) {\n componentPaths.push(path);\n },\n ArrowFunctionExpression(path) {\n componentPaths.push(path);\n },\n FunctionExpression(path) {\n componentPaths.push(path);\n },\n });\n\n for (const path of componentPaths) {\n const existingInfo = getExistingIntlayerInfo(path);\n\n if (existingInfo) {\n componentKeyMap.set(path.node, existingInfo.key);\n usedKeysInFile.add(existingInfo.key);\n hookMap.set(path.node, existingInfo.hook);\n } else {\n if (!globalFileKey) {\n globalFileKey = resolveDictionaryKey(\n defaultKey,\n filePath,\n configuration,\n unmergedDictionaries,\n usedKeysInFile\n );\n usedKeysInFile.add(globalFileKey);\n }\n componentKeyMap.set(path.node, globalFileKey);\n\n const compName = getComponentName(path);\n const isComponent = compName ? /^[A-Z]/.test(compName) : false;\n hookMap.set(path.node, isComponent ? 'useIntlayer' : 'getIntlayer');\n }\n }\n\n const getComponentKeyForPath = (path: NodePath): string => {\n let current: NodePath | null = path;\n while (current) {\n if (componentKeyMap.has(current.node)) {\n return componentKeyMap.get(current.node)!;\n }\n current = current.parentPath;\n }\n return globalFileKey || defaultKey;\n };\n\n traverse(ast, {\n JSXElement(path) {\n if (handledNodes.has(path.node)) return;\n\n handleJsxInsertionBabel(\n path,\n fileCode,\n existingKeys,\n getComponentKeyForPath,\n extractedContent,\n replacements,\n handledNodes\n );\n },\n JSXFragment(path) {\n if (handledNodes.has(path.node)) return;\n\n handleJsxInsertionBabel(\n path,\n fileCode,\n existingKeys,\n getComponentKeyForPath,\n extractedContent,\n replacements,\n handledNodes\n );\n },\n JSXText(path) {\n if (handledNodes.has(path.node)) return;\n\n const text = path.node.value;\n\n if (shouldExtract(text)) {\n const componentKey = getComponentKeyForPath(path);\n const key = getOrGenerateKey(\n text.replace(/\\s+/g, ' ').trim(),\n componentKey,\n existingKeys,\n extractedContent\n );\n replacements.push({ path, key, type: 'jsx-text', componentKey });\n }\n },\n JSXAttribute(path) {\n if (handledNodes.has(path.node)) return;\n\n const name = path.node.name.name;\n\n if (\n typeof name !== 'string' ||\n !ATTRIBUTES_TO_EXTRACT.includes(name as any)\n )\n return;\n const value = path.node.value;\n\n if (t.isStringLiteral(value) && shouldExtract(value.value)) {\n const componentKey = getComponentKeyForPath(path);\n const key = getOrGenerateKey(\n value.value.trim(),\n componentKey,\n existingKeys,\n extractedContent\n );\n replacements.push({ path, key, type: 'jsx-attribute', componentKey });\n }\n },\n StringLiteral(path) {\n if (handledNodes.has(path.node)) return;\n\n const text = path.node.value;\n\n if (!shouldExtract(text)) return;\n\n const parent = path.parentPath;\n\n if (\n parent.isImportDeclaration() ||\n parent.isImportSpecifier() ||\n parent.isExportDeclaration()\n )\n return;\n\n if (parent.isJSXAttribute()) return;\n\n if (\n parent.isCallExpression() &&\n t.isMemberExpression(parent.node.callee)\n ) {\n if (\n t.isIdentifier(parent.node.callee.object) &&\n parent.node.callee.object.name === 'console' &&\n t.isIdentifier(parent.node.callee.property) &&\n parent.node.callee.property.name === 'log'\n ) {\n return;\n }\n }\n\n if (parent.isObjectProperty() && parent.node.key === path.node) return;\n\n if (parent.isMemberExpression() && parent.node.property === path.node)\n return;\n\n const componentKey = getComponentKeyForPath(path);\n const key = getOrGenerateKey(\n text.trim(),\n componentKey,\n existingKeys,\n extractedContent\n );\n replacements.push({ path, key, type: 'string-literal', componentKey });\n },\n });\n\n const componentsNeedingHooks = new Set<NodePath>();\n for (const componentPath of componentPaths) {\n const hasReplacements = replacements.some((replacement) => {\n let current: NodePath | null = replacement.path;\n while (current) {\n if (current.node === componentPath.node) return true;\n\n current = current.parentPath;\n }\n return false;\n });\n\n if (hasReplacements) {\n const key = componentKeyMap.get(componentPath.node)!;\n let ancestorProvidesKey = false;\n let currentPath: NodePath | null = componentPath.parentPath;\n while (currentPath) {\n const ancestorPath = componentPaths.find(\n (path) => path.node === currentPath?.node\n );\n\n if (ancestorPath) {\n const ancestorKey = componentKeyMap.get(ancestorPath.node);\n\n if (ancestorKey === key) {\n const ancestorHasReplacements = replacements.some((replacement) => {\n let rPath: NodePath | null = replacement.path;\n while (rPath) {\n if (rPath.node === ancestorPath.node) return true;\n\n rPath = rPath.parentPath;\n }\n return false;\n });\n const existingInfo = getExistingIntlayerInfo(ancestorPath);\n\n if (ancestorHasReplacements || existingInfo) {\n ancestorProvidesKey = true;\n break;\n }\n }\n }\n currentPath = currentPath.parentPath;\n }\n\n if (!ancestorProvidesKey) {\n componentsNeedingHooks.add(componentPath);\n }\n }\n }\n\n return {\n extractedContent,\n replacements,\n componentsNeedingHooks,\n componentKeyMap,\n componentPaths,\n hookMap,\n isSolid: false,\n };\n};\n\n/**\n * High-level function to extract content from TS/JS/JSX/TSX AST.\n */\nexport const extractTsContent = (\n ast: t.File,\n fileCode: string,\n existingKeys: Set<string>,\n configuration: IntlayerConfig,\n filePath: string,\n unmergedDictionaries: Record<string, unknown> = {}\n): {\n extractedContent: Record<string, string>;\n replacements: BabelReplacement[];\n} => {\n const { extractedContent, replacements } = extractBabelContentForComponents(\n ast,\n fileCode,\n existingKeys,\n 'default',\n configuration,\n filePath,\n unmergedDictionaries\n );\n\n const flatContent: Record<string, string> = {};\n for (const group of Object.values(extractedContent)) {\n Object.assign(flatContent, group);\n }\n\n return { extractedContent: flatContent, replacements };\n};\n"],"mappings":"kdA2BA,MAAM,EACJ,OAAOA,EAAAA,SAAc,WAAaA,EAAAA,QAAaA,EAAAA,QAAkB,QAOtD,GACX,EACA,EACA,EACA,EACA,EACA,EACA,IACY,CACZ,IAAM,EAAW,EAAK,KAAK,SAE3B,GAAI,EAAS,QAAU,EAAG,MAAO,GAEjC,IAAM,EAIA,EAAE,CACJ,EAAqB,GACrB,EAAe,GAEnB,IAAK,IAAM,KAAS,EAClB,GAAIC,EAAE,UAAU,EAAM,CAAE,CACtB,IAAM,EAAO,EAAM,MAEf,EAAK,MAAM,CAA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ACA,EACA,UACA,EACA,EACA,EACD,CAEK,EAAsC,EAAE,CAC9C,IAAK,IAAM,KAAS,OAAO,OAAO,EAAiB,CACjD,OAAO,OAAO,EAAa,EAAM,CAGnC,MAAO,CAAE,iBAAkB,EAAa,eAAc"}
1
+ {"version":3,"file":"babelProcessor.cjs","names":["_traverse","t","shouldExtract","getOrGenerateKey","getExistingIntlayerInfo","resolveDictionaryKey","getComponentName","ATTRIBUTES_TO_EXTRACT"],"sources":["../../../src/extractContent/babelProcessor.ts"],"sourcesContent":["import _traverse, { type NodePath } from '@babel/traverse';\nimport * as t from '@babel/types';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { resolveDictionaryKey } from '../extractContent/utils';\nimport {\n ATTRIBUTES_TO_EXTRACT,\n getComponentName,\n getExistingIntlayerInfo,\n getOrGenerateKey,\n shouldExtract,\n} from './utils';\n\nexport type BabelReplacement = {\n path: NodePath;\n key: string;\n type:\n | 'jsx-text'\n | 'jsx-attribute'\n | 'string-literal'\n | 'jsx-insertion'\n | 'jsx-text-combined';\n componentKey: string;\n childrenToReplace?: t.Node[];\n variables?: string[];\n};\n\n// CJS/ESM interop: @babel/traverse exports its function as `.default` in CJS bundles\nconst traverse = (\n typeof _traverse === 'function' ? _traverse : (_traverse as any).default\n) as typeof _traverse;\n\n/**\n * Handles JSX insertions (elements with multiple children, including expressions).\n * Replaces complex JSX structures with variable-based translations.\n */\nexport const handleJsxInsertionBabel = (\n path: NodePath<t.JSXElement | t.JSXFragment>,\n fileCode: string,\n existingKeys: Set<string>,\n getComponentKeyForPath: (path: NodePath) => string,\n extractedContent: Record<string, Record<string, string>>,\n replacements: BabelReplacement[],\n handledNodes: Set<t.Node>\n): boolean => {\n const children = path.node.children;\n\n if (children.length <= 1) return false;\n\n const parts: {\n type: 'text' | 'var';\n value: string;\n originalExpr?: string;\n }[] = [];\n let hasSignificantText = false;\n let hasVariables = false;\n\n for (const child of children) {\n if (t.isJSXText(child)) {\n const text = child.value;\n\n if (text.trim().length > 0) hasSignificantText = true;\n\n parts.push({ type: 'text', value: text });\n } else if (t.isJSXExpressionContainer(child)) {\n if (t.isJSXEmptyExpression(child.expression)) {\n parts.push({ type: 'text', value: '' });\n } else {\n const expr = child.expression;\n\n if (t.isIdentifier(expr)) {\n parts.push({\n type: 'var',\n value: expr.name,\n originalExpr: expr.name,\n });\n hasVariables = true;\n } else if (t.isMemberExpression(expr)) {\n const code = fileCode.substring(expr.start!, expr.end!);\n\n const varName = t.isIdentifier(expr.property)\n ? expr.property.name\n : 'var';\n\n parts.push({ type: 'var', value: varName, originalExpr: code });\n\n hasVariables = true;\n } else {\n return false;\n }\n }\n } else {\n return false;\n }\n }\n\n if (!hasSignificantText) return false;\n\n let combinedString = '';\n for (const part of parts) {\n if (part.type === 'var') combinedString += `{{${part.value}}}`;\n else combinedString += part.value;\n }\n\n const cleanString = combinedString.replace(/\\s+/g, ' ').trim();\n\n if (shouldExtract(cleanString)) {\n const componentKey = getComponentKeyForPath(path);\n const key = getOrGenerateKey(\n cleanString,\n componentKey,\n existingKeys,\n extractedContent\n );\n\n const varMap = parts\n .filter((part) => part.type === 'var')\n .map((part) => `${part.value}: ${part.originalExpr}`);\n const uniqueVars = Array.from(new Set(varMap));\n\n if (hasVariables) {\n replacements.push({\n path,\n key,\n type: 'jsx-insertion',\n componentKey,\n childrenToReplace: children,\n variables: uniqueVars,\n });\n } else {\n replacements.push({\n path,\n key,\n type: 'jsx-text-combined',\n componentKey,\n childrenToReplace: children,\n });\n }\n\n children.forEach((child) => {\n handledNodes.add(child);\n });\n return true;\n }\n\n return false;\n};\n\n/**\n * Traverses the AST to identify components and extract content.\n * Returns extraction results and metadata about which components need Intlayer hooks.\n */\nexport const extractBabelContentForComponents = (\n ast: t.File,\n fileCode: string,\n existingKeys: Set<string>,\n defaultKey: string = 'default',\n configuration: IntlayerConfig,\n filePath: string,\n unmergedDictionaries: Record<string, unknown> = {}\n): {\n extractedContent: Record<string, Record<string, string>>;\n replacements: BabelReplacement[];\n componentsNeedingHooks: Set<NodePath>;\n componentKeyMap: Map<t.Node, string>;\n componentPaths: NodePath[];\n hookMap: Map<t.Node, 'useIntlayer' | 'getIntlayer'>;\n isSolid: boolean;\n} => {\n const extractedContent: Record<string, Record<string, string>> = {};\n const replacements: BabelReplacement[] = [];\n const handledNodes = new Set<t.Node>();\n const componentKeyMap = new Map<t.Node, string>();\n const hookMap = new Map<t.Node, 'useIntlayer' | 'getIntlayer'>();\n const usedKeysInFile = new Set<string>();\n let globalFileKey: string | undefined;\n\n const componentPaths: NodePath[] = [];\n\n traverse(ast, {\n FunctionDeclaration(path) {\n componentPaths.push(path);\n },\n ArrowFunctionExpression(path) {\n componentPaths.push(path);\n },\n FunctionExpression(path) {\n componentPaths.push(path);\n },\n });\n\n for (const path of componentPaths) {\n const existingInfo = getExistingIntlayerInfo(path);\n\n if (existingInfo) {\n componentKeyMap.set(path.node, existingInfo.key);\n usedKeysInFile.add(existingInfo.key);\n hookMap.set(path.node, existingInfo.hook);\n } else {\n if (!globalFileKey) {\n globalFileKey = resolveDictionaryKey(\n defaultKey,\n filePath,\n configuration,\n unmergedDictionaries,\n usedKeysInFile\n );\n usedKeysInFile.add(globalFileKey);\n }\n componentKeyMap.set(path.node, globalFileKey);\n\n const compName = getComponentName(path);\n const isComponent = compName ? /^[A-Z]/.test(compName) : false;\n hookMap.set(path.node, isComponent ? 'useIntlayer' : 'getIntlayer');\n }\n }\n\n const getComponentKeyForPath = (path: NodePath): string => {\n let current: NodePath | null = path;\n while (current) {\n if (componentKeyMap.has(current.node)) {\n return componentKeyMap.get(current.node)!;\n }\n current = current.parentPath;\n }\n return globalFileKey || defaultKey;\n };\n\n traverse(ast, {\n JSXElement(path) {\n if (handledNodes.has(path.node)) return;\n\n handleJsxInsertionBabel(\n path,\n fileCode,\n existingKeys,\n getComponentKeyForPath,\n extractedContent,\n replacements,\n handledNodes\n );\n },\n JSXFragment(path) {\n if (handledNodes.has(path.node)) return;\n\n handleJsxInsertionBabel(\n path,\n fileCode,\n existingKeys,\n getComponentKeyForPath,\n extractedContent,\n replacements,\n handledNodes\n );\n },\n JSXText(path) {\n if (handledNodes.has(path.node)) return;\n\n const text = path.node.value;\n\n if (shouldExtract(text)) {\n const componentKey = getComponentKeyForPath(path);\n const key = getOrGenerateKey(\n text.replace(/\\s+/g, ' ').trim(),\n componentKey,\n existingKeys,\n extractedContent\n );\n replacements.push({ path, key, type: 'jsx-text', componentKey });\n }\n },\n JSXAttribute(path) {\n if (handledNodes.has(path.node)) return;\n\n const name = path.node.name.name;\n\n if (\n typeof name !== 'string' ||\n !ATTRIBUTES_TO_EXTRACT.includes(name as any)\n )\n return;\n const value = path.node.value;\n\n if (t.isStringLiteral(value) && shouldExtract(value.value)) {\n const componentKey = getComponentKeyForPath(path);\n const key = getOrGenerateKey(\n value.value.trim(),\n componentKey,\n existingKeys,\n extractedContent\n );\n replacements.push({ path, key, type: 'jsx-attribute', componentKey });\n }\n },\n StringLiteral(path) {\n if (handledNodes.has(path.node)) return;\n\n const text = path.node.value;\n\n if (!shouldExtract(text)) return;\n\n const parent = path.parentPath;\n\n if (\n parent.isImportDeclaration() ||\n parent.isImportSpecifier() ||\n parent.isExportDeclaration()\n )\n return;\n\n if (parent.isJSXAttribute()) return;\n\n if (\n parent.isCallExpression() &&\n t.isMemberExpression(parent.node.callee)\n ) {\n if (\n t.isIdentifier(parent.node.callee.object) &&\n parent.node.callee.object.name === 'console' &&\n t.isIdentifier(parent.node.callee.property) &&\n parent.node.callee.property.name === 'log'\n ) {\n return;\n }\n }\n\n if (parent.isObjectProperty() && parent.node.key === path.node) return;\n\n if (parent.isMemberExpression() && parent.node.property === path.node)\n return;\n\n const componentKey = getComponentKeyForPath(path);\n const key = getOrGenerateKey(\n text.trim(),\n componentKey,\n existingKeys,\n extractedContent\n );\n replacements.push({ path, key, type: 'string-literal', componentKey });\n },\n });\n\n const componentsNeedingHooks = new Set<NodePath>();\n for (const componentPath of componentPaths) {\n const hasReplacements = replacements.some((replacement) => {\n let current: NodePath | null = replacement.path;\n while (current) {\n if (current.node === componentPath.node) return true;\n\n current = current.parentPath;\n }\n return false;\n });\n\n if (hasReplacements) {\n const key = componentKeyMap.get(componentPath.node)!;\n let ancestorProvidesKey = false;\n let currentPath: NodePath | null = componentPath.parentPath;\n while (currentPath) {\n const ancestorPath = componentPaths.find(\n (path) => path.node === currentPath?.node\n );\n\n if (ancestorPath) {\n const ancestorKey = componentKeyMap.get(ancestorPath.node);\n\n if (ancestorKey === key) {\n const ancestorHasReplacements = replacements.some((replacement) => {\n let rPath: NodePath | null = replacement.path;\n while (rPath) {\n if (rPath.node === ancestorPath.node) return true;\n\n rPath = rPath.parentPath;\n }\n return false;\n });\n const existingInfo = getExistingIntlayerInfo(ancestorPath);\n\n if (ancestorHasReplacements || existingInfo) {\n ancestorProvidesKey = true;\n break;\n }\n }\n }\n currentPath = currentPath.parentPath;\n }\n\n if (!ancestorProvidesKey) {\n componentsNeedingHooks.add(componentPath);\n }\n }\n }\n\n return {\n extractedContent,\n replacements,\n componentsNeedingHooks,\n componentKeyMap,\n componentPaths,\n hookMap,\n isSolid: false,\n };\n};\n\n/**\n * High-level function to extract content from TS/JS/JSX/TSX AST.\n */\nexport const extractTsContent = (\n ast: t.File,\n fileCode: string,\n existingKeys: Set<string>,\n configuration: IntlayerConfig,\n filePath: string,\n unmergedDictionaries: Record<string, unknown> = {}\n): {\n extractedContent: Record<string, string>;\n replacements: BabelReplacement[];\n} => {\n const { extractedContent, replacements } = extractBabelContentForComponents(\n ast,\n fileCode,\n existingKeys,\n 'default',\n configuration,\n filePath,\n unmergedDictionaries\n );\n\n const flatContent: Record<string, string> = {};\n for (const group of Object.values(extractedContent)) {\n Object.assign(flatContent, group);\n }\n\n return { extractedContent: flatContent, replacements };\n};\n"],"mappings":"0bA2BA,MAAM,EACJ,OAAOA,EAAAA,SAAc,WAAaA,EAAAA,QAAaA,EAAAA,QAAkB,QAOtD,GACX,EACA,EACA,EACA,EACA,EACA,EACA,IACY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,EAAsB,GACtB,OAIN,EAAc,EAAY,WAGvB,GACH,EAAuB,IAAI,EAAc,CAK/C,MAAO,CACL,mBACA,eACA,yBACA,kBACA,iBACA,UACA,QAAS,GACV,EAMU,GACX,EACA,EACA,EACA,EACA,EACA,EAAgD,EAAE,GAI/C,CACH,GAAM,CAAE,mBAAkB,gBAAiB,EACzC,EACA,EACA,EACA,UACA,EACA,EACA,EACD,CAEK,EAAsC,EAAE,CAC9C,IAAK,IAAM,KAAS,OAAO,OAAO,EAAiB,CACjD,OAAO,OAAO,EAAa,EAAM,CAGnC,MAAO,CAAE,iBAAkB,EAAa,eAAc"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./utils/extractDictionaryInfo.cjs`);let t=require(`node:fs`),n=require(`node:fs/promises`),r=require(`node:path`),i=require(`@intlayer/chokidar/build`),a=require(`@intlayer/core/plugins`),o=require(`@intlayer/types/nodeType`);const s=e=>/\{\{[^}]+\}\}/.test(e),c=e=>{let t=[],n=/\{\{([^}]+)\}\}/g,r;for(let i=n.exec(e);i!==null;i=n.exec(e)){r=i;let e=r[1].trim();t.includes(e)||t.push(e)}return t};let l;const u=(e,t,n)=>{let r=(0,a.insertContentInDictionary)(t??{key:``,content:{},filePath:``},e,n).content,i={};for(let t in e)i[t]=r[t];for(let t in e){let n=e[t];if(typeof n==`string`&&s(n)){let e=i[t];e&&e.nodeType===o.NodeType.Translation&&(i[t]={nodeType:o.NodeType.Insertion,[o.NodeType.Insertion]:e,fields:c(n)})}}return i},d=(e,t)=>{let n=(0,a.insertContentInDictionary)(t??{key:``,content:{},filePath:``},e).content,r={};for(let t in e)r[t]=n[t];for(let t in e){let n=e[t];if(typeof n==`string`&&s(n)){let e=r[t];typeof e==`string`&&(r[t]={nodeType:o.NodeType.Insertion,[o.NodeType.Insertion]:e,fields:c(n)})}}return r},f=async(a,o,s,c)=>{let{absolutePath:f,isPerLocale:p}=await e.resolveContentFilePaths(s,o,c),{defaultLocale:m}=c.internationalization,{baseDir:h}=c.system;l||=await(0,i.ensureIntlayerBundle)(c);let g=(0,r.dirname)(f);await(0,n.mkdir)(g,{recursive:!0});let _=null;if((0,t.existsSync)(f))try{_=await(0,i.loadContentDeclaration)(f,c,l)??null}catch(e){console.error(e)}let v=(0,r.relative)(h,f),y;if(p){let e=d(a,_);y={..._,key:o,content:e,locale:m,filePath:v}}else{let e=u(a,_,m);y={..._,key:o,content:e,filePath:v}}let b=(0,r.relative)(h,g),x=await(0,i.writeContentDeclaration)(y,c,{newDictionariesPath:b,localeList:[m]});return await(0,i.buildDictionary)([{...y,filePath:(0,r.relative)(h,x?.path??f)}],c),f};exports.mergeWithExistingMultilingualDictionary=u,exports.mergeWithExistingPerLocaleDictionary=d,exports.writeContentHelper=f;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-Bmb41Sf3.cjs`);const e=require(`./utils/extractDictionaryInfo.cjs`);let t=require(`node:fs`),n=require(`node:fs/promises`),r=require(`node:path`),i=require(`@intlayer/chokidar/build`),a=require(`@intlayer/core/plugins`),o=require(`@intlayer/types/nodeType`);const s=e=>/\{\{[^}]+\}\}/.test(e),c=e=>{let t=[],n=/\{\{([^}]+)\}\}/g,r;for(let i=n.exec(e);i!==null;i=n.exec(e)){r=i;let e=r[1].trim();t.includes(e)||t.push(e)}return t};let l;const u=(e,t,n)=>{let r=(0,a.insertContentInDictionary)(t??{key:``,content:{},filePath:``},e,n).content,i={};for(let t in e)i[t]=r[t];for(let t in e){let n=e[t];if(typeof n==`string`&&s(n)){let e=i[t];e&&e.nodeType===o.NodeType.Translation&&(i[t]={nodeType:o.NodeType.Insertion,[o.NodeType.Insertion]:e,fields:c(n)})}}return i},d=(e,t)=>{let n=(0,a.insertContentInDictionary)(t??{key:``,content:{},filePath:``},e).content,r={};for(let t in e)r[t]=n[t];for(let t in e){let n=e[t];if(typeof n==`string`&&s(n)){let e=r[t];typeof e==`string`&&(r[t]={nodeType:o.NodeType.Insertion,[o.NodeType.Insertion]:e,fields:c(n)})}}return r},f=async(a,o,s,c)=>{let{absolutePath:f,isPerLocale:p}=await e.resolveContentFilePaths(s,o,c),{defaultLocale:m}=c.internationalization,{baseDir:h}=c.system;l||=await(0,i.ensureIntlayerBundle)(c);let g=(0,r.dirname)(f);await(0,n.mkdir)(g,{recursive:!0});let _=null;if((0,t.existsSync)(f))try{_=await(0,i.loadContentDeclaration)(f,c,l)??null}catch(e){console.error(e)}let v=(0,r.relative)(h,f),y;if(p){let e=d(a,_);y={..._,key:o,content:e,locale:m,filePath:v}}else{let e=u(a,_,m);y={..._,key:o,content:e,filePath:v}}let b=(0,r.relative)(h,g),x=await(0,i.writeContentDeclaration)(y,c,{newDictionariesPath:b,localeList:[m]});return await(0,i.buildDictionary)([{...y,filePath:(0,r.relative)(h,x?.path??f)}],c),f};exports.mergeWithExistingMultilingualDictionary=u,exports.mergeWithExistingPerLocaleDictionary=d,exports.writeContentHelper=f;
2
2
  //# sourceMappingURL=contentWriter.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"contentWriter.cjs","names":["NodeType","resolveContentFilePaths"],"sources":["../../../src/extractContent/contentWriter.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport {\n buildDictionary,\n ensureIntlayerBundle,\n loadContentDeclaration,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport { insertContentInDictionary } from '@intlayer/core/plugins';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary, DictionaryKey } from '@intlayer/types/dictionary';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport { resolveContentFilePaths } from './utils/extractDictionaryInfo';\n\nconst hasInsertionVars = (str: string): boolean => /\\{\\{[^}]+\\}\\}/.test(str);\n\nconst getInsertionFields = (template: string): string[] => {\n const fields: string[] = [];\n const regex = /\\{\\{([^}]+)\\}\\}/g;\n let match: RegExpExecArray | null;\n for (\n let result = regex.exec(template);\n result !== null;\n result = regex.exec(template)\n ) {\n match = result;\n const field = match[1].trim();\n if (!fields.includes(field)) fields.push(field);\n }\n return fields;\n};\n\n/**\n * Translation node structure used in dictionaries\n */\ntype TranslationNode = {\n nodeType: 'translation';\n translation: Record<string, string>;\n};\n\n/**\n * Dictionary content structure - map of keys to translation nodes\n */\ntype DictionaryContentMap = Record<string, TranslationNode>;\n\n/**\n * Cached bundle file path to optimize performance\n */\nlet cachedBundleFilePath: string | undefined;\n\n/**\n * Merge extracted content with existing dictionary for multilingual format.\n * - Keys in extracted but not in existing: added with default locale only\n * - Keys in both: preserve existing translations, update default locale value\n * - Keys in existing but not in extracted: removed (no longer in source)\n */\nexport const mergeWithExistingMultilingualDictionary = (\n extractedContent: Record<string, string>,\n existingDictionary: Dictionary | null,\n defaultLocale: string\n): DictionaryContentMap => {\n const dictionary: Dictionary =\n existingDictionary ??\n ({\n key: '',\n content: {},\n filePath: '',\n } as Dictionary);\n\n const mergedDictionary = insertContentInDictionary(\n dictionary,\n extractedContent,\n defaultLocale as Locale\n );\n\n const mergedContent = mergedDictionary.content as DictionaryContentMap;\n\n // Pruning: remove keys not in extractedContent\n const finalContent: DictionaryContentMap = {};\n for (const key in extractedContent) {\n finalContent[key] = mergedContent[key];\n }\n\n // Promote any key whose source text contains {{vars}} to an insertion node\n for (const key in extractedContent) {\n const rawValue = extractedContent[key];\n if (typeof rawValue === 'string' && hasInsertionVars(rawValue)) {\n const node = finalContent[key] as any;\n if (node && node.nodeType === NodeType.Translation) {\n (finalContent as any)[key] = {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: node,\n fields: getInsertionFields(rawValue),\n };\n }\n }\n }\n\n return finalContent;\n};\n\n/**\n * Merge extracted content with existing dictionary for per-locale format.\n * - Keys in extracted but not in existing: added\n * - Keys in both: update value\n * - Keys in existing but not in extracted: removed (no longer in source)\n */\nexport const mergeWithExistingPerLocaleDictionary = (\n extractedContent: Record<string, string>,\n existingDictionary: Dictionary | null\n): Record<string, string> => {\n const dictionary: Dictionary =\n existingDictionary ??\n ({\n key: '',\n content: {},\n filePath: '',\n } as Dictionary);\n\n const mergedDictionary = insertContentInDictionary(\n dictionary,\n extractedContent\n );\n\n const mergedContent = mergedDictionary.content as Record<string, string>;\n\n // Pruning: remove keys not in extractedContent\n const finalContent: Record<string, string> = {};\n for (const key in extractedContent) {\n finalContent[key] = mergedContent[key];\n }\n\n // Promote any key whose source text contains {{vars}} to an insertion node\n for (const key in extractedContent) {\n const rawValue = extractedContent[key];\n if (typeof rawValue === 'string' && hasInsertionVars(rawValue)) {\n const currentVal = finalContent[key];\n if (typeof currentVal === 'string') {\n (finalContent as any)[key] = {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: currentVal,\n fields: getInsertionFields(rawValue),\n };\n }\n }\n }\n\n return finalContent;\n};\n\n/**\n * Helper to write extracted content to dictionary file(s).\n */\nexport const writeContentHelper = async (\n extractedContent: Record<string, string>,\n dictionaryKey: DictionaryKey,\n filePath: string,\n configuration: IntlayerConfig\n): Promise<string> => {\n const { absolutePath, isPerLocale } = await resolveContentFilePaths(\n filePath,\n dictionaryKey,\n configuration\n );\n\n const { defaultLocale } = configuration.internationalization;\n const { baseDir } = configuration.system;\n\n if (!cachedBundleFilePath) {\n cachedBundleFilePath = await ensureIntlayerBundle(configuration);\n }\n\n const outputDir = dirname(absolutePath);\n\n // Ensure output directory exists\n await mkdir(outputDir, { recursive: true });\n\n // Read existing dictionary to preserve translations and metadata\n let existingDictionary: Dictionary | null = null;\n\n if (existsSync(absolutePath)) {\n try {\n const dictionary = await loadContentDeclaration(\n absolutePath,\n configuration,\n cachedBundleFilePath\n );\n\n existingDictionary = dictionary ?? null;\n } catch (error) {\n console.error(error);\n }\n }\n\n const relativeContentFilePath = relative(baseDir, absolutePath);\n\n let mergedDictionary: Dictionary;\n\n if (isPerLocale) {\n // Per-locale format: simple string content for a single locale\n const mergedContent = mergeWithExistingPerLocaleDictionary(\n extractedContent,\n existingDictionary\n );\n\n mergedDictionary = {\n // Preserve existing metadata\n ...existingDictionary,\n key: dictionaryKey,\n content: mergedContent,\n locale: defaultLocale,\n filePath: relativeContentFilePath,\n };\n } else {\n // Multilingual format: content wrapped in translation nodes for multiple locales\n const mergedContent = mergeWithExistingMultilingualDictionary(\n extractedContent,\n existingDictionary,\n defaultLocale\n );\n\n mergedDictionary = {\n // Preserve existing metadata\n ...existingDictionary,\n key: dictionaryKey,\n content: mergedContent,\n filePath: relativeContentFilePath,\n };\n }\n\n const relativeDir = relative(baseDir, outputDir);\n\n const writeResult = await writeContentDeclaration(\n mergedDictionary,\n configuration,\n {\n newDictionariesPath: relativeDir,\n localeList: [defaultLocale],\n }\n );\n\n // Build the dictionary immediately\n const dictionaryToBuild: Dictionary = {\n ...mergedDictionary,\n filePath: relative(baseDir, writeResult?.path ?? absolutePath),\n };\n\n await buildDictionary([dictionaryToBuild], configuration);\n\n return absolutePath;\n};\n"],"mappings":"mWAgBA,MAAM,EAAoB,GAAyB,gBAAgB,KAAK,EAAI,CAEtE,EAAsB,GAA+B,CACzD,IAAM,EAAmB,EAAE,CACrB,EAAQ,mBACV,EACJ,IACE,IAAI,EAAS,EAAM,KAAK,EAAS,CACjC,IAAW,KACX,EAAS,EAAM,KAAK,EAAS,CAC7B,CACA,EAAQ,EACR,IAAM,EAAQ,EAAM,GAAG,MAAM,CACxB,EAAO,SAAS,EAAM,EAAE,EAAO,KAAK,EAAM,CAEjD,OAAO,GAmBT,IAAI,EAQJ,MAAa,GACX,EACA,EACA,IACyB,CAezB,IAAM,GAAA,EAAA,EAAA,2BAbJ,GACC,CACC,IAAK,GACL,QAAS,EAAE,CACX,SAAU,GACX,CAID,EACA,EACD,CAEsC,QAGjC,EAAqC,EAAE,CAC7C,IAAK,IAAM,KAAO,EAChB,EAAa,GAAO,EAAc,GAIpC,IAAK,IAAM,KAAO,EAAkB,CAClC,I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AAmC,EAAS,EAAa,CAE3D,EAEJ,GAAI,EAAa,CAEf,IAAM,EAAgB,EACpB,EACA,EACD,CAED,EAAmB,CAEjB,GAAG,EACH,IAAK,EACL,QAAS,EACT,OAAQ,EACR,SAAU,EACX,KACI,CAEL,IAAM,EAAgB,EACpB,EACA,EACA,EACD,CAED,EAAmB,CAEjB,GAAG,EACH,IAAK,EACL,QAAS,EACT,SAAU,EACX,CAGH,IAAM,GAAA,EAAA,EAAA,UAAuB,EAAS,EAAU,CAE1C,EAAc,MAAA,EAAA,EAAA,yBAClB,EACA,EACA,CACE,oBAAqB,EACrB,WAAY,CAAC,EAAc,CAC5B,CACF,CAUD,OAFA,MAAA,EAAA,EAAA,iBAAsB,CALgB,CACpC,GAAG,EACH,UAAA,EAAA,EAAA,UAAmB,EAAS,GAAa,MAAQ,EAAa,CAC/D,CAEwC,CAAE,EAAc,CAElD"}
1
+ {"version":3,"file":"contentWriter.cjs","names":["NodeType","resolveContentFilePaths"],"sources":["../../../src/extractContent/contentWriter.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport {\n buildDictionary,\n ensureIntlayerBundle,\n loadContentDeclaration,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport { insertContentInDictionary } from '@intlayer/core/plugins';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary, DictionaryKey } from '@intlayer/types/dictionary';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport { resolveContentFilePaths } from './utils/extractDictionaryInfo';\n\nconst hasInsertionVars = (str: string): boolean => /\\{\\{[^}]+\\}\\}/.test(str);\n\nconst getInsertionFields = (template: string): string[] => {\n const fields: string[] = [];\n const regex = /\\{\\{([^}]+)\\}\\}/g;\n let match: RegExpExecArray | null;\n for (\n let result = regex.exec(template);\n result !== null;\n result = regex.exec(template)\n ) {\n match = result;\n const field = match[1].trim();\n if (!fields.includes(field)) fields.push(field);\n }\n return fields;\n};\n\n/**\n * Translation node structure used in dictionaries\n */\ntype TranslationNode = {\n nodeType: 'translation';\n translation: Record<string, string>;\n};\n\n/**\n * Dictionary content structure - map of keys to translation nodes\n */\ntype DictionaryContentMap = Record<string, TranslationNode>;\n\n/**\n * Cached bundle file path to optimize performance\n */\nlet cachedBundleFilePath: string | undefined;\n\n/**\n * Merge extracted content with existing dictionary for multilingual format.\n * - Keys in extracted but not in existing: added with default locale only\n * - Keys in both: preserve existing translations, update default locale value\n * - Keys in existing but not in extracted: removed (no longer in source)\n */\nexport const mergeWithExistingMultilingualDictionary = (\n extractedContent: Record<string, string>,\n existingDictionary: Dictionary | null,\n defaultLocale: string\n): DictionaryContentMap => {\n const dictionary: Dictionary =\n existingDictionary ??\n ({\n key: '',\n content: {},\n filePath: '',\n } as Dictionary);\n\n const mergedDictionary = insertContentInDictionary(\n dictionary,\n extractedContent,\n defaultLocale as Locale\n );\n\n const mergedContent = mergedDictionary.content as DictionaryContentMap;\n\n // Pruning: remove keys not in extractedContent\n const finalContent: DictionaryContentMap = {};\n for (const key in extractedContent) {\n finalContent[key] = mergedContent[key];\n }\n\n // Promote any key whose source text contains {{vars}} to an insertion node\n for (const key in extractedContent) {\n const rawValue = extractedContent[key];\n if (typeof rawValue === 'string' && hasInsertionVars(rawValue)) {\n const node = finalContent[key] as any;\n if (node && node.nodeType === NodeType.Translation) {\n (finalContent as any)[key] = {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: node,\n fields: getInsertionFields(rawValue),\n };\n }\n }\n }\n\n return finalContent;\n};\n\n/**\n * Merge extracted content with existing dictionary for per-locale format.\n * - Keys in extracted but not in existing: added\n * - Keys in both: update value\n * - Keys in existing but not in extracted: removed (no longer in source)\n */\nexport const mergeWithExistingPerLocaleDictionary = (\n extractedContent: Record<string, string>,\n existingDictionary: Dictionary | null\n): Record<string, string> => {\n const dictionary: Dictionary =\n existingDictionary ??\n ({\n key: '',\n content: {},\n filePath: '',\n } as Dictionary);\n\n const mergedDictionary = insertContentInDictionary(\n dictionary,\n extractedContent\n );\n\n const mergedContent = mergedDictionary.content as Record<string, string>;\n\n // Pruning: remove keys not in extractedContent\n const finalContent: Record<string, string> = {};\n for (const key in extractedContent) {\n finalContent[key] = mergedContent[key];\n }\n\n // Promote any key whose source text contains {{vars}} to an insertion node\n for (const key in extractedContent) {\n const rawValue = extractedContent[key];\n if (typeof rawValue === 'string' && hasInsertionVars(rawValue)) {\n const currentVal = finalContent[key];\n if (typeof currentVal === 'string') {\n (finalContent as any)[key] = {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: currentVal,\n fields: getInsertionFields(rawValue),\n };\n }\n }\n }\n\n return finalContent;\n};\n\n/**\n * Helper to write extracted content to dictionary file(s).\n */\nexport const writeContentHelper = async (\n extractedContent: Record<string, string>,\n dictionaryKey: DictionaryKey,\n filePath: string,\n configuration: IntlayerConfig\n): Promise<string> => {\n const { absolutePath, isPerLocale } = await resolveContentFilePaths(\n filePath,\n dictionaryKey,\n configuration\n );\n\n const { defaultLocale } = configuration.internationalization;\n const { baseDir } = configuration.system;\n\n if (!cachedBundleFilePath) {\n cachedBundleFilePath = await ensureIntlayerBundle(configuration);\n }\n\n const outputDir = dirname(absolutePath);\n\n // Ensure output directory exists\n await mkdir(outputDir, { recursive: true });\n\n // Read existing dictionary to preserve translations and metadata\n let existingDictionary: Dictionary | null = null;\n\n if (existsSync(absolutePath)) {\n try {\n const dictionary = await loadContentDeclaration(\n absolutePath,\n configuration,\n cachedBundleFilePath\n );\n\n existingDictionary = dictionary ?? null;\n } catch (error) {\n console.error(error);\n }\n }\n\n const relativeContentFilePath = relative(baseDir, absolutePath);\n\n let mergedDictionary: Dictionary;\n\n if (isPerLocale) {\n // Per-locale format: simple string content for a single locale\n const mergedContent = mergeWithExistingPerLocaleDictionary(\n extractedContent,\n existingDictionary\n );\n\n mergedDictionary = {\n // Preserve existing metadata\n ...existingDictionary,\n key: dictionaryKey,\n content: mergedContent,\n locale: defaultLocale,\n filePath: relativeContentFilePath,\n };\n } else {\n // Multilingual format: content wrapped in translation nodes for multiple locales\n const mergedContent = mergeWithExistingMultilingualDictionary(\n extractedContent,\n existingDictionary,\n defaultLocale\n );\n\n mergedDictionary = {\n // Preserve existing metadata\n ...existingDictionary,\n key: dictionaryKey,\n content: mergedContent,\n filePath: relativeContentFilePath,\n };\n }\n\n const relativeDir = relative(baseDir, outputDir);\n\n const writeResult = await writeContentDeclaration(\n mergedDictionary,\n configuration,\n {\n newDictionariesPath: relativeDir,\n localeList: [defaultLocale],\n }\n );\n\n // Build the dictionary immediately\n const dictionaryToBuild: Dictionary = {\n ...mergedDictionary,\n filePath: relative(baseDir, writeResult?.path ?? absolutePath),\n };\n\n await buildDictionary([dictionaryToBuild], configuration);\n\n return absolutePath;\n};\n"],"mappings":"uVAgBA,MAAM,EAAoB,GAAyB,gBAAgB,KAAK,EAAI,CAEtE,EAAsB,GAA+B,CACzD,IAAM,EAAmB,EAAE,CACrB,EAAQ,mBACV,EACJ,IACE,IAAI,EAAS,EAAM,KAAK,EAAS,CACjC,IAAW,KACX,EAAS,EAAM,KAAK,EAAS,CAC7B,CACA,EAAQ,EACR,IAAM,EAAQ,EAAM,GAAG,MAAM,CACxB,EAAO,SAAS,EAAM,EAAE,EAAO,KAAK,EAAM,CAEjD,OAAO,GAmBT,IAAI,EAQJ,MAAa,GACX,EACA,EACA,IACyB,CAezB,IAAM,GAAA,EAAA,EAAA,2BAbJ,GACC,CACC,IAAK,GACL,QAAS,EAAE,CACX,SAAU,GACX,CAID,EACA,EACD,CAEsC,QAGjC,EAAqC,EAAE,CAC7C,IAAK,IAAM,KAAO,EAChB,EAAa,GAAO,EAAc,GAIpC,IAAK,IAAM,KAAO,EAAkB,CAClC,IAAM,EAAW,EAAiB,GAClC,GAAI,OAAO,GAAa,UAAY,EAAiB,EAAS,CAAE,CAC9D,IAAM,EAAO,EAAa,GACtB,GAAQ,EAAK,WAAaA,EAAAA,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EACT,OAAQ,EACR,SAAU,EACX,KACI,CAEL,IAAM,EAAgB,EACpB,EACA,EACA,EACD,CAED,EAAmB,CAEjB,GAAG,EACH,IAAK,EACL,QAAS,EACT,SAAU,EACX,CAGH,IAAM,GAAA,EAAA,EAAA,UAAuB,EAAS,EAAU,CAE1C,EAAc,MAAA,EAAA,EAAA,yBAClB,EACA,EACA,CACE,oBAAqB,EACrB,WAAY,CAAC,EAAc,CAC5B,CACF,CAUD,OAFA,MAAA,EAAA,EAAA,iBAAsB,CALgB,CACpC,GAAG,EACH,UAAA,EAAA,EAAA,UAAmB,EAAS,GAAa,MAAQ,EAAa,CAC/D,CAEwC,CAAE,EAAc,CAElD"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./utils/extractDictionaryKey.cjs`),t=require(`./contentWriter.cjs`),n=require(`./utils/constants.cjs`),r=require(`./utils/generateKey.cjs`),i=require(`./utils/shouldExtract.cjs`),a=require(`./babelProcessor.cjs`),o=require(`./processTsxFile.cjs`);let s=require(`@intlayer/config/logger`),c=require(`@intlayer/config/node`),l=require(`node:fs`),u=require(`node:path`),d=require(`@intlayer/config/utils`),f=require(`@intlayer/unmerged-dictionaries-entry`),p=require(`@intlayer/chokidar/cli`),m=require(`node:child_process`),h=null,g=null;const _=(e,t)=>{if(t)return{extractedContentMap:{[e]:t.extractedContent},transformedCode:t.code}},v=(t,c,d,f,p,m)=>{let h=d?.code??(0,l.readFileSync)(t,`utf-8`),g=m??e.extractDictionaryKey(t,h,f.configuration.compiler.dictionaryKeyPrefix),v=(0,u.extname)(t),{vueCompiler:y,svelteCompiler:b,unmergedDictionaries:x,configuration:S}=f,C={generateKey:r.generateKey,shouldExtract:i.shouldExtract,attributesToExtract:n.ATTRIBUTES_TO_EXTRACT,extractDictionaryKeyFromPath:e.extractDictionaryKeyFromPath,extractTsContent:(e,t,n,r,i)=>a.extractTsContent(e,t,n,r,i,x)};if(v===`.vue`){if(!y)throw Error(`Please install ${(0,s.colorizePath)(`@intlayer/vue-compiler`,s.ANSIColors.YELLOW)} to process Vue files.`);let e=y.processVueFile(t,g,c,C,p);if(e)return _(g,e)}if(v===`.svelte`){if(!b)throw Error(`Please install ${(0,s.colorizePath)(`@intlayer/svelte-compiler`,s.ANSIColors.YELLOW)} to process Svelte files.`);let e=b.processSvelteFile(t,g,c,C,p);if(e)return _(g,e)}if([`.tsx`,`.jsx`,`.ts`,`.js`,`.cjs`,`.mjs`].includes(v)){let e=o.processTsxFile(t,g,c,S,p,x,h);if(e)return{extractedContentMap:e.extractedContent,transformedCode:e.modifiedCode}}},y=async(e,n,r,{configuration:i,baseDir:a,appLogger:o},c)=>{if(r?.onExtract)for(let[t,i]of Object.entries(e))await r.onExtract({key:t,content:i,filePath:n});if(!r?.codeOnly&&!r?.onExtract)for(let[r,c]of Object.entries(e)){let e=(0,u.relative)(a,await t.writeContentHelper(c,r,n,i));o(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Created content file: ${(0,s.colorizePath)(e)}`)}if(c){let e=(0,p.detectFormatCommand)(i);if(e)try{(0,m.execSync)(e.replace(`{{file}}`,n),{stdio:`inherit`,cwd:a})}catch(e){console.error(e)}o(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Updated component: ${(0,s.colorizePath)((0,u.relative)(a,n))}`)}},b=(e,t)=>{let n=t?.configuration??(0,c.getConfiguration)(t?.configOptions),r=(0,s.getAppLogger)(n),{baseDir:i}=n.system;return{configuration:n,appLogger:r,baseDir:i,unmergedDictionaries:t?.unmergedDictionaries??(0,f.getUnmergedDictionaries)(n),saveComponent:!t?.declarationOnly,componentExtension:(0,u.extname)(e)}},x=async(t,n,r)=>{let{configuration:i,appLogger:a,baseDir:o,unmergedDictionaries:c,saveComponent:d,componentExtension:f}=b(t,r);if(f===`.vue`&&!h)try{h=await import(`@intlayer/vue-compiler`)}catch{a(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Install ${(0,s.colorizePath)(`@intlayer/vue-compiler`,s.ANSIColors.YELLOW)} to process Vue files.`)}if(f===`.svelte`&&!g)try{g=await import(`@intlayer/svelte-compiler`)}catch{a(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Install ${(0,s.colorizePath)(`@intlayer/svelte-compiler`,s.ANSIColors.YELLOW)} to process Svelte files.`)}let p=e.extractDictionaryKey(t,r?.code??(0,l.readFileSync)(t,`utf-8`),i.compiler.dictionaryKeyPrefix),m=v(t,n,r,{vueCompiler:h,svelteCompiler:g,unmergedDictionaries:c,configuration:i},d,p);if(!m||!m.extractedContentMap){a(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} No extractable text found in ${(0,s.colorizePath)((0,u.relative)(o,t))}`,{isVerbose:!0});return}return await y(m.extractedContentMap,t,r,{configuration:i,baseDir:o,appLogger:a},d),{transformedCode:m.transformedCode,extractedContentMap:m.extractedContentMap}},S=(e,t,n)=>{let{configuration:r,appLogger:i,baseDir:a,unmergedDictionaries:o,saveComponent:c,componentExtension:l}=b(e,n),f=(0,d.getProjectRequire)();if(l===`.vue`&&!h)try{h=f(`@intlayer/vue-compiler`)}catch{i(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Install ${(0,s.colorizePath)(`@intlayer/vue-compiler`,s.ANSIColors.YELLOW)} to process Vue files.`)}if(l===`.svelte`&&!g)try{g=f(`@intlayer/svelte-compiler`)}catch{i(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Install ${(0,s.colorizePath)(`@intlayer/svelte-compiler`,s.ANSIColors.YELLOW)} to process Svelte files.`)}let p=v(e,t,n,{vueCompiler:h,svelteCompiler:g,unmergedDictionaries:o,configuration:r},c);if(!p?.extractedContentMap){i(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} No extractable text found in ${(0,s.colorizePath)((0,u.relative)(a,e))}`,{isVerbose:!0});return}let{extractedContentMap:m,transformedCode:_}=p;if(n?.onExtract)for(let[t,r]of Object.entries(m))n.onExtract({key:t,content:r,filePath:e});return{transformedCode:_,extractedContentMap:m}};exports.extractContent=x,exports.extractContentSync=S;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-Bmb41Sf3.cjs`);const e=require(`./utils/extractDictionaryKey.cjs`),t=require(`./contentWriter.cjs`),n=require(`./utils/constants.cjs`),r=require(`./utils/generateKey.cjs`),i=require(`./utils/shouldExtract.cjs`),a=require(`./babelProcessor.cjs`),o=require(`./processTsxFile.cjs`);let s=require(`@intlayer/config/logger`),c=require(`@intlayer/config/node`),l=require(`node:fs`),u=require(`node:path`),d=require(`@intlayer/config/utils`),f=require(`@intlayer/unmerged-dictionaries-entry`),p=require(`@intlayer/chokidar/cli`),m=require(`node:child_process`),h=null,g=null;const _=(e,t)=>{if(t)return{extractedContentMap:{[e]:t.extractedContent},transformedCode:t.code}},v=(t,c,d,f,p,m)=>{let h=d?.code??(0,l.readFileSync)(t,`utf-8`),g=m??e.extractDictionaryKey(t,h,f.configuration.compiler.dictionaryKeyPrefix),v=(0,u.extname)(t),{vueCompiler:y,svelteCompiler:b,unmergedDictionaries:x,configuration:S}=f,C={generateKey:r.generateKey,shouldExtract:i.shouldExtract,attributesToExtract:n.ATTRIBUTES_TO_EXTRACT,extractDictionaryKeyFromPath:e.extractDictionaryKeyFromPath,extractTsContent:(e,t,n,r,i)=>a.extractTsContent(e,t,n,r,i,x)};if(v===`.vue`){if(!y)throw Error(`Please install ${(0,s.colorizePath)(`@intlayer/vue-compiler`,s.ANSIColors.YELLOW)} to process Vue files.`);let e=y.processVueFile(t,g,c,C,p);if(e)return _(g,e)}if(v===`.svelte`){if(!b)throw Error(`Please install ${(0,s.colorizePath)(`@intlayer/svelte-compiler`,s.ANSIColors.YELLOW)} to process Svelte files.`);let e=b.processSvelteFile(t,g,c,C,p);if(e)return _(g,e)}if([`.tsx`,`.jsx`,`.ts`,`.js`,`.cjs`,`.mjs`].includes(v)){let e=o.processTsxFile(t,g,c,S,p,x,h);if(e)return{extractedContentMap:e.extractedContent,transformedCode:e.modifiedCode}}},y=async(e,n,r,{configuration:i,baseDir:a,appLogger:o},c)=>{if(r?.onExtract)for(let[t,i]of Object.entries(e))await r.onExtract({key:t,content:i,filePath:n});if(!r?.codeOnly&&!r?.onExtract)for(let[r,c]of Object.entries(e)){let e=(0,u.relative)(a,await t.writeContentHelper(c,r,n,i));o(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Created content file: ${(0,s.colorizePath)(e)}`)}if(c){let e=(0,p.detectFormatCommand)(i);if(e)try{(0,m.execSync)(e.replace(`{{file}}`,n),{stdio:`inherit`,cwd:a})}catch(e){console.error(e)}o(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Updated component: ${(0,s.colorizePath)((0,u.relative)(a,n))}`)}},b=(e,t)=>{let n=t?.configuration??(0,c.getConfiguration)(t?.configOptions),r=(0,s.getAppLogger)(n),{baseDir:i}=n.system;return{configuration:n,appLogger:r,baseDir:i,unmergedDictionaries:t?.unmergedDictionaries??(0,f.getUnmergedDictionaries)(n),saveComponent:!t?.declarationOnly,componentExtension:(0,u.extname)(e)}},x=async(t,n,r)=>{let{configuration:i,appLogger:a,baseDir:o,unmergedDictionaries:c,saveComponent:d,componentExtension:f}=b(t,r);if(f===`.vue`&&!h)try{h=await import(`@intlayer/vue-compiler`)}catch{a(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Install ${(0,s.colorizePath)(`@intlayer/vue-compiler`,s.ANSIColors.YELLOW)} to process Vue files.`)}if(f===`.svelte`&&!g)try{g=await import(`@intlayer/svelte-compiler`)}catch{a(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Install ${(0,s.colorizePath)(`@intlayer/svelte-compiler`,s.ANSIColors.YELLOW)} to process Svelte files.`)}let p=e.extractDictionaryKey(t,r?.code??(0,l.readFileSync)(t,`utf-8`),i.compiler.dictionaryKeyPrefix),m=v(t,n,r,{vueCompiler:h,svelteCompiler:g,unmergedDictionaries:c,configuration:i},d,p);if(!m||!m.extractedContentMap){a(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} No extractable text found in ${(0,s.colorizePath)((0,u.relative)(o,t))}`,{isVerbose:!0});return}return await y(m.extractedContentMap,t,r,{configuration:i,baseDir:o,appLogger:a},d),{transformedCode:m.transformedCode,extractedContentMap:m.extractedContentMap}},S=(e,t,n)=>{let{configuration:r,appLogger:i,baseDir:a,unmergedDictionaries:o,saveComponent:c,componentExtension:l}=b(e,n),f=(0,d.getProjectRequire)();if(l===`.vue`&&!h)try{h=f(`@intlayer/vue-compiler`)}catch{i(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Install ${(0,s.colorizePath)(`@intlayer/vue-compiler`,s.ANSIColors.YELLOW)} to process Vue files.`)}if(l===`.svelte`&&!g)try{g=f(`@intlayer/svelte-compiler`)}catch{i(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} Install ${(0,s.colorizePath)(`@intlayer/svelte-compiler`,s.ANSIColors.YELLOW)} to process Svelte files.`)}let p=v(e,t,n,{vueCompiler:h,svelteCompiler:g,unmergedDictionaries:o,configuration:r},c);if(!p?.extractedContentMap){i(`${(0,s.colorize)(`Compiler:`,s.ANSIColors.GREY_DARK)} No extractable text found in ${(0,s.colorizePath)((0,u.relative)(a,e))}`,{isVerbose:!0});return}let{extractedContentMap:m,transformedCode:_}=p;if(n?.onExtract)for(let[t,r]of Object.entries(m))n.onExtract({key:t,content:r,filePath:e});return{transformedCode:_,extractedContentMap:m}};exports.extractContent=x,exports.extractContentSync=S;
2
2
  //# sourceMappingURL=extractContent.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"extractContent.cjs","names":["extractDictionaryKey","ATTRIBUTES_TO_EXTRACT","extractTsContent","ANSIColors","processTsxFile","writeContentHelper"],"sources":["../../../src/extractContent/extractContent.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { extname, relative } from 'node:path';\nimport type * as t from '@babel/types';\nimport { detectFormatCommand } from '@intlayer/chokidar/cli';\nimport {\n ANSIColors,\n colorize,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { extractTsContent } from './babelProcessor';\nimport { writeContentHelper } from './contentWriter';\nimport { processTsxFile } from './processTsxFile';\nimport {\n ATTRIBUTES_TO_EXTRACT,\n extractDictionaryKeyFromPath,\n type PackageName,\n shouldExtract,\n} from './utils';\nimport { extractDictionaryKey } from './utils/extractDictionaryKey';\nimport { generateKey } from './utils/generateKey';\n\nexport type ExtractIntlayerOptions = {\n configOptions?: GetConfigurationOptions;\n codeOnly?: boolean;\n declarationOnly?: boolean;\n unmergedDictionaries?: Record<string, unknown>;\n configuration?: IntlayerConfig;\n code?: string;\n onExtract?: (result: {\n key: string;\n content: Record<string, string>;\n filePath: string;\n }) => void | Promise<void>;\n};\n\ntype ExternalCompilerResult = {\n extractedContent: Record<string, string>;\n code: string;\n};\n\ntype ExternalCompilerOptions = {\n generateKey: typeof generateKey;\n shouldExtract: typeof shouldExtract;\n attributesToExtract: typeof ATTRIBUTES_TO_EXTRACT;\n extractDictionaryKeyFromPath: typeof extractDictionaryKeyFromPath;\n extractTsContent: (\n ast: unknown,\n code: string,\n keys: Set<string>,\n config: IntlayerConfig,\n path: string\n ) => ReturnType<typeof extractTsContent>;\n};\n\ntype VueCompiler = typeof import('@intlayer/vue-compiler');\ntype SvelteCompiler = typeof import('@intlayer/svelte-compiler');\n\n// Module caches\nlet vueCompiler: VueCompiler | null = null;\nlet svelteCompiler: SvelteCompiler | null = null;\n\ntype InternalExtractResult = {\n extractedContentMap: Record<string, Record<string, string>> | null;\n transformedCode: string | null;\n};\n\nconst formatCompilerResult = (\n componentKey: string,\n res?: ExternalCompilerResult\n): InternalExtractResult | undefined => {\n if (!res) return undefined;\n\n return {\n extractedContentMap: { [componentKey]: res.extractedContent },\n transformedCode: res.code,\n };\n};\n\ntype Dependencies = {\n vueCompiler: VueCompiler | null;\n svelteCompiler: SvelteCompiler | null;\n unmergedDictionaries: Record<string, unknown>;\n configuration: IntlayerConfig;\n};\n\nconst processFileInternal = (\n filePath: string,\n packageName: PackageName,\n options: ExtractIntlayerOptions | undefined,\n dependencies: Dependencies,\n saveComponent: boolean,\n providedComponentKey?: string\n): InternalExtractResult | undefined => {\n const fileText = options?.code ?? readFileSync(filePath, 'utf-8');\n const componentKey =\n providedComponentKey ??\n extractDictionaryKey(\n filePath,\n fileText,\n dependencies.configuration.compiler.dictionaryKeyPrefix\n );\n const ext = extname(filePath);\n\n const { vueCompiler, svelteCompiler, unmergedDictionaries, configuration } =\n dependencies;\n\n const compilerCommonOptions: ExternalCompilerOptions = {\n generateKey,\n shouldExtract,\n attributesToExtract: ATTRIBUTES_TO_EXTRACT,\n extractDictionaryKeyFromPath,\n extractTsContent: (ast, code, keys, config, path) =>\n extractTsContent(\n ast as t.File,\n code,\n keys,\n config,\n path,\n unmergedDictionaries\n ),\n };\n\n if (ext === '.vue') {\n if (!vueCompiler) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/vue-compiler', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n\n const res = vueCompiler.processVueFile(\n filePath,\n componentKey,\n packageName,\n compilerCommonOptions,\n saveComponent\n );\n\n if (res) {\n return formatCompilerResult(componentKey, res);\n }\n }\n\n if (ext === '.svelte') {\n if (!svelteCompiler) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/svelte-compiler', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n\n const res = svelteCompiler.processSvelteFile(\n filePath,\n componentKey,\n packageName,\n compilerCommonOptions,\n saveComponent\n );\n\n if (res) {\n return formatCompilerResult(componentKey, res);\n }\n }\n\n if (['.tsx', '.jsx', '.ts', '.js', '.cjs', '.mjs'].includes(ext)) {\n const result = processTsxFile(\n filePath,\n componentKey,\n packageName,\n configuration,\n saveComponent,\n unmergedDictionaries,\n fileText\n );\n\n if (result) {\n return {\n extractedContentMap: result.extractedContent,\n transformedCode: result.modifiedCode,\n };\n }\n }\n\n return undefined;\n};\n\nconst handleExtractionSideEffects = async (\n extractedContentMap: Record<string, Record<string, string>>,\n filePath: string,\n options: ExtractIntlayerOptions | undefined,\n {\n configuration,\n baseDir,\n appLogger,\n }: {\n configuration: IntlayerConfig;\n baseDir: string;\n appLogger: ReturnType<typeof getAppLogger>;\n },\n saveComponent: boolean\n) => {\n if (options?.onExtract) {\n for (const [key, content] of Object.entries(extractedContentMap)) {\n await options.onExtract({ key, content, filePath });\n }\n }\n\n const writeContent = !options?.codeOnly && !options?.onExtract;\n\n if (writeContent) {\n for (const [key, content] of Object.entries(extractedContentMap)) {\n const contentFilePath = await writeContentHelper(\n content,\n key,\n filePath,\n configuration\n );\n\n const relativeContentFilePath = relative(baseDir, contentFilePath);\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Created content file: ${colorizePath(relativeContentFilePath)}`\n );\n }\n }\n\n if (saveComponent) {\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Updated component: ${colorizePath(relative(baseDir, filePath))}`\n );\n }\n};\n\ntype ExtractResult = {\n transformedCode: string | null;\n extractedContentMap: Record<string, Record<string, string>>;\n};\n\ntype ExtractContext = {\n configuration: IntlayerConfig;\n appLogger: ReturnType<typeof getAppLogger>;\n baseDir: string;\n unmergedDictionaries: Record<string, unknown>;\n saveComponent: boolean;\n componentExtension: string;\n};\n\nconst buildContext = (\n filePath: string,\n options: ExtractIntlayerOptions | undefined\n): ExtractContext => {\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n const { baseDir } = configuration.system;\n const unmergedDictionaries =\n options?.unmergedDictionaries ?? getUnmergedDictionaries(configuration);\n const saveComponent = !options?.declarationOnly;\n const componentExtension = extname(filePath);\n\n return {\n configuration,\n appLogger,\n baseDir,\n unmergedDictionaries,\n saveComponent,\n componentExtension,\n };\n};\n\nexport const extractContent = async (\n filePath: string,\n packageName: PackageName,\n options?: ExtractIntlayerOptions\n): Promise<ExtractResult | undefined> => {\n const {\n configuration,\n appLogger,\n baseDir,\n unmergedDictionaries,\n saveComponent,\n componentExtension,\n } = buildContext(filePath, options);\n\n if (componentExtension === '.vue' && !vueCompiler) {\n try {\n vueCompiler = await import('@intlayer/vue-compiler');\n } catch {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Install ${colorizePath('@intlayer/vue-compiler', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n }\n\n if (componentExtension === '.svelte' && !svelteCompiler) {\n try {\n svelteCompiler = await import('@intlayer/svelte-compiler');\n } catch {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Install ${colorizePath('@intlayer/svelte-compiler', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n }\n\n const fileText = options?.code ?? readFileSync(filePath, 'utf-8');\n const dictionaryKey = extractDictionaryKey(\n filePath,\n fileText,\n configuration.compiler.dictionaryKeyPrefix\n );\n\n const result = processFileInternal(\n filePath,\n packageName,\n options,\n { vueCompiler, svelteCompiler, unmergedDictionaries, configuration },\n saveComponent,\n dictionaryKey\n );\n\n if (!result || !result.extractedContentMap) {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} No extractable text found in ${colorizePath(relative(baseDir, filePath))}`,\n { isVerbose: true }\n );\n return undefined;\n }\n\n await handleExtractionSideEffects(\n result.extractedContentMap,\n filePath,\n options,\n { configuration, baseDir, appLogger },\n saveComponent\n );\n\n return {\n transformedCode: result.transformedCode,\n extractedContentMap: result.extractedContentMap,\n };\n};\n\n/**\n * Synchronous variant of `extractContent` — used by the Babel plugin which\n * runs in a sync transform context (e.g. Next.js / Webpack).\n *\n * Differences from `extractContent`:\n * - Loads external compilers (Vue, Svelte) via `require()` instead of `import()`\n * - Fires `onExtract` callbacks as fire-and-forget (cannot await in sync context)\n * - Does NOT write dictionary files or run the code formatter; callers that\n * need persistence should supply an `onExtract` callback\n */\nexport const extractContentSync = (\n filePath: string,\n packageName: PackageName,\n options?: ExtractIntlayerOptions\n): ExtractResult | undefined => {\n const {\n configuration,\n appLogger,\n baseDir,\n unmergedDictionaries,\n saveComponent,\n componentExtension,\n } = buildContext(filePath, options);\n\n const requireFn = getProjectRequire();\n\n if (componentExtension === '.vue' && !vueCompiler) {\n try {\n vueCompiler = requireFn('@intlayer/vue-compiler') as VueCompiler;\n } catch {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Install ${colorizePath('@intlayer/vue-compiler', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n }\n\n if (componentExtension === '.svelte' && !svelteCompiler) {\n try {\n svelteCompiler = requireFn('@intlayer/svelte-compiler') as SvelteCompiler;\n } catch {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Install ${colorizePath('@intlayer/svelte-compiler', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n }\n\n const result = processFileInternal(\n filePath,\n packageName,\n options,\n { vueCompiler, svelteCompiler, unmergedDictionaries, configuration },\n saveComponent\n );\n\n if (!result?.extractedContentMap) {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} No extractable text found in ${colorizePath(relative(baseDir, filePath))}`,\n { isVerbose: true }\n );\n return undefined;\n }\n\n const { extractedContentMap, transformedCode } = result;\n\n if (options?.onExtract) {\n for (const [key, content] of Object.entries(extractedContentMap)) {\n void options.onExtract({ key, content, filePath });\n }\n }\n\n return { transformedCode, extractedContentMap };\n};\n"],"mappings":"2oBAmEI,EAAkC,KAClC,EAAwC,KAO5C,MAAM,GACJ,EACA,IACsC,CACjC,KAEL,MAAO,CACL,oBAAqB,EAAG,GAAe,EAAI,iBAAkB,CAC7D,gBAAiB,EAAI,KACtB,EAUG,GACJ,EACA,EACA,EACA,EACA,EACA,IACsC,CACtC,IAAM,EAAW,GAAS,OAAA,EAAA,EAAA,cAAqB,EAAU,QAAQ,CAC3D,EACJ,GACAA,EAAAA,qBACE,EACA,EACA,EAAa,cAAc,SAAS,oBACrC,CACG,GAAA,EAAA,EAAA,SAAc,EAAS,CAEvB,CAAE,cAAa,iBAAgB,uBAAsB,iBACzD,EAEI,EAAiD,CACrD,YAAA,EAAA,YACA,cAAA,EAAA,cACA,oBAAqBC,EAAAA,sBACrB,6BAAA,EAAA,6BACA,kBAAmB,EAAK,EAAM,EAAM,EAAQ,IAC1CC,EAAAA,iBACE,EACA,EACA,EACA,EACA,EACA,EACD,CACJ,CAED,GAAI,IAAQ,OAAQ,CAClB,GAAI,CAAC,EACH,MAAU,MACR,mBAAA,EAAA,EAAA,cAA+B,yBAA0BC,EAAAA,WAAW,OAAO,CAAC,wBAC7E,CAGH,IAAM,EAAM,EAAY,eACtB,EACA,EACA,EACA,EACA,EACD,CAED,GAAI,EACF,OAAO,EAAqB,EAAc,EAAI,CAIlD,GAAI,IAAQ,UAAW,CACrB,GAAI,CAAC,EACH,MAAU,MACR,mBAAA,EAAA,EAAA,cAA+B,4BAA6BA,EAAAA,WAAW,OAAO,CAAC,2BAChF,CAGH,IAAM,EAAM,EAAe,kBACzB,EACA,EACA,EACA,EACA,EACD,CAED,GAAI,EACF,OAAO,EAAqB,EAAc,EAAI,CAIlD,GAAI,CAAC,OAAQ,OAAQ,MAAO,MAAO,OAAQ,OAAO,CAAC,SAAS,EAAI,CAAE,CAChE,IAAM,EAASC,EAAAA,eACb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AuB,QAAU,CAAC,EACpC,GAAI,CACF,EAAc,EAAU,yBAAyB,MAC3C,CACN,EACE,IAAA,EAAA,EAAA,UAAY,YAAaA,EAAAA,WAAW,UAAU,CAAC,YAAA,EAAA,EAAA,cAAwB,yBAA0BA,EAAAA,WAAW,OAAO,CAAC,wBACrH,CAIL,GAAI,IAAuB,WAAa,CAAC,EACvC,GAAI,CACF,EAAiB,EAAU,4BAA4B,MACjD,CACN,EACE,IAAA,EAAA,EAAA,UAAY,YAAaA,EAAAA,WAAW,UAAU,CAAC,YAAA,EAAA,EAAA,cAAwB,4BAA6BA,EAAAA,WAAW,OAAO,CAAC,2BACxH,CAIL,IAAM,EAAS,EACb,EACA,EACA,EACA,CAAE,cAAa,iBAAgB,uBAAsB,gBAAe,CACpE,EACD,CAED,GAAI,CAAC,GAAQ,oBAAqB,CAChC,EACE,IAAA,EAAA,EAAA,UAAY,YAAaA,EAAAA,WAAW,UAAU,CAAC,iCAAA,EAAA,EAAA,eAAA,EAAA,EAAA,UAAsD,EAAS,EAAS,CAAC,GACxH,CAAE,UAAW,GAAM,CACpB,CACD,OAGF,GAAM,CAAE,sBAAqB,mBAAoB,EAEjD,GAAI,GAAS,UACX,IAAK,GAAM,CAAC,EAAK,KAAY,OAAO,QAAQ,EAAoB,CACzD,EAAQ,UAAU,CAAE,MAAK,UAAS,WAAU,CAAC,CAItD,MAAO,CAAE,kBAAiB,sBAAqB"}
1
+ {"version":3,"file":"extractContent.cjs","names":["extractDictionaryKey","ATTRIBUTES_TO_EXTRACT","extractTsContent","ANSIColors","processTsxFile","writeContentHelper"],"sources":["../../../src/extractContent/extractContent.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { extname, relative } from 'node:path';\nimport type * as t from '@babel/types';\nimport { detectFormatCommand } from '@intlayer/chokidar/cli';\nimport {\n ANSIColors,\n colorize,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getProjectRequire } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { extractTsContent } from './babelProcessor';\nimport { writeContentHelper } from './contentWriter';\nimport { processTsxFile } from './processTsxFile';\nimport {\n ATTRIBUTES_TO_EXTRACT,\n extractDictionaryKeyFromPath,\n type PackageName,\n shouldExtract,\n} from './utils';\nimport { extractDictionaryKey } from './utils/extractDictionaryKey';\nimport { generateKey } from './utils/generateKey';\n\nexport type ExtractIntlayerOptions = {\n configOptions?: GetConfigurationOptions;\n codeOnly?: boolean;\n declarationOnly?: boolean;\n unmergedDictionaries?: Record<string, unknown>;\n configuration?: IntlayerConfig;\n code?: string;\n onExtract?: (result: {\n key: string;\n content: Record<string, string>;\n filePath: string;\n }) => void | Promise<void>;\n};\n\ntype ExternalCompilerResult = {\n extractedContent: Record<string, string>;\n code: string;\n};\n\ntype ExternalCompilerOptions = {\n generateKey: typeof generateKey;\n shouldExtract: typeof shouldExtract;\n attributesToExtract: typeof ATTRIBUTES_TO_EXTRACT;\n extractDictionaryKeyFromPath: typeof extractDictionaryKeyFromPath;\n extractTsContent: (\n ast: unknown,\n code: string,\n keys: Set<string>,\n config: IntlayerConfig,\n path: string\n ) => ReturnType<typeof extractTsContent>;\n};\n\ntype VueCompiler = typeof import('@intlayer/vue-compiler');\ntype SvelteCompiler = typeof import('@intlayer/svelte-compiler');\n\n// Module caches\nlet vueCompiler: VueCompiler | null = null;\nlet svelteCompiler: SvelteCompiler | null = null;\n\ntype InternalExtractResult = {\n extractedContentMap: Record<string, Record<string, string>> | null;\n transformedCode: string | null;\n};\n\nconst formatCompilerResult = (\n componentKey: string,\n res?: ExternalCompilerResult\n): InternalExtractResult | undefined => {\n if (!res) return undefined;\n\n return {\n extractedContentMap: { [componentKey]: res.extractedContent },\n transformedCode: res.code,\n };\n};\n\ntype Dependencies = {\n vueCompiler: VueCompiler | null;\n svelteCompiler: SvelteCompiler | null;\n unmergedDictionaries: Record<string, unknown>;\n configuration: IntlayerConfig;\n};\n\nconst processFileInternal = (\n filePath: string,\n packageName: PackageName,\n options: ExtractIntlayerOptions | undefined,\n dependencies: Dependencies,\n saveComponent: boolean,\n providedComponentKey?: string\n): InternalExtractResult | undefined => {\n const fileText = options?.code ?? readFileSync(filePath, 'utf-8');\n const componentKey =\n providedComponentKey ??\n extractDictionaryKey(\n filePath,\n fileText,\n dependencies.configuration.compiler.dictionaryKeyPrefix\n );\n const ext = extname(filePath);\n\n const { vueCompiler, svelteCompiler, unmergedDictionaries, configuration } =\n dependencies;\n\n const compilerCommonOptions: ExternalCompilerOptions = {\n generateKey,\n shouldExtract,\n attributesToExtract: ATTRIBUTES_TO_EXTRACT,\n extractDictionaryKeyFromPath,\n extractTsContent: (ast, code, keys, config, path) =>\n extractTsContent(\n ast as t.File,\n code,\n keys,\n config,\n path,\n unmergedDictionaries\n ),\n };\n\n if (ext === '.vue') {\n if (!vueCompiler) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/vue-compiler', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n\n const res = vueCompiler.processVueFile(\n filePath,\n componentKey,\n packageName,\n compilerCommonOptions,\n saveComponent\n );\n\n if (res) {\n return formatCompilerResult(componentKey, res);\n }\n }\n\n if (ext === '.svelte') {\n if (!svelteCompiler) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/svelte-compiler', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n\n const res = svelteCompiler.processSvelteFile(\n filePath,\n componentKey,\n packageName,\n compilerCommonOptions,\n saveComponent\n );\n\n if (res) {\n return formatCompilerResult(componentKey, res);\n }\n }\n\n if (['.tsx', '.jsx', '.ts', '.js', '.cjs', '.mjs'].includes(ext)) {\n const result = processTsxFile(\n filePath,\n componentKey,\n packageName,\n configuration,\n saveComponent,\n unmergedDictionaries,\n fileText\n );\n\n if (result) {\n return {\n extractedContentMap: result.extractedContent,\n transformedCode: result.modifiedCode,\n };\n }\n }\n\n return undefined;\n};\n\nconst handleExtractionSideEffects = async (\n extractedContentMap: Record<string, Record<string, string>>,\n filePath: string,\n options: ExtractIntlayerOptions | undefined,\n {\n configuration,\n baseDir,\n appLogger,\n }: {\n configuration: IntlayerConfig;\n baseDir: string;\n appLogger: ReturnType<typeof getAppLogger>;\n },\n saveComponent: boolean\n) => {\n if (options?.onExtract) {\n for (const [key, content] of Object.entries(extractedContentMap)) {\n await options.onExtract({ key, content, filePath });\n }\n }\n\n const writeContent = !options?.codeOnly && !options?.onExtract;\n\n if (writeContent) {\n for (const [key, content] of Object.entries(extractedContentMap)) {\n const contentFilePath = await writeContentHelper(\n content,\n key,\n filePath,\n configuration\n );\n\n const relativeContentFilePath = relative(baseDir, contentFilePath);\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Created content file: ${colorizePath(relativeContentFilePath)}`\n );\n }\n }\n\n if (saveComponent) {\n const formatCommand = detectFormatCommand(configuration);\n\n if (formatCommand) {\n try {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'inherit',\n cwd: baseDir,\n });\n } catch (error) {\n console.error(error);\n }\n }\n\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Updated component: ${colorizePath(relative(baseDir, filePath))}`\n );\n }\n};\n\ntype ExtractResult = {\n transformedCode: string | null;\n extractedContentMap: Record<string, Record<string, string>>;\n};\n\ntype ExtractContext = {\n configuration: IntlayerConfig;\n appLogger: ReturnType<typeof getAppLogger>;\n baseDir: string;\n unmergedDictionaries: Record<string, unknown>;\n saveComponent: boolean;\n componentExtension: string;\n};\n\nconst buildContext = (\n filePath: string,\n options: ExtractIntlayerOptions | undefined\n): ExtractContext => {\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n const { baseDir } = configuration.system;\n const unmergedDictionaries =\n options?.unmergedDictionaries ?? getUnmergedDictionaries(configuration);\n const saveComponent = !options?.declarationOnly;\n const componentExtension = extname(filePath);\n\n return {\n configuration,\n appLogger,\n baseDir,\n unmergedDictionaries,\n saveComponent,\n componentExtension,\n };\n};\n\nexport const extractContent = async (\n filePath: string,\n packageName: PackageName,\n options?: ExtractIntlayerOptions\n): Promise<ExtractResult | undefined> => {\n const {\n configuration,\n appLogger,\n baseDir,\n unmergedDictionaries,\n saveComponent,\n componentExtension,\n } = buildContext(filePath, options);\n\n if (componentExtension === '.vue' && !vueCompiler) {\n try {\n vueCompiler = await import('@intlayer/vue-compiler');\n } catch {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Install ${colorizePath('@intlayer/vue-compiler', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n }\n\n if (componentExtension === '.svelte' && !svelteCompiler) {\n try {\n svelteCompiler = await import('@intlayer/svelte-compiler');\n } catch {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Install ${colorizePath('@intlayer/svelte-compiler', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n }\n\n const fileText = options?.code ?? readFileSync(filePath, 'utf-8');\n const dictionaryKey = extractDictionaryKey(\n filePath,\n fileText,\n configuration.compiler.dictionaryKeyPrefix\n );\n\n const result = processFileInternal(\n filePath,\n packageName,\n options,\n { vueCompiler, svelteCompiler, unmergedDictionaries, configuration },\n saveComponent,\n dictionaryKey\n );\n\n if (!result || !result.extractedContentMap) {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} No extractable text found in ${colorizePath(relative(baseDir, filePath))}`,\n { isVerbose: true }\n );\n return undefined;\n }\n\n await handleExtractionSideEffects(\n result.extractedContentMap,\n filePath,\n options,\n { configuration, baseDir, appLogger },\n saveComponent\n );\n\n return {\n transformedCode: result.transformedCode,\n extractedContentMap: result.extractedContentMap,\n };\n};\n\n/**\n * Synchronous variant of `extractContent` — used by the Babel plugin which\n * runs in a sync transform context (e.g. Next.js / Webpack).\n *\n * Differences from `extractContent`:\n * - Loads external compilers (Vue, Svelte) via `require()` instead of `import()`\n * - Fires `onExtract` callbacks as fire-and-forget (cannot await in sync context)\n * - Does NOT write dictionary files or run the code formatter; callers that\n * need persistence should supply an `onExtract` callback\n */\nexport const extractContentSync = (\n filePath: string,\n packageName: PackageName,\n options?: ExtractIntlayerOptions\n): ExtractResult | undefined => {\n const {\n configuration,\n appLogger,\n baseDir,\n unmergedDictionaries,\n saveComponent,\n componentExtension,\n } = buildContext(filePath, options);\n\n const requireFn = getProjectRequire();\n\n if (componentExtension === '.vue' && !vueCompiler) {\n try {\n vueCompiler = requireFn('@intlayer/vue-compiler') as VueCompiler;\n } catch {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Install ${colorizePath('@intlayer/vue-compiler', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n }\n\n if (componentExtension === '.svelte' && !svelteCompiler) {\n try {\n svelteCompiler = requireFn('@intlayer/svelte-compiler') as SvelteCompiler;\n } catch {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} Install ${colorizePath('@intlayer/svelte-compiler', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n }\n\n const result = processFileInternal(\n filePath,\n packageName,\n options,\n { vueCompiler, svelteCompiler, unmergedDictionaries, configuration },\n saveComponent\n );\n\n if (!result?.extractedContentMap) {\n appLogger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} No extractable text found in ${colorizePath(relative(baseDir, filePath))}`,\n { isVerbose: true }\n );\n return undefined;\n }\n\n const { extractedContentMap, transformedCode } = result;\n\n if (options?.onExtract) {\n for (const [key, content] of Object.entries(extractedContentMap)) {\n void options.onExtract({ key, content, filePath });\n }\n }\n\n return { transformedCode, extractedContentMap };\n};\n"],"mappings":"+nBAmEI,EAAkC,KAClC,EAAwC,KAO5C,MAAM,GACJ,EACA,IACsC,CACjC,KAEL,MAAO,CACL,oBAAqB,EAAG,GAAe,EAAI,iBAAkB,CAC7D,gBAAiB,EAAI,KACtB,EAUG,GACJ,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iB,EAAU,4BAA4B,MACjD,CACN,EACE,IAAA,EAAA,EAAA,UAAY,YAAaA,EAAAA,WAAW,UAAU,CAAC,YAAA,EAAA,EAAA,cAAwB,4BAA6BA,EAAAA,WAAW,OAAO,CAAC,2BACxH,CAIL,IAAM,EAAS,EACb,EACA,EACA,EACA,CAAE,cAAa,iBAAgB,uBAAsB,gBAAe,CACpE,EACD,CAED,GAAI,CAAC,GAAQ,oBAAqB,CAChC,EACE,IAAA,EAAA,EAAA,UAAY,YAAaA,EAAAA,WAAW,UAAU,CAAC,iCAAA,EAAA,EAAA,eAAA,EAAA,EAAA,UAAsD,EAAS,EAAS,CAAC,GACxH,CAAE,UAAW,GAAM,CACpB,CACD,OAGF,GAAM,CAAE,sBAAqB,mBAAoB,EAEjD,GAAI,GAAS,UACX,IAAK,GAAM,CAAC,EAAK,KAAY,OAAO,QAAQ,EAAoB,CACzD,EAAQ,UAAU,CAAE,MAAK,UAAS,WAAU,CAAC,CAItD,MAAO,CAAE,kBAAiB,sBAAqB"}
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./utils/constants.cjs`),n=require(`./utils/getExistingIntlayerInfo.cjs`),r=require(`./babelProcessor.cjs`);let i=require(`node:fs`),a=require(`@intlayer/chokidar/cli`),o=require(`@babel/parser`),s=require(`node:child_process`),c=require(`@babel/traverse`);c=e.__toESM(c);let l=require(`@babel/types`);l=e.__toESM(l);const u=typeof c.default==`function`?c.default:c.default.default,d=(e,c,d,f,p=!0,m={},h)=>{let g=h??(0,i.readFileSync)(e,`utf-8`),_=(0,o.parse)(g,{sourceType:`module`,plugins:[`jsx`,`typescript`]}),v=_.program.directives.some(e=>e.value.value===`use client`),y=t.SERVER_CAPABLE_PACKAGES.has(d)&&!v?`${d}/server`:d,b=d===`solid-intlayer`,{extractedContent:x,replacements:S,componentsNeedingHooks:C,componentKeyMap:w,componentPaths:T,hookMap:E}=r.extractBabelContentForComponents(_,g,new Set,c,f,e,m);if(Object.keys(x).length===0)return null;let D=[],O=new Map;for(let e of T)O.set(e.node,e);let k=new Map;for(let e of T)k.set(e.node,n.getExistingIntlayerInfo(e));let A=e=>{let t=e;for(;t;){if(O.has(t.node))return k.get(t.node);t=t.parentPath}},j=e=>{let t=e;for(;t;){let e=O.get(t.node);if(e){let t=k.get(e.node);if(t)return t.hook;if(C.has(e))return E.get(e.node)||`useIntlayer`}t=t.parentPath}return`useIntlayer`};for(let{path:e,key:t,type:n,variables:r,childrenToReplace:i}of S){let a=A(e),o=a?.variableName??`content`,s=a?.isDestructured?t:b?`${o}().${t}`:`${o}.${t}`,c=j(e)===`getIntlayer`?``:`.value`;if(n===`jsx-text`&&e.isJSXText())D.push({start:e.node.start,end:e.node.end,replacement:`{${s}}`});else if(n===`jsx-attribute`&&e.isJSXAttribute()){let t=e.node.value;t&&D.push({start:t.start,end:t.end,replacement:`{${s}${c}}`})}else if(n===`string-literal`&&e.isStringLiteral())D.push({start:e.node.start,end:e.node.end,replacement:`${s}${c}`});else if(n===`jsx-text-combined`&&i&&i.length>0){let e=`{${s}}`,t=i[0].start,n=i[i.length-1].end;D.push({start:t,end:n,replacement:e})}else if(n===`jsx-insertion`&&r&&i&&i.length>0){let e=`{${s}({ ${r.map(e=>{let[t,n]=e.split(`:`).map(e=>e.trim());return`${t}: ${n}`}).join(`, `)} })}`,t=i[0].start,n=i[i.length-1].end;D.push({start:t,end:n,replacement:e})}}let M=!1,N=!1;for(let e of C){let t=w.get(e.node),n=k.get(e.node);if(n){if(n.hook===`useIntlayer`&&(M=!0),n.hook===`getIntlayer`&&(N=!0),n.isDestructured&&n.objectPatternNode){let t=new Set;for(let{path:n,key:r}of S){let i=n;for(;i;){if(i.node===e.node){t.add(r);break}i=i.parentPath}}let r=[...t].filter(e=>!n.existingDestructuredKeys.includes(e));if(r.length>0){let{objectPatternNode:e}=n,t=e.properties[e.properties.length-1];D.push({start:t.end,end:t.end,replacement:`, ${r.join(`, `)}`})}}}else{let n=E.get(e.node)||`useIntlayer`;n===`useIntlayer`&&(M=!0),n===`getIntlayer`&&(N=!0);let r=e.get(`body`),i=`\n const content = ${n}('${t}');\n`;if(r.isBlockStatement())D.push({start:r.node.start+1,end:r.node.start+1,replacement:i});else if(r.isExpression()){let e=r.node.start,i=r.node.end,a=-1,o=-1;for(let t=e-1;t>=0;t--){let e=g[t];if(e===`(`){a=t;break}if(e!==` `&&e!==`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`./utils/constants.cjs`),n=require(`./utils/getExistingIntlayerInfo.cjs`),r=require(`./babelProcessor.cjs`);let i=require(`node:fs`),a=require(`@intlayer/chokidar/cli`),o=require(`@babel/parser`),s=require(`node:child_process`),c=require(`@babel/traverse`);c=e.t(c);let l=require(`@babel/types`);l=e.t(l);const u=typeof c.default==`function`?c.default:c.default.default,d=(e,c,d,f,p=!0,m={},h)=>{let g=h??(0,i.readFileSync)(e,`utf-8`),_=(0,o.parse)(g,{sourceType:`module`,plugins:[`jsx`,`typescript`]}),v=_.program.directives.some(e=>e.value.value===`use client`),y=t.SERVER_CAPABLE_PACKAGES.has(d)&&!v?`${d}/server`:d,b=d===`solid-intlayer`,{extractedContent:x,replacements:S,componentsNeedingHooks:C,componentKeyMap:w,componentPaths:T,hookMap:E}=r.extractBabelContentForComponents(_,g,new Set,c,f,e,m);if(Object.keys(x).length===0)return null;let D=[],O=new Map;for(let e of T)O.set(e.node,e);let k=new Map;for(let e of T)k.set(e.node,n.getExistingIntlayerInfo(e));let A=e=>{let t=e;for(;t;){if(O.has(t.node))return k.get(t.node);t=t.parentPath}},j=e=>{let t=e;for(;t;){let e=O.get(t.node);if(e){let t=k.get(e.node);if(t)return t.hook;if(C.has(e))return E.get(e.node)||`useIntlayer`}t=t.parentPath}return`useIntlayer`};for(let{path:e,key:t,type:n,variables:r,childrenToReplace:i}of S){let a=A(e),o=a?.variableName??`content`,s=a?.isDestructured?t:b?`${o}().${t}`:`${o}.${t}`,c=j(e)===`getIntlayer`?``:`.value`;if(n===`jsx-text`&&e.isJSXText())D.push({start:e.node.start,end:e.node.end,replacement:`{${s}}`});else if(n===`jsx-attribute`&&e.isJSXAttribute()){let t=e.node.value;t&&D.push({start:t.start,end:t.end,replacement:`{${s}${c}}`})}else if(n===`string-literal`&&e.isStringLiteral())D.push({start:e.node.start,end:e.node.end,replacement:`${s}${c}`});else if(n===`jsx-text-combined`&&i&&i.length>0){let e=`{${s}}`,t=i[0].start,n=i[i.length-1].end;D.push({start:t,end:n,replacement:e})}else if(n===`jsx-insertion`&&r&&i&&i.length>0){let e=`{${s}({ ${r.map(e=>{let[t,n]=e.split(`:`).map(e=>e.trim());return`${t}: ${n}`}).join(`, `)} })}`,t=i[0].start,n=i[i.length-1].end;D.push({start:t,end:n,replacement:e})}}let M=!1,N=!1;for(let e of C){let t=w.get(e.node),n=k.get(e.node);if(n){if(n.hook===`useIntlayer`&&(M=!0),n.hook===`getIntlayer`&&(N=!0),n.isDestructured&&n.objectPatternNode){let t=new Set;for(let{path:n,key:r}of S){let i=n;for(;i;){if(i.node===e.node){t.add(r);break}i=i.parentPath}}let r=[...t].filter(e=>!n.existingDestructuredKeys.includes(e));if(r.length>0){let{objectPatternNode:e}=n,t=e.properties[e.properties.length-1];D.push({start:t.end,end:t.end,replacement:`, ${r.join(`, `)}`})}}}else{let n=E.get(e.node)||`useIntlayer`;n===`useIntlayer`&&(M=!0),n===`getIntlayer`&&(N=!0);let r=e.get(`body`),i=`\n const content = ${n}('${t}');\n`;if(r.isBlockStatement())D.push({start:r.node.start+1,end:r.node.start+1,replacement:i});else if(r.isExpression()){let e=r.node.start,i=r.node.end,a=-1,o=-1;for(let t=e-1;t>=0;t--){let e=g[t];if(e===`(`){a=t;break}if(e!==` `&&e!==`
2
2
  `&&e!==`\r`&&e!==` `)break}if(a!==-1)for(let e=i;e<g.length;e++){let t=g[e];if(t===`)`){o=e;break}if(t!==` `&&t!==`
3
3
  `&&t!==`\r`&&t!==` `)break}a!==-1&&o!==-1?(D.push({start:o,end:o+1,replacement:`)
4
4
  }`}),D.push({start:a,end:a+1,replacement:`{\n const content = ${n}('${t}');\n return (`})):(D.push({start:i,end:i,replacement:`