@intlayer/babel 8.4.4 → 8.4.5

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 (139) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/cjs/babel-plugin-intlayer-extract.cjs +75 -1
  3. package/dist/cjs/babel-plugin-intlayer-extract.cjs.map +1 -1
  4. package/dist/cjs/babel-plugin-intlayer-optimize.cjs +306 -1
  5. package/dist/cjs/babel-plugin-intlayer-optimize.cjs.map +1 -1
  6. package/dist/cjs/extractContent/babelProcessor.cjs +261 -1
  7. package/dist/cjs/extractContent/babelProcessor.cjs.map +1 -1
  8. package/dist/cjs/extractContent/contentWriter.cjs +134 -1
  9. package/dist/cjs/extractContent/contentWriter.cjs.map +1 -1
  10. package/dist/cjs/extractContent/extractContent.cjs +184 -1
  11. package/dist/cjs/extractContent/extractContent.cjs.map +1 -1
  12. package/dist/cjs/extractContent/index.cjs +26 -1
  13. package/dist/cjs/extractContent/processTsxFile.cjs +263 -5
  14. package/dist/cjs/extractContent/processTsxFile.cjs.map +1 -1
  15. package/dist/cjs/extractContent/utils/constants.cjs +42 -1
  16. package/dist/cjs/extractContent/utils/constants.cjs.map +1 -1
  17. package/dist/cjs/extractContent/utils/detectPackageName.cjs +26 -1
  18. package/dist/cjs/extractContent/utils/detectPackageName.cjs.map +1 -1
  19. package/dist/cjs/extractContent/utils/extractDictionaryInfo.cjs +77 -1
  20. package/dist/cjs/extractContent/utils/extractDictionaryInfo.cjs.map +1 -1
  21. package/dist/cjs/extractContent/utils/extractDictionaryKey.cjs +29 -1
  22. package/dist/cjs/extractContent/utils/extractDictionaryKey.cjs.map +1 -1
  23. package/dist/cjs/extractContent/utils/generateKey.cjs +16 -1
  24. package/dist/cjs/extractContent/utils/generateKey.cjs.map +1 -1
  25. package/dist/cjs/extractContent/utils/getComponentName.cjs +18 -1
  26. package/dist/cjs/extractContent/utils/getComponentName.cjs.map +1 -1
  27. package/dist/cjs/extractContent/utils/getExistingIntlayerInfo.cjs +50 -1
  28. package/dist/cjs/extractContent/utils/getExistingIntlayerInfo.cjs.map +1 -1
  29. package/dist/cjs/extractContent/utils/getOrGenerateKey.cjs +19 -1
  30. package/dist/cjs/extractContent/utils/getOrGenerateKey.cjs.map +1 -1
  31. package/dist/cjs/extractContent/utils/index.cjs +27 -1
  32. package/dist/cjs/extractContent/utils/resolveDictionaryKey.cjs +34 -1
  33. package/dist/cjs/extractContent/utils/resolveDictionaryKey.cjs.map +1 -1
  34. package/dist/cjs/extractContent/utils/shouldExtract.cjs +23 -1
  35. package/dist/cjs/extractContent/utils/shouldExtract.cjs.map +1 -1
  36. package/dist/cjs/getExtractPluginOptions.cjs +41 -1
  37. package/dist/cjs/getExtractPluginOptions.cjs.map +1 -1
  38. package/dist/cjs/getOptimizePluginOptions.cjs +63 -1
  39. package/dist/cjs/getOptimizePluginOptions.cjs.map +1 -1
  40. package/dist/cjs/index.cjs +34 -1
  41. package/dist/esm/_virtual/_rolldown/runtime.mjs +8 -0
  42. package/dist/esm/babel-plugin-intlayer-extract.mjs +72 -1
  43. package/dist/esm/babel-plugin-intlayer-extract.mjs.map +1 -1
  44. package/dist/esm/babel-plugin-intlayer-optimize.mjs +304 -1
  45. package/dist/esm/babel-plugin-intlayer-optimize.mjs.map +1 -1
  46. package/dist/esm/extractContent/babelProcessor.mjs +255 -1
  47. package/dist/esm/extractContent/babelProcessor.mjs.map +1 -1
  48. package/dist/esm/extractContent/contentWriter.mjs +129 -1
  49. package/dist/esm/extractContent/contentWriter.mjs.map +1 -1
  50. package/dist/esm/extractContent/extractContent.mjs +180 -1
  51. package/dist/esm/extractContent/extractContent.mjs.map +1 -1
  52. package/dist/esm/extractContent/index.mjs +10 -1
  53. package/dist/esm/extractContent/processTsxFile.mjs +259 -5
  54. package/dist/esm/extractContent/processTsxFile.mjs.map +1 -1
  55. package/dist/esm/extractContent/utils/constants.mjs +38 -1
  56. package/dist/esm/extractContent/utils/constants.mjs.map +1 -1
  57. package/dist/esm/extractContent/utils/detectPackageName.mjs +24 -1
  58. package/dist/esm/extractContent/utils/detectPackageName.mjs.map +1 -1
  59. package/dist/esm/extractContent/utils/extractDictionaryInfo.mjs +72 -1
  60. package/dist/esm/extractContent/utils/extractDictionaryInfo.mjs.map +1 -1
  61. package/dist/esm/extractContent/utils/extractDictionaryKey.mjs +26 -1
  62. package/dist/esm/extractContent/utils/extractDictionaryKey.mjs.map +1 -1
  63. package/dist/esm/extractContent/utils/generateKey.mjs +14 -1
  64. package/dist/esm/extractContent/utils/generateKey.mjs.map +1 -1
  65. package/dist/esm/extractContent/utils/getComponentName.mjs +15 -1
  66. package/dist/esm/extractContent/utils/getComponentName.mjs.map +1 -1
  67. package/dist/esm/extractContent/utils/getExistingIntlayerInfo.mjs +47 -1
  68. package/dist/esm/extractContent/utils/getExistingIntlayerInfo.mjs.map +1 -1
  69. package/dist/esm/extractContent/utils/getOrGenerateKey.mjs +18 -1
  70. package/dist/esm/extractContent/utils/getOrGenerateKey.mjs.map +1 -1
  71. package/dist/esm/extractContent/utils/index.mjs +12 -1
  72. package/dist/esm/extractContent/utils/resolveDictionaryKey.mjs +32 -1
  73. package/dist/esm/extractContent/utils/resolveDictionaryKey.mjs.map +1 -1
  74. package/dist/esm/extractContent/utils/shouldExtract.mjs +21 -1
  75. package/dist/esm/extractContent/utils/shouldExtract.mjs.map +1 -1
  76. package/dist/esm/getExtractPluginOptions.mjs +38 -1
  77. package/dist/esm/getExtractPluginOptions.mjs.map +1 -1
  78. package/dist/esm/getOptimizePluginOptions.mjs +63 -1
  79. package/dist/esm/getOptimizePluginOptions.mjs.map +1 -0
  80. package/dist/esm/index.mjs +14 -1
  81. package/dist/types/babel-plugin-intlayer-extract.d.ts +1 -1
  82. package/dist/types/extractContent/contentWriter.d.ts +36 -2
  83. package/dist/types/extractContent/contentWriter.d.ts.map +1 -0
  84. package/dist/types/extractContent/extractContent.d.ts +37 -2
  85. package/dist/types/extractContent/extractContent.d.ts.map +1 -0
  86. package/dist/types/extractContent/index.d.ts +8 -8
  87. package/dist/types/extractContent/processTsxFile.d.ts +1 -1
  88. package/dist/types/extractContent/processTsxFile.d.ts.map +1 -1
  89. package/dist/types/extractContent/utils/constants.d.ts +20 -2
  90. package/dist/types/extractContent/utils/constants.d.ts.map +1 -0
  91. package/dist/types/extractContent/utils/detectPackageName.d.ts +10 -2
  92. package/dist/types/extractContent/utils/detectPackageName.d.ts.map +1 -0
  93. package/dist/types/extractContent/utils/extractDictionaryInfo.d.ts +28 -2
  94. package/dist/types/extractContent/utils/extractDictionaryInfo.d.ts.map +1 -0
  95. package/dist/types/extractContent/utils/extractDictionaryKey.d.ts +11 -2
  96. package/dist/types/extractContent/utils/extractDictionaryKey.d.ts.map +1 -0
  97. package/dist/types/extractContent/utils/generateKey.d.ts +5 -2
  98. package/dist/types/extractContent/utils/generateKey.d.ts.map +1 -0
  99. package/dist/types/extractContent/utils/getComponentName.d.ts +10 -2
  100. package/dist/types/extractContent/utils/getComponentName.d.ts.map +1 -0
  101. package/dist/types/extractContent/utils/getExistingIntlayerInfo.d.ts +19 -2
  102. package/dist/types/extractContent/utils/getExistingIntlayerInfo.d.ts.map +1 -0
  103. package/dist/types/extractContent/utils/getOrGenerateKey.d.ts +8 -2
  104. package/dist/types/extractContent/utils/getOrGenerateKey.d.ts.map +1 -0
  105. package/dist/types/extractContent/utils/index.d.ts +10 -10
  106. package/dist/types/extractContent/utils/resolveDictionaryKey.d.ts +12 -2
  107. package/dist/types/extractContent/utils/resolveDictionaryKey.d.ts.map +1 -0
  108. package/dist/types/extractContent/utils/shouldExtract.d.ts +14 -2
  109. package/dist/types/extractContent/utils/shouldExtract.d.ts.map +1 -0
  110. package/dist/types/index.d.ts +8 -8
  111. package/package.json +9 -9
  112. package/dist/cjs/chunk-Bmb41Sf3.cjs +0 -1
  113. package/dist/esm/getOptimizePluginOptions-BAFPfVq5.mjs +0 -2
  114. package/dist/esm/getOptimizePluginOptions-BAFPfVq5.mjs.map +0 -1
  115. package/dist/types/constants-BLArAqsA.d.ts +0 -20
  116. package/dist/types/constants-BLArAqsA.d.ts.map +0 -1
  117. package/dist/types/contentWriter-I2Ch5yQY.d.ts +0 -36
  118. package/dist/types/contentWriter-I2Ch5yQY.d.ts.map +0 -1
  119. package/dist/types/detectPackageName-C0TfbHa3.d.ts +0 -10
  120. package/dist/types/detectPackageName-C0TfbHa3.d.ts.map +0 -1
  121. package/dist/types/extractContent-AFk68B7L.d.ts +0 -37
  122. package/dist/types/extractContent-AFk68B7L.d.ts.map +0 -1
  123. package/dist/types/extractDictionaryInfo-5GLZsA_I.d.ts +0 -28
  124. package/dist/types/extractDictionaryInfo-5GLZsA_I.d.ts.map +0 -1
  125. package/dist/types/extractDictionaryKey-CHgfwRo6.d.ts +0 -11
  126. package/dist/types/extractDictionaryKey-CHgfwRo6.d.ts.map +0 -1
  127. package/dist/types/generateKey-Cgdh6seq.d.ts +0 -5
  128. package/dist/types/generateKey-Cgdh6seq.d.ts.map +0 -1
  129. package/dist/types/getComponentName-DGlmJa-F.d.ts +0 -10
  130. package/dist/types/getComponentName-DGlmJa-F.d.ts.map +0 -1
  131. package/dist/types/getExistingIntlayerInfo-Cy6Vpcfb.d.ts +0 -19
  132. package/dist/types/getExistingIntlayerInfo-Cy6Vpcfb.d.ts.map +0 -1
  133. package/dist/types/getOrGenerateKey-DtIR0WeU.d.ts +0 -8
  134. package/dist/types/getOrGenerateKey-DtIR0WeU.d.ts.map +0 -1
  135. package/dist/types/index-DK_kKFOF.d.ts +0 -1
  136. package/dist/types/resolveDictionaryKey-CcbieIfX.d.ts +0 -12
  137. package/dist/types/resolveDictionaryKey-CcbieIfX.d.ts.map +0 -1
  138. package/dist/types/shouldExtract-BRaeB9eg.d.ts +0 -14
  139. package/dist/types/shouldExtract-BRaeB9eg.d.ts.map +0 -1
@@ -1,2 +1,35 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../../chunk-Bmb41Sf3.cjs`);let e=require(`node:fs`),t=require(`node:path`),n=require(`@intlayer/unmerged-dictionaries-entry`);const r=(r,i,a,o,s=new Set)=>{let c=o??(0,n.getUnmergedDictionaries)(a)??{},{fileExtensions:l}=a.content,u=(0,t.dirname)(i),d=l[0],f=d.startsWith(`.`)?d:`.${d}`,p=0;for(;p<100;){let n=p===0?r:`${r}${p}`,i=c[n],a=(0,t.join)(u,`${n}${f}`),o=s.has(n),l=i&&i.length>0,d=(0,e.existsSync)(a);if(!o&&!l&&!d)return n;p++}return r};exports.resolveDictionaryKey=r;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
3
+ let node_fs = require("node:fs");
4
+ let node_path = require("node:path");
5
+ let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
6
+
7
+ //#region src/extractContent/utils/resolveDictionaryKey.ts
8
+ /**
9
+ * Resolves a unique dictionary key, checking for existing dictionaries and files.
10
+ * Note: this chokidar-specific variant fetches unmergedDictionaries internally
11
+ * from the configuration (unlike the `@intlayer/babel` version which takes it as a parameter).
12
+ */
13
+ const resolveDictionaryKey = (initialKey, filePath, configuration, unmergedDictionaries, usedKeys = /* @__PURE__ */ new Set()) => {
14
+ const dicts = unmergedDictionaries ?? (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration) ?? {};
15
+ const { fileExtensions } = configuration.content;
16
+ const dirName = (0, node_path.dirname)(filePath);
17
+ const firstExtension = fileExtensions[0];
18
+ const extension = firstExtension.startsWith(".") ? firstExtension : `.${firstExtension}`;
19
+ let index = 0;
20
+ while (index < 100) {
21
+ const keyToTest = index === 0 ? initialKey : `${initialKey}${index}`;
22
+ const dictionaries = dicts[keyToTest];
23
+ const contentFilePath = (0, node_path.join)(dirName, `${keyToTest}${extension}`);
24
+ const isKeyUsed = usedKeys.has(keyToTest);
25
+ const hasDictionaries = dictionaries && dictionaries.length > 0;
26
+ const fileExists = (0, node_fs.existsSync)(contentFilePath);
27
+ if (!isKeyUsed && !hasDictionaries && !fileExists) return keyToTest;
28
+ index++;
29
+ }
30
+ return initialKey;
31
+ };
32
+
33
+ //#endregion
34
+ exports.resolveDictionaryKey = resolveDictionaryKey;
2
35
  //# sourceMappingURL=resolveDictionaryKey.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveDictionaryKey.cjs","names":[],"sources":["../../../../src/extractContent/utils/resolveDictionaryKey.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\n/**\n * Resolves a unique dictionary key, checking for existing dictionaries and files.\n * Note: this chokidar-specific variant fetches unmergedDictionaries internally\n * from the configuration (unlike the `@intlayer/babel` version which takes it as a parameter).\n */\nexport const resolveDictionaryKey = (\n initialKey: string,\n filePath: string,\n configuration: IntlayerConfig,\n unmergedDictionaries?: Record<string, unknown>,\n usedKeys: Set<string> = new Set()\n): string => {\n const dicts =\n unmergedDictionaries ?? getUnmergedDictionaries(configuration) ?? {};\n\n const { fileExtensions } = configuration.content;\n\n const dirName = dirname(filePath);\n const firstExtension = fileExtensions[0];\n const extension = firstExtension.startsWith('.')\n ? firstExtension\n : `.${firstExtension}`;\n\n let index = 0;\n\n while (index < 100) {\n const keyToTest = index === 0 ? initialKey : `${initialKey}${index}`;\n const dictionaries = dicts[keyToTest] as Dictionary[] | undefined;\n const contentFilePath = join(dirName, `${keyToTest}${extension}`);\n const isKeyUsed = usedKeys.has(keyToTest);\n const hasDictionaries = dictionaries && dictionaries.length > 0;\n const fileExists = existsSync(contentFilePath);\n\n if (!isKeyUsed && !hasDictionaries && !fileExists) {\n return keyToTest;\n }\n index++;\n }\n\n return initialKey;\n};\n"],"mappings":"0MAWA,MAAa,GACX,EACA,EACA,EACA,EACA,EAAwB,IAAI,MACjB,CACX,IAAM,EACJ,IAAA,EAAA,EAAA,yBAAgD,EAAc,EAAI,EAAE,CAEhE,CAAE,kBAAmB,EAAc,QAEnC,GAAA,EAAA,EAAA,SAAkB,EAAS,CAC3B,EAAiB,EAAe,GAChC,EAAY,EAAe,WAAW,IAAI,CAC5C,EACA,IAAI,IAEJ,EAAQ,EAEZ,KAAO,EAAQ,KAAK,CAClB,IAAM,EAAY,IAAU,EAAI,EAAa,GAAG,IAAa,IACvD,EAAe,EAAM,GACrB,GAAA,EAAA,EAAA,MAAuB,EAAS,GAAG,IAAY,IAAY,CAC3D,EAAY,EAAS,IAAI,EAAU,CACnC,EAAkB,GAAgB,EAAa,OAAS,EACxD,GAAA,EAAA,EAAA,YAAwB,EAAgB,CAE9C,GAAI,CAAC,GAAa,CAAC,GAAmB,CAAC,EACrC,OAAO,EAET,IAGF,OAAO"}
1
+ {"version":3,"file":"resolveDictionaryKey.cjs","names":[],"sources":["../../../../src/extractContent/utils/resolveDictionaryKey.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\n/**\n * Resolves a unique dictionary key, checking for existing dictionaries and files.\n * Note: this chokidar-specific variant fetches unmergedDictionaries internally\n * from the configuration (unlike the `@intlayer/babel` version which takes it as a parameter).\n */\nexport const resolveDictionaryKey = (\n initialKey: string,\n filePath: string,\n configuration: IntlayerConfig,\n unmergedDictionaries?: Record<string, unknown>,\n usedKeys: Set<string> = new Set()\n): string => {\n const dicts =\n unmergedDictionaries ?? getUnmergedDictionaries(configuration) ?? {};\n\n const { fileExtensions } = configuration.content;\n\n const dirName = dirname(filePath);\n const firstExtension = fileExtensions[0];\n const extension = firstExtension.startsWith('.')\n ? firstExtension\n : `.${firstExtension}`;\n\n let index = 0;\n\n while (index < 100) {\n const keyToTest = index === 0 ? initialKey : `${initialKey}${index}`;\n const dictionaries = dicts[keyToTest] as Dictionary[] | undefined;\n const contentFilePath = join(dirName, `${keyToTest}${extension}`);\n const isKeyUsed = usedKeys.has(keyToTest);\n const hasDictionaries = dictionaries && dictionaries.length > 0;\n const fileExists = existsSync(contentFilePath);\n\n if (!isKeyUsed && !hasDictionaries && !fileExists) {\n return keyToTest;\n }\n index++;\n }\n\n return initialKey;\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,wBACX,YACA,UACA,eACA,sBACA,2BAAwB,IAAI,KAAK,KACtB;CACX,MAAM,QACJ,2FAAgD,cAAc,IAAI,EAAE;CAEtE,MAAM,EAAE,mBAAmB,cAAc;CAEzC,MAAM,iCAAkB,SAAS;CACjC,MAAM,iBAAiB,eAAe;CACtC,MAAM,YAAY,eAAe,WAAW,IAAI,GAC5C,iBACA,IAAI;CAER,IAAI,QAAQ;AAEZ,QAAO,QAAQ,KAAK;EAClB,MAAM,YAAY,UAAU,IAAI,aAAa,GAAG,aAAa;EAC7D,MAAM,eAAe,MAAM;EAC3B,MAAM,sCAAuB,SAAS,GAAG,YAAY,YAAY;EACjE,MAAM,YAAY,SAAS,IAAI,UAAU;EACzC,MAAM,kBAAkB,gBAAgB,aAAa,SAAS;EAC9D,MAAM,qCAAwB,gBAAgB;AAE9C,MAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,WACrC,QAAO;AAET;;AAGF,QAAO"}
@@ -1,2 +1,24 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=e=>{let t=e.trim();return!(!t||!t.includes(` `)||!/^[A-Z]/.test(t)||t.startsWith(`{`)||t.startsWith(`v-`))};exports.shouldExtract=e;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/extractContent/utils/shouldExtract.ts
4
+ /**
5
+ * Checks whether the given text should be extracted as a translatable string.
6
+ *
7
+ * Filters out:
8
+ * - Empty strings
9
+ * - Single words (typically icons or technical terms)
10
+ * - Strings not starting with an uppercase letter (likely technical values)
11
+ * - Dynamic content patterns like Vue bindings (`v-`) or object patterns (`{`)
12
+ */
13
+ const shouldExtract = (text) => {
14
+ const trimmed = text.trim();
15
+ if (!trimmed) return false;
16
+ if (!trimmed.includes(" ")) return false;
17
+ if (!/^[A-Z]/.test(trimmed)) return false;
18
+ if (trimmed.startsWith("{") || trimmed.startsWith("v-")) return false;
19
+ return true;
20
+ };
21
+
22
+ //#endregion
23
+ exports.shouldExtract = shouldExtract;
2
24
  //# sourceMappingURL=shouldExtract.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"shouldExtract.cjs","names":[],"sources":["../../../../src/extractContent/utils/shouldExtract.ts"],"sourcesContent":["/**\n * Checks whether the given text should be extracted as a translatable string.\n *\n * Filters out:\n * - Empty strings\n * - Single words (typically icons or technical terms)\n * - Strings not starting with an uppercase letter (likely technical values)\n * - Dynamic content patterns like Vue bindings (`v-`) or object patterns (`{`)\n */\nexport const shouldExtract = (text: string): boolean => {\n const trimmed = text.trim();\n\n if (!trimmed) return false;\n\n // We usually want to extract full sentences or labels, not single technical words\n if (!trimmed.includes(' ')) return false;\n\n // We assume content to extract starts with an uppercase letter\n if (!/^[A-Z]/.test(trimmed)) return false;\n\n // Ignore dynamic content patterns\n if (trimmed.startsWith('{') || trimmed.startsWith('v-')) return false;\n\n return true;\n};\n"],"mappings":"mEASA,MAAa,EAAiB,GAA0B,CACtD,IAAM,EAAU,EAAK,MAAM,CAa3B,MAFA,EATI,CAAC,GAGD,CAAC,EAAQ,SAAS,IAAI,EAGtB,CAAC,SAAS,KAAK,EAAQ,EAGvB,EAAQ,WAAW,IAAI,EAAI,EAAQ,WAAW,KAAK"}
1
+ {"version":3,"file":"shouldExtract.cjs","names":[],"sources":["../../../../src/extractContent/utils/shouldExtract.ts"],"sourcesContent":["/**\n * Checks whether the given text should be extracted as a translatable string.\n *\n * Filters out:\n * - Empty strings\n * - Single words (typically icons or technical terms)\n * - Strings not starting with an uppercase letter (likely technical values)\n * - Dynamic content patterns like Vue bindings (`v-`) or object patterns (`{`)\n */\nexport const shouldExtract = (text: string): boolean => {\n const trimmed = text.trim();\n\n if (!trimmed) return false;\n\n // We usually want to extract full sentences or labels, not single technical words\n if (!trimmed.includes(' ')) return false;\n\n // We assume content to extract starts with an uppercase letter\n if (!/^[A-Z]/.test(trimmed)) return false;\n\n // Ignore dynamic content patterns\n if (trimmed.startsWith('{') || trimmed.startsWith('v-')) return false;\n\n return true;\n};\n"],"mappings":";;;;;;;;;;;;AASA,MAAa,iBAAiB,SAA0B;CACtD,MAAM,UAAU,KAAK,MAAM;AAE3B,KAAI,CAAC,QAAS,QAAO;AAGrB,KAAI,CAAC,QAAQ,SAAS,IAAI,CAAE,QAAO;AAGnC,KAAI,CAAC,SAAS,KAAK,QAAQ,CAAE,QAAO;AAGpC,KAAI,QAAQ,WAAW,IAAI,IAAI,QAAQ,WAAW,KAAK,CAAE,QAAO;AAEhE,QAAO"}
@@ -1,2 +1,42 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-Bmb41Sf3.cjs`),t=require(`./extractContent/contentWriter.cjs`);let n=require(`@intlayer/chokidar/utils`),r=require(`@intlayer/config/colors`);r=e.t(r);let i=require(`@intlayer/config/defaultValues`),a=require(`@intlayer/config/logger`),o=require(`@intlayer/config/node`);const s=(e=(0,o.getConfiguration)(),s=process.env.INTLAYER_IS_DEV_COMMAND)=>{let c=s===`dev`||s===`serve`||s===`true`,l=c?`dev`:`build`,u=(0,a.getAppLogger)(e);e.compiler?.enabled===`build-only`&&c&&u(`${(0,a.colorize)(`Compiler:`,r.GREY_DARK)} i18n function is not inserted in the code in dev mode to optimize build time. (to test i18n in dev mode set compiler.enabled to true)`);let d=e.compiler?.enabled??i.COMPILER_ENABLED;d===`build-only`&&(d=l?l===`build`:process.env.NODE_ENV===`production`);let f=(0,n.buildComponentFilesList)(e);return{enabled:d,configuration:e,filesList:f,onExtract:async({dictionaryKey:n,content:r,filePath:i})=>{try{await t.writeContentHelper(r,n,i,e)}catch(e){u([`Failed to process extracted content for ${(0,a.colorizeKey)(n)}:`,e],{level:`error`})}}}};exports.getExtractPluginOptions=s;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_extractContent_contentWriter = require('./extractContent/contentWriter.cjs');
4
+ let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
5
+ let _intlayer_config_colors = require("@intlayer/config/colors");
6
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
7
+ let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
8
+ let _intlayer_config_logger = require("@intlayer/config/logger");
9
+ let _intlayer_config_node = require("@intlayer/config/node");
10
+
11
+ //#region src/getExtractPluginOptions.ts
12
+ /**
13
+ * Get the options for the Intlayer Babel extraction plugin
14
+ * This function loads the Intlayer configuration and sets up the onExtract callback
15
+ * to write dictionaries to the filesystem.
16
+ */
17
+ const getExtractPluginOptions = (configuration = (0, _intlayer_config_node.getConfiguration)(), isDev = process.env.INTLAYER_IS_DEV_COMMAND) => {
18
+ const isDevBoolean = isDev === "dev" || isDev === "serve" || isDev === "true";
19
+ const compilerMode = isDevBoolean ? "dev" : "build";
20
+ const logger = (0, _intlayer_config_logger.getAppLogger)(configuration);
21
+ if (configuration.compiler?.enabled === "build-only" && isDevBoolean) logger(`${(0, _intlayer_config_logger.colorize)("Compiler:", _intlayer_config_colors.GREY_DARK)} i18n function is not inserted in the code in dev mode to optimize build time. (to test i18n in dev mode set compiler.enabled to true)`);
22
+ let enabled = configuration.compiler?.enabled ?? _intlayer_config_defaultValues.COMPILER_ENABLED;
23
+ if (enabled === "build-only") if (compilerMode) enabled = compilerMode === "build";
24
+ else enabled = process.env.NODE_ENV === "production";
25
+ const filesList = (0, _intlayer_chokidar_utils.buildComponentFilesList)(configuration);
26
+ return {
27
+ enabled,
28
+ configuration,
29
+ filesList,
30
+ onExtract: async ({ dictionaryKey, content, filePath }) => {
31
+ try {
32
+ await require_extractContent_contentWriter.writeContentHelper(content, dictionaryKey, filePath, configuration);
33
+ } catch (error) {
34
+ logger([`Failed to process extracted content for ${(0, _intlayer_config_logger.colorizeKey)(dictionaryKey)}:`, error], { level: "error" });
35
+ }
36
+ }
37
+ };
38
+ };
39
+
40
+ //#endregion
41
+ exports.getExtractPluginOptions = getExtractPluginOptions;
2
42
  //# sourceMappingURL=getExtractPluginOptions.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getExtractPluginOptions.cjs","names":["ANSIColors","COMPILER_ENABLED","writeContentHelper"],"sources":["../../src/getExtractPluginOptions.ts"],"sourcesContent":["import { buildComponentFilesList } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { COMPILER_ENABLED } from '@intlayer/config/defaultValues';\nimport { colorize, colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { ExtractPluginOptions } from './babel-plugin-intlayer-extract';\nimport { writeContentHelper } from './extractContent/contentWriter';\n\n/**\n * Mode of the compiler\n * - 'dev': Development mode with HMR support\n * - 'build': Production build mode\n */\nexport type CompilerMode = 'dev' | 'build';\n\n/**\n * Get the options for the Intlayer Babel extraction plugin\n * This function loads the Intlayer configuration and sets up the onExtract callback\n * to write dictionaries to the filesystem.\n */\nexport const getExtractPluginOptions = (\n configuration: IntlayerConfig = getConfiguration(),\n isDev: CompilerMode | string | undefined = process.env.INTLAYER_IS_DEV_COMMAND\n): ExtractPluginOptions => {\n // Accept 'dev'/'serve' (Vite), boolean true, or the string 'true' (env var)\n const isDevBoolean = isDev === 'dev' || isDev === 'serve' || isDev === 'true';\n\n const compilerMode: CompilerMode = isDevBoolean ? 'dev' : 'build';\n\n const logger = getAppLogger(configuration);\n\n if (configuration.compiler?.enabled === 'build-only' && isDevBoolean) {\n logger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} i18n function is not inserted in the code in dev mode to optimize build time. (to test i18n in dev mode set compiler.enabled to true)`\n );\n }\n\n let enabled = configuration.compiler?.enabled ?? COMPILER_ENABLED;\n\n if (enabled === 'build-only') {\n if (compilerMode) {\n enabled = compilerMode === 'build';\n } else {\n // Fallback if mode isn't explicitly provided (e.g. pure babel plugin context)\n enabled = process.env.NODE_ENV === 'production';\n }\n }\n\n const filesList = buildComponentFilesList(configuration);\n\n return {\n enabled,\n configuration,\n filesList,\n onExtract: async ({ dictionaryKey, content, filePath }) => {\n try {\n await writeContentHelper(\n content,\n dictionaryKey,\n filePath,\n configuration\n );\n } catch (error) {\n logger(\n [\n `Failed to process extracted content for ${colorizeKey(dictionaryKey)}:`,\n error,\n ],\n { level: 'error' }\n );\n }\n },\n };\n};\n"],"mappings":"2WAqBA,MAAa,GACX,GAAA,EAAA,EAAA,mBAAkD,CAClD,EAA2C,QAAQ,IAAI,0BAC9B,CAEzB,IAAM,EAAe,IAAU,OAAS,IAAU,SAAW,IAAU,OAEjE,EAA6B,EAAe,MAAQ,QAEpD,GAAA,EAAA,EAAA,cAAsB,EAAc,CAEtC,EAAc,UAAU,UAAY,cAAgB,GACtD,EACE,IAAA,EAAA,EAAA,UAAY,YAAaA,EAAW,UAAU,CAAC,wIAChD,CAGH,IAAI,EAAU,EAAc,UAAU,SAAWC,EAAAA,iBAE7C,IAAY,eACd,AAIE,EAJE,EACQ,IAAiB,QAGjB,QAAQ,IAAI,WAAa,cAIvC,IAAM,GAAA,EAAA,EAAA,yBAAoC,EAAc,CAExD,MAAO,CACL,UACA,gBACA,YACA,UAAW,MAAO,CAAE,gBAAe,UAAS,cAAe,CACzD,GAAI,CACF,MAAMC,EAAAA,mBACJ,EACA,EACA,EACA,EACD,OACM,EAAO,CACd,EACE,CACE,4CAAA,EAAA,EAAA,aAAuD,EAAc,CAAC,GACtE,EACD,CACD,CAAE,MAAO,QAAS,CACnB,GAGN"}
1
+ {"version":3,"file":"getExtractPluginOptions.cjs","names":["ANSIColors","COMPILER_ENABLED","writeContentHelper"],"sources":["../../src/getExtractPluginOptions.ts"],"sourcesContent":["import { buildComponentFilesList } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { COMPILER_ENABLED } from '@intlayer/config/defaultValues';\nimport { colorize, colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { ExtractPluginOptions } from './babel-plugin-intlayer-extract';\nimport { writeContentHelper } from './extractContent/contentWriter';\n\n/**\n * Mode of the compiler\n * - 'dev': Development mode with HMR support\n * - 'build': Production build mode\n */\nexport type CompilerMode = 'dev' | 'build';\n\n/**\n * Get the options for the Intlayer Babel extraction plugin\n * This function loads the Intlayer configuration and sets up the onExtract callback\n * to write dictionaries to the filesystem.\n */\nexport const getExtractPluginOptions = (\n configuration: IntlayerConfig = getConfiguration(),\n isDev: CompilerMode | string | undefined = process.env.INTLAYER_IS_DEV_COMMAND\n): ExtractPluginOptions => {\n // Accept 'dev'/'serve' (Vite), boolean true, or the string 'true' (env var)\n const isDevBoolean = isDev === 'dev' || isDev === 'serve' || isDev === 'true';\n\n const compilerMode: CompilerMode = isDevBoolean ? 'dev' : 'build';\n\n const logger = getAppLogger(configuration);\n\n if (configuration.compiler?.enabled === 'build-only' && isDevBoolean) {\n logger(\n `${colorize('Compiler:', ANSIColors.GREY_DARK)} i18n function is not inserted in the code in dev mode to optimize build time. (to test i18n in dev mode set compiler.enabled to true)`\n );\n }\n\n let enabled = configuration.compiler?.enabled ?? COMPILER_ENABLED;\n\n if (enabled === 'build-only') {\n if (compilerMode) {\n enabled = compilerMode === 'build';\n } else {\n // Fallback if mode isn't explicitly provided (e.g. pure babel plugin context)\n enabled = process.env.NODE_ENV === 'production';\n }\n }\n\n const filesList = buildComponentFilesList(configuration);\n\n return {\n enabled,\n configuration,\n filesList,\n onExtract: async ({ dictionaryKey, content, filePath }) => {\n try {\n await writeContentHelper(\n content,\n dictionaryKey,\n filePath,\n configuration\n );\n } catch (error) {\n logger(\n [\n `Failed to process extracted content for ${colorizeKey(dictionaryKey)}:`,\n error,\n ],\n { level: 'error' }\n );\n }\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAa,2BACX,6DAAkD,EAClD,QAA2C,QAAQ,IAAI,4BAC9B;CAEzB,MAAM,eAAe,UAAU,SAAS,UAAU,WAAW,UAAU;CAEvE,MAAM,eAA6B,eAAe,QAAQ;CAE1D,MAAM,mDAAsB,cAAc;AAE1C,KAAI,cAAc,UAAU,YAAY,gBAAgB,aACtD,QACE,yCAAY,aAAaA,wBAAW,UAAU,CAAC,wIAChD;CAGH,IAAI,UAAU,cAAc,UAAU,WAAWC;AAEjD,KAAI,YAAY,aACd,KAAI,aACF,WAAU,iBAAiB;KAG3B,WAAU,QAAQ,IAAI,aAAa;CAIvC,MAAM,kEAAoC,cAAc;AAExD,QAAO;EACL;EACA;EACA;EACA,WAAW,OAAO,EAAE,eAAe,SAAS,eAAe;AACzD,OAAI;AACF,UAAMC,wDACJ,SACA,eACA,UACA,cACD;YACM,OAAO;AACd,WACE,CACE,oFAAuD,cAAc,CAAC,IACtE,MACD,EACD,EAAE,OAAO,SAAS,CACnB;;;EAGN"}
@@ -1,2 +1,64 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunk-Bmb41Sf3.cjs`);let e=require(`@intlayer/chokidar/utils`),t=require(`@intlayer/config/node`),n=require(`node:path`);const r=e=>{try{let{getDictionaries:t}=require(`@intlayer/dictionaries-entry`),n=t(e);return Object.values(n)}catch{return[]}},i=i=>{let{configOptions:a,dictionaries:o,overrides:s}=i??{},c=(0,t.getConfiguration)(a),{mainDir:l,dictionariesDir:u,unmergedDictionariesDir:d,dynamicDictionariesDir:f,fetchDictionariesDir:p}=c.system,{importMode:m,optimize:h}=c.build,g=(0,n.join)(l,`dictionaries.mjs`),_=(0,n.join)(l,`unmerged_dictionaries.mjs`),v=(0,n.join)(l,`dynamic_dictionaries.mjs`),y=(0,n.join)(l,`fetch_dictionaries.mjs`),b=[...(0,e.buildComponentFilesList)(c),g,_],x=o??r(c),S={};return x.forEach(e=>{S[e.key]=e.importMode??m}),{optimize:h,dictionariesDir:u,dictionariesEntryPath:g,unmergedDictionariesDir:d,unmergedDictionariesEntryPath:_,dynamicDictionariesDir:f,dynamicDictionariesEntryPath:v,fetchDictionariesDir:p,fetchDictionariesEntryPath:y,replaceDictionaryEntry:!0,importMode:m,dictionaryModeMap:S,filesList:b,...s}};exports.getOptimizePluginOptions=i;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
4
+ let _intlayer_config_node = require("@intlayer/config/node");
5
+ let node_path = require("node:path");
6
+
7
+ //#region src/getOptimizePluginOptions.ts
8
+ /**
9
+ * Load dictionaries from the dictionaries-entry package
10
+ */
11
+ const loadDictionaries = (config) => {
12
+ try {
13
+ const { getDictionaries } = require("@intlayer/dictionaries-entry");
14
+ const dictionariesRecord = getDictionaries(config);
15
+ return Object.values(dictionariesRecord);
16
+ } catch {
17
+ return [];
18
+ }
19
+ };
20
+ /**
21
+ * Get the options for the Intlayer Babel optimization plugin
22
+ * This function loads the Intlayer configuration and returns the paths
23
+ * needed for dictionary optimization and import rewriting.
24
+ */
25
+ const getOptimizePluginOptions = (params) => {
26
+ const { configOptions, dictionaries: providedDictionaries, overrides } = params ?? {};
27
+ const config = (0, _intlayer_config_node.getConfiguration)(configOptions);
28
+ const { mainDir, dictionariesDir, unmergedDictionariesDir, dynamicDictionariesDir, fetchDictionariesDir } = config.system;
29
+ const { importMode, optimize } = config.build;
30
+ const dictionariesEntryPath = (0, node_path.join)(mainDir, "dictionaries.mjs");
31
+ const unmergedDictionariesEntryPath = (0, node_path.join)(mainDir, "unmerged_dictionaries.mjs");
32
+ const dynamicDictionariesEntryPath = (0, node_path.join)(mainDir, "dynamic_dictionaries.mjs");
33
+ const fetchDictionariesEntryPath = (0, node_path.join)(mainDir, "fetch_dictionaries.mjs");
34
+ const filesList = [
35
+ ...(0, _intlayer_chokidar_utils.buildComponentFilesList)(config),
36
+ dictionariesEntryPath,
37
+ unmergedDictionariesEntryPath
38
+ ];
39
+ const dictionaries = providedDictionaries ?? loadDictionaries(config);
40
+ const dictionaryModeMap = {};
41
+ dictionaries.forEach((dictionary) => {
42
+ dictionaryModeMap[dictionary.key] = dictionary.importMode ?? importMode;
43
+ });
44
+ return {
45
+ optimize,
46
+ dictionariesDir,
47
+ dictionariesEntryPath,
48
+ unmergedDictionariesDir,
49
+ unmergedDictionariesEntryPath,
50
+ dynamicDictionariesDir,
51
+ dynamicDictionariesEntryPath,
52
+ fetchDictionariesDir,
53
+ fetchDictionariesEntryPath,
54
+ replaceDictionaryEntry: true,
55
+ importMode,
56
+ dictionaryModeMap,
57
+ filesList,
58
+ ...overrides
59
+ };
60
+ };
61
+
62
+ //#endregion
63
+ exports.getOptimizePluginOptions = getOptimizePluginOptions;
2
64
  //# sourceMappingURL=getOptimizePluginOptions.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getOptimizePluginOptions.cjs","names":[],"sources":["../../src/getOptimizePluginOptions.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { buildComponentFilesList } from '@intlayer/chokidar/utils';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { OptimizePluginOptions } from './babel-plugin-intlayer-optimize';\n\ntype GetOptimizePluginOptionsParams = {\n /**\n * Configuration options for loading intlayer config\n */\n configOptions?: GetConfigurationOptions;\n /**\n * Pre-loaded dictionaries (optional - will be loaded if not provided)\n */\n dictionaries?: Dictionary[];\n /**\n * Override specific options\n */\n overrides?: Partial<OptimizePluginOptions>;\n};\n\n/**\n * Load dictionaries from the dictionaries-entry package\n */\nconst loadDictionaries = (config: IntlayerConfig): Dictionary[] => {\n try {\n // Dynamic require to avoid build-time dependency issues\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const { getDictionaries } = require('@intlayer/dictionaries-entry');\n const dictionariesRecord = getDictionaries(config);\n\n return Object.values(dictionariesRecord);\n } catch {\n // If dictionaries-entry is not available, return empty array\n return [];\n }\n};\n\n/**\n * Get the options for the Intlayer Babel optimization plugin\n * This function loads the Intlayer configuration and returns the paths\n * needed for dictionary optimization and import rewriting.\n */\nexport const getOptimizePluginOptions = (\n params?: GetOptimizePluginOptionsParams\n): OptimizePluginOptions => {\n const {\n configOptions,\n dictionaries: providedDictionaries,\n overrides,\n } = params ?? {};\n\n const config = getConfiguration(configOptions);\n const {\n mainDir,\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n } = config.system;\n const { importMode, optimize } = config.build;\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n const unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = buildComponentFilesList(config);\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by an empty object if import made dynamic\n unmergedDictionariesEntryPath, // should add dictionariesEntryPath to replace it by an empty object if import made dynamic\n ];\n\n // Load dictionaries if not provided\n const dictionaries = providedDictionaries ?? loadDictionaries(config);\n\n const dictionaryModeMap: Record<\n string,\n 'static' | 'dynamic' | 'fetch' | undefined\n > = {};\n\n dictionaries.forEach((dictionary) => {\n dictionaryModeMap[dictionary.key] = dictionary.importMode ?? importMode;\n });\n\n return {\n optimize,\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesDir,\n unmergedDictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n replaceDictionaryEntry: true,\n importMode,\n dictionaryModeMap,\n filesList,\n ...overrides,\n };\n};\n"],"mappings":"uMA4BA,MAAM,EAAoB,GAAyC,CACjE,GAAI,CAGF,GAAM,CAAE,mBAAoB,QAAQ,+BAA+B,CAC7D,EAAqB,EAAgB,EAAO,CAElD,OAAO,OAAO,OAAO,EAAmB,MAClC,CAEN,MAAO,EAAE,GASA,EACX,GAC0B,CAC1B,GAAM,CACJ,gBACA,aAAc,EACd,aACE,GAAU,EAAE,CAEV,GAAA,EAAA,EAAA,kBAA0B,EAAc,CACxC,CACJ,UACA,kBACA,0BACA,yBACA,wBACE,EAAO,OACL,CAAE,aAAY,YAAa,EAAO,MAElC,GAAA,EAAA,EAAA,MAA6B,EAAS,mBAAmB,CACzD,GAAA,EAAA,EAAA,MACJ,EACA,4BACD,CACK,GAAA,EAAA,EAAA,MACJ,EACA,2BACD,CACK,GAAA,EAAA,EAAA,MAAkC,EAAS,yBAAyB,CAIpE,EAAY,CAChB,IAAA,EAAA,EAAA,yBAH+C,EAAO,CAItD,EACA,EACD,CAGK,EAAe,GAAwB,EAAiB,EAAO,CAE/D,EAGF,EAAE,CAMN,OAJA,EAAa,QAAS,GAAe,CACnC,EAAkB,EAAW,KAAO,EAAW,YAAc,GAC7D,CAEK,CACL,WACA,kBACA,wBACA,0BACA,gCACA,yBACA,+BACA,uBACA,6BACA,uBAAwB,GACxB,aACA,oBACA,YACA,GAAG,EACJ"}
1
+ {"version":3,"file":"getOptimizePluginOptions.cjs","names":[],"sources":["../../src/getOptimizePluginOptions.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { buildComponentFilesList } from '@intlayer/chokidar/utils';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { OptimizePluginOptions } from './babel-plugin-intlayer-optimize';\n\ntype GetOptimizePluginOptionsParams = {\n /**\n * Configuration options for loading intlayer config\n */\n configOptions?: GetConfigurationOptions;\n /**\n * Pre-loaded dictionaries (optional - will be loaded if not provided)\n */\n dictionaries?: Dictionary[];\n /**\n * Override specific options\n */\n overrides?: Partial<OptimizePluginOptions>;\n};\n\n/**\n * Load dictionaries from the dictionaries-entry package\n */\nconst loadDictionaries = (config: IntlayerConfig): Dictionary[] => {\n try {\n // Dynamic require to avoid build-time dependency issues\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const { getDictionaries } = require('@intlayer/dictionaries-entry');\n const dictionariesRecord = getDictionaries(config);\n\n return Object.values(dictionariesRecord);\n } catch {\n // If dictionaries-entry is not available, return empty array\n return [];\n }\n};\n\n/**\n * Get the options for the Intlayer Babel optimization plugin\n * This function loads the Intlayer configuration and returns the paths\n * needed for dictionary optimization and import rewriting.\n */\nexport const getOptimizePluginOptions = (\n params?: GetOptimizePluginOptionsParams\n): OptimizePluginOptions => {\n const {\n configOptions,\n dictionaries: providedDictionaries,\n overrides,\n } = params ?? {};\n\n const config = getConfiguration(configOptions);\n const {\n mainDir,\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n } = config.system;\n const { importMode, optimize } = config.build;\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n const unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = buildComponentFilesList(config);\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by an empty object if import made dynamic\n unmergedDictionariesEntryPath, // should add dictionariesEntryPath to replace it by an empty object if import made dynamic\n ];\n\n // Load dictionaries if not provided\n const dictionaries = providedDictionaries ?? loadDictionaries(config);\n\n const dictionaryModeMap: Record<\n string,\n 'static' | 'dynamic' | 'fetch' | undefined\n > = {};\n\n dictionaries.forEach((dictionary) => {\n dictionaryModeMap[dictionary.key] = dictionary.importMode ?? importMode;\n });\n\n return {\n optimize,\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesDir,\n unmergedDictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n replaceDictionaryEntry: true,\n importMode,\n dictionaryModeMap,\n filesList,\n ...overrides,\n };\n};\n"],"mappings":";;;;;;;;;;AA4BA,MAAM,oBAAoB,WAAyC;AACjE,KAAI;EAGF,MAAM,EAAE,oBAAoB,QAAQ,+BAA+B;EACnE,MAAM,qBAAqB,gBAAgB,OAAO;AAElD,SAAO,OAAO,OAAO,mBAAmB;SAClC;AAEN,SAAO,EAAE;;;;;;;;AASb,MAAa,4BACX,WAC0B;CAC1B,MAAM,EACJ,eACA,cAAc,sBACd,cACE,UAAU,EAAE;CAEhB,MAAM,qDAA0B,cAAc;CAC9C,MAAM,EACJ,SACA,iBACA,yBACA,wBACA,yBACE,OAAO;CACX,MAAM,EAAE,YAAY,aAAa,OAAO;CAExC,MAAM,4CAA6B,SAAS,mBAAmB;CAC/D,MAAM,oDACJ,SACA,4BACD;CACD,MAAM,mDACJ,SACA,2BACD;CACD,MAAM,iDAAkC,SAAS,yBAAyB;CAI1E,MAAM,YAAY;EAChB,yDAH+C,OAAO;EAItD;EACA;EACD;CAGD,MAAM,eAAe,wBAAwB,iBAAiB,OAAO;CAErE,MAAM,oBAGF,EAAE;AAEN,cAAa,SAAS,eAAe;AACnC,oBAAkB,WAAW,OAAO,WAAW,cAAc;GAC7D;AAEF,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB;EACxB;EACA;EACA;EACA,GAAG;EACJ"}
@@ -1 +1,34 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./extractContent/utils/extractDictionaryKey.cjs`),t=require(`./extractContent/utils/extractDictionaryInfo.cjs`),n=require(`./extractContent/contentWriter.cjs`),r=require(`./getExtractPluginOptions.cjs`),i=require(`./extractContent/utils/constants.cjs`),a=require(`./extractContent/utils/detectPackageName.cjs`),o=require(`./extractContent/utils/generateKey.cjs`),s=require(`./extractContent/utils/getComponentName.cjs`),c=require(`./extractContent/extractContent.cjs`),l=require(`./babel-plugin-intlayer-extract.cjs`),u=require(`./getOptimizePluginOptions.cjs`),d=require(`./babel-plugin-intlayer-optimize.cjs`);require(`./extractContent/index.cjs`),exports.ATTRIBUTES_TO_EXTRACT=i.ATTRIBUTES_TO_EXTRACT,exports.SERVER_CAPABLE_PACKAGES=i.SERVER_CAPABLE_PACKAGES,exports.detectPackageName=a.detectPackageName,exports.extractContent=c.extractContent,exports.extractContentSync=c.extractContentSync,exports.extractDictionaryInfo=t.extractDictionaryInfo,exports.extractDictionaryKey=e.extractDictionaryKey,exports.extractDictionaryKeyFromPath=e.extractDictionaryKeyFromPath,exports.generateKey=o.generateKey,exports.getComponentName=s.getComponentName,exports.getExtractPluginOptions=r.getExtractPluginOptions,exports.getOptimizePluginOptions=u.getOptimizePluginOptions,exports.getOutput=t.getOutput,exports.intlayerExtractBabelPlugin=l.intlayerExtractBabelPlugin,exports.intlayerOptimizeBabelPlugin=d.intlayerOptimizeBabelPlugin,exports.mergeWithExistingMultilingualDictionary=n.mergeWithExistingMultilingualDictionary,exports.mergeWithExistingPerLocaleDictionary=n.mergeWithExistingPerLocaleDictionary,exports.packageList=i.packageList,exports.resolveContentFilePaths=t.resolveContentFilePaths,exports.writeContentHelper=n.writeContentHelper;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_extractContent_utils_extractDictionaryKey = require('./extractContent/utils/extractDictionaryKey.cjs');
3
+ const require_extractContent_utils_extractDictionaryInfo = require('./extractContent/utils/extractDictionaryInfo.cjs');
4
+ const require_extractContent_contentWriter = require('./extractContent/contentWriter.cjs');
5
+ const require_getExtractPluginOptions = require('./getExtractPluginOptions.cjs');
6
+ const require_extractContent_utils_constants = require('./extractContent/utils/constants.cjs');
7
+ const require_extractContent_utils_detectPackageName = require('./extractContent/utils/detectPackageName.cjs');
8
+ const require_extractContent_utils_generateKey = require('./extractContent/utils/generateKey.cjs');
9
+ const require_extractContent_utils_getComponentName = require('./extractContent/utils/getComponentName.cjs');
10
+ const require_extractContent_extractContent = require('./extractContent/extractContent.cjs');
11
+ const require_babel_plugin_intlayer_extract = require('./babel-plugin-intlayer-extract.cjs');
12
+ const require_getOptimizePluginOptions = require('./getOptimizePluginOptions.cjs');
13
+ const require_babel_plugin_intlayer_optimize = require('./babel-plugin-intlayer-optimize.cjs');
14
+
15
+ exports.ATTRIBUTES_TO_EXTRACT = require_extractContent_utils_constants.ATTRIBUTES_TO_EXTRACT;
16
+ exports.SERVER_CAPABLE_PACKAGES = require_extractContent_utils_constants.SERVER_CAPABLE_PACKAGES;
17
+ exports.detectPackageName = require_extractContent_utils_detectPackageName.detectPackageName;
18
+ exports.extractContent = require_extractContent_extractContent.extractContent;
19
+ exports.extractContentSync = require_extractContent_extractContent.extractContentSync;
20
+ exports.extractDictionaryInfo = require_extractContent_utils_extractDictionaryInfo.extractDictionaryInfo;
21
+ exports.extractDictionaryKey = require_extractContent_utils_extractDictionaryKey.extractDictionaryKey;
22
+ exports.extractDictionaryKeyFromPath = require_extractContent_utils_extractDictionaryKey.extractDictionaryKeyFromPath;
23
+ exports.generateKey = require_extractContent_utils_generateKey.generateKey;
24
+ exports.getComponentName = require_extractContent_utils_getComponentName.getComponentName;
25
+ exports.getExtractPluginOptions = require_getExtractPluginOptions.getExtractPluginOptions;
26
+ exports.getOptimizePluginOptions = require_getOptimizePluginOptions.getOptimizePluginOptions;
27
+ exports.getOutput = require_extractContent_utils_extractDictionaryInfo.getOutput;
28
+ exports.intlayerExtractBabelPlugin = require_babel_plugin_intlayer_extract.intlayerExtractBabelPlugin;
29
+ exports.intlayerOptimizeBabelPlugin = require_babel_plugin_intlayer_optimize.intlayerOptimizeBabelPlugin;
30
+ exports.mergeWithExistingMultilingualDictionary = require_extractContent_contentWriter.mergeWithExistingMultilingualDictionary;
31
+ exports.mergeWithExistingPerLocaleDictionary = require_extractContent_contentWriter.mergeWithExistingPerLocaleDictionary;
32
+ exports.packageList = require_extractContent_utils_constants.packageList;
33
+ exports.resolveContentFilePaths = require_extractContent_utils_extractDictionaryInfo.resolveContentFilePaths;
34
+ exports.writeContentHelper = require_extractContent_contentWriter.writeContentHelper;
@@ -0,0 +1,8 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
3
+ if (typeof require !== "undefined") return require.apply(this, arguments);
4
+ throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
5
+ });
6
+
7
+ //#endregion
8
+ export { __require };
@@ -1,2 +1,73 @@
1
- import{detectPackageName as e}from"./extractContent/utils/detectPackageName.mjs";import{extractContentSync as t}from"./extractContent/extractContent.mjs";import*as n from"@intlayer/config/colors";import{colorize as r,colorizePath as i,getAppLogger as a}from"@intlayer/config/logger";import{relative as o}from"node:path";import{parse as s}from"@babel/parser";const c=c=>({name:`babel-plugin-intlayer-extract`,visitor:{Program:{enter(c,l){let u=l.opts;if(u.enabled===!1)return;let d=l.file.opts.filename;if(!d||u.filesList&&!u.filesList.includes(d))return;let f=l.file.code??``;if(!f)return;let p=a(u.configuration),m=u.packageName??e(d),{saveComponents:h}=u.configuration.compiler,g=t(d,m,{configuration:u.configuration,code:f,onExtract:e=>{u.onExtract&&u.onExtract({dictionaryKey:e.key,filePath:d,content:e.content,locale:u.configuration.internationalization.defaultLocale})},declarationOnly:!h});if(!g)return;let{transformedCode:_}=g;if(_)try{let e=s(_,{sourceType:`module`,plugins:[`jsx`,`typescript`]});c.node.body=e.program.body,c.node.directives=e.program.directives,p(`${r(`Compiler:`,n.GREY_DARK)} Extracted content from ${i(o(u.configuration.system.baseDir,d))}`,{level:`debug`})}catch(e){p([`Failed to parse transformed code for ${i(o(u.configuration.system.baseDir,d))}:`,e],{level:`error`})}}}}});export{c as intlayerExtractBabelPlugin};
1
+ import { detectPackageName } from "./extractContent/utils/detectPackageName.mjs";
2
+ import { extractContentSync } from "./extractContent/extractContent.mjs";
3
+ import * as ANSIColors from "@intlayer/config/colors";
4
+ import { colorize, colorizePath, getAppLogger } from "@intlayer/config/logger";
5
+ import { relative } from "node:path";
6
+ import { parse } from "@babel/parser";
7
+
8
+ //#region src/babel-plugin-intlayer-extract.ts
9
+ /**
10
+ * Babel plugin that extracts translatable content from source files and
11
+ * injects Intlayer hooks (`useIntlayer` / `getIntlayer`) automatically.
12
+ *
13
+ * Designed for use with Babel-based build tools such as Next.js and Webpack.
14
+ *
15
+ * @example babel.config.js
16
+ * ```js
17
+ * const { intlayerExtractBabelPlugin, getExtractPluginOptions } = require('@intlayer/babel');
18
+ * module.exports = {
19
+ * presets: ['next/babel'],
20
+ * plugins: [
21
+ * [intlayerExtractBabelPlugin, getExtractPluginOptions()],
22
+ * ],
23
+ * };
24
+ * ```
25
+ */
26
+ const intlayerExtractBabelPlugin = (_babel) => {
27
+ return {
28
+ name: "babel-plugin-intlayer-extract",
29
+ visitor: { Program: { enter(programPath, state) {
30
+ const opts = state.opts;
31
+ if (opts.enabled === false) return;
32
+ const filename = state.file.opts.filename;
33
+ if (!filename) return;
34
+ if (opts.filesList && !opts.filesList.includes(filename)) return;
35
+ const fileCode = state.file.code ?? "";
36
+ if (!fileCode) return;
37
+ const appLogger = getAppLogger(opts.configuration);
38
+ const packageName = opts.packageName ?? detectPackageName(filename);
39
+ const { saveComponents } = opts.configuration.compiler;
40
+ const result = extractContentSync(filename, packageName, {
41
+ configuration: opts.configuration,
42
+ code: fileCode,
43
+ onExtract: (extractResult) => {
44
+ if (opts.onExtract) opts.onExtract({
45
+ dictionaryKey: extractResult.key,
46
+ filePath: filename,
47
+ content: extractResult.content,
48
+ locale: opts.configuration.internationalization.defaultLocale
49
+ });
50
+ },
51
+ declarationOnly: !saveComponents
52
+ });
53
+ if (!result) return;
54
+ const { transformedCode: modifiedCode } = result;
55
+ if (!modifiedCode) return;
56
+ try {
57
+ const newAst = parse(modifiedCode, {
58
+ sourceType: "module",
59
+ plugins: ["jsx", "typescript"]
60
+ });
61
+ programPath.node.body = newAst.program.body;
62
+ programPath.node.directives = newAst.program.directives;
63
+ appLogger(`${colorize("Compiler:", ANSIColors.GREY_DARK)} Extracted content from ${colorizePath(relative(opts.configuration.system.baseDir, filename))}`, { level: "debug" });
64
+ } catch (error) {
65
+ appLogger([`Failed to parse transformed code for ${colorizePath(relative(opts.configuration.system.baseDir, filename))}:`, error], { level: "error" });
66
+ }
67
+ } } }
68
+ };
69
+ };
70
+
71
+ //#endregion
72
+ export { intlayerExtractBabelPlugin };
2
73
  //# sourceMappingURL=babel-plugin-intlayer-extract.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-intlayer-extract.mjs","names":[],"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 * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, getAppLogger } 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":"sWA0DA,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,EAAY,EAAa,EAAK,cAAc,CAC5C,EAAc,EAAK,aAAe,EAAkB,EAAS,CAE7D,CAAE,kBAAmB,EAAK,cAAc,SAExC,EAAS,EAAmB,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,EAAS,EAAM,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,GAAG,EAAS,YAAa,EAAW,UAAU,CAAC,0BAA0B,EAAa,EAAS,EAAK,cAAc,OAAO,QAAS,EAAS,CAAC,GAC5I,CAAE,MAAO,QAAS,CACnB,OACM,EAAO,CACd,EACE,CACE,wCAAwC,EAAa,EAAS,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.mjs","names":[],"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 * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, getAppLogger } 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":";;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAa,8BAA8B,WAEnB;AACtB,QAAO;EACL,MAAM;EAEN,SAAS,EACP,SAAS,EACP,MAAM,aAAa,OAAO;GACxB,MAAM,OAAO,MAAM;AAKnB,OAFkB,KAAK,YAEL,MAAO;GAEzB,MAAM,WAAW,MAAM,KAAK,KAAK;AAEjC,OAAI,CAAC,SAAU;AAEf,OAAI,KAAK,aAAa,CAAC,KAAK,UAAU,SAAS,SAAS,CAAE;GAE1D,MAAM,WAAmB,MAAM,KAAK,QAAQ;AAC5C,OAAI,CAAC,SAAU;GAEf,MAAM,YAAY,aAAa,KAAK,cAAc;GAClD,MAAM,cAAc,KAAK,eAAe,kBAAkB,SAAS;GAEnE,MAAM,EAAE,mBAAmB,KAAK,cAAc;GAE9C,MAAM,SAAS,mBAAmB,UAAU,aAAa;IACvD,eAAe,KAAK;IACpB,MAAM;IACN,YAAY,kBAGN;AACJ,SAAI,KAAK,UACP,MAAK,UAAU;MACb,eAAe,cAAc;MAC7B,UAAU;MACV,SAAS,cAAc;MACvB,QAAQ,KAAK,cAAc,qBAAqB;MACjD,CAAC;;IAGN,iBAAiB,CAAC;IACnB,CAAC;AAEF,OAAI,CAAC,OAAQ;GAEb,MAAM,EAAE,iBAAiB,iBAAiB;AAE1C,OAAI,CAAC,aAAc;AAKnB,OAAI;IACF,MAAM,SAAS,MAAM,cAAc;KACjC,YAAY;KACZ,SAAS,CAAC,OAAO,aAAa;KAC/B,CAAC;AAEF,gBAAY,KAAK,OAAO,OAAO,QAAQ;AACvC,gBAAY,KAAK,aAAa,OAAO,QAAQ;AAE7C,cACE,GAAG,SAAS,aAAa,WAAW,UAAU,CAAC,0BAA0B,aAAa,SAAS,KAAK,cAAc,OAAO,SAAS,SAAS,CAAC,IAC5I,EAAE,OAAO,SAAS,CACnB;YACM,OAAO;AACd,cACE,CACE,wCAAwC,aAAa,SAAS,KAAK,cAAc,OAAO,SAAS,SAAS,CAAC,CAAC,IAC5G,MACD,EACD,EAAE,OAAO,SAAS,CACnB;;KAGN,EACF;EACF"}