@visulima/vis 2.0.2 → 3.0.1

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 (306) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE.md +5395 -4307
  3. package/dist/bin.js +1 -1
  4. package/dist/binx.js +2 -2
  5. package/dist/config/index.js +1 -1
  6. package/dist/packem_chunks/CONFIG_FILES.js +6 -6
  7. package/dist/packem_chunks/DEFAULT_CLEAN_KEEP.js +1 -1
  8. package/dist/packem_chunks/agent-instructions.js +7 -7
  9. package/dist/packem_chunks/bloom-status.js +2 -2
  10. package/dist/packem_chunks/bloom-sync.js +2 -2
  11. package/dist/packem_chunks/cache-attestation.js +1 -1
  12. package/dist/packem_chunks/catalog-detector.js +1 -1
  13. package/dist/packem_chunks/catalog.js +87 -111
  14. package/dist/packem_chunks/cli-exec.js +1 -1
  15. package/dist/packem_chunks/cli-main.js +192 -217
  16. package/dist/packem_chunks/defineReleasePlugin.js +3 -3
  17. package/dist/packem_chunks/detect.js +8 -3
  18. package/dist/packem_chunks/devtools.js +1 -1
  19. package/dist/packem_chunks/discord.js +4 -4
  20. package/dist/packem_chunks/dispatch.js +4 -4
  21. package/dist/packem_chunks/doctor-probe.js +2 -2
  22. package/dist/packem_chunks/extra-files.js +3 -3
  23. package/dist/packem_chunks/fix.js +11 -11
  24. package/dist/packem_chunks/git.js +3 -3
  25. package/dist/packem_chunks/group-tags.js +1 -1
  26. package/dist/packem_chunks/handler.js +1 -1
  27. package/dist/packem_chunks/handler10.js +5 -5
  28. package/dist/packem_chunks/handler11.js +1 -1
  29. package/dist/packem_chunks/handler12.js +16 -16
  30. package/dist/packem_chunks/handler13.js +5 -5
  31. package/dist/packem_chunks/handler14.js +1 -1
  32. package/dist/packem_chunks/handler15.js +1 -1
  33. package/dist/packem_chunks/handler16.js +1 -1
  34. package/dist/packem_chunks/handler17.js +1 -1
  35. package/dist/packem_chunks/handler18.js +1 -1
  36. package/dist/packem_chunks/handler19.js +5 -5
  37. package/dist/packem_chunks/handler2.js +1 -1
  38. package/dist/packem_chunks/handler20.js +2 -2
  39. package/dist/packem_chunks/handler21.js +2 -2
  40. package/dist/packem_chunks/handler22.js +8 -8
  41. package/dist/packem_chunks/handler23.js +1 -1
  42. package/dist/packem_chunks/handler24.js +1 -1
  43. package/dist/packem_chunks/handler25.js +1 -1
  44. package/dist/packem_chunks/handler26.js +5 -5
  45. package/dist/packem_chunks/handler27.js +1 -1
  46. package/dist/packem_chunks/handler28.js +3 -3
  47. package/dist/packem_chunks/handler29.js +1 -1
  48. package/dist/packem_chunks/handler3.js +2 -2
  49. package/dist/packem_chunks/handler30.js +1 -1
  50. package/dist/packem_chunks/handler31.js +2 -2
  51. package/dist/packem_chunks/handler32.js +2 -2
  52. package/dist/packem_chunks/handler33.js +2 -2
  53. package/dist/packem_chunks/handler34.js +3 -3
  54. package/dist/packem_chunks/handler35.js +5 -5
  55. package/dist/packem_chunks/handler36.js +1 -1
  56. package/dist/packem_chunks/handler37.js +2 -2
  57. package/dist/packem_chunks/handler38.js +6 -6
  58. package/dist/packem_chunks/handler39.js +8 -8
  59. package/dist/packem_chunks/handler4.js +4 -4
  60. package/dist/packem_chunks/handler40.js +34 -34
  61. package/dist/packem_chunks/handler41.js +5 -5
  62. package/dist/packem_chunks/handler42.js +4 -4
  63. package/dist/packem_chunks/handler43.js +3 -3
  64. package/dist/packem_chunks/handler44.js +2 -2
  65. package/dist/packem_chunks/handler45.js +1 -1
  66. package/dist/packem_chunks/handler46.js +1 -1
  67. package/dist/packem_chunks/handler47.js +1 -1
  68. package/dist/packem_chunks/handler48.js +3 -3
  69. package/dist/packem_chunks/handler49.js +1 -1
  70. package/dist/packem_chunks/handler5.js +6 -6
  71. package/dist/packem_chunks/handler50.js +6 -6
  72. package/dist/packem_chunks/handler51.js +13 -13
  73. package/dist/packem_chunks/handler52.js +3 -3
  74. package/dist/packem_chunks/handler53.js +5 -5
  75. package/dist/packem_chunks/handler54.js +2 -2
  76. package/dist/packem_chunks/handler55.js +1 -1
  77. package/dist/packem_chunks/handler56.js +4 -4
  78. package/dist/packem_chunks/handler57.js +5 -5
  79. package/dist/packem_chunks/handler58.js +5 -5
  80. package/dist/packem_chunks/handler59.js +8 -8
  81. package/dist/packem_chunks/handler6.js +7 -7
  82. package/dist/packem_chunks/handler60.js +3 -3
  83. package/dist/packem_chunks/handler61.js +21 -21
  84. package/dist/packem_chunks/handler62.js +12 -12
  85. package/dist/packem_chunks/handler63.js +3 -3
  86. package/dist/packem_chunks/handler64.js +5 -5
  87. package/dist/packem_chunks/handler65.js +8 -8
  88. package/dist/packem_chunks/handler66.js +2 -2
  89. package/dist/packem_chunks/handler67.js +21 -21
  90. package/dist/packem_chunks/handler68.js +21 -21
  91. package/dist/packem_chunks/handler69.js +30 -30
  92. package/dist/packem_chunks/handler7.js +1 -1
  93. package/dist/packem_chunks/handler70.js +9 -9
  94. package/dist/packem_chunks/handler71.js +17 -17
  95. package/dist/packem_chunks/handler72.js +104 -104
  96. package/dist/packem_chunks/handler73.js +20 -20
  97. package/dist/packem_chunks/handler74.js +45 -45
  98. package/dist/packem_chunks/handler75.js +27 -3
  99. package/dist/packem_chunks/handler76.js +3 -27
  100. package/dist/packem_chunks/handler77.js +68 -68
  101. package/dist/packem_chunks/handler78.js +30 -30
  102. package/dist/packem_chunks/handler8.js +1 -1
  103. package/dist/packem_chunks/handler9.js +1 -1
  104. package/dist/packem_chunks/heal-accept.js +9 -9
  105. package/dist/packem_chunks/heal.js +11 -11
  106. package/dist/packem_chunks/help-command.js +7 -63
  107. package/dist/packem_chunks/index.js +1 -1
  108. package/dist/packem_chunks/index2.js +48 -802
  109. package/dist/packem_chunks/index3.js +3 -7
  110. package/dist/packem_chunks/index4.js +803 -134
  111. package/dist/packem_chunks/index5.js +7 -73
  112. package/dist/packem_chunks/index6.js +73 -0
  113. package/dist/packem_chunks/index7.js +135 -0
  114. package/dist/packem_chunks/interface.js +2 -2
  115. package/dist/packem_chunks/keys-refresh.js +4 -4
  116. package/dist/packem_chunks/lean.js +3 -3
  117. package/dist/packem_chunks/list.js +3 -3
  118. package/dist/packem_chunks/loader.js +4 -4
  119. package/dist/packem_chunks/loader2.js +1 -1
  120. package/dist/packem_chunks/orchestrator.js +27 -27
  121. package/dist/packem_chunks/pre-mode.js +2 -2
  122. package/dist/packem_chunks/print-config.js +1 -1
  123. package/dist/packem_chunks/prompts.js +7 -7
  124. package/dist/packem_chunks/prune.js +3 -3
  125. package/dist/packem_chunks/publish-guards.js +1 -1
  126. package/dist/packem_chunks/resolveFormatter.js +5 -5
  127. package/dist/packem_chunks/run.js +1 -1
  128. package/dist/packem_chunks/security.js +1 -1
  129. package/dist/packem_chunks/shell-runner.js +1 -1
  130. package/dist/packem_chunks/slack.js +2 -2
  131. package/dist/packem_chunks/snapshot.js +2 -2
  132. package/dist/packem_chunks/stage-publisher.js +1 -1
  133. package/dist/packem_chunks/staged-registry.js +2 -2
  134. package/dist/packem_chunks/state.js +3 -3
  135. package/dist/packem_chunks/status.js +2 -2
  136. package/dist/packem_chunks/success-walk.js +4 -4
  137. package/dist/packem_chunks/sync.js +2 -2
  138. package/dist/packem_chunks/sync2.js +2 -2
  139. package/dist/packem_chunks/tar.js +3 -3
  140. package/dist/packem_chunks/tripwire.js +2 -2
  141. package/dist/packem_chunks/ts-loader.js +5 -9
  142. package/dist/packem_chunks/verify-lockfile.js +2 -2
  143. package/dist/packem_chunks/version-resolver.js +2 -2
  144. package/dist/packem_chunks/webhook.js +1 -1
  145. package/dist/packem_chunks/workflow-templates.js +5 -5
  146. package/dist/packem_chunks/workspace.js +2 -2
  147. package/dist/packem_shared/ReleaseClient-DAvbxCdo.js +1 -0
  148. package/dist/packem_shared/Table-DyORjLji-CC9cYgCG.js +11 -0
  149. package/dist/packem_shared/{VisReleaseError-DMGRBTNO.js → VisReleaseError-DZtgcKf8.js} +1 -1
  150. package/dist/packem_shared/_commonjsHelpers-DTfxOvZk.js +1 -0
  151. package/dist/packem_shared/advisories-CyDqzi5j.js +1 -0
  152. package/dist/packem_shared/affected-selection-DPQR-Bd3.js +1 -0
  153. package/dist/packem_shared/affected-shas-Dd0P7fGD.js +1 -0
  154. package/dist/packem_shared/ai-analysis-DSQQDFU9.js +68 -0
  155. package/dist/packem_shared/ai-fix-6nXZbecQ.js +43 -0
  156. package/dist/packem_shared/augment-COAiXSIx.js +4 -0
  157. package/dist/packem_shared/bin-wafzkjaB.js +1 -0
  158. package/dist/packem_shared/build-scripts-pdVmqXRm.js +1 -0
  159. package/dist/packem_shared/clean-DRiLimTx.js +1 -0
  160. package/dist/packem_shared/command-runtime-CiLVo4ED.js +1 -0
  161. package/dist/packem_shared/{compile-cache-B_Vf_WxT.js → compile-cache-DoMHRsRZ.js} +1 -1
  162. package/dist/packem_shared/createAdapter-F7GidOzU.js +1 -0
  163. package/dist/packem_shared/createVersionActions-ByaJ1Nbv.js +1 -0
  164. package/dist/packem_shared/cyclonedx-C_ezHg8b.js +4 -0
  165. package/dist/packem_shared/dependency-scan-DBH2Qo4I.js +1 -0
  166. package/dist/packem_shared/docker-Br_iFmI-.js +59 -0
  167. package/dist/packem_shared/failure-log-D92tM0ie.js +2 -0
  168. package/dist/packem_shared/formatBytes-BHAzNIrn-DFIppnY0.js +4 -0
  169. package/dist/packem_shared/getRandomSpinner-4ZEcbTYv-DCyIuj19.js +1 -0
  170. package/dist/packem_shared/giget-CVyyR7x8.js +2 -0
  171. package/dist/packem_shared/glob-Cyk1H9ZL-ox19CSsT.js +1 -0
  172. package/dist/packem_shared/index-B4AjSxHU.js +1 -0
  173. package/dist/packem_shared/index-BisalDCf.js +39 -0
  174. package/dist/packem_shared/{index-BWl4DbMp.js → index-BjdW45xX.js} +1 -1
  175. package/dist/packem_shared/index-DHD8wb6Z.js +22 -0
  176. package/dist/packem_shared/index-DXPSWMbG.js +1 -0
  177. package/dist/packem_shared/index.server-CwSgbeN7.js +2 -0
  178. package/dist/packem_shared/isAccessibleSync-DYKTrrvc-CSnBISfV.js +1 -0
  179. package/dist/packem_shared/license-DvlYdo6T.js +1 -0
  180. package/dist/packem_shared/lifecycle-CfTZQHOG.js +2 -0
  181. package/dist/packem_shared/lockfile-35RFsJDs.js +1 -0
  182. package/dist/packem_shared/lockfile-DhHAaHN5.js +1 -0
  183. package/dist/packem_shared/main-BjJN8kWj.js +1 -0
  184. package/dist/packem_shared/manifests-BNSmpPF_.js +1 -0
  185. package/dist/packem_shared/min-release-age-ChzTC7_I.js +34 -0
  186. package/dist/packem_shared/missing-package-json-C0keIt78.js +1 -0
  187. package/dist/packem_shared/native-config-sync-BSzU4qUO.js +21 -0
  188. package/dist/packem_shared/osv-bloom-5wDAoZ1e.js +2 -0
  189. package/dist/packem_shared/otelPlugin-D8LL2-4L.js +1 -0
  190. package/dist/packem_shared/package-version-BJkg7-6H.js +4 -0
  191. package/dist/packem_shared/packument-C55kVxcQ.js +1 -0
  192. package/dist/packem_shared/{peer-warnings-BXAzXqY3.js → peer-warnings-CmYSxvql.js} +1 -1
  193. package/dist/packem_shared/pm-runner-de-jCq8q.js +1 -0
  194. package/dist/packem_shared/project-name-filter-BeREbPMI.js +7 -0
  195. package/dist/packem_shared/{prompt-BSAy8SMH.js → prompt-DMzaQEVa.js} +1 -1
  196. package/dist/packem_shared/provenance-CvfQEJPQ.js +1 -0
  197. package/dist/packem_shared/readJsonSync-CbryXYxN-B2aSeDpC.js +1 -0
  198. package/dist/packem_shared/registry-keys-DmBrAlhg.js +1 -0
  199. package/dist/packem_shared/resolve-explicit-COmP7eqr.js +5 -0
  200. package/dist/packem_shared/resolve-runtime-C7NBCA1C.js +1 -0
  201. package/dist/packem_shared/run-file-jMngGQhs.js +1 -0
  202. package/dist/packem_shared/runtime-check-BklgEMkC.js +1 -0
  203. package/dist/packem_shared/s1ngularity-RZOHbGrE.js +1 -0
  204. package/dist/packem_shared/scan-progress-C9nMDLis.js +2 -0
  205. package/dist/packem_shared/selectors-B7lSFz7l.js +3 -0
  206. package/dist/packem_shared/signatures-oZ_2IneN.js +2 -0
  207. package/dist/packem_shared/{slug-DoueYuLo.js → slug-OBHcH7wV.js} +1 -1
  208. package/dist/packem_shared/spinner-CbJfWYwB.js +1 -0
  209. package/dist/packem_shared/sticky-comment-DjhyCIZt.js +1 -0
  210. package/dist/packem_shared/subtree-DtmcKAJK.js +2 -0
  211. package/dist/packem_shared/symbols-BXDZ_sKt.js +1 -0
  212. package/dist/packem_shared/tabs-BilwonkM.js +1 -0
  213. package/dist/packem_shared/target-merge-D1xbylFw.js +4 -0
  214. package/dist/packem_shared/target-options-d_rIrLyq.js +1 -0
  215. package/dist/packem_shared/toolchain-DY11tPCw.js +5 -0
  216. package/dist/packem_shared/typosquats-D8ppc5kr.js +1 -0
  217. package/dist/packem_shared/use-measured-height-BPQg2q_p.js +1 -0
  218. package/dist/packem_shared/utils-DQFHJn72.js +1 -0
  219. package/dist/packem_shared/verify-D8wYvB85.js +1 -0
  220. package/dist/packem_shared/vis-update-app-ngwL2mRv.js +1 -0
  221. package/dist/packem_shared/vis-user-error-jhNwmkZp.js +30 -0
  222. package/dist/packem_shared/watch-Dswvj6Zp.js +1 -0
  223. package/dist/packem_shared/watch-loop-COWvvSbR.js +11 -0
  224. package/dist/packem_shared/writeFileSync-DJoHk3Ks-CgQ-VNNT.js +1 -0
  225. package/dist/release/core/changelog/index.d.ts +62 -2
  226. package/dist/release/core/package-managers/index.d.ts +25 -1
  227. package/dist/release/core/package-managers/index.js +1 -1
  228. package/dist/release/core/version-actions/index.d.ts +47 -2
  229. package/dist/release/core/version-actions/index.js +1 -1
  230. package/dist/release/index.d.ts +100 -1
  231. package/dist/release/index.js +1 -1
  232. package/dist/release/plugin-sdk.d.ts +16 -1
  233. package/dist/release/plugin-sdk.js +1 -1
  234. package/dist/release/presets.js +1 -1
  235. package/dist/release/types.js +1 -1
  236. package/dist/runtime/preload.js +1 -1
  237. package/index.d.ts +204 -204
  238. package/index.js +26 -26
  239. package/package.json +13 -13
  240. package/dist/packem_chunks/detect2.js +0 -8
  241. package/dist/packem_chunks/registry.js +0 -48
  242. package/dist/packem_shared/ReleaseClient-BY4OZNCK.js +0 -1
  243. package/dist/packem_shared/_commonjsHelpers-B5Y90VFO.js +0 -1
  244. package/dist/packem_shared/advisories-CCBGdU8U.js +0 -1
  245. package/dist/packem_shared/affected-selection-Dj-ymxhw.js +0 -1
  246. package/dist/packem_shared/affected-shas-PwkVbPch.js +0 -1
  247. package/dist/packem_shared/ai-analysis-bGCAc1jR.js +0 -68
  248. package/dist/packem_shared/ai-fix-DV5-dHBY.js +0 -43
  249. package/dist/packem_shared/augment-24KX2nkI.js +0 -4
  250. package/dist/packem_shared/bin-CtzhnYMp.js +0 -1
  251. package/dist/packem_shared/build-scripts-w4SNeR7D.js +0 -1
  252. package/dist/packem_shared/clean-DWjQl14S.js +0 -1
  253. package/dist/packem_shared/command-runtime-BLFPUYAT.js +0 -1
  254. package/dist/packem_shared/createAdapter-bU4DIP3F.js +0 -1
  255. package/dist/packem_shared/createVersionActions-BK43SNDH.js +0 -1
  256. package/dist/packem_shared/cyclonedx-C4KaVTn1.js +0 -4
  257. package/dist/packem_shared/dependency-scan-D_ona0Qm.js +0 -1
  258. package/dist/packem_shared/docker-DaVs-9wK.js +0 -59
  259. package/dist/packem_shared/en-D3CfXlO7.js +0 -27
  260. package/dist/packem_shared/failure-log-CTneNcio.js +0 -2
  261. package/dist/packem_shared/giget-CAxjpwew.js +0 -2
  262. package/dist/packem_shared/glob-BUjyjdE8-C4M8e02u.js +0 -1
  263. package/dist/packem_shared/index-BAe6e0XE.js +0 -1
  264. package/dist/packem_shared/index-CTMU29dI.js +0 -1
  265. package/dist/packem_shared/index-uBVnF4ji.js +0 -35
  266. package/dist/packem_shared/index.server-CusjRLCh.js +0 -2
  267. package/dist/packem_shared/license-t5KnNX6v.js +0 -1
  268. package/dist/packem_shared/lifecycle-B8A2T3gx.js +0 -2
  269. package/dist/packem_shared/lockfile-Bccery3L.js +0 -1
  270. package/dist/packem_shared/main-D_cam4hv.js +0 -1
  271. package/dist/packem_shared/manifests-BDkwiVbh.js +0 -1
  272. package/dist/packem_shared/min-release-age-OaYpLwux.js +0 -34
  273. package/dist/packem_shared/missing-package-json-BqS-OnKd.js +0 -1
  274. package/dist/packem_shared/native-config-sync-Ds1FtcrM.js +0 -21
  275. package/dist/packem_shared/osv-bloom-pKp7urSB.js +0 -2
  276. package/dist/packem_shared/otelPlugin-DmKDBaPo.js +0 -1
  277. package/dist/packem_shared/package-version-C47v64aB.js +0 -4
  278. package/dist/packem_shared/packument-HBVbyf7x.js +0 -1
  279. package/dist/packem_shared/pm-runner-C6eTANt1.js +0 -1
  280. package/dist/packem_shared/project-name-filter-CJ3XX2TI.js +0 -7
  281. package/dist/packem_shared/provenance-D4Cza8cp.js +0 -1
  282. package/dist/packem_shared/public-api-WqUCiyIe.js +0 -131
  283. package/dist/packem_shared/readJsonSync-DweZd5ZA-0eZh9sGm.js +0 -1
  284. package/dist/packem_shared/registry-keys-C0ez2VND.js +0 -1
  285. package/dist/packem_shared/resolve-explicit-BbT764KS.js +0 -5
  286. package/dist/packem_shared/resolve-runtime-D_vZovbB.js +0 -1
  287. package/dist/packem_shared/run-file-DyPFFN9U.js +0 -1
  288. package/dist/packem_shared/runtime-check-D4um-yQq.js +0 -1
  289. package/dist/packem_shared/s1ngularity-St6dhKiq.js +0 -1
  290. package/dist/packem_shared/scan-progress-q-N2JtIp.js +0 -2
  291. package/dist/packem_shared/selectors-Ce_6UAoY.js +0 -3
  292. package/dist/packem_shared/signatures-Dyeyg1q9.js +0 -2
  293. package/dist/packem_shared/sticky-comment-D6_7-w8T.js +0 -1
  294. package/dist/packem_shared/subtree-DSm0QEoE.js +0 -2
  295. package/dist/packem_shared/symbols-DPTlrJ3B.js +0 -1
  296. package/dist/packem_shared/target-merge-Cfy7c__2.js +0 -11
  297. package/dist/packem_shared/target-options-7XcbqGDe.js +0 -1
  298. package/dist/packem_shared/toolchain-C_pNMBM6.js +0 -5
  299. package/dist/packem_shared/typosquats-xzcAGPiM.js +0 -1
  300. package/dist/packem_shared/use-measured-height-CBjN0fle.js +0 -1
  301. package/dist/packem_shared/utils-CRueU43T.js +0 -1
  302. package/dist/packem_shared/verify-Dve9PQj3.js +0 -1
  303. package/dist/packem_shared/vis-update-app-DMAC2pPf.js +0 -1
  304. package/dist/packem_shared/vis-user-error-xmha3L4n.js +0 -30
  305. package/dist/packem_shared/watch-BXOOX7lx.js +0 -1
  306. package/dist/packem_shared/watch-loop-Q7UpkVbr.js +0 -11
@@ -1,17 +1,17 @@
1
- import{z as F,J as P,b as S,w as b,j as I,q as U,d as T}from"../packem_shared/index-uBVnF4ji.js";import _ from"./index.js";import{v as J,k as q}from"./catalog.js";import{n as M}from"../packem_shared/manifests-BDkwiVbh.js";import{Q as C,T as B}from"./cli-main.js";import{s as z}from"../packem_shared/glob-BUjyjdE8-C4M8e02u.js";const K=(e,t)=>{const o=t.replace(/^\.?\//,"");return o===""||o==="."?`/${e}/`:e===""||e==="."?`/${o}`:`/${e}/${o}`},v=(e,t,o=[])=>{const s=[],n=new Set;for(const[r,a]of Object.entries(t?.globalPaths??{}))s.push({owners:a,path:r,source:"project-json"}),n.add(r);for(const[r,a]of Object.entries(e.projects)){const i=a.owners??[];for(const c of i){const f=K(a.root??r,c.path);s.push({channel:c.channel,owners:c.owners,path:f,projectId:r,source:"project-json"}),n.add(f)}}for(const r of o)n.has(r.path)||(s.push(r),n.add(r.path));return(t?.orderBy??"file-source")==="project-id"?s.sort((r,a)=>(r.projectId??"").localeCompare(a.projectId??"")||r.path.localeCompare(a.path)):s.sort((r,a)=>r.path.localeCompare(a.path)),s},H="Update each project's project.json `owners` field and re-run the command.",Q=e=>["# CODEOWNERS — generated by `vis sync codeowners`. Do not edit by hand.",e?`# Re-run with: ${e}`:`# ${H}`,""],W=e=>{const t=[];for(const o of e){const s=o.owners.join(" "),n=o.channel?` # notify: ${o.channel}`:"";t.push(`${o.path} ${s}${n}`)}return t},Y=(e,t={})=>[...Q(t.regenerationCommand),...W(e),""].join(`
2
- `),O={begin:"# BEGIN vis-codeowners",end:"# END vis-codeowners"},V=(e,t=O,o={})=>{const s=o.regenerationCommand?`# Generated by vis sync codeowners — re-run with: ${o.regenerationCommand}`:"# Generated by `vis sync codeowners` — do not edit by hand.";return[t.begin,s,...W(e),t.end].join(`
3
- `)},X=(e,t,o=O)=>{const s=e.indexOf(o.begin),n=e.indexOf(o.end);if(s!==-1&&n!==-1&&n>s){const a=e.slice(0,s),i=n+o.end.length,c=e.slice(i);return`${a}${t}${c}`}const r=e.replace(/\s+$/u,"");return`${r.length===0?"":`${r}
1
+ import{z as A,m as G,a as I,e as b}from"../packem_shared/index-DHD8wb6Z.js";import x from"./index.js";import{d as U,x as F}from"./catalog.js";import{n as B}from"../packem_shared/manifests-BNSmpPF_.js";import{_ as E,$ as J}from"./cli-main.js";import{l as K}from"../packem_shared/glob-Cyk1H9ZL-ox19CSsT.js";import{U as R,h as q}from"../packem_shared/writeFileSync-DJoHk3Ks-CgQ-VNNT.js";import{T as M}from"../packem_shared/target-merge-D1xbylFw.js";const H=(e,t)=>{const n=t.replace(/^\.?\//,"");return n===""||n==="."?`/${e}/`:e===""||e==="."?`/${n}`:`/${e}/${n}`},N=(e,t,n=[])=>{const s=[],o=new Set;for(const[c,r]of Object.entries(t?.globalPaths??{}))s.push({owners:r,path:c,source:"project-json"}),o.add(c);for(const[c,r]of Object.entries(e.projects)){const a=r.owners??[];for(const f of a){const l=H(r.root??c,f.path);s.push({channel:f.channel,owners:f.owners,path:l,projectId:c,source:"project-json"}),o.add(l)}}for(const c of n)o.has(c.path)||(s.push(c),o.add(c.path));return(t?.orderBy??"file-source")==="project-id"?s.sort((c,r)=>(c.projectId??"").localeCompare(r.projectId??"")||c.path.localeCompare(r.path)):s.sort((c,r)=>c.path.localeCompare(r.path)),s},z="Update each project's project.json `owners` field and re-run the command.",Y=e=>["# CODEOWNERS — generated by `vis sync codeowners`. Do not edit by hand.",e?`# Re-run with: ${e}`:`# ${z}`,""],D=e=>{const t=[];for(const n of e){const s=n.owners.join(" "),o=n.channel?` # notify: ${n.channel}`:"";t.push(`${n.path} ${s}${o}`)}return t},Q=(e,t={})=>[...Y(t.regenerationCommand),...D(e),""].join(`
2
+ `),O={begin:"# BEGIN vis-codeowners",end:"# END vis-codeowners"},X=(e,t=O,n={})=>{const s=n.regenerationCommand?`# Generated by vis sync codeowners — re-run with: ${n.regenerationCommand}`:"# Generated by `vis sync codeowners` — do not edit by hand.";return[t.begin,s,...D(e),t.end].join(`
3
+ `)},Z=(e,t,n=O)=>{const s=e.indexOf(n.begin),o=e.indexOf(n.end);if(s!==-1&&o!==-1&&o>s){const r=e.slice(0,s),a=o+n.end.length,f=e.slice(a);return`${r}${t}${f}`}const i=e.replace(/\s+$/u,"");return`${i.length===0?"":`${i}
4
4
 
5
5
  `}${t}
6
- `},Z=["**/CODEOWNERS"],ee=["**/node_modules/**","**/dist/**","**/build/**","**/coverage/**","**/.git/**","**/.next/**","**/.nuxt/**"],te=e=>{const t=[];for(const o of e.split(/\r?\n/u)){const s=o.indexOf("#"),n=(s===-1?o:o.slice(0,s)).trim();if(n.length===0)continue;const r=n.split(/\s+/u);if(r.length<2)continue;const[a,...i]=r,c=i.filter(f=>f.length>0);!a||c.length===0||t.push({owners:c,path:a})}return t},oe=(e,t)=>{const o=t.replace(/^\.\/?/,"").replace(/\/$/,"");return e.startsWith("/")?o===""?e:`/${o}${e}`:o===""?`/${e}`:`/${o}/${e}`},ne=async(e,t,o)=>{const s=t&&t.length>0?[...t]:[...Z],n=[...ee];if(o){const i=o.replace(/^\.\/?/,"").replace(/^\/+/,"");i.length>0&&n.push(i)}const r=await z(s,{absolute:!0,cwd:e,ignore:n}),a=[];for(const i of r){let c;try{c=F(i)}catch{continue}const f=P(i),h=S(e,f);for(const p of te(c))a.push({owners:p.owners,path:oe(p.path,h)})}return a},re=/^(?:https?:\/\/)?(?:www\.)?github\.com\/([^/?#]+)/iu,se=e=>{if(!e)return;const t=e.match(re);if(!t?.[1])return;const o=t[1].trim();if(!(o===""||o.includes(" ")))return`@${o.replace(/^@/,"")}`},ie=(e,t)=>{const o=[];for(const[s,n]of Object.entries(e.projects)){if(n.owners&&n.owners.length>0)continue;const r=n.root??s,a=b(t,r,"package.json"),i=C(a);if(!i)continue;const c=M(i.maintainers);if(!c||c.length===0)continue;const f=[],h=new Set;for(const p of c){const $=se(p.url);$&&!h.has($)&&(h.add($),f.push($))}f.length!==0&&o.push({owners:f,path:r===""||r==="."?"/":`/${r}/`,projectId:s})}return o},ae=["author","bugs","homepage","license","repository","engines"],N=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),E=(e,t)=>{if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(const[o,s]of e.entries())if(!E(s,t[o]))return!1;return!0}if(typeof e=="object"&&typeof t=="object"){const o=Object.keys(e),s=Object.keys(t);if(o.length!==s.length)return!1;for(const n of o)if(!E(e[n],t[n]))return!1;return!0}return!1},R=e=>e===void 0?e:structuredClone(e),ce=(e,t,o)=>{if(e==="repository"&&N(t)&&N(o)){const s={};for(const[n,r]of Object.entries(t))n!=="directory"&&(s[n]=R(r));return typeof o.directory=="string"&&(s.directory=o.directory),s}return R(t)},de=(e,t,o)=>{const s=[];for(const n of o.fields){if(!Object.hasOwn(e,n))continue;const r=e[n],a=t[n],i=ce(n,r,a);E(i,a)||s.push({after:i,before:a,field:n,packageJsonPath:""})}return s},fe=(e,t)=>{for(const o of t)e[o.field]=o.after},x="Generated by `vis sync codeowners --write-guard`. Do not edit by hand.",le=e=>{const t=e.replace(/^\.?\/+/u,"").replace(/\/+$/u,"");return t===""||t==="."?"**":`${t}/**`},D=e=>{const t=new Set,o=[];for(const s of[...e].sort((n,r)=>n.name.localeCompare(r.name))){const n=le(s.root);t.has(n)||(t.add(n),o.push(n))}return o},pe=e=>{const t=D(e),o=t.map(n=>` - "${n}"`).join(`
7
- `),s=t.map(n=>` ${n}`).join(`
8
- `);return`# ${x}
6
+ `},V=["**/CODEOWNERS"],ee=["**/node_modules/**","**/dist/**","**/build/**","**/coverage/**","**/.git/**","**/.next/**","**/.nuxt/**"],te=e=>{const t=[];for(const n of e.split(/\r?\n/u)){const s=n.indexOf("#"),o=(s===-1?n:n.slice(0,s)).trim();if(o.length===0)continue;const i=o.split(/\s+/u);if(i.length<2)continue;const[c,...r]=i,a=r.filter(f=>f.length>0);!c||a.length===0||t.push({owners:a,path:c})}return t},ne=(e,t)=>{const n=t.replace(/^\.\/?/,"").replace(/\/$/,"");return e.startsWith("/")?n===""?e:`/${n}${e}`:n===""?`/${e}`:`/${n}/${e}`},oe=async(e,t,n)=>{const s=t&&t.length>0?[...t]:[...V],o=[...ee];if(n){const r=n.replace(/^\.\/?/,"").replace(/^\/+/,"");r.length>0&&o.push(r)}const i=await K(s,{absolute:!0,cwd:e,ignore:o}),c=[];for(const r of i){let a;try{a=A(r)}catch{continue}const f=G(r),l=I(e,f);for(const p of te(a))c.push({owners:p.owners,path:ne(p.path,l)})}return c},re=/^(?:https?:\/\/)?(?:www\.)?github\.com\/([^/?#]+)/iu,se=e=>{if(!e)return;const t=e.match(re);if(!t?.[1])return;const n=t[1].trim();if(!(n===""||n.includes(" ")))return`@${n.replace(/^@/,"")}`},ce=(e,t)=>{const n=[];for(const[s,o]of Object.entries(e.projects)){if(o.owners&&o.owners.length>0)continue;const i=o.root??s,c=b(t,i,"package.json"),r=E(c);if(!r)continue;const a=B(r.maintainers);if(!a||a.length===0)continue;const f=[],l=new Set;for(const p of a){const y=se(p.url);y&&!l.has(y)&&(l.add(y),f.push(y))}f.length!==0&&n.push({owners:f,path:i===""||i==="."?"/":`/${i}/`,projectId:s})}return n},ie=["author","bugs","homepage","license","repository","engines"],v=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),C=(e,t)=>{if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(const[n,s]of e.entries())if(!C(s,t[n]))return!1;return!0}if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(const o of n)if(!C(e[o],t[o]))return!1;return!0}return!1},P=e=>e===void 0?e:structuredClone(e),ae=(e,t,n)=>{if(e==="repository"&&v(t)&&v(n)){const s={};for(const[o,i]of Object.entries(t))o!=="directory"&&(s[o]=P(i));return typeof n.directory=="string"&&(s.directory=n.directory),s}return P(t)},de=(e,t,n)=>{const s=[];for(const o of n.fields){if(!Object.hasOwn(e,o))continue;const i=e[o],c=t[o],r=ae(o,i,c);C(r,c)||s.push({after:r,before:c,field:o,packageJsonPath:""})}return s},fe=(e,t)=>{for(const n of t)e[n.field]=n.after},L="Generated by `vis sync codeowners --write-guard`. Do not edit by hand.",le=e=>{const t=e.replace(/^\.?\/+/u,"").replace(/\/+$/u,"");return t===""||t==="."?"**":`${t}/**`},T=e=>{const t=new Set,n=[];for(const s of[...e].sort((o,i)=>o.name.localeCompare(i.name))){const o=le(s.root);t.has(o)||(t.add(o),n.push(o))}return n},ue=e=>{const t=T(e),n=t.map(o=>` - "${o}"`).join(`
7
+ `),s=t.map(o=>` ${o}`).join(`
8
+ `);return`# ${L}
9
9
  name: Write Guard
10
10
 
11
11
  on:
12
12
  pull_request:
13
13
  paths:
14
- ${o}
14
+ ${n}
15
15
 
16
16
  permissions:
17
17
  contents: read
@@ -29,8 +29,8 @@ jobs:
29
29
  codeowners: CODEOWNERS
30
30
  paths: |
31
31
  ${s}
32
- `},ue=e=>{const t=D(e).map(o=>` - "${o}/*"`).join(`
33
- `);return`# ${x}
32
+ `},pe=e=>{const n=T(e).map(s=>` - "${s}/*"`).join(`
33
+ `);return`# ${L}
34
34
  #
35
35
  # SOFT GUARD ONLY — this job does NOT block a merge by itself.
36
36
  # It verifies the generated CODEOWNERS is in sync and flags that a
@@ -47,7 +47,7 @@ write-guard:
47
47
  rules:
48
48
  - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
49
49
  changes:
50
- ${t}
50
+ ${n}
51
51
  script:
52
52
  - corepack enable
53
53
  - pnpm install --frozen-lockfile
@@ -57,5 +57,5 @@ ${t}
57
57
  code-owner approval. Enable 'Require approval from Code Owners' on the
58
58
  protected branch (GitLab Premium/Ultimate) for a real merge gate:
59
59
  https://docs.gitlab.com/ee/user/project/codeowners/"
60
- `},he=e=>e.length===0?[]:[{content:pe(e),path:".github/workflows/write-guard.yml"},{content:ue(e),path:".gitlab/write-guard.gitlab-ci.yml"}],L=new Set(["nested-codeowners","package-json-maintainers","project-json"]),A=(e,t,o)=>{const s=new Set,n=[];for(const r of e??[])for(const a of r.split(",")){const i=a.trim();if(i.length===0)continue;if(o&&!o(i))throw new Error(`Unknown codeowners source: "${i}". Known: ${[...L].join(", ")}.`);const c=i;s.has(c)||(s.add(c),n.push(c))}return n.length>0?n:[...t]},ge=e=>L.has(e),G=["codeowners","package-json-fields"],we=(e,t)=>t.some(o=>_(o,e)),me=async(e,t,o,s,n)=>{const r=Object.entries(s.projects).filter(([,i])=>i.restricted===!0).map(([i,c])=>({name:i,root:c.root??i})),a=he(r);if(a.length===0){t.info("No projects flagged `restricted: true` in project.json. Skipping Write Guard.");return}if(n){let i=!1;for(const c of a){const f=b(o,c.path);let h="";try{h=await e.readFile(f,"utf8")}catch(p){if(p.code!=="ENOENT")throw p}h.trim()!==c.content.trim()&&(t.error(`${c.path} is out of date. Run \`vis sync codeowners --write-guard\` to update it.`),i=!0)}i?process.exitCode=1:t.info(`Write Guard CI is up to date (${a.length} files, ${r.length} restricted projects).`);return}for(const i of a){const c=b(o,i.path);T(P(c)),I(c,i.content),t.info(`Wrote ${i.path}`)}t.info(`Write Guard CI scoped to ${r.length} restricted project${r.length===1?"":"s"}.`)},$e=async({fs:e,logger:t,options:o,visConfig:s,workspaceRoot:n})=>{const r=n,{workspace:a}=J(r,s),i=s?.codeowners;o.writeGuard===!0&&await me(e,t,r,a,o.check===!0);const c=A(o.from,i?.sources??["project-json"],ge),f=o.regenerationCommand??i?.regenerationCommand,h=o.preserveBlock===!0||i?.preserveBlock===!0,p=i?.blockMarker??O,$=o.nestedIncludes??i?.nestedIncludes,g=o.out??"CODEOWNERS",m=[];if(c.includes("nested-codeowners")){const w=await ne(r,$,g);for(const y of w)m.push({...y,source:"nested"})}if(c.includes("package-json-maintainers")){const w=ie(a,r);for(const y of w)m.push({...y,source:"maintainers"})}const l=c.includes("project-json")?v(a,i,m):v({projects:{}},i,m);if(l.length===0){t.info("No `owners` entries found in any source. Nothing to sync.");return}const k=b(r,g);let d="";try{d=await e.readFile(k,"utf8")}catch(w){if(w.code!=="ENOENT")throw w}const u={regenerationCommand:f},j=h?X(d,V(l,p,u),p):Y(l,u);if(o.check){if(d.trim()!==j.trim()){t.error(`${k} is out of date. Run \`vis sync codeowners\` to update it.`),process.exitCode=1;return}t.info(`${k} is up to date.`);return}I(k,j),t.info(`Wrote ${l.length} entries to ${k}`)},je=({logger:e,options:t,visConfig:o,workspaceRoot:s})=>{const n=s,r=o?.editorconfig??!0,a=C(b(n,"package.json"));if(!a){e.error("Could not read root package.json. Nothing to sync."),process.exitCode=1;return}const i=A(t.fields,ae),c=t.ignorePackageName??[],f=t.check===!0,h=(t.format??"human").toLowerCase(),p=t.quiet===!0,$=B(n).filter(d=>d!=="."),g=[];let m=0;for(const d of $){const u=b(n,d,"package.json"),j=C(u);if(!j)continue;const w=typeof j.name=="string"?j.name:void 0;if(w!==void 0&&c.length>0&&we(w,c))continue;m+=1;const y=de(a,j,{fields:i});y.length!==0&&g.push({filePath:u,packageJsonPath:S(n,u),packageName:w,pkg:j,pkgChanges:y})}if(!f)for(const d of g)fe(d.pkg,d.pkgChanges),U(d.filePath,d.pkg,{indent:q(d.filePath,{useEditorconfig:r}),overwrite:!0});const l=g.flatMap(d=>d.pkgChanges.map(u=>({after:u.after,before:u.before,field:u.field,packageJsonPath:d.packageJsonPath,packageName:d.packageName}))),k={changes:l,fields:i,kind:"package-json-fields",mode:f?"check":"write",totalChanges:l.length,totalPackages:m};if(h==="json")process.stdout.write(`${JSON.stringify(k,null,4)}
61
- `);else if(l.length===0)e.info(`All ${m} package${m===1?"":"s"} in sync (fields: ${i.join(", ")}).`);else if(f){if(!p)for(const d of l)e.error(`${d.packageJsonPath}: ${d.field} drifts from root`);e.error(`Found ${l.length} field drift${l.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}. Run \`vis sync package-json-fields\` to fix.`)}else{if(!p)for(const d of g)e.info(`${d.packageJsonPath}: synced ${d.pkgChanges.map(u=>u.field).join(", ")}`);e.info(`Synced ${l.length} field${l.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}.`)}f&&l.length>0&&(process.exitCode=1)},ve=async e=>{const t=e.argument[0];if(!t)throw new Error(`Missing sync kind. Usage: vis sync <kind> (known kinds: ${G.join(", ")})`);if(!e.workspaceRoot)throw new Error("Could not determine workspace root. Run inside a monorepo.");if(t==="codeowners"){await $e(e);return}if(t==="package-json-fields"){je(e);return}throw new Error(`Unknown sync kind: "${t}". Known kinds: ${G.join(", ")}.`)};export{ve as default};
60
+ `},he=e=>e.length===0?[]:[{content:ue(e),path:".github/workflows/write-guard.yml"},{content:pe(e),path:".gitlab/write-guard.gitlab-ci.yml"}],W=new Set(["nested-codeowners","package-json-maintainers","project-json"]),_=(e,t,n)=>{const s=new Set,o=[];for(const i of e??[])for(const c of i.split(",")){const r=c.trim();if(r.length===0)continue;if(n&&!n(r))throw new Error(`Unknown codeowners source: "${r}". Known: ${[...W].join(", ")}.`);const a=r;s.has(a)||(s.add(a),o.push(a))}return o.length>0?o:[...t]},ge=e=>W.has(e),S=["codeowners","package-json-fields"],me=(e,t)=>t.some(n=>x(n,e)),we=async(e,t,n,s,o)=>{const i=Object.entries(s.projects).filter(([,r])=>r.restricted===!0).map(([r,a])=>({name:r,root:a.root??r})),c=he(i);if(c.length===0){t.info("No projects flagged `restricted: true` in project.json. Skipping Write Guard.");return}if(o){let r=!1;for(const a of c){const f=b(n,a.path);let l="";try{l=await e.readFile(f,"utf8")}catch(p){if(p.code!=="ENOENT")throw p}l.trim()!==a.content.trim()&&(t.error(`${a.path} is out of date. Run \`vis sync codeowners --write-guard\` to update it.`),r=!0)}r?process.exitCode=1:t.info(`Write Guard CI is up to date (${c.length} files, ${i.length} restricted projects).`);return}for(const r of c){const a=b(n,r.path);q(G(a)),R(a,r.content),t.info(`Wrote ${r.path}`)}t.info(`Write Guard CI scoped to ${i.length} restricted project${i.length===1?"":"s"}.`)},ye=async({fs:e,logger:t,options:n,visConfig:s,workspaceRoot:o})=>{const i=o,{workspace:c}=U(i,s),r=s?.codeowners;n.writeGuard===!0&&await we(e,t,i,c,n.check===!0);const a=_(n.from,r?.sources??["project-json"],ge),f=n.regenerationCommand??r?.regenerationCommand,l=n.preserveBlock===!0||r?.preserveBlock===!0,p=r?.blockMarker??O,y=n.nestedIncludes??r?.nestedIncludes,g=n.out??"CODEOWNERS",w=[];if(a.includes("nested-codeowners")){const m=await oe(i,y,g);for(const j of m)w.push({...j,source:"nested"})}if(a.includes("package-json-maintainers")){const m=ce(c,i);for(const j of m)w.push({...j,source:"maintainers"})}const u=a.includes("project-json")?N(c,r,w):N({projects:{}},r,w);if(u.length===0){t.info("No `owners` entries found in any source. Nothing to sync.");return}const $=b(i,g);let d="";try{d=await e.readFile($,"utf8")}catch(m){if(m.code!=="ENOENT")throw m}const h={regenerationCommand:f},k=l?Z(d,X(u,p,h),p):Q(u,h);if(n.check){if(d.trim()!==k.trim()){t.error(`${$} is out of date. Run \`vis sync codeowners\` to update it.`),process.exitCode=1;return}t.info(`${$} is up to date.`);return}R($,k),t.info(`Wrote ${u.length} entries to ${$}`)},ke=({logger:e,options:t,visConfig:n,workspaceRoot:s})=>{const o=s,i=n?.editorconfig??!0,c=E(b(o,"package.json"));if(!c){e.error("Could not read root package.json. Nothing to sync."),process.exitCode=1;return}const r=_(t.fields,ie),a=t.ignorePackageName??[],f=t.check===!0,l=(t.format??"human").toLowerCase(),p=t.quiet===!0,y=J(o).filter(d=>d!=="."),g=[];let w=0;for(const d of y){const h=b(o,d,"package.json"),k=E(h);if(!k)continue;const m=typeof k.name=="string"?k.name:void 0;if(m!==void 0&&a.length>0&&me(m,a))continue;w+=1;const j=de(c,k,{fields:r});j.length!==0&&g.push({filePath:h,packageJsonPath:I(o,h),packageName:m,pkg:k,pkgChanges:j})}if(!f)for(const d of g)fe(d.pkg,d.pkgChanges),M(d.filePath,d.pkg,{indent:F(d.filePath,{useEditorconfig:i}),overwrite:!0});const u=g.flatMap(d=>d.pkgChanges.map(h=>({after:h.after,before:h.before,field:h.field,packageJsonPath:d.packageJsonPath,packageName:d.packageName}))),$={changes:u,fields:r,kind:"package-json-fields",mode:f?"check":"write",totalChanges:u.length,totalPackages:w};if(l==="json")process.stdout.write(`${JSON.stringify($,null,4)}
61
+ `);else if(u.length===0)e.info(`All ${w} package${w===1?"":"s"} in sync (fields: ${r.join(", ")}).`);else if(f){if(!p)for(const d of u)e.error(`${d.packageJsonPath}: ${d.field} drifts from root`);e.error(`Found ${u.length} field drift${u.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}. Run \`vis sync package-json-fields\` to fix.`)}else{if(!p)for(const d of g)e.info(`${d.packageJsonPath}: synced ${d.pkgChanges.map(h=>h.field).join(", ")}`);e.info(`Synced ${u.length} field${u.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}.`)}f&&u.length>0&&(process.exitCode=1)},Pe=async e=>{const t=e.argument[0];if(!t)throw new Error(`Missing sync kind. Usage: vis sync <kind> (known kinds: ${S.join(", ")})`);if(!e.workspaceRoot)throw new Error("Could not determine workspace root. Run inside a monorepo.");if(t==="codeowners"){await ye(e);return}if(t==="package-json-fields"){ke(e);return}throw new Error(`Unknown sync kind: "${t}". Known kinds: ${S.join(", ")}.`)};export{Pe as default};
@@ -1,3 +1,3 @@
1
- import{createRequire as G}from"node:module";import{I as q,j as Q,E as O,V as K,s as T,q as X}from"../packem_shared/index.server-CusjRLCh.js";import{b as B}from"../packem_shared/index-uBVnF4ji.js";import{P as Y}from"./cli-main.js";import{d as k,f as v,r as Z,a as ee,b as ne,s as te,c as ie,e as re,u as se,h as oe,i as ae,j as le,k as ce,l as de,m as ue,n as fe,v as ge,w as pe,q as me,t as he}from"../packem_shared/watch-loop-Q7UpkVbr.js";import{n as c}from"./catalog.js";let H;const U=e=>(H??=G(import.meta.url))(e),w=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,D=e=>{if(typeof w<"u"&&w.versions&&w.versions.node){const[n,t]=w.versions.node.split(".").map(Number);if(n>22||n===22&&t>=3||n===20&&t>=16)return w.getBuiltinModule(e)}return U(e)},{createHash:y}=D("node:crypto"),xe={1:"warning",2:"error"},we={argsCheck:(e,n)=>V(e,n,!1),argsFix:(e,n)=>V(e,n,!0),bin:()=>["pnpm","exec","eslint"],cacheKey:(e,n)=>{const t=["eslint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.eslint.packageNames[0]),i=v(e,c.eslint.configFiles);if(!(!t&&!i))return{adapter:"eslint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["cjs","cts","js","jsx","mjs","mts","ts","tsx","vue"],id:"eslint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"eslint",file:n.root,fixable:!1,message:`eslint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t)for(const s of r.messages)i.push({adapter:"eslint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:r.filePath,fixable:!!s.fix,line:s.line,message:s.message,ruleId:s.ruleId??void 0,severity:s.fatal?"error":xe[s.severity]??"warning"});return i}},V=(e,n,t)=>{const i=["--format","json","--no-error-on-unmatched-pattern"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},ke=/^([^:]+):(\d+)(?::(\d+))?\s+([\w/-]+)\s+(.+)$/,ve=e=>{const n=ke.exec(e);if(!n)return;const[,t,i,r,s,a]=n;return{column:r===void 0?void 0:Number(r),file:t,line:Number(i),message:a,ruleId:s}},ye=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),be={argsCheck:(e,n)=>J(e,n,!1),argsFix:(e,n)=>J(e,n,!0),bin:()=>["pnpm","exec","markdownlint-cli2"],cacheKey:(e,n)=>{const t=["markdownlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=c.markdownlint.packageNames.map(r=>k(n,r)).find(r=>r!==void 0),i=v(e,c.markdownlint.configFiles);if(!(!t&&!i))return{adapter:"markdownlint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["markdown","md"],id:"markdownlint",kind:"lint",parse:(e,n)=>{const t=(e.stderr||e.stdout||"").trim();if(!t)return[];const i=[];for(const r of t.split(/\r?\n/)){const s=ve(r.trim());s&&i.push({adapter:"markdownlint",column:s.column,file:ye(s.file)?s.file:`${n.root}/${s.file}`,fixable:!0,line:s.line,message:s.message,ruleId:s.ruleId,severity:"warning"})}return i}},J=(e,n,t)=>{const i=[];return t&&i.push("--fix"),n.extraArgs?.length&&i.push(...n.extraArgs),e.length===0?i.push("**/*.md"):i.push(...e),i},$e={advice:"info",error:"error",warning:"warning"},Ae={argsCheck:(e,n)=>R(e,n,!1),argsFix:(e,n)=>R(e,n,!0),bin:()=>["pnpm","exec","oxlint"],cacheKey:(e,n)=>{const t=["oxlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.oxlint.packageNames[0]),i=v(e,c.oxlint.configFiles);if(!(!t&&!i))return{adapter:"oxlint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","cjs","cts","js","jsx","mjs","mts","svelte","ts","tsx","vue"],id:"oxlint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"oxlint",file:n.root,fixable:!1,message:`oxlint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t.diagnostics??[]){const s=r.labels?.[0]?.span;i.push({adapter:"oxlint",column:s?.column,file:r.filename??n.root,fixable:!1,line:s?.line,message:r.message??"",ruleId:r.code,severity:$e[r.severity??""]??"warning"})}return i}},R=(e,n,t)=>{const i=["--format","json"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push(`--max-warnings=${String(n.maxWarnings)}`),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},Fe={error:"error",info:"info",style:"info",warning:"warning"},je=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),Ce=(e,n)=>e?je(e)?e:`${n}/${e}`:n,Se={argsCheck:(e,n)=>L(e,n),argsFix:(e,n)=>L(e,n),bin:()=>["shellcheck"],cacheKey:(e,n)=>{const t=["shellcheck",e.declaredVersion??"unknown",e.configFile??"no-config",n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.shellcheck.packageNames[0]),i=v(e,c.shellcheck.configFiles);if(!(!t&&!i))return{adapter:"shellcheck",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["bash","ksh","sh"],id:"shellcheck",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"shellcheck",file:n.root,fixable:!1,message:`shellcheck output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t.comments??[])i.push({adapter:"shellcheck",column:r.column,endColumn:r.endColumn,endLine:r.endLine,file:Ce(r.file,n.root),fixable:!!r.fix,line:r.line,message:r.message??"",ruleId:r.code===void 0?void 0:`SC${String(r.code)}`,severity:Fe[r.level??""]??"warning"});return i}},L=(e,n)=>{const t=["--format=json1"];return n.extraArgs?.length&&t.push(...n.extraArgs),t.push(...e),t},qe={error:"error",warning:"warning"},We={argsCheck:(e,n)=>M(e,n,!1),argsFix:(e,n)=>M(e,n,!0),bin:()=>["pnpm","exec","stylelint"],cacheKey:(e,n)=>{const t=["stylelint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.stylelint.packageNames[0]),i=v(e,c.stylelint.configFiles);if(!(!t&&!i))return{adapter:"stylelint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","css","less","sass","scss","svelte","vue"],id:"stylelint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"stylelint",file:n.root,fixable:!1,message:`stylelint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t)for(const s of r.warnings??[])i.push({adapter:"stylelint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:r.source,fixable:!1,line:s.line,message:s.text??"",ruleId:s.rule,severity:qe[s.severity??""]??"warning"});return i}},M=(e,n,t)=>{const i=["--formatter","json"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},Ne=[Ae,fe,we,We,ge,be,Se,pe],Pe=async({logger:e,options:n,visConfig:t,workspaceRoot:i})=>{const r=i??process.cwd(),s=t?.lint,a=Z(Ne,s?.order),j=ee(r,a),d=ne(j,a,"lint").filter(({adapter:l})=>s?.adapters?.[l.id]?.enabled!==!1);if(d.length===0){e.warn("vis lint: no linter detected in this workspace (looked for: oxlint, biome, eslint, stylelint, ruff, markdownlint, shellcheck, deno).");return}const C=l=>{const u=s?.adapters?.[l]?.extraArgs;return u&&u.length>0?[...u]:void 0},b={extraArgs:void 0,maxWarnings:typeof n.maxWarnings=="number"?n.maxWarnings:void 0,quiet:n.quiet??!1},$=_e(n),P=n.fix?"fix":"check";let f;if(n.staged){if(f=te(r),f===void 0)e.warn("vis lint: could not resolve --staged (not a git repo or git unavailable). Falling back to a workspace-wide run.");else if(f.length===0){e.info(q("✓ lint: no staged files"));return}}else if(typeof n.since=="string"&&n.since.length>0){if(f=ie(r,n.since),f===void 0)e.warn(`vis lint: could not resolve --since ${n.since} (not a git repo or unknown ref). Falling back to a workspace-wide run.`);else if(f.length===0){e.info(q(`✓ lint: no files changed since ${n.since}`));return}}const W=$.length>0?$:void 0,E=Y(r,void 0,void 0,!0),S=n.format??"human";S==="human"&&n.output!==void 0&&e.warn("vis lint: --output is ignored for the human format; pass --format json|minimal|sarif|junit|github to redirect findings to a file.");const N=async l=>{const u=l!==void 0&&l.length>0&&W===void 0,m=[];for(const{adapter:o,presence:x}of d){let g;if(u){if(g=se(l,o.extensions),g.length===0)continue}else g=W??l??["."];const F=C(o.id),I={adapter:o,files:g,presence:x};F&&(I.options={...b,extraArgs:F}),m.push(I)}if(m.length===0)return;const z=await oe(m,b,P,{cacheRoot:E}),A=m.map((o,x)=>{const g=z[x],F=o.adapter.parse(g,o.presence);return{adapter:o.adapter,durationMs:g.durationMs,exitCode:g.exitCode,findings:F}}),h=ae(A.map(o=>({adapter:o.adapter.id,durationMs:o.durationMs,exitCode:o.exitCode,findingCount:o.findings.length,findings:o.findings}))),p=S==="human"?void 0:le({cwd:r,target:n.output});try{switch(S){case"github":{p.write(ue({runs:A.map(o=>({findings:o.findings})),workspaceRoot:r}));break}case"json":{p.write(`${JSON.stringify({findings:h.findings,runs:h.runs},null,2)}
2
- `);break}case"junit":{p.write(de({runs:A.map(o=>({adapter:o.adapter.id,durationMs:o.durationMs,findings:o.findings})),workspaceRoot:r}));break}case"minimal":{Oe(h.findings,r,p);break}case"sarif":{p.write(ce({runs:A.map(o=>({adapter:o.adapter.id,findings:o.findings,presence:m.find(x=>x.adapter.id===o.adapter.id)?.presence})),workspaceRoot:r}));break}default:Ie(h.findings,r,e)}}finally{p?.close()}const _=he(h);_!==0&&(process.exitCode=_)};if(n.watch){const l=[...new Set(d.flatMap(({adapter:u})=>u.extensions))];await re({extensions:l,initialFiles:f,label:"lint",log:u=>{e.info(u)},runCycle:N,workspaceRoot:r});return}await N(f)},_e=e=>{const n=e;return[...n._??n.args??[]]},Ie=(e,n,t)=>{if(e.length===0){t.info(q("✓ lint: no findings"));return}const i=me(e);for(const[a,j]of i){t.info(Q(B(n,a)));for(const d of j){const C=Ve(d),b=Je(d.severity),$=d.ruleId?O(` ${d.ruleId}`):"";t.info(` ${O(C)} ${b} ${d.message}${$}`)}}const r=e.filter(a=>a.severity==="error").length,s=e.filter(a=>a.severity==="warning").length;t.info(""),t.info(`${K(`${String(r)} error${r===1?"":"s"}`)}, ${T(`${String(s)} warning${s===1?"":"s"}`)}`)},Oe=(e,n,t)=>{for(const i of e){const r=B(n,i.file),s=i.line??"",a=i.column??"";t.write(`${i.adapter} ${r} ${String(s)} ${String(a)} ${i.severity} ${i.ruleId??""} ${i.message}
3
- `)}},Ve=e=>e.line===void 0?"":e.column===void 0?String(e.line):`${String(e.line)}:${String(e.column)}`,Je=e=>e==="error"?K("error"):e==="warning"?T("warn "):X("info ");export{Pe as default};
1
+ import{createRequire as G}from"node:module";import{J as q,q as X,F as E,X as B,r as L,D as Z}from"../packem_shared/index.server-CwSgbeN7.js";import{a as J}from"../packem_shared/index-DHD8wb6Z.js";import{Z as Q}from"./cli-main.js";import{d as k,f as y,r as ee,a as ne,b as te,s as re,c as ie,e as se,g as ae,u as oe,v as le,w as ce,k as de,l as ue,m as fe,n as ge,o as me,p as pe,t as he,q as xe}from"../packem_shared/watch-loop-COWvvSbR.js";import{T as c}from"./catalog.js";let H;const U=e=>(H??=G(import.meta.url))(e),v=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,z=e=>{if(typeof v<"u"&&v.versions&&v.versions.node){const[n,t]=v.versions.node.split(".").map(Number);if(n>22||n===22&&t>=3||n===20&&t>=16)return v.getBuiltinModule(e)}return U(e)},{createHash:b}=z("node:crypto"),we={1:"warning",2:"error"},ve={argsCheck:(e,n)=>V(e,n,!1),argsFix:(e,n)=>V(e,n,!0),bin:()=>["pnpm","exec","eslint"],cacheKey:(e,n)=>{const t=["eslint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return b("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.eslint.packageNames[0]),r=y(e,c.eslint.configFiles);if(!(!t&&!r))return{adapter:"eslint",configFile:r,declared:!!t,declaredVersion:t,root:e}},extensions:["cjs","cts","js","jsx","mjs","mts","ts","tsx","vue"],id:"eslint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"eslint",file:n.root,fixable:!1,message:`eslint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of t)for(const s of i.messages)r.push({adapter:"eslint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:i.filePath,fixable:!!s.fix,line:s.line,message:s.message,ruleId:s.ruleId??void 0,severity:s.fatal?"error":we[s.severity]??"warning"});return r}},V=(e,n,t)=>{const r=["--format","json","--no-error-on-unmatched-pattern"];return t&&r.push("--fix"),n.quiet&&r.push("--quiet"),typeof n.maxWarnings=="number"&&r.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&r.push(...n.extraArgs),r.push(...e),r},ke=/^([^:]+):(\d+)(?::(\d+))?\s+([\w/-]+)\s+(.+)$/,ye=e=>{const n=ke.exec(e);if(!n)return;const[,t,r,i,s,o]=n;return{column:i===void 0?void 0:Number(i),file:t,line:Number(r),message:o,ruleId:s}},be=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),Ae={argsCheck:(e,n)=>M(e,n,!1),argsFix:(e,n)=>M(e,n,!0),bin:()=>["pnpm","exec","markdownlint-cli2"],cacheKey:(e,n)=>{const t=["markdownlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return b("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=c.markdownlint.packageNames.map(i=>k(n,i)).find(i=>i!==void 0),r=y(e,c.markdownlint.configFiles);if(!(!t&&!r))return{adapter:"markdownlint",configFile:r,declared:!!t,declaredVersion:t,root:e}},extensions:["markdown","md"],id:"markdownlint",kind:"lint",parse:(e,n)=>{const t=(e.stderr||e.stdout||"").trim();if(!t)return[];const r=[];for(const i of t.split(/\r?\n/)){const s=ye(i.trim());s&&r.push({adapter:"markdownlint",column:s.column,file:be(s.file)?s.file:`${n.root}/${s.file}`,fixable:!0,line:s.line,message:s.message,ruleId:s.ruleId,severity:"warning"})}return r}},M=(e,n,t)=>{const r=[];return t&&r.push("--fix"),n.extraArgs?.length&&r.push(...n.extraArgs),e.length===0?r.push("**/*.md"):r.push(...e),r},$e={advice:"info",error:"error",warning:"warning"},Ce={argsCheck:(e,n)=>O(e,n,!1),argsFix:(e,n)=>O(e,n,!0),bin:()=>["pnpm","exec","oxlint"],cacheKey:(e,n)=>{const t=["oxlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return b("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.oxlint.packageNames[0]),r=y(e,c.oxlint.configFiles);if(!(!t&&!r))return{adapter:"oxlint",configFile:r,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","cjs","cts","js","jsx","mjs","mts","svelte","ts","tsx","vue"],id:"oxlint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"oxlint",file:n.root,fixable:!1,message:`oxlint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of t.diagnostics??[]){const s=i.labels?.[0]?.span;r.push({adapter:"oxlint",column:s?.column,file:i.filename??n.root,fixable:!1,line:s?.line,message:i.message??"",ruleId:i.code,severity:$e[i.severity??""]??"warning"})}return r}},O=(e,n,t)=>{const r=["--format","json"];return t&&r.push("--fix"),n.quiet&&r.push("--quiet"),typeof n.maxWarnings=="number"&&r.push(`--max-warnings=${String(n.maxWarnings)}`),n.extraArgs?.length&&r.push(...n.extraArgs),r.push(...e),r},Fe={error:"error",info:"info",style:"info",warning:"warning"},Se=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),je=(e,n)=>e?Se(e)?e:`${n}/${e}`:n,qe={argsCheck:(e,n)=>T(e,n),argsFix:(e,n)=>T(e,n),bin:()=>["shellcheck"],cacheKey:(e,n)=>{const t=["shellcheck",e.declaredVersion??"unknown",e.configFile??"no-config",n.quiet?"q":"",...n.extraArgs??[]];return b("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.shellcheck.packageNames[0]),r=y(e,c.shellcheck.configFiles);if(!(!t&&!r))return{adapter:"shellcheck",configFile:r,declared:!!t,declaredVersion:t,root:e}},extensions:["bash","ksh","sh"],id:"shellcheck",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"shellcheck",file:n.root,fixable:!1,message:`shellcheck output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of t.comments??[])r.push({adapter:"shellcheck",column:i.column,endColumn:i.endColumn,endLine:i.endLine,file:je(i.file,n.root),fixable:!!i.fix,line:i.line,message:i.message??"",ruleId:i.code===void 0?void 0:`SC${String(i.code)}`,severity:Fe[i.level??""]??"warning"});return r}},T=(e,n)=>{const t=["--format=json1"];return n.extraArgs?.length&&t.push(...n.extraArgs),t.push(...e),t},Ne={error:"error",warning:"warning"},_e={argsCheck:(e,n)=>P(e,n,!1),argsFix:(e,n)=>P(e,n,!0),bin:()=>["pnpm","exec","stylelint"],cacheKey:(e,n)=>{const t=["stylelint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return b("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.stylelint.packageNames[0]),r=y(e,c.stylelint.configFiles);if(!(!t&&!r))return{adapter:"stylelint",configFile:r,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","css","less","sass","scss","svelte","vue"],id:"stylelint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"stylelint",file:n.root,fixable:!1,message:`stylelint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const r=[];for(const i of t)for(const s of i.warnings??[])r.push({adapter:"stylelint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:i.source,fixable:!1,line:s.line,message:s.text??"",ruleId:s.rule,severity:Ne[s.severity??""]??"warning"});return r}},P=(e,n,t)=>{const r=["--formatter","json"];return t&&r.push("--fix"),n.quiet&&r.push("--quiet"),typeof n.maxWarnings=="number"&&r.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&r.push(...n.extraArgs),r.push(...e),r},We=[Ce,ae,ve,_e,oe,Ae,qe,le],Ke=async({logger:e,options:n,visConfig:t,workspaceRoot:r})=>{const i=r??process.cwd(),s=t?.lint,o=ee(We,s?.order),F=ne(i,o),p=te(F,o,"lint").filter(({adapter:l})=>s?.adapters?.[l.id]?.enabled!==!1);if(p.length===0){e.warn("vis lint: no linter detected in this workspace (looked for: oxlint, biome, eslint, stylelint, ruff, markdownlint, shellcheck, deno).");return}const S=l=>{const d=s?.adapters?.[l]?.extraArgs;return d&&d.length>0?[...d]:void 0},A={extraArgs:void 0,maxWarnings:typeof n.maxWarnings=="number"?n.maxWarnings:void 0,quiet:n.quiet??!1},N=Ie(n),K=n.fix?"fix":"check";let u;if(n.staged){if(u=re(i),u===void 0)e.warn("vis lint: could not resolve --staged (not a git repo or git unavailable). Falling back to a workspace-wide run.");else if(u.length===0){e.info(q("✓ lint: no staged files"));return}}else if(typeof n.since=="string"&&n.since.length>0){if(u=ie(i,n.since),u===void 0)e.warn(`vis lint: could not resolve --since ${n.since} (not a git repo or unknown ref). Falling back to a workspace-wide run.`);else if(u.length===0){e.info(q(`✓ lint: no files changed since ${n.since}`));return}}const _=N.length>0?N:void 0,D=Q(i,void 0,void 0,!0),j=n.format??"human";j==="human"&&n.output!==void 0&&e.warn("vis lint: --output is ignored for the human format; pass --format json|minimal|sarif|junit|github to redirect findings to a file.");const W=async l=>{const d=l!==void 0&&l.length>0&&_===void 0,h=[];for(const{adapter:a,presence:w}of p){let f;if(d){if(f=ce(l,a.extensions),f.length===0)continue}else f=_??l??["."];const C=S(a.id),R={adapter:a,files:f,presence:w};C&&(R.options={...A,extraArgs:C}),h.push(R)}if(h.length===0)return;const Y=await de(h,A,K,{cacheRoot:D}),$=h.map((a,w)=>{const f=Y[w],C=a.adapter.parse(f,a.presence);return{adapter:a.adapter,durationMs:f.durationMs,exitCode:f.exitCode,findings:C}}),x=ue($.map(a=>({adapter:a.adapter.id,durationMs:a.durationMs,exitCode:a.exitCode,findingCount:a.findings.length,findings:a.findings}))),m=j==="human"?void 0:fe({cwd:i,target:n.output});try{switch(j){case"github":{m.write(pe({runs:$.map(a=>({findings:a.findings})),workspaceRoot:i}));break}case"json":{m.write(`${JSON.stringify({findings:x.findings,runs:x.runs},null,2)}
2
+ `);break}case"junit":{m.write(me({runs:$.map(a=>({adapter:a.adapter.id,durationMs:a.durationMs,findings:a.findings})),workspaceRoot:i}));break}case"minimal":{Ee(x.findings,i,m);break}case"sarif":{m.write(ge({runs:$.map(a=>({adapter:a.adapter.id,findings:a.findings,presence:h.find(w=>w.adapter.id===a.adapter.id)?.presence})),workspaceRoot:i}));break}default:Re(x.findings,i,e)}}finally{m?.close()}const I=xe(x);I!==0&&(process.exitCode=I)};if(n.watch){const l=[...new Set(p.flatMap(({adapter:d})=>d.extensions))];await se({extensions:l,initialFiles:u,label:"lint",log:d=>{e.info(d)},runCycle:W,workspaceRoot:i});return}await W(u)},Ie=e=>{const n=e;return[...n._??n.args??[]]},Re=(e,n,t)=>{if(e.length===0){t.info(q("✓ lint: no findings"));return}const r=he(e);for(const[o,F]of r){t.info(X(J(n,o)));for(const g of F){const p=Ve(g),S=Me(g.severity),A=g.ruleId?E(` ${g.ruleId}`):"";t.info(` ${E(p)} ${S} ${g.message}${A}`)}}const i=e.filter(o=>o.severity==="error").length,s=e.filter(o=>o.severity==="warning").length;t.info(""),t.info(`${B(`${String(i)} error${i===1?"":"s"}`)}, ${L(`${String(s)} warning${s===1?"":"s"}`)}`)},Ee=(e,n,t)=>{for(const r of e){const i=J(n,r.file),s=r.line??"",o=r.column??"";t.write(`${r.adapter} ${i} ${String(s)} ${String(o)} ${r.severity} ${r.ruleId??""} ${r.message}
3
+ `)}},Ve=e=>e.line===void 0?"":e.column===void 0?String(e.line):`${String(e.line)}:${String(e.column)}`,Me=e=>e==="error"?B("error"):e==="warning"?L("warn "):Z("info ");export{Ke as default};
@@ -1,6 +1,6 @@
1
- import{b as J,z as X,w as E,l as M,K as V,P as W}from"../packem_shared/index-uBVnF4ji.js";import{l as t,m as a,i as c,r as v,X as Y,R as Q,P as U,p as Z,o as _,s as ee,x as re,e as N}from"./catalog.js";import"../packem_shared/en-D3CfXlO7.js";import{I as te}from"../packem_shared/index-BWl4DbMp.js";import se from"./index.js";import{sortPackageJsonStringWithOptions as q}from"#native";import{J as oe,I as ne,K as ie,p as S}from"./cli-main.js";import{ScrollView as le}from"@visulima/tui-kit/scroll-view";import{ScrollBar as ce}from"@visulima/tui-kit/scroll-bar";import{o as O}from"../packem_shared/utils-CRueU43T.js";const A={error:0,rewritten:1,"would-rewrite":1,unchanged:2},ae=e=>[...e].sort((r,s)=>A[r.status]-A[s.status]),de=(e,r)=>r==="all"?e:r==="errors"?e.filter(s=>s.status==="error"):r==="rewritten"?e.filter(s=>s.status==="rewritten"||s.status==="would-rewrite"):e.filter(s=>s.status==="unchanged");class ue{#e;#r=new Set;constructor(r){this.#e={entries:ae(r),filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=()=>this.#e;subscribe=r=>(this.#r.add(r),()=>{this.#r.delete(r)});getFilteredEntries=()=>de(this.#e.entries,this.#e.filterType);#t(){this.#e={...this.#e};for(const r of this.#r)r()}select(r){const s=this.getFilteredEntries();this.#e.selectedIndex=s.length===0?-1:Math.max(0,Math.min(r,s.length-1)),this.#t()}selectStep(r){this.select(this.#e.selectedIndex+r)}setFilter(r){this.#e.filterType=r,this.#e.selectedIndex=0,this.#t()}setFocusedPanel(r){this.#e.focusedPanel=r,this.#t()}}const fe=({checkMode:e,entry:r,focused:s,scrollRef:l})=>{const i=s?"white":"gray";return r?t.jsxs(a,{borderColor:i,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsx(a,{flexShrink:0,paddingTop:1,paddingX:2,children:t.jsx(c,{bold:!0,color:"white",children:r.relativePath})}),t.jsxs(le,{flexGrow:1,flexShrink:1,paddingX:2,ref:l,scrollbar:!0,scrollbarColor:"gray",children:[t.jsx(c,{}),t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Status:"})}),r.status==="error"?t.jsx(c,{bold:!0,color:"red",children:"error"}):r.status==="unchanged"?t.jsx(c,{bold:!0,color:"green",children:"already sorted"}):r.status==="rewritten"?t.jsx(c,{bold:!0,color:"yellow",children:"rewritten"}):t.jsx(c,{bold:!0,color:"yellow",children:"would rewrite (--check)"})]}),t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Path:"})}),t.jsx(c,{children:r.filePath})]}),r.error?t.jsxs(t.Fragment,{children:[t.jsxs(a,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"red",children:"ERROR"}),t.jsxs(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Step:"})}),t.jsx(c,{color:"yellow",children:r.error.step})]}),r.error.context&&t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Position:"})}),t.jsx(c,{children:`line ${String(r.error.context.line)}, column ${String(r.error.context.column)}`})]}),t.jsx(a,{marginTop:1,children:t.jsx(c,{color:"red",children:r.error.message})})]})]}),r.error.context&&r.error.context.snippet.length>0&&t.jsxs(a,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"white",children:"SNIPPET"}),t.jsxs(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r.error.context.snippet.map(o=>{const n=`${o.isErrorLine?"❯":" "} ${String(o.lineNumber).padStart(4)} `;return t.jsxs(a,{children:[t.jsx(c,{color:o.isErrorLine?"red":"gray",children:n}),t.jsx(c,{color:o.isErrorLine?"white":"gray",wrap:"truncate-end",children:o.content||" "})]},o.lineNumber)}),r.error.context.column>0&&t.jsx(a,{children:t.jsx(c,{color:"red",children:`${" ".repeat(7+r.error.context.column-1)}↑`})})]})]})]}):t.jsxs(a,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"white",children:"KEY DIFF"}),t.jsx(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.diff.length===0?t.jsx(c,{dimColor:!0,children:"No top-level keys moved (sub-key reorder only)."}):r.diff.map(o=>{const n=o.toIndex-o.fromIndex,d=n<0?`↑ ${String(Math.abs(n))}`:`↓ ${String(n)}`,g=n<0?"green":"yellow";return t.jsxs(a,{children:[t.jsx(a,{width:28,children:t.jsx(c,{wrap:"truncate",children:o.key})}),t.jsx(a,{width:10,children:t.jsxs(c,{dimColor:!0,children:[String(o.fromIndex)," → ",String(o.toIndex)]})}),t.jsx(c,{color:g,children:d})]},o.key)})}),e&&r.status==="would-rewrite"&&t.jsx(a,{marginTop:1,paddingLeft:2,children:t.jsx(c,{dimColor:!0,children:"--check mode: no write performed."})})]})]})]}):t.jsx(a,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:t.jsx(c,{dimColor:!0,children:"No entry selected"})})},he={error:"red",rewritten:"yellow",unchanged:"green","would-rewrite":"yellow"},ge={error:"ERROR",rewritten:"REWROTE",unchanged:"SORTED","would-rewrite":"REWRITE"},H={error:"errors",rewritten:"rewrites",unchanged:"sorted","would-rewrite":"rewrites"},xe={errors:"Errors",rewrites:"Rewrites",sorted:"Sorted"},pe=[{count:e=>e.errors+e.rewrites+e.sorted,key:"all",label:"All",shortcut:"1"},{count:e=>e.rewrites,key:"rewritten",label:"Rewrites",shortcut:"2"},{count:e=>e.errors,key:"errors",label:"Errors",shortcut:"3"},{count:e=>e.sorted,key:"unchanged",label:"Sorted",shortcut:"4"}],z=e=>{const r={errors:0,rewrites:0,sorted:0};for(const s of e)r[H[s.status]]++;return r},me=({entry:e,isSelected:r})=>{const s=he[e.status],l=ge[e.status];return t.jsxs(a,{flexShrink:0,height:1,children:[t.jsx(c,{children:r?">":" "}),t.jsx(c,{children:" "}),t.jsx(c,{bold:!0,color:s,children:`[${l}]`.padEnd(10)}),t.jsx(c,{children:" "}),t.jsx(a,{flexGrow:1,children:t.jsx(c,{bold:r,inverse:r,wrap:"truncate",children:e.relativePath})}),e.status!=="error"&&e.diff.length>0&&t.jsx(c,{dimColor:!0,children:` ${String(e.diff.length)} key${e.diff.length===1?"":"s"}`})]})},we=({color:e,count:r,label:s})=>t.jsx(a,{flexShrink:0,height:1,children:t.jsx(c,{bold:!0,color:e,children:`${s} (${String(r)})`})}),je=({counts:e,entries:r,filterType:s,focused:l,selectedIndex:i,totalEntries:o,viewportHeight:n})=>{const d=l?"white":"gray",g=z(r),m=(g.errors>0?1:0)+(g.rewrites>0?1:0)+(g.sorted>0?1:0),y=s==="all"&&m>1,h=[];let w;for(const[u,p]of r.entries()){const b=H[p.status];y&&b!==w&&(w!==void 0&&h.push({kind:"spacer"}),h.push({color:b==="errors"?"red":b==="rewrites"?"yellow":"green",count:g[b],kind:"header",label:xe[b]}),w=b),h.push({entry:p,entryIndex:u,kind:"entry"})}const x=h.findIndex(u=>u.kind==="entry"&&u.entryIndex===i),k=x!==-1,j=h.length,$=Math.max(0,j-n);let f=0;k&&n>0&&(f=Math.min($,Math.max(0,x-n+1)));const P=j>n&&n>0;return t.jsxs(a,{borderColor:d,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsxs(a,{flexShrink:0,gap:1,paddingX:1,children:[t.jsx(c,{bold:!0,inverse:!0,children:" VIS SORT "}),t.jsxs(c,{wrap:"truncate",children:[o," ","file",o===1?"":"s"]})]}),t.jsx(a,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:pe.map(u=>{const p=s===u.key,b=u.count(e);return t.jsxs(a,{children:[t.jsx(c,{dimColor:!p,children:"["}),t.jsx(c,{bold:p,color:p?"cyan":"gray",children:u.shortcut}),t.jsx(c,{dimColor:!p,children:"]"}),t.jsxs(c,{color:p?"white":"gray",children:[" ",u.label]}),t.jsxs(c,{dimColor:!0,children:[" ","(",b,")"]})]},u.key)})}),t.jsxs(a,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[t.jsx(a,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:t.jsx(a,{flexDirection:"column",marginTop:-f,children:h.map((u,p)=>u.kind==="spacer"?t.jsx(a,{flexShrink:0,height:1},`s-${String(p)}`):u.kind==="header"?t.jsx(we,{color:u.color,count:u.count,label:u.label},`h-${u.label}`):t.jsx(me,{entry:u.entry,isSelected:u.entryIndex===i},u.entry.filePath))})}),P&&t.jsx(a,{flexShrink:0,marginLeft:1,marginRight:1,children:t.jsx(ce,{contentHeight:j,placement:"inset",scrollOffset:f,style:"block",viewportHeight:n})})]})]})},ye=100,D=10,be=6,Se=1,F={1:"all",2:"rewritten",3:"errors",4:"unchanged"},ke=({checkMode:e,store:r})=>{const{exit:s}=oe(),{columns:l,rows:i}=ne(),o=v.useSyncExternalStore(r.subscribe,r.getSnapshot),n=v.useRef(null),d=r.getFilteredEntries(),g=d[o.selectedIndex]??null,m=z(o.entries),y=l>=ye,h=Math.max(0,i-Se),w=y?h:Math.floor(h/2),x=Math.max(0,w-be),k=v.useCallback(()=>{s()},[s]),j=v.useRef(0),$=v.useRef(void 0),f=v.useRef(!1),P=v.useCallback((u,p)=>{j.current+=p,$.current=u,!f.current&&(f.current=!0,queueMicrotask(()=>{f.current=!1;const b=j.current,T=$.current;j.current=0,$.current=void 0,!(b===0||T===void 0)&&(T==="list"?r.selectStep(Math.sign(b)):n.current?.scrollBy(Math.sign(b)))}))},[r]);return ie((u,p)=>{if(u==="q"||p.escape){k();return}if(F[u]){r.setFilter(F[u]);return}if(p.tab){r.setFocusedPanel(o.focusedPanel==="list"?"detail":"list");return}o.focusedPanel==="list"?p.upArrow||u==="k"?P("list",-1):(p.downArrow||u==="j")&&P("list",1):o.focusedPanel==="detail"&&(p.upArrow||u==="k"?P("detail",-1):(p.downArrow||u==="j")&&P("detail",1))}),i<D?t.jsx(a,{alignItems:"center",justifyContent:"center",children:t.jsxs(c,{color:"yellow",children:["Terminal too small. Resize to at least",D," ","rows."]})}):t.jsxs(a,{flexDirection:"column",height:i,width:l,children:[t.jsxs(a,{flexDirection:y?"row":"column",flexGrow:1,children:[t.jsx(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(je,{counts:m,entries:d,filterType:o.filterType,focused:o.focusedPanel==="list",selectedIndex:o.selectedIndex,totalEntries:o.entries.length,viewportHeight:x})}),t.jsx(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(fe,{checkMode:e,entry:g,focused:o.focusedPanel==="detail",scrollRef:n})})]}),t.jsx(a,{flexShrink:0,paddingX:1,children:t.jsx(c,{dimColor:!0,children:"↑/↓ or j/k:navigate | tab:switch panel | 1-4:filter | q:quit"})})]})},G=["types","node-addons","node","import","require","default"],$e=/^git\+https:\/\/github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,ve=/^git\+ssh:\/\/git@github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,C=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),R=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(s=>R(s));const r={};for(const[s,l]of Object.entries(e))r[s]=R(l);return r},Pe=e=>{if(!C(e))return{changed:!1,value:e};const r=Object.keys(e);return r.length===1&&r[0]==="url"&&typeof e.url=="string"?{changed:!0,value:e.url}:{changed:!1,value:e}},Ee=e=>e.endsWith(".git")?e.slice(0,-4):e,Oe=e=>{if(!C(e))return{changed:!1,value:e};if(typeof e.directory=="string"&&e.directory.length>0)return{changed:!1,value:e};const{type:r}=e;if(r!==void 0&&r!=="git")return{changed:!1,value:e};const{url:s}=e;if(typeof s!="string")return{changed:!1,value:e};const l=$e.exec(s)??ve.exec(s);if(!l)return{changed:!1,value:e};const i=l[1],o=Ee(l[2]??"");if(!i||!o)return{changed:!1,value:e};const n=new Set(["type","url"]);for(const d of Object.keys(e))if(!n.has(d))return{changed:!1,value:e};return{changed:!0,value:`${i}/${o}`}},Ce=e=>{const r=Object.keys(e),s=[],l=[];for(const n of G)Object.hasOwn(e,n)&&s.push(n);for(const n of r)G.includes(n)||l.push(n);const i=[...s,...l];if(i.length===r.length&&i.every((n,d)=>n===r[d]))return{changed:!1,value:e};const o={};for(const n of i)o[n]=e[n];return{changed:!0,value:o}},K=e=>{if(!C(e))return{changed:!1,value:e};let r=!1;const s={};for(const[i,o]of Object.entries(e)){const n=K(o);s[i]=n.value,n.changed&&(r=!0)}const l=Ce(s);return{changed:r||l.changed,value:l.value}},Ie=(e,r)=>{const s=R(e);let l=!1;if(r.formatBugs!==!1&&Object.hasOwn(s,"bugs")){const i=Pe(s.bugs);i.changed&&(s.bugs=i.value,l=!0)}if(r.formatRepository!==!1&&Object.hasOwn(s,"repository")){const i=Oe(s.repository);i.changed&&(s.repository=i.value,l=!0)}if(r.sortExports!==!1&&Object.hasOwn(s,"exports")&&C(s.exports)){const i=K(s.exports);i.changed&&(s.exports=i.value,l=!0)}return{changed:l,pkg:s}},Re=/at position (\d+)/,Te=/\(?line (\d+) column (\d+)\)?/,Me=e=>{const r=new Set,s=[],l=o=>{const n=W(o);!r.has(n)&&M(n)&&(r.add(n),s.push(n))};l(E(e,"package.json"));const i=re(e);if(i){const o=N(e,i);for(const n of o)l(E(e,n,"package.json"))}else{const o=E(e,"package.json");if(M(o)){const n=JSON.parse(X(o)),d=Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages;if(d){const g=N(e,d);for(const m of g)l(E(e,m,"package.json"))}}}return s},Ne=e=>/\n([ \t]+)/.exec(e)?.[1]??" ",Ae=e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},I=e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(r=>r.split(",")).map(r=>r.trim()).filter(r=>r.length>0),De=e=>e.includes(`\r
2
- `)?"crlf":"lf",Fe=new Set(["auto","crlf","lf"]),Ge=e=>{if(e===void 0||e==="")return"auto";if(Fe.has(e))return e;throw new Error(`--line-ending must be one of: auto, lf, crlf (got "${e}")`)},Le=(e,r,s)=>r.length===0?e:e.filter(l=>{const i=J(s,l),o=V(l);return!r.some(n=>{const d=n.includes("/")?i:o;return se(n,d)})}),Be=(e,r)=>{if(r.length===0)return e;const s={},l=new Set;for(const i of r)Object.hasOwn(e,i)&&(s[i]=e[i],l.add(i));for(const i of Object.keys(e))l.has(i)||(s[i]=e[i]);return s},Je=(e,r,s)=>{if(s.length===0)return e;const l={...e};for(const i of s)Object.hasOwn(r,i)&&(l[i]=r[i]);return l},Xe=(e,r)=>{let s=1,l=1;const i=Math.min(r,e.length);for(let o=0;o<i;o++)e.codePointAt(o)===10?(s++,l=1):l++;return{column:l,line:s}},L=(e,r,s=2)=>{const l=e.split(`
3
- `);if(r<1||r>l.length)return[];const i=Math.max(0,r-1-s),o=Math.min(l.length,r+s),n=[];for(let d=i;d<o;d++)n.push({content:l[d]??"",isErrorLine:d+1===r,lineNumber:d+1});return n},B=(e,r)=>{if(!(e instanceof Error))return;const s=Re.exec(e.message);if(s){const{column:i,line:o}=Xe(r,Number.parseInt(s[1]??"0",10));return{column:i,line:o,snippet:L(r,o)}}const l=Te.exec(e.message);if(l){const i=Number.parseInt(l[1]??"1",10);return{column:Number.parseInt(l[2]??"1",10),line:i,snippet:L(r,i)}}},qe=(e,r)=>{const s=Object.keys(JSON.parse(e)),l=Object.keys(JSON.parse(r)),i=new Map(s.map((n,d)=>[n,d])),o=[];for(const[n,d]of l.entries()){const g=i.get(d);g!==void 0&&g!==n&&o.push({fromIndex:g,key:d,toIndex:n})}return o},He=(e,r,s)=>{const l=r.indent??s.indent??Ne(e),i=r.lineEnding==="auto"?s.lineEnding??De(e):r.lineEnding,o=q(e,{pretty:!1,sortScripts:r.sortScripts});let n=JSON.parse(o);if(r.unsorted.length>0){const y=JSON.parse(e);n=Je(n,y,r.unsorted)}n=Be(n,r.sortOrder);const d={formatBugs:r.formatBugs,formatRepository:r.formatRepository,sortExports:r.sortExports},g=Ie(n,d);let m=JSON.stringify(g.pkg,null,l);return r.finalNewline&&(m+=`
4
- `),i==="crlf"&&(m=m.replaceAll(`
1
+ import{a as B,z as J,e as C,$ as K,U as Y}from"../packem_shared/index-DHD8wb6Z.js";import{U as q,V,W as z,T as Z,u as Q,p as E,C as ee}from"./cli-main.js";import{i as re}from"../packem_shared/index-BjdW45xX.js";import{y as t,X as f,m as a,u as R,R as te,v as se,A as ne,B as oe,C as ie,i as ce,j as A}from"./catalog.js";import le from"./index.js";import{sortPackageJsonStringWithOptions as U}from"#native";import{e as I}from"../packem_shared/utils-DQFHJn72.js";import{y as L}from"../packem_shared/isAccessibleSync-DYKTrrvc-CSnBISfV.js";const _={error:0,rewritten:1,"would-rewrite":1,unchanged:2},ae=e=>[...e].sort((r,s)=>_[r.status]-_[s.status]),de=(e,r)=>r==="all"?e:r==="errors"?e.filter(s=>s.status==="error"):r==="rewritten"?e.filter(s=>s.status==="rewritten"||s.status==="would-rewrite"):e.filter(s=>s.status==="unchanged");class fe{#e;#r=new Set;constructor(r){this.#e={entries:ae(r),filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=()=>this.#e;subscribe=r=>(this.#r.add(r),()=>{this.#r.delete(r)});getFilteredEntries=()=>de(this.#e.entries,this.#e.filterType);#t(){this.#e={...this.#e};for(const r of this.#r)r()}select(r){const s=this.getFilteredEntries();this.#e.selectedIndex=s.length===0?-1:Math.max(0,Math.min(r,s.length-1)),this.#t()}selectStep(r){this.select(this.#e.selectedIndex+r)}setFilter(r){this.#e.filterType=r,this.#e.selectedIndex=0,this.#t()}setFocusedPanel(r){this.#e.focusedPanel=r,this.#t()}}const ue=({checkMode:e,entry:r,focused:s,scrollRef:c})=>{const o=s?"white":"gray";return r?t.jsxs(f,{borderColor:o,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsx(f,{flexShrink:0,paddingTop:1,paddingX:2,children:t.jsx(a,{bold:!0,color:"white",children:r.relativePath})}),t.jsxs(q,{flexGrow:1,flexShrink:1,paddingX:2,ref:c,scrollbar:!0,scrollbarColor:"gray",children:[t.jsx(a,{}),t.jsxs(f,{children:[t.jsx(f,{width:10,children:t.jsx(a,{dimColor:!0,children:"Status:"})}),r.status==="error"?t.jsx(a,{bold:!0,color:"red",children:"error"}):r.status==="unchanged"?t.jsx(a,{bold:!0,color:"green",children:"already sorted"}):r.status==="rewritten"?t.jsx(a,{bold:!0,color:"yellow",children:"rewritten"}):t.jsx(a,{bold:!0,color:"yellow",children:"would rewrite (--check)"})]}),t.jsxs(f,{children:[t.jsx(f,{width:10,children:t.jsx(a,{dimColor:!0,children:"Path:"})}),t.jsx(a,{children:r.filePath})]}),r.error?t.jsxs(t.Fragment,{children:[t.jsxs(f,{flexDirection:"column",marginTop:1,children:[t.jsx(a,{dimColor:!0,children:"── "}),t.jsx(a,{bold:!0,color:"red",children:"ERROR"}),t.jsxs(f,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[t.jsxs(f,{children:[t.jsx(f,{width:10,children:t.jsx(a,{dimColor:!0,children:"Step:"})}),t.jsx(a,{color:"yellow",children:r.error.step})]}),r.error.context&&t.jsxs(f,{children:[t.jsx(f,{width:10,children:t.jsx(a,{dimColor:!0,children:"Position:"})}),t.jsx(a,{children:`line ${String(r.error.context.line)}, column ${String(r.error.context.column)}`})]}),t.jsx(f,{marginTop:1,children:t.jsx(a,{color:"red",children:r.error.message})})]})]}),r.error.context&&r.error.context.snippet.length>0&&t.jsxs(f,{flexDirection:"column",marginTop:1,children:[t.jsx(a,{dimColor:!0,children:"── "}),t.jsx(a,{bold:!0,color:"white",children:"SNIPPET"}),t.jsxs(f,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r.error.context.snippet.map(n=>{const i=`${n.isErrorLine?"❯":" "} ${String(n.lineNumber).padStart(4)} `;return t.jsxs(f,{children:[t.jsx(a,{color:n.isErrorLine?"red":"gray",children:i}),t.jsx(a,{color:n.isErrorLine?"white":"gray",wrap:"truncate-end",children:n.content||" "})]},n.lineNumber)}),r.error.context.column>0&&t.jsx(f,{children:t.jsx(a,{color:"red",children:`${" ".repeat(7+r.error.context.column-1)}↑`})})]})]})]}):t.jsxs(f,{flexDirection:"column",marginTop:1,children:[t.jsx(a,{dimColor:!0,children:"── "}),t.jsx(a,{bold:!0,color:"white",children:"KEY DIFF"}),t.jsx(f,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.diff.length===0?t.jsx(a,{dimColor:!0,children:"No top-level keys moved (sub-key reorder only)."}):r.diff.map(n=>{const i=n.toIndex-n.fromIndex,d=i<0?`↑ ${String(Math.abs(i))}`:`↓ ${String(i)}`,u=i<0?"green":"yellow";return t.jsxs(f,{children:[t.jsx(f,{width:28,children:t.jsx(a,{wrap:"truncate",children:n.key})}),t.jsx(f,{width:10,children:t.jsxs(a,{dimColor:!0,children:[String(n.fromIndex)," → ",String(n.toIndex)]})}),t.jsx(a,{color:u,children:d})]},n.key)})}),e&&r.status==="would-rewrite"&&t.jsx(f,{marginTop:1,paddingLeft:2,children:t.jsx(a,{dimColor:!0,children:"--check mode: no write performed."})})]})]})]}):t.jsx(f,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:t.jsx(a,{dimColor:!0,children:"No entry selected"})})},he={error:"red",rewritten:"yellow",unchanged:"green","would-rewrite":"yellow"},ge={error:"ERROR",rewritten:"REWROTE",unchanged:"SORTED","would-rewrite":"REWRITE"},W={error:"errors",rewritten:"rewrites",unchanged:"sorted","would-rewrite":"rewrites"},xe={errors:"Errors",rewrites:"Rewrites",sorted:"Sorted"},pe=[{count:e=>e.errors+e.rewrites+e.sorted,key:"all",label:"All",shortcut:"1"},{count:e=>e.rewrites,key:"rewritten",label:"Rewrites",shortcut:"2"},{count:e=>e.errors,key:"errors",label:"Errors",shortcut:"3"},{count:e=>e.sorted,key:"unchanged",label:"Sorted",shortcut:"4"}],X=e=>{const r={errors:0,rewrites:0,sorted:0};for(const s of e)r[W[s.status]]++;return r},me=({entry:e,isSelected:r})=>{const s=he[e.status],c=ge[e.status];return t.jsxs(f,{flexShrink:0,height:1,children:[t.jsx(a,{children:r?">":" "}),t.jsx(a,{children:" "}),t.jsx(a,{bold:!0,color:s,children:`[${c}]`.padEnd(10)}),t.jsx(a,{children:" "}),t.jsx(f,{flexGrow:1,children:t.jsx(a,{bold:r,inverse:r,wrap:"truncate",children:e.relativePath})}),e.status!=="error"&&e.diff.length>0&&t.jsx(a,{dimColor:!0,children:` ${String(e.diff.length)} key${e.diff.length===1?"":"s"}`})]})},je=({color:e,count:r,label:s})=>t.jsx(f,{flexShrink:0,height:1,children:t.jsx(a,{bold:!0,color:e,children:`${s} (${String(r)})`})}),Se=({counts:e,entries:r,filterType:s,focused:c,selectedIndex:o,totalEntries:n,viewportHeight:i})=>{const d=c?"white":"gray",u=X(r),x=(u.errors>0?1:0)+(u.rewrites>0?1:0)+(u.sorted>0?1:0),m=s==="all"&&x>1,h=[];let j;for(const[l,g]of r.entries()){const k=W[g.status];m&&k!==j&&(j!==void 0&&h.push({kind:"spacer"}),h.push({color:k==="errors"?"red":k==="rewrites"?"yellow":"green",count:u[k],kind:"header",label:xe[k]}),j=k),h.push({entry:g,entryIndex:l,kind:"entry"})}const p=h.findIndex(l=>l.kind==="entry"&&l.entryIndex===o),y=p!==-1,S=h.length,w=Math.max(0,S-i);let b=0;y&&i>0&&(b=Math.min(w,Math.max(0,p-i+1)));const O=S>i&&i>0;return t.jsxs(f,{borderColor:d,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsxs(f,{flexShrink:0,gap:1,paddingX:1,children:[t.jsx(a,{bold:!0,inverse:!0,children:" VIS SORT "}),t.jsxs(a,{wrap:"truncate",children:[n," ","file",n===1?"":"s"]})]}),t.jsx(f,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:pe.map(l=>{const g=s===l.key,k=l.count(e);return t.jsxs(f,{children:[t.jsx(a,{dimColor:!g,children:"["}),t.jsx(a,{bold:g,color:g?"cyan":"gray",children:l.shortcut}),t.jsx(a,{dimColor:!g,children:"]"}),t.jsxs(a,{color:g?"white":"gray",children:[" ",l.label]}),t.jsxs(a,{dimColor:!0,children:[" ","(",k,")"]})]},l.key)})}),t.jsxs(f,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[t.jsx(f,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:t.jsx(f,{flexDirection:"column",marginTop:-b,children:h.map((l,g)=>l.kind==="spacer"?t.jsx(f,{flexShrink:0,height:1},`s-${String(g)}`):l.kind==="header"?t.jsx(je,{color:l.color,count:l.count,label:l.label},`h-${l.label}`):t.jsx(me,{entry:l.entry,isSelected:l.entryIndex===o},l.entry.filePath))})}),O&&t.jsx(f,{flexShrink:0,marginLeft:1,marginRight:1,children:t.jsx(V,{contentHeight:S,placement:"inset",scrollOffset:b,style:"block",viewportHeight:i})})]})]})},we=100,D=10,ye=6,ke=1,M={1:"all",2:"rewritten",3:"errors",4:"unchanged"},Ee=({checkMode:e,store:r})=>{const{exit:s}=z(),{columns:c,rows:o}=Z(),n=R.useSyncExternalStore(r.subscribe,r.getSnapshot),i=R.useRef(null),d=r.getFilteredEntries(),u=d[n.selectedIndex]??null,x=X(n.entries),m=c>=we,h=Math.max(0,o-ke),j=m?h:Math.floor(h/2),p=Math.max(0,j-ye),y=R.useCallback(()=>{s()},[s]),S=R.useRef(0),w=R.useRef(void 0),b=R.useRef(!1),O=R.useCallback((l,g)=>{S.current+=g,w.current=l,!b.current&&(b.current=!0,queueMicrotask(()=>{b.current=!1;const k=S.current,N=w.current;S.current=0,w.current=void 0,!(k===0||N===void 0)&&(N==="list"?r.selectStep(Math.sign(k)):i.current?.scrollBy(Math.sign(k)))}))},[r]);return Q((l,g)=>{if(l==="q"||g.escape){y();return}if(M[l]){r.setFilter(M[l]);return}if(g.tab){r.setFocusedPanel(n.focusedPanel==="list"?"detail":"list");return}n.focusedPanel==="list"?g.upArrow||l==="k"?O("list",-1):(g.downArrow||l==="j")&&O("list",1):n.focusedPanel==="detail"&&(g.upArrow||l==="k"?O("detail",-1):(g.downArrow||l==="j")&&O("detail",1))}),o<D?t.jsx(f,{alignItems:"center",justifyContent:"center",children:t.jsxs(a,{color:"yellow",children:["Terminal too small. Resize to at least",D," ","rows."]})}):t.jsxs(f,{flexDirection:"column",height:o,width:c,children:[t.jsxs(f,{flexDirection:m?"row":"column",flexGrow:1,children:[t.jsx(f,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(Se,{counts:x,entries:d,filterType:n.filterType,focused:n.focusedPanel==="list",selectedIndex:n.selectedIndex,totalEntries:n.entries.length,viewportHeight:p})}),t.jsx(f,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(ue,{checkMode:e,entry:u,focused:n.focusedPanel==="detail",scrollRef:i})})]}),t.jsx(f,{flexShrink:0,paddingX:1,children:t.jsx(a,{dimColor:!0,children:"↑/↓ or j/k:navigate | tab:switch panel | 1-4:filter | q:quit"})})]})},F=["types","node-addons","node","import","require","default"],be=/^git\+https:\/\/github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,Oe=/^git\+ssh:\/\/git@github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,T=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),$=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(s=>$(s));const r={};for(const[s,c]of Object.entries(e))r[s]=$(c);return r},Re=e=>{if(!T(e))return{changed:!1,value:e};const r=Object.keys(e);return r.length===1&&r[0]==="url"&&typeof e.url=="string"?{changed:!0,value:e.url}:{changed:!1,value:e}},Ce=e=>e.endsWith(".git")?e.slice(0,-4):e,Ie=e=>{if(!T(e))return{changed:!1,value:e};if(typeof e.directory=="string"&&e.directory.length>0)return{changed:!1,value:e};const{type:r}=e;if(r!==void 0&&r!=="git")return{changed:!1,value:e};const{url:s}=e;if(typeof s!="string")return{changed:!1,value:e};const c=be.exec(s)??Oe.exec(s);if(!c)return{changed:!1,value:e};const o=c[1],n=Ce(c[2]??"");if(!o||!n)return{changed:!1,value:e};const i=new Set(["type","url"]);for(const d of Object.keys(e))if(!i.has(d))return{changed:!1,value:e};return{changed:!0,value:`${o}/${n}`}},Te=e=>{const r=Object.keys(e),s=[],c=[];for(const d of F)Object.hasOwn(e,d)&&s.push(d);for(const d of r)F.includes(d)||c.push(d);const o=[...s,...c];if(o.length===r.length&&o.every((d,u)=>d===r[u]))return{changed:!1,value:e};const i={};for(const d of o)i[d]=e[d];return{changed:!0,value:i}},H=e=>{if(!T(e))return{changed:!1,value:e};let r=!1;const s={};for(const[o,n]of Object.entries(e)){const i=H(n);s[o]=i.value,i.changed&&(r=!0)}const c=Te(s);return{changed:r||c.changed,value:c.value}},Pe=(e,r)=>{const s=$(e);let c=!1;if(r.formatBugs!==!1&&Object.hasOwn(s,"bugs")){const o=Re(s.bugs);o.changed&&(s.bugs=o.value,c=!0)}if(r.formatRepository!==!1&&Object.hasOwn(s,"repository")){const o=Ie(s.repository);o.changed&&(s.repository=o.value,c=!0)}if(r.sortExports!==!1&&Object.hasOwn(s,"exports")&&T(s.exports)){const o=H(s.exports);o.changed&&(s.exports=o.value,c=!0)}return{changed:c,pkg:s}},$e=/at position (\d+)/,Ne=/\(?line (\d+) column (\d+)\)?/,Ae=e=>{const r=new Set,s=[],c=n=>{const i=Y(n);!r.has(i)&&L(i)&&(r.add(i),s.push(i))};c(C(e,"package.json"));const o=ce(e);if(o){const n=A(e,o);for(const i of n)c(C(e,i,"package.json"))}else{const n=C(e,"package.json");if(L(n)){const i=JSON.parse(J(n)),d=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;if(d){const u=A(e,d);for(const x of u)c(C(e,x,"package.json"))}}}return s},Le=e=>/\n([ \t]+)/.exec(e)?.[1]??" ",_e=e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},P=e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(s=>s.split(",")).map(s=>s.trim()).filter(s=>s.length>0),De=e=>e.includes(`\r
2
+ `)?"crlf":"lf",Me=new Set(["auto","crlf","lf"]),Fe=e=>{if(e===void 0||e==="")return"auto";if(Me.has(e))return e;throw new Error(`--line-ending must be one of: auto, lf, crlf (got "${e}")`)},Ge=(e,r,s)=>r.length===0?e:e.filter(c=>{const o=B(s,c),n=K(c);return!r.some(i=>{const d=i.includes("/")?o:n;return le(i,d)})}),ve=(e,r)=>{if(r.length===0)return e;const s={},c=new Set;for(const o of r)Object.hasOwn(e,o)&&(s[o]=e[o],c.add(o));for(const o of Object.keys(e))c.has(o)||(s[o]=e[o]);return s},Be=(e,r,s)=>{if(s.length===0)return e;const c={...e};for(const o of s)Object.hasOwn(r,o)&&(c[o]=r[o]);return c},Je=(e,r)=>{let s=1,c=1;const o=Math.min(r,e.length);for(let n=0;n<o;n++)e.codePointAt(n)===10?(s++,c=1):c++;return{column:c,line:s}},G=(e,r,s=2)=>{const c=e.split(`
3
+ `);if(r<1||r>c.length)return[];const o=Math.max(0,r-1-s),n=Math.min(c.length,r+s),i=[];for(let d=o;d<n;d++)i.push({content:c[d]??"",isErrorLine:d+1===r,lineNumber:d+1});return i},v=(e,r)=>{if(!(e instanceof Error))return;const s=$e.exec(e.message);if(s){const{column:o,line:n}=Je(r,Number.parseInt(s[1]??"0",10));return{column:o,line:n,snippet:G(r,n)}}const c=Ne.exec(e.message);if(c){const o=Number.parseInt(c[1]??"1",10);return{column:Number.parseInt(c[2]??"1",10),line:o,snippet:G(r,o)}}},Ue=(e,r)=>{const s=Object.keys(JSON.parse(e)),c=Object.keys(JSON.parse(r)),o=new Map(s.map((i,d)=>[i,d])),n=[];for(const[i,d]of c.entries()){const u=o.get(d);u!==void 0&&u!==i&&n.push({fromIndex:u,key:d,toIndex:i})}return n},We=(e,r,s)=>{const c=r.indent??s.indent??Le(e),o=r.lineEnding==="auto"?s.lineEnding??De(e):r.lineEnding,n=U(e,{pretty:!1,sortScripts:r.sortScripts});let i=JSON.parse(n);if(r.unsorted.length>0){const m=JSON.parse(e);i=Be(i,m,r.unsorted)}i=ve(i,r.sortOrder);const d={formatBugs:r.formatBugs,formatRepository:r.formatRepository,sortExports:r.sortExports},u=Pe(i,d);let x=JSON.stringify(u.pkg,null,c);return r.finalNewline&&(x+=`
4
+ `),o==="crlf"&&(x=x.replaceAll(`
5
5
  `,`\r
6
- `)),m},ze=(e,r)=>{const s=Me(e),l=U(e),i=Z({cwd:e,extraPatterns:_(l)}),o=s.filter(d=>!i.ignores(d)),n=Le(o,r,e);return{afterGitignore:o,allFiles:s,files:n}},Ke=async(e,{checkMode:r,cwd:s,fs:l,normalized:i})=>{const o=J(s,e)||e;let n;try{n=X(e)}catch(h){return{diff:[],error:{message:O(h),step:"read"},filePath:e,relativePath:o,status:"error"}}let d;try{d=q(n,{pretty:!1,sortScripts:i.sortScripts})}catch(h){const w={message:O(h),step:"native-sort"},x=B(h,n);return x&&(w.context=x),{diff:[],error:w,filePath:e,relativePath:o,status:"error"}}const g=i.editorconfig?ee(e):{};let m;try{m=He(n,i,g)}catch(h){const w={message:O(h),step:"json-parse"},x=B(h,n);return x&&(w.context=x),{diff:[],error:w,filePath:e,relativePath:o,status:"error"}}if(n===m)return{diff:[],filePath:e,relativePath:o,status:"unchanged"};let y;try{y=qe(n,d)}catch{y=[]}if(r)return{diff:y,filePath:e,relativePath:o,status:"would-rewrite"};try{await l.writeFile(e,m,"utf8")}catch(h){return{diff:y,error:{message:O(h),step:"write"},filePath:e,relativePath:o,status:"error"}}return{diff:y,filePath:e,relativePath:o,status:"rewritten"}},Ve=e=>{if(e.error&&(S.error(`${e.filePath}: ${e.error.message}`),S.info(` step: ${e.error.step}`),e.error.context)){S.info(` at line ${String(e.error.context.line)}, column ${String(e.error.context.column)}`);for(const r of e.error.context.snippet){const s=r.isErrorLine?">":" ";S.info(` ${s} ${String(r.lineNumber).padStart(4)} | ${r.content}`)}}},or=async({fs:e,options:r,visConfig:s,workspaceRoot:l})=>{const i=l??process.cwd(),o=s?.sortPackageJson,n=r.check||!1,d={editorconfig:r.editorconfig===!1?!1:o?.editorconfig??!0,finalNewline:r.finalNewline??o?.finalNewline??!0,formatBugs:r.formatBugs===!1?!1:o?.formatBugs??!0,formatRepository:r.formatRepository===!1?!1:o?.formatRepository??!0,ignore:[...I(r.ignore),...o?.ignore??[]],indent:Ae(r.indent??o?.indent),lineEnding:Ge(r.lineEnding??o?.lineEnding),sortExports:r.sortExports===!1?!1:o?.sortExports??!0,sortOrder:[...I(r.sortOrder),...o?.sortOrder??[]],sortScripts:r.sortScripts||o?.sortScripts||!1,unsorted:[...I(r.unsorted),...o?.unsorted??[]]},g=ze(i,d.ignore),{afterGitignore:m,allFiles:y,files:h}=g;if(h.length===0){y.length===0?S.info("No package.json files found."):m.length===0?S.info("All package.json files were excluded by .gitignore or workspace exclusions."):S.info("All package.json files were excluded by --ignore.");return}const w=[];for(const f of h)w.push(await Ke(f,{checkMode:n,cwd:i,fs:e,normalized:d}));let x=0,k=0,j=0;for(const f of w)f.status==="error"?j++:f.status==="rewritten"||f.status==="would-rewrite"?x++:k++;const $=x>0||j>0;if(process.stdout.isTTY&&!te&&$){const f=new ue(w);await Y(Q.createElement(ke,{checkMode:n,store:f}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit()}else for(const f of w)switch(f.status){case"error":{Ve(f);break}case"rewritten":{S.success(`Sorted ${f.filePath}`);break}case"would-rewrite":{S.warn(`${f.filePath} is not sorted`);break}}if(n)x>0?(S.info(`${String(x)} file${x===1?"":"s"} not sorted, ${String(k)} already sorted`),process.exitCode=1):j===0&&S.info(`All ${String(k)} package.json file${k===1?" is":"s are"} sorted`);else{const f=[];x>0&&f.push(`sorted ${String(x)} file${x===1?"":"s"}`),k>0&&f.push(`${String(k)} already sorted`),j>0&&f.push(`${String(j)} error${j===1?"":"s"}`),f.length>0&&S.info(f.join(", "))}j>0&&(process.exitCode=1)};export{L as buildSnippet,qe as computeKeyDiff,Xe as computeLineColumn,or as default,ze as discoverPackageJsonFiles,B as extractParseErrorContext,Ke as processFile};
6
+ `)),x},Xe=(e,r)=>{const s=Ae(e),c=se(e),o=ne({cwd:e,extraPatterns:oe(c)}),n=s.filter(d=>!o.ignores(d)),i=Ge(n,r,e);return{afterGitignore:n,allFiles:s,files:i}},He=async(e,{checkMode:r,cwd:s,fs:c,normalized:o})=>{const n=B(s,e)||e;let i;try{i=J(e)}catch(h){return{diff:[],error:{message:I(h),step:"read"},filePath:e,relativePath:n,status:"error"}}let d;try{d=U(i,{pretty:!1,sortScripts:o.sortScripts})}catch(h){const j={message:I(h),step:"native-sort"},p=v(h,i);return p&&(j.context=p),{diff:[],error:j,filePath:e,relativePath:n,status:"error"}}const u=o.editorconfig?ie(e):{};let x;try{x=We(i,o,u)}catch(h){const j={message:I(h),step:"json-parse"},p=v(h,i);return p&&(j.context=p),{diff:[],error:j,filePath:e,relativePath:n,status:"error"}}if(i===x)return{diff:[],filePath:e,relativePath:n,status:"unchanged"};let m;try{m=Ue(i,d)}catch{m=[]}if(r)return{diff:m,filePath:e,relativePath:n,status:"would-rewrite"};try{await c.writeFile(e,x,"utf8")}catch(h){return{diff:m,error:{message:I(h),step:"write"},filePath:e,relativePath:n,status:"error"}}return{diff:m,filePath:e,relativePath:n,status:"rewritten"}},Ke=e=>{if(e.error&&(E.error(`${e.filePath}: ${e.error.message}`),E.info(` step: ${e.error.step}`),e.error.context)){E.info(` at line ${String(e.error.context.line)}, column ${String(e.error.context.column)}`);for(const r of e.error.context.snippet){const s=r.isErrorLine?">":" ";E.info(` ${s} ${String(r.lineNumber).padStart(4)} | ${r.content}`)}}},tr=async({fs:e,options:r,visConfig:s,workspaceRoot:c})=>{const o=c??process.cwd(),n=s?.sortPackageJson,i=r.check||!1,u={editorconfig:r.editorconfig===!1?!1:n?.editorconfig??!0,finalNewline:r.finalNewline??n?.finalNewline??!0,formatBugs:r.formatBugs===!1?!1:n?.formatBugs??!0,formatRepository:r.formatRepository===!1?!1:n?.formatRepository??!0,ignore:[...P(r.ignore),...n?.ignore??[]],indent:_e(r.indent??n?.indent),lineEnding:Fe(r.lineEnding??n?.lineEnding),sortExports:r.sortExports===!1?!1:n?.sortExports??!0,sortOrder:[...P(r.sortOrder),...n?.sortOrder??[]],sortScripts:r.sortScripts||n?.sortScripts||!1,unsorted:[...P(r.unsorted),...n?.unsorted??[]]},x=Xe(o,u.ignore),{afterGitignore:m,allFiles:h,files:j}=x;if(j.length===0){h.length===0?E.info("No package.json files found."):m.length===0?E.info("All package.json files were excluded by .gitignore or workspace exclusions."):E.info("All package.json files were excluded by --ignore.");return}const p=[];for(const l of j)p.push(await He(l,{checkMode:i,cwd:o,fs:e,normalized:u}));let y=0,S=0,w=0;for(const l of p)l.status==="error"?w++:l.status==="rewritten"||l.status==="would-rewrite"?y++:S++;const b=y>0||w>0;if(!!process.stdout.isTTY&&!re&&b){const l=new fe(p);await ee(te.createElement(Ee,{checkMode:i,store:l}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit()}else for(const l of p)switch(l.status){case"error":{Ke(l);break}case"rewritten":{E.success(`Sorted ${l.filePath}`);break}case"would-rewrite":{E.warn(`${l.filePath} is not sorted`);break}}if(i)y>0?(E.info(`${String(y)} file${y===1?"":"s"} not sorted, ${String(S)} already sorted`),process.exitCode=1):w===0&&E.info(`All ${String(S)} package.json file${S===1?" is":"s are"} sorted`);else{const l=[];y>0&&l.push(`sorted ${String(y)} file${y===1?"":"s"}`),S>0&&l.push(`${String(S)} already sorted`),w>0&&l.push(`${String(w)} error${w===1?"":"s"}`),l.length>0&&E.info(l.join(", "))}w>0&&(process.exitCode=1)};export{G as buildSnippet,Ue as computeKeyDiff,Je as computeLineColumn,tr as default,Xe as discoverPackageJsonFiles,v as extractParseErrorContext,He as processFile};
@@ -1,9 +1,9 @@
1
- import{createRequire as z}from"node:module";import{DEFAULT_CHANGES_DIR as J}from"./DEFAULT_CLEAN_KEEP.js";import{b as Q,f as X}from"./orchestrator.js";import{createShellRunner as ee}from"./shell-runner.js";import{r as te}from"../packem_shared/slug-DoueYuLo.js";import{maxBump as re}from"../release/types.js";let V;const U=n=>(V??=z(import.meta.url))(n),_=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Y=n=>{if(typeof _<"u"&&_.versions&&_.versions.node){const[e,t]=_.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return _.getBuiltinModule(n)}return U(n)},{join:M,relative:Z}=Y("node:path"),D=/(?!.*)/;function ne(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function j(n){return n.map(e=>typeof e=="string"?ne(e.trim()):e.source).filter(Boolean).join("|")}function se(n,e){if(!n)return D;const t=j(n);return e?e(t):new RegExp(`^[\\s|*]*(${t})[:\\s]+(.*)`,"i")}function ie(n,e){if(!n)return D;const t=e?"g":"gi";return new RegExp(`(?:.*?)??\\s*([\\w-\\.\\/]*?)??(${j(n)})([\\w-]+)(?=\\s|$|[,;.)\\]])`,t)}function oe(n){if(!n)return/()(.+)/gi;const e=j(n);return new RegExp(`(${e})(?:\\s+(.*?))(?=(?:${e})|$)`,"gi")}function ce(n){const e=n?`|\\s+(?:${j(n)})`:"";return new RegExp(`^\\s*(?:BREAKING CHANGE|[\\w-]+)(?::\\s+${e}).+`,"i")}function ae(n={}){const e=se(n.noteKeywords,n.notesPattern),t=ie(n.issuePrefixes,n.issuePrefixesCaseSensitive),r=oe(n.referenceActions),s=ce(n.issuePrefixes);return{notes:e,referenceParts:t,references:r,footerToken:s,mentions:/@([\w-]+)/g,url:/\b(?:https?):\/\/(?:www\.)?([-a-zA-Z0-9@:%_+.~#?&//=])+\b/}}const le="------------------------ >8 ------------------------";function P(n){const e=n.match(/[^\r\n]/);if(typeof e?.index!="number")return"";const t=e.index;let r=n.length-1;for(;n[r]==="\r"||n[r]===`
2
- `;)r--;return n.substring(t,r+1)}function A(n,e){return n?`${n}
3
- ${e||""}`:e||""}function fe(n){return n?e=>!e.startsWith(n):()=>!0}function ue(n,e){const t=n.indexOf(`${e} ${le}`);return t===-1?n:n.slice(0,t)}function T(n){return!n.match(/^\s*gpg:/)}function S(n,e,t){const{groups:r}=e;for(let s=0,i=t.length,c;s<i;s++)c=t[s],n[c]=(r?r[c]:e[s+1])||null;return n}const he={noteKeywords:["BREAKING CHANGE","BREAKING-CHANGE"],issuePrefixes:["#"],referenceActions:["close","closes","closed","fix","fixes","fixed","resolve","resolves","resolved"],headerPattern:/^(\w*)(?:\(([\w$@.\-*/ ]*)\))?: (.*)$/,headerCorrespondence:["type","scope","subject"],revertPattern:/^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\.?/,revertCorrespondence:["header","hash"],fieldPattern:/^-(.*?)-$/};function I(n={}){return{merge:null,revert:null,header:null,body:null,footer:null,notes:[],mentions:[],references:[],...n}}class pe{options;regexes;lines=[];lineIndex=0;commit=I();constructor(e={}){this.options={...he,...e},this.regexes=ae(this.options)}currentLine(){return this.lines[this.lineIndex]}nextLine(){return this.lines[this.lineIndex++]}isLineAvailable(){return this.lineIndex<this.lines.length}parseReference(e,t){const{regexes:r}=this;if(r.url.test(e))return null;const s=r.referenceParts.exec(e);if(!s)return null;let[i,c=null,h,p]=s,x=null;if(c){const b=c.indexOf("/");b!==-1&&(x=c.slice(0,b),c=c.slice(b+1))}return{raw:i,action:t,owner:x,repository:c,prefix:h,issue:p}}parseReferences(e){const{regexes:t}=this,r=e.match(t.references)?t.references:/()(.+)/gi,s=[];let i,c,h,p;for(;i=r.exec(e),!!i;)for(c=i[1]||null,h=i[2]||"";p=this.parseReference(h,c),!!p;)s.push(p);return s}skipEmptyLines(){let e=this.currentLine();for(;e!==void 0&&!e.trim();)this.nextLine(),e=this.currentLine()}parseMerge(){const{commit:e,options:t}=this,r=t.mergeCorrespondence||[],s=this.currentLine(),i=s&&t.mergePattern?s.match(t.mergePattern):null;return i?(this.nextLine(),e.merge=i[0]||null,S(e,i,r),!0):!1}parseHeader(e){e&&this.skipEmptyLines();const{commit:t,options:r}=this,s=r.headerCorrespondence||[],i=t.header??this.nextLine();let c=null;i&&(r.breakingHeaderPattern&&(c=i.match(r.breakingHeaderPattern)),!c&&r.headerPattern&&(c=i.match(r.headerPattern))),i&&(t.header=i),c&&S(t,c,s)}parseMeta(){const{options:e,commit:t}=this;if(!e.fieldPattern||!this.isLineAvailable())return!1;let r,s=null,i=!1;for(;this.isLineAvailable();){if(r=this.currentLine().match(e.fieldPattern),r){s=r[1]||null,this.nextLine();continue}if(s)i=!0,t[s]=A(t[s],this.currentLine()),this.nextLine();else break}return i}parseNotes(){const{regexes:e,commit:t}=this;if(!this.isLineAvailable())return!1;const r=this.currentLine().match(e.notes);let s;if(r){const i={title:r[1],text:r[2]};for(t.notes.push(i),t.footer=A(t.footer,this.currentLine()),this.nextLine();this.isLineAvailable();){if(this.parseMeta()||this.parseNotes())return!0;if(s=e.footerToken.test(this.currentLine()),t.references.push(...this.parseReferences(this.currentLine())),s||(i.text=A(i.text,this.currentLine())),t.footer=A(t.footer,this.currentLine()),this.nextLine(),s)break}return!0}return!1}parseBodyAndFooter(e){const{commit:t,regexes:r}=this;if(!this.isLineAvailable())return e;const s=!r.footerToken.test(this.currentLine())&&e;return t.references.push(...this.parseReferences(this.currentLine())),s?t.body=A(t.body,this.currentLine()):t.footer=A(t.footer,this.currentLine()),this.nextLine(),s}parseBreakingHeader(){const{commit:e,options:t}=this;if(!t.breakingHeaderPattern||e.notes.length||!e.header)return;const r=e.header.match(t.breakingHeaderPattern);r&&e.notes.push({title:"BREAKING CHANGE",text:r[3]})}parseMentions(e){const{commit:t,regexes:r}=this;let s;for(;s=r.mentions.exec(e),!!s;)t.mentions.push(s[1])}parseRevert(e){const{commit:t,options:r}=this,s=r.revertCorrespondence||[],i=r.revertPattern?e.match(r.revertPattern):null;i&&(t.revert=S({},i,s))}cleanupCommit(){const{commit:e}=this;e.body&&=P(e.body),e.footer&&=P(e.footer),e.notes.forEach(r=>{r.text=P(r.text)});const t=new Set;e.references=e.references.filter(r=>{const s=`${r.action} ${r.raw}`.toLocaleLowerCase(),i=!t.has(s);return i&&t.add(s),i})}parse(e){if(!e.trim())throw new TypeError("Expected a raw commit");const{commentChar:t}=this.options,r=fe(t),s=P(e).split(/\r?\n/),i=t?ue(s,t).filter(x=>r(x)&&T(x)):s.filter(x=>T(x)),c=I();this.lines=i,this.lineIndex=0,this.commit=c;const h=this.parseMerge();this.parseHeader(h),c.header&&(c.references=this.parseReferences(c.header));let p=!0;for(;this.isLineAvailable();)this.parseMeta(),this.parseNotes()&&(p=!1),this.parseBodyAndFooter(p)||(p=!1);return this.parseBreakingHeader(),this.parseMentions(e),this.parseRevert(e),this.cleanupCommit(),c}}const N={build:"patch",chore:"patch",ci:"patch",docs:"patch",feat:"minor",fix:"patch",perf:"patch",refactor:"patch",style:"patch",test:"patch"},de=new pe,me=/^Revert\s+"(.+)"\s*$/,ge=/This reverts commit\s+([0-9a-f]{7,40})/i,xe=/^(?:[\p{Emoji_Presentation}\p{Extended_Pictographic}]|:\w+:)\s+/u,ve=(n,e)=>{const t=n.replace(xe,""),r=de.parse(`${t}
1
+ import{createRequire as z}from"node:module";import{DEFAULT_CHANGES_DIR as Y}from"./DEFAULT_CLEAN_KEEP.js";import{b as Z,f as Q}from"./orchestrator.js";import{createShellRunner as ee}from"./shell-runner.js";import{r as te}from"../packem_shared/slug-OBHcH7wV.js";import{maxBump as ne}from"../release/types.js";let X;const V=r=>(X??=z(import.meta.url))(r),k=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,U=r=>{if(typeof k<"u"&&k.versions&&k.versions.node){const[e,t]=k.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return k.getBuiltinModule(r)}return V(r)},{join:N,relative:J}=U("node:path"),G=/(?!.*)/;function re(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function C(r){return r.map(e=>typeof e=="string"?re(e.trim()):e.source).filter(Boolean).join("|")}function se(r,e){if(!r)return G;const t=C(r);return e?e(t):new RegExp(`^[\\s|*]*(${t})[:\\s]+(.*)`,"i")}function ie(r,e){if(!r)return G;const t=e?"g":"gi";return new RegExp(`(?:.*?)??\\s*([\\w-\\.\\/]*?)??(${C(r)})([\\w-]+)(?=\\s|$|[,;.)\\]])`,t)}function oe(r){if(!r)return/()(.+)/gi;const e=C(r);return new RegExp(`(${e})(?:\\s+(.*?))(?=(?:${e})|$)`,"gi")}function ce(r){const e=r?`|\\s+(?:${C(r)})`:"";return new RegExp(`^\\s*(?:BREAKING CHANGE|[\\w-]+)(?::\\s+${e}).+`,"i")}function ae(r={}){const e=se(r.noteKeywords,r.notesPattern),t=ie(r.issuePrefixes,r.issuePrefixesCaseSensitive),n=oe(r.referenceActions),s=ce(r.issuePrefixes);return{notes:e,referenceParts:t,references:n,footerToken:s,mentions:/@([\w-]+)/g,url:/\b(?:https?):\/\/(?:www\.)?([-a-zA-Z0-9@:%_+.~#?&//=])+\b/}}const le="------------------------ >8 ------------------------";function S(r){const e=r.match(/[^\r\n]/);if(typeof e?.index!="number")return"";const t=e.index;let n=r.length-1;for(;r[n]==="\r"||r[n]===`
2
+ `;)n--;return r.substring(t,n+1)}function $(r,e){return r?`${r}
3
+ ${e||""}`:e||""}function fe(r){return r?e=>!e.startsWith(r):()=>!0}function he(r,e){const t=r.indexOf(`${e} ${le}`);return t===-1?r:r.slice(0,t)}function B(r){return!r.match(/^\s*gpg:/)}function I(r,e,t){const{groups:n}=e;for(let s=0,i=t.length,c;s<i;s++)c=t[s],r[c]=(n?n[c]:e[s+1])||null;return r}const ue={noteKeywords:["BREAKING CHANGE","BREAKING-CHANGE"],issuePrefixes:["#"],referenceActions:["close","closes","closed","fix","fixes","fixed","resolve","resolves","resolved"],headerPattern:/^(\w*)(?:\(([\w$@.\-*/ ]*)\))?: (.*)$/,headerCorrespondence:["type","scope","subject"],revertPattern:/^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\.?/,revertCorrespondence:["header","hash"],fieldPattern:/^-(.*?)-$/};function F(r={}){return{merge:null,revert:null,header:null,body:null,footer:null,notes:[],mentions:[],references:[],...r}}class de{options;regexes;lines=[];lineIndex=0;commit=F();constructor(e={}){this.options={...ue,...e},this.regexes=ae(this.options)}currentLine(){return this.lines[this.lineIndex]}nextLine(){return this.lines[this.lineIndex++]}isLineAvailable(){return this.lineIndex<this.lines.length}parseReference(e,t){const{regexes:n}=this;if(n.url.test(e))return null;const s=n.referenceParts.exec(e);if(!s)return null;let[i,c=null,u,d]=s,x=null;if(c){const w=c.indexOf("/");w!==-1&&(x=c.slice(0,w),c=c.slice(w+1))}return{raw:i,action:t,owner:x,repository:c,prefix:u,issue:d}}parseReferences(e){const{regexes:t}=this,n=e.match(t.references)?t.references:/()(.+)/gi,s=[];let i,c,u,d;for(;i=n.exec(e),!!i;)for(c=i[1]||null,u=i[2]||"";d=this.parseReference(u,c),!!d;)s.push(d);return s}skipEmptyLines(){let e=this.currentLine();for(;e!==void 0&&!e.trim();)this.nextLine(),e=this.currentLine()}parseMerge(){const{commit:e,options:t}=this,n=t.mergeCorrespondence||[],s=this.currentLine(),i=s&&t.mergePattern?s.match(t.mergePattern):null;return i?(this.nextLine(),e.merge=i[0]||null,I(e,i,n),!0):!1}parseHeader(e){e&&this.skipEmptyLines();const{commit:t,options:n}=this,s=n.headerCorrespondence||[],i=t.header??this.nextLine();let c=null;i&&(n.breakingHeaderPattern&&(c=i.match(n.breakingHeaderPattern)),!c&&n.headerPattern&&(c=i.match(n.headerPattern))),i&&(t.header=i),c&&I(t,c,s)}parseMeta(){const{options:e,commit:t}=this;if(!e.fieldPattern||!this.isLineAvailable())return!1;let n,s=null,i=!1;for(;this.isLineAvailable();){if(n=this.currentLine().match(e.fieldPattern),n){s=n[1]||null,this.nextLine();continue}if(s)i=!0,t[s]=$(t[s],this.currentLine()),this.nextLine();else break}return i}parseNotes(){const{regexes:e,commit:t}=this;if(!this.isLineAvailable())return!1;const n=this.currentLine().match(e.notes);let s;if(n){const i={title:n[1],text:n[2]};for(t.notes.push(i),t.footer=$(t.footer,this.currentLine()),this.nextLine();this.isLineAvailable();){if(this.parseMeta()||this.parseNotes())return!0;if(s=e.footerToken.test(this.currentLine()),t.references.push(...this.parseReferences(this.currentLine())),s||(i.text=$(i.text,this.currentLine())),t.footer=$(t.footer,this.currentLine()),this.nextLine(),s)break}return!0}return!1}parseBodyAndFooter(e){const{commit:t,regexes:n}=this;if(!this.isLineAvailable())return e;const i=!n.footerToken.test(this.currentLine())&&e;return t.references.push(...this.parseReferences(this.currentLine())),i?t.body=$(t.body,this.currentLine()):t.footer=$(t.footer,this.currentLine()),this.nextLine(),i}parseBreakingHeader(){const{commit:e,options:t}=this;if(!t.breakingHeaderPattern||e.notes.length||!e.header)return;const n=e.header.match(t.breakingHeaderPattern);n&&e.notes.push({title:"BREAKING CHANGE",text:n[3]})}parseMentions(e){const{commit:t,regexes:n}=this;let s;for(;s=n.mentions.exec(e),!!s;)t.mentions.push(s[1])}parseRevert(e){const{commit:t,options:n}=this,s=n.revertCorrespondence||[],i=n.revertPattern?e.match(n.revertPattern):null;i&&(t.revert=I({},i,s))}cleanupCommit(){const{commit:e}=this;e.body&&=S(e.body),e.footer&&=S(e.footer),e.notes.forEach(n=>{n.text=S(n.text)});const t=new Set;e.references=e.references.filter(n=>{const s=`${n.action} ${n.raw}`.toLocaleLowerCase(),i=!t.has(s);return i&&t.add(s),i})}parse(e){if(!e.trim())throw new TypeError("Expected a raw commit");const{commentChar:t}=this.options,n=fe(t),s=S(e).split(/\r?\n/),i=t?he(s,t).filter(x=>n(x)&&B(x)):s.filter(x=>B(x)),c=F();this.lines=i,this.lineIndex=0,this.commit=c;const u=this.parseMerge();this.parseHeader(u),c.header&&(c.references=this.parseReferences(c.header));let d=!0;for(;this.isLineAvailable();)this.parseMeta(),this.parseNotes()&&(d=!1),this.parseBodyAndFooter(d)||(d=!1);return this.parseBreakingHeader(),this.parseMentions(e),this.parseRevert(e),this.cleanupCommit(),c}}const D={build:"patch",chore:"patch",ci:"patch",docs:"patch",feat:"minor",fix:"patch",perf:"patch",refactor:"patch",style:"patch",test:"patch"},me=new de,pe=/^Revert\s+"(.+)"\s*$/,ge=/This reverts commit\s+([0-9a-f]{7,40})/i,xe=/^(?:[\p{Emoji_Presentation}\p{Extended_Pictographic}]|:\w+:)\s+/u,be=(r,e)=>{const t=r.replace(xe,""),n=me.parse(`${t}
4
4
 
5
- ${e}`);return{breaking:r.notes.some(s=>/BREAKING/i.test(s.title)),scope:r.scope??void 0,type:r.type??void 0}},be=(n,e,t)=>{let r,s=!1;if(t.type==="revert"){s=!0;const h=n.indexOf(":");h!==-1&&(r=n.slice(h+1).trim())}else{const h=me.exec(n.trim());h&&(s=!0,r=h[1]?.trim())}let i;const c=ge.exec(e);return c&&(i=c[1]?.toLowerCase()),{isRevert:s,targetSha:i,targetSubject:r}},we=(n,e=new Set,t)=>{const r=n.map(o=>{const l=ve(o.subject,o.body),{isRevert:a,targetSha:f,targetSubject:d}=be(o.subject,o.body,l);return{...o,cancelled:!1,parsed:l,revert:a,revertSubject:d,revertTargetSha:f}}),s=r.toReversed(),i=12,c=new Map;for(const o of s)if(c.set(o.hash,o),o.hash.length>=7){const l=Math.min(o.hash.length-1,i);for(let a=7;a<=l;a+=1){const f=o.hash.slice(0,a);if(c.has(f)){const d=c.get(f);d!==null&&d!==o&&c.set(f,null)}else c.set(f,o)}}const h=(o,l)=>{if(o.revertTargetSha){const a=o.revertTargetSha.toLowerCase();let f=c.get(a)??void 0;if(f||(f=s.find(d=>d.hash.startsWith(a))),f&&f!==o)return f}if(o.revertSubject)for(let a=l.length-1;a>=0;a-=1){const f=l[a];if(f.subject===o.revertSubject)return f}},p=64,x=o=>{let l=o;for(let a=0;a<p;a+=1){if(!l.revert)return l;const f=l.cancelledBy;let d;if(f&&(d=c.get(f)??void 0,d||(d=c.get(f.slice(0,7))??void 0)),!d||d===l)return l;l=d}},b=[],w=[];for(const o of s){if(o.revert){const l=h(o,w);if(l){if(e.has(l.hash)){w.push(o);continue}const a=x(l);if(a===void 0){b.push(`Revert chain at ${o.hash} exceeded depth limit (${p}) — skipping cancellation`),w.push(o);continue}if(e.has(a.hash)){w.push(o);continue}a.cancelled=!a.cancelled,a.cancelledBy=a.cancelled?o.hash:void 0,o.cancelled=!0,o.cancelledBy=l.hash}}w.push(o)}const L=r.filter(o=>!o.cancelled&&!o.revert&&!o.subject?.startsWith("Merge ")),E=L.filter(o=>!o.parsed.type);if(L.length>0&&E.length/L.length>.5){const o=t??"<from>..HEAD";b.push(`${E.length}/${L.length} commits in ${o} have no conventional-commits prefix. Consider enabling commit-message linting.`)}return{commits:r,warnings:b}},Ce=async({fs:n,logger:e,options:t,workspaceRoot:r})=>{const s=r??process.cwd(),i=await Q({cwd:s,skipRegistryLookup:!0}),{printConfigIfRequested:c}=await import("./print-config.js");if(c(t,i,e))return;const h=ee();let p=t.from;if(!p){const u=i.config.baseBranch??"main",m=await h.run("git",["merge-base",`origin/${u}`,"HEAD"],{cwd:s,silent:!0});if(m.exitCode===0&&m.stdout.trim())p=m.stdout.trim();else{const g=await h.run("git",["merge-base",u,"HEAD"],{cwd:s,silent:!0});p=g.exitCode===0?g.stdout.trim():"HEAD~10"}}const x=new Map;for(const u of i.packages){const m=(u.dir.startsWith(s)?u.dir.slice(s.length):u.dir).replaceAll("\\","/").replace(/^\/+/,"");x.set(m,u.name)}const b=u=>{for(const[m,g]of x)if(u.startsWith(`${m}/`)||u===`${m}/package.json`)return g},w=Math.random().toString(16).slice(2,10),L=`@@VIS_RELEASE_COMMIT_${w}@@`,E=`@@VIS_RELEASE_FILES_${w}@@`,o=await h.run("git",["log",`${p}..HEAD`,`--pretty=format:${L}%n%H%n%s%n%b%n${E}`,"--name-only"],{cwd:s,silent:!0});if(o.exitCode!==0){e.error(`git log failed: ${o.stderr}`),process.exitCode=1;return}const l=new Map,a=[],f=[],d=o.stdout.split(L).map(u=>u.trim()).filter(Boolean);for(const u of d){const[m,g=""]=u.split(E).toReversed(),C=g.split(`
6
- `),$=C[0]?.trim()??"",y=C[1]?.trim()??"",v=C.slice(2).join(`
7
- `).trim(),R=(m??"").split(`
8
- `).map(q=>q.trim()).filter(Boolean);$&&f.push({body:v,files:R,hash:$,subject:y})}const{commits:G,warnings:F}=we(f,void 0,`${p}..HEAD`);for(const u of F)e.warn(u);for(const{cancelled:u,files:m,parsed:g,subject:C}of G){if(u)continue;let $="patch";g.breaking?$="major":g.type&&N[g.type]&&($=N[g.type]??"patch");const y=new Set;if(g.scope)for(const v of i.packages)(v.name===g.scope||v.name.endsWith(`/${g.scope}`))&&y.add(v.name);if(y.size===0)for(const v of m){const R=b(v);R&&y.add(R)}for(const v of y){const R=l.get(v);l.set(v,R?re(R,$):$)}y.size>0&&a.push(`- ${C}`)}if(l.size===0){e.info("No commits affected workspace packages — nothing to generate.");return}const O={bumps:Object.fromEntries(l)},K=a.length>0?a.join(`
9
- `):"Auto-generated change file.",k=X(O,K);if(t.dryRun){e.info("[dry-run] would write:"),e.info(k);return}const B=i.config.changesDir??J,W=(t.name??te()).replaceAll(/[^a-z0-9-]/gi,"-"),H=M(s,B,`${W}.md`);await n.mkdir(M(s,B),{recursive:!0}),await n.writeFile(H,k),e.info(`Created ${Z(s,H)}`);for(const[u,m]of l)e.info(` ${u}: ${m}`)};export{Ce as default};
5
+ ${e}`);return{breaking:n.notes.some(i=>/BREAKING/i.test(i.title)),scope:n.scope??void 0,type:n.type??void 0}},we=(r,e,t)=>{let n,s=!1;if(t.type==="revert"){s=!0;const u=r.indexOf(":");u!==-1&&(n=r.slice(u+1).trim())}else{const u=pe.exec(r.trim());u&&(s=!0,n=u[1]?.trim())}let i;const c=ge.exec(e);return c&&(i=c[1]?.toLowerCase()),{isRevert:s,targetSha:i,targetSubject:n}},Re=(r,e=new Set,t)=>{const n=r.map(o=>{const l=be(o.subject,o.body),{isRevert:a,targetSha:m,targetSubject:h}=we(o.subject,o.body,l);return{...o,cancelled:!1,parsed:l,revert:a,revertSubject:h,revertTargetSha:m}}),s=n.toReversed(),i=12,c=new Map;for(const o of s)if(c.set(o.hash,o),o.hash.length>=7){const l=Math.min(o.hash.length-1,i);for(let a=7;a<=l;a+=1){const m=o.hash.slice(0,a);if(c.has(m)){const h=c.get(m);h!==null&&h!==o&&c.set(m,null)}else c.set(m,o)}}const u=(o,l)=>{if(o.revertTargetSha){const a=o.revertTargetSha.toLowerCase();let h=c.get(a)??void 0;if(h||(h=s.find(P=>P.hash.startsWith(a))),h&&h!==o)return h}if(o.revertSubject)for(let a=l.length-1;a>=0;a-=1){const m=l[a];if(m.subject===o.revertSubject)return m}},d=64,x=o=>{let l=o;for(let a=0;a<d;a+=1){if(!l.revert)return l;const m=l.cancelledBy;let h;if(m&&(h=c.get(m)??void 0,h||(h=c.get(m.slice(0,7))??void 0)),!h||h===l)return l;l=h}},w=[],R=[];for(const o of s){if(o.revert){const l=u(o,R);if(l){if(e.has(l.hash)){R.push(o);continue}const a=x(l);if(a===void 0){w.push(`Revert chain at ${o.hash} exceeded depth limit (${d}) — skipping cancellation`),R.push(o);continue}if(e.has(a.hash)){R.push(o);continue}a.cancelled=!a.cancelled,a.cancelledBy=a.cancelled?o.hash:void 0,o.cancelled=!0,o.cancelledBy=l.hash}}R.push(o)}const v=n.filter(o=>!o.cancelled&&!o.revert&&!o.subject?.startsWith("Merge ")),_=v.filter(o=>!o.parsed.type);if(v.length>0&&_.length/v.length>.5){const o=t??"<from>..HEAD";w.push(`${_.length}/${v.length} commits in ${o} have no conventional-commits prefix. Consider enabling commit-message linting.`)}return{commits:n,warnings:w}},Ae=async({fs:r,logger:e,options:t,workspaceRoot:n})=>{const s=n??process.cwd(),i=await Z({cwd:s,skipRegistryLookup:!0}),{printConfigIfRequested:c}=await import("./print-config.js");if(c(t,i,e))return;const u=ee();let d=t.from;if(!d){const f=i.config.baseBranch??"main",g=await u.run("git",["merge-base",`origin/${f}`,"HEAD"],{cwd:s,silent:!0});if(g.exitCode===0&&g.stdout.trim())d=g.stdout.trim();else{const p=await u.run("git",["merge-base",f,"HEAD"],{cwd:s,silent:!0});d=p.exitCode===0?p.stdout.trim():"HEAD~10"}}const x=new Map;for(const f of i.packages){const p=(f.dir.startsWith(s)?f.dir.slice(s.length):f.dir).replaceAll("\\","/").replace(/^\/+/,"");x.set(p,f.name)}const w=f=>{for(const[g,p]of x)if(f.startsWith(`${g}/`)||f===`${g}/package.json`)return p},R=Math.random().toString(16).slice(2,10),v=`@@VIS_RELEASE_COMMIT_${R}@@`,_=`@@VIS_RELEASE_FILES_${R}@@`,o=await u.run("git",["log",`${d}..HEAD`,`--pretty=format:${v}%n%H%n%s%n%b%n${_}`,"--name-only"],{cwd:s,silent:!0});if(o.exitCode!==0){e.error(`git log failed: ${o.stderr}`),process.exitCode=1;return}const l=new Map,a=[],m=[],h=o.stdout.split(v).map(f=>f.trim()).filter(Boolean);for(const f of h){const[g,p=""]=f.split(_).toReversed(),A=p.split(`
6
+ `),E=A[0]?.trim()??"",L=A[1]?.trim()??"",b=A.slice(2).join(`
7
+ `).trim(),y=(g??"").split(`
8
+ `).map(q=>q.trim()).filter(Boolean);E&&m.push({body:b,files:y,hash:E,subject:L})}const{commits:P,warnings:T}=Re(m,void 0,`${d}..HEAD`);for(const f of T)e.warn(f);for(const{cancelled:f,files:g,parsed:p,subject:A}of P){if(f)continue;let E="patch";p.breaking?E="major":p.type&&D[p.type]&&(E=D[p.type]??"patch");const L=new Set;if(p.scope)for(const b of i.packages)(b.name===p.scope||b.name.endsWith(`/${p.scope}`))&&L.add(b.name);if(L.size===0)for(const b of g){const y=w(b);y&&L.add(y)}for(const b of L){const y=l.get(b);l.set(b,y?ne(y,E):E)}L.size>0&&a.push(`- ${A}`)}if(l.size===0){e.info("No commits affected workspace packages — nothing to generate.");return}const O={bumps:Object.fromEntries(l)},K=a.length>0?a.join(`
9
+ `):"Auto-generated change file.",j=Q(O,K);if(t.dryRun){e.info("[dry-run] would write:"),e.info(j);return}const M=i.config.changesDir??Y,W=(t.name??te()).replaceAll(/[^a-z0-9-]/gi,"-"),H=N(s,M,`${W}.md`);await r.mkdir(N(s,M),{recursive:!0}),await r.writeFile(H,j),e.info(`Created ${J(s,H)}`);for(const[f,g]of l)e.info(` ${f}: ${g}`)};export{Ae as default};
@@ -1,2 +1,2 @@
1
- import{createRequire as H}from"node:module";import{I as W}from"../packem_shared/index-BWl4DbMp.js";import{p as F}from"../packem_shared/prompt-BSAy8SMH.js";import{l as X,w as J,d as U,j as Q}from"../packem_shared/index-uBVnF4ji.js";import{f as D,A as Z,C as ee,r as te,z as se,i as A}from"../packem_shared/en-D3CfXlO7.js";import{a as re}from"../packem_shared/readJsonSync-DweZd5ZA-0eZh9sGm.js";import{g as oe,r as ne}from"../packem_shared/packument-HBVbyf7x.js";import{q as ie,j as ae,E as $,s as k,V as C,I as _}from"../packem_shared/index.server-CusjRLCh.js";import{h as ce,W as le}from"../packem_shared/pm-runner-C6eTANt1.js";import{r as fe,a as pe}from"../packem_shared/command-runtime-BLFPUYAT.js";let L;const q=e=>(L??=H(import.meta.url))(e),v=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,G=e=>{if(typeof v<"u"&&v.versions&&v.versions.node){const[t,s]=v.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return v.getBuiltinModule(e)}return q(e)},{renameSync:Y}=G("node:fs"),{stripVTControlCharacters:z}=G("node:util"),ue=(e={})=>{const t=e.isCi??W;return(e.isTty??!!(process.stdin.isTTY&&process.stdout.isTTY))&&!t},w=J(D(),"dlx-seen.json"),P=(e,t)=>`${e}@${t}`,ge=e=>{if(typeof e!="object"||e===null)return!1;const t=e;return Array.isArray(t.alertKeys)&&t.alertKeys.every(s=>typeof s=="string")&&typeof t.seenAt=="number"},V=()=>{try{if(X(w)){const e=re(w);if(e&&typeof e=="object"&&e.packages&&typeof e.packages=="object"&&e.version===1){const t={};for(const[s,r]of Object.entries(e.packages))ge(r)&&(t[s]=r);return{packages:t,version:1}}}}catch{}return{packages:{},version:1}},me=e=>{try{U(D());const t=`${w}.${String(process.pid)}.tmp`;Q(t,JSON.stringify(e)),Y(t,w)}catch{}},de=(e,t,s)=>e.packages[P(t,s)],he=(e,t)=>{if(!e)return!0;const s=new Set(Array.isArray(e.alertKeys)?e.alertKeys:[]);return t.some(r=>!s.has(r))},x=(e,t,s,r)=>{const o=V();o.packages[P(e,t)]={alertKeys:[...s].sort(),seenAt:r},me(o)},ye=/[\u0000-\u0008\u000B-\u001F\u007F]/g,B=e=>z(e).replaceAll(" "," ").replaceAll(ye,""),E=["CHANGELOG.md","CHANGELOG","changelog.md","CHANGES.md","HISTORY.md"],$e=4e3,j=async(e,t,s)=>{if(t?.aborted)return;const r=new AbortController,o=setTimeout(()=>{r.abort()},$e),a=()=>{r.abort()};t?.addEventListener("abort",a,{once:!0});try{const i=await fetch(e,{headers:s,signal:r.signal});return i.ok?await i.text():void 0}catch{return}finally{clearTimeout(o),t?.removeEventListener("abort",a)}},ve=e=>{const t=typeof e=="string"?e:e?.url;if(!t)return;const s=/github\.com[/:]([^/]+)\/([^/#]+?)(?:\.git)?(?:[/#]|$)/i.exec(t)??/^github:([^/]+)\/([^/#]+)/i.exec(t);return s?{directory:typeof e=="object"?e?.directory:void 0,owner:s[1],repo:s[2].replace(/\.git$/,"")}:void 0},R=(e,t)=>{const s=e.split(/\r?\n/),r=/^(#{1,4})\s+(.*)$/,o=t.replaceAll(/[$()*+.?[\\\]^{|}]/g,String.raw`\$&`),a=new RegExp(String.raw`(?<![\w.])${o}(?![\w.])`);let i=-1,u=0;for(const[c,l]of s.entries()){const f=r.exec(l);if(f&&a.test(f[2])){i=c,u=f[1].length;break}}if(i===-1)return;const n=[];for(let c=i+1;c<s.length;c+=1){const l=r.exec(s[c]);if(l&&l[1].length<=u)break;n.push(s[c])}return n},I=(e,t=4)=>e.map(s=>s.trim()).filter(s=>s.length>0).map(s=>B(s.replace(/^#{1,6}\s+/,"").replace(/^[*-]\s+/,"- ")).trim()).filter(s=>s.length>0&&!/^\[.*\]:/.test(s)).slice(0,t),O=(e,t)=>{if(!e)return"";const s=Date.parse(e);if(Number.isNaN(s))return"";const r=Math.floor((t-s)/(1440*60*1e3));if(r<=0)return"today";if(r===1)return"1d ago";if(r<30)return`${String(r)}d ago`;const o=Math.floor(r/30);return o<12?`${String(o)}mo ago`:`${String(Math.floor(o/12))}y ago`},N=(e,t,s)=>{const r=e.time??{},o=O(r[t],s),a=[o?`${e.name}@${t} — published ${o}`:`${e.name}@${t}`],i=Date.parse(r[t]??""),u=Object.entries(r).filter(([n])=>n!=="created"&&n!=="modified"&&n!==t).sort((n,c)=>Date.parse(c[1])-Date.parse(n[1])).filter(([,n])=>Date.parse(n)<i).slice(0,3);for(const[n,c]of u)a.push(`- ${n} (${O(c,s)})`);return{lines:a,source:"npm-diff",version:t}},ke=async e=>{const{name:t,now:s,offline:r,packument:o,signal:a,version:i}=e;if(r)return o?N(o,i,s):void 0;for(const c of E){const l=`https://cdn.jsdelivr.net/npm/${t}@${i}/${c}`,f=await j(l,a);if(f){const d=R(f,i),p=I(d??f.split(/\r?\n/));if(p.length>0)return{lines:p,source:"package-file",url:l,version:i}}}const u=o?.versions[i],n=ve(u?.repository);if(n){const c=n.directory?`${n.directory.replaceAll(/^\/+|\/+$/g,"")}/`:"";for(const l of["HEAD","main","master"])for(const f of E){const d=`https://raw.githubusercontent.com/${n.owner}/${n.repo}/${l}/${c}${f}`,p=await j(d,a);if(p){const h=R(p,i),m=I(h??p.split(/\r?\n/));if(m.length>0){const g=`https://github.com/${n.owner}/${n.repo}/blob/${l}/${c}${f}`;return{lines:m,source:"repo-file",url:g,version:i}}}}}if(o)return N(o,i,s)},be={dynamicRequire:"dynamic require",envVars:"env access",filesystemAccess:"filesystem",networkAccess:"network",shellAccess:"shell",telemetry:"telemetry",unsafe:"eval/unsafe",usesEval:"eval/unsafe"},we=["preinstall","install","postinstall"],Se=(e,t)=>({fileCount:e?.dist?.fileCount,tarballBytes:t?.size,unpackedBytes:e?.dist?.unpackedSize}),Te=(e,t)=>{const s=we.filter(i=>!!e?.scripts?.[i]),r=e?.bin,o=typeof r=="string"?["(default)"]:Object.keys(r??{}).map(i=>B(i)),a=[...new Set(t.map(i=>be[i.type]).filter(i=>i!==void 0))];return{bins:o,capabilities:a,lifecycleScripts:s}},Ce=(e,t,s)=>{const r=e.get(`${t}@${s}`);if(r)return r;for(const o of e.values())if(o.name===t&&o.version===s)return o},Ae=async e=>{const{name:t,now:s,offline:r,signal:o,socketToken:a,spec:i,workspaceRoot:u}=e;let n;try{n=await oe(t,{offline:r,signal:o,workspaceRoot:u})}catch{n=void 0}const c=n?ne(n,i):void 0;if(!c)return;const l=n?.versions[c],f=async()=>{if(!(r||!a))try{const y=await ee([{name:t,version:c}],{apiToken:a});return Ce(y,t,c)}catch{return}},d=ke({name:t,now:s,offline:r,packument:n,signal:o,version:c}).catch(()=>{}),[p,h]=await Promise.all([f(),d]),m=p?.alerts??[],g=[...new Set(m.filter(y=>y.severity==="critical"||y.severity==="high").map(y=>y.key))].sort(),S=p?Math.round((p.score.overall??Z(p.score))*100):void 0;return{changelog:h,name:t,permissions:Te(l,m),security:{alerts:m,available:!!p,highSeverityKeys:g,score:S},size:Se(l,p),version:c}},b=e=>te(z(e)),_e={critical:C,high:C,low:$,medium:k},K=e=>{if(!(e===void 0||e<0))return se(e,{decimals:1,space:!0})},xe=e=>{const{fileCount:t,tarballBytes:s,unpackedBytes:r}=e.size,o=K(r),a=K(s);if(o&&a){const i=t===void 0?"":`, ${String(t)} files`;return`${o} unpacked (${a} tarball${i})`}if(o)return`${o} unpacked`;if(a)return`${a} tarball`},Ee=e=>{const{alerts:t,available:s,score:r}=e.security;if(!s)return $("unavailable — set VIS_SOCKET_TOKEN for a Socket.dev score");const o=r===void 0?$:r>=70?_:r>=40?k:C,a=r===void 0?"n/a":`${String(r)}/100`,i=new Map;for(const l of t)i.set(l.severity,(i.get(l.severity)??0)+1);const u=[],n=["critical","high","medium","low"];for(const l of n){const f=i.get(l);f&&u.push(_e[l](`${String(f)} ${l}`))}const c=u.length>0?` ${k("!")} ${u.join(", ")}`:` ${_("no alerts")}`;return`${o(a)} ${$("(Socket.dev)")}${c}`},je=e=>{const{bins:t,capabilities:s,lifecycleScripts:r}=e.permissions,o=[];for(const a of r)o.push(k(`${a} script`));for(const a of s)o.push(k(a));return t.length>0&&o.push($(`bins: ${t.join(", ")}`)),o.length>0?o.join($(" · ")):void 0},Re=e=>{const t=[],s=xe(e);s&&t.push({label:"size",values:[s]}),t.push({label:"score",values:[Ee(e)]});const r=je(e);if(r&&t.push({label:"perms",values:[r]}),e.changelog){const o=e.changelog.source==="npm-diff"?"registry":e.changelog.source==="repo-file"?"repo CHANGELOG":"CHANGELOG";t.push({label:"latest",values:[...e.changelog.lines,$(`source: ${o}`)]})}return t},M=6,Ie=e=>{const t=Re(e),s=` first run: ${e.name}@${e.version} `,r=[];for(const n of t)n.values.forEach((c,l)=>{const f=l===0?ie(n.label.padEnd(M)):" ".repeat(M);r.push(`${f} ${c}`)});const o=Math.max(b(s),...r.map(n=>b(n))),a=n=>`${n}${" ".repeat(Math.max(0,o-b(n)))}`,i=`┌─${ae(s)}${"─".repeat(Math.max(0,o-b(s)))}─┐`,u=`└─${"─".repeat(o)}─┘`;return[i,...r.map(n=>`│ ${a(n)} │`),u]},Oe=e=>{if(e.startsWith("@")){const s=e.indexOf("@",1);return s===-1?{name:e}:{name:e.slice(0,s),spec:e.slice(s+1)}}const t=e.indexOf("@");return t<=0?{name:e}:{name:e.slice(0,t),spec:e.slice(t+1)}},Ne=e=>e===""||e.startsWith(".")||e.startsWith("/")||e.startsWith("~")?!1:!(e.startsWith("@")?e.slice(1):e).includes(":"),Ke=6e3,Me=e=>{process.stdout.write(e)},Ge=async e=>{const{forceInfo:t=!1,noInfo:s=!1,offline:r=!1,pkg:o,socketToken:a,workspaceRoot:i,yes:u=!1}=e;if(s||!Ne(o))return{proceed:!0};const n=e.now??Date.now(),c=u||!ue({isCi:e.isCi,isTty:e.isTty}),l=e.output??Me;if(c&&!t)return{proceed:!0};const{name:f,spec:d}=Oe(o),p=new AbortController;let h;const m=new Promise(T=>{h=setTimeout(()=>{p.abort(),T(void 0)},Ke)}),g=await Promise.race([Ae({name:f,now:n,offline:r,signal:p.signal,socketToken:a,spec:d,workspaceRoot:i}).catch(()=>{}),m]);if(h&&clearTimeout(h),!g)return{proceed:!0};const S=de(V(),g.name,g.version);if(!t&&!he(S,g.security.highSeverityKeys))return{proceed:!0};for(const T of Ie(g))l(`${T}
2
- `);if(c)return x(g.name,g.version,g.security.highSeverityKeys,n),{proceed:!0};const y=await F("? Ok to proceed? (y/N) ",e.readline);return y&&x(g.name,g.version,g.security.highSeverityKeys,n),{proceed:y}},Ye=async({argument:e,logger:t,options:s,visConfig:r,workspaceRoot:o})=>{const a=e;if(!a||a.length===0)throw new Error("No package specified. Usage: vis dlx <package[@version]> [args...]");const[i,...u]=a,n=o??process.cwd(),c=s.package?Array.isArray(s.package)?s.package:[s.package]:[],l=s.shellMode?c:[i,...c];for(const h of l){const m=s.info||!1,g=m?!1:s.noInfo||A(process.env.VIS_DLX_NO_INFO);if(!(await Ge({forceInfo:m,noInfo:g,offline:s.offline||!1,pkg:h,socketToken:r?.security?.socket?.apiToken??process.env.VIS_SOCKET_TOKEN,workspaceRoot:n,yes:s.yes||A(process.env.VIS_DLX_YES)})).proceed){t.info("Aborted."),process.exitCode=1;return}}const f=fe({logger:t,options:s,visConfig:r},n),d=ce(n,{backend:pe(f),configBackend:r?.install?.backend,configCorepack:r?.install?.corepack}),p=le(d,{additionalPackages:c,args:u,package:i,shellMode:s.shellMode||!1,silent:s.silent||!1},n,t,{offline:s.offline||!1});p!==0&&(process.exitCode=p)};export{Ye as default};
1
+ import{createRequire as F}from"node:module";import{i as W}from"../packem_shared/index-BjdW45xX.js";import{p as Y}from"../packem_shared/prompt-DMzaQEVa.js";import{e as U}from"../packem_shared/index-DHD8wb6Z.js";import{l as B,m as X,n as J,D as Q,o as Z,$ as ee,k as _}from"../packem_shared/formatBytes-BHAzNIrn-DFIppnY0.js";import{y as te}from"../packem_shared/isAccessibleSync-DYKTrrvc-CSnBISfV.js";import{p as se}from"../packem_shared/readJsonSync-CbryXYxN-B2aSeDpC.js";import{h as re,U as oe}from"../packem_shared/writeFileSync-DJoHk3Ks-CgQ-VNNT.js";import{g as ne,r as ce}from"../packem_shared/packument-C55kVxcQ.js";import{D as ie,q as ae,F as v,r as b,X as E,J as A}from"../packem_shared/index.server-CwSgbeN7.js";import{a as le,o as fe}from"../packem_shared/pm-runner-de-jCq8q.js";import{r as ue,a as pe}from"../packem_shared/command-runtime-CiLVo4ED.js";let V;const z=e=>(V??=F(import.meta.url))(e),$=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,M=e=>{if(typeof $<"u"&&$.versions&&$.versions.node){const[t,s]=$.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return $.getBuiltinModule(e)}return z(e)},{renameSync:q}=M("node:fs"),{stripVTControlCharacters:G}=M("node:util"),de=(e={})=>{const t=e.isCi??W;return(e.isTty??!!(process.stdin.isTTY&&process.stdout.isTTY))&&!t},k=U(B(),"dlx-seen.json"),H=(e,t)=>`${e}@${t}`,me=e=>{if(typeof e!="object"||e===null)return!1;const t=e;return Array.isArray(t.alertKeys)&&t.alertKeys.every(s=>typeof s=="string")&&typeof t.seenAt=="number"},P=()=>{try{if(te(k)){const e=se(k);if(e&&typeof e=="object"&&e.packages&&typeof e.packages=="object"&&e.version===1){const t={};for(const[s,r]of Object.entries(e.packages))me(r)&&(t[s]=r);return{packages:t,version:1}}}}catch{}return{packages:{},version:1}},he=e=>{try{re(B());const t=`${k}.${String(process.pid)}.tmp`;oe(t,JSON.stringify(e)),q(t,k)}catch{}},ge=(e,t,s)=>e.packages[H(t,s)],ye=(e,t)=>{if(!e)return!0;const s=new Set(Array.isArray(e.alertKeys)?e.alertKeys:[]);return t.some(r=>!s.has(r))},R=(e,t,s,r)=>{const o=P();o.packages[H(e,t)]={alertKeys:[...s].sort(),seenAt:r},he(o)},ve=/[\u0000-\u0008\u000B-\u001F\u007F]/g,K=e=>G(e).replaceAll(" "," ").replaceAll(ve,""),x=["CHANGELOG.md","CHANGELOG","changelog.md","CHANGES.md","HISTORY.md"],$e=4e3,C=async(e,t,s)=>{if(t?.aborted)return;const r=new AbortController,o=setTimeout(()=>{r.abort()},$e),a=()=>{r.abort()};t?.addEventListener("abort",a,{once:!0});try{const n=await fetch(e,{headers:s,signal:r.signal});return n.ok?await n.text():void 0}catch{return}finally{clearTimeout(o),t?.removeEventListener("abort",a)}},be=e=>{const t=typeof e=="string"?e:e?.url;if(!t)return;const s=/github\.com[/:]([^/]+)\/([^/#]+?)(?:\.git)?(?:[/#]|$)/i.exec(t)??/^github:([^/]+)\/([^/#]+)/i.exec(t);return s?{directory:typeof e=="object"?e?.directory:void 0,owner:s[1],repo:s[2].replace(/\.git$/,"")}:void 0},O=(e,t)=>{const s=e.split(/\r?\n/),r=/^(#{1,4})\s+(.*)$/,o=t.replaceAll(/[$()*+.?[\\\]^{|}]/g,String.raw`\$&`),a=new RegExp(String.raw`(?<![\w.])${o}(?![\w.])`);let n=-1,p=0;for(const[i,l]of s.entries()){const f=r.exec(l);if(f&&a.test(f[2])){n=i,p=f[1].length;break}}if(n===-1)return;const c=[];for(let i=n+1;i<s.length;i+=1){const l=r.exec(s[i]);if(l&&l[1].length<=p)break;c.push(s[i])}return c},I=(e,t=4)=>e.map(r=>r.trim()).filter(r=>r.length>0).map(r=>K(r.replace(/^#{1,6}\s+/,"").replace(/^[*-]\s+/,"- ")).trim()).filter(r=>r.length>0&&!/^\[.*\]:/.test(r)).slice(0,t),L=(e,t)=>{if(!e)return"";const s=Date.parse(e);if(Number.isNaN(s))return"";const r=Math.floor((t-s)/(1440*60*1e3));if(r<=0)return"today";if(r===1)return"1d ago";if(r<30)return`${String(r)}d ago`;const o=Math.floor(r/30);return o<12?`${String(o)}mo ago`:`${String(Math.floor(o/12))}y ago`},N=(e,t,s)=>{const r=e.time??{},o=L(r[t],s),a=[o?`${e.name}@${t} — published ${o}`:`${e.name}@${t}`],n=Date.parse(r[t]??""),c=Object.entries(r).filter(([i])=>i!=="created"&&i!=="modified"&&i!==t).sort((i,l)=>Date.parse(l[1])-Date.parse(i[1])).filter(([,i])=>Date.parse(i)<n).slice(0,3);for(const[i,l]of c)a.push(`- ${i} (${L(l,s)})`);return{lines:a,source:"npm-diff",version:t}},Se=async e=>{const{name:t,now:s,offline:r,packument:o,signal:a,version:n}=e;if(r)return o?N(o,n,s):void 0;for(const i of x){const l=`https://cdn.jsdelivr.net/npm/${t}@${n}/${i}`,f=await C(l,a);if(f){const h=O(f,n),u=I(h??f.split(/\r?\n/));if(u.length>0)return{lines:u,source:"package-file",url:l,version:n}}}const p=o?.versions[n],c=be(p?.repository);if(c){const i=c.directory?`${c.directory.replaceAll(/^\/+|\/+$/g,"")}/`:"";for(const l of["HEAD","main","master"])for(const f of x){const h=`https://raw.githubusercontent.com/${c.owner}/${c.repo}/${l}/${i}${f}`,u=await C(h,a);if(u){const g=O(u,n),m=I(g??u.split(/\r?\n/));if(m.length>0){const d=`https://github.com/${c.owner}/${c.repo}/blob/${l}/${i}${f}`;return{lines:m,source:"repo-file",url:d,version:n}}}}}if(o)return N(o,n,s)},we={dynamicRequire:"dynamic require",envVars:"env access",filesystemAccess:"filesystem",networkAccess:"network",shellAccess:"shell",telemetry:"telemetry",unsafe:"eval/unsafe",usesEval:"eval/unsafe"},ke=["preinstall","install","postinstall"],Te=(e,t)=>({fileCount:e?.dist?.fileCount,tarballBytes:t?.size,unpackedBytes:e?.dist?.unpackedSize}),Ee=(e,t)=>{const s=ke.filter(n=>!!e?.scripts?.[n]),r=e?.bin,o=typeof r=="string"?["(default)"]:Object.keys(r??{}).map(n=>K(n)),a=[...new Set(t.map(n=>we[n.type]).filter(n=>n!==void 0))];return{bins:o,capabilities:a,lifecycleScripts:s}},_e=(e,t,s)=>{const r=e.get(`${t}@${s}`);if(r)return r;for(const o of e.values())if(o.name===t&&o.version===s)return o},Ae=async e=>{const{name:t,now:s,offline:r,signal:o,socketToken:a,spec:n,workspaceRoot:p}=e;let c;try{c=await ne(t,{offline:r,signal:o,workspaceRoot:p})}catch{c=void 0}const i=c?ce(c,n):void 0;if(!i)return;const l=c?.versions[i],f=async()=>{if(!(r||!a))try{const y=await J([{name:t,version:i}],{apiToken:a,minimumScore:Q});return _e(y,t,i)}catch{return}},h=Se({name:t,now:s,offline:r,packument:c,signal:o,version:i}).catch(()=>{}),[u,g]=await Promise.all([f(),h]),m=u?.alerts??[],d=[...new Set(m.filter(y=>y.severity==="critical"||y.severity==="high").map(y=>y.key))].sort(),S=u?Math.round((u.score.overall??X(u.score))*100):void 0;return{changelog:g,name:t,permissions:Ee(l,m),security:{alerts:m,available:!!u,highSeverityKeys:d,score:S},size:Te(l,u),version:i}},w=e=>Z(G(e)),Re={critical:E,high:E,low:v,medium:b},D=e=>{if(!(e===void 0||e<0))return ee(e,{decimals:1,space:!0})},xe=e=>{const{fileCount:t,tarballBytes:s,unpackedBytes:r}=e.size,o=D(r),a=D(s);if(o&&a){const n=t===void 0?"":`, ${String(t)} files`;return`${o} unpacked (${a} tarball${n})`}if(o)return`${o} unpacked`;if(a)return`${a} tarball`},Ce=e=>{const{alerts:t,available:s,score:r}=e.security;if(!s)return v("unavailable — set VIS_SOCKET_TOKEN for a Socket.dev score");const o=r===void 0?v:r>=70?A:r>=40?b:E,a=r===void 0?"n/a":`${String(r)}/100`,n=new Map;for(const l of t)n.set(l.severity,(n.get(l.severity)??0)+1);const p=[],c=["critical","high","medium","low"];for(const l of c){const f=n.get(l);f&&p.push(Re[l](`${String(f)} ${l}`))}const i=p.length>0?` ${b("!")} ${p.join(", ")}`:` ${A("no alerts")}`;return`${o(a)} ${v("(Socket.dev)")}${i}`},Oe=e=>{const{bins:t,capabilities:s,lifecycleScripts:r}=e.permissions,o=[];for(const a of r)o.push(b(`${a} script`));for(const a of s)o.push(b(a));return t.length>0&&o.push(v(`bins: ${t.join(", ")}`)),o.length>0?o.join(v(" · ")):void 0},Ie=e=>{const t=[],s=xe(e);s&&t.push({label:"size",values:[s]}),t.push({label:"score",values:[Ce(e)]});const r=Oe(e);if(r&&t.push({label:"perms",values:[r]}),e.changelog){const o=e.changelog.source==="npm-diff"?"registry":e.changelog.source==="repo-file"?"repo CHANGELOG":"CHANGELOG";t.push({label:"latest",values:[...e.changelog.lines,v(`source: ${o}`)]})}return t},j=6,Le=e=>{const t=Ie(e),s=` first run: ${e.name}@${e.version} `,r=[];for(const c of t)c.values.forEach((i,l)=>{const f=l===0?ie(c.label.padEnd(j)):" ".repeat(j);r.push(`${f} ${i}`)});const o=Math.max(w(s),...r.map(c=>w(c))),a=c=>`${c}${" ".repeat(Math.max(0,o-w(c)))}`,n=`┌─${ae(s)}${"─".repeat(Math.max(0,o-w(s)))}─┐`,p=`└─${"─".repeat(o)}─┘`;return[n,...r.map(c=>`│ ${a(c)} │`),p]},Ne=e=>{if(e.startsWith("@")){const s=e.indexOf("@",1);return s===-1?{name:e}:{name:e.slice(0,s),spec:e.slice(s+1)}}const t=e.indexOf("@");return t<=0?{name:e}:{name:e.slice(0,t),spec:e.slice(t+1)}},De=e=>e===""||e.startsWith(".")||e.startsWith("/")||e.startsWith("~")?!1:!(e.startsWith("@")?e.slice(1):e).includes(":"),je=6e3,Me=e=>{process.stdout.write(e)},Be=async e=>{const{forceInfo:t=!1,noInfo:s=!1,offline:r=!1,pkg:o,socketToken:a,workspaceRoot:n,yes:p=!1}=e;if(s||!De(o))return{proceed:!0};const c=e.now??Date.now(),i=p||!de({isCi:e.isCi,isTty:e.isTty}),l=e.output??Me;if(i&&!t)return{proceed:!0};const{name:f,spec:h}=Ne(o),u=new AbortController;let g;const m=new Promise(T=>{g=setTimeout(()=>{u.abort(),T(void 0)},je)}),d=await Promise.race([Ae({name:f,now:c,offline:r,signal:u.signal,socketToken:a,spec:h,workspaceRoot:n}).catch(()=>{}),m]);if(g&&clearTimeout(g),!d)return{proceed:!0};const S=ge(P(),d.name,d.version);if(!t&&!ye(S,d.security.highSeverityKeys))return{proceed:!0};for(const T of Le(d))l(`${T}
2
+ `);if(i)return R(d.name,d.version,d.security.highSeverityKeys,c),{proceed:!0};const y=await Y("? Ok to proceed? (y/N) ",e.readline);return y&&R(d.name,d.version,d.security.highSeverityKeys,c),{proceed:y}},Je=async({argument:e,logger:t,options:s,visConfig:r,workspaceRoot:o})=>{const a=e;if(!a||a.length===0)throw new Error("No package specified. Usage: vis dlx <package[@version]> [args...]");const[n,...p]=a,c=o??process.cwd(),i=s.package?Array.isArray(s.package)?s.package:[s.package]:[],l=s.shellMode?i:[n,...i];for(const g of l){const m=s.info||!1,d=m?!1:s.noInfo||_(process.env.VIS_DLX_NO_INFO);if(!(await Be({forceInfo:m,noInfo:d,offline:s.offline||!1,pkg:g,socketToken:r?.security?.socket?.apiToken??process.env.VIS_SOCKET_TOKEN,workspaceRoot:c,yes:s.yes||_(process.env.VIS_DLX_YES)})).proceed){t.info("Aborted."),process.exitCode=1;return}}const f=ue({logger:t,options:s,visConfig:r},c),h=le(c,{backend:pe(f),configBackend:r?.install?.backend,configCorepack:r?.install?.corepack}),u=fe(h,{additionalPackages:i,args:p,package:n,shellMode:s.shellMode||!1,silent:s.silent||!1},c,t,{offline:s.offline||!1});u!==0&&(process.exitCode=u)};export{Je as default};