gtx-cli 2.6.31 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/CHANGELOG.md +4 -1261
  2. package/README.md +12 -3
  3. package/dist/bin/bin-entry.js +2 -1
  4. package/dist/config/generateSettings.d.ts +1 -9
  5. package/dist/config/generateSettings.js +1 -214
  6. package/dist/config/resolveConfig.d.ts +1 -4
  7. package/dist/config/resolveConfig.js +1 -33
  8. package/dist/fs/config/setupConfig.d.ts +1 -17
  9. package/dist/fs/config/setupConfig.js +1 -50
  10. package/dist/fs/matchFiles.d.ts +1 -1
  11. package/dist/fs/matchFiles.js +1 -8
  12. package/dist/functions.d.ts +1 -7
  13. package/dist/functions.js +1 -6
  14. package/dist/index.d.ts +1 -4
  15. package/dist/index.js +1 -27
  16. package/dist/main.js +2 -2
  17. package/dist/next/parse/handleInitGT.d.ts +1 -7
  18. package/dist/next/parse/handleInitGT.js +1 -157
  19. package/dist/next/parse/wrapContent.d.ts +1 -12
  20. package/dist/next/parse/wrapContent.js +1 -164
  21. package/dist/react/parse/wrapContent.d.ts +1 -12
  22. package/dist/react/parse/wrapContent.js +1 -162
  23. package/dist/types/index.d.ts +1 -243
  24. package/dist/types/index.js +1 -1
  25. package/dist/utils/installPackage.d.ts +1 -3
  26. package/dist/utils/installPackage.js +1 -77
  27. package/dist/utils/packageInfo.d.ts +1 -3
  28. package/dist/utils/packageInfo.js +1 -17
  29. package/dist/utils/packageJson.d.ts +1 -6
  30. package/dist/utils/packageJson.js +1 -68
  31. package/dist/utils/packageManager.d.ts +1 -28
  32. package/dist/utils/packageManager.js +1 -269
  33. package/package.json +11 -97
  34. package/dist/api/collectUserEditDiffs.d.ts +0 -9
  35. package/dist/api/collectUserEditDiffs.js +0 -159
  36. package/dist/api/downloadFileBatch.d.ts +0 -23
  37. package/dist/api/downloadFileBatch.js +0 -190
  38. package/dist/api/saveLocalEdits.d.ts +0 -6
  39. package/dist/api/saveLocalEdits.js +0 -38
  40. package/dist/cli/base.d.ts +0 -59
  41. package/dist/cli/base.js +0 -529
  42. package/dist/cli/commands/download.d.ts +0 -8
  43. package/dist/cli/commands/download.js +0 -51
  44. package/dist/cli/commands/enqueue.d.ts +0 -9
  45. package/dist/cli/commands/enqueue.js +0 -27
  46. package/dist/cli/commands/setupProject.d.ts +0 -7
  47. package/dist/cli/commands/setupProject.js +0 -37
  48. package/dist/cli/commands/stage.d.ts +0 -9
  49. package/dist/cli/commands/stage.js +0 -59
  50. package/dist/cli/commands/translate.d.ts +0 -7
  51. package/dist/cli/commands/translate.js +0 -70
  52. package/dist/cli/commands/upload.d.ts +0 -13
  53. package/dist/cli/commands/upload.js +0 -142
  54. package/dist/cli/commands/utils/validation.d.ts +0 -13
  55. package/dist/cli/commands/utils/validation.js +0 -38
  56. package/dist/cli/flags.d.ts +0 -15
  57. package/dist/cli/flags.js +0 -70
  58. package/dist/cli/inline.d.ts +0 -17
  59. package/dist/cli/inline.js +0 -135
  60. package/dist/cli/next.d.ts +0 -10
  61. package/dist/cli/next.js +0 -12
  62. package/dist/cli/node.d.ts +0 -10
  63. package/dist/cli/node.js +0 -9
  64. package/dist/cli/react.d.ts +0 -12
  65. package/dist/cli/react.js +0 -72
  66. package/dist/config/optionPresets.d.ts +0 -3
  67. package/dist/config/optionPresets.js +0 -65
  68. package/dist/config/utils.d.ts +0 -2
  69. package/dist/config/utils.js +0 -4
  70. package/dist/config/validateSettings.d.ts +0 -3
  71. package/dist/config/validateSettings.js +0 -32
  72. package/dist/console/colors.d.ts +0 -6
  73. package/dist/console/colors.js +0 -19
  74. package/dist/console/displayTranslateSummary.d.ts +0 -1
  75. package/dist/console/displayTranslateSummary.js +0 -42
  76. package/dist/console/formatting.d.ts +0 -1
  77. package/dist/console/formatting.js +0 -7
  78. package/dist/console/index.d.ts +0 -34
  79. package/dist/console/index.js +0 -46
  80. package/dist/console/logger.d.ts +0 -35
  81. package/dist/console/logger.js +0 -250
  82. package/dist/console/logging.d.ts +0 -52
  83. package/dist/console/logging.js +0 -175
  84. package/dist/formats/files/aggregateFiles.d.ts +0 -4
  85. package/dist/formats/files/aggregateFiles.js +0 -156
  86. package/dist/formats/files/collectFiles.d.ts +0 -6
  87. package/dist/formats/files/collectFiles.js +0 -49
  88. package/dist/formats/files/convertToFileTranslationData.d.ts +0 -15
  89. package/dist/formats/files/convertToFileTranslationData.js +0 -21
  90. package/dist/formats/files/fileMapping.d.ts +0 -11
  91. package/dist/formats/files/fileMapping.js +0 -115
  92. package/dist/formats/files/preprocess/mdx.d.ts +0 -6
  93. package/dist/formats/files/preprocess/mdx.js +0 -14
  94. package/dist/formats/files/preprocess/mintlify.d.ts +0 -5
  95. package/dist/formats/files/preprocess/mintlify.js +0 -15
  96. package/dist/formats/files/preprocessContent.d.ts +0 -8
  97. package/dist/formats/files/preprocessContent.js +0 -23
  98. package/dist/formats/files/save.d.ts +0 -5
  99. package/dist/formats/files/save.js +0 -17
  100. package/dist/formats/files/supportedFiles.d.ts +0 -11
  101. package/dist/formats/files/supportedFiles.js +0 -20
  102. package/dist/formats/json/extractJson.d.ts +0 -15
  103. package/dist/formats/json/extractJson.js +0 -101
  104. package/dist/formats/json/flattenJson.d.ts +0 -14
  105. package/dist/formats/json/flattenJson.js +0 -64
  106. package/dist/formats/json/mergeJson.d.ts +0 -13
  107. package/dist/formats/json/mergeJson.js +0 -367
  108. package/dist/formats/json/parseJson.d.ts +0 -2
  109. package/dist/formats/json/parseJson.js +0 -109
  110. package/dist/formats/json/utils.d.ts +0 -47
  111. package/dist/formats/json/utils.js +0 -150
  112. package/dist/formats/utils.d.ts +0 -2
  113. package/dist/formats/utils.js +0 -24
  114. package/dist/formats/yaml/mergeYaml.d.ts +0 -5
  115. package/dist/formats/yaml/mergeYaml.js +0 -61
  116. package/dist/formats/yaml/parseYaml.d.ts +0 -5
  117. package/dist/formats/yaml/parseYaml.js +0 -24
  118. package/dist/formats/yaml/utils.d.ts +0 -2
  119. package/dist/formats/yaml/utils.js +0 -23
  120. package/dist/fs/clearLocaleDirs.d.ts +0 -8
  121. package/dist/fs/clearLocaleDirs.js +0 -126
  122. package/dist/fs/config/downloadedVersions.d.ts +0 -21
  123. package/dist/fs/config/downloadedVersions.js +0 -50
  124. package/dist/fs/config/loadConfig.d.ts +0 -1
  125. package/dist/fs/config/loadConfig.js +0 -9
  126. package/dist/fs/config/parseFilesConfig.d.ts +0 -27
  127. package/dist/fs/config/parseFilesConfig.js +0 -150
  128. package/dist/fs/config/updateConfig.d.ts +0 -21
  129. package/dist/fs/config/updateConfig.js +0 -57
  130. package/dist/fs/config/updateVersions.d.ts +0 -11
  131. package/dist/fs/config/updateVersions.js +0 -30
  132. package/dist/fs/copyFile.d.ts +0 -7
  133. package/dist/fs/copyFile.js +0 -39
  134. package/dist/fs/createLoadTranslationsFile.d.ts +0 -1
  135. package/dist/fs/createLoadTranslationsFile.js +0 -49
  136. package/dist/fs/determineFramework.d.ts +0 -5
  137. package/dist/fs/determineFramework.js +0 -53
  138. package/dist/fs/findFilepath.d.ts +0 -36
  139. package/dist/fs/findFilepath.js +0 -90
  140. package/dist/fs/index.d.ts +0 -1
  141. package/dist/fs/index.js +0 -1
  142. package/dist/fs/loadJSON.d.ts +0 -6
  143. package/dist/fs/loadJSON.js +0 -17
  144. package/dist/fs/saveJSON.d.ts +0 -1
  145. package/dist/fs/saveJSON.js +0 -7
  146. package/dist/fs/utils.d.ts +0 -1
  147. package/dist/fs/utils.js +0 -16
  148. package/dist/generated/version.d.ts +0 -1
  149. package/dist/generated/version.js +0 -2
  150. package/dist/git/branches.d.ts +0 -7
  151. package/dist/git/branches.js +0 -88
  152. package/dist/hooks/postProcess.d.ts +0 -4
  153. package/dist/hooks/postProcess.js +0 -110
  154. package/dist/locadex/setupFlow.d.ts +0 -2
  155. package/dist/locadex/setupFlow.js +0 -9
  156. package/dist/next/config/parseNextConfig.d.ts +0 -10
  157. package/dist/next/config/parseNextConfig.js +0 -53
  158. package/dist/next/jsx/utils.d.ts +0 -7
  159. package/dist/next/jsx/utils.js +0 -42
  160. package/dist/react/config/createESBuildConfig.d.ts +0 -2
  161. package/dist/react/config/createESBuildConfig.js +0 -119
  162. package/dist/react/jsx/evaluateJsx.d.ts +0 -24
  163. package/dist/react/jsx/evaluateJsx.js +0 -123
  164. package/dist/react/jsx/utils/buildImportMap.d.ts +0 -9
  165. package/dist/react/jsx/utils/buildImportMap.js +0 -30
  166. package/dist/react/jsx/utils/constants.d.ts +0 -15
  167. package/dist/react/jsx/utils/constants.js +0 -49
  168. package/dist/react/jsx/utils/getCalleeNameFromExpression.d.ts +0 -9
  169. package/dist/react/jsx/utils/getCalleeNameFromExpression.js +0 -32
  170. package/dist/react/jsx/utils/getPathsAndAliases.d.ts +0 -21
  171. package/dist/react/jsx/utils/getPathsAndAliases.js +0 -91
  172. package/dist/react/jsx/utils/isNumberLiteral.d.ts +0 -7
  173. package/dist/react/jsx/utils/isNumberLiteral.js +0 -13
  174. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.d.ts +0 -9
  175. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +0 -138
  176. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.d.ts +0 -6
  177. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +0 -197
  178. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +0 -13
  179. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +0 -42
  180. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.d.ts +0 -5
  181. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +0 -69
  182. package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +0 -33
  183. package/dist/react/jsx/utils/jsxParsing/parseJsx.js +0 -918
  184. package/dist/react/jsx/utils/jsxParsing/parseTProps.d.ts +0 -8
  185. package/dist/react/jsx/utils/jsxParsing/parseTProps.js +0 -65
  186. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.d.ts +0 -2
  187. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +0 -61
  188. package/dist/react/jsx/utils/jsxParsing/types.d.ts +0 -48
  189. package/dist/react/jsx/utils/jsxParsing/types.js +0 -34
  190. package/dist/react/jsx/utils/mapAttributeName.d.ts +0 -11
  191. package/dist/react/jsx/utils/mapAttributeName.js +0 -12
  192. package/dist/react/jsx/utils/parseAst.d.ts +0 -31
  193. package/dist/react/jsx/utils/parseAst.js +0 -278
  194. package/dist/react/jsx/utils/parseDeclareStatic.d.ts +0 -15
  195. package/dist/react/jsx/utils/parseDeclareStatic.js +0 -540
  196. package/dist/react/jsx/utils/parseString.d.ts +0 -25
  197. package/dist/react/jsx/utils/parseString.js +0 -540
  198. package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -30
  199. package/dist/react/jsx/utils/parseStringFunction.js +0 -348
  200. package/dist/react/jsx/utils/resolveImportPath.d.ts +0 -11
  201. package/dist/react/jsx/utils/resolveImportPath.js +0 -111
  202. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.d.ts +0 -29
  203. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +0 -86
  204. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.d.ts +0 -14
  205. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +0 -24
  206. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.d.ts +0 -19
  207. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +0 -31
  208. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.d.ts +0 -22
  209. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.js +0 -51
  210. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.d.ts +0 -18
  211. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +0 -39
  212. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.d.ts +0 -24
  213. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +0 -68
  214. package/dist/react/jsx/utils/stringParsing/types.d.ts +0 -41
  215. package/dist/react/jsx/utils/stringParsing/types.js +0 -1
  216. package/dist/react/jsx/utils/types.d.ts +0 -14
  217. package/dist/react/jsx/utils/types.js +0 -1
  218. package/dist/react/jsx/utils/validateStringFunction.d.ts +0 -7
  219. package/dist/react/jsx/utils/validateStringFunction.js +0 -31
  220. package/dist/react/jsx/wrapJsx.d.ts +0 -51
  221. package/dist/react/jsx/wrapJsx.js +0 -387
  222. package/dist/react/parse/addVitePlugin/index.d.ts +0 -22
  223. package/dist/react/parse/addVitePlugin/index.js +0 -41
  224. package/dist/react/parse/addVitePlugin/installCompiler.d.ts +0 -8
  225. package/dist/react/parse/addVitePlugin/installCompiler.js +0 -22
  226. package/dist/react/parse/addVitePlugin/updateViteConfig.d.ts +0 -19
  227. package/dist/react/parse/addVitePlugin/updateViteConfig.js +0 -120
  228. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.d.ts +0 -9
  229. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +0 -34
  230. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.d.ts +0 -11
  231. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +0 -48
  232. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.d.ts +0 -15
  233. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +0 -113
  234. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.d.ts +0 -12
  235. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +0 -32
  236. package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
  237. package/dist/react/parse/createDictionaryUpdates.js +0 -187
  238. package/dist/react/parse/createInlineUpdates.d.ts +0 -13
  239. package/dist/react/parse/createInlineUpdates.js +0 -161
  240. package/dist/react/utils/flattenDictionary.d.ts +0 -20
  241. package/dist/react/utils/flattenDictionary.js +0 -75
  242. package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
  243. package/dist/react/utils/getEntryAndMetadata.js +0 -11
  244. package/dist/react/utils/getVariableName.d.ts +0 -25
  245. package/dist/react/utils/getVariableName.js +0 -37
  246. package/dist/setup/agentInstructions.d.ts +0 -24
  247. package/dist/setup/agentInstructions.js +0 -138
  248. package/dist/setup/detectFramework.d.ts +0 -31
  249. package/dist/setup/detectFramework.js +0 -106
  250. package/dist/setup/frameworkUtils.d.ts +0 -3
  251. package/dist/setup/frameworkUtils.js +0 -30
  252. package/dist/setup/instructions/base.md +0 -29
  253. package/dist/setup/instructions/gt-next.md +0 -107
  254. package/dist/setup/instructions/gt-react.md +0 -98
  255. package/dist/setup/userInput.d.ts +0 -4
  256. package/dist/setup/userInput.js +0 -32
  257. package/dist/setup/wizard.d.ts +0 -3
  258. package/dist/setup/wizard.js +0 -147
  259. package/dist/state/recentDownloads.d.ts +0 -12
  260. package/dist/state/recentDownloads.js +0 -18
  261. package/dist/state/translateWarnings.d.ts +0 -10
  262. package/dist/state/translateWarnings.js +0 -13
  263. package/dist/translation/parse.d.ts +0 -17
  264. package/dist/translation/parse.js +0 -77
  265. package/dist/translation/stage.d.ts +0 -3
  266. package/dist/translation/stage.js +0 -44
  267. package/dist/translation/validate.d.ts +0 -14
  268. package/dist/translation/validate.js +0 -100
  269. package/dist/types/branch.d.ts +0 -14
  270. package/dist/types/branch.js +0 -1
  271. package/dist/types/data/json.d.ts +0 -6
  272. package/dist/types/data/json.js +0 -1
  273. package/dist/types/data.d.ts +0 -37
  274. package/dist/types/data.js +0 -1
  275. package/dist/types/files.d.ts +0 -8
  276. package/dist/types/files.js +0 -1
  277. package/dist/types/libraries.d.ts +0 -31
  278. package/dist/types/libraries.js +0 -72
  279. package/dist/types/parsing.d.ts +0 -3
  280. package/dist/types/parsing.js +0 -1
  281. package/dist/utils/addExplicitAnchorIds.d.ts +0 -24
  282. package/dist/utils/addExplicitAnchorIds.js +0 -416
  283. package/dist/utils/constants.d.ts +0 -5
  284. package/dist/utils/constants.js +0 -6
  285. package/dist/utils/credentials.d.ts +0 -12
  286. package/dist/utils/credentials.js +0 -120
  287. package/dist/utils/flattenJsonFiles.d.ts +0 -2
  288. package/dist/utils/flattenJsonFiles.js +0 -36
  289. package/dist/utils/gitDiff.d.ts +0 -8
  290. package/dist/utils/gitDiff.js +0 -34
  291. package/dist/utils/gt.d.ts +0 -2
  292. package/dist/utils/gt.js +0 -2
  293. package/dist/utils/hash.d.ts +0 -6
  294. package/dist/utils/hash.js +0 -11
  295. package/dist/utils/headers.d.ts +0 -1
  296. package/dist/utils/headers.js +0 -14
  297. package/dist/utils/localizeRelativeAssets.d.ts +0 -8
  298. package/dist/utils/localizeRelativeAssets.js +0 -166
  299. package/dist/utils/localizeStaticImports.d.ts +0 -15
  300. package/dist/utils/localizeStaticImports.js +0 -397
  301. package/dist/utils/localizeStaticUrls.d.ts +0 -19
  302. package/dist/utils/localizeStaticUrls.js +0 -450
  303. package/dist/utils/mintlifyTitleFallback.d.ts +0 -6
  304. package/dist/utils/mintlifyTitleFallback.js +0 -80
  305. package/dist/utils/parse/needsCJS.d.ts +0 -20
  306. package/dist/utils/parse/needsCJS.js +0 -72
  307. package/dist/utils/persistPostprocessHashes.d.ts +0 -12
  308. package/dist/utils/persistPostprocessHashes.js +0 -39
  309. package/dist/utils/processAnchorIds.d.ts +0 -6
  310. package/dist/utils/processAnchorIds.js +0 -56
  311. package/dist/utils/processOpenApi.d.ts +0 -8
  312. package/dist/utils/processOpenApi.js +0 -651
  313. package/dist/utils/sanitizeFileContent.d.ts +0 -6
  314. package/dist/utils/sanitizeFileContent.js +0 -29
  315. package/dist/utils/sharedStaticAssets.d.ts +0 -9
  316. package/dist/utils/sharedStaticAssets.js +0 -384
  317. package/dist/utils/validateMdx.d.ts +0 -10
  318. package/dist/utils/validateMdx.js +0 -25
  319. package/dist/utils/wrapPlainUrls.d.ts +0 -8
  320. package/dist/utils/wrapPlainUrls.js +0 -72
  321. package/dist/workflows/download.d.ts +0 -32
  322. package/dist/workflows/download.js +0 -131
  323. package/dist/workflows/enqueue.d.ts +0 -17
  324. package/dist/workflows/enqueue.js +0 -59
  325. package/dist/workflows/setupProject.d.ts +0 -13
  326. package/dist/workflows/setupProject.js +0 -48
  327. package/dist/workflows/stage.d.ts +0 -18
  328. package/dist/workflows/stage.js +0 -59
  329. package/dist/workflows/steps/BranchStep.d.ts +0 -13
  330. package/dist/workflows/steps/BranchStep.js +0 -161
  331. package/dist/workflows/steps/DownloadStep.d.ts +0 -19
  332. package/dist/workflows/steps/DownloadStep.js +0 -131
  333. package/dist/workflows/steps/EnqueueStep.d.ts +0 -15
  334. package/dist/workflows/steps/EnqueueStep.js +0 -33
  335. package/dist/workflows/steps/PollJobsStep.d.ts +0 -31
  336. package/dist/workflows/steps/PollJobsStep.js +0 -288
  337. package/dist/workflows/steps/SetupStep.d.ts +0 -16
  338. package/dist/workflows/steps/SetupStep.js +0 -72
  339. package/dist/workflows/steps/UploadSourcesStep.d.ts +0 -27
  340. package/dist/workflows/steps/UploadSourcesStep.js +0 -131
  341. package/dist/workflows/steps/UploadTranslationsStep.d.ts +0 -22
  342. package/dist/workflows/steps/UploadTranslationsStep.js +0 -71
  343. package/dist/workflows/steps/UserEditDiffsStep.d.ts +0 -11
  344. package/dist/workflows/steps/UserEditDiffsStep.js +0 -30
  345. package/dist/workflows/steps/WorkflowStep.d.ts +0 -4
  346. package/dist/workflows/steps/WorkflowStep.js +0 -2
  347. package/dist/workflows/upload.d.ts +0 -15
  348. package/dist/workflows/upload.js +0 -47
@@ -1,540 +0,0 @@
1
- import * as t from '@babel/types';
2
- import { buildImportMap } from './buildImportMap.js';
3
- import { resolveImportPath } from './resolveImportPath.js';
4
- import { parse } from '@babel/parser';
5
- import fs from 'node:fs';
6
- import { warnDeclareStaticNoResultsSync, warnFunctionNotFoundSync, warnInvalidDeclareVarNameSync, } from '../../../console/index.js';
7
- import traverseModule from '@babel/traverse';
8
- import { DECLARE_VAR_FUNCTION } from '../../jsx/utils/constants.js';
9
- import { GT_LIBRARIES } from '../../../types/libraries.js';
10
- import { declareVar } from 'generaltranslation/internal';
11
- import { isStaticExpression } from '../evaluateJsx.js';
12
- import generateModule from '@babel/generator';
13
- // Handle CommonJS/ESM interop
14
- const traverse = traverseModule.default || traverseModule;
15
- const generate = generateModule.default || generateModule;
16
- /**
17
- * Cache for resolved import paths to avoid redundant I/O operations.
18
- */
19
- const resolveImportPathCache = new Map();
20
- /**
21
- * Cache for processed functions to avoid re-parsing the same files.
22
- */
23
- const processFunctionCache = new Map();
24
- /**
25
- * Processes a string expression node and resolves any function calls within it
26
- * This handles cases like:
27
- * - "hello" (string literal)
28
- * - "hello" + world() (binary expression with function call)
29
- * - Math.random() > 0.5 ? "day" : "night" (conditional expression)
30
- * - greeting() (function call that returns string or conditional)
31
- *
32
- * @param node - The AST node to process
33
- * @param tPath - NodePath for scope resolution
34
- * @param file - Current file path
35
- * @param parsingOptions - Parsing configuration
36
- * @param warnings - Set to collect warning messages
37
- * @returns Node | null
38
- */
39
- export function parseStringExpression(node, tPath, file, parsingOptions, warnings = new Set()) {
40
- // Handle string literals
41
- if (t.isStringLiteral(node)) {
42
- return { type: 'text', text: node.value };
43
- }
44
- // Handle numeric literals
45
- if (t.isNumericLiteral(node)) {
46
- return { type: 'text', text: String(node.value) };
47
- }
48
- // Handle boolean literals
49
- if (t.isBooleanLiteral(node)) {
50
- return { type: 'text', text: String(node.value) };
51
- }
52
- // Handle null literal
53
- if (t.isNullLiteral(node)) {
54
- return { type: 'text', text: 'null' };
55
- }
56
- // Handle template literals
57
- if (t.isTemplateLiteral(node)) {
58
- const parts = [];
59
- for (let index = 0; index < node.quasis.length; index++) {
60
- const quasi = node.quasis[index];
61
- const text = quasi.value.cooked ?? quasi.value.raw ?? '';
62
- if (text) {
63
- parts.push({ type: 'text', text });
64
- }
65
- const exprNode = node.expressions[index];
66
- if (exprNode && t.isExpression(exprNode)) {
67
- const result = parseStringExpression(exprNode, tPath, file, parsingOptions, warnings);
68
- if (result === null) {
69
- return null;
70
- }
71
- parts.push(result);
72
- }
73
- }
74
- if (parts.length === 0) {
75
- return { type: 'text', text: '' };
76
- }
77
- if (parts.length === 1) {
78
- return parts[0];
79
- }
80
- return { type: 'sequence', nodes: parts };
81
- }
82
- // Handle binary expressions (e.g., "hello" + world())
83
- if (t.isBinaryExpression(node) && node.operator === '+') {
84
- if (!t.isExpression(node.left) || !t.isExpression(node.right)) {
85
- return null;
86
- }
87
- const leftResult = parseStringExpression(node.left, tPath, file, parsingOptions, warnings);
88
- const rightResult = parseStringExpression(node.right, tPath, file, parsingOptions, warnings);
89
- if (leftResult === null || rightResult === null) {
90
- return null;
91
- }
92
- return { type: 'sequence', nodes: [leftResult, rightResult] };
93
- }
94
- // Handle conditional expressions (e.g., cond ? "day" : "night")
95
- if (t.isConditionalExpression(node)) {
96
- if (!t.isExpression(node.consequent) || !t.isExpression(node.alternate)) {
97
- return null;
98
- }
99
- const consequentResult = parseStringExpression(node.consequent, tPath, file, parsingOptions, warnings);
100
- const alternateResult = parseStringExpression(node.alternate, tPath, file, parsingOptions, warnings);
101
- if (consequentResult === null || alternateResult === null) {
102
- return null;
103
- }
104
- // Create a choice node with both branches
105
- return {
106
- type: 'choice',
107
- nodes: [consequentResult, alternateResult],
108
- };
109
- }
110
- // Handle variable references (e.g., result)
111
- if (t.isIdentifier(node)) {
112
- const binding = tPath.scope.getBinding(node.name);
113
- if (!binding) {
114
- // Variable not found in scope
115
- return null;
116
- }
117
- // Check if it's a const/let/var with an initializer
118
- if (binding.path.isVariableDeclarator() && binding.path.node.init) {
119
- const init = binding.path.node.init;
120
- if (t.isExpression(init)) {
121
- // Recursively resolve the initializer
122
- return parseStringExpression(init, binding.path, file, parsingOptions, warnings);
123
- }
124
- }
125
- // Not a resolvable variable
126
- return null;
127
- }
128
- // Handle function calls (e.g., getName())
129
- if (t.isCallExpression(node) && t.isIdentifier(node.callee)) {
130
- const functionName = node.callee.name;
131
- const calleeBinding = tPath.scope.getBinding(functionName);
132
- if (!calleeBinding) {
133
- // Function not found in scope
134
- warnings.add(warnFunctionNotFoundSync(file, functionName, `${node.callee.loc?.start?.line}:${node.callee.loc?.start?.column}`));
135
- return null;
136
- }
137
- // Check if this is an imported function
138
- const programPath = tPath.scope.getProgramParent().path;
139
- const importedFunctionsMap = buildImportMap(programPath);
140
- if (importedFunctionsMap.has(functionName)) {
141
- // Function is imported - resolve cross-file
142
- let originalName;
143
- if (calleeBinding.path.isImportSpecifier()) {
144
- originalName = t.isIdentifier(calleeBinding.path.node.imported)
145
- ? calleeBinding.path.node.imported.name
146
- : calleeBinding.path.node.imported.value;
147
- }
148
- else if (calleeBinding.path.isImportDefaultSpecifier()) {
149
- originalName = calleeBinding.path.node.local.name;
150
- }
151
- else if (calleeBinding.path.isImportNamespaceSpecifier()) {
152
- originalName = calleeBinding.path.node.local.name;
153
- }
154
- const importPath = importedFunctionsMap.get(functionName);
155
- // Handle declareVar function
156
- if (originalName === DECLARE_VAR_FUNCTION &&
157
- GT_LIBRARIES.includes(importPath)) {
158
- // check for name field eg declareVar('test', { $name: 'test' })
159
- if (node.arguments.length > 1 &&
160
- t.isObjectExpression(node.arguments[1])) {
161
- const name = node.arguments[1].properties
162
- .filter((prop) => t.isObjectProperty(prop))
163
- .find((prop) => t.isIdentifier(prop.key) && prop.key.name === '$name')?.value;
164
- if (name) {
165
- if (!t.isExpression(name)) {
166
- warnings.add(warnInvalidDeclareVarNameSync(file, generate(name).code, `${node.arguments[1].loc?.start?.line}:${node.arguments[1].loc?.start?.column}`));
167
- return null;
168
- }
169
- const staticResult = isStaticExpression(name);
170
- if (!staticResult.isStatic) {
171
- warnings.add(warnInvalidDeclareVarNameSync(file, generate(name).code, `${node.arguments[1].loc?.start?.line}:${node.arguments[1].loc?.start?.column}`));
172
- return null;
173
- }
174
- return {
175
- type: 'text',
176
- text: declareVar('', { $name: staticResult.value }),
177
- };
178
- }
179
- }
180
- return {
181
- type: 'text',
182
- text: declareVar(''),
183
- };
184
- }
185
- const filePath = resolveImportPath(file, importPath, parsingOptions, resolveImportPathCache);
186
- if (filePath && originalName) {
187
- return resolveFunctionInFile(filePath, originalName, parsingOptions, warnings);
188
- }
189
- return null;
190
- }
191
- // Resolve the function locally and get its return values
192
- return resolveFunctionCall(calleeBinding, tPath, file, parsingOptions, warnings);
193
- }
194
- // Handle parenthesized expressions
195
- if (t.isParenthesizedExpression(node)) {
196
- return parseStringExpression(node.expression, tPath, file, parsingOptions, warnings);
197
- }
198
- // Handle unary expressions (e.g., -123)
199
- if (t.isUnaryExpression(node)) {
200
- let operator = '';
201
- if (node.operator === '-') {
202
- operator = node.operator;
203
- }
204
- if (t.isNumericLiteral(node.argument)) {
205
- if (node.argument.value === 0) {
206
- return { type: 'text', text: '0' };
207
- }
208
- else {
209
- return {
210
- type: 'text',
211
- text: operator + node.argument.value.toString(),
212
- };
213
- }
214
- }
215
- return null;
216
- }
217
- // Unsupported expression type
218
- return null;
219
- }
220
- /**
221
- * Resolves a function call by traversing its body and collecting return values
222
- */
223
- function resolveFunctionCall(calleeBinding, tPath, file, parsingOptions, warnings) {
224
- if (!calleeBinding) {
225
- return null;
226
- }
227
- const bindingPath = calleeBinding.path;
228
- const branches = [];
229
- // Handle function declarations: function time() { return "day"; }
230
- if (bindingPath.isFunctionDeclaration()) {
231
- bindingPath.traverse({
232
- // Don't skip nested functions - let parseStringExpression handle function calls
233
- ReturnStatement(returnPath) {
234
- // Only process return statements that are direct children of this function
235
- // Skip return statements from nested functions (they'll be handled when those functions are called)
236
- const parentFunction = returnPath.getFunctionParent();
237
- if (parentFunction?.node !== bindingPath.node) {
238
- // This return belongs to a nested function, skip it
239
- return;
240
- }
241
- const returnArg = returnPath.node.argument;
242
- if (!returnArg || !t.isExpression(returnArg)) {
243
- return;
244
- }
245
- const returnResult = parseStringExpression(returnArg, returnPath, file, parsingOptions, warnings);
246
- if (returnResult !== null) {
247
- branches.push(returnResult);
248
- }
249
- },
250
- });
251
- }
252
- // Handle arrow functions: const time = () => "day"
253
- else if (bindingPath.isVariableDeclarator()) {
254
- const init = bindingPath.get('init');
255
- if (!init.isArrowFunctionExpression()) {
256
- return null;
257
- }
258
- const body = init.get('body');
259
- // Handle expression body: () => "day"
260
- if (body.isExpression()) {
261
- const bodyResult = parseStringExpression(body.node, body, file, parsingOptions, warnings);
262
- if (bodyResult !== null) {
263
- branches.push(bodyResult);
264
- }
265
- }
266
- // Handle block body: () => { return "day"; }
267
- else if (body.isBlockStatement()) {
268
- const arrowFunction = init.node;
269
- body.traverse({
270
- // Don't skip nested functions - let parseStringExpression handle function calls
271
- ReturnStatement(returnPath) {
272
- // Only process return statements that are direct children of this function
273
- // Skip return statements from nested functions (they'll be handled when those functions are called)
274
- const parentFunction = returnPath.getFunctionParent();
275
- if (parentFunction?.node !== arrowFunction) {
276
- // This return belongs to a nested function, skip it
277
- return;
278
- }
279
- const returnArg = returnPath.node.argument;
280
- if (!returnArg || !t.isExpression(returnArg)) {
281
- return;
282
- }
283
- const returnResult = parseStringExpression(returnArg, returnPath, file, parsingOptions, warnings);
284
- if (returnResult !== null) {
285
- branches.push(returnResult);
286
- }
287
- },
288
- });
289
- }
290
- }
291
- if (branches.length === 0) {
292
- return null;
293
- }
294
- if (branches.length === 1) {
295
- return branches[0];
296
- }
297
- return { type: 'choice', nodes: branches };
298
- }
299
- /**
300
- * Resolves a function definition in an external file
301
- */
302
- function resolveFunctionInFile(filePath, functionName, parsingOptions, warnings) {
303
- // Check cache first
304
- const cacheKey = `${filePath}::${functionName}`;
305
- if (processFunctionCache.has(cacheKey)) {
306
- return processFunctionCache.get(cacheKey) ?? null;
307
- }
308
- let result = null;
309
- try {
310
- const code = fs.readFileSync(filePath, 'utf8');
311
- const ast = parse(code, {
312
- sourceType: 'module',
313
- plugins: ['jsx', 'typescript'],
314
- });
315
- traverse(ast, {
316
- // Handle re-exports: export * from './utils1'
317
- ExportAllDeclaration(path) {
318
- // Only follow re-exports if we haven't found the function yet
319
- if (result !== null)
320
- return;
321
- if (t.isStringLiteral(path.node.source)) {
322
- const reexportPath = path.node.source.value;
323
- const resolvedPath = resolveImportPath(filePath, reexportPath, parsingOptions, resolveImportPathCache);
324
- if (resolvedPath) {
325
- // Recursively resolve in the re-exported file
326
- const reexportResult = resolveFunctionInFile(resolvedPath, functionName, parsingOptions, warnings);
327
- if (reexportResult) {
328
- result = reexportResult;
329
- }
330
- }
331
- }
332
- },
333
- // Handle named re-exports: export { fn1 } from './utils'
334
- ExportNamedDeclaration(path) {
335
- // Only follow re-exports if we haven't found the function yet
336
- if (result !== null)
337
- return;
338
- // Check if this is a re-export with a source
339
- if (path.node.source && t.isStringLiteral(path.node.source)) {
340
- // Check if any of the exported specifiers match our function name
341
- const hasMatchingExport = path.node.specifiers.some((spec) => {
342
- if (t.isExportSpecifier(spec)) {
343
- const exportedName = t.isIdentifier(spec.exported)
344
- ? spec.exported.name
345
- : spec.exported.value;
346
- return exportedName === functionName;
347
- }
348
- return false;
349
- });
350
- if (hasMatchingExport) {
351
- const reexportPath = path.node.source.value;
352
- const resolvedPath = resolveImportPath(filePath, reexportPath, parsingOptions, resolveImportPathCache);
353
- if (resolvedPath) {
354
- // Find the original name in case it was renamed
355
- const specifier = path.node.specifiers.find((spec) => {
356
- if (t.isExportSpecifier(spec)) {
357
- const exportedName = t.isIdentifier(spec.exported)
358
- ? spec.exported.name
359
- : spec.exported.value;
360
- return exportedName === functionName;
361
- }
362
- return false;
363
- });
364
- let originalName = functionName;
365
- if (specifier &&
366
- t.isExportSpecifier(specifier) &&
367
- t.isIdentifier(specifier.local)) {
368
- originalName = specifier.local.name;
369
- }
370
- // Recursively resolve in the re-exported file
371
- const reexportResult = resolveFunctionInFile(resolvedPath, originalName, parsingOptions, warnings);
372
- if (reexportResult) {
373
- result = reexportResult;
374
- }
375
- }
376
- }
377
- }
378
- },
379
- // Handle function declarations: function interjection() { ... }
380
- FunctionDeclaration(path) {
381
- if (path.node.id?.name === functionName && result === null) {
382
- const branches = [];
383
- path.traverse({
384
- Function(innerPath) {
385
- // Skip nested functions
386
- innerPath.skip();
387
- },
388
- ReturnStatement(returnPath) {
389
- if (!t.isReturnStatement(returnPath.node)) {
390
- return;
391
- }
392
- const returnArg = returnPath.node.argument;
393
- if (!returnArg || !t.isExpression(returnArg)) {
394
- return;
395
- }
396
- const returnResult = parseStringExpression(returnArg, returnPath, filePath, parsingOptions, warnings);
397
- if (returnResult !== null) {
398
- branches.push(returnResult);
399
- }
400
- },
401
- });
402
- if (branches.length === 1) {
403
- result = branches[0];
404
- }
405
- else if (branches.length > 1) {
406
- result = { type: 'choice', nodes: branches };
407
- }
408
- }
409
- },
410
- // Handle variable declarations: const interjection = () => { ... }
411
- VariableDeclarator(path) {
412
- if (t.isIdentifier(path.node.id) &&
413
- path.node.id.name === functionName &&
414
- path.node.init &&
415
- (t.isArrowFunctionExpression(path.node.init) ||
416
- t.isFunctionExpression(path.node.init)) &&
417
- result === null) {
418
- const init = path.get('init');
419
- if (!init.isArrowFunctionExpression() &&
420
- !init.isFunctionExpression()) {
421
- return;
422
- }
423
- const bodyPath = init.get('body');
424
- const branches = [];
425
- // Handle expression body: () => "day"
426
- if (!Array.isArray(bodyPath) && t.isExpression(bodyPath.node)) {
427
- const bodyResult = parseStringExpression(bodyPath.node, bodyPath, filePath, parsingOptions, warnings);
428
- if (bodyResult !== null) {
429
- branches.push(bodyResult);
430
- }
431
- }
432
- // Handle block body: () => { return "day"; }
433
- else if (!Array.isArray(bodyPath) &&
434
- t.isBlockStatement(bodyPath.node)) {
435
- const arrowFunction = init.node;
436
- bodyPath.traverse({
437
- Function(innerPath) {
438
- // Skip nested functions
439
- innerPath.skip();
440
- },
441
- ReturnStatement(returnPath) {
442
- // Only process return statements that are direct children of this function
443
- const parentFunction = returnPath.getFunctionParent();
444
- if (parentFunction?.node !== arrowFunction) {
445
- return;
446
- }
447
- if (!t.isReturnStatement(returnPath.node)) {
448
- return;
449
- }
450
- const returnArg = returnPath.node.argument;
451
- if (!returnArg || !t.isExpression(returnArg)) {
452
- return;
453
- }
454
- const returnResult = parseStringExpression(returnArg, returnPath, filePath, parsingOptions, warnings);
455
- if (returnResult !== null) {
456
- branches.push(returnResult);
457
- }
458
- },
459
- });
460
- }
461
- if (branches.length === 1) {
462
- result = branches[0];
463
- }
464
- else if (branches.length > 1) {
465
- result = { type: 'choice', nodes: branches };
466
- }
467
- }
468
- },
469
- });
470
- }
471
- catch (error) {
472
- // File read or parse error - return null
473
- warnings.add(warnDeclareStaticNoResultsSync(filePath, functionName, 'file read/parse error: ' + error));
474
- result = null;
475
- }
476
- // Cache the result
477
- processFunctionCache.set(cacheKey, result);
478
- return result;
479
- }
480
- /**
481
- * Converts a Node tree to an array of all possible string combinations
482
- * This is a helper function for compatibility with existing code
483
- */
484
- export function nodeToStrings(node) {
485
- if (node === null) {
486
- return [];
487
- }
488
- // Handle TextNode
489
- if (typeof node === 'object' &&
490
- node !== null &&
491
- 'type' in node &&
492
- node.type === 'text') {
493
- return [node.text];
494
- }
495
- // Handle SequenceNode - concatenate all parts
496
- if (typeof node === 'object' &&
497
- node !== null &&
498
- 'type' in node &&
499
- node.type === 'sequence') {
500
- const partResults = node.nodes.map((n) => nodeToStrings(n));
501
- return cartesianProduct(partResults);
502
- }
503
- // Handle ChoiceNode - flatten all branches
504
- if (typeof node === 'object' &&
505
- node !== null &&
506
- 'type' in node &&
507
- node.type === 'choice') {
508
- const allStrings = [];
509
- for (const branch of node.nodes) {
510
- allStrings.push(...nodeToStrings(branch));
511
- }
512
- return [...new Set(allStrings)]; // Deduplicate
513
- }
514
- return [];
515
- }
516
- /**
517
- * Creates cartesian product of string arrays and concatenates them
518
- * @example cartesianProduct([["Hello "], ["day", "night"]]) → ["Hello day", "Hello night"]
519
- */
520
- function cartesianProduct(arrays) {
521
- if (arrays.length === 0) {
522
- return [];
523
- }
524
- if (arrays.length === 1) {
525
- return arrays[0];
526
- }
527
- // Start with first array
528
- let result = arrays[0];
529
- // Combine with each subsequent array
530
- for (let i = 1; i < arrays.length; i++) {
531
- const newResult = [];
532
- for (const prev of result) {
533
- for (const curr of arrays[i]) {
534
- newResult.push(prev + curr);
535
- }
536
- }
537
- result = newResult;
538
- }
539
- return result;
540
- }
@@ -1,30 +0,0 @@
1
- import { NodePath, Scope } from '@babel/traverse';
2
- import type { ParsingConfig, ParsingOutput } from './stringParsing/types.js';
3
- /**
4
- * Clears all caches. Useful for testing or when file system changes.
5
- */
6
- export declare function clearParsingCaches(): void;
7
- /**
8
- * Recursively resolves variable assignments to find all aliases of a translation callback parameter.
9
- * Handles cases like: const t = translate; const a = translate; const b = a; const c = b;
10
- *
11
- * @param scope The scope to search within
12
- * @param variableName The variable name to resolve
13
- * @param visited Set to track already visited variables to prevent infinite loops
14
- * @returns Array of all variable names that reference the original translation callback
15
- */
16
- export declare function resolveVariableAliases(scope: Scope, variableName: string, visited?: Set<string>): string[];
17
- /**
18
- * Main entry point for parsing translation strings from useGT() and getGT() calls.
19
- *
20
- * Supports complex patterns including:
21
- * 1. Direct calls: const t = useGT(); t('hello');
22
- * 2. Translation callback prop drilling: const t = useGT(); getInfo(t); where getInfo uses t() internally
23
- * 3. Cross-file function calls: imported functions that receive the translation callback as a parameter
24
- *
25
- * Example flow:
26
- * - const t = useGT();
27
- * - const { home } = getInfo(t); // getInfo is imported from './constants'
28
- * - This will parse constants.ts to find translation calls within getInfo function
29
- */
30
- export declare function parseStrings(importName: string, originalName: string, path: NodePath, config: ParsingConfig, output: ParsingOutput): void;