binary-collections 2.0.11 → 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 (225) hide show
  1. package/.opencode/package.json +5 -0
  2. package/binaries/rmx +15 -1
  3. package/binaries/rmx.cmd +12 -0
  4. package/binaries/test-cjs +9 -1
  5. package/binaries/test-cjs.cmd +16 -1
  6. package/binaries/test-esm +16 -0
  7. package/binaries/test-esm.cjs +178 -0
  8. package/binaries/test-esm.cmd +23 -0
  9. package/binaries/yarn-clean +1 -1
  10. package/binaries/yarn-clean.cmd +1 -1
  11. package/binaries/yarn-clean.py +33 -15
  12. package/binaries/yc +110 -0
  13. package/binaries/yc.cjs +178 -0
  14. package/lib/binary-collections/config.cjs +126 -0
  15. package/lib/binary-collections/config.mjs +7 -0
  16. package/lib/binary-collections/executeScript.cjs +19 -0
  17. package/lib/binary-collections/executeScript.d.cts +12 -0
  18. package/lib/binary-collections/executeScript.mjs +6 -0
  19. package/lib/binary-collections/findScript.cjs +284 -0
  20. package/lib/binary-collections/findScript.d.cts +12 -0
  21. package/lib/binary-collections/findScript.mjs +7 -0
  22. package/lib/binary-collections/listScript.cjs +266 -0
  23. package/lib/binary-collections/listScript.d.cts +19 -0
  24. package/lib/binary-collections/listScript.mjs +7 -0
  25. package/lib/binary-collections.cjs +224 -137
  26. package/lib/binary-collections.mjs +22 -282
  27. package/lib/changelog.cjs +2 -2
  28. package/lib/changelog.mjs +1 -1
  29. package/lib/{chunk-AJDD5DZM.mjs → chunk-2LSRSEXF.mjs} +1 -1
  30. package/lib/{chunk-Z6JLYU2J.mjs → chunk-5RTXZVCW.mjs} +2 -2
  31. package/lib/{chunk-XA3SNBPA.mjs → chunk-66KDU4TX.mjs} +93 -9
  32. package/lib/chunk-6PU7BAHB.mjs +61 -0
  33. package/lib/chunk-C6D2TTYU.mjs +32 -0
  34. package/lib/chunk-FB2WKVJD.mjs +158 -0
  35. package/lib/{chunk-NCXAP7AA.mjs → chunk-G5UUEWUO.mjs} +9 -5
  36. package/lib/{chunk-N436BNBK.mjs → chunk-GAGABICI.mjs} +19 -13
  37. package/lib/chunk-H44UWUFY.mjs +105 -0
  38. package/lib/chunk-NCZPTKDV.mjs +79 -0
  39. package/lib/chunk-NGFK3EYW.mjs +28 -0
  40. package/lib/chunk-NVEG3LEZ.mjs +143 -0
  41. package/lib/chunk-OGXVGBRI.mjs +29 -0
  42. package/lib/chunk-OXV52GD5.mjs +62 -0
  43. package/lib/chunk-PXBMHE7O.mjs +35 -0
  44. package/lib/chunk-R5FJOR63.mjs +47 -0
  45. package/lib/chunk-SPTECFE5.mjs +180 -0
  46. package/lib/chunk-UXCFNAR6.mjs +55 -0
  47. package/lib/chunk-V2IBPCEV.mjs +39 -0
  48. package/lib/chunk-XPJGCDOD.mjs +14 -0
  49. package/lib/chunk-ZOWVMII3.mjs +228 -0
  50. package/lib/clean-github-actions-caches-cli.cjs +465 -0
  51. package/lib/clean-github-actions-caches-cli.d.cts +1 -0
  52. package/lib/clean-github-actions-caches-cli.mjs +56 -0
  53. package/lib/clean-github-actions-caches.cjs +149 -205
  54. package/lib/clean-github-actions-caches.d.cts +15 -1
  55. package/lib/clean-github-actions-caches.mjs +4 -130
  56. package/lib/cross-env/command.cjs +63 -0
  57. package/lib/cross-env/command.d.ts +8 -0
  58. package/lib/cross-env/command.js +45 -0
  59. package/lib/cross-env/command.mjs +9 -0
  60. package/lib/cross-env/index.cjs +178 -0
  61. package/lib/cross-env/index.d.ts +8 -0
  62. package/lib/cross-env/index.js +102 -0
  63. package/lib/cross-env/index.mjs +101 -0
  64. package/lib/cross-env/variable.cjs +60 -0
  65. package/lib/cross-env/variable.d.ts +7 -0
  66. package/lib/cross-env/variable.js +59 -0
  67. package/lib/cross-env/variable.mjs +9 -0
  68. package/lib/del-gradle.cjs +2 -2
  69. package/lib/del-gradle.js +8 -8
  70. package/lib/del-gradle.mjs +1 -1
  71. package/lib/del-node-modules.js +24 -24
  72. package/lib/del-ps.cjs +2 -2
  73. package/lib/del-ps.js +8 -8
  74. package/lib/del-ps.mjs +1 -1
  75. package/lib/del-yarn-caches.cjs +2 -2
  76. package/lib/del-yarn-caches.js +2 -2
  77. package/lib/del-yarn-caches.mjs +1 -1
  78. package/lib/file/copy-cli.cjs +92 -0
  79. package/lib/file/copy-cli.d.mts +1 -0
  80. package/lib/file/copy-cli.mjs +55 -0
  81. package/lib/file/copy.cjs +56 -0
  82. package/lib/file/copy.d.mts +1 -0
  83. package/lib/file/copy.mjs +8 -0
  84. package/lib/file/move-cli.cjs +91 -0
  85. package/lib/file/move-cli.d.mts +1 -0
  86. package/lib/file/move-cli.mjs +55 -0
  87. package/lib/file/move.cjs +55 -0
  88. package/lib/file/move.d.mts +1 -0
  89. package/lib/file/move.mjs +8 -0
  90. package/lib/find-node-modules-cli.js +1 -1
  91. package/lib/free-chatgpt.cjs +21 -15
  92. package/lib/free-chatgpt.js +10 -10
  93. package/lib/free-chatgpt.mjs +2 -2
  94. package/lib/git/user-config.cjs +2 -2
  95. package/lib/git/user-config.mjs +2 -2
  96. package/lib/git-diff-cli.cjs +188 -42
  97. package/lib/git-diff-cli.mjs +5 -4
  98. package/lib/git-diff.cjs +188 -42
  99. package/lib/git-diff.d.ts +2 -1
  100. package/lib/git-diff.js +91 -34
  101. package/lib/git-diff.mjs +5 -4
  102. package/lib/git-fix.cjs +2 -2
  103. package/lib/git-fix.mjs +2 -2
  104. package/lib/git-purge.cjs +2 -2
  105. package/lib/git-purge.mjs +1 -1
  106. package/lib/index.d.ts +1 -1
  107. package/lib/kill-night-crows.cjs +7 -7
  108. package/lib/kill-night-crows.mjs +7 -7
  109. package/lib/node-cache-cleaner/npm.cjs +65 -0
  110. package/lib/node-cache-cleaner/npm.d.ts +2 -0
  111. package/lib/node-cache-cleaner/npm.js +41 -0
  112. package/lib/node-cache-cleaner/npm.mjs +10 -0
  113. package/lib/node-cache-cleaner/npx.cjs +89 -0
  114. package/lib/node-cache-cleaner/npx.d.ts +4 -0
  115. package/lib/node-cache-cleaner/npx.js +82 -0
  116. package/lib/{ps/index.d.mjs → node-cache-cleaner/npx.mjs} +6 -5
  117. package/lib/node-cache-cleaner/yarn.cjs +73 -0
  118. package/lib/node-cache-cleaner/yarn.d.ts +2 -0
  119. package/lib/node-cache-cleaner/yarn.js +62 -0
  120. package/lib/node-cache-cleaner/yarn.mjs +10 -0
  121. package/lib/node-cache-cleaner-cli.cjs +182 -0
  122. package/lib/node-cache-cleaner-cli.d.ts +2 -0
  123. package/lib/node-cache-cleaner-cli.js +60 -0
  124. package/lib/node-cache-cleaner-cli.mjs +56 -0
  125. package/lib/node-executor.cjs +91 -0
  126. package/lib/node-executor.d.cts +2 -0
  127. package/lib/node-executor.mjs +103 -0
  128. package/lib/npm-run-series.cjs +21 -28
  129. package/lib/npm-run-series.mjs +20 -6
  130. package/lib/package-resolutions-updater-cli.cjs +213 -128
  131. package/lib/package-resolutions-updater-cli.mjs +17 -39
  132. package/lib/package-resolutions-updater.cjs +204 -98
  133. package/lib/package-resolutions-updater.d.mts +20 -1
  134. package/lib/package-resolutions-updater.mjs +7 -5
  135. package/lib/print-directory-tree.cjs +2 -2
  136. package/lib/print-directory-tree.mjs +1 -1
  137. package/lib/ps/connected-domain.js +10 -10
  138. package/lib/ps/index.cjs +1 -1
  139. package/lib/ps/index.mjs +177 -171
  140. package/lib/ps/isWin.js +1 -1
  141. package/lib/ps/table-parser.js +6 -6
  142. package/lib/remove-module.cjs +2 -2
  143. package/lib/remove-module.mjs +1 -1
  144. package/lib/rm-node-module-cli.cjs +222 -0
  145. package/lib/rm-node-module-cli.d.cts +1 -0
  146. package/lib/rm-node-module-cli.mjs +89 -0
  147. package/lib/rm-node-modules.cjs +127 -0
  148. package/lib/rm-node-modules.d.cts +35 -0
  149. package/lib/{binary-collections-config.mjs → rm-node-modules.mjs} +3 -3
  150. package/lib/rmpath.cjs +2 -2
  151. package/lib/rmpath.mjs +1 -1
  152. package/lib/submodule-install.cjs +47 -34
  153. package/lib/submodule-install.mjs +46 -33
  154. package/lib/submodule-remove-cli.cjs +1 -2
  155. package/lib/submodule-remove-cli.js +3 -3
  156. package/lib/submodule-remove-cli.mjs +1 -2
  157. package/lib/utils/chatgpt.cjs +19 -13
  158. package/lib/utils/chatgpt.js +94 -94
  159. package/lib/utils/chatgpt.mjs +1 -1
  160. package/lib/utils/findEnvFiles.cjs +28 -46
  161. package/lib/utils/findEnvFiles.d.cts +19 -0
  162. package/lib/utils/findEnvFiles.mjs +3 -5
  163. package/lib/utils/findWorkspaceRoot.js +4 -4
  164. package/lib/utils/index.cjs +2 -2
  165. package/lib/utils/index.mjs +1 -1
  166. package/lib/utils/isGithubTokenValid.js +7 -7
  167. package/lib/{ps/index.d.cjs → utils/isWindows.cjs} +17 -3
  168. package/lib/utils/isWindows.d.ts +5 -0
  169. package/lib/utils/isWindows.js +10 -0
  170. package/lib/utils/isWindows.mjs +8 -0
  171. package/lib/utils/runBash.cjs +53 -0
  172. package/lib/utils/runBash.d.cts +12 -0
  173. package/lib/utils/runBash.mjs +66 -0
  174. package/lib/yarn-per-branch-lock-installer.cjs +97 -0
  175. package/lib/yarn-per-branch-lock-installer.d.cts +2 -0
  176. package/lib/yarn-per-branch-lock-installer.mjs +109 -0
  177. package/lib/yarn-reinstall.cjs +2 -2
  178. package/lib/yarn-reinstall.mjs +1 -1
  179. package/package.json +61 -52
  180. package/readme.html +784 -0
  181. package/readme.md +106 -218
  182. package/releases/readme.md +1 -1
  183. package/test/README.md +2 -2
  184. package/test-project/package.json +8 -2
  185. package/test-project/workspaces/workspace-a/package.json +135 -0
  186. package/test-project/workspaces/workspace-a/readme.md +20 -0
  187. package/test-project/workspaces/workspace-a/release/readme.md +42 -0
  188. package/test-project/workspaces/workspace-a/test/demo/package.json +25 -0
  189. package/test-project/workspaces/workspace-a/test/readme.md +12 -0
  190. package/test-project/workspaces/workspace-b/package.json +139 -0
  191. package/test-project/workspaces/workspace-b/readme.md +94 -0
  192. package/test-project/workspaces/workspace-b/requirements.txt +1 -0
  193. package/test-project/workspaces/workspace-b/test/sample-project/package.json +7 -0
  194. package/test-project/workspaces/workspace-b/themes/hexo-theme-flowbite/package.json +96 -0
  195. package/test-project/workspaces/workspace-b/themes/hexo-theme-flowbite/readme.md +156 -0
  196. package/tmp/rm-node-modules-test-project/package.json +17 -0
  197. package/tmp/rm-node-modules-test-project/packages/workspace-a/package.json +16 -0
  198. package/tmp/rm-node-modules-test-project/packages/workspace-b/package.json +16 -0
  199. package/tmp/test-repo/README.md +2 -35
  200. package/tmp/test-repo/package.json +13 -3
  201. package/docs-src/clean-github-actions-caches.md +0 -26
  202. package/docs-src/free-chatgpt.md +0 -26
  203. package/lib/binary-collections-config.cjs +0 -15
  204. package/lib/chunk-2CBJCW7E.mjs +0 -81
  205. package/lib/chunk-4UHL4WVN.mjs +0 -136
  206. package/lib/chunk-66PAU5PS.mjs +0 -31
  207. package/lib/chunk-6HHJRKFB.mjs +0 -59
  208. package/lib/chunk-7XTEJHOE.mjs +0 -193
  209. package/lib/chunk-FCDQGYBF.mjs +0 -136
  210. package/lib/chunk-GEYA2USY.mjs +0 -207
  211. package/lib/chunk-GJTGHXRA.mjs +0 -356
  212. package/lib/chunk-ID2WBTE2.mjs +0 -80
  213. package/lib/chunk-JXFOHKDM.mjs +0 -239
  214. package/lib/chunk-PDSXF5HY.mjs +0 -187
  215. package/lib/chunk-RWLXRTYP.mjs +0 -109
  216. package/lib/chunk-TOIVAQF7.mjs +0 -136
  217. package/lib/chunk-V5SKYJUB.mjs +0 -136
  218. package/lib/chunk-WSRETQCA.mjs +0 -59
  219. package/lib/chunk-YYLIQQKF.mjs +0 -31
  220. package/lib/ps/index.d.ts +0 -2
  221. package/lib/ps/index.js +0 -254
  222. package/lib/utils/findEnvFiles.d.ts +0 -8
  223. package/lib/utils/findEnvFiles.js +0 -121
  224. package/tmp/typedoc/readme.md +0 -320
  225. /package/lib/{binary-collections-config.d.cts → binary-collections/config.d.cts} +0 -0
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  var __getOwnPropNames = Object.getOwnPropertyNames;
3
2
  var __esm = (fn, res) => function __init() {
4
3
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
@@ -13,198 +12,172 @@ var init_cjs_shims = __esm({
13
12
  }
14
13
  });
15
14
 
16
- // src/utils/index.cjs
17
- var require_utils = __commonJS({
18
- "src/utils/index.cjs"(exports2, module2) {
15
+ // src/utils/findEnvFiles.cjs
16
+ var require_findEnvFiles = __commonJS({
17
+ "src/utils/findEnvFiles.cjs"(exports2, module2) {
19
18
  init_cjs_shims();
20
- var fs2 = require("fs");
21
- var path2 = require("upath");
22
- var argv = require("minimist")(process.argv.slice(2));
23
- var { exec } = require("child_process");
24
- var { URL: URL2 } = require("url");
25
- var { promisify } = require("util");
26
- var execAsync = promisify(exec);
27
- async function parseGitRemotes2() {
28
- try {
29
- const { stdout } = await execAsync("git remote -v");
30
- const lines = stdout.split("\n");
31
- const remotes = {};
32
- lines.forEach((line) => {
33
- const [name, url] = line.split(" ");
34
- if (name && url) {
35
- const [repoUrl] = url.split(" ");
36
- try {
37
- const parsedUrl = new URL2(repoUrl);
38
- const pathParts = parsedUrl.pathname.split("/").filter(Boolean);
39
- if (parsedUrl.hostname === "github.com" && pathParts.length === 2) {
40
- let repoPath = pathParts.join("/");
41
- if (repoPath.endsWith(".git")) {
42
- repoPath = repoPath.slice(0, -4);
43
- }
44
- remotes[name] = repoPath;
45
- }
46
- } catch (e) {
47
- console.error("URL Parsing Error:", e.message);
48
- }
49
- }
50
- });
51
- return remotes;
52
- } catch (error) {
53
- console.error("Error:", error.message);
54
- return {};
55
- }
56
- }
57
- module2.exports.parseGitRemotes = parseGitRemotes2;
58
- function joinPathPreserveDriveLetter(...segments) {
59
- let fullPath = require("path").join(...segments);
60
- if (/^[a-z]:\\/.test(fullPath)) {
61
- fullPath = fullPath.charAt(0).toUpperCase() + fullPath.slice(1);
62
- }
63
- return fullPath;
64
- }
65
- module2.exports.joinPathPreserveDriveLetter = joinPathPreserveDriveLetter;
66
- function getArgs() {
67
- return argv;
68
- }
69
- module2.exports.getArgs = getArgs;
70
- function del(fullPath) {
71
- try {
72
- if (!fs2.existsSync(fullPath)) return;
73
- const stat = fs2.lstatSync(fullPath);
74
- if (stat.isSymbolicLink()) {
75
- try {
76
- fs2.unlinkSync(fullPath);
77
- console.log("deleted symlink", fullPath);
78
- } catch (e) {
79
- console.log("failed delete symlink", fullPath, e && e.message);
80
- }
19
+ var fs = require("fs");
20
+ var path = require("path");
21
+ var glob = require("glob");
22
+ var DEFAULT_IGNORES = [
23
+ "**/node_modules/**",
24
+ "**/.git/**",
25
+ "**/.yarn/**",
26
+ "**/.pnpm/**",
27
+ "**/dist/**",
28
+ "**/build/**",
29
+ "**/coverage/**",
30
+ "**/vendor/**",
31
+ "**/tmp/**",
32
+ "**/.cache/**",
33
+ "**/assets/**",
34
+ "**/logs/**",
35
+ "**/output/**",
36
+ "**/public/**",
37
+ "**/static/**",
38
+ "**/temp/**",
39
+ "**/backup/**",
40
+ "**/backups/**",
41
+ "**/examples/**",
42
+ "**/docs/**",
43
+ "**/tests/**",
44
+ "**/__tests__/**",
45
+ "**/spec/**",
46
+ "**/__specs__/**",
47
+ "**/scripts/**",
48
+ "**/bin/**",
49
+ "**/hooks/**",
50
+ "**/config/**",
51
+ "**/configs/**",
52
+ "**/settings/**",
53
+ "**/.vscode/**",
54
+ "**/.idea/**"
55
+ ];
56
+ function findEnvFiles(startDir = process.cwd(), filter) {
57
+ const found = /* @__PURE__ */ new Set();
58
+ function addFile(file) {
59
+ const normalized = path.normalize(file);
60
+ if (typeof filter === "function" && !filter(normalized)) {
81
61
  return;
82
62
  }
83
- if (stat.isDirectory()) {
84
- const subdir = fs2.readdirSync(fullPath).map((dirPath) => path2.resolve(fullPath, dirPath));
85
- for (let i = 0; i < subdir.length; i++) {
86
- del(subdir[i]);
87
- }
88
- try {
89
- fs2.rmdirSync(fullPath);
90
- console.log("deleted", fullPath);
91
- } catch (e) {
92
- try {
93
- fs2.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
94
- console.log("deleted", fullPath);
95
- } catch (ee) {
96
- console.log("failed delete", fullPath, ee && ee.message);
97
- }
98
- }
99
- return;
63
+ found.add(normalized);
64
+ }
65
+ let current = path.resolve(startDir);
66
+ while (true) {
67
+ const envPath = path.join(current, ".env");
68
+ if (fs.existsSync(envPath)) {
69
+ addFile(envPath);
100
70
  }
101
- try {
102
- fs2.unlinkSync(fullPath);
103
- console.log("deleted", fullPath);
104
- } catch (e) {
105
- try {
106
- fs2.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
107
- console.log("deleted", fullPath);
108
- } catch (ee) {
109
- console.log("failed delete", fullPath, ee && ee.message);
110
- }
71
+ const parent = path.dirname(current);
72
+ if (parent === current) {
73
+ break;
111
74
  }
112
- } catch (err) {
113
- console.log("failed delete", fullPath, err && err.message);
75
+ current = parent;
76
+ }
77
+ const files = glob.globSync("**/.env*", {
78
+ cwd: startDir,
79
+ absolute: true,
80
+ nodir: true,
81
+ ignore: DEFAULT_IGNORES
82
+ });
83
+ for (const file of files) {
84
+ addFile(file);
114
85
  }
86
+ return [...found];
115
87
  }
116
- module2.exports.del = del;
117
- function delStream(globStream) {
118
- globStream.stream().on("data", (result) => {
119
- const fullPath = path2.resolve(process.cwd(), result);
88
+ function findEnvWithToken2(startDir = process.cwd(), tokenName = "GITHUB_TOKEN") {
89
+ const envFiles = findEnvFiles(startDir);
90
+ return envFiles.find((file) => {
120
91
  try {
121
- if (fs2.existsSync(fullPath)) {
122
- const stat = fs2.lstatSync(fullPath);
123
- if (stat.isSymbolicLink()) {
124
- try {
125
- fs2.unlinkSync(fullPath);
126
- console.log("deleted symlink", fullPath);
127
- } catch (e) {
128
- console.log("failed delete symlink", fullPath, e && e.message);
129
- }
130
- return;
131
- }
132
- if (stat.isDirectory()) {
133
- const subdir = fs2.readdirSync(fullPath).map((dirPath) => path2.resolve(fullPath, dirPath));
134
- for (let i = 0; i < subdir.length; i++) {
135
- del(subdir[i]);
136
- }
137
- }
138
- }
139
- del(fullPath);
92
+ const content = fs.readFileSync(file, "utf-8");
93
+ const regex = new RegExp(`^\\s*${tokenName}\\s*=`, "m");
94
+ return regex.test(content);
140
95
  } catch (err) {
141
- console.log("failed processing", fullPath, err && err.message);
96
+ console.warn(`Failed to read ${file}: ${err instanceof Error ? err.message : String(err)}`);
97
+ return false;
142
98
  }
143
99
  });
144
100
  }
145
- module2.exports.delStream = delStream;
146
- function getFileTreeString(hashArray) {
147
- const tree = {};
148
- const hashMap = {};
149
- for (const entry of hashArray) {
150
- const [filePath, hash] = entry.split(" ");
151
- hashMap[filePath] = hash;
152
- const parts = filePath.split("/");
153
- let current = tree;
154
- for (let i = 0; i < parts.length; i++) {
155
- const part = parts[i];
156
- if (i === parts.length - 1) {
157
- current[part] = null;
158
- } else {
159
- current[part] = current[part] || {};
160
- current = current[part];
161
- }
162
- }
163
- }
164
- function printNode(node, prefix = "", parentPath = "") {
165
- const keys = Object.keys(node).sort();
166
- let lines = [];
167
- keys.forEach((key, idx) => {
168
- const isLast = idx === keys.length - 1;
169
- const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
170
- const currentPath = parentPath ? parentPath + "/" + key : key;
171
- if (node[key] === null) {
172
- lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
173
- } else {
174
- lines.push(prefix + branch + key + "/");
175
- lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "\u2502 "), currentPath));
176
- }
177
- });
178
- return lines;
179
- }
180
- return printNode(tree, "", "").join("\n");
181
- }
182
- module2.exports.getFileTreeString = getFileTreeString;
183
- var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
184
- module2.exports.delay = delay;
101
+ module2.exports = {
102
+ DEFAULT_IGNORES,
103
+ findEnvFiles,
104
+ findEnvWithToken: findEnvWithToken2,
105
+ default: findEnvFiles
106
+ };
185
107
  }
186
108
  });
187
109
 
188
110
  // src/clean-github-actions-caches.cjs
189
111
  init_cjs_shims();
190
112
  var axios = require("axios");
191
- var { parseGitRemotes } = require_utils();
192
- var path = require("upath");
193
- var fs = require("fs");
194
- var projectDir = process.cwd();
195
- var envPath = path.join(projectDir, ".env");
196
- if (fs.existsSync(envPath)) {
197
- require("dotenv").config({ path: envPath, quiet: true });
198
- } else {
199
- console.warn(`.env file not found at ${envPath}`);
200
- }
201
- require("dotenv").config({ path: path.join(process.cwd(), ".env"), quiet: true });
113
+ var minimist = require("minimist");
114
+ var { findEnvWithToken } = require_findEnvFiles();
115
+ require("dotenv").config({
116
+ path: findEnvWithToken(),
117
+ quiet: true,
118
+ overwrite: true
119
+ });
202
120
  var ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
203
121
  if (!ACCESS_TOKEN) {
204
122
  throw new Error(
205
123
  "Access token is not provided. Please set ACCESS_TOKEN or GITHUB_TOKEN in your environment variables."
206
124
  );
207
125
  }
126
+ function printHelp() {
127
+ console.log(`
128
+ GitHub Actions Cache Cleaner
129
+
130
+ Description:
131
+ Removes outdated GitHub Actions caches for a repository, keeping only the newest
132
+ cache for each cache-key prefix. Authenticates via ACCESS_TOKEN or GITHUB_TOKEN
133
+ from your environment or .env file.
134
+
135
+ Usage:
136
+ clean-github-actions-caches [options]
137
+
138
+ Options:
139
+ -h, --help Show this help message
140
+ -r, --repo <repo> GitHub repository (owner/repo). If omitted, the tool will
141
+ attempt to infer the repository from the current working
142
+ directory's git remotes.
143
+
144
+ Environment Variables:
145
+ ACCESS_TOKEN GitHub access token (preferred)
146
+ GITHUB_TOKEN GitHub access token (fallback)
147
+
148
+ Behavior & Safety:
149
+ - Groups caches by a derived prefix from the cache key and keeps the most
150
+ recently created cache for each group.
151
+ - Deletes only caches older than the latest per prefix to reduce risk of
152
+ removing needed artifacts.
153
+
154
+ Examples:
155
+ # Run against a specific repo (owner/repo)
156
+ clean-github-actions-caches --repo octocat/hello-world
157
+
158
+ # Run via npx without installing
159
+ npx -y binary-collections@https://raw.githubusercontent.com/dimaslanjaka/bin/master/releases/bin.tgz clean-github-actions-caches --repo owner/repo
160
+
161
+ # Run via yarn dlx
162
+ yarn dlx binary-collections@https://raw.githubusercontent.com/dimaslanjaka/bin/master/releases/bin.tgz clean-github-actions-caches
163
+
164
+ Notes:
165
+ - Ensure ACCESS_TOKEN or GITHUB_TOKEN is set and has permissions to manage Actions caches.
166
+ - Intended for repository maintainers with appropriate permissions.
167
+ `);
168
+ }
169
+ var argv = minimist(process.argv.slice(2), {
170
+ alias: {
171
+ h: "help",
172
+ r: "repo"
173
+ },
174
+ string: ["repo"],
175
+ boolean: ["help"]
176
+ });
177
+ if (argv.help) {
178
+ printHelp();
179
+ process.exit(0);
180
+ }
208
181
  function deleteGitHubActionsCache(GH_REPO, cacheId) {
209
182
  return new Promise((resolve, reject) => {
210
183
  const url = `https://api.github.com/repos/${GH_REPO}/actions/caches/${cacheId}`;
@@ -239,9 +212,10 @@ function get_caches(GH_REPO) {
239
212
  const data = response.data.actions_caches;
240
213
  const getPrefix = (key) => {
241
214
  const split = key.split(/[-_]/);
242
- if (split.length == 3) {
215
+ if (split.length === 3) {
243
216
  return `${split[0]}-${split[1]}`;
244
- } else if (split.length > 3) {
217
+ }
218
+ if (split.length > 3) {
245
219
  return `${split[0]}-${split[1]}-${split[2]}`;
246
220
  }
247
221
  return split[0];
@@ -269,37 +243,7 @@ function get_caches(GH_REPO) {
269
243
  });
270
244
  });
271
245
  }
272
- (async () => {
273
- try {
274
- const remotes = await parseGitRemotes();
275
- const GH_REPO = remotes.origin;
276
- const caches = await get_caches(GH_REPO);
277
- for (const key in caches) {
278
- if (Object.hasOwnProperty.call(caches, key)) {
279
- const items = caches[key].sort((a, b) => new Date(b.created_at) - new Date(a.created_at)).map((item) => ({
280
- ...item,
281
- human_readable_date: new Date(item.created_at).toLocaleString()
282
- }));
283
- if (items.length > 1) {
284
- const ids = items.map((o) => o.id);
285
- ids.shift();
286
- if (ids.length > 0) {
287
- for (const id of ids) {
288
- try {
289
- await deleteGitHubActionsCache(GH_REPO, id);
290
- } catch (err) {
291
- console.error(`Error deleting cache ${id}:`, err);
292
- }
293
- }
294
- } else {
295
- console.log(`cache prefix ${key} no cache left`);
296
- }
297
- } else {
298
- console.log(`cache prefix ${key} only have 1 cache`);
299
- }
300
- }
301
- }
302
- } catch (e) {
303
- console.error(`Error: ${e}`);
304
- }
305
- })();
246
+ module.exports = {
247
+ deleteGitHubActionsCache,
248
+ get_caches
249
+ };
@@ -1 +1,15 @@
1
- export {};
1
+ /**
2
+ * Deletes a GitHub Actions cache.
3
+ *
4
+ * @param {string} GH_REPO - The GitHub repository in the format "owner/repo".
5
+ * @param {string|number} cacheId - The ID of the cache to delete.
6
+ * @returns {Promise<any>} Promise resolving with GitHub API response.
7
+ */
8
+ export function deleteGitHubActionsCache(GH_REPO: string, cacheId: string | number): Promise<any>;
9
+ /**
10
+ * List GitHub Actions caches grouped by cache key prefix.
11
+ *
12
+ * @param {string} GH_REPO GitHub repository in format `owner/repo`.
13
+ * @returns {Promise<Record<string, Record<string, any>[]>>}
14
+ */
15
+ export function get_caches(GH_REPO: string): Promise<Record<string, Record<string, any>[]>>;
@@ -1,133 +1,7 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
2
  import {
3
- require_utils
4
- } from "./chunk-Z6JLYU2J.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"() {
14
- init_esm_shims();
15
- var axios = __require("axios");
16
- var { parseGitRemotes } = require_utils();
17
- var path = __require("upath");
18
- var fs = __require("fs");
19
- var projectDir = process.cwd();
20
- var envPath = path.join(projectDir, ".env");
21
- if (fs.existsSync(envPath)) {
22
- __require("dotenv").config({ path: envPath, quiet: true });
23
- } else {
24
- console.warn(`.env file not found at ${envPath}`);
25
- }
26
- __require("dotenv").config({ path: path.join(process.cwd(), ".env"), quiet: true });
27
- var ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
28
- if (!ACCESS_TOKEN) {
29
- throw new Error(
30
- "Access token is not provided. Please set ACCESS_TOKEN or GITHUB_TOKEN in your environment variables."
31
- );
32
- }
33
- function deleteGitHubActionsCache(GH_REPO, cacheId) {
34
- return new Promise((resolve, reject) => {
35
- const url = `https://api.github.com/repos/${GH_REPO}/actions/caches/${cacheId}`;
36
- const token = ACCESS_TOKEN;
37
- if (!token) {
38
- return reject(new Error("Access token is not provided"));
39
- }
40
- axios.delete(url, {
41
- headers: {
42
- Authorization: `token ${token}`,
43
- Accept: "application/vnd.github.v3+json"
44
- }
45
- }).then((response) => {
46
- console.log(`Cache (${cacheId}) deleted successfully`, response.data);
47
- resolve(response.data);
48
- }).catch((error) => {
49
- var _a;
50
- console.error("Error deleting cache:", ((_a = error.response) == null ? void 0 : _a.data) || error.message || "Unknown error");
51
- reject(error);
52
- });
53
- });
54
- }
55
- function get_caches(GH_REPO) {
56
- const url = `https://api.github.com/repos/${GH_REPO}/actions/caches`;
57
- return new Promise((resolve, reject) => {
58
- axios.get(url, {
59
- headers: {
60
- Accept: "application/vnd.github.v3+json",
61
- Authorization: `token ${ACCESS_TOKEN}`
62
- }
63
- }).then((response) => {
64
- const data = response.data.actions_caches;
65
- const getPrefix = (key) => {
66
- const split = key.split(/[-_]/);
67
- if (split.length == 3) {
68
- return `${split[0]}-${split[1]}`;
69
- } else if (split.length > 3) {
70
- return `${split[0]}-${split[1]}-${split[2]}`;
71
- }
72
- return split[0];
73
- };
74
- const grouped = data.reduce(
75
- /**
76
- * @param {Record<string, Record<string, any>[]>} acc
77
- * @param {Record<string, any>} item
78
- * @returns {Record<string, Record<string, any>[]>}
79
- */
80
- (acc, item) => {
81
- const prefix = getPrefix(item.key);
82
- if (!acc[prefix]) {
83
- acc[prefix] = [];
84
- }
85
- acc[prefix].push(item);
86
- return acc;
87
- },
88
- {}
89
- );
90
- resolve(grouped);
91
- }).catch((error) => {
92
- console.error("Error fetching data:", error);
93
- reject(error);
94
- });
95
- });
96
- }
97
- (async () => {
98
- try {
99
- const remotes = await parseGitRemotes();
100
- const GH_REPO = remotes.origin;
101
- const caches = await get_caches(GH_REPO);
102
- for (const key in caches) {
103
- if (Object.hasOwnProperty.call(caches, key)) {
104
- const items = caches[key].sort((a, b) => new Date(b.created_at) - new Date(a.created_at)).map((item) => ({
105
- ...item,
106
- human_readable_date: new Date(item.created_at).toLocaleString()
107
- }));
108
- if (items.length > 1) {
109
- const ids = items.map((o) => o.id);
110
- ids.shift();
111
- if (ids.length > 0) {
112
- for (const id of ids) {
113
- try {
114
- await deleteGitHubActionsCache(GH_REPO, id);
115
- } catch (err) {
116
- console.error(`Error deleting cache ${id}:`, err);
117
- }
118
- }
119
- } else {
120
- console.log(`cache prefix ${key} no cache left`);
121
- }
122
- } else {
123
- console.log(`cache prefix ${key} only have 1 cache`);
124
- }
125
- }
126
- }
127
- } catch (e) {
128
- console.error(`Error: ${e}`);
129
- }
130
- })();
131
- }
132
- });
3
+ require_clean_github_actions_caches
4
+ } from "./chunk-FB2WKVJD.mjs";
5
+ import "./chunk-H44UWUFY.mjs";
6
+ import "./chunk-QQ4A6DLD.mjs";
133
7
  export default require_clean_github_actions_caches();
@@ -0,0 +1,63 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/cross-env/command.ts
30
+ var command_exports = {};
31
+ __export(command_exports, {
32
+ commandConvert: () => commandConvert
33
+ });
34
+ module.exports = __toCommonJS(command_exports);
35
+ var import_path = __toESM(require("path"), 1);
36
+
37
+ // src/utils/isWindows.js
38
+ function isWindows() {
39
+ return process.platform === "win32" || /^(msys|cygwin)$/.test(process.env.OSTYPE || "");
40
+ }
41
+
42
+ // src/cross-env/command.ts
43
+ function commandConvert(command, env, normalize = false) {
44
+ if (!isWindows()) {
45
+ return command;
46
+ }
47
+ const simpleEnvRegex = /\$(\w+)|\${(\w+)}/g;
48
+ const defaultValueRegex = /\$\{(\w+):-([^}]+)\}/g;
49
+ let convertedCmd = command;
50
+ convertedCmd = convertedCmd.replace(defaultValueRegex, (match, varName, defaultValue) => {
51
+ const value = env[varName] || defaultValue;
52
+ return value;
53
+ });
54
+ convertedCmd = convertedCmd.replace(simpleEnvRegex, (match, $1, $2) => {
55
+ const varName = $1 || $2;
56
+ return env[varName] ? `%${varName}%` : "";
57
+ });
58
+ return normalize === true ? import_path.default.normalize(convertedCmd) : convertedCmd;
59
+ }
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ commandConvert
63
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts an environment variable usage to be appropriate for the current OS
3
+ * @param command Command to convert
4
+ * @param env Map of the current environment variable names and their values
5
+ * @param normalize If the command should be normalized using `path` after converting
6
+ * @returns Converted command
7
+ */
8
+ export declare function commandConvert(command: string, env: NodeJS.ProcessEnv, normalize?: boolean): string;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.commandConvert = commandConvert;
7
+ const path_1 = __importDefault(require("path"));
8
+ const isWindows_js_1 = require("../utils/isWindows.js");
9
+ /**
10
+ * Converts an environment variable usage to be appropriate for the current OS
11
+ * @param command Command to convert
12
+ * @param env Map of the current environment variable names and their values
13
+ * @param normalize If the command should be normalized using `path` after converting
14
+ * @returns Converted command
15
+ */
16
+ function commandConvert(command, env, normalize = false) {
17
+ if (!(0, isWindows_js_1.isWindows)()) {
18
+ return command;
19
+ }
20
+ // Handle simple variables: $var or ${var}
21
+ const simpleEnvRegex = /\$(\w+)|\${(\w+)}/g;
22
+ // Handle bash parameter expansion with default values: ${var:-default}
23
+ const defaultValueRegex = /\$\{(\w+):-([^}]+)\}/g;
24
+ let convertedCmd = command;
25
+ // First, handle bash parameter expansion with default values
26
+ convertedCmd = convertedCmd.replace(defaultValueRegex, (match, varName, defaultValue) => {
27
+ // If the variable exists, use its value; otherwise use the default
28
+ const value = env[varName] || defaultValue;
29
+ return value;
30
+ });
31
+ // Then handle simple variable references
32
+ convertedCmd = convertedCmd.replace(simpleEnvRegex, (match, $1, $2) => {
33
+ const varName = $1 || $2;
34
+ // In Windows, non-existent variables are not replaced by the shell,
35
+ // so for example "echo %FOO%" will literally print the string "%FOO%", as
36
+ // opposed to printing an empty string in UNIX. See kentcdodds/cross-env#145
37
+ // If the env variable isn't defined at runtime, just strip it from the command entirely
38
+ return env[varName] ? `%${varName}%` : '';
39
+ });
40
+ // Normalization is required for commands with relative paths
41
+ // For example, `./cmd.bat`. See kentcdodds/cross-env#127
42
+ // However, it should not be done for command arguments.
43
+ // See https://github.com/kentcdodds/cross-env/pull/130#issuecomment-319887970
44
+ return normalize === true ? path_1.default.normalize(convertedCmd) : convertedCmd;
45
+ }