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
@@ -1,443 +1,260 @@
1
- import * as fs from 'fs';
2
- import { createFileMapping } from '../formats/files/fileMapping.js';
3
- import micromatch from 'micromatch';
4
- import { unified } from 'unified';
5
- import remarkParse from 'remark-parse';
6
- import remarkMdx from 'remark-mdx';
7
- import remarkFrontmatter from 'remark-frontmatter';
8
- import remarkStringify from 'remark-stringify';
9
- import { visit } from 'unist-util-visit';
10
- import { escapeHtmlInTextNodes, normalizeCJKCharacters } from 'gt-remark';
1
+ import { createFileMapping } from "../formats/files/fileMapping.js";
2
+ import * as fs$1 from "fs";
3
+ import micromatch from "micromatch";
4
+ import { unified } from "unified";
5
+ import remarkParse from "remark-parse";
6
+ import remarkMdx from "remark-mdx";
7
+ import remarkFrontmatter from "remark-frontmatter";
8
+ import { visit } from "unist-util-visit";
9
+ import remarkStringify from "remark-stringify";
10
+ import { escapeHtmlInTextNodes, normalizeCJKCharacters } from "gt-remark";
11
+ //#region src/utils/localizeStaticUrls.ts
11
12
  const { isMatch } = micromatch;
12
13
  /**
13
- * Localizes static urls in content files.
14
- * Currently only supported for md and mdx files. (/docs/ -> /[locale]/docs/)
15
- * @param settings - The settings object containing the project configuration.
16
- * @returns void
17
- *
18
- * @TODO This is an experimental feature, and only works in very specific cases. This needs to be improved before
19
- * it can be enabled by default.
20
- *
21
- * Before this becomes a non-experimental feature, we need to:
22
- * - Support more file types
23
- * - Support more complex paths
24
- */
25
- export default async function localizeStaticUrls(settings, targetLocales, includeFiles) {
26
- if (!settings.files ||
27
- (Object.keys(settings.files.placeholderPaths).length === 1 &&
28
- settings.files.placeholderPaths.gt)) {
29
- return;
30
- }
31
- const { resolvedPaths: sourceFiles } = settings.files;
32
- // Use filtered locales if provided, otherwise use all locales
33
- const locales = targetLocales || settings.locales;
34
- const fileMapping = createFileMapping(sourceFiles, settings.files.placeholderPaths, settings.files.transformPaths ?? {}, settings.files.transformFormats ?? {}, settings.locales, // Always use all locales for mapping, filter later
35
- settings.defaultLocale);
36
- // Process all file types at once with a single call
37
- const processPromises = [];
38
- // First, process default locale files (from source files)
39
- // This is needed because they might not be in the fileMapping if they're not being translated
40
- // Only process default locale if it's in the target locales filter
41
- if (!fileMapping[settings.defaultLocale] &&
42
- locales.includes(settings.defaultLocale) &&
43
- !includeFiles // when filtering, skip default-locale pass
44
- ) {
45
- const defaultLocaleFiles = [];
46
- // Collect all .md and .mdx files from sourceFiles
47
- if (sourceFiles.md) {
48
- defaultLocaleFiles.push(...sourceFiles.md);
49
- }
50
- if (sourceFiles.mdx) {
51
- defaultLocaleFiles.push(...sourceFiles.mdx);
52
- }
53
- if (defaultLocaleFiles.length > 0) {
54
- const defaultPromise = Promise.all(defaultLocaleFiles.map(async (filePath) => {
55
- // Check if file exists before processing
56
- if (!fs.existsSync(filePath)) {
57
- return;
58
- }
59
- // Get file content
60
- const fileContent = await fs.promises.readFile(filePath, 'utf8');
61
- // Localize the file using default locale
62
- const result = localizeStaticUrlsForFile(fileContent, settings.defaultLocale, settings.defaultLocale, // Process as default locale
63
- settings.options?.experimentalHideDefaultLocale || false, settings.options?.docsUrlPattern, settings.options?.excludeStaticUrls, settings.options?.baseDomain);
64
- // Only write the file if there were changes
65
- if (result.hasChanges) {
66
- await fs.promises.writeFile(filePath, result.content);
67
- }
68
- }));
69
- processPromises.push(defaultPromise);
70
- }
71
- }
72
- // Then process all other locales from fileMapping
73
- const mappingPromises = Object.entries(fileMapping)
74
- .filter(([locale]) => locales.includes(locale)) // Filter by target locales
75
- .map(async ([locale, filesMap]) => {
76
- // Get all files that are md or mdx
77
- const targetFiles = Object.values(filesMap).filter((p) => (p.endsWith('.md') || p.endsWith('.mdx')) &&
78
- (!includeFiles || includeFiles.has(p)));
79
- // Replace the placeholder path with the target path
80
- await Promise.all(targetFiles.map(async (filePath) => {
81
- // Check if file exists before processing
82
- if (!fs.existsSync(filePath)) {
83
- return;
84
- }
85
- // Get file content
86
- const fileContent = await fs.promises.readFile(filePath, 'utf8');
87
- // Localize the file (handles both URLs and hrefs in single AST pass)
88
- const result = localizeStaticUrlsForFile(fileContent, settings.defaultLocale, locale, settings.options?.experimentalHideDefaultLocale || false, settings.options?.docsUrlPattern, settings.options?.excludeStaticUrls, settings.options?.baseDomain);
89
- // Only write the file if there were changes
90
- if (result.hasChanges) {
91
- await fs.promises.writeFile(filePath, result.content);
92
- }
93
- }));
94
- });
95
- processPromises.push(...mappingPromises);
96
- await Promise.all(processPromises);
14
+ * Localizes static urls in content files.
15
+ * Currently only supported for md and mdx files. (/docs/ -> /[locale]/docs/)
16
+ * @param settings - The settings object containing the project configuration.
17
+ * @returns void
18
+ *
19
+ * @TODO This is an experimental feature, and only works in very specific cases. This needs to be improved before
20
+ * it can be enabled by default.
21
+ *
22
+ * Before this becomes a non-experimental feature, we need to:
23
+ * - Support more file types
24
+ * - Support more complex paths
25
+ */
26
+ async function localizeStaticUrls(settings, targetLocales, includeFiles) {
27
+ if (!settings.files || Object.keys(settings.files.placeholderPaths).length === 1 && settings.files.placeholderPaths.gt) return;
28
+ const { resolvedPaths: sourceFiles } = settings.files;
29
+ const locales = targetLocales || settings.locales;
30
+ const fileMapping = createFileMapping(sourceFiles, settings.files.placeholderPaths, settings.files.transformPaths ?? {}, settings.files.transformFormats ?? {}, settings.locales, settings.defaultLocale);
31
+ const processPromises = [];
32
+ if (!fileMapping[settings.defaultLocale] && locales.includes(settings.defaultLocale) && !includeFiles) {
33
+ const defaultLocaleFiles = [];
34
+ if (sourceFiles.md) defaultLocaleFiles.push(...sourceFiles.md);
35
+ if (sourceFiles.mdx) defaultLocaleFiles.push(...sourceFiles.mdx);
36
+ if (defaultLocaleFiles.length > 0) {
37
+ const defaultPromise = Promise.all(defaultLocaleFiles.map(async (filePath) => {
38
+ if (!fs$1.existsSync(filePath)) return;
39
+ const result = localizeStaticUrlsForFile(await fs$1.promises.readFile(filePath, "utf8"), settings.defaultLocale, settings.defaultLocale, settings.options?.experimentalHideDefaultLocale || false, settings.options?.docsUrlPattern, settings.options?.excludeStaticUrls, settings.options?.baseDomain);
40
+ if (result.hasChanges) await fs$1.promises.writeFile(filePath, result.content);
41
+ }));
42
+ processPromises.push(defaultPromise);
43
+ }
44
+ }
45
+ const mappingPromises = Object.entries(fileMapping).filter(([locale]) => locales.includes(locale)).map(async ([locale, filesMap]) => {
46
+ const targetFiles = Object.values(filesMap).filter((p) => (p.endsWith(".md") || p.endsWith(".mdx")) && (!includeFiles || includeFiles.has(p)));
47
+ await Promise.all(targetFiles.map(async (filePath) => {
48
+ if (!fs$1.existsSync(filePath)) return;
49
+ const result = localizeStaticUrlsForFile(await fs$1.promises.readFile(filePath, "utf8"), settings.defaultLocale, locale, settings.options?.experimentalHideDefaultLocale || false, settings.options?.docsUrlPattern, settings.options?.excludeStaticUrls, settings.options?.baseDomain);
50
+ if (result.hasChanges) await fs$1.promises.writeFile(filePath, result.content);
51
+ }));
52
+ });
53
+ processPromises.push(...mappingPromises);
54
+ await Promise.all(processPromises);
97
55
  }
98
56
  /**
99
- * Determines if a URL should be processed based on pattern matching
100
- */
57
+ * Determines if a URL should be processed based on pattern matching
58
+ */
101
59
  function shouldProcessUrl(originalUrl, patternHead, targetLocale, defaultLocale, baseDomain) {
102
- // Check fragment-only URLs like "#id-name"
103
- if (/^\s*#/.test(originalUrl)) {
104
- return false;
105
- }
106
- const patternWithoutSlash = patternHead.replace(/\/$/, '');
107
- // Handle absolute URLs with baseDomain
108
- let urlToCheck = originalUrl;
109
- if (baseDomain && originalUrl.startsWith(baseDomain)) {
110
- urlToCheck = originalUrl.substring(baseDomain.length);
111
- }
112
- if (targetLocale === defaultLocale) {
113
- // For default locale processing, check if URL contains the pattern
114
- return urlToCheck.includes(patternWithoutSlash);
115
- }
116
- else {
117
- // For non-default locales, check if URL starts with pattern
118
- return urlToCheck.startsWith(patternWithoutSlash);
119
- }
60
+ if (/^\s*#/.test(originalUrl)) return false;
61
+ const patternWithoutSlash = patternHead.replace(/\/$/, "");
62
+ let urlToCheck = originalUrl;
63
+ if (baseDomain && originalUrl.startsWith(baseDomain)) urlToCheck = originalUrl.substring(baseDomain.length);
64
+ if (targetLocale === defaultLocale) return urlToCheck.includes(patternWithoutSlash);
65
+ else return urlToCheck.startsWith(patternWithoutSlash);
120
66
  }
121
67
  /**
122
- * Determines if a URL should be processed based on the base domain
123
- */
68
+ * Determines if a URL should be processed based on the base domain
69
+ */
124
70
  function shouldProcessAbsoluteUrl(originalUrl, baseDomain) {
125
- return originalUrl.startsWith(baseDomain);
71
+ return originalUrl.startsWith(baseDomain);
126
72
  }
127
73
  /**
128
- * Checks if a URL should be excluded based on exclusion patterns
129
- */
74
+ * Checks if a URL should be excluded based on exclusion patterns
75
+ */
130
76
  function isUrlExcluded(originalUrl, exclude, defaultLocale) {
131
- const excludePatterns = exclude.map((p) => p.replace(/\[locale\]/g, defaultLocale));
132
- return excludePatterns.some((pattern) => isMatch(originalUrl, pattern));
77
+ return exclude.map((p) => p.replace(/\[locale\]/g, defaultLocale)).some((pattern) => isMatch(originalUrl, pattern));
133
78
  }
134
79
  /**
135
- * Main URL transformation function that delegates to specific scenarios
136
- */
137
- export function transformUrlPath(originalUrl, patternHead, targetLocale, defaultLocale, hideDefaultLocale) {
138
- const originalPathArray = originalUrl
139
- .split('/')
140
- .filter((path) => path !== '');
141
- const patternHeadArray = patternHead.split('/').filter((path) => path !== '');
142
- // check if the pattern head matches the original path
143
- if (!checkIfPathMatchesPattern(originalPathArray, patternHeadArray)) {
144
- return null;
145
- }
146
- if (patternHeadArray.length > originalPathArray.length) {
147
- return null; // Pattern is longer than the URL path
148
- }
149
- let result = null;
150
- if (targetLocale === defaultLocale) {
151
- if (hideDefaultLocale) {
152
- // check if default locale is already present
153
- if (originalPathArray?.[patternHeadArray.length] !== defaultLocale) {
154
- return null;
155
- }
156
- // remove default locale
157
- const newPathArray = [
158
- ...originalPathArray.slice(0, patternHeadArray.length),
159
- ...originalPathArray.slice(patternHeadArray.length + 1),
160
- ];
161
- result = newPathArray.join('/');
162
- }
163
- else {
164
- // check if default locale is already present
165
- if (originalPathArray?.[patternHeadArray.length] === defaultLocale) {
166
- return null;
167
- }
168
- // insert default locale
169
- const newPathArray = [
170
- ...originalPathArray.slice(0, patternHeadArray.length),
171
- defaultLocale,
172
- ...originalPathArray.slice(patternHeadArray.length),
173
- ];
174
- result = newPathArray.join('/');
175
- }
176
- }
177
- else if (hideDefaultLocale) {
178
- // Avoid duplicating target locale if already present
179
- if (originalPathArray?.[patternHeadArray.length] === targetLocale) {
180
- return null;
181
- }
182
- const newPathArray = [
183
- ...originalPathArray.slice(0, patternHeadArray.length),
184
- targetLocale,
185
- ...originalPathArray.slice(patternHeadArray.length),
186
- ];
187
- result = newPathArray.join('/');
188
- }
189
- else {
190
- // check default locale
191
- if (originalPathArray?.[patternHeadArray.length] !== defaultLocale) {
192
- return null;
193
- }
194
- // replace default locale with target locale
195
- const newPathArray = [...originalPathArray];
196
- newPathArray[patternHeadArray.length] = targetLocale;
197
- result = newPathArray.join('/');
198
- }
199
- // check for leading and trailing slashes
200
- if (originalUrl.startsWith('/')) {
201
- result = '/' + result;
202
- }
203
- if (originalUrl.endsWith('/')) {
204
- result = result + '/';
205
- }
206
- return result;
80
+ * Main URL transformation function that delegates to specific scenarios
81
+ */
82
+ function transformUrlPath(originalUrl, patternHead, targetLocale, defaultLocale, hideDefaultLocale) {
83
+ const originalPathArray = originalUrl.split("/").filter((path) => path !== "");
84
+ const patternHeadArray = patternHead.split("/").filter((path) => path !== "");
85
+ if (!checkIfPathMatchesPattern(originalPathArray, patternHeadArray)) return null;
86
+ if (patternHeadArray.length > originalPathArray.length) return null;
87
+ let result = null;
88
+ if (targetLocale === defaultLocale) if (hideDefaultLocale) {
89
+ if (originalPathArray?.[patternHeadArray.length] !== defaultLocale) return null;
90
+ result = [...originalPathArray.slice(0, patternHeadArray.length), ...originalPathArray.slice(patternHeadArray.length + 1)].join("/");
91
+ } else {
92
+ if (originalPathArray?.[patternHeadArray.length] === defaultLocale) return null;
93
+ result = [
94
+ ...originalPathArray.slice(0, patternHeadArray.length),
95
+ defaultLocale,
96
+ ...originalPathArray.slice(patternHeadArray.length)
97
+ ].join("/");
98
+ }
99
+ else if (hideDefaultLocale) {
100
+ if (originalPathArray?.[patternHeadArray.length] === targetLocale) return null;
101
+ result = [
102
+ ...originalPathArray.slice(0, patternHeadArray.length),
103
+ targetLocale,
104
+ ...originalPathArray.slice(patternHeadArray.length)
105
+ ].join("/");
106
+ } else {
107
+ if (originalPathArray?.[patternHeadArray.length] !== defaultLocale) return null;
108
+ const newPathArray = [...originalPathArray];
109
+ newPathArray[patternHeadArray.length] = targetLocale;
110
+ result = newPathArray.join("/");
111
+ }
112
+ if (originalUrl.startsWith("/")) result = "/" + result;
113
+ if (originalUrl.endsWith("/")) result = result + "/";
114
+ return result;
207
115
  }
208
116
  /**
209
- * AST-based transformation for MDX files using remark-mdx
210
- */
211
- function transformMdxUrls(mdxContent, defaultLocale, targetLocale, hideDefaultLocale, pattern = '/[locale]', exclude = [], baseDomain) {
212
- const transformedUrls = [];
213
- if (!pattern.startsWith('/')) {
214
- pattern = '/' + pattern;
215
- }
216
- const patternHead = pattern.split('[locale]')[0];
217
- // Quick check: if the file doesn't contain the pattern, skip expensive AST parsing
218
- // For default locale processing, we also need to check if content might need adjustment
219
- if (targetLocale === defaultLocale) {
220
- // For default locale files, we always need to check as we're looking for either:
221
- // - paths without locale (when hideDefaultLocale=false)
222
- // - paths with default locale (when hideDefaultLocale=true)
223
- const patternWithoutSlash = patternHead.replace(/\/$/, '');
224
- if (!mdxContent.includes(patternWithoutSlash)) {
225
- return {
226
- content: mdxContent,
227
- hasChanges: false,
228
- transformedUrls: [],
229
- };
230
- }
231
- }
232
- else {
233
- // For non-default locales, use the original logic
234
- if (!mdxContent.includes(patternHead.replace(/\/$/, ''))) {
235
- return {
236
- content: mdxContent,
237
- hasChanges: false,
238
- transformedUrls: [],
239
- };
240
- }
241
- }
242
- // Parse the MDX content into an AST
243
- let processedAst;
244
- try {
245
- const parseProcessor = unified()
246
- .use(remarkParse)
247
- .use(remarkFrontmatter, ['yaml', 'toml'])
248
- .use(remarkMdx);
249
- const ast = parseProcessor.parse(mdxContent);
250
- processedAst = parseProcessor.runSync(ast);
251
- }
252
- catch {
253
- return {
254
- content: mdxContent,
255
- hasChanges: false,
256
- transformedUrls,
257
- };
258
- }
259
- // Helper function to transform URL based on pattern
260
- const transformUrl = (originalUrl, linkType) => {
261
- // For Markdown links [text](path), only process absolute-root paths starting with '/'
262
- // Relative markdown links should remain relative to the current page and not be localized.
263
- if (linkType === 'markdown') {
264
- const isFragment = /^\s*#/.test(originalUrl);
265
- const isAbsoluteRoot = originalUrl.startsWith('/');
266
- const looksAbsoluteWithDomain = baseDomain
267
- ? shouldProcessAbsoluteUrl(originalUrl, baseDomain)
268
- : false;
269
- if (!isAbsoluteRoot && !looksAbsoluteWithDomain && !isFragment) {
270
- return null;
271
- }
272
- }
273
- // Check if URL should be processed
274
- if (!shouldProcessUrl(originalUrl, patternHead, targetLocale, defaultLocale, baseDomain)) {
275
- return null;
276
- }
277
- // Skip absolute URLs (http://, https://, //, etc.)
278
- if (baseDomain && shouldProcessAbsoluteUrl(originalUrl, baseDomain)) {
279
- // Get everything after the base domain
280
- const afterDomain = originalUrl.substring(baseDomain.length);
281
- const transformedPath = transformUrlPath(afterDomain, patternHead, targetLocale, defaultLocale, hideDefaultLocale);
282
- if (!transformedPath) {
283
- return null;
284
- }
285
- transformedUrls.push({
286
- originalPath: originalUrl,
287
- newPath: transformedPath,
288
- type: linkType,
289
- });
290
- return transformedPath ? baseDomain + transformedPath : null;
291
- }
292
- // Exclude colon-prefixed URLs (http://, https://, //, etc.)
293
- if (originalUrl.split('?')[0].includes(':')) {
294
- return null;
295
- }
296
- // Transform the URL based on locale and configuration
297
- const newUrl = transformUrlPath(originalUrl, patternHead, targetLocale, defaultLocale, hideDefaultLocale);
298
- if (!newUrl) {
299
- return null;
300
- }
301
- // Check exclusions
302
- if (isUrlExcluded(originalUrl, exclude, defaultLocale)) {
303
- return null;
304
- }
305
- transformedUrls.push({
306
- originalPath: originalUrl,
307
- newPath: newUrl,
308
- type: linkType,
309
- });
310
- return newUrl;
311
- };
312
- // Visit markdown link nodes: [text](url)
313
- visit(processedAst, 'link', (node) => {
314
- if (node.url) {
315
- const newUrl = transformUrl(node.url, 'markdown');
316
- if (newUrl) {
317
- node.url = newUrl;
318
- }
319
- }
320
- });
321
- // Visit JSX/HTML elements for href attributes: <a href="url"> or <Card href="url">
322
- visit(processedAst, ['mdxJsxFlowElement', 'mdxJsxTextElement'], (node) => {
323
- const jsxNode = node;
324
- if (jsxNode.attributes) {
325
- for (const attr of jsxNode.attributes) {
326
- if (attr.type === 'mdxJsxAttribute' &&
327
- attr.name === 'href' &&
328
- attr.value) {
329
- // Handle MdxJsxAttribute with string or MdxJsxAttributeValueExpression
330
- const hrefValue = typeof attr.value === 'string' ? attr.value : attr.value.value;
331
- if (typeof hrefValue === 'string') {
332
- const newUrl = transformUrl(hrefValue, 'href');
333
- if (newUrl) {
334
- if (typeof attr.value === 'string') {
335
- attr.value = newUrl;
336
- }
337
- else {
338
- attr.value.value = newUrl;
339
- }
340
- }
341
- }
342
- }
343
- }
344
- }
345
- });
346
- // Visit raw JSX nodes for href attributes in JSX strings
347
- visit(processedAst, 'jsx', (node) => {
348
- if (node.value && typeof node.value === 'string') {
349
- const jsxContent = node.value;
350
- // Use regex to find href attributes in the JSX string
351
- const hrefRegex = /href\s*=\s*["']([^"']+)["']/g;
352
- let match;
353
- const replacements = [];
354
- // Reset regex lastIndex to avoid issues with global flag
355
- hrefRegex.lastIndex = 0;
356
- while ((match = hrefRegex.exec(jsxContent)) !== null) {
357
- const originalHref = match[1];
358
- const newUrl = transformUrl(originalHref, 'href');
359
- if (newUrl) {
360
- // Store replacement info
361
- const oldHrefAttr = match[0]; // The full match like 'href="/quickstart"'
362
- const quote = oldHrefAttr.includes('"') ? '"' : "'";
363
- const newHrefAttr = `href=${quote}${newUrl}${quote}`;
364
- replacements.push({
365
- start: match.index,
366
- end: match.index + oldHrefAttr.length,
367
- oldHrefAttr,
368
- newHrefAttr,
369
- });
370
- }
371
- }
372
- // Apply replacements in reverse order (from end to start) to avoid position shifts
373
- if (replacements.length > 0) {
374
- let newJsxContent = jsxContent;
375
- replacements
376
- .sort((a, b) => b.start - a.start)
377
- .forEach(({ start, end, newHrefAttr }) => {
378
- newJsxContent =
379
- newJsxContent.slice(0, start) +
380
- newHrefAttr +
381
- newJsxContent.slice(end);
382
- });
383
- node.value = newJsxContent;
384
- }
385
- }
386
- });
387
- // Convert the modified AST back to MDX string
388
- let content;
389
- try {
390
- const stringifyProcessor = unified()
391
- .use(remarkFrontmatter, ['yaml', 'toml'])
392
- .use(remarkMdx)
393
- .use(normalizeCJKCharacters)
394
- .use(escapeHtmlInTextNodes)
395
- .use(remarkStringify, {
396
- handlers: {
397
- // Handler to prevent escaping (avoids '&lt;' -> '\&lt;')
398
- text(node) {
399
- return node.value;
400
- },
401
- },
402
- });
403
- const outTree = stringifyProcessor.runSync(processedAst);
404
- content = stringifyProcessor.stringify(outTree);
405
- }
406
- catch (error) {
407
- console.warn(`Failed to stringify MDX content: ${error instanceof Error ? error.message : String(error)}`);
408
- console.warn('Returning original content unchanged due to stringify error.');
409
- return {
410
- content: mdxContent,
411
- hasChanges: false,
412
- transformedUrls: [],
413
- };
414
- }
415
- // Handle newline formatting to match original input
416
- if (content.endsWith('\n') && !mdxContent.endsWith('\n')) {
417
- content = content.slice(0, -1);
418
- }
419
- // Preserve leading newlines from original content
420
- if (mdxContent.startsWith('\n') && !content.startsWith('\n')) {
421
- content = '\n' + content;
422
- }
423
- return {
424
- content,
425
- hasChanges: transformedUrls.length > 0,
426
- transformedUrls,
427
- };
117
+ * AST-based transformation for MDX files using remark-mdx
118
+ */
119
+ function transformMdxUrls(mdxContent, defaultLocale, targetLocale, hideDefaultLocale, pattern = "/[locale]", exclude = [], baseDomain) {
120
+ const transformedUrls = [];
121
+ if (!pattern.startsWith("/")) pattern = "/" + pattern;
122
+ const patternHead = pattern.split("[locale]")[0];
123
+ if (targetLocale === defaultLocale) {
124
+ const patternWithoutSlash = patternHead.replace(/\/$/, "");
125
+ if (!mdxContent.includes(patternWithoutSlash)) return {
126
+ content: mdxContent,
127
+ hasChanges: false,
128
+ transformedUrls: []
129
+ };
130
+ } else if (!mdxContent.includes(patternHead.replace(/\/$/, ""))) return {
131
+ content: mdxContent,
132
+ hasChanges: false,
133
+ transformedUrls: []
134
+ };
135
+ let processedAst;
136
+ try {
137
+ const parseProcessor = unified().use(remarkParse).use(remarkFrontmatter, ["yaml", "toml"]).use(remarkMdx);
138
+ const ast = parseProcessor.parse(mdxContent);
139
+ processedAst = parseProcessor.runSync(ast);
140
+ } catch {
141
+ return {
142
+ content: mdxContent,
143
+ hasChanges: false,
144
+ transformedUrls
145
+ };
146
+ }
147
+ const transformUrl = (originalUrl, linkType) => {
148
+ if (linkType === "markdown") {
149
+ const isFragment = /^\s*#/.test(originalUrl);
150
+ const isAbsoluteRoot = originalUrl.startsWith("/");
151
+ const looksAbsoluteWithDomain = baseDomain ? shouldProcessAbsoluteUrl(originalUrl, baseDomain) : false;
152
+ if (!isAbsoluteRoot && !looksAbsoluteWithDomain && !isFragment) return null;
153
+ }
154
+ if (!shouldProcessUrl(originalUrl, patternHead, targetLocale, defaultLocale, baseDomain)) return null;
155
+ if (baseDomain && shouldProcessAbsoluteUrl(originalUrl, baseDomain)) {
156
+ const transformedPath = transformUrlPath(originalUrl.substring(baseDomain.length), patternHead, targetLocale, defaultLocale, hideDefaultLocale);
157
+ if (!transformedPath) return null;
158
+ transformedUrls.push({
159
+ originalPath: originalUrl,
160
+ newPath: transformedPath,
161
+ type: linkType
162
+ });
163
+ return transformedPath ? baseDomain + transformedPath : null;
164
+ }
165
+ if (originalUrl.split("?")[0].includes(":")) return null;
166
+ const newUrl = transformUrlPath(originalUrl, patternHead, targetLocale, defaultLocale, hideDefaultLocale);
167
+ if (!newUrl) return null;
168
+ if (isUrlExcluded(originalUrl, exclude, defaultLocale)) return null;
169
+ transformedUrls.push({
170
+ originalPath: originalUrl,
171
+ newPath: newUrl,
172
+ type: linkType
173
+ });
174
+ return newUrl;
175
+ };
176
+ visit(processedAst, "link", (node) => {
177
+ if (node.url) {
178
+ const newUrl = transformUrl(node.url, "markdown");
179
+ if (newUrl) node.url = newUrl;
180
+ }
181
+ });
182
+ visit(processedAst, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
183
+ const jsxNode = node;
184
+ if (jsxNode.attributes) {
185
+ for (const attr of jsxNode.attributes) if (attr.type === "mdxJsxAttribute" && attr.name === "href" && attr.value) {
186
+ const hrefValue = typeof attr.value === "string" ? attr.value : attr.value.value;
187
+ if (typeof hrefValue === "string") {
188
+ const newUrl = transformUrl(hrefValue, "href");
189
+ if (newUrl) if (typeof attr.value === "string") attr.value = newUrl;
190
+ else attr.value.value = newUrl;
191
+ }
192
+ }
193
+ }
194
+ });
195
+ visit(processedAst, "jsx", (node) => {
196
+ if (node.value && typeof node.value === "string") {
197
+ const jsxContent = node.value;
198
+ const hrefRegex = /href\s*=\s*["']([^"']+)["']/g;
199
+ let match;
200
+ const replacements = [];
201
+ hrefRegex.lastIndex = 0;
202
+ while ((match = hrefRegex.exec(jsxContent)) !== null) {
203
+ const originalHref = match[1];
204
+ const newUrl = transformUrl(originalHref, "href");
205
+ if (newUrl) {
206
+ const oldHrefAttr = match[0];
207
+ const quote = oldHrefAttr.includes("\"") ? "\"" : "'";
208
+ const newHrefAttr = `href=${quote}${newUrl}${quote}`;
209
+ replacements.push({
210
+ start: match.index,
211
+ end: match.index + oldHrefAttr.length,
212
+ oldHrefAttr,
213
+ newHrefAttr
214
+ });
215
+ }
216
+ }
217
+ if (replacements.length > 0) {
218
+ let newJsxContent = jsxContent;
219
+ replacements.sort((a, b) => b.start - a.start).forEach(({ start, end, newHrefAttr }) => {
220
+ newJsxContent = newJsxContent.slice(0, start) + newHrefAttr + newJsxContent.slice(end);
221
+ });
222
+ node.value = newJsxContent;
223
+ }
224
+ }
225
+ });
226
+ let content;
227
+ try {
228
+ const stringifyProcessor = unified().use(remarkFrontmatter, ["yaml", "toml"]).use(remarkMdx).use(normalizeCJKCharacters).use(escapeHtmlInTextNodes).use(remarkStringify, { handlers: { text(node) {
229
+ return node.value;
230
+ } } });
231
+ const outTree = stringifyProcessor.runSync(processedAst);
232
+ content = stringifyProcessor.stringify(outTree);
233
+ } catch (error) {
234
+ console.warn(`Failed to stringify MDX content: ${error instanceof Error ? error.message : String(error)}`);
235
+ console.warn("Returning original content unchanged due to stringify error.");
236
+ return {
237
+ content: mdxContent,
238
+ hasChanges: false,
239
+ transformedUrls: []
240
+ };
241
+ }
242
+ if (content.endsWith("\n") && !mdxContent.endsWith("\n")) content = content.slice(0, -1);
243
+ if (mdxContent.startsWith("\n") && !content.startsWith("\n")) content = "\n" + content;
244
+ return {
245
+ content,
246
+ hasChanges: transformedUrls.length > 0,
247
+ transformedUrls
248
+ };
428
249
  }
429
- // AST-based transformation for MDX files using remark
430
- function localizeStaticUrlsForFile(file, defaultLocale, targetLocale, hideDefaultLocale, pattern = '/[locale]', // eg /docs/[locale] or /[locale]
431
- exclude = [], baseDomain) {
432
- // Use AST-based transformation for MDX files
433
- return transformMdxUrls(file, defaultLocale, targetLocale, hideDefaultLocale, pattern, exclude, baseDomain || '');
250
+ function localizeStaticUrlsForFile(file, defaultLocale, targetLocale, hideDefaultLocale, pattern = "/[locale]", exclude = [], baseDomain) {
251
+ return transformMdxUrls(file, defaultLocale, targetLocale, hideDefaultLocale, pattern, exclude, baseDomain || "");
434
252
  }
435
253
  function checkIfPathMatchesPattern(originalUrlArray, patternHeadArray) {
436
- // check if the pattern head matches the original path
437
- for (let i = 0; i < patternHeadArray.length; i++) {
438
- if (patternHeadArray[i] !== originalUrlArray?.[i]) {
439
- return false;
440
- }
441
- }
442
- return true;
254
+ for (let i = 0; i < patternHeadArray.length; i++) if (patternHeadArray[i] !== originalUrlArray?.[i]) return false;
255
+ return true;
443
256
  }
257
+ //#endregion
258
+ export { localizeStaticUrls as default, transformUrlPath };
259
+
260
+ //# sourceMappingURL=localizeStaticUrls.js.map