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,203 +1,174 @@
1
- import { getLocaleProperties } from '@generaltranslation/format';
2
- import { exitSync } from '../../console/logging.js';
3
- import { logger } from '../../console/logger.js';
4
- import { flattenJson } from './flattenJson.js';
5
- import chalk from 'chalk';
6
- import path from 'node:path';
7
- import micromatch from 'micromatch';
8
- import { getJSONPathMatches } from './jsonPath.js';
1
+ import { logger } from "../../console/logger.js";
2
+ import { exitSync } from "../../console/logging.js";
3
+ import { getJSONPathMatches } from "./jsonPath.js";
4
+ import { flattenJson } from "./flattenJson.js";
5
+ import chalk from "chalk";
6
+ import path from "node:path";
7
+ import micromatch from "micromatch";
8
+ import { getLocaleProperties } from "@generaltranslation/format";
9
+ //#region src/formats/json/utils.ts
9
10
  const { isMatch } = micromatch;
10
- // Find the matching source item in an array
11
- // where the key matches the identifying locale property
12
- // If no matching item is found, exit with an error
13
- export function findMatchingItemArray(locale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue) {
14
- const { identifyingLocaleProperty, localeKeyJsonPath } = getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions);
15
- // Use the json pointer key to locate the source item
16
- const matchingItems = {};
17
- for (const [index, item] of sourceObjectValue.entries()) {
18
- // Get the key candidates
19
- const keyCandidates = getJSONPathMatches(item, localeKeyJsonPath);
20
- if (!keyCandidates) {
21
- logger.error(`Source item at path: ${sourceObjectPointer} does not have a key value at path: ${localeKeyJsonPath}`);
22
- return exitSync(1);
23
- }
24
- else if (keyCandidates.length === 0) {
25
- // If no key candidates, skip the item
26
- continue;
27
- }
28
- else if (keyCandidates.length > 1) {
29
- // If multiple key candidates, exit with an error
30
- logger.error(`Source item at path: ${sourceObjectPointer} has multiple matching keys with path: ${localeKeyJsonPath}`);
31
- return exitSync(1);
32
- }
33
- else if (identifyingLocaleProperty !== keyCandidates[0].value) {
34
- // Validate the key is the identifying locale property
35
- continue;
36
- }
37
- const keyParentProperty = keyCandidates[0].parentProperty;
38
- if (keyParentProperty === null) {
39
- logger.error(`Source item at path: ${sourceObjectPointer} has a root-level key match with path: ${localeKeyJsonPath}`);
40
- return exitSync(1);
41
- }
42
- // Map the index to the source item
43
- matchingItems[`/${index}`] = {
44
- sourceItem: item,
45
- keyParentProperty,
46
- keyPointer: keyCandidates[0].pointer,
47
- index,
48
- };
49
- }
50
- return matchingItems;
11
+ function findMatchingItemArray(locale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue) {
12
+ const { identifyingLocaleProperty, localeKeyJsonPath } = getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions);
13
+ const matchingItems = {};
14
+ for (const [index, item] of sourceObjectValue.entries()) {
15
+ const keyCandidates = getJSONPathMatches(item, localeKeyJsonPath);
16
+ if (!keyCandidates) {
17
+ logger.error(`Source item at path: ${sourceObjectPointer} does not have a key value at path: ${localeKeyJsonPath}`);
18
+ return exitSync(1);
19
+ } else if (keyCandidates.length === 0) continue;
20
+ else if (keyCandidates.length > 1) {
21
+ logger.error(`Source item at path: ${sourceObjectPointer} has multiple matching keys with path: ${localeKeyJsonPath}`);
22
+ return exitSync(1);
23
+ } else if (identifyingLocaleProperty !== keyCandidates[0].value) continue;
24
+ const keyParentProperty = keyCandidates[0].parentProperty;
25
+ if (keyParentProperty === null) {
26
+ logger.error(`Source item at path: ${sourceObjectPointer} has a root-level key match with path: ${localeKeyJsonPath}`);
27
+ return exitSync(1);
28
+ }
29
+ matchingItems[`/${index}`] = {
30
+ sourceItem: item,
31
+ keyParentProperty,
32
+ keyPointer: keyCandidates[0].pointer,
33
+ index
34
+ };
35
+ }
36
+ return matchingItems;
51
37
  }
52
- export function findMatchingItemObject(locale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue) {
53
- const { identifyingLocaleProperty } = getSourceObjectOptionsObject(locale, sourceObjectPointer, sourceObjectOptions);
54
- // Locate the source item
55
- if (sourceObjectValue[identifyingLocaleProperty]) {
56
- return {
57
- sourceItem: sourceObjectValue[identifyingLocaleProperty],
58
- keyParentProperty: identifyingLocaleProperty,
59
- };
60
- }
61
- return {
62
- sourceItem: undefined,
63
- keyParentProperty: identifyingLocaleProperty,
64
- };
38
+ function findMatchingItemObject(locale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue) {
39
+ const { identifyingLocaleProperty } = getSourceObjectOptionsObject(locale, sourceObjectPointer, sourceObjectOptions);
40
+ if (sourceObjectValue[identifyingLocaleProperty]) return {
41
+ sourceItem: sourceObjectValue[identifyingLocaleProperty],
42
+ keyParentProperty: identifyingLocaleProperty
43
+ };
44
+ return {
45
+ sourceItem: void 0,
46
+ keyParentProperty: identifyingLocaleProperty
47
+ };
65
48
  }
66
49
  /**
67
- * Get the identifying locale property for an object
68
- * @param locale - The locale to get the identifying locale property for
69
- * @param sourceObjectPointer - The path to the source object
70
- * @param sourceObjectOptions - The source object options
71
- * @returns The identifying locale property
72
- */
73
- export function getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions) {
74
- // Validate localeProperty
75
- const localeProperty = sourceObjectOptions.localeProperty || 'code';
76
- const identifyingLocaleProperty = getLocaleProperties(locale)[localeProperty];
77
- if (!identifyingLocaleProperty) {
78
- logger.error(`Source object options localeProperty is not a valid locale property at path: ${sourceObjectPointer}`);
79
- return exitSync(1);
80
- }
81
- return identifyingLocaleProperty;
50
+ * Get the identifying locale property for an object
51
+ * @param locale - The locale to get the identifying locale property for
52
+ * @param sourceObjectPointer - The path to the source object
53
+ * @param sourceObjectOptions - The source object options
54
+ * @returns The identifying locale property
55
+ */
56
+ function getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions) {
57
+ const localeProperty = sourceObjectOptions.localeProperty || "code";
58
+ const identifyingLocaleProperty = getLocaleProperties(locale)[localeProperty];
59
+ if (!identifyingLocaleProperty) {
60
+ logger.error(`Source object options localeProperty is not a valid locale property at path: ${sourceObjectPointer}`);
61
+ return exitSync(1);
62
+ }
63
+ return identifyingLocaleProperty;
82
64
  }
83
65
  /**
84
- * Get the identifying locale property and the json path to the key for an array
85
- * @param locale - The locale to get the identifying locale property for
86
- * @param sourceObjectPointer - The path to the source object
87
- * @param sourceObjectOptions - The source object options
88
- * @returns The identifying locale property and the json path to the key
89
- */
90
- export function getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions) {
91
- const identifyingLocaleProperty = getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions);
92
- const localeKeyJsonPath = sourceObjectOptions.key;
93
- if (!localeKeyJsonPath) {
94
- logger.error(`Source object options key is required for array at path: ${sourceObjectPointer}`);
95
- return exitSync(1);
96
- }
97
- return { identifyingLocaleProperty, localeKeyJsonPath };
66
+ * Get the identifying locale property and the json path to the key for an array
67
+ * @param locale - The locale to get the identifying locale property for
68
+ * @param sourceObjectPointer - The path to the source object
69
+ * @param sourceObjectOptions - The source object options
70
+ * @returns The identifying locale property and the json path to the key
71
+ */
72
+ function getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions) {
73
+ const identifyingLocaleProperty = getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions);
74
+ const localeKeyJsonPath = sourceObjectOptions.key;
75
+ if (!localeKeyJsonPath) {
76
+ logger.error(`Source object options key is required for array at path: ${sourceObjectPointer}`);
77
+ return exitSync(1);
78
+ }
79
+ return {
80
+ identifyingLocaleProperty,
81
+ localeKeyJsonPath
82
+ };
98
83
  }
99
- export function getSourceObjectOptionsObject(defaultLocale, sourceObjectPointer, sourceObjectOptions) {
100
- const identifyingLocaleProperty = getIdentifyingLocaleProperty(defaultLocale, sourceObjectPointer, sourceObjectOptions);
101
- const jsonPathKey = sourceObjectOptions.key;
102
- if (jsonPathKey) {
103
- logger.error(`Source object options key is not allowed for object at path: ${sourceObjectPointer}`);
104
- return exitSync(1);
105
- }
106
- return { identifyingLocaleProperty };
84
+ function getSourceObjectOptionsObject(defaultLocale, sourceObjectPointer, sourceObjectOptions) {
85
+ const identifyingLocaleProperty = getIdentifyingLocaleProperty(defaultLocale, sourceObjectPointer, sourceObjectOptions);
86
+ if (sourceObjectOptions.key) {
87
+ logger.error(`Source object options key is not allowed for object at path: ${sourceObjectPointer}`);
88
+ return exitSync(1);
89
+ }
90
+ return { identifyingLocaleProperty };
107
91
  }
108
92
  /**
109
- * Generate a mapping of sourceObjectPointer to SourceObjectOptions
110
- * where the sourceObjectPointer is a jsonpointer to the array or object containing
111
- * @param jsonSchema - The json schema to generate the mapping from
112
- * @param originalJson - The original json to generate the mapping from
113
- * @returns A mapping of sourceObjectPointer to SourceObjectOptions
114
- */
115
- export function generateSourceObjectPointers(jsonSchema, originalJson) {
116
- const sourceObjectPointers = Object.entries(jsonSchema).reduce((acc, [sourceObjectPath, sourceObjectOptions]) => {
117
- const sourceObjects = flattenJson(originalJson, [sourceObjectPath]);
118
- Object.entries(sourceObjects).forEach(([pointer, value]) => {
119
- acc[pointer] = {
120
- sourceObjectValue: value,
121
- sourceObjectOptions,
122
- };
123
- });
124
- return acc;
125
- }, {});
126
- return sourceObjectPointers;
93
+ * Generate a mapping of sourceObjectPointer to SourceObjectOptions
94
+ * where the sourceObjectPointer is a jsonpointer to the array or object containing
95
+ * @param jsonSchema - The json schema to generate the mapping from
96
+ * @param originalJson - The original json to generate the mapping from
97
+ * @returns A mapping of sourceObjectPointer to SourceObjectOptions
98
+ */
99
+ function generateSourceObjectPointers(jsonSchema, originalJson) {
100
+ return Object.entries(jsonSchema).reduce((acc, [sourceObjectPath, sourceObjectOptions]) => {
101
+ const sourceObjects = flattenJson(originalJson, [sourceObjectPath]);
102
+ Object.entries(sourceObjects).forEach(([pointer, value]) => {
103
+ acc[pointer] = {
104
+ sourceObjectValue: value,
105
+ sourceObjectOptions
106
+ };
107
+ });
108
+ return acc;
109
+ }, {});
127
110
  }
128
111
  /**
129
- * Validate the json schema for composite or include schemas
130
- * @param options - Additional options containing jsonSchema config
131
- * @param filePath - The path to the file (used for matching jsonSchema)
132
- * @returns The json schema, or null if no schema is found
133
- * @returns exitSync(1) if the json schema is invalid
134
- */
135
- export function validateJsonSchema(options, filePath) {
136
- if (!options.jsonSchema) {
137
- return null;
138
- }
139
- const fileGlobs = Object.keys(options.jsonSchema);
140
- const matchingGlob = fileGlobs.find((fileGlob) => isMatch(path.relative(process.cwd(), filePath), fileGlob));
141
- if (!matchingGlob || !options.jsonSchema[matchingGlob]) {
142
- return null;
143
- }
144
- // Validate includes or composite
145
- const jsonSchema = options.jsonSchema[matchingGlob];
146
- if (jsonSchema.include && jsonSchema.composite) {
147
- logger.error('include and composite cannot be used together in the same JSON schema');
148
- return exitSync(1);
149
- }
150
- if (!jsonSchema.include && !jsonSchema.composite) {
151
- logger.error('No include or composite property found in JSON schema');
152
- return exitSync(1);
153
- }
154
- if (jsonSchema.structuralTransform && !jsonSchema.composite) {
155
- logger.error('structuralTransform requires composite to be defined in the JSON schema');
156
- return exitSync(1);
157
- }
158
- return jsonSchema;
112
+ * Validate the json schema for composite or include schemas
113
+ * @param options - Additional options containing jsonSchema config
114
+ * @param filePath - The path to the file (used for matching jsonSchema)
115
+ * @returns The json schema, or null if no schema is found
116
+ * @returns exitSync(1) if the json schema is invalid
117
+ */
118
+ function validateJsonSchema(options, filePath) {
119
+ if (!options.jsonSchema) return null;
120
+ const matchingGlob = Object.keys(options.jsonSchema).find((fileGlob) => isMatch(path.relative(process.cwd(), filePath), fileGlob));
121
+ if (!matchingGlob || !options.jsonSchema[matchingGlob]) return null;
122
+ const jsonSchema = options.jsonSchema[matchingGlob];
123
+ if (jsonSchema.include && jsonSchema.composite) {
124
+ logger.error("include and composite cannot be used together in the same JSON schema");
125
+ return exitSync(1);
126
+ }
127
+ if (!jsonSchema.include && !jsonSchema.composite) {
128
+ logger.error("No include or composite property found in JSON schema");
129
+ return exitSync(1);
130
+ }
131
+ if (jsonSchema.structuralTransform && !jsonSchema.composite) {
132
+ logger.error("structuralTransform requires composite to be defined in the JSON schema");
133
+ return exitSync(1);
134
+ }
135
+ return jsonSchema;
159
136
  }
160
- const UNSUPPORTED_MINTLIFY_FIELDS = ['$ref'];
137
+ const UNSUPPORTED_MINTLIFY_FIELDS = ["$ref"];
161
138
  /**
162
- * Recursively traverse a JSON value and collect all objects whose key
163
- * matches one of the unsupported field names.
164
- */
165
- function findMintlifyUnsupportedFields(value, fieldNames, pointer = '') {
166
- if (value === null || typeof value !== 'object')
167
- return [];
168
- if (Array.isArray(value)) {
169
- const results = [];
170
- for (let i = 0; i < value.length; i++) {
171
- results.push(...findMintlifyUnsupportedFields(value[i], fieldNames, `${pointer}/${i}`));
172
- }
173
- return results;
174
- }
175
- // Check if this object contains an unsupported field
176
- const objectValue = value;
177
- for (const field of fieldNames) {
178
- if (typeof objectValue[field] === 'string') {
179
- return [{ pointer, field, fieldValue: objectValue[field] }];
180
- }
181
- }
182
- // Recurse into child properties
183
- const results = [];
184
- for (const key of Object.keys(objectValue)) {
185
- results.push(...findMintlifyUnsupportedFields(objectValue[key], fieldNames, `${pointer}/${key}`));
186
- }
187
- return results;
139
+ * Recursively traverse a JSON value and collect all objects whose key
140
+ * matches one of the unsupported field names.
141
+ */
142
+ function findMintlifyUnsupportedFields(value, fieldNames, pointer = "") {
143
+ if (value === null || typeof value !== "object") return [];
144
+ if (Array.isArray(value)) {
145
+ const results = [];
146
+ for (let i = 0; i < value.length; i++) results.push(...findMintlifyUnsupportedFields(value[i], fieldNames, `${pointer}/${i}`));
147
+ return results;
148
+ }
149
+ const objectValue = value;
150
+ for (const field of fieldNames) if (typeof objectValue[field] === "string") return [{
151
+ pointer,
152
+ field,
153
+ fieldValue: objectValue[field]
154
+ }];
155
+ const results = [];
156
+ for (const key of Object.keys(objectValue)) results.push(...findMintlifyUnsupportedFields(objectValue[key], fieldNames, `${pointer}/${key}`));
157
+ return results;
188
158
  }
189
159
  /**
190
- * Detect unsupported fields (e.g. $ref) in Mintlify docs.json files.
191
- * Logs a warning listing the fields found.
192
- */
193
- export function detectMintlifyUnsupportedFields(json, filePath) {
194
- const unsupported = findMintlifyUnsupportedFields(json, UNSUPPORTED_MINTLIFY_FIELDS);
195
- if (unsupported.length > 0) {
196
- const fileName = path.basename(filePath);
197
- const lines = unsupported
198
- .map((u) => chalk.yellow('• ') +
199
- chalk.white(`${u.pointer.replace(/\//g, '.').replace(/^\./, '')}.${u.field}`))
200
- .join('\n');
201
- logger.warn(chalk.yellow(`Mintlify config splitting is not yet supported. The following \`$ref\` fields were detected in \`${fileName}\` and will not be resolved:\n`) + lines);
202
- }
160
+ * Detect unsupported fields (e.g. $ref) in Mintlify docs.json files.
161
+ * Logs a warning listing the fields found.
162
+ */
163
+ function detectMintlifyUnsupportedFields(json, filePath) {
164
+ const unsupported = findMintlifyUnsupportedFields(json, UNSUPPORTED_MINTLIFY_FIELDS);
165
+ if (unsupported.length > 0) {
166
+ const fileName = path.basename(filePath);
167
+ const lines = unsupported.map((u) => chalk.yellow("• ") + chalk.white(`${u.pointer.replace(/\//g, ".").replace(/^\./, "")}.${u.field}`)).join("\n");
168
+ logger.warn(chalk.yellow(`Mintlify config splitting is not yet supported. The following \`$ref\` fields were detected in \`${fileName}\` and will not be resolved:\n`) + lines);
169
+ }
203
170
  }
171
+ //#endregion
172
+ export { detectMintlifyUnsupportedFields, findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, getIdentifyingLocaleProperty, getSourceObjectOptionsArray, getSourceObjectOptionsObject, validateJsonSchema };
173
+
174
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../src/formats/json/utils.ts"],"sourcesContent":["import { getLocaleProperties } from '@generaltranslation/format';\nimport { exitSync } from '../../console/logging.js';\nimport { logger } from '../../console/logger.js';\nimport type { LocaleProperties } from '@generaltranslation/format/types';\nimport {\n AdditionalOptions,\n JsonSchema,\n SourceObjectOptions,\n} from '../../types/index.js';\nimport { flattenJson } from './flattenJson.js';\nimport chalk from 'chalk';\nimport path from 'node:path';\nimport micromatch from 'micromatch';\nimport type { JSONObject, JSONValue } from '../../types/data/json.js';\nimport { getJSONPathMatches } from './jsonPath.js';\nconst { isMatch } = micromatch;\n\ntype MatchingArrayItem = {\n sourceItem: JSONValue;\n keyParentProperty: string | number;\n keyPointer: string;\n index: number;\n};\n\ntype SourceObjectPointerMap = Record<\n string,\n { sourceObjectValue: JSONValue; sourceObjectOptions: SourceObjectOptions }\n>;\n\n// Find the matching source item in an array\n// where the key matches the identifying locale property\n// If no matching item is found, exit with an error\nexport function findMatchingItemArray(\n locale: string,\n sourceObjectOptions: SourceObjectOptions,\n sourceObjectPointer: string,\n sourceObjectValue: JSONValue[]\n): Record<string, MatchingArrayItem> {\n const { identifyingLocaleProperty, localeKeyJsonPath } =\n getSourceObjectOptionsArray(\n locale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n // Use the json pointer key to locate the source item\n const matchingItems: Record<string, MatchingArrayItem> = {};\n for (const [index, item] of sourceObjectValue.entries()) {\n // Get the key candidates\n const keyCandidates = getJSONPathMatches(item, localeKeyJsonPath);\n if (!keyCandidates) {\n logger.error(\n `Source item at path: ${sourceObjectPointer} does not have a key value at path: ${localeKeyJsonPath}`\n );\n return exitSync(1);\n } else if (keyCandidates.length === 0) {\n // If no key candidates, skip the item\n continue;\n } else if (keyCandidates.length > 1) {\n // If multiple key candidates, exit with an error\n logger.error(\n `Source item at path: ${sourceObjectPointer} has multiple matching keys with path: ${localeKeyJsonPath}`\n );\n return exitSync(1);\n } else if (identifyingLocaleProperty !== keyCandidates[0].value) {\n // Validate the key is the identifying locale property\n continue;\n }\n const keyParentProperty = keyCandidates[0].parentProperty;\n if (keyParentProperty === null) {\n logger.error(\n `Source item at path: ${sourceObjectPointer} has a root-level key match with path: ${localeKeyJsonPath}`\n );\n return exitSync(1);\n }\n // Map the index to the source item\n matchingItems[`/${index}`] = {\n sourceItem: item,\n keyParentProperty,\n keyPointer: keyCandidates[0].pointer,\n index,\n };\n }\n return matchingItems;\n}\n\nexport function findMatchingItemObject(\n locale: string,\n sourceObjectPointer: string,\n sourceObjectOptions: SourceObjectOptions,\n sourceObjectValue: JSONObject\n): { sourceItem: JSONValue | undefined; keyParentProperty: string } {\n const { identifyingLocaleProperty } = getSourceObjectOptionsObject(\n locale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n\n // Locate the source item\n if (sourceObjectValue[identifyingLocaleProperty]) {\n return {\n sourceItem: sourceObjectValue[identifyingLocaleProperty],\n keyParentProperty: identifyingLocaleProperty,\n };\n }\n return {\n sourceItem: undefined,\n keyParentProperty: identifyingLocaleProperty,\n };\n}\n\n/**\n * Get the identifying locale property for an object\n * @param locale - The locale to get the identifying locale property for\n * @param sourceObjectPointer - The path to the source object\n * @param sourceObjectOptions - The source object options\n * @returns The identifying locale property\n */\nexport function getIdentifyingLocaleProperty(\n locale: string,\n sourceObjectPointer: string,\n sourceObjectOptions: SourceObjectOptions\n): string {\n // Validate localeProperty\n const localeProperty = sourceObjectOptions.localeProperty || 'code';\n const identifyingLocaleProperty =\n getLocaleProperties(locale)[localeProperty as keyof LocaleProperties];\n if (!identifyingLocaleProperty) {\n logger.error(\n `Source object options localeProperty is not a valid locale property at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n return identifyingLocaleProperty;\n}\n\n/**\n * Get the identifying locale property and the json path to the key for an array\n * @param locale - The locale to get the identifying locale property for\n * @param sourceObjectPointer - The path to the source object\n * @param sourceObjectOptions - The source object options\n * @returns The identifying locale property and the json path to the key\n */\nexport function getSourceObjectOptionsArray(\n locale: string,\n sourceObjectPointer: string,\n sourceObjectOptions: SourceObjectOptions\n): { identifyingLocaleProperty: string; localeKeyJsonPath: string } {\n const identifyingLocaleProperty = getIdentifyingLocaleProperty(\n locale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n const localeKeyJsonPath = sourceObjectOptions.key;\n if (!localeKeyJsonPath) {\n logger.error(\n `Source object options key is required for array at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n return { identifyingLocaleProperty, localeKeyJsonPath };\n}\n\nexport function getSourceObjectOptionsObject(\n defaultLocale: string,\n sourceObjectPointer: string,\n sourceObjectOptions: SourceObjectOptions\n): { identifyingLocaleProperty: string } {\n const identifyingLocaleProperty = getIdentifyingLocaleProperty(\n defaultLocale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n const jsonPathKey = sourceObjectOptions.key;\n if (jsonPathKey) {\n logger.error(\n `Source object options key is not allowed for object at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n return { identifyingLocaleProperty };\n}\n\n/**\n * Generate a mapping of sourceObjectPointer to SourceObjectOptions\n * where the sourceObjectPointer is a jsonpointer to the array or object containing\n * @param jsonSchema - The json schema to generate the mapping from\n * @param originalJson - The original json to generate the mapping from\n * @returns A mapping of sourceObjectPointer to SourceObjectOptions\n */\nexport function generateSourceObjectPointers(\n jsonSchema: {\n [sourceObjectPath: string]: SourceObjectOptions;\n },\n originalJson: JSONValue\n): SourceObjectPointerMap {\n const sourceObjectPointers = Object.entries(jsonSchema).reduce(\n (acc: SourceObjectPointerMap, [sourceObjectPath, sourceObjectOptions]) => {\n const sourceObjects = flattenJson(originalJson, [sourceObjectPath]);\n Object.entries(sourceObjects).forEach(([pointer, value]) => {\n acc[pointer as string] = {\n sourceObjectValue: value,\n sourceObjectOptions,\n };\n });\n return acc;\n },\n {}\n );\n return sourceObjectPointers;\n}\n\n/**\n * Validate the json schema for composite or include schemas\n * @param options - Additional options containing jsonSchema config\n * @param filePath - The path to the file (used for matching jsonSchema)\n * @returns The json schema, or null if no schema is found\n * @returns exitSync(1) if the json schema is invalid\n */\nexport function validateJsonSchema(\n options: AdditionalOptions,\n filePath: string\n): JsonSchema | null {\n if (!options.jsonSchema) {\n return null;\n }\n\n const fileGlobs = Object.keys(options.jsonSchema);\n const matchingGlob = fileGlobs.find((fileGlob) =>\n isMatch(path.relative(process.cwd(), filePath), fileGlob)\n );\n if (!matchingGlob || !options.jsonSchema[matchingGlob]) {\n return null;\n }\n // Validate includes or composite\n const jsonSchema = options.jsonSchema[matchingGlob];\n if (jsonSchema.include && jsonSchema.composite) {\n logger.error(\n 'include and composite cannot be used together in the same JSON schema'\n );\n return exitSync(1);\n }\n\n if (!jsonSchema.include && !jsonSchema.composite) {\n logger.error('No include or composite property found in JSON schema');\n return exitSync(1);\n }\n\n if (jsonSchema.structuralTransform && !jsonSchema.composite) {\n logger.error(\n 'structuralTransform requires composite to be defined in the JSON schema'\n );\n return exitSync(1);\n }\n return jsonSchema;\n}\n\nconst UNSUPPORTED_MINTLIFY_FIELDS = ['$ref'];\n\n/**\n * Recursively traverse a JSON value and collect all objects whose key\n * matches one of the unsupported field names.\n */\nfunction findMintlifyUnsupportedFields(\n value: JSONValue,\n fieldNames: string[],\n pointer: string = ''\n): { pointer: string; field: string; fieldValue: string }[] {\n if (value === null || typeof value !== 'object') return [];\n if (Array.isArray(value)) {\n const results: { pointer: string; field: string; fieldValue: string }[] =\n [];\n for (let i = 0; i < value.length; i++) {\n results.push(\n ...findMintlifyUnsupportedFields(\n value[i],\n fieldNames,\n `${pointer}/${i}`\n )\n );\n }\n return results;\n }\n // Check if this object contains an unsupported field\n const objectValue = value as JSONObject;\n for (const field of fieldNames) {\n if (typeof objectValue[field] === 'string') {\n return [{ pointer, field, fieldValue: objectValue[field] }];\n }\n }\n // Recurse into child properties\n const results: { pointer: string; field: string; fieldValue: string }[] = [];\n for (const key of Object.keys(objectValue)) {\n results.push(\n ...findMintlifyUnsupportedFields(\n objectValue[key],\n fieldNames,\n `${pointer}/${key}`\n )\n );\n }\n return results;\n}\n\n/**\n * Detect unsupported fields (e.g. $ref) in Mintlify docs.json files.\n * Logs a warning listing the fields found.\n */\nexport function detectMintlifyUnsupportedFields(\n json: JSONValue,\n filePath: string\n): void {\n const unsupported = findMintlifyUnsupportedFields(\n json,\n UNSUPPORTED_MINTLIFY_FIELDS\n );\n\n if (unsupported.length > 0) {\n const fileName = path.basename(filePath);\n const lines = unsupported\n .map(\n (u) =>\n chalk.yellow('• ') +\n chalk.white(\n `${u.pointer.replace(/\\//g, '.').replace(/^\\./, '')}.${u.field}`\n )\n )\n .join('\\n');\n logger.warn(\n chalk.yellow(\n `Mintlify config splitting is not yet supported. The following \\`$ref\\` fields were detected in \\`${fileName}\\` and will not be resolved:\\n`\n ) + lines\n );\n }\n}\n"],"mappings":";;;;;;;;;AAeA,MAAM,EAAE,YAAY;AAiBpB,SAAgB,sBACd,QACA,qBACA,qBACA,mBACmC;CACnC,MAAM,EAAE,2BAA2B,sBACjC,4BACE,QACA,qBACA,oBACD;CAEH,MAAM,gBAAmD,EAAE;AAC3D,MAAK,MAAM,CAAC,OAAO,SAAS,kBAAkB,SAAS,EAAE;EAEvD,MAAM,gBAAgB,mBAAmB,MAAM,kBAAkB;AACjE,MAAI,CAAC,eAAe;AAClB,UAAO,MACL,wBAAwB,oBAAoB,sCAAsC,oBACnF;AACD,UAAO,SAAS,EAAE;aACT,cAAc,WAAW,EAElC;WACS,cAAc,SAAS,GAAG;AAEnC,UAAO,MACL,wBAAwB,oBAAoB,yCAAyC,oBACtF;AACD,UAAO,SAAS,EAAE;aACT,8BAA8B,cAAc,GAAG,MAExD;EAEF,MAAM,oBAAoB,cAAc,GAAG;AAC3C,MAAI,sBAAsB,MAAM;AAC9B,UAAO,MACL,wBAAwB,oBAAoB,yCAAyC,oBACtF;AACD,UAAO,SAAS,EAAE;;AAGpB,gBAAc,IAAI,WAAW;GAC3B,YAAY;GACZ;GACA,YAAY,cAAc,GAAG;GAC7B;GACD;;AAEH,QAAO;;AAGT,SAAgB,uBACd,QACA,qBACA,qBACA,mBACkE;CAClE,MAAM,EAAE,8BAA8B,6BACpC,QACA,qBACA,oBACD;AAGD,KAAI,kBAAkB,2BACpB,QAAO;EACL,YAAY,kBAAkB;EAC9B,mBAAmB;EACpB;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C,QAAQ,OAAO,GAAG,CAAC,GAAG,EAAE,QAC1D,CACJ,CACA,KAAK,KAAK;AACb,SAAO,KACL,MAAM,OACJ,oGAAoG,SAAS,gCAC9G,GAAG,MACL"}
@@ -1,111 +1,90 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import YAML from 'yaml';
4
- import { logger } from '../console/logger.js';
5
- import { exitSync } from '../console/logging.js';
1
+ import { logger } from "../console/logger.js";
2
+ import { exitSync } from "../console/logging.js";
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+ import YAML from "yaml";
6
+ //#region src/formats/parseKeyedMetadata.ts
6
7
  /**
7
- * Validates that the metadata key structure is a subset of the source key structure.
8
- * Uses the source to determine whether a metadata value is a leaf (source value is a string)
9
- * or a nested object (source value is an object).
10
- */
8
+ * Validates that the metadata key structure is a subset of the source key structure.
9
+ * Uses the source to determine whether a metadata value is a leaf (source value is a string)
10
+ * or a nested object (source value is an object).
11
+ */
11
12
  function validateMetadataStructure(source, metadata, currentPath = []) {
12
- const errors = [];
13
- for (const key of Object.keys(metadata)) {
14
- const sourceValue = source[key];
15
- const keyPath = [...currentPath, key];
16
- if (sourceValue === undefined) {
17
- errors.push(`Key "${keyPath.join('.')}" does not exist in source`);
18
- continue;
19
- }
20
- // If the source value is a string, this is a translatable leaf — metadata should be a MetadataLeaf
21
- // If the source value is a nested object, recurse
22
- if (typeof sourceValue === 'object' &&
23
- sourceValue !== null &&
24
- !Array.isArray(sourceValue)) {
25
- const metaValue = metadata[key];
26
- if (Array.isArray(metaValue)) {
27
- errors.push(`Key "${keyPath.join('.')}" is an array but source is an object`);
28
- }
29
- else if (typeof metaValue === 'object' && metaValue !== null) {
30
- errors.push(...validateMetadataStructure(sourceValue, metaValue, keyPath));
31
- }
32
- else {
33
- errors.push(`Key "${keyPath.join('.')}" is a primitive but source is an object`);
34
- }
35
- }
36
- }
37
- return errors;
13
+ const errors = [];
14
+ for (const key of Object.keys(metadata)) {
15
+ const sourceValue = source[key];
16
+ const keyPath = [...currentPath, key];
17
+ if (sourceValue === void 0) {
18
+ errors.push(`Key "${keyPath.join(".")}" does not exist in source`);
19
+ continue;
20
+ }
21
+ if (typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue)) {
22
+ const metaValue = metadata[key];
23
+ if (Array.isArray(metaValue)) errors.push(`Key "${keyPath.join(".")}" is an array but source is an object`);
24
+ else if (typeof metaValue === "object" && metaValue !== null) errors.push(...validateMetadataStructure(sourceValue, metaValue, keyPath));
25
+ else errors.push(`Key "${keyPath.join(".")}" is a primitive but source is an object`);
26
+ }
27
+ }
28
+ return errors;
38
29
  }
39
30
  /**
40
- * Detects and parses a companion metadata file for a given source file.
41
- *
42
- * For `translations.json`, looks for `translations.metadata.json`.
43
- * For `translations.yaml` or `translations.yml`, looks for `translations.metadata.yaml` or `.yml`.
44
- *
45
- * @param sourceFilePath - Absolute path to the source file
46
- * @param sourceContent - Parsed source content (object) for structure validation
47
- * @returns Parsed metadata object, or undefined if no companion file exists
48
- */
49
- export function parseKeyedMetadata(sourceFilePath, sourceContent) {
50
- const ext = path.extname(sourceFilePath);
51
- const baseName = sourceFilePath.slice(0, -ext.length);
52
- // Determine companion file path and parser
53
- let metadataFilePath;
54
- let parse;
55
- if (ext === '.json') {
56
- metadataFilePath = `${baseName}.metadata.json`;
57
- parse = JSON.parse;
58
- }
59
- else if (ext === '.yaml' || ext === '.yml') {
60
- const yamlPath = `${baseName}.metadata.yaml`;
61
- const ymlPath = `${baseName}.metadata.yml`;
62
- if (fs.existsSync(yamlPath)) {
63
- metadataFilePath = yamlPath;
64
- }
65
- else if (fs.existsSync(ymlPath)) {
66
- metadataFilePath = ymlPath;
67
- }
68
- parse = YAML.parse;
69
- }
70
- if (!metadataFilePath || !parse) {
71
- return undefined;
72
- }
73
- if (!fs.existsSync(metadataFilePath)) {
74
- return undefined;
75
- }
76
- // Read and parse
77
- let metadataContent;
78
- try {
79
- const raw = fs.readFileSync(metadataFilePath, 'utf8');
80
- const parsed = parse(raw);
81
- if (typeof parsed !== 'object' || parsed === null) {
82
- const relativePath = path.relative(process.cwd(), metadataFilePath);
83
- logger.error(`Metadata file ${relativePath}: Expected an object or array`);
84
- return exitSync(1);
85
- }
86
- metadataContent = parsed;
87
- }
88
- catch {
89
- const relativePath = path.relative(process.cwd(), metadataFilePath);
90
- logger.error(`Metadata file ${relativePath}: File is not parsable`);
91
- return exitSync(1);
92
- }
93
- // Reject if root types don't match (array vs object)
94
- if (Array.isArray(metadataContent) !== Array.isArray(sourceContent)) {
95
- const relativePath = path.relative(process.cwd(), metadataFilePath);
96
- logger.error(`Metadata file ${relativePath}: Root type (array vs object) does not match source`);
97
- return exitSync(1);
98
- }
99
- // Validate structure against source (only for object-rooted files)
100
- if (!Array.isArray(metadataContent) && !Array.isArray(sourceContent)) {
101
- const errors = validateMetadataStructure(sourceContent, metadataContent);
102
- if (errors.length > 0) {
103
- const relativePath = path.relative(process.cwd(), metadataFilePath);
104
- for (const error of errors) {
105
- logger.error(`Metadata file ${relativePath}: ${error}`);
106
- }
107
- return exitSync(1);
108
- }
109
- }
110
- return metadataContent;
31
+ * Detects and parses a companion metadata file for a given source file.
32
+ *
33
+ * For `translations.json`, looks for `translations.metadata.json`.
34
+ * For `translations.yaml` or `translations.yml`, looks for `translations.metadata.yaml` or `.yml`.
35
+ *
36
+ * @param sourceFilePath - Absolute path to the source file
37
+ * @param sourceContent - Parsed source content (object) for structure validation
38
+ * @returns Parsed metadata object, or undefined if no companion file exists
39
+ */
40
+ function parseKeyedMetadata(sourceFilePath, sourceContent) {
41
+ const ext = path.extname(sourceFilePath);
42
+ const baseName = sourceFilePath.slice(0, -ext.length);
43
+ let metadataFilePath;
44
+ let parse;
45
+ if (ext === ".json") {
46
+ metadataFilePath = `${baseName}.metadata.json`;
47
+ parse = JSON.parse;
48
+ } else if (ext === ".yaml" || ext === ".yml") {
49
+ const yamlPath = `${baseName}.metadata.yaml`;
50
+ const ymlPath = `${baseName}.metadata.yml`;
51
+ if (fs.existsSync(yamlPath)) metadataFilePath = yamlPath;
52
+ else if (fs.existsSync(ymlPath)) metadataFilePath = ymlPath;
53
+ parse = YAML.parse;
54
+ }
55
+ if (!metadataFilePath || !parse) return;
56
+ if (!fs.existsSync(metadataFilePath)) return;
57
+ let metadataContent;
58
+ try {
59
+ const raw = fs.readFileSync(metadataFilePath, "utf8");
60
+ const parsed = parse(raw);
61
+ if (typeof parsed !== "object" || parsed === null) {
62
+ const relativePath = path.relative(process.cwd(), metadataFilePath);
63
+ logger.error(`Metadata file ${relativePath}: Expected an object or array`);
64
+ return exitSync(1);
65
+ }
66
+ metadataContent = parsed;
67
+ } catch {
68
+ const relativePath = path.relative(process.cwd(), metadataFilePath);
69
+ logger.error(`Metadata file ${relativePath}: File is not parsable`);
70
+ return exitSync(1);
71
+ }
72
+ if (Array.isArray(metadataContent) !== Array.isArray(sourceContent)) {
73
+ const relativePath = path.relative(process.cwd(), metadataFilePath);
74
+ logger.error(`Metadata file ${relativePath}: Root type (array vs object) does not match source`);
75
+ return exitSync(1);
76
+ }
77
+ if (!Array.isArray(metadataContent) && !Array.isArray(sourceContent)) {
78
+ const errors = validateMetadataStructure(sourceContent, metadataContent);
79
+ if (errors.length > 0) {
80
+ const relativePath = path.relative(process.cwd(), metadataFilePath);
81
+ for (const error of errors) logger.error(`Metadata file ${relativePath}: ${error}`);
82
+ return exitSync(1);
83
+ }
84
+ }
85
+ return metadataContent;
111
86
  }
87
+ //#endregion
88
+ export { parseKeyedMetadata };
89
+
90
+ //# sourceMappingURL=parseKeyedMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseKeyedMetadata.js","names":[],"sources":["../../src/formats/parseKeyedMetadata.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport YAML from 'yaml';\nimport { logger } from '../console/logger.js';\nimport { exitSync } from '../console/logging.js';\nimport type { SourceCode } from '../react/jsx/utils/extractSourceCode.js';\nimport type { JSONObject } from '../types/data/json.js';\n\nexport type MetadataLeaf = {\n context?: string;\n maxChars?: number;\n sourceCode?: Record<string, SourceCode[]>;\n};\n\nexport type MetadataObject = { [key: string]: MetadataLeaf | MetadataObject };\nexport type MetadataArray = (MetadataLeaf | MetadataObject)[];\nexport type KeyedMetadata = MetadataObject | MetadataArray;\n\n/**\n * Validates that the metadata key structure is a subset of the source key structure.\n * Uses the source to determine whether a metadata value is a leaf (source value is a string)\n * or a nested object (source value is an object).\n */\nfunction validateMetadataStructure(\n source: JSONObject,\n metadata: MetadataObject,\n currentPath: string[] = []\n): string[] {\n const errors: string[] = [];\n\n for (const key of Object.keys(metadata)) {\n const sourceValue = source[key];\n const keyPath = [...currentPath, key];\n\n if (sourceValue === undefined) {\n errors.push(`Key \"${keyPath.join('.')}\" does not exist in source`);\n continue;\n }\n\n // If the source value is a string, this is a translatable leaf — metadata should be a MetadataLeaf\n // If the source value is a nested object, recurse\n if (\n typeof sourceValue === 'object' &&\n sourceValue !== null &&\n !Array.isArray(sourceValue)\n ) {\n const metaValue = metadata[key];\n if (Array.isArray(metaValue)) {\n errors.push(\n `Key \"${keyPath.join('.')}\" is an array but source is an object`\n );\n } else if (typeof metaValue === 'object' && metaValue !== null) {\n errors.push(\n ...validateMetadataStructure(\n sourceValue as JSONObject,\n metaValue as MetadataObject,\n keyPath\n )\n );\n } else {\n errors.push(\n `Key \"${keyPath.join('.')}\" is a primitive but source is an object`\n );\n }\n }\n }\n\n return errors;\n}\n\n/**\n * Detects and parses a companion metadata file for a given source file.\n *\n * For `translations.json`, looks for `translations.metadata.json`.\n * For `translations.yaml` or `translations.yml`, looks for `translations.metadata.yaml` or `.yml`.\n *\n * @param sourceFilePath - Absolute path to the source file\n * @param sourceContent - Parsed source content (object) for structure validation\n * @returns Parsed metadata object, or undefined if no companion file exists\n */\nexport function parseKeyedMetadata(\n sourceFilePath: string,\n sourceContent: JSONObject | JSONObject[]\n): KeyedMetadata | undefined {\n const ext = path.extname(sourceFilePath);\n const baseName = sourceFilePath.slice(0, -ext.length);\n\n // Determine companion file path and parser\n let metadataFilePath: string | undefined;\n let parse: ((content: string) => JSONObject) | undefined;\n\n if (ext === '.json') {\n metadataFilePath = `${baseName}.metadata.json`;\n parse = JSON.parse;\n } else if (ext === '.yaml' || ext === '.yml') {\n const yamlPath = `${baseName}.metadata.yaml`;\n const ymlPath = `${baseName}.metadata.yml`;\n if (fs.existsSync(yamlPath)) {\n metadataFilePath = yamlPath;\n } else if (fs.existsSync(ymlPath)) {\n metadataFilePath = ymlPath;\n }\n parse = YAML.parse;\n }\n\n if (!metadataFilePath || !parse) {\n return undefined;\n }\n\n if (!fs.existsSync(metadataFilePath)) {\n return undefined;\n }\n\n // Read and parse\n let metadataContent: KeyedMetadata;\n try {\n const raw = fs.readFileSync(metadataFilePath, 'utf8');\n const parsed = parse(raw);\n if (typeof parsed !== 'object' || parsed === null) {\n const relativePath = path.relative(process.cwd(), metadataFilePath);\n logger.error(\n `Metadata file ${relativePath}: Expected an object or array`\n );\n return exitSync(1);\n }\n metadataContent = parsed as KeyedMetadata;\n } catch {\n const relativePath = path.relative(process.cwd(), metadataFilePath);\n logger.error(`Metadata file ${relativePath}: File is not parsable`);\n return exitSync(1);\n }\n\n // Reject if root types don't match (array vs object)\n if (Array.isArray(metadataContent) !== Array.isArray(sourceContent)) {\n const relativePath = path.relative(process.cwd(), metadataFilePath);\n logger.error(\n `Metadata file ${relativePath}: Root type (array vs object) does not match source`\n );\n return exitSync(1);\n }\n\n // Validate structure against source (only for object-rooted files)\n if (!Array.isArray(metadataContent) && !Array.isArray(sourceContent)) {\n const errors = validateMetadataStructure(sourceContent, metadataContent);\n if (errors.length > 0) {\n const relativePath = path.relative(process.cwd(), metadataFilePath);\n for (const error of errors) {\n logger.error(`Metadata file ${relativePath}: ${error}`);\n }\n return exitSync(1);\n }\n }\n\n return metadataContent;\n}\n"],"mappings":";;;;;;;;;;;AAuBA,SAAS,0BACP,QACA,UACA,cAAwB,EAAE,EAChB;CACV,MAAM,SAAmB,EAAE;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