binary-collections 2.0.10 → 2.0.12

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 (290) hide show
  1. package/.opencode/package.json +5 -0
  2. package/.puppeterrc.cjs +25 -0
  3. package/binaries/binary-executor.cjs +138 -3
  4. package/binaries/clean-nodemodule.cjs +138 -3
  5. package/binaries/clean-nodemodules.cjs +138 -3
  6. package/binaries/dev.cjs +138 -3
  7. package/binaries/empty.cjs +138 -3
  8. package/binaries/git-reduce-size.cjs +138 -3
  9. package/binaries/javakill.cjs +138 -3
  10. package/binaries/kill-night-crows.bat +7 -0
  11. package/binaries/kill-night-crows.ps1 +172 -0
  12. package/binaries/kill-process.cjs +138 -3
  13. package/binaries/nodekill.cjs +138 -3
  14. package/binaries/prod.cjs +138 -3
  15. package/binaries/py +111 -0
  16. package/binaries/py.cjs +178 -0
  17. package/binaries/py.cmd +49 -0
  18. package/binaries/rmfind.cjs +138 -3
  19. package/binaries/rmx +15 -1
  20. package/binaries/rmx.cjs +138 -3
  21. package/binaries/rmx.cmd +12 -0
  22. package/binaries/submodule-token.cjs +138 -3
  23. package/binaries/test-cjs +18 -0
  24. package/binaries/test-cjs.cjs +178 -0
  25. package/binaries/test-cjs.cmd +26 -0
  26. package/binaries/test-esm +16 -0
  27. package/binaries/test-esm.cjs +178 -0
  28. package/binaries/test-esm.cmd +23 -0
  29. package/binaries/yarn-clean +32 -0
  30. package/binaries/yarn-clean.cjs +178 -0
  31. package/binaries/yarn-clean.cmd +30 -0
  32. package/binaries/yarn-clean.py +166 -0
  33. package/binaries/yc +110 -0
  34. package/binaries/yc.cjs +178 -0
  35. package/lib/binary-collections/config.cjs +126 -0
  36. package/lib/binary-collections/config.mjs +7 -0
  37. package/lib/binary-collections/executeScript.cjs +19 -0
  38. package/lib/binary-collections/executeScript.d.cts +12 -0
  39. package/lib/binary-collections/executeScript.mjs +6 -0
  40. package/lib/binary-collections/findScript.cjs +284 -0
  41. package/lib/binary-collections/findScript.d.cts +12 -0
  42. package/lib/binary-collections/findScript.mjs +7 -0
  43. package/lib/binary-collections/listScript.cjs +266 -0
  44. package/lib/binary-collections/listScript.d.cts +19 -0
  45. package/lib/binary-collections/listScript.mjs +7 -0
  46. package/lib/binary-collections.cjs +342 -194
  47. package/lib/binary-collections.mjs +22 -268
  48. package/lib/changelog.cjs +61 -13
  49. package/lib/changelog.mjs +1 -1
  50. package/lib/{chunk-E6FDDAOO.mjs → chunk-2LSRSEXF.mjs} +2 -2
  51. package/lib/chunk-34IQDTLZ.mjs +27 -0
  52. package/lib/chunk-3HFFECCI.mjs +27 -0
  53. package/lib/{chunk-V3N3JEUF.mjs → chunk-5RTXZVCW.mjs} +60 -13
  54. package/lib/chunk-66KDU4TX.mjs +268 -0
  55. package/lib/chunk-6PU7BAHB.mjs +61 -0
  56. package/lib/{chunk-6HHJRKFB.mjs → chunk-BZWVHODJ.mjs} +4 -1
  57. package/lib/chunk-C6D2TTYU.mjs +32 -0
  58. package/lib/chunk-FB2WKVJD.mjs +158 -0
  59. package/lib/{chunk-66PAU5PS.mjs → chunk-G5UUEWUO.mjs} +9 -5
  60. package/lib/{chunk-HO6GHCOB.mjs → chunk-GAGABICI.mjs} +198 -63
  61. package/lib/chunk-H44UWUFY.mjs +105 -0
  62. package/lib/chunk-NCZPTKDV.mjs +79 -0
  63. package/lib/chunk-NGFK3EYW.mjs +28 -0
  64. package/lib/chunk-NVEG3LEZ.mjs +143 -0
  65. package/lib/chunk-OGXVGBRI.mjs +29 -0
  66. package/lib/chunk-OXV52GD5.mjs +62 -0
  67. package/lib/{chunk-PDSXF5HY.mjs → chunk-PDN26I7O.mjs} +1 -0
  68. package/lib/chunk-PXBMHE7O.mjs +35 -0
  69. package/lib/chunk-R5FJOR63.mjs +47 -0
  70. package/lib/chunk-SPTECFE5.mjs +180 -0
  71. package/lib/chunk-UXCFNAR6.mjs +55 -0
  72. package/lib/chunk-V2IBPCEV.mjs +39 -0
  73. package/lib/chunk-XPJGCDOD.mjs +14 -0
  74. package/lib/{chunk-AI4CVPJ7.mjs → chunk-ZDMWBSYF.mjs} +4 -4
  75. package/lib/chunk-ZOWVMII3.mjs +228 -0
  76. package/lib/clean-github-actions-caches-cli.cjs +465 -0
  77. package/lib/clean-github-actions-caches-cli.d.cts +1 -0
  78. package/lib/clean-github-actions-caches-cli.mjs +56 -0
  79. package/lib/clean-github-actions-caches.cjs +152 -160
  80. package/lib/clean-github-actions-caches.d.cts +15 -1
  81. package/lib/clean-github-actions-caches.mjs +4 -130
  82. package/lib/cross-env/command.cjs +63 -0
  83. package/lib/cross-env/command.d.ts +8 -0
  84. package/lib/cross-env/command.js +45 -0
  85. package/lib/cross-env/command.mjs +9 -0
  86. package/lib/cross-env/index.cjs +178 -0
  87. package/lib/cross-env/index.d.ts +8 -0
  88. package/lib/cross-env/index.js +102 -0
  89. package/lib/cross-env/index.mjs +101 -0
  90. package/lib/cross-env/variable.cjs +60 -0
  91. package/lib/cross-env/variable.d.ts +7 -0
  92. package/lib/cross-env/variable.js +59 -0
  93. package/lib/cross-env/variable.mjs +9 -0
  94. package/lib/del-gradle.cjs +61 -13
  95. package/lib/del-gradle.js +9 -8
  96. package/lib/del-gradle.mjs +1 -1
  97. package/lib/del-node-modules.cjs +143 -148
  98. package/lib/del-node-modules.js +210 -14
  99. package/lib/del-node-modules.mjs +148 -17
  100. package/lib/del-ps.cjs +61 -13
  101. package/lib/del-ps.js +9 -8
  102. package/lib/del-ps.mjs +1 -1
  103. package/lib/del-yarn-caches.cjs +61 -13
  104. package/lib/del-yarn-caches.js +2 -2
  105. package/lib/del-yarn-caches.mjs +1 -1
  106. package/lib/file/copy-cli.cjs +92 -0
  107. package/lib/file/copy-cli.d.mts +1 -0
  108. package/lib/file/copy-cli.mjs +55 -0
  109. package/lib/file/copy.cjs +56 -0
  110. package/lib/file/copy.d.mts +1 -0
  111. package/lib/file/copy.mjs +8 -0
  112. package/lib/file/move-cli.cjs +91 -0
  113. package/lib/file/move-cli.d.mts +1 -0
  114. package/lib/file/move-cli.mjs +55 -0
  115. package/lib/file/move.cjs +55 -0
  116. package/lib/file/move.d.mts +1 -0
  117. package/lib/file/move.mjs +8 -0
  118. package/lib/find-node-modules-cli.js +2 -1
  119. package/lib/free-chatgpt.cjs +259 -47
  120. package/lib/free-chatgpt.js +10 -10
  121. package/lib/free-chatgpt.mjs +2 -2
  122. package/lib/git/gitattributes.cjs +1 -0
  123. package/lib/git/gitattributes.d.cts +7 -2
  124. package/lib/git/gitattributes.mjs +1 -1
  125. package/lib/git/line-endings.cjs +2 -1
  126. package/lib/git/line-endings.mjs +2 -2
  127. package/lib/git/undo-commit-cli.cjs +110 -0
  128. package/lib/git/undo-commit-cli.d.ts +1 -0
  129. package/lib/git/undo-commit-cli.js +4 -0
  130. package/lib/git/undo-commit-cli.mjs +14 -0
  131. package/lib/git/undo-commit.cjs +81 -0
  132. package/lib/git/undo-commit.d.cts +1 -0
  133. package/lib/git/undo-commit.mjs +7 -0
  134. package/lib/git/undo-staged-cli.cjs +110 -0
  135. package/lib/git/undo-staged-cli.d.ts +1 -0
  136. package/lib/git/undo-staged-cli.js +4 -0
  137. package/lib/git/undo-staged-cli.mjs +14 -0
  138. package/lib/git/undo-staged.cjs +81 -0
  139. package/lib/git/undo-staged.d.cts +1 -0
  140. package/lib/git/undo-staged.mjs +7 -0
  141. package/lib/git/user-config.cjs +61 -14
  142. package/lib/git/user-config.mjs +2 -2
  143. package/lib/git-diff-cli.cjs +427 -75
  144. package/lib/git-diff-cli.d.ts +1 -0
  145. package/lib/git-diff-cli.js +1 -0
  146. package/lib/git-diff-cli.mjs +6 -4
  147. package/lib/git-diff.cjs +426 -75
  148. package/lib/git-diff.d.ts +2 -1
  149. package/lib/git-diff.js +91 -34
  150. package/lib/git-diff.mjs +5 -4
  151. package/lib/git-fix.cjs +64 -16
  152. package/lib/git-fix.mjs +10 -10
  153. package/lib/git-purge.cjs +61 -13
  154. package/lib/git-purge.mjs +1 -1
  155. package/lib/index.d.ts +1 -1
  156. package/lib/kill-night-crows.cjs +87 -0
  157. package/lib/kill-night-crows.d.mts +1 -0
  158. package/lib/kill-night-crows.mjs +65 -0
  159. package/lib/node-cache-cleaner/npm.cjs +65 -0
  160. package/lib/node-cache-cleaner/npm.d.ts +2 -0
  161. package/lib/node-cache-cleaner/npm.js +41 -0
  162. package/lib/node-cache-cleaner/npm.mjs +10 -0
  163. package/lib/node-cache-cleaner/npx.cjs +89 -0
  164. package/lib/node-cache-cleaner/npx.d.ts +4 -0
  165. package/lib/node-cache-cleaner/npx.js +82 -0
  166. package/lib/{ps/index.d.mjs → node-cache-cleaner/npx.mjs} +6 -5
  167. package/lib/node-cache-cleaner/yarn.cjs +73 -0
  168. package/lib/node-cache-cleaner/yarn.d.ts +2 -0
  169. package/lib/node-cache-cleaner/yarn.js +62 -0
  170. package/lib/node-cache-cleaner/yarn.mjs +10 -0
  171. package/lib/node-cache-cleaner-cli.cjs +182 -0
  172. package/lib/node-cache-cleaner-cli.d.ts +2 -0
  173. package/lib/node-cache-cleaner-cli.js +60 -0
  174. package/lib/node-cache-cleaner-cli.mjs +56 -0
  175. package/lib/node-executor.cjs +91 -0
  176. package/lib/node-executor.d.cts +2 -0
  177. package/lib/node-executor.mjs +103 -0
  178. package/lib/npm-run-series.cjs +79 -39
  179. package/lib/npm-run-series.mjs +20 -6
  180. package/lib/package-resolutions-updater-cli.cjs +645 -0
  181. package/lib/package-resolutions-updater-cli.d.mts +1 -0
  182. package/lib/package-resolutions-updater-cli.mjs +102 -0
  183. package/lib/package-resolutions-updater.cjs +259 -133
  184. package/lib/package-resolutions-updater.d.mts +51 -1
  185. package/lib/package-resolutions-updater.mjs +18 -294
  186. package/lib/php-cs-fixer-staged.cjs +105 -0
  187. package/lib/php-cs-fixer-staged.d.cts +2 -0
  188. package/lib/php-cs-fixer-staged.mjs +117 -0
  189. package/lib/print-directory-tree.cjs +62 -14
  190. package/lib/print-directory-tree.mjs +2 -2
  191. package/lib/ps/connected-domain.d.ts +1 -1
  192. package/lib/ps/connected-domain.js +10 -10
  193. package/lib/ps/index.cjs +1 -1
  194. package/lib/ps/index.mjs +177 -171
  195. package/lib/ps/isWin.js +1 -1
  196. package/lib/ps/table-parser.js +6 -6
  197. package/lib/remove-module.cjs +61 -13
  198. package/lib/remove-module.mjs +1 -1
  199. package/lib/rm-node-module-cli.cjs +222 -0
  200. package/lib/rm-node-module-cli.d.cts +1 -0
  201. package/lib/rm-node-module-cli.mjs +89 -0
  202. package/lib/rm-node-modules.cjs +127 -0
  203. package/lib/rm-node-modules.d.cts +35 -0
  204. package/lib/{binary-collections-config.mjs → rm-node-modules.mjs} +3 -3
  205. package/lib/rmpath.cjs +63 -15
  206. package/lib/rmpath.mjs +2 -2
  207. package/lib/submodule-install.cjs +107 -47
  208. package/lib/submodule-install.mjs +48 -35
  209. package/lib/submodule-remove-cli.cjs +6 -3
  210. package/lib/submodule-remove-cli.js +3 -3
  211. package/lib/submodule-remove-cli.mjs +2 -3
  212. package/lib/submodule-remove.cjs +4 -1
  213. package/lib/submodule-remove.mjs +1 -1
  214. package/lib/utils/chatgpt.cjs +198 -34
  215. package/lib/utils/chatgpt.js +260 -93
  216. package/lib/utils/chatgpt.mjs +1 -1
  217. package/lib/utils/findEnvFiles.cjs +89 -0
  218. package/lib/utils/findEnvFiles.d.cts +19 -0
  219. package/lib/utils/findEnvFiles.mjs +6 -0
  220. package/lib/utils/findWorkspaceRoot.cjs +70 -0
  221. package/lib/utils/findWorkspaceRoot.d.ts +9 -0
  222. package/lib/utils/findWorkspaceRoot.js +57 -0
  223. package/lib/utils/findWorkspaceRoot.mjs +40 -0
  224. package/lib/utils/index.cjs +60 -13
  225. package/lib/utils/index.mjs +1 -1
  226. package/lib/utils/isGithubTokenValid.cjs +64 -0
  227. package/lib/utils/isGithubTokenValid.d.ts +7 -0
  228. package/lib/utils/isGithubTokenValid.js +48 -0
  229. package/lib/utils/isGithubTokenValid.mjs +36 -0
  230. package/lib/{ps/index.d.cjs → utils/isWindows.cjs} +17 -3
  231. package/lib/utils/isWindows.d.ts +5 -0
  232. package/lib/utils/isWindows.js +10 -0
  233. package/lib/utils/isWindows.mjs +8 -0
  234. package/lib/utils/runBash.cjs +53 -0
  235. package/lib/utils/runBash.d.cts +12 -0
  236. package/lib/utils/runBash.mjs +66 -0
  237. package/lib/yarn-per-branch-lock-installer.cjs +97 -0
  238. package/lib/yarn-per-branch-lock-installer.d.cts +2 -0
  239. package/lib/yarn-per-branch-lock-installer.mjs +109 -0
  240. package/lib/yarn-reinstall.cjs +61 -13
  241. package/lib/yarn-reinstall.mjs +1 -1
  242. package/package.json +133 -110
  243. package/readme.html +784 -0
  244. package/readme.md +116 -229
  245. package/releases/readme.md +1 -1
  246. package/requirements.txt +1 -0
  247. package/test/README.md +2 -2
  248. package/test-project/package.json +8 -2
  249. package/test-project/workspaces/workspace-a/package.json +135 -0
  250. package/test-project/workspaces/workspace-a/readme.md +20 -0
  251. package/test-project/workspaces/workspace-a/release/readme.md +42 -0
  252. package/test-project/workspaces/workspace-a/test/demo/package.json +25 -0
  253. package/test-project/workspaces/workspace-a/test/readme.md +12 -0
  254. package/test-project/workspaces/workspace-b/package.json +139 -0
  255. package/test-project/workspaces/workspace-b/readme.md +94 -0
  256. package/test-project/workspaces/workspace-b/requirements.txt +1 -0
  257. package/test-project/workspaces/workspace-b/test/sample-project/package.json +7 -0
  258. package/test-project/workspaces/workspace-b/themes/hexo-theme-flowbite/package.json +96 -0
  259. package/test-project/workspaces/workspace-b/themes/hexo-theme-flowbite/readme.md +156 -0
  260. package/tmp/rm-node-modules-test-project/package.json +17 -0
  261. package/tmp/rm-node-modules-test-project/packages/workspace-a/package.json +16 -0
  262. package/tmp/rm-node-modules-test-project/packages/workspace-b/package.json +16 -0
  263. package/tmp/test-repo/README.md +2 -35
  264. package/tmp/test-repo/package.json +13 -3
  265. package/docs-src/clean-github-actions-caches.md +0 -26
  266. package/docs-src/free-chatgpt.md +0 -26
  267. package/lib/binary-collections-config.cjs +0 -15
  268. package/lib/chunk-4EWQC6GZ.mjs +0 -382
  269. package/lib/chunk-4ZI7BQKQ.mjs +0 -381
  270. package/lib/chunk-5J2BEPY5.mjs +0 -83
  271. package/lib/chunk-AGZYRDC2.mjs +0 -323
  272. package/lib/chunk-BDCHCWHD.mjs +0 -136
  273. package/lib/chunk-BEZKJ25G.mjs +0 -140
  274. package/lib/chunk-DI5MDPSN.mjs +0 -386
  275. package/lib/chunk-GJTGHXRA.mjs +0 -356
  276. package/lib/chunk-HMRMTYZM.mjs +0 -40
  277. package/lib/chunk-HN52G2YL.mjs +0 -305
  278. package/lib/chunk-LEM5OMRP.mjs +0 -384
  279. package/lib/chunk-O6SWBEOQ.mjs +0 -81
  280. package/lib/chunk-RCP7DHVY.mjs +0 -190
  281. package/lib/chunk-SBNDSKG5.mjs +0 -136
  282. package/lib/chunk-U6SO4QEV.mjs +0 -320
  283. package/lib/chunk-XD6BJK6Q.mjs +0 -351
  284. package/lib/chunk-YXSFGA2D.mjs +0 -383
  285. package/lib/git/gitattributes.d.ts +0 -33
  286. package/lib/git/gitattributes.js +0 -223
  287. package/lib/ps/index.d.ts +0 -2
  288. package/lib/ps/index.js +0 -253
  289. package/tmp/typedoc/readme.md +0 -320
  290. /package/lib/{binary-collections-config.d.cts → binary-collections/config.d.cts} +0 -0
@@ -0,0 +1,268 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_findEnvFiles
4
+ } from "./chunk-H44UWUFY.mjs";
5
+ import {
6
+ require_utils
7
+ } from "./chunk-5RTXZVCW.mjs";
8
+ import {
9
+ __toESM,
10
+ init_esm_shims
11
+ } from "./chunk-QQ4A6DLD.mjs";
12
+
13
+ // src/package-resolutions-updater.mjs
14
+ init_esm_shims();
15
+ var utils = __toESM(require_utils(), 1);
16
+ var import_findEnvFiles = __toESM(require_findEnvFiles(), 1);
17
+ import * as dotenv from "dotenv";
18
+ import fs from "fs";
19
+ import https from "https";
20
+ import os from "os";
21
+ import path from "path";
22
+ import { parseGitHubUrl } from "git-command-helper";
23
+ import axios from "axios";
24
+ var projectDir = process.cwd();
25
+ var envPath = path.join(projectDir, ".env");
26
+ var args = utils.getArgs();
27
+ if (!fs.existsSync(envPath)) {
28
+ const envFiles = (0, import_findEnvFiles.findEnvFiles)(projectDir, (file) => {
29
+ const content = fs.readFileSync(file, "utf-8");
30
+ return /GITHUB_TOKEN|ACCESS_TOKEN/.test(content);
31
+ });
32
+ if (envFiles.length > 0) {
33
+ envPath = envFiles[0];
34
+ }
35
+ }
36
+ if (fs.existsSync(envPath)) {
37
+ dotenv.config({ path: envPath, quiet: true, override: true });
38
+ }
39
+ var ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
40
+ if (args.help || args.h) {
41
+ showHelp();
42
+ }
43
+ function showHelp() {
44
+ const helpText = `
45
+ GitHub Package Resolutions Updater
46
+ Usage:
47
+ node src/package-resolutions-updater.mjs [options]
48
+ Options:
49
+ --help, -h Show this help message
50
+ Description:
51
+ Updates the commit hashes in package.json's 'resolutions' field for GitHub tarball URLs to point to the latest commit SHA of the corresponding repository and branch.
52
+ Features:
53
+ - Parses GitHub URLs to extract repository owner, name, and branch.
54
+ - Fetches the latest commit SHA across all branches using GitHub's API.
55
+ - Replaces the old branch or commit in the URL with the latest SHA.
56
+ - Overwrites package.json with the updated URLs.
57
+ Requirements:
58
+ - GitHub Personal Access Token (GITHUB_TOKEN) via .env
59
+ - ESM support (type: "module" in package.json)
60
+ - Node.js v18+ recommended
61
+ Dependencies:
62
+ - ansi-colors \u2013 for styled terminal output
63
+ - dotenv \u2013 to load GitHub token from .env
64
+ Examples:
65
+ node src/package-resolutions-updater.mjs
66
+ node src/package-resolutions-updater.mjs --help
67
+
68
+ `;
69
+ console.log(helpText);
70
+ process.exit(0);
71
+ }
72
+ var GITHUB_USER_AGENTS = [
73
+ "octokit-rest.js/19.0.7",
74
+ "GitHub CLI/2.40.0",
75
+ "Mozilla/5.0 (compatible; GitHubCopilot/1.0)",
76
+ "PostmanRuntime/7.32.3",
77
+ "binary-collections-resolver/1.0 (+https://github.com/dimaslanjaka/bin)"
78
+ ];
79
+ var userAgentDir = path.join(os.tmpdir(), "nodejs");
80
+ var userAgentFile = path.join(userAgentDir, "useragent.txt");
81
+ var selectedUserAgent;
82
+ try {
83
+ if (!fs.existsSync(userAgentDir)) fs.mkdirSync(userAgentDir, { recursive: true });
84
+ if (fs.existsSync(userAgentFile)) {
85
+ const fileAgent = fs.readFileSync(userAgentFile, "utf-8").trim();
86
+ if (GITHUB_USER_AGENTS.includes(fileAgent)) {
87
+ selectedUserAgent = fileAgent;
88
+ }
89
+ }
90
+ if (!selectedUserAgent) {
91
+ selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
92
+ fs.writeFileSync(userAgentFile, selectedUserAgent, "utf-8");
93
+ }
94
+ } catch (_e) {
95
+ selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
96
+ }
97
+ function fetchJson(url) {
98
+ const headers = {
99
+ "User-Agent": selectedUserAgent,
100
+ Accept: "application/vnd.github.v3+json",
101
+ "X-GitHub-Api-Version": "2022-11-28",
102
+ ...ACCESS_TOKEN ? { Authorization: `token ${ACCESS_TOKEN}` } : {}
103
+ };
104
+ return new Promise((resolve, reject) => {
105
+ https.get(url, { headers }, (res) => {
106
+ let data = "";
107
+ res.on("data", (chunk) => data += chunk);
108
+ res.on("end", () => {
109
+ try {
110
+ const json = JSON.parse(data);
111
+ if (res.statusCode < 200 || res.statusCode >= 300) {
112
+ return reject(
113
+ new Error(`GitHub API Error ${res.statusCode}: ${json.message || "Unknown error"}
114
+ URL: ${url}`)
115
+ );
116
+ }
117
+ resolve(json);
118
+ } catch {
119
+ reject(new Error(`Invalid JSON from: ${url}`));
120
+ }
121
+ });
122
+ }).on("error", reject);
123
+ });
124
+ }
125
+ async function getLatestCommit(owner, repo, branch = "main") {
126
+ var _a, _b, _c, _d;
127
+ const url = `https://api.github.com/repos/${owner}/${repo}/commits/${branch}`;
128
+ const json = await fetchJson(url);
129
+ const sha = json.sha;
130
+ const dateStr = ((_b = (_a = json.commit) == null ? void 0 : _a.committer) == null ? void 0 : _b.date) || ((_d = (_c = json.commit) == null ? void 0 : _c.author) == null ? void 0 : _d.date);
131
+ if (!sha || !dateStr) {
132
+ console.log(json);
133
+ throw new Error(`Missing SHA or date for ${owner}/${repo}@${branch}`);
134
+ }
135
+ return {
136
+ owner,
137
+ repo,
138
+ branch,
139
+ sha,
140
+ date: new Date(dateStr).toISOString()
141
+ };
142
+ }
143
+ async function getLatestCommitAcrossBranches(owner, repo) {
144
+ const branches = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/branches`);
145
+ const commits = await Promise.all(
146
+ branches.map(async ({ name, commit }) => {
147
+ var _a, _b, _c, _d;
148
+ const commitSha = commit == null ? void 0 : commit.sha;
149
+ if (!commitSha) {
150
+ console.warn(`No commit SHA for '${owner}/${repo}' branch: ${name}`);
151
+ return { branch: name, sha: "", date: /* @__PURE__ */ new Date(0) };
152
+ }
153
+ try {
154
+ const commitData = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}`);
155
+ const dateStr = ((_b = (_a = commitData.commit) == null ? void 0 : _a.committer) == null ? void 0 : _b.date) || ((_d = (_c = commitData.commit) == null ? void 0 : _c.author) == null ? void 0 : _d.date);
156
+ const date = dateStr ? new Date(dateStr) : /* @__PURE__ */ new Date(0);
157
+ return { branch: name, sha: commitData.sha, date };
158
+ } catch (e) {
159
+ console.warn(`Failed to fetch commit for ${name}: ${e.message}`);
160
+ return { branch: name, sha: commitSha, date: /* @__PURE__ */ new Date(0) };
161
+ }
162
+ })
163
+ );
164
+ const latest = commits.reduce((a, b) => a.date > b.date ? a : b, { date: /* @__PURE__ */ new Date(0) });
165
+ return {
166
+ owner,
167
+ repo,
168
+ branch: latest.branch,
169
+ sha: latest.sha,
170
+ date: latest.date.toISOString()
171
+ };
172
+ }
173
+ function replaceRawWithLatestHash(url, latestHash) {
174
+ const parsed = parseGitHubUrl(url);
175
+ if (!parsed || !parsed.owner || !parsed.repo || !parsed.branch) {
176
+ throw new Error("Invalid GitHub raw URL");
177
+ }
178
+ const branchPrefix = `${parsed.branch}/`;
179
+ const rawPrefix = parsed.host === "github.com" ? `raw/${branchPrefix}` : branchPrefix;
180
+ const refsPrefix = `refs/heads/${branchPrefix}`;
181
+ const path2 = parsed.path.startsWith(rawPrefix) ? parsed.path.slice(rawPrefix.length) : parsed.path.startsWith(refsPrefix) ? parsed.path.slice(refsPrefix.length) : parsed.path.startsWith(branchPrefix) ? parsed.path.slice(branchPrefix.length) : parsed.path;
182
+ if (parsed.host === "github.com") {
183
+ return `https://github.com/${parsed.owner}/${parsed.repo}/raw/${latestHash}/${path2}`;
184
+ }
185
+ if (parsed.host === "raw.githubusercontent.com") {
186
+ return `https://raw.githubusercontent.com/${parsed.owner}/${parsed.repo}/${latestHash}/${path2}`;
187
+ }
188
+ throw new Error("Invalid GitHub raw URL");
189
+ }
190
+ async function resolvePackageResolutionUpdates(resolutions, specialPackageOverrides = []) {
191
+ const updates = [];
192
+ for (const [currentPkgName, url] of Object.entries(resolutions || {})) {
193
+ let repo;
194
+ try {
195
+ repo = parseGitHubUrl(url);
196
+ } catch (error) {
197
+ updates.push({
198
+ skipped: true,
199
+ currentPkgName,
200
+ url,
201
+ error
202
+ });
203
+ continue;
204
+ }
205
+ try {
206
+ const override = specialPackageOverrides.find((p) => p.pkg === currentPkgName);
207
+ const latest = override ? await getLatestCommit(override.owner, override.repo, override.branch) : await getLatestCommitAcrossBranches(repo.owner, repo.repo);
208
+ const new_url = replaceRawWithLatestHash(url, latest.sha);
209
+ await axios.head(new_url, {
210
+ headers: {
211
+ "User-Agent": selectedUserAgent,
212
+ Accept: "application/vnd.github.v3+json",
213
+ "X-GitHub-Api-Version": "2022-11-28",
214
+ ...ACCESS_TOKEN ? { Authorization: `token ${ACCESS_TOKEN}` } : {}
215
+ }
216
+ }).then((response) => {
217
+ if (response.status < 200 || response.status >= 300) {
218
+ updates.push({
219
+ failed: true,
220
+ currentPkgName,
221
+ url,
222
+ new_url,
223
+ repo,
224
+ latest,
225
+ error: new Error(`New URL is not accessible, status code: ${response.status}`)
226
+ });
227
+ return;
228
+ }
229
+ updates.push({
230
+ currentPkgName,
231
+ url,
232
+ new_url,
233
+ repo,
234
+ latest
235
+ });
236
+ }).catch((e) => {
237
+ updates.push({
238
+ failed: true,
239
+ currentPkgName,
240
+ url,
241
+ new_url,
242
+ repo,
243
+ latest,
244
+ error: new Error(`New URL is not accessible: ${e.message}`)
245
+ });
246
+ return null;
247
+ });
248
+ } catch (error) {
249
+ updates.push({
250
+ failed: true,
251
+ currentPkgName,
252
+ url,
253
+ repo,
254
+ error
255
+ });
256
+ }
257
+ }
258
+ return updates;
259
+ }
260
+
261
+ export {
262
+ parseGitHubUrl,
263
+ fetchJson,
264
+ getLatestCommit,
265
+ getLatestCommitAcrossBranches,
266
+ replaceRawWithLatestHash,
267
+ resolvePackageResolutionUpdates
268
+ };
@@ -0,0 +1,61 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_package
4
+ } from "./chunk-ZOWVMII3.mjs";
5
+ import {
6
+ __commonJS,
7
+ __dirname,
8
+ __require,
9
+ init_esm_shims
10
+ } from "./chunk-QQ4A6DLD.mjs";
11
+
12
+ // src/binary-collections/listScript.cjs
13
+ var require_listScript = __commonJS({
14
+ "src/binary-collections/listScript.cjs"(exports, module) {
15
+ init_esm_shims();
16
+ var pkgJson = require_package();
17
+ var path = __require("upath");
18
+ var fs = __require("fs-extra");
19
+ function listScript(verbose = false) {
20
+ const keys = Object.keys(pkgJson.bin);
21
+ const results = [];
22
+ for (const scriptName of keys) {
23
+ if (verbose) {
24
+ console.log(`\u{1F50D} Finding script "${scriptName}" -> "${pkgJson.bin[scriptName]}"`);
25
+ }
26
+ const searchDirs = [
27
+ path.join(__dirname, ".."),
28
+ path.join(__dirname, "../.."),
29
+ path.join(process.cwd(), "node_modules/binary-collections"),
30
+ __dirname
31
+ ];
32
+ let scriptPath;
33
+ for (const searchDir of searchDirs) {
34
+ scriptPath = path.join(searchDir, pkgJson.bin[scriptName]);
35
+ if (fs.existsSync(scriptPath)) {
36
+ break;
37
+ }
38
+ }
39
+ if (!fs.existsSync(scriptPath)) {
40
+ console.warn(`\u26A0\uFE0F Script "${scriptName}" defined in package.json not found at ${scriptPath}`);
41
+ } else {
42
+ if (verbose) {
43
+ console.log(`\u2705 Found script "${scriptName}" at ${scriptPath}`);
44
+ }
45
+ results.push({
46
+ name: scriptName,
47
+ path: path.relative(process.cwd(), scriptPath),
48
+ absolutePath: path.resolve(scriptPath)
49
+ });
50
+ }
51
+ }
52
+ return results;
53
+ }
54
+ module.exports = listScript;
55
+ module.exports.default = listScript;
56
+ }
57
+ });
58
+
59
+ export {
60
+ require_listScript
61
+ };
@@ -13,7 +13,10 @@ var require_submodule_remove = __commonJS({
13
13
  var path = __require("upath");
14
14
  var fs = __require("fs-extra");
15
15
  var dotenv = __require("dotenv");
16
- dotenv.config({ path: path.resolve(process.cwd(), ".env") });
16
+ var envPath = path.resolve(process.cwd(), ".env");
17
+ if (fs.existsSync(envPath)) {
18
+ dotenv.config({ path: envPath, override: true, quiet: true });
19
+ }
17
20
  async function removeSubmodule(submodulePath) {
18
21
  try {
19
22
  await spawnAsync("git", ["submodule", "deinit", "-f", submodulePath], { stdio: "inherit" });
@@ -0,0 +1,32 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ isWindows
4
+ } from "./chunk-XPJGCDOD.mjs";
5
+ import {
6
+ init_esm_shims
7
+ } from "./chunk-QQ4A6DLD.mjs";
8
+
9
+ // src/cross-env/command.ts
10
+ init_esm_shims();
11
+ import path from "path";
12
+ function commandConvert(command, env, normalize = false) {
13
+ if (!isWindows()) {
14
+ return command;
15
+ }
16
+ const simpleEnvRegex = /\$(\w+)|\${(\w+)}/g;
17
+ const defaultValueRegex = /\$\{(\w+):-([^}]+)\}/g;
18
+ let convertedCmd = command;
19
+ convertedCmd = convertedCmd.replace(defaultValueRegex, (match, varName, defaultValue) => {
20
+ const value = env[varName] || defaultValue;
21
+ return value;
22
+ });
23
+ convertedCmd = convertedCmd.replace(simpleEnvRegex, (match, $1, $2) => {
24
+ const varName = $1 || $2;
25
+ return env[varName] ? `%${varName}%` : "";
26
+ });
27
+ return normalize === true ? path.normalize(convertedCmd) : convertedCmd;
28
+ }
29
+
30
+ export {
31
+ commandConvert
32
+ };
@@ -0,0 +1,158 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_findEnvFiles
4
+ } from "./chunk-H44UWUFY.mjs";
5
+ import {
6
+ __commonJS,
7
+ __require,
8
+ init_esm_shims
9
+ } from "./chunk-QQ4A6DLD.mjs";
10
+
11
+ // src/clean-github-actions-caches.cjs
12
+ var require_clean_github_actions_caches = __commonJS({
13
+ "src/clean-github-actions-caches.cjs"(exports, module) {
14
+ init_esm_shims();
15
+ var axios = __require("axios");
16
+ var minimist = __require("minimist");
17
+ var { findEnvWithToken } = require_findEnvFiles();
18
+ __require("dotenv").config({
19
+ path: findEnvWithToken(),
20
+ quiet: true,
21
+ overwrite: true
22
+ });
23
+ var ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
24
+ if (!ACCESS_TOKEN) {
25
+ throw new Error(
26
+ "Access token is not provided. Please set ACCESS_TOKEN or GITHUB_TOKEN in your environment variables."
27
+ );
28
+ }
29
+ function printHelp() {
30
+ console.log(`
31
+ GitHub Actions Cache Cleaner
32
+
33
+ Description:
34
+ Removes outdated GitHub Actions caches for a repository, keeping only the newest
35
+ cache for each cache-key prefix. Authenticates via ACCESS_TOKEN or GITHUB_TOKEN
36
+ from your environment or .env file.
37
+
38
+ Usage:
39
+ clean-github-actions-caches [options]
40
+
41
+ Options:
42
+ -h, --help Show this help message
43
+ -r, --repo <repo> GitHub repository (owner/repo). If omitted, the tool will
44
+ attempt to infer the repository from the current working
45
+ directory's git remotes.
46
+
47
+ Environment Variables:
48
+ ACCESS_TOKEN GitHub access token (preferred)
49
+ GITHUB_TOKEN GitHub access token (fallback)
50
+
51
+ Behavior & Safety:
52
+ - Groups caches by a derived prefix from the cache key and keeps the most
53
+ recently created cache for each group.
54
+ - Deletes only caches older than the latest per prefix to reduce risk of
55
+ removing needed artifacts.
56
+
57
+ Examples:
58
+ # Run against a specific repo (owner/repo)
59
+ clean-github-actions-caches --repo octocat/hello-world
60
+
61
+ # Run via npx without installing
62
+ npx -y binary-collections@https://raw.githubusercontent.com/dimaslanjaka/bin/master/releases/bin.tgz clean-github-actions-caches --repo owner/repo
63
+
64
+ # Run via yarn dlx
65
+ yarn dlx binary-collections@https://raw.githubusercontent.com/dimaslanjaka/bin/master/releases/bin.tgz clean-github-actions-caches
66
+
67
+ Notes:
68
+ - Ensure ACCESS_TOKEN or GITHUB_TOKEN is set and has permissions to manage Actions caches.
69
+ - Intended for repository maintainers with appropriate permissions.
70
+ `);
71
+ }
72
+ var argv = minimist(process.argv.slice(2), {
73
+ alias: {
74
+ h: "help",
75
+ r: "repo"
76
+ },
77
+ string: ["repo"],
78
+ boolean: ["help"]
79
+ });
80
+ if (argv.help) {
81
+ printHelp();
82
+ process.exit(0);
83
+ }
84
+ function deleteGitHubActionsCache(GH_REPO, cacheId) {
85
+ return new Promise((resolve, reject) => {
86
+ const url = `https://api.github.com/repos/${GH_REPO}/actions/caches/${cacheId}`;
87
+ const token = ACCESS_TOKEN;
88
+ if (!token) {
89
+ return reject(new Error("Access token is not provided"));
90
+ }
91
+ axios.delete(url, {
92
+ headers: {
93
+ Authorization: `token ${token}`,
94
+ Accept: "application/vnd.github.v3+json"
95
+ }
96
+ }).then((response) => {
97
+ console.log(`Cache (${cacheId}) deleted successfully`, response.data);
98
+ resolve(response.data);
99
+ }).catch((error) => {
100
+ var _a;
101
+ console.error("Error deleting cache:", ((_a = error.response) == null ? void 0 : _a.data) || error.message || "Unknown error");
102
+ reject(error);
103
+ });
104
+ });
105
+ }
106
+ function get_caches(GH_REPO) {
107
+ const url = `https://api.github.com/repos/${GH_REPO}/actions/caches`;
108
+ return new Promise((resolve, reject) => {
109
+ axios.get(url, {
110
+ headers: {
111
+ Accept: "application/vnd.github.v3+json",
112
+ Authorization: `token ${ACCESS_TOKEN}`
113
+ }
114
+ }).then((response) => {
115
+ const data = response.data.actions_caches;
116
+ const getPrefix = (key) => {
117
+ const split = key.split(/[-_]/);
118
+ if (split.length === 3) {
119
+ return `${split[0]}-${split[1]}`;
120
+ }
121
+ if (split.length > 3) {
122
+ return `${split[0]}-${split[1]}-${split[2]}`;
123
+ }
124
+ return split[0];
125
+ };
126
+ const grouped = data.reduce(
127
+ /**
128
+ * @param {Record<string, Record<string, any>[]>} acc
129
+ * @param {Record<string, any>} item
130
+ * @returns {Record<string, Record<string, any>[]>}
131
+ */
132
+ (acc, item) => {
133
+ const prefix = getPrefix(item.key);
134
+ if (!acc[prefix]) {
135
+ acc[prefix] = [];
136
+ }
137
+ acc[prefix].push(item);
138
+ return acc;
139
+ },
140
+ {}
141
+ );
142
+ resolve(grouped);
143
+ }).catch((error) => {
144
+ console.error("Error fetching data:", error);
145
+ reject(error);
146
+ });
147
+ });
148
+ }
149
+ module.exports = {
150
+ deleteGitHubActionsCache,
151
+ get_caches
152
+ };
153
+ }
154
+ });
155
+
156
+ export {
157
+ require_clean_github_actions_caches
158
+ };
@@ -1,16 +1,20 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_findEnvFiles
4
+ } from "./chunk-H44UWUFY.mjs";
2
5
  import {
3
6
  __commonJS,
4
7
  __require,
5
8
  init_esm_shims
6
9
  } from "./chunk-QQ4A6DLD.mjs";
7
10
 
8
- // src/binary-collections-config.cjs
9
- var require_binary_collections_config = __commonJS({
10
- "src/binary-collections-config.cjs"(exports, module) {
11
+ // src/binary-collections/config.cjs
12
+ var require_config = __commonJS({
13
+ "src/binary-collections/config.cjs"(exports, module) {
11
14
  init_esm_shims();
12
15
  var path = __require("path");
13
- __require("dotenv").config({ path: path.join(process.cwd(), ".env") });
16
+ var { findEnvWithToken } = require_findEnvFiles();
17
+ __require("dotenv").config({ path: findEnvWithToken(), quiet: true, overwrite: true });
14
18
  function getTempDir() {
15
19
  return process.env.TEMP_DIR || path.join(process.cwd(), "tmp");
16
20
  }
@@ -27,5 +31,5 @@ var require_binary_collections_config = __commonJS({
27
31
  });
28
32
 
29
33
  export {
30
- require_binary_collections_config
34
+ require_config
31
35
  };