gt 2.14.35 → 2.14.36

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 (429) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/api/collectUserEditDiffs.js +112 -155
  3. package/dist/api/collectUserEditDiffs.js.map +1 -0
  4. package/dist/api/downloadFileBatch.js +164 -241
  5. package/dist/api/downloadFileBatch.js.map +1 -0
  6. package/dist/api/saveLocalEdits.js +37 -41
  7. package/dist/api/saveLocalEdits.js.map +1 -0
  8. package/dist/bin/bin-entry.js +17 -7
  9. package/dist/bin/bin-entry.js.map +1 -0
  10. package/dist/bin/bin-main.js +43 -61
  11. package/dist/bin/bin-main.js.map +1 -0
  12. package/dist/cli/base.js +382 -497
  13. package/dist/cli/base.js.map +1 -0
  14. package/dist/cli/commands/download.js +41 -49
  15. package/dist/cli/commands/download.js.map +1 -0
  16. package/dist/cli/commands/enqueue.js +26 -25
  17. package/dist/cli/commands/enqueue.js.map +1 -0
  18. package/dist/cli/commands/setupProject.js +33 -36
  19. package/dist/cli/commands/setupProject.js.map +1 -0
  20. package/dist/cli/commands/stage.js +53 -61
  21. package/dist/cli/commands/stage.js.map +1 -0
  22. package/dist/cli/commands/translate.js +75 -112
  23. package/dist/cli/commands/translate.js.map +1 -0
  24. package/dist/cli/commands/upload.js +185 -213
  25. package/dist/cli/commands/upload.js.map +1 -0
  26. package/dist/cli/commands/utils/validation.js +39 -34
  27. package/dist/cli/commands/utils/validation.js.map +1 -0
  28. package/dist/cli/flags.js +35 -62
  29. package/dist/cli/flags.js.map +1 -0
  30. package/dist/cli/inline.js +112 -137
  31. package/dist/cli/inline.js.map +1 -0
  32. package/dist/cli/next.js +17 -12
  33. package/dist/cli/next.js.map +1 -0
  34. package/dist/cli/node.js +19 -15
  35. package/dist/cli/node.js.map +1 -0
  36. package/dist/cli/python.js +13 -8
  37. package/dist/cli/python.js.map +1 -0
  38. package/dist/cli/react.js +61 -78
  39. package/dist/cli/react.js.map +1 -0
  40. package/dist/config/defaults.js +16 -11
  41. package/dist/config/defaults.js.map +1 -0
  42. package/dist/config/generateSettings.js +167 -269
  43. package/dist/config/generateSettings.js.map +1 -0
  44. package/dist/config/optionPresets.js +78 -96
  45. package/dist/config/optionPresets.js.map +1 -0
  46. package/dist/config/resolveConfig.js +27 -32
  47. package/dist/config/resolveConfig.js.map +1 -0
  48. package/dist/config/utils.js +7 -3
  49. package/dist/config/utils.js.map +1 -0
  50. package/dist/config/validateSettings.js +19 -30
  51. package/dist/config/validateSettings.js.map +1 -0
  52. package/dist/console/colors.js +18 -13
  53. package/dist/console/colors.js.map +1 -0
  54. package/dist/console/displayTranslateSummary.js +40 -37
  55. package/dist/console/displayTranslateSummary.js.map +1 -0
  56. package/dist/console/formatting.js +8 -5
  57. package/dist/console/formatting.js.map +1 -0
  58. package/dist/console/index.d.ts +11 -9
  59. package/dist/console/index.js +53 -50
  60. package/dist/console/index.js.map +1 -0
  61. package/dist/console/inkFields.d.ts +23 -0
  62. package/dist/console/inkFields.js +87 -0
  63. package/dist/console/inkFields.js.map +1 -0
  64. package/dist/console/inkLayout.d.ts +7 -0
  65. package/dist/console/inkLayout.js +139 -0
  66. package/dist/console/inkLayout.js.map +1 -0
  67. package/dist/console/inkLocaleData.d.ts +4 -0
  68. package/dist/console/inkLocaleData.js +32 -0
  69. package/dist/console/inkLocaleData.js.map +1 -0
  70. package/dist/console/inkPrompts.d.ts +8 -0
  71. package/dist/console/inkPrompts.js +496 -0
  72. package/dist/console/inkPrompts.js.map +1 -0
  73. package/dist/console/inkSession.d.ts +3 -0
  74. package/dist/console/inkSession.js +42 -0
  75. package/dist/console/inkSession.js.map +1 -0
  76. package/dist/console/inkTerminal.d.ts +4 -0
  77. package/dist/console/inkTerminal.js +15 -0
  78. package/dist/console/inkTerminal.js.map +1 -0
  79. package/dist/console/inkTypes.d.ts +66 -0
  80. package/dist/console/inkTypes.js +1 -0
  81. package/dist/console/inkUtils.d.ts +24 -0
  82. package/dist/console/inkUtils.js +87 -0
  83. package/dist/console/inkUtils.js.map +1 -0
  84. package/dist/console/logger.js +209 -249
  85. package/dist/console/logger.js.map +1 -0
  86. package/dist/console/logging.d.ts +14 -0
  87. package/dist/console/logging.js +203 -162
  88. package/dist/console/logging.js.map +1 -0
  89. package/dist/console/promptParsing.d.ts +5 -0
  90. package/dist/console/promptParsing.js +28 -0
  91. package/dist/console/promptParsing.js.map +1 -0
  92. package/dist/console/terminalSession.d.ts +5 -0
  93. package/dist/console/terminalSession.js +38 -0
  94. package/dist/console/terminalSession.js.map +1 -0
  95. package/dist/extraction/index.js +3 -2
  96. package/dist/extraction/mapToUpdates.js +19 -18
  97. package/dist/extraction/mapToUpdates.js.map +1 -0
  98. package/dist/extraction/postProcess.js +68 -86
  99. package/dist/extraction/postProcess.js.map +1 -0
  100. package/dist/formats/files/aggregateFiles.js +223 -304
  101. package/dist/formats/files/aggregateFiles.js.map +1 -0
  102. package/dist/formats/files/collectFiles.js +53 -54
  103. package/dist/formats/files/collectFiles.js.map +1 -0
  104. package/dist/formats/files/convertToFileTranslationData.js +21 -19
  105. package/dist/formats/files/convertToFileTranslationData.js.map +1 -0
  106. package/dist/formats/files/fileMapping.js +82 -119
  107. package/dist/formats/files/fileMapping.js.map +1 -0
  108. package/dist/formats/files/preprocess/mdx.js +15 -12
  109. package/dist/formats/files/preprocess/mdx.js.map +1 -0
  110. package/dist/formats/files/preprocess/mintlify.js +15 -13
  111. package/dist/formats/files/preprocess/mintlify.js.map +1 -0
  112. package/dist/formats/files/preprocessContent.js +20 -21
  113. package/dist/formats/files/preprocessContent.js.map +1 -0
  114. package/dist/formats/files/save.js +18 -15
  115. package/dist/formats/files/save.js.map +1 -0
  116. package/dist/formats/files/supportedFiles.js +27 -22
  117. package/dist/formats/files/supportedFiles.js.map +1 -0
  118. package/dist/formats/files/transformFormat.js +93 -100
  119. package/dist/formats/files/transformFormat.js.map +1 -0
  120. package/dist/formats/json/extractJson.js +83 -110
  121. package/dist/formats/json/extractJson.js.map +1 -0
  122. package/dist/formats/json/flattenJson.js +41 -48
  123. package/dist/formats/json/flattenJson.js.map +1 -0
  124. package/dist/formats/json/jsonPath.js +20 -15
  125. package/dist/formats/json/jsonPath.js.map +1 -0
  126. package/dist/formats/json/jsonPointer.js +17 -17
  127. package/dist/formats/json/jsonPointer.js.map +1 -0
  128. package/dist/formats/json/mergeJson.js +230 -371
  129. package/dist/formats/json/mergeJson.js.map +1 -0
  130. package/dist/formats/json/parseJson.js +74 -111
  131. package/dist/formats/json/parseJson.js.map +1 -0
  132. package/dist/formats/json/transformJson.js +53 -61
  133. package/dist/formats/json/transformJson.js.map +1 -0
  134. package/dist/formats/json/utils.js +158 -187
  135. package/dist/formats/json/utils.js.map +1 -0
  136. package/dist/formats/parseKeyedMetadata.js +85 -106
  137. package/dist/formats/parseKeyedMetadata.js.map +1 -0
  138. package/dist/formats/utils.js +13 -23
  139. package/dist/formats/utils.js.map +1 -0
  140. package/dist/formats/yaml/extractYaml.js +32 -31
  141. package/dist/formats/yaml/extractYaml.js.map +1 -0
  142. package/dist/formats/yaml/mergeYaml.js +43 -60
  143. package/dist/formats/yaml/mergeYaml.js.map +1 -0
  144. package/dist/formats/yaml/parseYaml.js +34 -23
  145. package/dist/formats/yaml/parseYaml.js.map +1 -0
  146. package/dist/formats/yaml/utils.js +19 -21
  147. package/dist/formats/yaml/utils.js.map +1 -0
  148. package/dist/fs/clearLocaleDirs.js +82 -114
  149. package/dist/fs/clearLocaleDirs.js.map +1 -0
  150. package/dist/fs/config/downloadedVersions.js +174 -188
  151. package/dist/fs/config/downloadedVersions.js.map +1 -0
  152. package/dist/fs/config/loadConfig.js +12 -8
  153. package/dist/fs/config/loadConfig.js.map +1 -0
  154. package/dist/fs/config/parseFilesConfig.js +166 -227
  155. package/dist/fs/config/parseFilesConfig.js.map +1 -0
  156. package/dist/fs/config/setupConfig.js +43 -52
  157. package/dist/fs/config/setupConfig.js.map +1 -0
  158. package/dist/fs/config/updateConfig.js +44 -56
  159. package/dist/fs/config/updateConfig.js.map +1 -0
  160. package/dist/fs/config/updateVersions.js +27 -28
  161. package/dist/fs/config/updateVersions.js.map +1 -0
  162. package/dist/fs/copyFile.js +33 -37
  163. package/dist/fs/copyFile.js.map +1 -0
  164. package/dist/fs/createLoadTranslationsFile.js +32 -48
  165. package/dist/fs/createLoadTranslationsFile.js.map +1 -0
  166. package/dist/fs/determineFramework/detectPythonLibrary.js +30 -34
  167. package/dist/fs/determineFramework/detectPythonLibrary.js.map +1 -0
  168. package/dist/fs/determineFramework/index.js +46 -64
  169. package/dist/fs/determineFramework/index.js.map +1 -0
  170. package/dist/fs/determineFramework/matchPyprojectDependency.js +65 -78
  171. package/dist/fs/determineFramework/matchPyprojectDependency.js.map +1 -0
  172. package/dist/fs/determineFramework/matchRequirementsTxtDependency.js +21 -19
  173. package/dist/fs/determineFramework/matchRequirementsTxtDependency.js.map +1 -0
  174. package/dist/fs/determineFramework/matchSetupPyDependency.js +60 -81
  175. package/dist/fs/determineFramework/matchSetupPyDependency.js.map +1 -0
  176. package/dist/fs/determineFramework/resolveGtDependency.js +15 -15
  177. package/dist/fs/determineFramework/resolveGtDependency.js.map +1 -0
  178. package/dist/fs/findFilepath.js +63 -78
  179. package/dist/fs/findFilepath.js.map +1 -0
  180. package/dist/fs/loadJSON.js +18 -15
  181. package/dist/fs/loadJSON.js.map +1 -0
  182. package/dist/fs/matchFiles.js +12 -7
  183. package/dist/fs/matchFiles.js.map +1 -0
  184. package/dist/fs/saveJSON.js +10 -6
  185. package/dist/fs/saveJSON.js.map +1 -0
  186. package/dist/fs/utils.js +19 -15
  187. package/dist/fs/utils.js.map +1 -0
  188. package/dist/functions.d.ts +2 -1
  189. package/dist/functions.js +3 -6
  190. package/dist/generated/version.d.ts +1 -1
  191. package/dist/generated/version.js +6 -2
  192. package/dist/generated/version.js.map +1 -0
  193. package/dist/git/branches.js +77 -83
  194. package/dist/git/branches.js.map +1 -0
  195. package/dist/hooks/postProcess.js +97 -114
  196. package/dist/hooks/postProcess.js.map +1 -0
  197. package/dist/index.js +23 -31
  198. package/dist/index.js.map +1 -0
  199. package/dist/locadex/setupFlow.js +11 -8
  200. package/dist/locadex/setupFlow.js.map +1 -0
  201. package/dist/main.js +17 -7
  202. package/dist/main.js.map +1 -0
  203. package/dist/next/config/parseNextConfig.js +32 -51
  204. package/dist/next/config/parseNextConfig.js.map +1 -0
  205. package/dist/next/jsx/utils.js +25 -37
  206. package/dist/next/jsx/utils.js.map +1 -0
  207. package/dist/next/parse/handleInitGT.js +87 -154
  208. package/dist/next/parse/handleInitGT.js.map +1 -0
  209. package/dist/next/parse/wrapContent.js +136 -158
  210. package/dist/next/parse/wrapContent.js.map +1 -0
  211. package/dist/python/parse/createPythonInlineUpdates.js +36 -33
  212. package/dist/python/parse/createPythonInlineUpdates.js.map +1 -0
  213. package/dist/react/config/createESBuildConfig.js +115 -115
  214. package/dist/react/config/createESBuildConfig.js.map +1 -0
  215. package/dist/react/jsx/evaluateJsx.js +90 -124
  216. package/dist/react/jsx/evaluateJsx.js.map +1 -0
  217. package/dist/react/jsx/utils/buildImportMap.js +24 -28
  218. package/dist/react/jsx/utils/buildImportMap.js.map +1 -0
  219. package/dist/react/jsx/utils/constants.js +79 -87
  220. package/dist/react/jsx/utils/constants.js.map +1 -0
  221. package/dist/react/jsx/utils/extractSourceCode.js +36 -37
  222. package/dist/react/jsx/utils/extractSourceCode.js.map +1 -0
  223. package/dist/react/jsx/utils/getCalleeNameFromExpression.js +30 -30
  224. package/dist/react/jsx/utils/getCalleeNameFromExpression.js.map +1 -0
  225. package/dist/react/jsx/utils/getPathsAndAliases.js +70 -105
  226. package/dist/react/jsx/utils/getPathsAndAliases.js.map +1 -0
  227. package/dist/react/jsx/utils/isNumberLiteral.js +13 -11
  228. package/dist/react/jsx/utils/isNumberLiteral.js.map +1 -0
  229. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +103 -148
  230. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js.map +1 -0
  231. package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +305 -389
  232. package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -0
  233. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +122 -193
  234. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js.map +1 -0
  235. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +50 -64
  236. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js.map +1 -0
  237. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +41 -68
  238. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js.map +1 -0
  239. package/dist/react/jsx/utils/jsxParsing/parseJsx.js +760 -1107
  240. package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -0
  241. package/dist/react/jsx/utils/jsxParsing/parseTProps.js +35 -71
  242. package/dist/react/jsx/utils/jsxParsing/parseTProps.js.map +1 -0
  243. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +39 -58
  244. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -0
  245. package/dist/react/jsx/utils/jsxParsing/types.js +10 -24
  246. package/dist/react/jsx/utils/jsxParsing/types.js.map +1 -0
  247. package/dist/react/jsx/utils/mapAttributeName.js +13 -13
  248. package/dist/react/jsx/utils/mapAttributeName.js.map +1 -0
  249. package/dist/react/jsx/utils/parseAst.js +142 -272
  250. package/dist/react/jsx/utils/parseAst.js.map +1 -0
  251. package/dist/react/jsx/utils/parseString.js +726 -1090
  252. package/dist/react/jsx/utils/parseString.js.map +1 -0
  253. package/dist/react/jsx/utils/parseStringFunction.js +274 -401
  254. package/dist/react/jsx/utils/parseStringFunction.js.map +1 -0
  255. package/dist/react/jsx/utils/resolveImportPath.js +104 -108
  256. package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
  257. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
  258. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
  259. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
  260. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
  261. package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
  262. package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
  263. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
  264. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
  265. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
  266. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
  267. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
  268. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
  269. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
  270. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
  271. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
  272. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
  273. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
  274. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
  275. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
  276. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
  277. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
  278. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
  279. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
  280. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
  281. package/dist/react/jsx/utils/validateStringFunction.js +21 -29
  282. package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
  283. package/dist/react/jsx/wrapJsx.js +192 -375
  284. package/dist/react/jsx/wrapJsx.js.map +1 -0
  285. package/dist/react/parse/addVitePlugin/index.js +40 -34
  286. package/dist/react/parse/addVitePlugin/index.js.map +1 -0
  287. package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
  288. package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
  289. package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
  290. package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
  291. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
  292. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
  293. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
  294. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
  295. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
  296. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
  297. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
  298. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
  299. package/dist/react/parse/createDictionaryUpdates.js +121 -185
  300. package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
  301. package/dist/react/parse/createInlineUpdates.js +123 -139
  302. package/dist/react/parse/createInlineUpdates.js.map +1 -0
  303. package/dist/react/parse/wrapContent.js +131 -156
  304. package/dist/react/parse/wrapContent.js.map +1 -0
  305. package/dist/react/utils/flattenDictionary.js +55 -70
  306. package/dist/react/utils/flattenDictionary.js.map +1 -0
  307. package/dist/react/utils/getEntryAndMetadata.js +14 -10
  308. package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
  309. package/dist/react/utils/getVariableName.js +36 -33
  310. package/dist/react/utils/getVariableName.js.map +1 -0
  311. package/dist/setup/detectFramework.js +85 -102
  312. package/dist/setup/detectFramework.js.map +1 -0
  313. package/dist/setup/frameworkUtils.js +17 -28
  314. package/dist/setup/frameworkUtils.js.map +1 -0
  315. package/dist/setup/userInput.js +24 -31
  316. package/dist/setup/userInput.js.map +1 -0
  317. package/dist/setup/wizard.js +141 -143
  318. package/dist/setup/wizard.js.map +1 -0
  319. package/dist/state/mintlifyRefMap.js +12 -9
  320. package/dist/state/mintlifyRefMap.js.map +1 -0
  321. package/dist/state/recentDownloads.js +26 -23
  322. package/dist/state/recentDownloads.js.map +1 -0
  323. package/dist/state/translateWarnings.js +17 -8
  324. package/dist/state/translateWarnings.js.map +1 -0
  325. package/dist/translation/parse.js +77 -98
  326. package/dist/translation/parse.js.map +1 -0
  327. package/dist/translation/stage.js +28 -43
  328. package/dist/translation/stage.js.map +1 -0
  329. package/dist/translation/validate.js +68 -91
  330. package/dist/translation/validate.js.map +1 -0
  331. package/dist/types/libraries.js +93 -91
  332. package/dist/types/libraries.js.map +1 -0
  333. package/dist/types/parsing.js +19 -10
  334. package/dist/types/parsing.js.map +1 -0
  335. package/dist/utils/addExplicitAnchorIds.js +270 -389
  336. package/dist/utils/addExplicitAnchorIds.js.map +1 -0
  337. package/dist/utils/calculateTimeoutMs.js +11 -6
  338. package/dist/utils/calculateTimeoutMs.js.map +1 -0
  339. package/dist/utils/constants.js +15 -12
  340. package/dist/utils/constants.js.map +1 -0
  341. package/dist/utils/credentials.js +67 -114
  342. package/dist/utils/credentials.js.map +1 -0
  343. package/dist/utils/fetch.js +22 -20
  344. package/dist/utils/fetch.js.map +1 -0
  345. package/dist/utils/flattenJsonFiles.js +27 -34
  346. package/dist/utils/flattenJsonFiles.js.map +1 -0
  347. package/dist/utils/gitDiff.js +30 -32
  348. package/dist/utils/gitDiff.js.map +1 -0
  349. package/dist/utils/gt.js +7 -2
  350. package/dist/utils/gt.js.map +1 -0
  351. package/dist/utils/hash.js +14 -9
  352. package/dist/utils/hash.js.map +1 -0
  353. package/dist/utils/headers.js +10 -13
  354. package/dist/utils/headers.js.map +1 -0
  355. package/dist/utils/installPackage.js +70 -75
  356. package/dist/utils/installPackage.js.map +1 -0
  357. package/dist/utils/localizeRelativeAssets.js +114 -157
  358. package/dist/utils/localizeRelativeAssets.js.map +1 -0
  359. package/dist/utils/localizeStaticImports.js +229 -371
  360. package/dist/utils/localizeStaticImports.js.map +1 -0
  361. package/dist/utils/localizeStaticUrls.js +241 -424
  362. package/dist/utils/localizeStaticUrls.js.map +1 -0
  363. package/dist/utils/mintlifyTitleFallback.js +64 -72
  364. package/dist/utils/mintlifyTitleFallback.js.map +1 -0
  365. package/dist/utils/monorepoVersionCheck.js +177 -215
  366. package/dist/utils/monorepoVersionCheck.js.map +1 -0
  367. package/dist/utils/packageInfo.js +17 -16
  368. package/dist/utils/packageInfo.js.map +1 -0
  369. package/dist/utils/packageJson.js +51 -66
  370. package/dist/utils/packageJson.js.map +1 -0
  371. package/dist/utils/packageManager.js +237 -260
  372. package/dist/utils/packageManager.js.map +1 -0
  373. package/dist/utils/parse/needsCJS.js +36 -69
  374. package/dist/utils/parse/needsCJS.js.map +1 -0
  375. package/dist/utils/persistPostprocessHashes.js +30 -32
  376. package/dist/utils/persistPostprocessHashes.js.map +1 -0
  377. package/dist/utils/processAnchorIds.js +32 -54
  378. package/dist/utils/processAnchorIds.js.map +1 -0
  379. package/dist/utils/processOpenApi.js +469 -578
  380. package/dist/utils/processOpenApi.js.map +1 -0
  381. package/dist/utils/resolveMintlifyRefs.js +89 -105
  382. package/dist/utils/resolveMintlifyRefs.js.map +1 -0
  383. package/dist/utils/resolvePublish.js +46 -54
  384. package/dist/utils/resolvePublish.js.map +1 -0
  385. package/dist/utils/sanitizeFileContent.js +20 -27
  386. package/dist/utils/sanitizeFileContent.js.map +1 -0
  387. package/dist/utils/sharedStaticAssets.js +248 -366
  388. package/dist/utils/sharedStaticAssets.js.map +1 -0
  389. package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
  390. package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
  391. package/dist/utils/validateMdx.js +26 -23
  392. package/dist/utils/validateMdx.js.map +1 -0
  393. package/dist/utils/wrapPlainUrls.js +58 -70
  394. package/dist/utils/wrapPlainUrls.js.map +1 -0
  395. package/dist/workflows/download.js +92 -126
  396. package/dist/workflows/download.js.map +1 -0
  397. package/dist/workflows/enqueue.js +47 -54
  398. package/dist/workflows/enqueue.js.map +1 -0
  399. package/dist/workflows/publish.js +29 -29
  400. package/dist/workflows/publish.js.map +1 -0
  401. package/dist/workflows/setupProject.js +39 -40
  402. package/dist/workflows/setupProject.js.map +1 -0
  403. package/dist/workflows/stage.js +61 -65
  404. package/dist/workflows/stage.js.map +1 -0
  405. package/dist/workflows/steps/BranchStep.js +118 -163
  406. package/dist/workflows/steps/BranchStep.js.map +1 -0
  407. package/dist/workflows/steps/DownloadStep.js +107 -137
  408. package/dist/workflows/steps/DownloadStep.js.map +1 -0
  409. package/dist/workflows/steps/EnqueueStep.js +32 -32
  410. package/dist/workflows/steps/EnqueueStep.js.map +1 -0
  411. package/dist/workflows/steps/PollJobsStep.js +208 -292
  412. package/dist/workflows/steps/PollJobsStep.js.map +1 -0
  413. package/dist/workflows/steps/PublishStep.js +33 -38
  414. package/dist/workflows/steps/PublishStep.js.map +1 -0
  415. package/dist/workflows/steps/SetupStep.js +71 -72
  416. package/dist/workflows/steps/SetupStep.js.map +1 -0
  417. package/dist/workflows/steps/TagStep.js +39 -44
  418. package/dist/workflows/steps/TagStep.js.map +1 -0
  419. package/dist/workflows/steps/UploadSourcesStep.js +108 -140
  420. package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
  421. package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
  422. package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
  423. package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
  424. package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
  425. package/dist/workflows/steps/WorkflowStep.js +6 -2
  426. package/dist/workflows/steps/WorkflowStep.js.map +1 -0
  427. package/dist/workflows/upload.js +45 -46
  428. package/dist/workflows/upload.js.map +1 -0
  429. package/package.json +14 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapJsx.js","names":[],"sources":["../../../src/react/jsx/wrapJsx.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { isStaticExpression, isStaticValue } from './evaluateJsx.js';\nimport { ImportItem } from './utils/parseAst.js';\nimport { warnTernarySync } from '../../console/index.js';\n/**\n * Recursively wraps a JSX element with a <T> component and unique id\n * @param node - The JSX element to wrap\n * @param updates - The updates array\n * @param errors - The errors array\n * @param file - The file name\n * @param options - Optional component names for T and Var\n */\nexport interface WrapResult {\n node: t.JSXElement | t.JSXFragment;\n // Whether the node has meaningful content (aka, whether the node should be wrapped in a T)\n hasMeaningfulContent: boolean;\n // Whether the node has already been wrapped in a T\n wrappedInT: boolean;\n}\n\nfunction wrapJsxExpression(\n node: t.JSXExpressionContainer,\n options: {\n createIds: boolean;\n TComponent?: string;\n VarComponent?: string;\n idPrefix: string;\n idCount: number;\n usedImports: ImportItem[];\n modified: boolean;\n warnings: string[];\n file: string;\n },\n isMeaningful: (node: t.Node) => boolean,\n mark: boolean\n): {\n node: t.JSXElement | t.JSXExpressionContainer;\n hasMeaningfulContent: boolean;\n wrappedInT: boolean;\n} {\n const expression = t.isParenthesizedExpression(node.expression)\n ? node.expression.expression\n : node.expression;\n\n // Ignore template literals containing quasis - they should not be counted as meaningful\n if (t.isTemplateLiteral(expression) && expression.expressions.length > 0) {\n return {\n node,\n hasMeaningfulContent: false,\n wrappedInT: false,\n };\n }\n\n // Handle both JSX Elements and Fragments\n if (\n t.isJSXElement(expression) ||\n t.isJSXFragment(expression) ||\n t.isStringLiteral(expression) ||\n t.isJSXText(expression) ||\n t.isTemplateLiteral(expression)\n ) {\n if (t.isJSXElement(expression) || t.isJSXFragment(expression)) {\n const result = wrapJsxElement(expression, options, isMeaningful, mark);\n // re-wrap the result in a JSXExpressionContainer\n if (t.isParenthesizedExpression(node.expression)) {\n node.expression.expression = result.node;\n } else {\n node.expression = result.node;\n }\n return {\n node,\n hasMeaningfulContent: result.hasMeaningfulContent,\n wrappedInT: result.wrappedInT,\n };\n }\n return {\n node,\n hasMeaningfulContent: isMeaningful(expression),\n wrappedInT: false,\n };\n }\n // Handle conditional expressions (ternary)\n else if (t.isConditionalExpression(expression)) {\n const consequent = t.isParenthesizedExpression(expression.consequent)\n ? expression.consequent.expression\n : expression.consequent;\n const alternate = t.isParenthesizedExpression(expression.alternate)\n ? expression.alternate.expression\n : expression.alternate;\n\n // Handle consequent\n if (t.isJSXElement(consequent) || t.isJSXFragment(consequent)) {\n const result = handleJsxElement(consequent, options, isMeaningful);\n\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.consequent)) {\n expression.consequent.expression = result.node;\n } else {\n expression.consequent = result.node;\n }\n\n // Warn about ternary (should use branch instead)\n if (result.wrappedInT && !mark) {\n options.warnings.push(\n warnTernarySync(\n options.file,\n `${consequent.loc?.start?.line}:${consequent.loc?.start?.column}`\n )\n );\n }\n } else if (\n t.isConditionalExpression(consequent) ||\n t.isLogicalExpression(consequent)\n ) {\n // Recursively handle nested ternary in consequent\n const consequentResult = wrapJsxExpression(\n t.jsxExpressionContainer(consequent),\n options,\n isMeaningful,\n mark\n );\n if (\n t.isJSXExpressionContainer(consequentResult.node) &&\n t.isExpression(consequentResult.node.expression)\n ) {\n expression.consequent = consequentResult.node.expression;\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.consequent)) {\n expression.consequent.expression = consequentResult.node.expression;\n } else {\n expression.consequent = consequentResult.node.expression;\n }\n }\n } else if (\n t.isTemplateLiteral(consequent) &&\n consequent.expressions.length > 0\n ) {\n // Ignore template literals in consequent with expressions (${}), don't wrap them\n // Do nothing\n } else {\n if (isStaticValue(consequent) && isMeaningful(consequent)) {\n const wrapped = wrapExpressionWithT(consequent, options, false);\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.consequent)) {\n expression.consequent.expression = wrapped;\n } else {\n expression.consequent = wrapped;\n }\n }\n }\n\n // Handle alternate\n if (t.isJSXElement(alternate) || t.isJSXFragment(alternate)) {\n const result = handleJsxElement(alternate, options, isMeaningful);\n\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.alternate)) {\n expression.alternate.expression = result.node;\n } else {\n expression.alternate = result.node;\n }\n } else if (\n t.isConditionalExpression(alternate) ||\n t.isLogicalExpression(alternate)\n ) {\n // Recursively handle nested ternary in alternate\n const alternateResult = wrapJsxExpression(\n t.jsxExpressionContainer(alternate),\n options,\n isMeaningful,\n mark\n );\n if (\n t.isJSXExpressionContainer(alternateResult.node) &&\n t.isExpression(alternateResult.node.expression)\n ) {\n expression.alternate = alternateResult.node.expression;\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.alternate)) {\n expression.alternate.expression = alternateResult.node.expression;\n } else {\n expression.alternate = alternateResult.node.expression;\n }\n }\n } else if (\n t.isTemplateLiteral(alternate) &&\n alternate.expressions.length > 0\n ) {\n // Ignore template literals in alternate with expressions (${}), don't wrap them\n // Do nothing\n } else {\n if (isStaticValue(alternate) && isMeaningful(alternate)) {\n const wrapped = wrapExpressionWithT(alternate, options, false);\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.alternate)) {\n expression.alternate.expression = wrapped;\n } else {\n expression.alternate = wrapped;\n }\n }\n }\n }\n // Handle logical expressions (&& and ||)\n else if (t.isLogicalExpression(expression)) {\n const left = t.isParenthesizedExpression(expression.left)\n ? expression.left.expression\n : expression.left;\n const right = t.isParenthesizedExpression(expression.right)\n ? expression.right.expression\n : expression.right;\n\n if (t.isJSXElement(left) || t.isJSXFragment(left)) {\n const result = handleJsxElement(left, options, isMeaningful);\n\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.left)) {\n expression.left.expression = result.node;\n } else {\n expression.left = result.node;\n }\n } else if (t.isLogicalExpression(left) || t.isConditionalExpression(left)) {\n // Recursively handle nested logical expressions\n const leftResult = wrapJsxExpression(\n t.jsxExpressionContainer(left),\n options,\n isMeaningful,\n mark\n );\n if (\n t.isJSXExpressionContainer(leftResult.node) &&\n t.isExpression(leftResult.node.expression)\n ) {\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.left)) {\n expression.left.expression = leftResult.node.expression;\n } else {\n expression.left = leftResult.node.expression;\n }\n }\n } else if (t.isTemplateLiteral(left) && left.expressions.length > 0) {\n // Ignore template literals with expressions (${}) in left side of logical expression\n // Do nothing - don't wrap them\n } else {\n if (\n isStaticValue(left) &&\n isMeaningful(left) &&\n expression.operator !== '&&'\n ) {\n const wrapped = wrapExpressionWithT(left, options, false);\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.left)) {\n expression.left.expression = wrapped;\n } else {\n expression.left = wrapped;\n }\n }\n }\n\n if (t.isJSXElement(right) || t.isJSXFragment(right)) {\n const result = handleJsxElement(right, options, isMeaningful);\n\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.right)) {\n expression.right.expression = result.node;\n } else {\n expression.right = result.node;\n }\n } else if (\n t.isLogicalExpression(right) ||\n t.isConditionalExpression(right)\n ) {\n // Recursively handle nested logical expressions\n const rightResult = wrapJsxExpression(\n t.jsxExpressionContainer(right),\n options,\n isMeaningful,\n mark\n );\n if (\n t.isJSXExpressionContainer(rightResult.node) &&\n t.isExpression(rightResult.node.expression)\n ) {\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.right)) {\n expression.right.expression = rightResult.node.expression;\n } else {\n expression.right = rightResult.node.expression;\n }\n }\n } else if (t.isTemplateLiteral(right) && right.expressions.length > 0) {\n // Ignore template literals with expressions (${}) in right side of logical expression\n // Do nothing - don't wrap them\n } else {\n if (\n isStaticValue(right) &&\n isMeaningful(right) &&\n expression.operator !== '||'\n ) {\n const wrapped = wrapExpressionWithT(right, options, false);\n // Re-insert into parenthesized expression if necessary\n if (t.isParenthesizedExpression(expression.right)) {\n expression.right.expression = wrapped;\n } else {\n expression.right = wrapped;\n }\n }\n }\n }\n const staticCheck = isStaticExpression(expression);\n // If the expression is not derivable or if it's already wrapped in T,\n // wrap with Var\n if (!staticCheck.isStatic) {\n return {\n node: wrapWithVar(node, options, mark),\n hasMeaningfulContent: false,\n wrappedInT: false,\n };\n }\n\n // If it's a derivable expression, check if it's meaningful\n return {\n node,\n hasMeaningfulContent: false,\n wrappedInT: false,\n };\n}\n\n/**\n * Recursively traverse a JSX element and wrap variables with a <Var> component\n * @param node - The JSX element to wrap\n * @param options - Optional component names for T and Var\n * @param isMeaningful - A function to determine if a node is meaningful\n * @returns The wrapped JSX element\n */\nexport function wrapJsxElement(\n node: t.JSXElement | t.JSXFragment,\n options: {\n createIds: boolean;\n TComponent?: string;\n VarComponent?: string;\n idPrefix: string;\n idCount: number;\n usedImports: ImportItem[];\n modified: boolean;\n warnings: string[];\n file: string;\n },\n isMeaningful: (node: t.Node) => boolean,\n mark: boolean\n): WrapResult {\n const TComponentName = options.TComponent || 'T';\n const VarComponentName = options.VarComponent || 'Var';\n\n // Handle both JSX Elements and Fragments\n if (t.isJSXElement(node) || t.isJSXFragment(node)) {\n // For elements, check if it's already a T or Var component\n if (t.isJSXElement(node)) {\n const name = node.openingElement.name;\n if (\n t.isJSXIdentifier(name) &&\n (name.name === TComponentName || name.name === VarComponentName)\n ) {\n return {\n node,\n hasMeaningfulContent: false,\n wrappedInT: name.name === TComponentName,\n };\n }\n }\n\n // Process children recursively (DFS postorder)\n let hasMeaningfulContent = false;\n let wrappedInT = false;\n const processedChildren = node.children.map((child) => {\n if (t.isJSXElement(child) || t.isJSXFragment(child)) {\n const result = wrapJsxElement(child, options, isMeaningful, mark);\n hasMeaningfulContent =\n hasMeaningfulContent || result.hasMeaningfulContent;\n wrappedInT = wrappedInT || result.wrappedInT;\n return result.node;\n }\n if (t.isJSXExpressionContainer(child)) {\n const result = wrapJsxExpression(child, options, isMeaningful, mark);\n wrappedInT = wrappedInT || result.wrappedInT;\n hasMeaningfulContent =\n hasMeaningfulContent || result.hasMeaningfulContent;\n\n // Expressions are never meaningful because they will either:\n // 1. be sub-wrapped in a T (if they contain meaningful content)\n // 2. be wrapped in a Var (if they are not marked as derivable)\n return result.node;\n }\n const isMeaningfulVal = isMeaningful(child);\n if (isMeaningfulVal) {\n hasMeaningfulContent = true;\n }\n return child;\n });\n\n node.children = processedChildren;\n return {\n node,\n hasMeaningfulContent: hasMeaningfulContent,\n wrappedInT: wrappedInT,\n };\n }\n // For any other node types, return as-is\n return {\n node,\n hasMeaningfulContent: false,\n wrappedInT: false,\n };\n}\n\n/**\n * Wraps a JSX element with a <T> component and unique id\n * @param rootNode - The JSX element to wrap\n * @param options - Optional component names for T and Var\n * @param isMeaningful - A function to determine if a node is meaningful\n * @returns The wrapped JSX element\n */\nexport function handleJsxElement(\n rootNode: t.JSXElement | t.JSXFragment,\n options: {\n createIds: boolean;\n usedImports: ImportItem[];\n TComponent?: string;\n VarComponent?: string;\n idPrefix: string;\n idCount: number;\n modified: boolean;\n warnings: string[];\n file: string;\n },\n isMeaningful: (node: t.Node) => boolean\n): WrapResult {\n const result = wrapJsxElement(rootNode, options, isMeaningful, true);\n\n // Only wrap with T at the root level if there's meaningful content\n if (result.hasMeaningfulContent) {\n const output = wrapJsxElement(result.node, options, isMeaningful, false);\n const node = wrapWithT(output.node, options, false);\n return {\n node,\n hasMeaningfulContent: true,\n wrappedInT: true,\n };\n }\n\n return {\n node: result.node,\n hasMeaningfulContent: false,\n wrappedInT: result.wrappedInT,\n };\n}\n\nfunction wrapWithT(\n node: t.JSXElement | t.JSXFragment,\n options: {\n createIds: boolean;\n TComponent?: string;\n VarComponent?: string;\n idPrefix: string;\n idCount: number;\n usedImports: ImportItem[];\n modified: boolean;\n file: string;\n warnings: string[];\n },\n mark: boolean\n) {\n if (mark) {\n return node;\n }\n const TComponentName = options.TComponent || 'T';\n const uniqueId = `${options.idPrefix}.${options.idCount}`;\n options.modified = true;\n options.idCount++;\n if (!options.usedImports.includes(TComponentName)) {\n options.usedImports.push(TComponentName);\n }\n if (options.createIds) {\n return t.jsxElement(\n t.jsxOpeningElement(\n t.jsxIdentifier(TComponentName),\n [t.jsxAttribute(t.jsxIdentifier('id'), t.stringLiteral(uniqueId))],\n false\n ),\n t.jsxClosingElement(t.jsxIdentifier(TComponentName)),\n [node],\n false\n );\n }\n return t.jsxElement(\n t.jsxOpeningElement(t.jsxIdentifier(TComponentName), [], false),\n t.jsxClosingElement(t.jsxIdentifier(TComponentName)),\n [node],\n false\n );\n}\n\nfunction wrapExpressionWithT(\n node: t.Expression,\n options: {\n createIds: boolean;\n TComponent?: string;\n VarComponent?: string;\n idPrefix: string;\n idCount: number;\n usedImports: ImportItem[];\n modified: boolean;\n file: string;\n warnings: string[];\n },\n mark: boolean\n) {\n if (mark) {\n return node;\n }\n const TComponentName = options.TComponent || 'T';\n const uniqueId = `${options.idPrefix}.${options.idCount}`;\n options.modified = true;\n options.idCount++;\n if (!options.usedImports.includes(TComponentName)) {\n options.usedImports.push(TComponentName);\n }\n if (options.createIds) {\n return t.jsxElement(\n t.jsxOpeningElement(\n t.jsxIdentifier(TComponentName),\n [t.jsxAttribute(t.jsxIdentifier('id'), t.stringLiteral(uniqueId))],\n false\n ),\n t.jsxClosingElement(t.jsxIdentifier(TComponentName)),\n [t.jsxExpressionContainer(node)],\n false\n );\n }\n return t.jsxElement(\n t.jsxOpeningElement(t.jsxIdentifier(TComponentName), [], false),\n t.jsxClosingElement(t.jsxIdentifier(TComponentName)),\n [t.jsxExpressionContainer(node)],\n false\n );\n}\n\nfunction wrapWithVar(\n node: t.JSXElement | t.JSXExpressionContainer,\n options: {\n TComponent?: string;\n VarComponent?: string;\n usedImports: ImportItem[];\n modified: boolean;\n file: string;\n warnings: string[];\n },\n mark: boolean\n) {\n if (mark) {\n return node;\n }\n const VarComponentName = options.VarComponent || 'Var';\n options.modified = true;\n if (!options.usedImports.includes(VarComponentName)) {\n options.usedImports.push(VarComponentName);\n }\n return t.jsxElement(\n t.jsxOpeningElement(t.jsxIdentifier(VarComponentName), [], false),\n t.jsxClosingElement(t.jsxIdentifier(VarComponentName)),\n [node],\n false\n );\n}\n"],"mappings":";;;;AAoBA,SAAS,kBACP,MACA,SAWA,cACA,MAKA;CACA,MAAM,aAAa,EAAE,0BAA0B,KAAK,WAAW,GAC3D,KAAK,WAAW,aAChB,KAAK;AAGT,KAAI,EAAE,kBAAkB,WAAW,IAAI,WAAW,YAAY,SAAS,EACrE,QAAO;EACL;EACA,sBAAsB;EACtB,YAAY;EACb;AAIH,KACE,EAAE,aAAa,WAAW,IAC1B,EAAE,cAAc,WAAW,IAC3B,EAAE,gBAAgB,WAAW,IAC7B,EAAE,UAAU,WAAW,IACvB,EAAE,kBAAkB,WAAW,EAC/B;AACA,MAAI,EAAE,aAAa,WAAW,IAAI,EAAE,cAAc,WAAW,EAAE;GAC7D,MAAM,SAAS,eAAe,YAAY,SAAS,cAAc,KAAK;AAEtE,OAAI,EAAE,0BAA0B,KAAK,WAAW,CAC9C,MAAK,WAAW,aAAa,OAAO;OAEpC,MAAK,aAAa,OAAO;AAE3B,UAAO;IACL;IACA,sBAAsB,OAAO;IAC7B,YAAY,OAAO;IACpB;;AAEH,SAAO;GACL;GACA,sBAAsB,aAAa,WAAW;GAC9C,YAAY;GACb;YAGM,EAAE,wBAAwB,WAAW,EAAE;EAC9C,MAAM,aAAa,EAAE,0BAA0B,WAAW,WAAW,GACjE,WAAW,WAAW,aACtB,WAAW;EACf,MAAM,YAAY,EAAE,0BAA0B,WAAW,UAAU,GAC/D,WAAW,UAAU,aACrB,WAAW;AAGf,MAAI,EAAE,aAAa,WAAW,IAAI,EAAE,cAAc,WAAW,EAAE;GAC7D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,gBAAgB;AACjD,SAAQ,WAAW;AACnB,KAAI,CAAC,QAAQ,YAAY,SAAS,iBAAiB,CACjD,SAAQ,YAAY,KAAK,iBAAiB;AAE5C,QAAO,EAAE,WACP,EAAE,kBAAkB,EAAE,cAAc,iBAAiB,EAAE,EAAE,EAAE,MAAM,EACjE,EAAE,kBAAkB,EAAE,cAAc,iBAAiB,CAAC,EACtD,CAAC,KAAK,EACN,MACD"}
@@ -1,41 +1,47 @@
1
- import findFilepath from '../../../fs/findFilepath.js';
2
- import { logger } from '../../../console/logger.js';
3
- import { installCompiler } from './installCompiler.js';
4
- import { updateViteConfig } from './updateViteConfig.js';
5
- import { exitSync } from '../../../console/logging.js';
6
- const VITE_CONFIG_PATH_BASE = './vite.config.';
1
+ import { logger } from "../../../console/logger.js";
2
+ import { exitSync } from "../../../console/logging.js";
3
+ import findFilepath from "../../../fs/findFilepath.js";
4
+ import { installCompiler } from "./installCompiler.js";
5
+ import { updateViteConfig } from "./updateViteConfig.js";
6
+ //#region src/react/parse/addVitePlugin/index.ts
7
+ const VITE_CONFIG_PATH_BASE = "./vite.config.";
7
8
  /**
8
- * Adds the gt compiler plugin to the vite config file
9
- */
10
- export async function addVitePlugin({ errors, warnings, filesUpdated, packageJson, tsconfigJson, }) {
11
- // Resolve file path
12
- const viteConfigPath = findFilepath([
13
- VITE_CONFIG_PATH_BASE + 'js',
14
- VITE_CONFIG_PATH_BASE + 'ts',
15
- VITE_CONFIG_PATH_BASE + 'mjs',
16
- VITE_CONFIG_PATH_BASE + 'mts',
17
- VITE_CONFIG_PATH_BASE + 'cjs',
18
- VITE_CONFIG_PATH_BASE + 'cts',
19
- ]);
20
- if (!viteConfigPath) {
21
- logger.error(`No ${VITE_CONFIG_PATH_BASE}[js|ts|mjs|mts|cjs|cts] file found. Add the @generaltranslation/compiler plugin to your vite configuration file:
9
+ * Adds the gt compiler plugin to the vite config file
10
+ */
11
+ async function addVitePlugin({ errors, warnings, filesUpdated, packageJson, tsconfigJson }) {
12
+ const viteConfigPath = findFilepath([
13
+ VITE_CONFIG_PATH_BASE + "js",
14
+ VITE_CONFIG_PATH_BASE + "ts",
15
+ VITE_CONFIG_PATH_BASE + "mjs",
16
+ VITE_CONFIG_PATH_BASE + "mts",
17
+ VITE_CONFIG_PATH_BASE + "cjs",
18
+ VITE_CONFIG_PATH_BASE + "cts"
19
+ ]);
20
+ if (!viteConfigPath) {
21
+ logger.error(`No ${VITE_CONFIG_PATH_BASE}[js|ts|mjs|mts|cjs|cts] file found. Add the @generaltranslation/compiler plugin to your vite configuration file:
22
22
  import { vite as gtCompiler } from '@generaltranslation/compiler';
23
23
  export default defineConfig({
24
24
  plugins: [gtCompiler()],
25
25
  });
26
26
  `);
27
- exitSync(1);
28
- }
29
- // Install @generaltranslation/compiler if not installed
30
- await installCompiler({ packageJson });
31
- // Update the config file
32
- await updateViteConfig({
33
- errors,
34
- warnings,
35
- filesUpdated,
36
- viteConfigPath,
37
- packageJson,
38
- tsconfigJson,
39
- });
40
- return { errors, warnings, filesUpdated };
27
+ exitSync(1);
28
+ }
29
+ await installCompiler({ packageJson });
30
+ await updateViteConfig({
31
+ errors,
32
+ warnings,
33
+ filesUpdated,
34
+ viteConfigPath,
35
+ packageJson,
36
+ tsconfigJson
37
+ });
38
+ return {
39
+ errors,
40
+ warnings,
41
+ filesUpdated
42
+ };
41
43
  }
44
+ //#endregion
45
+ export { addVitePlugin };
46
+
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/react/parse/addVitePlugin/index.ts"],"sourcesContent":["import findFilepath from '../../../fs/findFilepath.js';\nimport { logger } from '../../../console/logger.js';\nimport { installCompiler } from './installCompiler.js';\nimport { updateViteConfig } from './updateViteConfig.js';\nimport { exitSync } from '../../../console/logging.js';\n\nconst VITE_CONFIG_PATH_BASE = './vite.config.';\n/**\n * Adds the gt compiler plugin to the vite config file\n */\nexport async function addVitePlugin({\n errors,\n warnings,\n filesUpdated,\n packageJson,\n tsconfigJson,\n}: {\n errors: string[];\n warnings: string[];\n filesUpdated: string[];\n packageJson?: {\n type?: string;\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n tsconfigJson?: { compilerOptions?: { module?: string } };\n}) {\n // Resolve file path\n const viteConfigPath = findFilepath([\n VITE_CONFIG_PATH_BASE + 'js',\n VITE_CONFIG_PATH_BASE + 'ts',\n VITE_CONFIG_PATH_BASE + 'mjs',\n VITE_CONFIG_PATH_BASE + 'mts',\n VITE_CONFIG_PATH_BASE + 'cjs',\n VITE_CONFIG_PATH_BASE + 'cts',\n ]);\n if (!viteConfigPath) {\n logger.error(\n `No ${VITE_CONFIG_PATH_BASE}[js|ts|mjs|mts|cjs|cts] file found. Add the @generaltranslation/compiler plugin to your vite configuration file:\n import { vite as gtCompiler } from '@generaltranslation/compiler';\n export default defineConfig({\n plugins: [gtCompiler()],\n });\n `\n );\n exitSync(1);\n }\n\n // Install @generaltranslation/compiler if not installed\n await installCompiler({ packageJson });\n\n // Update the config file\n await updateViteConfig({\n errors,\n warnings,\n filesUpdated,\n viteConfigPath,\n packageJson,\n tsconfigJson,\n });\n\n return { errors, warnings, filesUpdated };\n}\n"],"mappings":";;;;;;AAMA,MAAM,wBAAwB;;;;AAI9B,eAAsB,cAAc,EAClC,QACA,UACA,cACA,aACA,gBAWC;CAED,MAAM,iBAAiB,aAAa;EAClC,wBAAwB;EACxB,wBAAwB;EACxB,wBAAwB;EACxB,wBAAwB;EACxB,wBAAwB;EACxB,wBAAwB;EACzB,CAAC;AACF,KAAI,CAAC,gBAAgB;AACnB,SAAO,MACL,MAAM,sBAAsB;;;;;QAM7B;AACD,WAAS,EAAE;;AAIb,OAAM,gBAAgB,EAAE,aAAa,CAAC;AAGtC,OAAM,iBAAiB;EACrB;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAEF,QAAO;EAAE;EAAQ;EAAU;EAAc"}
@@ -1,22 +1,20 @@
1
- import { logger } from '../../../console/logger.js';
2
- import { installPackage } from '../../../utils/installPackage.js';
3
- import { isPackageInstalled } from '../../../utils/packageJson.js';
4
- import { getPackageManager } from '../../../utils/packageManager.js';
5
- import chalk from 'chalk';
1
+ import { logger } from "../../../console/logger.js";
2
+ import { isPackageInstalled } from "../../../utils/packageJson.js";
3
+ import { getPackageManager } from "../../../utils/packageManager.js";
4
+ import { installPackage } from "../../../utils/installPackage.js";
5
+ import chalk from "chalk";
6
+ //#region src/react/parse/addVitePlugin/installCompiler.ts
6
7
  /**
7
- * Installs @generaltranslation/compiler if not installed
8
- */
9
- export async function installCompiler({ packageJson, }) {
10
- // Check if installed
11
- if (isPackageInstalled('@generaltranslation/compiler', packageJson || {})) {
12
- return;
13
- }
14
- // Animation
15
- const spinner = logger.createSpinner();
16
- spinner.start(`Installing @generaltranslation/compiler...`);
17
- // Install
18
- const packageManager = await getPackageManager();
19
- await installPackage('@generaltranslation/compiler', packageManager, true);
20
- // Animation
21
- spinner.stop(chalk.green('Installed @generaltranslation/compiler.'));
8
+ * Installs @generaltranslation/compiler if not installed
9
+ */
10
+ async function installCompiler({ packageJson }) {
11
+ if (isPackageInstalled("@generaltranslation/compiler", packageJson || {})) return;
12
+ const spinner = logger.createSpinner();
13
+ spinner.start(`Installing @generaltranslation/compiler...`);
14
+ await installPackage("@generaltranslation/compiler", await getPackageManager(), true);
15
+ spinner.stop(chalk.green("Installed @generaltranslation/compiler."));
22
16
  }
17
+ //#endregion
18
+ export { installCompiler };
19
+
20
+ //# sourceMappingURL=installCompiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installCompiler.js","names":[],"sources":["../../../../src/react/parse/addVitePlugin/installCompiler.ts"],"sourcesContent":["import { logger } from '../../../console/logger.js';\nimport { installPackage } from '../../../utils/installPackage.js';\nimport { isPackageInstalled } from '../../../utils/packageJson.js';\nimport { getPackageManager } from '../../../utils/packageManager.js';\nimport chalk from 'chalk';\n\n/**\n * Installs @generaltranslation/compiler if not installed\n */\nexport async function installCompiler({\n packageJson,\n}: {\n packageJson?: { type?: string };\n}) {\n // Check if installed\n if (isPackageInstalled('@generaltranslation/compiler', packageJson || {})) {\n return;\n }\n\n // Animation\n const spinner = logger.createSpinner();\n spinner.start(`Installing @generaltranslation/compiler...`);\n\n // Install\n const packageManager = await getPackageManager();\n await installPackage('@generaltranslation/compiler', packageManager, true);\n\n // Animation\n spinner.stop(chalk.green('Installed @generaltranslation/compiler.'));\n}\n"],"mappings":";;;;;;;;;AASA,eAAsB,gBAAgB,EACpC,eAGC;AAED,KAAI,mBAAmB,gCAAgC,eAAe,EAAE,CAAC,CACvE;CAIF,MAAM,UAAU,OAAO,eAAe;AACtC,SAAQ,MAAM,6CAA6C;AAI3D,OAAM,eAAe,gCAAgC,MADxB,mBAAmB,EACqB,KAAK;AAG1E,SAAQ,KAAK,MAAM,MAAM,0CAA0C,CAAC"}
@@ -1,120 +1,116 @@
1
- import { logger } from '../../../console/logger.js';
2
- import fs from 'node:fs';
3
- import chalk from 'chalk';
4
- import generateModule from '@babel/generator';
5
- import { parse } from '@babel/parser';
6
- import { needsCJS } from '../../../utils/parse/needsCJS.js';
7
- import { addCompilerImport } from './utils/addCompilerImport.js';
8
- import { checkCompilerImport } from './utils/checkCompilerImport.js';
9
- import { checkPluginInvocation } from './utils/checkPluginInvocation.js';
10
- import { addPluginInvocation } from './utils/addPluginInvocation.js';
11
- import { exitSync } from '../../../console/logging.js';
12
- // Handle CommonJS/ESM interop
1
+ import { logger } from "../../../console/logger.js";
2
+ import { exitSync } from "../../../console/logging.js";
3
+ import { needsCJS } from "../../../utils/parse/needsCJS.js";
4
+ import { addCompilerImport } from "./utils/addCompilerImport.js";
5
+ import { checkCompilerImport } from "./utils/checkCompilerImport.js";
6
+ import { checkPluginInvocation } from "./utils/checkPluginInvocation.js";
7
+ import { addPluginInvocation } from "./utils/addPluginInvocation.js";
8
+ import chalk from "chalk";
9
+ import fs from "node:fs";
10
+ import { parse } from "@babel/parser";
11
+ import generateModule from "@babel/generator";
12
+ //#region src/react/parse/addVitePlugin/updateViteConfig.ts
13
13
  const generate = generateModule.default || generateModule;
14
14
  /**
15
- * - Reads the vite config file
16
- * - Updates the ast to add the gt compiler plugin
17
- * - Writes the file back to the filesystem
18
- */
19
- export async function updateViteConfig({ errors, warnings, filesUpdated, viteConfigPath, packageJson, tsconfigJson, }) {
20
- // Animation
21
- const spinner = logger.createSpinner();
22
- spinner.start(`Adding gt compiler plugin to ${viteConfigPath}...`);
23
- // Read the file
24
- let code;
25
- try {
26
- code = await fs.promises.readFile(viteConfigPath, 'utf8');
27
- }
28
- catch (error) {
29
- logger.error(`Error: Failed to read ${viteConfigPath}: ${error}`);
30
- exitSync(1);
31
- }
32
- // Update the ast
33
- let updatedCode, success;
34
- try {
35
- ({ updatedCode, success } = await updateViteConfigAst({
36
- code,
37
- errors,
38
- warnings,
39
- viteConfigPath,
40
- packageJson,
41
- tsconfigJson,
42
- }));
43
- }
44
- catch (error) {
45
- logger.error(`Error: Failed to update ${viteConfigPath}: ${error}`);
46
- exitSync(1);
47
- }
48
- // Write the file
49
- try {
50
- await fs.promises.writeFile(viteConfigPath, updatedCode);
51
- filesUpdated.push(viteConfigPath);
52
- }
53
- catch (error) {
54
- logger.error(`Error: Failed to write ${viteConfigPath}: ${error}`);
55
- exitSync(1);
56
- }
57
- // Animation
58
- spinner.stop(success
59
- ? chalk.green(`Success! Added gt compiler plugin to ${viteConfigPath}`)
60
- : chalk.red(`Failed to add gt compiler plugin to ${viteConfigPath}. Continuing setup...`));
15
+ * - Reads the vite config file
16
+ * - Updates the ast to add the gt compiler plugin
17
+ * - Writes the file back to the filesystem
18
+ */
19
+ async function updateViteConfig({ errors, warnings, filesUpdated, viteConfigPath, packageJson, tsconfigJson }) {
20
+ const spinner = logger.createSpinner();
21
+ spinner.start(`Adding gt compiler plugin to ${viteConfigPath}...`);
22
+ let code;
23
+ try {
24
+ code = await fs.promises.readFile(viteConfigPath, "utf8");
25
+ } catch (error) {
26
+ logger.error(`Error: Failed to read ${viteConfigPath}: ${error}`);
27
+ exitSync(1);
28
+ }
29
+ let updatedCode, success;
30
+ try {
31
+ ({updatedCode, success} = await updateViteConfigAst({
32
+ code,
33
+ errors,
34
+ warnings,
35
+ viteConfigPath,
36
+ packageJson,
37
+ tsconfigJson
38
+ }));
39
+ } catch (error) {
40
+ logger.error(`Error: Failed to update ${viteConfigPath}: ${error}`);
41
+ exitSync(1);
42
+ }
43
+ try {
44
+ await fs.promises.writeFile(viteConfigPath, updatedCode);
45
+ filesUpdated.push(viteConfigPath);
46
+ } catch (error) {
47
+ logger.error(`Error: Failed to write ${viteConfigPath}: ${error}`);
48
+ exitSync(1);
49
+ }
50
+ spinner.stop(success ? chalk.green(`Success! Added gt compiler plugin to ${viteConfigPath}`) : chalk.red(`Failed to add gt compiler plugin to ${viteConfigPath}. Continuing setup...`));
61
51
  }
62
52
  /**
63
- * Orchestrates AST manipulation
64
- * @param code - The code to update
65
- * @param errors - The errors to update
66
- * @param warnings - The warnings to update
67
- * @param viteConfigPath - The path to the vite config file
68
- * @param packageJson - The package.json file
69
- * @param tsconfigJson - The tsconfig.json file
70
- * @returns
71
- */
72
- async function updateViteConfigAst({ code, warnings, viteConfigPath, packageJson, tsconfigJson, }) {
73
- // Parse the code
74
- const ast = parse(code, {
75
- sourceType: 'module',
76
- plugins: ['jsx', 'typescript'],
77
- });
78
- // Get cjs or esm
79
- const cjsEnabled = needsCJS({
80
- ast,
81
- warnings,
82
- filepath: viteConfigPath,
83
- packageJson,
84
- tsconfigJson,
85
- });
86
- // Check if the compiler import is already present
87
- let { hasCompilerImport, alias, namespaces } = checkCompilerImport(ast);
88
- // Add the import declaration
89
- if (!hasCompilerImport) {
90
- addCompilerImport({ ast, cjsEnabled });
91
- hasCompilerImport = true;
92
- alias = 'gtCompiler';
93
- namespaces = [];
94
- }
95
- // Check if plugin is already present
96
- let pluginAlreadyPresent = false;
97
- if (hasCompilerImport) {
98
- pluginAlreadyPresent = checkPluginInvocation({ ast, alias, namespaces });
99
- }
100
- // Insert plugin invocation
101
- let success = false;
102
- if (!pluginAlreadyPresent) {
103
- success = addPluginInvocation({ ast, alias, namespaces });
104
- if (!success) {
105
- warnings.push(`Failed to add gt compiler plugin to ${viteConfigPath}. Add the plugin manually:
53
+ * Orchestrates AST manipulation
54
+ * @param code - The code to update
55
+ * @param errors - The errors to update
56
+ * @param warnings - The warnings to update
57
+ * @param viteConfigPath - The path to the vite config file
58
+ * @param packageJson - The package.json file
59
+ * @param tsconfigJson - The tsconfig.json file
60
+ * @returns
61
+ */
62
+ async function updateViteConfigAst({ code, warnings, viteConfigPath, packageJson, tsconfigJson }) {
63
+ const ast = parse(code, {
64
+ sourceType: "module",
65
+ plugins: ["jsx", "typescript"]
66
+ });
67
+ const cjsEnabled = needsCJS({
68
+ ast,
69
+ warnings,
70
+ filepath: viteConfigPath,
71
+ packageJson,
72
+ tsconfigJson
73
+ });
74
+ let { hasCompilerImport, alias, namespaces } = checkCompilerImport(ast);
75
+ if (!hasCompilerImport) {
76
+ addCompilerImport({
77
+ ast,
78
+ cjsEnabled
79
+ });
80
+ hasCompilerImport = true;
81
+ alias = "gtCompiler";
82
+ namespaces = [];
83
+ }
84
+ let pluginAlreadyPresent = false;
85
+ if (hasCompilerImport) pluginAlreadyPresent = checkPluginInvocation({
86
+ ast,
87
+ alias,
88
+ namespaces
89
+ });
90
+ let success = false;
91
+ if (!pluginAlreadyPresent) {
92
+ success = addPluginInvocation({
93
+ ast,
94
+ alias,
95
+ namespaces
96
+ });
97
+ if (!success) warnings.push(`Failed to add gt compiler plugin to ${viteConfigPath}. Add the plugin manually:
106
98
  import { vite as gtCompiler } from '@generaltranslation/compiler';
107
99
  export default defineConfig({
108
100
  plugins: [gtCompiler()],
109
101
  });`);
110
- }
111
- }
112
- // Generate the modified code
113
- const output = generate(ast, {
114
- retainLines: true,
115
- retainFunctionParens: true,
116
- comments: true,
117
- compact: 'auto',
118
- }, code);
119
- return { updatedCode: output.code, success };
102
+ }
103
+ return {
104
+ updatedCode: generate(ast, {
105
+ retainLines: true,
106
+ retainFunctionParens: true,
107
+ comments: true,
108
+ compact: "auto"
109
+ }, code).code,
110
+ success
111
+ };
120
112
  }
113
+ //#endregion
114
+ export { updateViteConfig };
115
+
116
+ //# sourceMappingURL=updateViteConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateViteConfig.js","names":[],"sources":["../../../../src/react/parse/addVitePlugin/updateViteConfig.ts"],"sourcesContent":["import { logger } from '../../../console/logger.js';\nimport fs from 'node:fs';\nimport chalk from 'chalk';\nimport generateModule from '@babel/generator';\nimport { parse } from '@babel/parser';\nimport { needsCJS } from '../../../utils/parse/needsCJS.js';\nimport { addCompilerImport } from './utils/addCompilerImport.js';\nimport { checkCompilerImport } from './utils/checkCompilerImport.js';\nimport { checkPluginInvocation } from './utils/checkPluginInvocation.js';\nimport { addPluginInvocation } from './utils/addPluginInvocation.js';\nimport { exitSync } from '../../../console/logging.js';\n\n// Handle CommonJS/ESM interop\nconst generate = generateModule.default || generateModule;\n\n/**\n * - Reads the vite config file\n * - Updates the ast to add the gt compiler plugin\n * - Writes the file back to the filesystem\n */\nexport async function updateViteConfig({\n errors,\n warnings,\n filesUpdated,\n viteConfigPath,\n packageJson,\n tsconfigJson,\n}: {\n errors: string[];\n warnings: string[];\n filesUpdated: string[];\n viteConfigPath: string;\n packageJson?: { type?: string };\n tsconfigJson?: { compilerOptions?: { module?: string } };\n}) {\n // Animation\n const spinner = logger.createSpinner();\n spinner.start(`Adding gt compiler plugin to ${viteConfigPath}...`);\n\n // Read the file\n let code;\n try {\n code = await fs.promises.readFile(viteConfigPath, 'utf8');\n } catch (error) {\n logger.error(`Error: Failed to read ${viteConfigPath}: ${error}`);\n exitSync(1);\n }\n\n // Update the ast\n let updatedCode, success;\n try {\n ({ updatedCode, success } = await updateViteConfigAst({\n code,\n errors,\n warnings,\n viteConfigPath,\n packageJson,\n tsconfigJson,\n }));\n } catch (error) {\n logger.error(`Error: Failed to update ${viteConfigPath}: ${error}`);\n exitSync(1);\n }\n\n // Write the file\n try {\n await fs.promises.writeFile(viteConfigPath, updatedCode);\n filesUpdated.push(viteConfigPath);\n } catch (error) {\n logger.error(`Error: Failed to write ${viteConfigPath}: ${error}`);\n exitSync(1);\n }\n\n // Animation\n spinner.stop(\n success\n ? chalk.green(`Success! Added gt compiler plugin to ${viteConfigPath}`)\n : chalk.red(\n `Failed to add gt compiler plugin to ${viteConfigPath}. Continuing setup...`\n )\n );\n}\n\n/**\n * Orchestrates AST manipulation\n * @param code - The code to update\n * @param errors - The errors to update\n * @param warnings - The warnings to update\n * @param viteConfigPath - The path to the vite config file\n * @param packageJson - The package.json file\n * @param tsconfigJson - The tsconfig.json file\n * @returns\n */\nasync function updateViteConfigAst({\n code,\n warnings,\n viteConfigPath,\n packageJson,\n tsconfigJson,\n}: {\n code: string;\n errors: string[];\n warnings: string[];\n viteConfigPath: string;\n packageJson?: { type?: string };\n tsconfigJson?: { compilerOptions?: { module?: string } };\n}): Promise<{ updatedCode: string; success: boolean }> {\n // Parse the code\n const ast = parse(code, {\n sourceType: 'module',\n plugins: ['jsx', 'typescript'],\n });\n\n // Get cjs or esm\n const cjsEnabled = needsCJS({\n ast,\n warnings,\n filepath: viteConfigPath,\n packageJson,\n tsconfigJson,\n });\n\n // Check if the compiler import is already present\n let { hasCompilerImport, alias, namespaces } = checkCompilerImport(ast);\n\n // Add the import declaration\n if (!hasCompilerImport) {\n addCompilerImport({ ast, cjsEnabled });\n hasCompilerImport = true;\n alias = 'gtCompiler';\n namespaces = [];\n }\n\n // Check if plugin is already present\n let pluginAlreadyPresent = false;\n if (hasCompilerImport) {\n pluginAlreadyPresent = checkPluginInvocation({ ast, alias, namespaces });\n }\n\n // Insert plugin invocation\n let success = false;\n if (!pluginAlreadyPresent) {\n success = addPluginInvocation({ ast, alias, namespaces });\n if (!success) {\n warnings.push(\n `Failed to add gt compiler plugin to ${viteConfigPath}. Add the plugin manually:\nimport { vite as gtCompiler } from '@generaltranslation/compiler';\nexport default defineConfig({\n plugins: [gtCompiler()],\n});`\n );\n }\n }\n\n // Generate the modified code\n const output = generate(\n ast,\n {\n retainLines: true,\n retainFunctionParens: true,\n comments: true,\n compact: 'auto',\n },\n code\n );\n\n return { updatedCode: output.code, success };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,WAAW,eAAe,WAAW;;;;;;AAO3C,eAAsB,iBAAiB,EACrC,QACA,UACA,cACA,gBACA,aACA,gBAQC;CAED,MAAM,UAAU,OAAO,eAAe;AACtC,SAAQ,MAAM,gCAAgC,eAAe,KAAK;CAGlE,IAAI;AACJ,KAAI;AACF,SAAO,MAAM,GAAG,SAAS,SAAS,gBAAgB,OAAO;UAClD,OAAO;AACd,SAAO,MAAM,yBAAyB,eAAe,IAAI,QAAQ;AACjE,WAAS,EAAE;;CAIb,IAAI,aAAa;AACjB,KAAI;AACF,GAAC,CAAE,aAAa,WAAY,MAAM,oBAAoB;GACpD;GACA;GACA;GACA;GACA;GACA;GACD,CAAC;UACK,OAAO;AACd,SAAO,MAAM,2BAA2B,eAAe,IAAI,QAAQ;AACnE,WAAS,EAAE;;AAIb,KAAI;AACF,QAAM,GAAG,SAAS,UAAU,gBAAgB,YAAY;AACxD,eAAa,KAAK,eAAe;UAC1B,OAAO;AACd,SAAO,MAAM,0BAA0B,eAAe,IAAI,QAAQ;AAClE,WAAS,EAAE;;AAIb,SAAQ,KACN,UACI,MAAM,MAAM,wCAAwC,iBAAiB,GACrE,MAAM,IACJ,uCAAuC,eAAe,uBACvD,CACN;;;;;;;;;;;;AAaH,eAAe,oBAAoB,EACjC,MACA,UACA,gBACA,aACA,gBAQqD;CAErD,MAAM,MAAM,MAAM,MAAM;EACtB,YAAY;EACZ,SAAS,CAAC,OAAO,aAAa;EAC/B,CAAC;CAGF,MAAM,aAAa,SAAS;EAC1B;EACA;EACA,UAAU;EACV;EACA;EACD,CAAC;CAGF,IAAI,EAAE,mBAAmB,OAAO,eAAe,oBAAoB,IAAI;AAGvE,KAAI,CAAC,mBAAmB;AACtB,oBAAkB;GAAE;GAAK;GAAY,CAAC;AACtC,sBAAoB;AACpB,UAAQ;AACR,eAAa,EAAE;;CAIjB,IAAI,uBAAuB;AAC3B,KAAI,kBACF,wBAAuB,sBAAsB;EAAE;EAAK;EAAO;EAAY,CAAC;CAI1E,IAAI,UAAU;AACd,KAAI,CAAC,sBAAsB;AACzB,YAAU,oBAAoB;GAAE;GAAK;GAAO;GAAY,CAAC;AACzD,MAAI,CAAC,QACH,UAAS,KACP,uCAAuC,eAAe;;;;KAKvD;;AAgBL,QAAO;EAAE,aAXM,SACb,KACA;GACE,aAAa;GACb,sBAAsB;GACtB,UAAU;GACV,SAAS;GACV,EACD,KAG0B,CAAC;EAAM;EAAS"}
@@ -1,34 +1,31 @@
1
- import * as t from '@babel/types';
1
+ import * as t from "@babel/types";
2
+ //#region src/react/parse/addVitePlugin/utils/addCompilerImport.ts
2
3
  /**
3
- * Given the vite config file ast, inserts the import declaration for the @generaltranslation/compiler package
4
- */
5
- export function addCompilerImport({ ast, cjsEnabled, }) {
6
- if (cjsEnabled) {
7
- handleCjsImport(ast);
8
- }
9
- else {
10
- handleEsmImport(ast);
11
- }
4
+ * Given the vite config file ast, inserts the import declaration for the @generaltranslation/compiler package
5
+ */
6
+ function addCompilerImport({ ast, cjsEnabled }) {
7
+ if (cjsEnabled) handleCjsImport(ast);
8
+ else handleEsmImport(ast);
12
9
  }
13
10
  /**
14
- * Adds a CJS import declaration for the @generaltranslation/compiler package
15
- * @param ast - The ast of the file
16
- * const gtCompiler = require('@generaltranslation/compiler').vite;
17
- */
11
+ * Adds a CJS import declaration for the @generaltranslation/compiler package
12
+ * @param ast - The ast of the file
13
+ * const gtCompiler = require('@generaltranslation/compiler').vite;
14
+ */
18
15
  function handleCjsImport(ast) {
19
- const variableDeclaration = t.variableDeclaration('const', [
20
- t.variableDeclarator(t.identifier('gtCompiler'), t.memberExpression(t.callExpression(t.identifier('require'), [
21
- t.stringLiteral('@generaltranslation/compiler'),
22
- ]), t.identifier('vite'))),
23
- ]);
24
- ast.program.body.unshift(variableDeclaration);
16
+ const variableDeclaration = t.variableDeclaration("const", [t.variableDeclarator(t.identifier("gtCompiler"), t.memberExpression(t.callExpression(t.identifier("require"), [t.stringLiteral("@generaltranslation/compiler")]), t.identifier("vite")))]);
17
+ ast.program.body.unshift(variableDeclaration);
25
18
  }
26
19
  /**
27
- * Adds an ESM import declaration for the @generaltranslation/compiler package
28
- * @param ast - The ast of the file
29
- * import { vite as gtCompiler } from '@generaltranslation/compiler';
30
- */
20
+ * Adds an ESM import declaration for the @generaltranslation/compiler package
21
+ * @param ast - The ast of the file
22
+ * import { vite as gtCompiler } from '@generaltranslation/compiler';
23
+ */
31
24
  function handleEsmImport(ast) {
32
- const importDeclaration = t.importDeclaration([t.importSpecifier(t.identifier('gtCompiler'), t.identifier('vite'))], t.stringLiteral('@generaltranslation/compiler'));
33
- ast.program.body.unshift(importDeclaration);
25
+ const importDeclaration = t.importDeclaration([t.importSpecifier(t.identifier("gtCompiler"), t.identifier("vite"))], t.stringLiteral("@generaltranslation/compiler"));
26
+ ast.program.body.unshift(importDeclaration);
34
27
  }
28
+ //#endregion
29
+ export { addCompilerImport };
30
+
31
+ //# sourceMappingURL=addCompilerImport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addCompilerImport.js","names":[],"sources":["../../../../../src/react/parse/addVitePlugin/utils/addCompilerImport.ts"],"sourcesContent":["import { ParseResult } from '@babel/parser';\nimport * as t from '@babel/types';\n\n/**\n * Given the vite config file ast, inserts the import declaration for the @generaltranslation/compiler package\n */\nexport function addCompilerImport({\n ast,\n cjsEnabled,\n}: {\n ast: ParseResult<t.File>;\n cjsEnabled: boolean;\n}) {\n if (cjsEnabled) {\n handleCjsImport(ast);\n } else {\n handleEsmImport(ast);\n }\n}\n\n/**\n * Adds a CJS import declaration for the @generaltranslation/compiler package\n * @param ast - The ast of the file\n * const gtCompiler = require('@generaltranslation/compiler').vite;\n */\nfunction handleCjsImport(ast: ParseResult<t.File>) {\n const variableDeclaration = t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier('gtCompiler'),\n t.memberExpression(\n t.callExpression(t.identifier('require'), [\n t.stringLiteral('@generaltranslation/compiler'),\n ]),\n t.identifier('vite')\n )\n ),\n ]);\n ast.program.body.unshift(variableDeclaration);\n}\n\n/**\n * Adds an ESM import declaration for the @generaltranslation/compiler package\n * @param ast - The ast of the file\n * import { vite as gtCompiler } from '@generaltranslation/compiler';\n */\nfunction handleEsmImport(ast: ParseResult<t.File>) {\n const importDeclaration = t.importDeclaration(\n [t.importSpecifier(t.identifier('gtCompiler'), t.identifier('vite'))],\n t.stringLiteral('@generaltranslation/compiler')\n );\n ast.program.body.unshift(importDeclaration);\n}\n"],"mappings":";;;;;AAMA,SAAgB,kBAAkB,EAChC,KACA,cAIC;AACD,KAAI,WACF,iBAAgB,IAAI;KAEpB,iBAAgB,IAAI;;;;;;;AASxB,SAAS,gBAAgB,KAA0B;CACjD,MAAM,sBAAsB,EAAE,oBAAoB,SAAS,CACzD,EAAE,mBACA,EAAE,WAAW,aAAa,EAC1B,EAAE,iBACA,EAAE,eAAe,EAAE,WAAW,UAAU,EAAE,CACxC,EAAE,cAAc,+BAA+B,CAChD,CAAC,EACF,EAAE,WAAW,OAAO,CACrB,CACF,CACF,CAAC;AACF,KAAI,QAAQ,KAAK,QAAQ,oBAAoB;;;;;;;AAQ/C,SAAS,gBAAgB,KAA0B;CACjD,MAAM,oBAAoB,EAAE,kBAC1B,CAAC,EAAE,gBAAgB,EAAE,WAAW,aAAa,EAAE,EAAE,WAAW,OAAO,CAAC,CAAC,EACrE,EAAE,cAAc,+BAA+B,CAChD;AACD,KAAI,QAAQ,KAAK,QAAQ,kBAAkB"}
@@ -1,48 +1,34 @@
1
- import * as t from '@babel/types';
2
- import traverseModule from '@babel/traverse';
3
- // Handle CommonJS/ESM interop
1
+ import * as t from "@babel/types";
2
+ import traverseModule from "@babel/traverse";
3
+ //#region src/react/parse/addVitePlugin/utils/addPluginInvocation.ts
4
4
  const traverse = traverseModule.default || traverseModule;
5
5
  /**
6
- * Adds the plugin invocation to the vite config file
7
- * Naive solution: look for an object with a plugins property only inside of a defineConfig call
8
- */
9
- export function addPluginInvocation({ ast, alias, namespaces, }) {
10
- let addedPlugin = false;
11
- if (namespaces.length === 0 && !alias) {
12
- return false;
13
- }
14
- const pluginInvocation = alias
15
- ? t.callExpression(t.identifier(alias), [])
16
- : t.callExpression(t.memberExpression(t.identifier(namespaces[0]), t.identifier('vite')), []);
17
- traverse(ast, {
18
- CallExpression(path) {
19
- if (!t.isIdentifier(path.node.callee, { name: 'defineConfig' }) ||
20
- !path.node.arguments.length ||
21
- !t.isObjectExpression(path.node.arguments[0])) {
22
- return;
23
- }
24
- for (const property of path.node.arguments[0].properties) {
25
- if (!t.isObjectProperty(property) || !isPluginsProperty(property))
26
- continue;
27
- if (t.isArrayExpression(property.value)) {
28
- // Add to array: [react()] -> [react(), gtCompiler()]
29
- property.value.elements.push(pluginInvocation);
30
- addedPlugin = true;
31
- }
32
- else {
33
- // Spread the array: someList -> [...someList, gtCompiler()]
34
- property.value = t.arrayExpression([
35
- t.spreadElement(property.value),
36
- pluginInvocation,
37
- ]);
38
- addedPlugin = true;
39
- }
40
- }
41
- },
42
- });
43
- return addedPlugin;
6
+ * Adds the plugin invocation to the vite config file
7
+ * Naive solution: look for an object with a plugins property only inside of a defineConfig call
8
+ */
9
+ function addPluginInvocation({ ast, alias, namespaces }) {
10
+ let addedPlugin = false;
11
+ if (namespaces.length === 0 && !alias) return false;
12
+ const pluginInvocation = alias ? t.callExpression(t.identifier(alias), []) : t.callExpression(t.memberExpression(t.identifier(namespaces[0]), t.identifier("vite")), []);
13
+ traverse(ast, { CallExpression(path) {
14
+ if (!t.isIdentifier(path.node.callee, { name: "defineConfig" }) || !path.node.arguments.length || !t.isObjectExpression(path.node.arguments[0])) return;
15
+ for (const property of path.node.arguments[0].properties) {
16
+ if (!t.isObjectProperty(property) || !isPluginsProperty(property)) continue;
17
+ if (t.isArrayExpression(property.value)) {
18
+ property.value.elements.push(pluginInvocation);
19
+ addedPlugin = true;
20
+ } else {
21
+ property.value = t.arrayExpression([t.spreadElement(property.value), pluginInvocation]);
22
+ addedPlugin = true;
23
+ }
24
+ }
25
+ } });
26
+ return addedPlugin;
44
27
  }
45
28
  function isPluginsProperty(node) {
46
- return (t.isIdentifier(node.key, { name: 'plugins' }) ||
47
- t.isStringLiteral(node.key, { value: 'plugins' }));
29
+ return t.isIdentifier(node.key, { name: "plugins" }) || t.isStringLiteral(node.key, { value: "plugins" });
48
30
  }
31
+ //#endregion
32
+ export { addPluginInvocation };
33
+
34
+ //# sourceMappingURL=addPluginInvocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addPluginInvocation.js","names":[],"sources":["../../../../../src/react/parse/addVitePlugin/utils/addPluginInvocation.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { ParseResult } from '@babel/parser';\nimport traverseModule from '@babel/traverse';\n\n// Handle CommonJS/ESM interop\nconst traverse = traverseModule.default || traverseModule;\n\n/**\n * Adds the plugin invocation to the vite config file\n * Naive solution: look for an object with a plugins property only inside of a defineConfig call\n */\nexport function addPluginInvocation({\n ast,\n alias,\n namespaces,\n}: {\n ast: ParseResult<t.File>;\n alias: string | null;\n namespaces: string[];\n}): boolean {\n let addedPlugin = false;\n if (namespaces.length === 0 && !alias) {\n return false;\n }\n const pluginInvocation = alias\n ? t.callExpression(t.identifier(alias), [])\n : t.callExpression(\n t.memberExpression(t.identifier(namespaces[0]), t.identifier('vite')),\n []\n );\n\n traverse(ast, {\n CallExpression(path) {\n if (\n !t.isIdentifier(path.node.callee, { name: 'defineConfig' }) ||\n !path.node.arguments.length ||\n !t.isObjectExpression(path.node.arguments[0])\n ) {\n return;\n }\n for (const property of path.node.arguments[0].properties) {\n if (!t.isObjectProperty(property) || !isPluginsProperty(property))\n continue;\n if (t.isArrayExpression(property.value)) {\n // Add to array: [react()] -> [react(), gtCompiler()]\n property.value.elements.push(pluginInvocation);\n addedPlugin = true;\n } else {\n // Spread the array: someList -> [...someList, gtCompiler()]\n property.value = t.arrayExpression([\n t.spreadElement(property.value as t.Expression),\n pluginInvocation,\n ]);\n addedPlugin = true;\n }\n }\n },\n });\n return addedPlugin;\n}\n\nfunction isPluginsProperty(node: t.ObjectProperty) {\n return (\n t.isIdentifier(node.key, { name: 'plugins' }) ||\n t.isStringLiteral(node.key, { value: 'plugins' })\n );\n}\n"],"mappings":";;;AAKA,MAAM,WAAW,eAAe,WAAW;;;;;AAM3C,SAAgB,oBAAoB,EAClC,KACA,OACA,cAKU;CACV,IAAI,cAAc;AAClB,KAAI,WAAW,WAAW,KAAK,CAAC,MAC9B,QAAO;CAET,MAAM,mBAAmB,QACrB,EAAE,eAAe,EAAE,WAAW,MAAM,EAAE,EAAE,CAAC,GACzC,EAAE,eACA,EAAE,iBAAiB,EAAE,WAAW,WAAW,GAAG,EAAE,EAAE,WAAW,OAAO,CAAC,EACrE,EAAE,CACH;AAEL,UAAS,KAAK,EACZ,eAAe,MAAM;AACnB,MACE,CAAC,EAAE,aAAa,KAAK,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC,IAC3D,CAAC,KAAK,KAAK,UAAU,UACrB,CAAC,EAAE,mBAAmB,KAAK,KAAK,UAAU,GAAG,CAE7C;AAEF,OAAK,MAAM,YAAY,KAAK,KAAK,UAAU,GAAG,YAAY;AACxD,OAAI,CAAC,EAAE,iBAAiB,SAAS,IAAI,CAAC,kBAAkB,SAAS,CAC/D;AACF,OAAI,EAAE,kBAAkB,SAAS,MAAM,EAAE;AAEvC,aAAS,MAAM,SAAS,KAAK,iBAAiB;AAC9C,kBAAc;UACT;AAEL,aAAS,QAAQ,EAAE,gBAAgB,CACjC,EAAE,cAAc,SAAS,MAAsB,EAC/C,iBACD,CAAC;AACF,kBAAc;;;IAIrB,CAAC;AACF,QAAO;;AAGT,SAAS,kBAAkB,MAAwB;AACjD,QACE,EAAE,aAAa,KAAK,KAAK,EAAE,MAAM,WAAW,CAAC,IAC7C,EAAE,gBAAgB,KAAK,KAAK,EAAE,OAAO,WAAW,CAAC"}