binary-collections 2.0.10 → 2.0.11

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 (165) hide show
  1. package/.puppeterrc.cjs +25 -0
  2. package/binaries/binary-executor.cjs +138 -3
  3. package/binaries/clean-nodemodule.cjs +138 -3
  4. package/binaries/clean-nodemodules.cjs +138 -3
  5. package/binaries/dev.cjs +138 -3
  6. package/binaries/empty.cjs +138 -3
  7. package/binaries/git-reduce-size.cjs +138 -3
  8. package/binaries/javakill.cjs +138 -3
  9. package/binaries/kill-night-crows.bat +7 -0
  10. package/binaries/kill-night-crows.ps1 +172 -0
  11. package/binaries/kill-process.cjs +138 -3
  12. package/binaries/nodekill.cjs +138 -3
  13. package/binaries/prod.cjs +138 -3
  14. package/binaries/py +111 -0
  15. package/binaries/py.cjs +178 -0
  16. package/binaries/py.cmd +49 -0
  17. package/binaries/rmfind.cjs +138 -3
  18. package/binaries/rmx.cjs +138 -3
  19. package/binaries/submodule-token.cjs +138 -3
  20. package/binaries/test-cjs +10 -0
  21. package/binaries/test-cjs.cjs +178 -0
  22. package/binaries/test-cjs.cmd +11 -0
  23. package/binaries/yarn-clean +32 -0
  24. package/binaries/yarn-clean.cjs +178 -0
  25. package/binaries/yarn-clean.cmd +30 -0
  26. package/binaries/yarn-clean.py +148 -0
  27. package/lib/binary-collections-config.cjs +1 -1
  28. package/lib/binary-collections-config.mjs +1 -1
  29. package/lib/binary-collections.cjs +167 -106
  30. package/lib/binary-collections.mjs +108 -94
  31. package/lib/changelog.cjs +61 -13
  32. package/lib/changelog.mjs +1 -1
  33. package/lib/{chunk-AI4CVPJ7.mjs → chunk-2CBJCW7E.mjs} +4 -4
  34. package/lib/chunk-34IQDTLZ.mjs +27 -0
  35. package/lib/chunk-3HFFECCI.mjs +27 -0
  36. package/lib/{chunk-SBNDSKG5.mjs → chunk-4UHL4WVN.mjs} +1 -1
  37. package/lib/chunk-7XTEJHOE.mjs +193 -0
  38. package/lib/chunk-AJDD5DZM.mjs +109 -0
  39. package/lib/chunk-BZWVHODJ.mjs +62 -0
  40. package/lib/{chunk-BEZKJ25G.mjs → chunk-FCDQGYBF.mjs} +5 -9
  41. package/lib/chunk-GEYA2USY.mjs +207 -0
  42. package/lib/chunk-ID2WBTE2.mjs +80 -0
  43. package/lib/chunk-JXFOHKDM.mjs +239 -0
  44. package/lib/{chunk-DI5MDPSN.mjs → chunk-N436BNBK.mjs} +192 -64
  45. package/lib/chunk-NCXAP7AA.mjs +31 -0
  46. package/lib/chunk-PDN26I7O.mjs +188 -0
  47. package/lib/{chunk-E6FDDAOO.mjs → chunk-RWLXRTYP.mjs} +1 -1
  48. package/lib/{chunk-BDCHCWHD.mjs → chunk-TOIVAQF7.mjs} +4 -4
  49. package/lib/chunk-V5SKYJUB.mjs +136 -0
  50. package/lib/{chunk-HMRMTYZM.mjs → chunk-WSRETQCA.mjs} +21 -2
  51. package/lib/chunk-XA3SNBPA.mjs +184 -0
  52. package/lib/chunk-YYLIQQKF.mjs +31 -0
  53. package/lib/{chunk-V3N3JEUF.mjs → chunk-Z6JLYU2J.mjs} +60 -13
  54. package/lib/{chunk-O6SWBEOQ.mjs → chunk-ZDMWBSYF.mjs} +2 -2
  55. package/lib/clean-github-actions-caches.cjs +63 -15
  56. package/lib/clean-github-actions-caches.mjs +3 -3
  57. package/lib/del-gradle.cjs +61 -13
  58. package/lib/del-gradle.js +1 -0
  59. package/lib/del-gradle.mjs +1 -1
  60. package/lib/del-node-modules.cjs +143 -148
  61. package/lib/del-node-modules.js +210 -14
  62. package/lib/del-node-modules.mjs +148 -17
  63. package/lib/del-ps.cjs +61 -13
  64. package/lib/del-ps.js +1 -0
  65. package/lib/del-ps.mjs +1 -1
  66. package/lib/del-yarn-caches.cjs +61 -13
  67. package/lib/del-yarn-caches.mjs +1 -1
  68. package/lib/find-node-modules-cli.js +1 -0
  69. package/lib/free-chatgpt.cjs +253 -47
  70. package/lib/free-chatgpt.mjs +2 -2
  71. package/lib/git/gitattributes.cjs +1 -0
  72. package/lib/git/gitattributes.d.cts +7 -2
  73. package/lib/git/gitattributes.mjs +1 -1
  74. package/lib/git/line-endings.cjs +2 -1
  75. package/lib/git/line-endings.mjs +2 -2
  76. package/lib/git/undo-commit-cli.cjs +110 -0
  77. package/lib/git/undo-commit-cli.d.ts +1 -0
  78. package/lib/git/undo-commit-cli.js +4 -0
  79. package/lib/git/undo-commit-cli.mjs +14 -0
  80. package/lib/git/undo-commit.cjs +81 -0
  81. package/lib/git/undo-commit.d.cts +1 -0
  82. package/lib/git/undo-commit.mjs +7 -0
  83. package/lib/git/undo-staged-cli.cjs +110 -0
  84. package/lib/git/undo-staged-cli.d.ts +1 -0
  85. package/lib/git/undo-staged-cli.js +4 -0
  86. package/lib/git/undo-staged-cli.mjs +14 -0
  87. package/lib/git/undo-staged.cjs +81 -0
  88. package/lib/git/undo-staged.d.cts +1 -0
  89. package/lib/git/undo-staged.mjs +7 -0
  90. package/lib/git/user-config.cjs +61 -14
  91. package/lib/git/user-config.mjs +2 -2
  92. package/lib/git-diff-cli.cjs +255 -49
  93. package/lib/git-diff-cli.d.ts +1 -0
  94. package/lib/git-diff-cli.js +1 -0
  95. package/lib/git-diff-cli.mjs +5 -4
  96. package/lib/git-diff.cjs +254 -49
  97. package/lib/git-diff.mjs +4 -4
  98. package/lib/git-fix.cjs +64 -16
  99. package/lib/git-fix.mjs +10 -10
  100. package/lib/git-purge.cjs +61 -13
  101. package/lib/git-purge.mjs +1 -1
  102. package/lib/kill-night-crows.cjs +87 -0
  103. package/lib/kill-night-crows.d.mts +1 -0
  104. package/lib/kill-night-crows.mjs +65 -0
  105. package/lib/npm-run-series.cjs +60 -13
  106. package/lib/npm-run-series.mjs +1 -1
  107. package/lib/package-resolutions-updater-cli.cjs +560 -0
  108. package/lib/package-resolutions-updater-cli.d.mts +1 -0
  109. package/lib/package-resolutions-updater-cli.mjs +124 -0
  110. package/lib/package-resolutions-updater.cjs +174 -154
  111. package/lib/package-resolutions-updater.d.mts +32 -1
  112. package/lib/package-resolutions-updater.mjs +16 -294
  113. package/lib/php-cs-fixer-staged.cjs +105 -0
  114. package/lib/php-cs-fixer-staged.d.cts +2 -0
  115. package/lib/php-cs-fixer-staged.mjs +117 -0
  116. package/lib/print-directory-tree.cjs +62 -14
  117. package/lib/print-directory-tree.mjs +2 -2
  118. package/lib/ps/connected-domain.d.ts +1 -1
  119. package/lib/ps/index.js +1 -0
  120. package/lib/remove-module.cjs +61 -13
  121. package/lib/remove-module.mjs +1 -1
  122. package/lib/rmpath.cjs +63 -15
  123. package/lib/rmpath.mjs +2 -2
  124. package/lib/submodule-install.cjs +62 -15
  125. package/lib/submodule-install.mjs +3 -3
  126. package/lib/submodule-remove-cli.cjs +5 -1
  127. package/lib/submodule-remove-cli.mjs +1 -1
  128. package/lib/submodule-remove.cjs +4 -1
  129. package/lib/submodule-remove.mjs +1 -1
  130. package/lib/utils/chatgpt.cjs +192 -34
  131. package/lib/utils/chatgpt.js +210 -43
  132. package/lib/utils/chatgpt.mjs +1 -1
  133. package/lib/utils/findEnvFiles.cjs +107 -0
  134. package/lib/utils/findEnvFiles.d.ts +8 -0
  135. package/lib/utils/findEnvFiles.js +121 -0
  136. package/lib/utils/findEnvFiles.mjs +8 -0
  137. package/lib/utils/findWorkspaceRoot.cjs +70 -0
  138. package/lib/utils/findWorkspaceRoot.d.ts +9 -0
  139. package/lib/utils/findWorkspaceRoot.js +57 -0
  140. package/lib/utils/findWorkspaceRoot.mjs +40 -0
  141. package/lib/utils/index.cjs +60 -13
  142. package/lib/utils/index.mjs +1 -1
  143. package/lib/utils/isGithubTokenValid.cjs +64 -0
  144. package/lib/utils/isGithubTokenValid.d.ts +7 -0
  145. package/lib/utils/isGithubTokenValid.js +48 -0
  146. package/lib/utils/isGithubTokenValid.mjs +36 -0
  147. package/lib/yarn-reinstall.cjs +61 -13
  148. package/lib/yarn-reinstall.mjs +1 -1
  149. package/package.json +107 -93
  150. package/readme.md +33 -34
  151. package/releases/readme.md +1 -1
  152. package/requirements.txt +1 -0
  153. package/lib/chunk-4EWQC6GZ.mjs +0 -382
  154. package/lib/chunk-4ZI7BQKQ.mjs +0 -381
  155. package/lib/chunk-5J2BEPY5.mjs +0 -83
  156. package/lib/chunk-AGZYRDC2.mjs +0 -323
  157. package/lib/chunk-HN52G2YL.mjs +0 -305
  158. package/lib/chunk-HO6GHCOB.mjs +0 -385
  159. package/lib/chunk-LEM5OMRP.mjs +0 -384
  160. package/lib/chunk-RCP7DHVY.mjs +0 -190
  161. package/lib/chunk-U6SO4QEV.mjs +0 -320
  162. package/lib/chunk-XD6BJK6Q.mjs +0 -351
  163. package/lib/chunk-YXSFGA2D.mjs +0 -383
  164. package/lib/git/gitattributes.d.ts +0 -33
  165. package/lib/git/gitattributes.js +0 -223
@@ -0,0 +1,560 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+
31
+ // node_modules/tsup/assets/cjs_shims.js
32
+ var init_cjs_shims = __esm({
33
+ "node_modules/tsup/assets/cjs_shims.js"() {
34
+ }
35
+ });
36
+
37
+ // src/utils/index.cjs
38
+ var require_utils = __commonJS({
39
+ "src/utils/index.cjs"(exports2, module2) {
40
+ init_cjs_shims();
41
+ var fs4 = require("fs");
42
+ var path4 = require("upath");
43
+ var argv = require("minimist")(process.argv.slice(2));
44
+ var { exec } = require("child_process");
45
+ var { URL: URL2 } = require("url");
46
+ var { promisify } = require("util");
47
+ var execAsync = promisify(exec);
48
+ async function parseGitRemotes() {
49
+ try {
50
+ const { stdout } = await execAsync("git remote -v");
51
+ const lines = stdout.split("\n");
52
+ const remotes = {};
53
+ lines.forEach((line) => {
54
+ const [name, url] = line.split(" ");
55
+ if (name && url) {
56
+ const [repoUrl] = url.split(" ");
57
+ try {
58
+ const parsedUrl = new URL2(repoUrl);
59
+ const pathParts = parsedUrl.pathname.split("/").filter(Boolean);
60
+ if (parsedUrl.hostname === "github.com" && pathParts.length === 2) {
61
+ let repoPath = pathParts.join("/");
62
+ if (repoPath.endsWith(".git")) {
63
+ repoPath = repoPath.slice(0, -4);
64
+ }
65
+ remotes[name] = repoPath;
66
+ }
67
+ } catch (e) {
68
+ console.error("URL Parsing Error:", e.message);
69
+ }
70
+ }
71
+ });
72
+ return remotes;
73
+ } catch (error) {
74
+ console.error("Error:", error.message);
75
+ return {};
76
+ }
77
+ }
78
+ module2.exports.parseGitRemotes = parseGitRemotes;
79
+ function joinPathPreserveDriveLetter(...segments) {
80
+ let fullPath = require("path").join(...segments);
81
+ if (/^[a-z]:\\/.test(fullPath)) {
82
+ fullPath = fullPath.charAt(0).toUpperCase() + fullPath.slice(1);
83
+ }
84
+ return fullPath;
85
+ }
86
+ module2.exports.joinPathPreserveDriveLetter = joinPathPreserveDriveLetter;
87
+ function getArgs2() {
88
+ return argv;
89
+ }
90
+ module2.exports.getArgs = getArgs2;
91
+ function del(fullPath) {
92
+ try {
93
+ if (!fs4.existsSync(fullPath)) return;
94
+ const stat = fs4.lstatSync(fullPath);
95
+ if (stat.isSymbolicLink()) {
96
+ try {
97
+ fs4.unlinkSync(fullPath);
98
+ console.log("deleted symlink", fullPath);
99
+ } catch (e) {
100
+ console.log("failed delete symlink", fullPath, e && e.message);
101
+ }
102
+ return;
103
+ }
104
+ if (stat.isDirectory()) {
105
+ const subdir = fs4.readdirSync(fullPath).map((dirPath) => path4.resolve(fullPath, dirPath));
106
+ for (let i = 0; i < subdir.length; i++) {
107
+ del(subdir[i]);
108
+ }
109
+ try {
110
+ fs4.rmdirSync(fullPath);
111
+ console.log("deleted", fullPath);
112
+ } catch (e) {
113
+ try {
114
+ fs4.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
115
+ console.log("deleted", fullPath);
116
+ } catch (ee) {
117
+ console.log("failed delete", fullPath, ee && ee.message);
118
+ }
119
+ }
120
+ return;
121
+ }
122
+ try {
123
+ fs4.unlinkSync(fullPath);
124
+ console.log("deleted", fullPath);
125
+ } catch (e) {
126
+ try {
127
+ fs4.rmSync(fullPath, { recursive: true, force: true, retryDelay: 7e3 });
128
+ console.log("deleted", fullPath);
129
+ } catch (ee) {
130
+ console.log("failed delete", fullPath, ee && ee.message);
131
+ }
132
+ }
133
+ } catch (err) {
134
+ console.log("failed delete", fullPath, err && err.message);
135
+ }
136
+ }
137
+ module2.exports.del = del;
138
+ function delStream(globStream) {
139
+ globStream.stream().on("data", (result) => {
140
+ const fullPath = path4.resolve(process.cwd(), result);
141
+ try {
142
+ if (fs4.existsSync(fullPath)) {
143
+ const stat = fs4.lstatSync(fullPath);
144
+ if (stat.isSymbolicLink()) {
145
+ try {
146
+ fs4.unlinkSync(fullPath);
147
+ console.log("deleted symlink", fullPath);
148
+ } catch (e) {
149
+ console.log("failed delete symlink", fullPath, e && e.message);
150
+ }
151
+ return;
152
+ }
153
+ if (stat.isDirectory()) {
154
+ const subdir = fs4.readdirSync(fullPath).map((dirPath) => path4.resolve(fullPath, dirPath));
155
+ for (let i = 0; i < subdir.length; i++) {
156
+ del(subdir[i]);
157
+ }
158
+ }
159
+ }
160
+ del(fullPath);
161
+ } catch (err) {
162
+ console.log("failed processing", fullPath, err && err.message);
163
+ }
164
+ });
165
+ }
166
+ module2.exports.delStream = delStream;
167
+ function getFileTreeString(hashArray) {
168
+ const tree = {};
169
+ const hashMap = {};
170
+ for (const entry of hashArray) {
171
+ const [filePath, hash] = entry.split(" ");
172
+ hashMap[filePath] = hash;
173
+ const parts = filePath.split("/");
174
+ let current = tree;
175
+ for (let i = 0; i < parts.length; i++) {
176
+ const part = parts[i];
177
+ if (i === parts.length - 1) {
178
+ current[part] = null;
179
+ } else {
180
+ current[part] = current[part] || {};
181
+ current = current[part];
182
+ }
183
+ }
184
+ }
185
+ function printNode(node, prefix = "", parentPath = "") {
186
+ const keys = Object.keys(node).sort();
187
+ let lines = [];
188
+ keys.forEach((key, idx) => {
189
+ const isLast = idx === keys.length - 1;
190
+ const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
191
+ const currentPath = parentPath ? parentPath + "/" + key : key;
192
+ if (node[key] === null) {
193
+ lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
194
+ } else {
195
+ lines.push(prefix + branch + key + "/");
196
+ lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "\u2502 "), currentPath));
197
+ }
198
+ });
199
+ return lines;
200
+ }
201
+ return printNode(tree, "", "").join("\n");
202
+ }
203
+ module2.exports.getFileTreeString = getFileTreeString;
204
+ var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
205
+ module2.exports.delay = delay;
206
+ }
207
+ });
208
+
209
+ // src/package-resolutions-updater-cli.mjs
210
+ init_cjs_shims();
211
+ var import_ansi_colors = __toESM(require("ansi-colors"), 1);
212
+ var import_fs2 = __toESM(require("fs"), 1);
213
+ var import_path2 = __toESM(require("path"), 1);
214
+
215
+ // src/package-resolutions-updater.mjs
216
+ init_cjs_shims();
217
+ var dotenv = __toESM(require("dotenv"), 1);
218
+ var import_fs = __toESM(require("fs"), 1);
219
+ var import_https = __toESM(require("https"), 1);
220
+ var import_os = __toESM(require("os"), 1);
221
+ var import_path = __toESM(require("path"), 1);
222
+ var utils = __toESM(require_utils(), 1);
223
+
224
+ // src/utils/findEnvFiles.js
225
+ init_cjs_shims();
226
+ var import_node_fs = __toESM(require("fs"), 1);
227
+ var import_node_path = __toESM(require("path"), 1);
228
+ var glob = __toESM(require("glob"), 1);
229
+ var DEFAULT_IGNORES = [
230
+ "**/node_modules/**",
231
+ "**/.git/**",
232
+ "**/.yarn/**",
233
+ "**/.pnpm/**",
234
+ "**/dist/**",
235
+ "**/build/**",
236
+ "**/coverage/**",
237
+ "**/vendor/**",
238
+ "**/tmp/**",
239
+ "**/.cache/**",
240
+ "**/assets/**",
241
+ "**/logs/**",
242
+ "**/output/**",
243
+ "**/public/**",
244
+ "**/static/**",
245
+ "**/temp/**",
246
+ "**/backup/**",
247
+ "**/backups/**",
248
+ "**/examples/**",
249
+ "**/docs/**",
250
+ "**/tests/**",
251
+ "**/__tests__/**",
252
+ "**/spec/**",
253
+ "**/__specs__/**",
254
+ "**/scripts/**",
255
+ "**/bin/**",
256
+ "**/hooks/**",
257
+ "**/config/**",
258
+ "**/configs/**",
259
+ "**/settings/**",
260
+ "**/.vscode/**",
261
+ "**/.idea/**"
262
+ ];
263
+ function findEnvFiles(startDir = process.cwd(), filter) {
264
+ const found = /* @__PURE__ */ new Set();
265
+ function addFile(file) {
266
+ const normalized = import_node_path.default.normalize(file);
267
+ if (typeof filter === "function" && !filter(normalized)) {
268
+ return;
269
+ }
270
+ found.add(normalized);
271
+ }
272
+ let current = import_node_path.default.resolve(startDir);
273
+ while (true) {
274
+ const envPath2 = import_node_path.default.join(current, ".env");
275
+ if (import_node_fs.default.existsSync(envPath2)) {
276
+ addFile(envPath2);
277
+ }
278
+ const parent = import_node_path.default.dirname(current);
279
+ if (parent === current) {
280
+ break;
281
+ }
282
+ current = parent;
283
+ }
284
+ const files = glob.globSync("**/.env*", {
285
+ cwd: startDir,
286
+ absolute: true,
287
+ nodir: true,
288
+ ignore: DEFAULT_IGNORES
289
+ });
290
+ for (const file of files) {
291
+ addFile(file);
292
+ }
293
+ return [...found];
294
+ }
295
+
296
+ // src/package-resolutions-updater.mjs
297
+ var import_git_command_helper = require("git-command-helper");
298
+ var projectDir = process.cwd();
299
+ var envPath = import_path.default.join(projectDir, ".env");
300
+ var args = utils.getArgs();
301
+ if (!import_fs.default.existsSync(envPath)) {
302
+ const envFiles = findEnvFiles(projectDir, (file) => {
303
+ const content = import_fs.default.readFileSync(file, "utf-8");
304
+ return /GITHUB_TOKEN|ACCESS_TOKEN/.test(content);
305
+ });
306
+ if (envFiles.length > 0) {
307
+ envPath = envFiles[0];
308
+ }
309
+ }
310
+ if (import_fs.default.existsSync(envPath)) {
311
+ dotenv.config({ path: envPath, quiet: true, override: true });
312
+ }
313
+ var ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
314
+ if (args.help || args.h) {
315
+ showHelp();
316
+ }
317
+ function showHelp() {
318
+ const helpText = `
319
+ GitHub Package Resolutions Updater
320
+ Usage:
321
+ node src/package-resolutions-updater.mjs [options]
322
+ Options:
323
+ --help, -h Show this help message
324
+ Description:
325
+ 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.
326
+ Features:
327
+ - Parses GitHub URLs to extract repository owner, name, and branch.
328
+ - Fetches the latest commit SHA across all branches using GitHub's API.
329
+ - Replaces the old branch or commit in the URL with the latest SHA.
330
+ - Overwrites package.json with the updated URLs.
331
+ Requirements:
332
+ - GitHub Personal Access Token (GITHUB_TOKEN) via .env
333
+ - ESM support (type: "module" in package.json)
334
+ - Node.js v18+ recommended
335
+ Dependencies:
336
+ - ansi-colors \u2013 for styled terminal output
337
+ - dotenv \u2013 to load GitHub token from .env
338
+ Examples:
339
+ node src/package-resolutions-updater.mjs
340
+ node src/package-resolutions-updater.mjs --help
341
+
342
+ `;
343
+ console.log(helpText);
344
+ process.exit(0);
345
+ }
346
+ var GITHUB_USER_AGENTS = [
347
+ "octokit-rest.js/19.0.7",
348
+ "GitHub CLI/2.40.0",
349
+ "Mozilla/5.0 (compatible; GitHubCopilot/1.0)",
350
+ "PostmanRuntime/7.32.3",
351
+ "binary-collections-resolver/1.0 (+https://github.com/dimaslanjaka/bin)"
352
+ ];
353
+ var userAgentDir = import_path.default.join(import_os.default.tmpdir(), "nodejs");
354
+ var userAgentFile = import_path.default.join(userAgentDir, "useragent.txt");
355
+ var selectedUserAgent;
356
+ try {
357
+ if (!import_fs.default.existsSync(userAgentDir)) import_fs.default.mkdirSync(userAgentDir, { recursive: true });
358
+ if (import_fs.default.existsSync(userAgentFile)) {
359
+ const fileAgent = import_fs.default.readFileSync(userAgentFile, "utf-8").trim();
360
+ if (GITHUB_USER_AGENTS.includes(fileAgent)) {
361
+ selectedUserAgent = fileAgent;
362
+ }
363
+ }
364
+ if (!selectedUserAgent) {
365
+ selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
366
+ import_fs.default.writeFileSync(userAgentFile, selectedUserAgent, "utf-8");
367
+ }
368
+ } catch (_e) {
369
+ selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
370
+ }
371
+ function fetchJson(url) {
372
+ const headers = {
373
+ "User-Agent": selectedUserAgent,
374
+ Accept: "application/vnd.github.v3+json",
375
+ "X-GitHub-Api-Version": "2022-11-28",
376
+ ...ACCESS_TOKEN ? { Authorization: `token ${ACCESS_TOKEN}` } : {}
377
+ };
378
+ return new Promise((resolve, reject) => {
379
+ import_https.default.get(url, { headers }, (res) => {
380
+ let data = "";
381
+ res.on("data", (chunk) => data += chunk);
382
+ res.on("end", () => {
383
+ try {
384
+ const json = JSON.parse(data);
385
+ if (res.statusCode < 200 || res.statusCode >= 300) {
386
+ return reject(
387
+ new Error(`GitHub API Error ${res.statusCode}: ${json.message || "Unknown error"}
388
+ URL: ${url}`)
389
+ );
390
+ }
391
+ resolve(json);
392
+ } catch {
393
+ reject(new Error(`Invalid JSON from: ${url}`));
394
+ }
395
+ });
396
+ }).on("error", reject);
397
+ });
398
+ }
399
+ async function getLatestCommit(owner, repo, branch = "main") {
400
+ var _a, _b, _c, _d;
401
+ const url = `https://api.github.com/repos/${owner}/${repo}/commits/${branch}`;
402
+ const json = await fetchJson(url);
403
+ const sha = json.sha;
404
+ 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);
405
+ if (!sha || !dateStr) {
406
+ console.log(json);
407
+ throw new Error(`Missing SHA or date for ${owner}/${repo}@${branch}`);
408
+ }
409
+ return {
410
+ owner,
411
+ repo,
412
+ branch,
413
+ sha,
414
+ date: new Date(dateStr).toISOString()
415
+ };
416
+ }
417
+ async function getLatestCommitAcrossBranches(owner, repo) {
418
+ const branches = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/branches`);
419
+ const commits = await Promise.all(
420
+ branches.map(async ({ name, commit }) => {
421
+ var _a, _b, _c, _d;
422
+ const commitSha = commit == null ? void 0 : commit.sha;
423
+ if (!commitSha) {
424
+ console.warn(`No commit SHA for '${owner}/${repo}' branch: ${name}`);
425
+ return { branch: name, sha: "", date: /* @__PURE__ */ new Date(0) };
426
+ }
427
+ try {
428
+ const commitData = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}`);
429
+ 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);
430
+ const date = dateStr ? new Date(dateStr) : /* @__PURE__ */ new Date(0);
431
+ return { branch: name, sha: commitData.sha, date };
432
+ } catch (e) {
433
+ console.warn(`Failed to fetch commit for ${name}: ${e.message}`);
434
+ return { branch: name, sha: commitSha, date: /* @__PURE__ */ new Date(0) };
435
+ }
436
+ })
437
+ );
438
+ const latest = commits.reduce((a, b) => a.date > b.date ? a : b, { date: /* @__PURE__ */ new Date(0) });
439
+ return {
440
+ owner,
441
+ repo,
442
+ branch: latest.branch,
443
+ sha: latest.sha,
444
+ date: latest.date.toISOString()
445
+ };
446
+ }
447
+ function replaceRawWithLatestHash(url, latestHash) {
448
+ const match = url.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+)\/raw\/([^/]+)\/(.+)$/);
449
+ if (!match) throw new Error("Invalid GitHub raw URL");
450
+ const [, owner, repo, _oldHash, path4] = match;
451
+ return `https://github.com/${owner}/${repo}/raw/${latestHash}/${path4}`;
452
+ }
453
+
454
+ // src/package-resolutions-updater-cli.mjs
455
+ (async () => {
456
+ const specialPackageOverrides = [
457
+ // SBG packages
458
+ { pkg: "sbg-utility", branch: "sbg-utility", repo: "static-blog-generator", owner: "dimaslanjaka" },
459
+ { pkg: "sbg-api", branch: "sbg-api", repo: "static-blog-generator", owner: "dimaslanjaka" },
460
+ { pkg: "instant-indexing", branch: "instant-indexing", repo: "static-blog-generator", owner: "dimaslanjaka" },
461
+ { pkg: "sbg-server", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
462
+ { pkg: "sbg-cli", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
463
+ { pkg: "static-blog-generator", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
464
+ // Hexo family
465
+ // { pkg: "hexo", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
466
+ // { pkg: "hexo-util", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
467
+ // { pkg: "warehouse", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
468
+ // { pkg: "hexo-server", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
469
+ // { pkg: "hexo-log", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
470
+ // { pkg: "hexo-front-matter", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
471
+ // { pkg: "hexo-cli", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
472
+ // { pkg: "hexo-asset-link", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
473
+ { pkg: "hexo-post-parser", branch: "pre-release", repo: "hexo-post-parser", owner: "dimaslanjaka" },
474
+ { pkg: "hexo-seo", branch: "pre-release", repo: "hexo-seo", owner: "dimaslanjaka" },
475
+ { pkg: "hexo-is", branch: "master", repo: "hexo-is", owner: "dimaslanjaka" },
476
+ { pkg: "markdown-it", branch: "master", repo: "markdown-it", owner: "dimaslanjaka" },
477
+ { pkg: "hexo-renderers", branch: "pre-release", repo: "hexo-renderers", owner: "dimaslanjaka" },
478
+ { pkg: "hexo-shortcodes", branch: "pre-release", repo: "hexo-shortcodes", owner: "dimaslanjaka" },
479
+ { pkg: "google-news-sitemap", branch: "master", repo: "google-news-sitemap", owner: "dimaslanjaka" },
480
+ { pkg: "git-command-helper", branch: "pre-release", repo: "git-command-helper", owner: "dimaslanjaka" },
481
+ {
482
+ pkg: "nodejs-package-types",
483
+ branch: "main",
484
+ repo: "nodejs-package-types",
485
+ owner: "dimaslanjaka"
486
+ },
487
+ { pkg: "cross-spawn", branch: "private", repo: "node-cross-spawn", owner: "dimaslanjaka" },
488
+ { pkg: "hexo-generator-redirect", branch: "master", repo: "hexo-generator-redirect", owner: "dimaslanjaka" },
489
+ { pkg: "binary-collections", branch: "master", repo: "bin", owner: "dimaslanjaka" },
490
+ // { pkg: "@types/hexo", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
491
+ { pkg: "@types/git-command-helper", branch: "pre-release", repo: "git-command-helper", owner: "dimaslanjaka" }
492
+ ];
493
+ const pkgPath = import_path2.default.join(process.cwd(), "package.json");
494
+ let pkg;
495
+ try {
496
+ pkg = JSON.parse(import_fs2.default.readFileSync(pkgPath, "utf-8"));
497
+ } catch (e) {
498
+ console.error(import_ansi_colors.default.red(`Failed to read package.json: ${e.message}`));
499
+ process.exit(1);
500
+ }
501
+ const entries = Object.entries(pkg.resolutions || {});
502
+ if (entries.length === 0) {
503
+ console.log(import_ansi_colors.default.yellow("No resolutions found in package.json"));
504
+ return;
505
+ }
506
+ console.log(`Processing ${entries.length} resolution(s)...`);
507
+ const updates = [];
508
+ for (const [currentPkgName, url] of entries) {
509
+ let repo;
510
+ try {
511
+ repo = (0, import_git_command_helper.parseGitHubUrl)(url);
512
+ } catch (error) {
513
+ console.log(`\u23ED\uFE0F Skipping ${import_ansi_colors.default.yellow(currentPkgName)}: ${error.message}`);
514
+ continue;
515
+ }
516
+ try {
517
+ const override = specialPackageOverrides.find((p) => p.pkg === currentPkgName);
518
+ const latest = override ? await getLatestCommit(override.owner, override.repo, override.branch) : await getLatestCommitAcrossBranches(repo.owner, repo.repo);
519
+ const new_url = replaceRawWithLatestHash(url, latest.sha);
520
+ updates.push({
521
+ currentPkgName,
522
+ url,
523
+ new_url,
524
+ repo,
525
+ latest
526
+ });
527
+ } catch (error) {
528
+ console.log(`\u274C Failed to process ${import_ansi_colors.default.red(currentPkgName)}: ${error.message}`);
529
+ }
530
+ }
531
+ if (updates.length === 0) {
532
+ console.log(import_ansi_colors.default.yellow("No GitHub URLs were processed"));
533
+ return;
534
+ }
535
+ console.log(`\u{1F4DD} Applying updates to ${updates.length} GitHub URL(s)...`);
536
+ let changed = false;
537
+ for (const { currentPkgName, url, new_url, repo, latest } of updates) {
538
+ if (url !== new_url) {
539
+ console.log(`${import_ansi_colors.default.cyan(currentPkgName)}:`);
540
+ console.log(" from:", url.replace(repo.branch, import_ansi_colors.default.red(repo.branch)));
541
+ console.log(" to:", new_url.replace(latest.sha, import_ansi_colors.default.green(latest.sha)));
542
+ pkg.resolutions[currentPkgName] = new_url;
543
+ changed = true;
544
+ } else {
545
+ console.log(`${import_ansi_colors.default.cyan(currentPkgName)}: ${import_ansi_colors.default.gray("already up-to-date")}`);
546
+ }
547
+ }
548
+ console.log("\n\u{1F4CC} Summary:");
549
+ if (changed) {
550
+ try {
551
+ import_fs2.default.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "");
552
+ console.log(`\u2705 package.json updated successfully`);
553
+ } catch (e) {
554
+ console.error(import_ansi_colors.default.red(`Failed to write package.json: ${e.message}`));
555
+ process.exit(1);
556
+ }
557
+ } else {
558
+ console.log(import_ansi_colors.default.green("No changes to package.json were necessary."));
559
+ }
560
+ })();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,124 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ getLatestCommit,
4
+ getLatestCommitAcrossBranches,
5
+ parseGitHubUrl,
6
+ replaceRawWithLatestHash
7
+ } from "./chunk-XA3SNBPA.mjs";
8
+ import "./chunk-ID2WBTE2.mjs";
9
+ import "./chunk-Z6JLYU2J.mjs";
10
+ import {
11
+ init_esm_shims
12
+ } from "./chunk-QQ4A6DLD.mjs";
13
+
14
+ // src/package-resolutions-updater-cli.mjs
15
+ init_esm_shims();
16
+ import ansiColors from "ansi-colors";
17
+ import fs from "fs";
18
+ import path from "path";
19
+ (async () => {
20
+ const specialPackageOverrides = [
21
+ // SBG packages
22
+ { pkg: "sbg-utility", branch: "sbg-utility", repo: "static-blog-generator", owner: "dimaslanjaka" },
23
+ { pkg: "sbg-api", branch: "sbg-api", repo: "static-blog-generator", owner: "dimaslanjaka" },
24
+ { pkg: "instant-indexing", branch: "instant-indexing", repo: "static-blog-generator", owner: "dimaslanjaka" },
25
+ { pkg: "sbg-server", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
26
+ { pkg: "sbg-cli", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
27
+ { pkg: "static-blog-generator", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
28
+ // Hexo family
29
+ // { pkg: "hexo", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
30
+ // { pkg: "hexo-util", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
31
+ // { pkg: "warehouse", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
32
+ // { pkg: "hexo-server", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
33
+ // { pkg: "hexo-log", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
34
+ // { pkg: "hexo-front-matter", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
35
+ // { pkg: "hexo-cli", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
36
+ // { pkg: "hexo-asset-link", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
37
+ { pkg: "hexo-post-parser", branch: "pre-release", repo: "hexo-post-parser", owner: "dimaslanjaka" },
38
+ { pkg: "hexo-seo", branch: "pre-release", repo: "hexo-seo", owner: "dimaslanjaka" },
39
+ { pkg: "hexo-is", branch: "master", repo: "hexo-is", owner: "dimaslanjaka" },
40
+ { pkg: "markdown-it", branch: "master", repo: "markdown-it", owner: "dimaslanjaka" },
41
+ { pkg: "hexo-renderers", branch: "pre-release", repo: "hexo-renderers", owner: "dimaslanjaka" },
42
+ { pkg: "hexo-shortcodes", branch: "pre-release", repo: "hexo-shortcodes", owner: "dimaslanjaka" },
43
+ { pkg: "google-news-sitemap", branch: "master", repo: "google-news-sitemap", owner: "dimaslanjaka" },
44
+ { pkg: "git-command-helper", branch: "pre-release", repo: "git-command-helper", owner: "dimaslanjaka" },
45
+ {
46
+ pkg: "nodejs-package-types",
47
+ branch: "main",
48
+ repo: "nodejs-package-types",
49
+ owner: "dimaslanjaka"
50
+ },
51
+ { pkg: "cross-spawn", branch: "private", repo: "node-cross-spawn", owner: "dimaslanjaka" },
52
+ { pkg: "hexo-generator-redirect", branch: "master", repo: "hexo-generator-redirect", owner: "dimaslanjaka" },
53
+ { pkg: "binary-collections", branch: "master", repo: "bin", owner: "dimaslanjaka" },
54
+ // { pkg: "@types/hexo", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
55
+ { pkg: "@types/git-command-helper", branch: "pre-release", repo: "git-command-helper", owner: "dimaslanjaka" }
56
+ ];
57
+ const pkgPath = path.join(process.cwd(), "package.json");
58
+ let pkg;
59
+ try {
60
+ pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
61
+ } catch (e) {
62
+ console.error(ansiColors.red(`Failed to read package.json: ${e.message}`));
63
+ process.exit(1);
64
+ }
65
+ const entries = Object.entries(pkg.resolutions || {});
66
+ if (entries.length === 0) {
67
+ console.log(ansiColors.yellow("No resolutions found in package.json"));
68
+ return;
69
+ }
70
+ console.log(`Processing ${entries.length} resolution(s)...`);
71
+ const updates = [];
72
+ for (const [currentPkgName, url] of entries) {
73
+ let repo;
74
+ try {
75
+ repo = parseGitHubUrl(url);
76
+ } catch (error) {
77
+ console.log(`\u23ED\uFE0F Skipping ${ansiColors.yellow(currentPkgName)}: ${error.message}`);
78
+ continue;
79
+ }
80
+ try {
81
+ const override = specialPackageOverrides.find((p) => p.pkg === currentPkgName);
82
+ const latest = override ? await getLatestCommit(override.owner, override.repo, override.branch) : await getLatestCommitAcrossBranches(repo.owner, repo.repo);
83
+ const new_url = replaceRawWithLatestHash(url, latest.sha);
84
+ updates.push({
85
+ currentPkgName,
86
+ url,
87
+ new_url,
88
+ repo,
89
+ latest
90
+ });
91
+ } catch (error) {
92
+ console.log(`\u274C Failed to process ${ansiColors.red(currentPkgName)}: ${error.message}`);
93
+ }
94
+ }
95
+ if (updates.length === 0) {
96
+ console.log(ansiColors.yellow("No GitHub URLs were processed"));
97
+ return;
98
+ }
99
+ console.log(`\u{1F4DD} Applying updates to ${updates.length} GitHub URL(s)...`);
100
+ let changed = false;
101
+ for (const { currentPkgName, url, new_url, repo, latest } of updates) {
102
+ if (url !== new_url) {
103
+ console.log(`${ansiColors.cyan(currentPkgName)}:`);
104
+ console.log(" from:", url.replace(repo.branch, ansiColors.red(repo.branch)));
105
+ console.log(" to:", new_url.replace(latest.sha, ansiColors.green(latest.sha)));
106
+ pkg.resolutions[currentPkgName] = new_url;
107
+ changed = true;
108
+ } else {
109
+ console.log(`${ansiColors.cyan(currentPkgName)}: ${ansiColors.gray("already up-to-date")}`);
110
+ }
111
+ }
112
+ console.log("\n\u{1F4CC} Summary:");
113
+ if (changed) {
114
+ try {
115
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "");
116
+ console.log(`\u2705 package.json updated successfully`);
117
+ } catch (e) {
118
+ console.error(ansiColors.red(`Failed to write package.json: ${e.message}`));
119
+ process.exit(1);
120
+ }
121
+ } else {
122
+ console.log(ansiColors.green("No changes to package.json were necessary."));
123
+ }
124
+ })();