gt 2.14.35 → 2.14.37

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 (430) hide show
  1. package/CHANGELOG.md +22 -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.d.ts +1 -1
  256. package/dist/react/jsx/utils/resolveImportPath.js +125 -108
  257. package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
  258. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
  259. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
  260. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
  261. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
  262. package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
  263. package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
  264. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
  265. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
  266. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
  267. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
  268. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
  269. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
  270. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
  271. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
  272. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
  273. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
  274. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
  275. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
  276. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
  277. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
  278. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
  279. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
  280. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
  281. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
  282. package/dist/react/jsx/utils/validateStringFunction.js +21 -29
  283. package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
  284. package/dist/react/jsx/wrapJsx.js +192 -375
  285. package/dist/react/jsx/wrapJsx.js.map +1 -0
  286. package/dist/react/parse/addVitePlugin/index.js +40 -34
  287. package/dist/react/parse/addVitePlugin/index.js.map +1 -0
  288. package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
  289. package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
  290. package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
  291. package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
  292. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
  293. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
  294. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
  295. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
  296. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
  297. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
  298. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
  299. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
  300. package/dist/react/parse/createDictionaryUpdates.js +121 -185
  301. package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
  302. package/dist/react/parse/createInlineUpdates.js +123 -139
  303. package/dist/react/parse/createInlineUpdates.js.map +1 -0
  304. package/dist/react/parse/wrapContent.js +131 -156
  305. package/dist/react/parse/wrapContent.js.map +1 -0
  306. package/dist/react/utils/flattenDictionary.js +55 -70
  307. package/dist/react/utils/flattenDictionary.js.map +1 -0
  308. package/dist/react/utils/getEntryAndMetadata.js +14 -10
  309. package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
  310. package/dist/react/utils/getVariableName.js +36 -33
  311. package/dist/react/utils/getVariableName.js.map +1 -0
  312. package/dist/setup/detectFramework.js +85 -102
  313. package/dist/setup/detectFramework.js.map +1 -0
  314. package/dist/setup/frameworkUtils.js +17 -28
  315. package/dist/setup/frameworkUtils.js.map +1 -0
  316. package/dist/setup/userInput.js +24 -31
  317. package/dist/setup/userInput.js.map +1 -0
  318. package/dist/setup/wizard.js +141 -143
  319. package/dist/setup/wizard.js.map +1 -0
  320. package/dist/state/mintlifyRefMap.js +12 -9
  321. package/dist/state/mintlifyRefMap.js.map +1 -0
  322. package/dist/state/recentDownloads.js +26 -23
  323. package/dist/state/recentDownloads.js.map +1 -0
  324. package/dist/state/translateWarnings.js +17 -8
  325. package/dist/state/translateWarnings.js.map +1 -0
  326. package/dist/translation/parse.js +77 -98
  327. package/dist/translation/parse.js.map +1 -0
  328. package/dist/translation/stage.js +28 -43
  329. package/dist/translation/stage.js.map +1 -0
  330. package/dist/translation/validate.js +68 -91
  331. package/dist/translation/validate.js.map +1 -0
  332. package/dist/types/libraries.js +93 -91
  333. package/dist/types/libraries.js.map +1 -0
  334. package/dist/types/parsing.js +19 -10
  335. package/dist/types/parsing.js.map +1 -0
  336. package/dist/utils/addExplicitAnchorIds.js +270 -389
  337. package/dist/utils/addExplicitAnchorIds.js.map +1 -0
  338. package/dist/utils/calculateTimeoutMs.js +11 -6
  339. package/dist/utils/calculateTimeoutMs.js.map +1 -0
  340. package/dist/utils/constants.js +15 -12
  341. package/dist/utils/constants.js.map +1 -0
  342. package/dist/utils/credentials.js +67 -114
  343. package/dist/utils/credentials.js.map +1 -0
  344. package/dist/utils/fetch.js +22 -20
  345. package/dist/utils/fetch.js.map +1 -0
  346. package/dist/utils/flattenJsonFiles.js +27 -34
  347. package/dist/utils/flattenJsonFiles.js.map +1 -0
  348. package/dist/utils/gitDiff.js +30 -32
  349. package/dist/utils/gitDiff.js.map +1 -0
  350. package/dist/utils/gt.js +7 -2
  351. package/dist/utils/gt.js.map +1 -0
  352. package/dist/utils/hash.js +14 -9
  353. package/dist/utils/hash.js.map +1 -0
  354. package/dist/utils/headers.js +10 -13
  355. package/dist/utils/headers.js.map +1 -0
  356. package/dist/utils/installPackage.js +70 -75
  357. package/dist/utils/installPackage.js.map +1 -0
  358. package/dist/utils/localizeRelativeAssets.js +114 -157
  359. package/dist/utils/localizeRelativeAssets.js.map +1 -0
  360. package/dist/utils/localizeStaticImports.js +229 -371
  361. package/dist/utils/localizeStaticImports.js.map +1 -0
  362. package/dist/utils/localizeStaticUrls.js +241 -424
  363. package/dist/utils/localizeStaticUrls.js.map +1 -0
  364. package/dist/utils/mintlifyTitleFallback.js +64 -72
  365. package/dist/utils/mintlifyTitleFallback.js.map +1 -0
  366. package/dist/utils/monorepoVersionCheck.js +177 -215
  367. package/dist/utils/monorepoVersionCheck.js.map +1 -0
  368. package/dist/utils/packageInfo.js +17 -16
  369. package/dist/utils/packageInfo.js.map +1 -0
  370. package/dist/utils/packageJson.js +51 -66
  371. package/dist/utils/packageJson.js.map +1 -0
  372. package/dist/utils/packageManager.js +237 -260
  373. package/dist/utils/packageManager.js.map +1 -0
  374. package/dist/utils/parse/needsCJS.js +36 -69
  375. package/dist/utils/parse/needsCJS.js.map +1 -0
  376. package/dist/utils/persistPostprocessHashes.js +30 -32
  377. package/dist/utils/persistPostprocessHashes.js.map +1 -0
  378. package/dist/utils/processAnchorIds.js +32 -54
  379. package/dist/utils/processAnchorIds.js.map +1 -0
  380. package/dist/utils/processOpenApi.js +469 -578
  381. package/dist/utils/processOpenApi.js.map +1 -0
  382. package/dist/utils/resolveMintlifyRefs.js +89 -105
  383. package/dist/utils/resolveMintlifyRefs.js.map +1 -0
  384. package/dist/utils/resolvePublish.js +46 -54
  385. package/dist/utils/resolvePublish.js.map +1 -0
  386. package/dist/utils/sanitizeFileContent.js +20 -27
  387. package/dist/utils/sanitizeFileContent.js.map +1 -0
  388. package/dist/utils/sharedStaticAssets.js +248 -366
  389. package/dist/utils/sharedStaticAssets.js.map +1 -0
  390. package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
  391. package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
  392. package/dist/utils/validateMdx.js +26 -23
  393. package/dist/utils/validateMdx.js.map +1 -0
  394. package/dist/utils/wrapPlainUrls.js +58 -70
  395. package/dist/utils/wrapPlainUrls.js.map +1 -0
  396. package/dist/workflows/download.js +92 -126
  397. package/dist/workflows/download.js.map +1 -0
  398. package/dist/workflows/enqueue.js +47 -54
  399. package/dist/workflows/enqueue.js.map +1 -0
  400. package/dist/workflows/publish.js +29 -29
  401. package/dist/workflows/publish.js.map +1 -0
  402. package/dist/workflows/setupProject.js +39 -40
  403. package/dist/workflows/setupProject.js.map +1 -0
  404. package/dist/workflows/stage.js +61 -65
  405. package/dist/workflows/stage.js.map +1 -0
  406. package/dist/workflows/steps/BranchStep.js +118 -163
  407. package/dist/workflows/steps/BranchStep.js.map +1 -0
  408. package/dist/workflows/steps/DownloadStep.js +107 -137
  409. package/dist/workflows/steps/DownloadStep.js.map +1 -0
  410. package/dist/workflows/steps/EnqueueStep.js +32 -32
  411. package/dist/workflows/steps/EnqueueStep.js.map +1 -0
  412. package/dist/workflows/steps/PollJobsStep.js +208 -292
  413. package/dist/workflows/steps/PollJobsStep.js.map +1 -0
  414. package/dist/workflows/steps/PublishStep.js +33 -38
  415. package/dist/workflows/steps/PublishStep.js.map +1 -0
  416. package/dist/workflows/steps/SetupStep.js +71 -72
  417. package/dist/workflows/steps/SetupStep.js.map +1 -0
  418. package/dist/workflows/steps/TagStep.js +39 -44
  419. package/dist/workflows/steps/TagStep.js.map +1 -0
  420. package/dist/workflows/steps/UploadSourcesStep.js +108 -140
  421. package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
  422. package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
  423. package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
  424. package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
  425. package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
  426. package/dist/workflows/steps/WorkflowStep.js +6 -2
  427. package/dist/workflows/steps/WorkflowStep.js.map +1 -0
  428. package/dist/workflows/upload.js +45 -46
  429. package/dist/workflows/upload.js.map +1 -0
  430. package/package.json +14 -7
@@ -1,651 +1,542 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { unified } from 'unified';
4
- import remarkParse from 'remark-parse';
5
- import remarkFrontmatter from 'remark-frontmatter';
6
- import YAML, { isMap, isScalar } from 'yaml';
7
- import { logger } from '../console/logger.js';
8
- import { createFileMapping } from '../formats/files/fileMapping.js';
1
+ import { logger } from "../console/logger.js";
2
+ import { createFileMapping } from "../formats/files/fileMapping.js";
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+ import YAML, { isMap, isScalar } from "yaml";
6
+ import { unified } from "unified";
7
+ import remarkParse from "remark-parse";
8
+ import remarkFrontmatter from "remark-frontmatter";
9
+ //#region src/utils/processOpenApi.ts
9
10
  const HTTP_METHODS = new Set([
10
- 'GET',
11
- 'POST',
12
- 'PUT',
13
- 'PATCH',
14
- 'DELETE',
15
- 'OPTIONS',
16
- 'HEAD',
17
- 'TRACE',
11
+ "GET",
12
+ "POST",
13
+ "PUT",
14
+ "PATCH",
15
+ "DELETE",
16
+ "OPTIONS",
17
+ "HEAD",
18
+ "TRACE"
19
+ ]);
20
+ const OPENAPI_SPEC_EXTENSIONS = new Set([
21
+ ".json",
22
+ ".yaml",
23
+ ".yml"
18
24
  ]);
19
- const OPENAPI_SPEC_EXTENSIONS = new Set(['.json', '.yaml', '.yml']);
20
25
  /**
21
- * Postprocess Mintlify OpenAPI references to point to locale-specific spec files.
22
- * - Uses openapi.files (ordered) to resolve ambiguities (first match wins).
23
- * - Relies on the user's json transform rules for locale paths.
24
- * - Warns on missing/ambiguous references but keeps behavior deterministic.
25
- */
26
- export default async function processOpenApi(settings, includeFiles) {
27
- const openapiConfig = settings.options?.mintlify?.openapi;
28
- if (!openapiConfig || !openapiConfig.files?.length)
29
- return;
30
- if (!settings.files)
31
- return;
32
- const configDir = path.dirname(settings.config);
33
- const specAnalyses = buildSpecAnalyses(openapiConfig.files, configDir);
34
- if (!specAnalyses.length)
35
- return;
36
- const warnings = new Set();
37
- const { resolvedPaths, placeholderPaths, transformPaths, transformFormats } = settings.files;
38
- const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, transformFormats, settings.locales, settings.defaultLocale);
39
- const fileMappingAbs = {};
40
- for (const [locale, mapping] of Object.entries(fileMapping)) {
41
- fileMappingAbs[locale] = {};
42
- for (const [src, dest] of Object.entries(mapping)) {
43
- const absSrc = path.resolve(configDir, src);
44
- const absDest = path.resolve(configDir, dest);
45
- fileMappingAbs[locale][absSrc] = absDest;
46
- }
47
- }
48
- // Also rewrite default-locale source files so they use the deterministic spec selection
49
- const defaultFiles = [
50
- ...(resolvedPaths.mdx || []),
51
- ...(resolvedPaths.md || []),
52
- ];
53
- for (const filePath of defaultFiles) {
54
- if (!fs.existsSync(filePath))
55
- continue;
56
- const content = fs.readFileSync(filePath, 'utf8');
57
- const updated = rewriteFrontmatter(content, filePath, settings.defaultLocale, specAnalyses, fileMappingAbs, warnings, configDir);
58
- if (updated?.changed) {
59
- await fs.promises.writeFile(filePath, updated.content, 'utf8');
60
- }
61
- }
62
- for (const [locale, filesMap] of Object.entries(fileMapping)) {
63
- const targetFiles = Object.values(filesMap).filter((p) => (p.endsWith('.md') || p.endsWith('.mdx')) &&
64
- (!includeFiles || includeFiles.has(p)));
65
- for (const filePath of targetFiles) {
66
- if (!fs.existsSync(filePath))
67
- continue;
68
- const content = fs.readFileSync(filePath, 'utf8');
69
- const updated = rewriteFrontmatter(content, filePath, locale, specAnalyses, fileMappingAbs, warnings, configDir);
70
- if (updated?.changed) {
71
- await fs.promises.writeFile(filePath, updated.content, 'utf8');
72
- }
73
- }
74
- }
75
- const docsJsonTargets = collectDocsJsonTargets(settings, fileMapping, includeFiles);
76
- for (const target of docsJsonTargets) {
77
- if (!fs.existsSync(target.path))
78
- continue;
79
- const content = fs.readFileSync(target.path, 'utf8');
80
- const updated = rewriteDocsJsonOpenApi(content, target.path, target.localeHint, specAnalyses, fileMappingAbs, fileMapping, warnings, configDir, settings.defaultLocale);
81
- if (updated?.changed) {
82
- await fs.promises.writeFile(target.path, updated.content, 'utf8');
83
- }
84
- }
85
- for (const message of warnings) {
86
- logger.warn(message);
87
- }
26
+ * Postprocess Mintlify OpenAPI references to point to locale-specific spec files.
27
+ * - Uses openapi.files (ordered) to resolve ambiguities (first match wins).
28
+ * - Relies on the user's json transform rules for locale paths.
29
+ * - Warns on missing/ambiguous references but keeps behavior deterministic.
30
+ */
31
+ async function processOpenApi(settings, includeFiles) {
32
+ const openapiConfig = settings.options?.mintlify?.openapi;
33
+ if (!openapiConfig || !openapiConfig.files?.length) return;
34
+ if (!settings.files) return;
35
+ const configDir = path.dirname(settings.config);
36
+ const specAnalyses = buildSpecAnalyses(openapiConfig.files, configDir);
37
+ if (!specAnalyses.length) return;
38
+ const warnings = /* @__PURE__ */ new Set();
39
+ const { resolvedPaths, placeholderPaths, transformPaths, transformFormats } = settings.files;
40
+ const fileMapping = createFileMapping(resolvedPaths, placeholderPaths, transformPaths, transformFormats, settings.locales, settings.defaultLocale);
41
+ const fileMappingAbs = {};
42
+ for (const [locale, mapping] of Object.entries(fileMapping)) {
43
+ fileMappingAbs[locale] = {};
44
+ for (const [src, dest] of Object.entries(mapping)) {
45
+ const absSrc = path.resolve(configDir, src);
46
+ const absDest = path.resolve(configDir, dest);
47
+ fileMappingAbs[locale][absSrc] = absDest;
48
+ }
49
+ }
50
+ const defaultFiles = [...resolvedPaths.mdx || [], ...resolvedPaths.md || []];
51
+ for (const filePath of defaultFiles) {
52
+ if (!fs.existsSync(filePath)) continue;
53
+ const updated = rewriteFrontmatter(fs.readFileSync(filePath, "utf8"), filePath, settings.defaultLocale, specAnalyses, fileMappingAbs, warnings, configDir);
54
+ if (updated?.changed) await fs.promises.writeFile(filePath, updated.content, "utf8");
55
+ }
56
+ for (const [locale, filesMap] of Object.entries(fileMapping)) {
57
+ const targetFiles = Object.values(filesMap).filter((p) => (p.endsWith(".md") || p.endsWith(".mdx")) && (!includeFiles || includeFiles.has(p)));
58
+ for (const filePath of targetFiles) {
59
+ if (!fs.existsSync(filePath)) continue;
60
+ const updated = rewriteFrontmatter(fs.readFileSync(filePath, "utf8"), filePath, locale, specAnalyses, fileMappingAbs, warnings, configDir);
61
+ if (updated?.changed) await fs.promises.writeFile(filePath, updated.content, "utf8");
62
+ }
63
+ }
64
+ const docsJsonTargets = collectDocsJsonTargets(settings, fileMapping, includeFiles);
65
+ for (const target of docsJsonTargets) {
66
+ if (!fs.existsSync(target.path)) continue;
67
+ const updated = rewriteDocsJsonOpenApi(fs.readFileSync(target.path, "utf8"), target.path, target.localeHint, specAnalyses, fileMappingAbs, fileMapping, warnings, configDir, settings.defaultLocale);
68
+ if (updated?.changed) await fs.promises.writeFile(target.path, updated.content, "utf8");
69
+ }
70
+ for (const message of warnings) logger.warn(message);
88
71
  }
89
72
  function collectDocsJsonTargets(settings, fileMapping, includeFiles) {
90
- const targets = [];
91
- const seen = new Map();
92
- const addTarget = (filePath, locale) => {
93
- const canonicalPath = path.resolve(filePath);
94
- if (includeFiles &&
95
- !includeFiles.has(filePath) &&
96
- !includeFiles.has(canonicalPath)) {
97
- return;
98
- }
99
- const locales = seen.get(canonicalPath) ?? new Set();
100
- if (locale)
101
- locales.add(locale);
102
- seen.set(canonicalPath, locales);
103
- };
104
- if (!includeFiles && settings.files?.resolvedPaths.json) {
105
- for (const filePath of settings.files.resolvedPaths.json) {
106
- addTarget(filePath, settings.defaultLocale);
107
- }
108
- }
109
- for (const [locale, filesMap] of Object.entries(fileMapping)) {
110
- for (const filePath of Object.values(filesMap)) {
111
- if (!filePath.endsWith('.json'))
112
- continue;
113
- addTarget(filePath, locale);
114
- }
115
- }
116
- for (const [filePath, locales] of seen.entries()) {
117
- const localeHint = locales.size === 1 ? Array.from(locales)[0] : undefined;
118
- targets.push({ path: filePath, localeHint });
119
- }
120
- return targets;
73
+ const targets = [];
74
+ const seen = /* @__PURE__ */ new Map();
75
+ const addTarget = (filePath, locale) => {
76
+ const canonicalPath = path.resolve(filePath);
77
+ if (includeFiles && !includeFiles.has(filePath) && !includeFiles.has(canonicalPath)) return;
78
+ const locales = seen.get(canonicalPath) ?? /* @__PURE__ */ new Set();
79
+ if (locale) locales.add(locale);
80
+ seen.set(canonicalPath, locales);
81
+ };
82
+ if (!includeFiles && settings.files?.resolvedPaths.json) for (const filePath of settings.files.resolvedPaths.json) addTarget(filePath, settings.defaultLocale);
83
+ for (const [locale, filesMap] of Object.entries(fileMapping)) for (const filePath of Object.values(filesMap)) {
84
+ if (!filePath.endsWith(".json")) continue;
85
+ addTarget(filePath, locale);
86
+ }
87
+ for (const [filePath, locales] of seen.entries()) {
88
+ const localeHint = locales.size === 1 ? Array.from(locales)[0] : void 0;
89
+ targets.push({
90
+ path: filePath,
91
+ localeHint
92
+ });
93
+ }
94
+ return targets;
121
95
  }
122
96
  function isMintlifyDocsJson(filePath, json) {
123
- if (!isRecord(json))
124
- return false;
125
- const schema = json.$schema;
126
- if (typeof schema === 'string') {
127
- return (schema.includes('mintlify.com/docs.json') ||
128
- schema.includes('mintlify.com/mint.json'));
129
- }
130
- const base = path.basename(filePath);
131
- return base === 'docs.json' || base === 'mint.json';
97
+ if (!isRecord(json)) return false;
98
+ const schema = json.$schema;
99
+ if (typeof schema === "string") return schema.includes("mintlify.com/docs.json") || schema.includes("mintlify.com/mint.json");
100
+ const base = path.basename(filePath);
101
+ return base === "docs.json" || base === "mint.json";
132
102
  }
133
103
  function rewriteDocsJsonOpenApi(content, filePath, localeHint, specs, fileMappingAbs, fileMappingRel, warnings, configDir, defaultLocale) {
134
- let json;
135
- try {
136
- json = JSON.parse(content);
137
- }
138
- catch {
139
- return null;
140
- }
141
- if (!isMintlifyDocsJson(filePath, json))
142
- return null;
143
- let changed = false;
144
- const visitNode = (node, activeLocale) => {
145
- if (Array.isArray(node)) {
146
- node.forEach((item) => visitNode(item, activeLocale));
147
- return;
148
- }
149
- if (!isRecord(node))
150
- return;
151
- let nextLocale = activeLocale;
152
- if (typeof node.language === 'string') {
153
- nextLocale = node.language;
154
- }
155
- const locale = nextLocale || localeHint || defaultLocale;
156
- if (typeof node.openapi === 'string') {
157
- const sourceValue = node.openapi;
158
- const localizedSource = localizeDocsJsonSpecPath(sourceValue, locale, filePath, specs, fileMappingAbs, fileMappingRel, warnings, configDir);
159
- if (localizedSource && localizedSource !== sourceValue) {
160
- node.openapi = localizedSource;
161
- changed = true;
162
- }
163
- }
164
- else if (isRecord(node.openapi)) {
165
- const openapiConfig = node.openapi;
166
- const sourceValue = openapiConfig.source;
167
- if (typeof sourceValue === 'string') {
168
- const localizedSource = localizeDocsJsonSpecPath(sourceValue, locale, filePath, specs, fileMappingAbs, fileMappingRel, warnings, configDir);
169
- if (localizedSource && localizedSource !== sourceValue) {
170
- openapiConfig.source = localizedSource;
171
- changed = true;
172
- }
173
- }
174
- }
175
- if (Array.isArray(node.pages)) {
176
- const pages = node.pages;
177
- for (let i = 0; i < pages.length; i += 1) {
178
- const page = pages[i];
179
- if (typeof page !== 'string')
180
- continue;
181
- const updated = stripLocaleFromOpenApiPage(page, locale);
182
- if (updated !== page) {
183
- pages[i] = updated;
184
- changed = true;
185
- }
186
- }
187
- }
188
- for (const value of Object.values(node)) {
189
- visitNode(value, nextLocale);
190
- }
191
- };
192
- visitNode(json, undefined);
193
- if (!changed)
194
- return null;
195
- return { changed, content: JSON.stringify(json, null, 2) };
104
+ let json;
105
+ try {
106
+ json = JSON.parse(content);
107
+ } catch {
108
+ return null;
109
+ }
110
+ if (!isMintlifyDocsJson(filePath, json)) return null;
111
+ let changed = false;
112
+ const visitNode = (node, activeLocale) => {
113
+ if (Array.isArray(node)) {
114
+ node.forEach((item) => visitNode(item, activeLocale));
115
+ return;
116
+ }
117
+ if (!isRecord(node)) return;
118
+ let nextLocale = activeLocale;
119
+ if (typeof node.language === "string") nextLocale = node.language;
120
+ const locale = nextLocale || localeHint || defaultLocale;
121
+ if (typeof node.openapi === "string") {
122
+ const sourceValue = node.openapi;
123
+ const localizedSource = localizeDocsJsonSpecPath(sourceValue, locale, filePath, specs, fileMappingAbs, fileMappingRel, warnings, configDir);
124
+ if (localizedSource && localizedSource !== sourceValue) {
125
+ node.openapi = localizedSource;
126
+ changed = true;
127
+ }
128
+ } else if (isRecord(node.openapi)) {
129
+ const openapiConfig = node.openapi;
130
+ const sourceValue = openapiConfig.source;
131
+ if (typeof sourceValue === "string") {
132
+ const localizedSource = localizeDocsJsonSpecPath(sourceValue, locale, filePath, specs, fileMappingAbs, fileMappingRel, warnings, configDir);
133
+ if (localizedSource && localizedSource !== sourceValue) {
134
+ openapiConfig.source = localizedSource;
135
+ changed = true;
136
+ }
137
+ }
138
+ }
139
+ if (Array.isArray(node.pages)) {
140
+ const pages = node.pages;
141
+ for (let i = 0; i < pages.length; i += 1) {
142
+ const page = pages[i];
143
+ if (typeof page !== "string") continue;
144
+ const updated = stripLocaleFromOpenApiPage(page, locale);
145
+ if (updated !== page) {
146
+ pages[i] = updated;
147
+ changed = true;
148
+ }
149
+ }
150
+ }
151
+ for (const value of Object.values(node)) visitNode(value, nextLocale);
152
+ };
153
+ visitNode(json, void 0);
154
+ if (!changed) return null;
155
+ return {
156
+ changed,
157
+ content: JSON.stringify(json, null, 2)
158
+ };
196
159
  }
197
160
  function stripLocaleFromOpenApiPage(value, locale) {
198
- const trimmed = value.trim();
199
- const prefix = `${locale}/`;
200
- if (!trimmed.startsWith(prefix))
201
- return value;
202
- const candidate = trimmed.slice(prefix.length);
203
- const parsed = parseOpenApiValue(candidate);
204
- if (!parsed)
205
- return value;
206
- return candidate;
161
+ const trimmed = value.trim();
162
+ const prefix = `${locale}/`;
163
+ if (!trimmed.startsWith(prefix)) return value;
164
+ const candidate = trimmed.slice(prefix.length);
165
+ if (!parseOpenApiValue(candidate)) return value;
166
+ return candidate;
207
167
  }
208
168
  function localizeDocsJsonSpecPath(source, locale, filePath, specs, fileMappingAbs, _fileMappingRel, warnings, configDir) {
209
- const resolvedAbs = resolveDocsJsonSpecPath(source, filePath, configDir);
210
- const matched = matchSpecBySource(source, resolvedAbs, specs, warnings);
211
- if (!matched)
212
- return source;
213
- const localizedSpecPath = resolveLocalizedSpecPath(matched, locale, fileMappingAbs, configDir, source);
214
- const localizedAbs = resolveDocsJsonSpecPath(localizedSpecPath, filePath, configDir);
215
- if (!fs.existsSync(localizedAbs)) {
216
- warnings.add(`OpenAPI source "${source}" localized for locale "${locale}" points to a missing file (${localizedAbs}). Keeping original source.`);
217
- return source;
218
- }
219
- const rel = normalizeSlashes(path.relative(configDir, localizedAbs));
220
- return formatSpecPathForDocsJson(rel, source);
169
+ const matched = matchSpecBySource(source, resolveDocsJsonSpecPath(source, filePath, configDir), specs, warnings);
170
+ if (!matched) return source;
171
+ const localizedAbs = resolveDocsJsonSpecPath(resolveLocalizedSpecPath(matched, locale, fileMappingAbs, configDir, source), filePath, configDir);
172
+ if (!fs.existsSync(localizedAbs)) {
173
+ warnings.add(`OpenAPI source "${source}" localized for locale "${locale}" points to a missing file (${localizedAbs}). Keeping original source.`);
174
+ return source;
175
+ }
176
+ return formatSpecPathForDocsJson(normalizeSlashes(path.relative(configDir, localizedAbs)), source);
221
177
  }
222
178
  function resolveDocsJsonSpecPath(source, filePath, configDir) {
223
- if (source.startsWith('/')) {
224
- return path.resolve(configDir, source.replace(/^\/+/, ''));
225
- }
226
- if (source.startsWith('./') || source.startsWith('../')) {
227
- return path.resolve(path.dirname(filePath), source);
228
- }
229
- return path.resolve(configDir, source);
179
+ if (source.startsWith("/")) return path.resolve(configDir, source.replace(/^\/+/, ""));
180
+ if (source.startsWith("./") || source.startsWith("../")) return path.resolve(path.dirname(filePath), source);
181
+ return path.resolve(configDir, source);
230
182
  }
231
183
  function matchSpecBySource(source, resolvedAbs, specs, warnings) {
232
- const exact = specs.find((spec) => samePath(resolvedAbs, spec.absPath));
233
- if (exact)
234
- return exact;
235
- const normalizedExplicit = normalizeSlashes(source).replace(/^\.?\/+/, '');
236
- const explicitWithoutExt = stripExtension(normalizedExplicit);
237
- const explicitBase = path.basename(normalizedExplicit);
238
- const explicitBaseWithoutExt = stripExtension(explicitBase);
239
- const matches = specs.filter((spec) => {
240
- const configPath = normalizeSlashes(spec.configPath).replace(/^\.?\/+/, '');
241
- const configBase = path.basename(configPath);
242
- const configPathNoExt = stripExtension(configPath);
243
- const configBaseNoExt = stripExtension(configBase);
244
- return (configPath === normalizedExplicit ||
245
- configPathNoExt === explicitWithoutExt ||
246
- configBase === explicitBase ||
247
- configBaseNoExt === explicitBaseWithoutExt);
248
- });
249
- if (matches.length === 1)
250
- return matches[0];
251
- if (matches.length > 1) {
252
- warnings.add(`OpenAPI source "${source}" matches multiple specs (${matches
253
- .map((m) => m.configPath)
254
- .join(', ')}). Using the first configured match (${matches[0].configPath}).`);
255
- return matches[0];
256
- }
257
- return null;
184
+ const exact = specs.find((spec) => samePath(resolvedAbs, spec.absPath));
185
+ if (exact) return exact;
186
+ const normalizedExplicit = normalizeSlashes(source).replace(/^\.?\/+/, "");
187
+ const explicitWithoutExt = stripExtension(normalizedExplicit);
188
+ const explicitBase = path.basename(normalizedExplicit);
189
+ const explicitBaseWithoutExt = stripExtension(explicitBase);
190
+ const matches = specs.filter((spec) => {
191
+ const configPath = normalizeSlashes(spec.configPath).replace(/^\.?\/+/, "");
192
+ const configBase = path.basename(configPath);
193
+ const configPathNoExt = stripExtension(configPath);
194
+ const configBaseNoExt = stripExtension(configBase);
195
+ return configPath === normalizedExplicit || configPathNoExt === explicitWithoutExt || configBase === explicitBase || configBaseNoExt === explicitBaseWithoutExt;
196
+ });
197
+ if (matches.length === 1) return matches[0];
198
+ if (matches.length > 1) {
199
+ warnings.add(`OpenAPI source "${source}" matches multiple specs (${matches.map((m) => m.configPath).join(", ")}). Using the first configured match (${matches[0].configPath}).`);
200
+ return matches[0];
201
+ }
202
+ return null;
258
203
  }
259
204
  function formatSpecPathForDocsJson(relativePath, originalPathText) {
260
- const normalized = normalizeSlashes(relativePath);
261
- const base = normalized.replace(/^\.\//, '').replace(/\/+/g, '/');
262
- if (originalPathText.startsWith('/')) {
263
- return `/${base.replace(/^\/+/, '')}`;
264
- }
265
- if (originalPathText.startsWith('../')) {
266
- return normalized;
267
- }
268
- if (originalPathText.startsWith('./')) {
269
- return `./${base.replace(/^\/+/, '')}`;
270
- }
271
- return base.replace(/^\/+/, '');
205
+ const normalized = normalizeSlashes(relativePath);
206
+ const base = normalized.replace(/^\.\//, "").replace(/\/+/g, "/");
207
+ if (originalPathText.startsWith("/")) return `/${base.replace(/^\/+/, "")}`;
208
+ if (originalPathText.startsWith("../")) return normalized;
209
+ if (originalPathText.startsWith("./")) return `./${base.replace(/^\/+/, "")}`;
210
+ return base.replace(/^\/+/, "");
272
211
  }
273
212
  /**
274
- * Resolve configured OpenAPI files to absolute paths and collect the operations,
275
- * schemas, and webhooks they expose. Warns and skips when files are missing,
276
- * unsupported (non-JSON/YAML), or fail to parse so later steps can continue gracefully.
277
- */
213
+ * Resolve configured OpenAPI files to absolute paths and collect the operations,
214
+ * schemas, and webhooks they expose. Warns and skips when files are missing,
215
+ * unsupported (non-JSON/YAML), or fail to parse so later steps can continue gracefully.
216
+ */
278
217
  function buildSpecAnalyses(openapiFiles, configDir) {
279
- const analyses = [];
280
- for (const configEntry of openapiFiles) {
281
- const absPath = path.resolve(configDir, configEntry);
282
- if (!fs.existsSync(absPath)) {
283
- logger.warn(`OpenAPI file not found: ${configEntry}`);
284
- continue;
285
- }
286
- const ext = path.extname(absPath).toLowerCase();
287
- if (!OPENAPI_SPEC_EXTENSIONS.has(ext)) {
288
- logger.warn(`Skipping OpenAPI file (only .json/.yml/.yaml supported): ${configEntry}`);
289
- continue;
290
- }
291
- let spec;
292
- try {
293
- const raw = fs.readFileSync(absPath, 'utf8');
294
- spec = ext === '.json' ? JSON.parse(raw) : YAML.parse(raw);
295
- }
296
- catch {
297
- const format = ext === '.json' ? 'JSON' : 'YAML';
298
- logger.warn(`Failed to parse OpenAPI ${format}: ${configEntry}`);
299
- continue;
300
- }
301
- analyses.push({
302
- absPath,
303
- configPath: configEntry,
304
- operations: extractOperations(spec),
305
- schemas: extractSchemas(spec),
306
- webhooks: extractWebhooks(spec),
307
- });
308
- }
309
- return analyses;
218
+ const analyses = [];
219
+ for (const configEntry of openapiFiles) {
220
+ const absPath = path.resolve(configDir, configEntry);
221
+ if (!fs.existsSync(absPath)) {
222
+ logger.warn(`OpenAPI file not found: ${configEntry}`);
223
+ continue;
224
+ }
225
+ const ext = path.extname(absPath).toLowerCase();
226
+ if (!OPENAPI_SPEC_EXTENSIONS.has(ext)) {
227
+ logger.warn(`Skipping OpenAPI file (only .json/.yml/.yaml supported): ${configEntry}`);
228
+ continue;
229
+ }
230
+ let spec;
231
+ try {
232
+ const raw = fs.readFileSync(absPath, "utf8");
233
+ spec = ext === ".json" ? JSON.parse(raw) : YAML.parse(raw);
234
+ } catch {
235
+ const format = ext === ".json" ? "JSON" : "YAML";
236
+ logger.warn(`Failed to parse OpenAPI ${format}: ${configEntry}`);
237
+ continue;
238
+ }
239
+ analyses.push({
240
+ absPath,
241
+ configPath: configEntry,
242
+ operations: extractOperations(spec),
243
+ schemas: extractSchemas(spec),
244
+ webhooks: extractWebhooks(spec)
245
+ });
246
+ }
247
+ return analyses;
310
248
  }
311
249
  function isRecord(val) {
312
- return typeof val === 'object' && val !== null;
250
+ return typeof val === "object" && val !== null;
313
251
  }
314
252
  /**
315
- * Collect path+method identifiers (e.g., "POST /foo") from an OpenAPI spec.
316
- * Safely no-ops when paths is missing or malformed.
317
- */
253
+ * Collect path+method identifiers (e.g., "POST /foo") from an OpenAPI spec.
254
+ * Safely no-ops when paths is missing or malformed.
255
+ */
318
256
  function extractOperations(spec) {
319
- const ops = new Set();
320
- if (!isRecord(spec) || !isRecord(spec.paths))
321
- return ops;
322
- const paths = spec.paths;
323
- for (const [route, methods] of Object.entries(paths)) {
324
- if (!isRecord(methods))
325
- continue;
326
- for (const [method, operation] of Object.entries(methods)) {
327
- if (!isRecord(operation))
328
- continue;
329
- const upper = method.toUpperCase();
330
- if (!HTTP_METHODS.has(upper))
331
- continue;
332
- ops.add(`${upper} ${route}`);
333
- }
334
- }
335
- return ops;
257
+ const ops = /* @__PURE__ */ new Set();
258
+ if (!isRecord(spec) || !isRecord(spec.paths)) return ops;
259
+ const paths = spec.paths;
260
+ for (const [route, methods] of Object.entries(paths)) {
261
+ if (!isRecord(methods)) continue;
262
+ for (const [method, operation] of Object.entries(methods)) {
263
+ if (!isRecord(operation)) continue;
264
+ const upper = method.toUpperCase();
265
+ if (!HTTP_METHODS.has(upper)) continue;
266
+ ops.add(`${upper} ${route}`);
267
+ }
268
+ }
269
+ return ops;
336
270
  }
337
271
  /**
338
- * Collect schema names from components.schemas.
339
- * Returns empty set if components/schemas are missing or malformed.
340
- */
272
+ * Collect schema names from components.schemas.
273
+ * Returns empty set if components/schemas are missing or malformed.
274
+ */
341
275
  function extractSchemas(spec) {
342
- if (!isRecord(spec) || !isRecord(spec.components))
343
- return new Set();
344
- const components = spec.components;
345
- if (!isRecord(components.schemas))
346
- return new Set();
347
- return new Set(Object.keys(components.schemas));
276
+ if (!isRecord(spec) || !isRecord(spec.components)) return /* @__PURE__ */ new Set();
277
+ const components = spec.components;
278
+ if (!isRecord(components.schemas)) return /* @__PURE__ */ new Set();
279
+ return new Set(Object.keys(components.schemas));
348
280
  }
349
281
  /**
350
- * Collect webhook names from webhooks (OpenAPI 3.1+).
351
- * Returns empty set if webhooks is missing or malformed.
352
- */
282
+ * Collect webhook names from webhooks (OpenAPI 3.1+).
283
+ * Returns empty set if webhooks is missing or malformed.
284
+ */
353
285
  function extractWebhooks(spec) {
354
- if (!isRecord(spec) || !isRecord(spec.webhooks))
355
- return new Set();
356
- return new Set(Object.keys(spec.webhooks));
286
+ if (!isRecord(spec) || !isRecord(spec.webhooks)) return /* @__PURE__ */ new Set();
287
+ return new Set(Object.keys(spec.webhooks));
357
288
  }
358
289
  /**
359
- * Parse MDX/MD frontmatter, rewrite openapi/openapi-schema entries to the
360
- * resolved (possibly localized) spec path, and return updated content.
361
- * Uses remark to find the YAML node so the rest of the document remains
362
- * untouched. When parsing fails or no relevant keys exist, it returns null.
363
- */
290
+ * Parse MDX/MD frontmatter, rewrite openapi/openapi-schema entries to the
291
+ * resolved (possibly localized) spec path, and return updated content.
292
+ * Uses remark to find the YAML node so the rest of the document remains
293
+ * untouched. When parsing fails or no relevant keys exist, it returns null.
294
+ */
364
295
  function rewriteFrontmatter(content, filePath, locale, specs, fileMapping, warnings, configDir) {
365
- let tree;
366
- try {
367
- tree = unified()
368
- .use(remarkParse)
369
- .use(remarkFrontmatter, ['yaml', 'toml'])
370
- .parse(content);
371
- }
372
- catch {
373
- return null;
374
- }
375
- const yamlNode = tree.children.find((node) => node.type === 'yaml');
376
- if (!yamlNode ||
377
- !yamlNode.position ||
378
- yamlNode.position.start?.offset === undefined) {
379
- return null;
380
- }
381
- const start = yamlNode.position.start.offset;
382
- const end = yamlNode.position.end.offset;
383
- const frontmatterRaw = yamlNode.value || '';
384
- const doc = YAML.parseDocument(frontmatterRaw, {
385
- prettyErrors: false,
386
- keepSourceTokens: true,
387
- });
388
- if (doc.errors?.length)
389
- return null;
390
- if (!isMap(doc.contents))
391
- return null;
392
- let changed = false;
393
- const openapiNode = doc.get('openapi', true);
394
- if (isScalar(openapiNode) && typeof openapiNode.value === 'string') {
395
- const parsedValue = parseOpenApiValue(openapiNode.value);
396
- if (parsedValue) {
397
- const matchKey = parsedValue.kind === 'operation'
398
- ? {
399
- type: 'operation',
400
- key: `${parsedValue.method.toUpperCase()} ${parsedValue.operationPath}`,
401
- }
402
- : { type: 'webhook', key: parsedValue.name };
403
- const spec = resolveSpec(parsedValue.specPath, specs, filePath, configDir, warnings, describeOpenApiRef(parsedValue), matchKey);
404
- if (spec) {
405
- const descriptor = formatOpenApiDescriptor(parsedValue);
406
- const localizedSpecPath = resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath);
407
- const newValue = `${localizedSpecPath} ${descriptor}`.trim();
408
- if (newValue !== openapiNode.value) {
409
- doc.set('openapi', newValue);
410
- changed = true;
411
- }
412
- }
413
- }
414
- }
415
- const schemaNode = doc.get('openapi-schema', true);
416
- if (isScalar(schemaNode) && typeof schemaNode.value === 'string') {
417
- const parsedValue = parseSchemaValue(schemaNode.value);
418
- if (parsedValue) {
419
- const spec = resolveSpec(parsedValue.specPath, specs, filePath, configDir, warnings, `schema "${parsedValue.schemaName}"`, { type: 'schema', key: parsedValue.schemaName });
420
- if (spec) {
421
- const localizedSpecPath = resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath);
422
- const newValue = `${localizedSpecPath} ${parsedValue.schemaName}`.trim();
423
- if (newValue !== schemaNode.value) {
424
- doc.set('openapi-schema', newValue);
425
- changed = true;
426
- }
427
- }
428
- }
429
- }
430
- if (!changed)
431
- return null;
432
- const fmString = doc.toString().trimEnd();
433
- const rebuilt = `${content.slice(0, start)}---\n${fmString}\n---${content.slice(end)}`;
434
- return { changed, content: rebuilt };
296
+ let tree;
297
+ try {
298
+ tree = unified().use(remarkParse).use(remarkFrontmatter, ["yaml", "toml"]).parse(content);
299
+ } catch {
300
+ return null;
301
+ }
302
+ const yamlNode = tree.children.find((node) => node.type === "yaml");
303
+ if (!yamlNode || !yamlNode.position || yamlNode.position.start?.offset === void 0) return null;
304
+ const start = yamlNode.position.start.offset;
305
+ const end = yamlNode.position.end.offset;
306
+ const frontmatterRaw = yamlNode.value || "";
307
+ const doc = YAML.parseDocument(frontmatterRaw, {
308
+ prettyErrors: false,
309
+ keepSourceTokens: true
310
+ });
311
+ if (doc.errors?.length) return null;
312
+ if (!isMap(doc.contents)) return null;
313
+ let changed = false;
314
+ const openapiNode = doc.get("openapi", true);
315
+ if (isScalar(openapiNode) && typeof openapiNode.value === "string") {
316
+ const parsedValue = parseOpenApiValue(openapiNode.value);
317
+ if (parsedValue) {
318
+ const matchKey = parsedValue.kind === "operation" ? {
319
+ type: "operation",
320
+ key: `${parsedValue.method.toUpperCase()} ${parsedValue.operationPath}`
321
+ } : {
322
+ type: "webhook",
323
+ key: parsedValue.name
324
+ };
325
+ const spec = resolveSpec(parsedValue.specPath, specs, filePath, configDir, warnings, describeOpenApiRef(parsedValue), matchKey);
326
+ if (spec) {
327
+ const descriptor = formatOpenApiDescriptor(parsedValue);
328
+ const newValue = `${resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath)} ${descriptor}`.trim();
329
+ if (newValue !== openapiNode.value) {
330
+ doc.set("openapi", newValue);
331
+ changed = true;
332
+ }
333
+ }
334
+ }
335
+ }
336
+ const schemaNode = doc.get("openapi-schema", true);
337
+ if (isScalar(schemaNode) && typeof schemaNode.value === "string") {
338
+ const parsedValue = parseSchemaValue(schemaNode.value);
339
+ if (parsedValue) {
340
+ const spec = resolveSpec(parsedValue.specPath, specs, filePath, configDir, warnings, `schema "${parsedValue.schemaName}"`, {
341
+ type: "schema",
342
+ key: parsedValue.schemaName
343
+ });
344
+ if (spec) {
345
+ const newValue = `${resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath)} ${parsedValue.schemaName}`.trim();
346
+ if (newValue !== schemaNode.value) {
347
+ doc.set("openapi-schema", newValue);
348
+ changed = true;
349
+ }
350
+ }
351
+ }
352
+ }
353
+ if (!changed) return null;
354
+ const fmString = doc.toString().trimEnd();
355
+ const rebuilt = `${content.slice(0, start)}---\n${fmString}\n---${content.slice(end)}`;
356
+ return {
357
+ changed,
358
+ content: rebuilt
359
+ };
435
360
  }
436
361
  function stripWrappingQuotes(value) {
437
- return value.trim().replace(/^['"]|['"]$/g, '');
362
+ return value.trim().replace(/^['"]|['"]$/g, "");
438
363
  }
439
364
  /**
440
- * Parse frontmatter openapi string into spec/method/path or webhook.
441
- * Supports optional leading spec file, the webhook keyword, quoted values,
442
- * and forgiving whitespace. Returns null when the structure is unrecognized.
443
- */
365
+ * Parse frontmatter openapi string into spec/method/path or webhook.
366
+ * Supports optional leading spec file, the webhook keyword, quoted values,
367
+ * and forgiving whitespace. Returns null when the structure is unrecognized.
368
+ */
444
369
  function parseOpenApiValue(value) {
445
- const stripped = stripWrappingQuotes(value);
446
- const tokens = stripped.split(/\s+/).filter(Boolean);
447
- if (!tokens.length)
448
- return null;
449
- let cursor = 0;
450
- let specPath;
451
- const first = tokens[0];
452
- const second = tokens[1];
453
- const methodCandidate = second?.toUpperCase();
454
- const firstLooksLikeSpec = hasOpenApiSpecExtension(first) ||
455
- (second &&
456
- (second.toLowerCase() === 'webhook' ||
457
- (methodCandidate && HTTP_METHODS.has(methodCandidate))));
458
- if (firstLooksLikeSpec) {
459
- specPath = tokens[0];
460
- cursor = 1;
461
- }
462
- if (cursor >= tokens.length)
463
- return null;
464
- const keyword = tokens[cursor];
465
- if (keyword.toLowerCase() === 'webhook') {
466
- const name = tokens.slice(cursor + 1).join(' ');
467
- if (!name)
468
- return null;
469
- return { kind: 'webhook', specPath, name };
470
- }
471
- const method = keyword.toUpperCase();
472
- if (!HTTP_METHODS.has(method))
473
- return null;
474
- const operationPath = tokens.slice(cursor + 1).join(' ');
475
- if (!operationPath)
476
- return null;
477
- return { kind: 'operation', specPath, method, operationPath };
370
+ const tokens = stripWrappingQuotes(value).split(/\s+/).filter(Boolean);
371
+ if (!tokens.length) return null;
372
+ let cursor = 0;
373
+ let specPath;
374
+ const first = tokens[0];
375
+ const second = tokens[1];
376
+ const methodCandidate = second?.toUpperCase();
377
+ if (hasOpenApiSpecExtension(first) || second && (second.toLowerCase() === "webhook" || methodCandidate && HTTP_METHODS.has(methodCandidate))) {
378
+ specPath = tokens[0];
379
+ cursor = 1;
380
+ }
381
+ if (cursor >= tokens.length) return null;
382
+ const keyword = tokens[cursor];
383
+ if (keyword.toLowerCase() === "webhook") {
384
+ const name = tokens.slice(cursor + 1).join(" ");
385
+ if (!name) return null;
386
+ return {
387
+ kind: "webhook",
388
+ specPath,
389
+ name
390
+ };
391
+ }
392
+ const method = keyword.toUpperCase();
393
+ if (!HTTP_METHODS.has(method)) return null;
394
+ const operationPath = tokens.slice(cursor + 1).join(" ");
395
+ if (!operationPath) return null;
396
+ return {
397
+ kind: "operation",
398
+ specPath,
399
+ method,
400
+ operationPath
401
+ };
478
402
  }
479
403
  /**
480
- * Parse frontmatter openapi-schema string into spec/schemaName.
481
- * Accepts optional leading spec file and quoted values; returns null on invalid
482
- * shapes so callers can skip rewrites gracefully.
483
- */
404
+ * Parse frontmatter openapi-schema string into spec/schemaName.
405
+ * Accepts optional leading spec file and quoted values; returns null on invalid
406
+ * shapes so callers can skip rewrites gracefully.
407
+ */
484
408
  function parseSchemaValue(value) {
485
- const stripped = stripWrappingQuotes(value);
486
- const tokens = stripped.split(/\s+/).filter(Boolean);
487
- if (!tokens.length)
488
- return null;
489
- let cursor = 0;
490
- let specPath;
491
- if (hasOpenApiSpecExtension(tokens[0])) {
492
- specPath = tokens[0];
493
- cursor = 1;
494
- }
495
- const schemaName = tokens.slice(cursor).join(' ');
496
- if (!schemaName)
497
- return null;
498
- return { specPath, schemaName };
409
+ const tokens = stripWrappingQuotes(value).split(/\s+/).filter(Boolean);
410
+ if (!tokens.length) return null;
411
+ let cursor = 0;
412
+ let specPath;
413
+ if (hasOpenApiSpecExtension(tokens[0])) {
414
+ specPath = tokens[0];
415
+ cursor = 1;
416
+ }
417
+ const schemaName = tokens.slice(cursor).join(" ");
418
+ if (!schemaName) return null;
419
+ return {
420
+ specPath,
421
+ schemaName
422
+ };
499
423
  }
500
424
  /**
501
- * Choose which configured spec a reference should use.
502
- * - If an explicit spec path is provided, resolve it relative to the config
503
- * and the referencing file, warn when unknown, and bail.
504
- * - Otherwise, try to match by operation/webhook/schema name; resolve
505
- * ambiguity using config order and warn when ambiguous or missing.
506
- */
425
+ * Choose which configured spec a reference should use.
426
+ * - If an explicit spec path is provided, resolve it relative to the config
427
+ * and the referencing file, warn when unknown, and bail.
428
+ * - Otherwise, try to match by operation/webhook/schema name; resolve
429
+ * ambiguity using config order and warn when ambiguous or missing.
430
+ */
507
431
  function resolveSpec(explicitPath, specs, filePath, configDir, warnings, refDescription, match) {
508
- if (!specs.length)
509
- return null;
510
- if (explicitPath) {
511
- const normalizedExplicit = normalizeSlashes(explicitPath.replace(/^\.?\/+/, ''));
512
- const candidates = [
513
- path.resolve(configDir, normalizedExplicit),
514
- path.resolve(path.dirname(filePath), normalizedExplicit),
515
- ];
516
- const foundSpec = specs.find((spec) => {
517
- const normalizedSpecPath = normalizeSlashes(spec.absPath);
518
- return candidates.some((candidate) => samePath(candidate, normalizedSpecPath));
519
- });
520
- if (foundSpec) {
521
- if (specHasMatch(foundSpec, match)) {
522
- return foundSpec;
523
- }
524
- const alternatives = specs.filter((spec) => spec !== foundSpec && specHasMatch(spec, match));
525
- if (alternatives.length === 1) {
526
- warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to ${foundSpec.configPath}, but the entry was not found there. Using ${alternatives[0].configPath} instead.`);
527
- return alternatives[0];
528
- }
529
- if (alternatives.length > 1) {
530
- warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to ${foundSpec.configPath}, but the entry was not found there and matches multiple specs (${alternatives
531
- .map((spec) => spec.configPath)
532
- .join(', ')}). Skipping localization for this reference.`);
533
- return null;
534
- }
535
- warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to ${foundSpec.configPath}, but the entry was not found in any configured spec. Skipping localization for this reference.`);
536
- return null;
537
- }
538
- const explicitWithoutExt = stripExtension(normalizedExplicit);
539
- const explicitBase = path.basename(normalizedExplicit);
540
- const explicitBaseWithoutExt = stripExtension(explicitBase);
541
- const matches = specs.filter((spec) => {
542
- const configPath = normalizeSlashes(spec.configPath).replace(/^\.?\/+/, '');
543
- const configBase = path.basename(configPath);
544
- const configPathNoExt = stripExtension(configPath);
545
- const configBaseNoExt = stripExtension(configBase);
546
- return (configPath === normalizedExplicit ||
547
- configPathNoExt === explicitWithoutExt ||
548
- configBase === explicitBase ||
549
- configBaseNoExt === explicitBaseWithoutExt);
550
- });
551
- if (matches.length === 1)
552
- return matches[0];
553
- if (matches.length > 1) {
554
- warnings.add(`OpenAPI reference ${refDescription} in ${filePath} matches multiple specs (${matches
555
- .map((m) => m.configPath)
556
- .join(', ')}). Using the first configured match (${matches[0].configPath}).`);
557
- return matches[0];
558
- }
559
- warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to an unconfigured spec (${explicitPath}). Skipping localization for this reference.`);
560
- return null;
561
- }
562
- // No explicit spec: try to find by contents
563
- const matches = specs.filter((spec) => {
564
- if (match.type === 'schema') {
565
- return spec.schemas.has(match.key);
566
- }
567
- if (match.type === 'webhook') {
568
- return spec.webhooks.has(match.key);
569
- }
570
- // operation
571
- return spec.operations.has(match.key);
572
- });
573
- if (matches.length === 1)
574
- return matches[0];
575
- if (matches.length > 1) {
576
- warnings.add(`OpenAPI reference ${refDescription} in ${filePath} is available in multiple specs. Skipping localization for this reference.`);
577
- return null;
578
- }
579
- warnings.add(`OpenAPI reference ${refDescription} in ${filePath} was not found in any configured spec. Skipping localization for this reference.`);
580
- return null;
432
+ if (!specs.length) return null;
433
+ if (explicitPath) {
434
+ const normalizedExplicit = normalizeSlashes(explicitPath.replace(/^\.?\/+/, ""));
435
+ const candidates = [path.resolve(configDir, normalizedExplicit), path.resolve(path.dirname(filePath), normalizedExplicit)];
436
+ const foundSpec = specs.find((spec) => {
437
+ const normalizedSpecPath = normalizeSlashes(spec.absPath);
438
+ return candidates.some((candidate) => samePath(candidate, normalizedSpecPath));
439
+ });
440
+ if (foundSpec) {
441
+ if (specHasMatch(foundSpec, match)) return foundSpec;
442
+ const alternatives = specs.filter((spec) => spec !== foundSpec && specHasMatch(spec, match));
443
+ if (alternatives.length === 1) {
444
+ warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to ${foundSpec.configPath}, but the entry was not found there. Using ${alternatives[0].configPath} instead.`);
445
+ return alternatives[0];
446
+ }
447
+ if (alternatives.length > 1) {
448
+ warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to ${foundSpec.configPath}, but the entry was not found there and matches multiple specs (${alternatives.map((spec) => spec.configPath).join(", ")}). Skipping localization for this reference.`);
449
+ return null;
450
+ }
451
+ warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to ${foundSpec.configPath}, but the entry was not found in any configured spec. Skipping localization for this reference.`);
452
+ return null;
453
+ }
454
+ const explicitWithoutExt = stripExtension(normalizedExplicit);
455
+ const explicitBase = path.basename(normalizedExplicit);
456
+ const explicitBaseWithoutExt = stripExtension(explicitBase);
457
+ const matches = specs.filter((spec) => {
458
+ const configPath = normalizeSlashes(spec.configPath).replace(/^\.?\/+/, "");
459
+ const configBase = path.basename(configPath);
460
+ const configPathNoExt = stripExtension(configPath);
461
+ const configBaseNoExt = stripExtension(configBase);
462
+ return configPath === normalizedExplicit || configPathNoExt === explicitWithoutExt || configBase === explicitBase || configBaseNoExt === explicitBaseWithoutExt;
463
+ });
464
+ if (matches.length === 1) return matches[0];
465
+ if (matches.length > 1) {
466
+ warnings.add(`OpenAPI reference ${refDescription} in ${filePath} matches multiple specs (${matches.map((m) => m.configPath).join(", ")}). Using the first configured match (${matches[0].configPath}).`);
467
+ return matches[0];
468
+ }
469
+ warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to an unconfigured spec (${explicitPath}). Skipping localization for this reference.`);
470
+ return null;
471
+ }
472
+ const matches = specs.filter((spec) => {
473
+ if (match.type === "schema") return spec.schemas.has(match.key);
474
+ if (match.type === "webhook") return spec.webhooks.has(match.key);
475
+ return spec.operations.has(match.key);
476
+ });
477
+ if (matches.length === 1) return matches[0];
478
+ if (matches.length > 1) {
479
+ warnings.add(`OpenAPI reference ${refDescription} in ${filePath} is available in multiple specs. Skipping localization for this reference.`);
480
+ return null;
481
+ }
482
+ warnings.add(`OpenAPI reference ${refDescription} in ${filePath} was not found in any configured spec. Skipping localization for this reference.`);
483
+ return null;
581
484
  }
582
485
  function specHasMatch(spec, match) {
583
- if (match.type === 'schema') {
584
- return spec.schemas.has(match.key);
585
- }
586
- if (match.type === 'webhook') {
587
- return spec.webhooks.has(match.key);
588
- }
589
- return spec.operations.has(match.key);
486
+ if (match.type === "schema") return spec.schemas.has(match.key);
487
+ if (match.type === "webhook") return spec.webhooks.has(match.key);
488
+ return spec.operations.has(match.key);
590
489
  }
591
490
  /**
592
- * Map a spec to the locale-specific file path when available and normalize it
593
- * for frontmatter. Falls back to the source spec when the locale copy does
594
- * not exist to preserve deterministic behavior.
595
- */
491
+ * Map a spec to the locale-specific file path when available and normalize it
492
+ * for frontmatter. Falls back to the source spec when the locale copy does
493
+ * not exist to preserve deterministic behavior.
494
+ */
596
495
  function resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, originalPathText) {
597
- const mapping = fileMapping[locale]?.[spec.absPath];
598
- const chosenAbs = mapping || spec.absPath;
599
- const rel = normalizeSlashes(path.relative(configDir, chosenAbs));
600
- const rooted = `/${rel.replace(/^\/+/, '')}`;
601
- return formatSpecPathForFrontmatter(rooted, originalPathText || spec.configPath);
496
+ const chosenAbs = fileMapping[locale]?.[spec.absPath] || spec.absPath;
497
+ return formatSpecPathForFrontmatter(`/${normalizeSlashes(path.relative(configDir, chosenAbs)).replace(/^\/+/, "")}`, originalPathText || spec.configPath);
602
498
  }
603
499
  /**
604
- * Format the path that will be written back to frontmatter:
605
- * - Preserve the user's absolute style when they used a leading slash.
606
- * - Preserve upward relative references (../) exactly.
607
- * - Otherwise return a repo-root-relative path with a leading slash so Mintlify
608
- * resolves consistently regardless of the MDX file location.
609
- */
500
+ * Format the path that will be written back to frontmatter:
501
+ * - Preserve the user's absolute style when they used a leading slash.
502
+ * - Preserve upward relative references (../) exactly.
503
+ * - Otherwise return a repo-root-relative path with a leading slash so Mintlify
504
+ * resolves consistently regardless of the MDX file location.
505
+ */
610
506
  function formatSpecPathForFrontmatter(relativePath, originalPathText) {
611
- const normalized = normalizeSlashes(relativePath);
612
- const base = normalized.replace(/^\.\//, '').replace(/\/+/g, '/');
613
- if (originalPathText.startsWith('/')) {
614
- // Force repo-root absolute style
615
- return `/${base.replace(/^\/+/, '')}`;
616
- }
617
- if (originalPathText.startsWith('../')) {
618
- // Preserve explicit relative upward references
619
- return normalized;
620
- }
621
- // Default to repo-root relative with leading slash to avoid resolving relative to the MDX directory
622
- return `/${base.replace(/^\/+/, '')}`;
507
+ const normalized = normalizeSlashes(relativePath);
508
+ const base = normalized.replace(/^\.\//, "").replace(/\/+/g, "/");
509
+ if (originalPathText.startsWith("/")) return `/${base.replace(/^\/+/, "")}`;
510
+ if (originalPathText.startsWith("../")) return normalized;
511
+ return `/${base.replace(/^\/+/, "")}`;
623
512
  }
624
513
  /** Normalize the descriptive portion after the spec path for frontmatter. */
625
514
  function formatOpenApiDescriptor(value) {
626
- if (value.kind === 'webhook')
627
- return `webhook ${value.name}`;
628
- return `${value.method.toUpperCase()} ${value.operationPath}`;
515
+ if (value.kind === "webhook") return `webhook ${value.name}`;
516
+ return `${value.method.toUpperCase()} ${value.operationPath}`;
629
517
  }
630
518
  /** Human-readable description a specific OpenAPI reference. */
631
519
  function describeOpenApiRef(value) {
632
- if (value.kind === 'webhook')
633
- return `webhook ${value.name}`;
634
- return `${value.method.toUpperCase()} ${value.operationPath}`;
520
+ if (value.kind === "webhook") return `webhook ${value.name}`;
521
+ return `${value.method.toUpperCase()} ${value.operationPath}`;
635
522
  }
636
523
  /** Remove a single trailing file extension while preserving directory segments. */
637
524
  function stripExtension(p) {
638
- const parsed = path.parse(p);
639
- return normalizeSlashes(path.join(parsed.dir, parsed.name));
525
+ const parsed = path.parse(p);
526
+ return normalizeSlashes(path.join(parsed.dir, parsed.name));
640
527
  }
641
528
  function hasOpenApiSpecExtension(value) {
642
- return OPENAPI_SPEC_EXTENSIONS.has(path.extname(value).toLowerCase());
529
+ return OPENAPI_SPEC_EXTENSIONS.has(path.extname(value).toLowerCase());
643
530
  }
644
531
  /** Normalize separators for stable comparisons and output. */
645
532
  function normalizeSlashes(p) {
646
- return p.replace(/\\/g, '/');
533
+ return p.replace(/\\/g, "/");
647
534
  }
648
535
  /** Compare paths after resolution to avoid casing/separator mismatches. */
649
536
  function samePath(a, b) {
650
- return path.resolve(a) === path.resolve(b);
537
+ return path.resolve(a) === path.resolve(b);
651
538
  }
539
+ //#endregion
540
+ export { processOpenApi as default };
541
+
542
+ //# sourceMappingURL=processOpenApi.js.map