binary-collections 2.0.7 → 2.0.9

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 (155) hide show
  1. package/bin/dir-tree.cmd +7 -0
  2. package/bin/git-diff +4 -0
  3. package/bin/git-diff.cmd +5 -2
  4. package/bin/{git-fix-encoding → git-fix} +1 -4
  5. package/bin/git-fix.cmd +7 -0
  6. package/bin/nodekill +0 -0
  7. package/bin/nodekill.ps1 +0 -0
  8. package/bin/{submodule → submodule.txt} +0 -0
  9. package/lib/binary-collections-config.cjs +14 -0
  10. package/lib/binary-collections-config.d.mts +18 -0
  11. package/lib/binary-collections-config.d.ts +16 -0
  12. package/lib/binary-collections-config.js +39 -0
  13. package/lib/binary-collections-config.mjs +6 -0
  14. package/lib/binary-collections.cjs +123 -0
  15. package/lib/binary-collections.d.cts +2 -0
  16. package/lib/binary-collections.d.mts +137 -0
  17. package/lib/binary-collections.d.ts +137 -0
  18. package/lib/binary-collections.mjs +300 -0
  19. package/lib/changelog.cjs +328 -0
  20. package/lib/changelog.d.mts +2 -0
  21. package/lib/changelog.d.ts +1 -0
  22. package/lib/changelog.js +226 -0
  23. package/lib/changelog.mjs +199 -0
  24. package/lib/chunk-4BYBVEYC.mjs +30 -0
  25. package/lib/{chunk-FB6YIQYR.mjs → chunk-AASHBCRW.mjs} +17 -2
  26. package/lib/chunk-APBWENF6.mjs +135 -0
  27. package/lib/{chunk-4LEXWIIF.mjs → chunk-DPKAJKFO.mjs} +2 -4
  28. package/lib/chunk-EGSSKVDH.mjs +66 -0
  29. package/lib/{chunk-3LOB2P54.mjs → chunk-G3THLIDT.mjs} +3 -5
  30. package/lib/chunk-JGR2NW6D.mjs +187 -0
  31. package/lib/chunk-ONIBBBQ3.mjs +108 -0
  32. package/lib/chunk-SH3L6HHV.mjs +27 -0
  33. package/lib/chunk-VVEZVNIV.mjs +81 -0
  34. package/lib/{chunk-JL32QDSH.mjs → chunk-W3ENOM53.mjs} +2 -4
  35. package/lib/chunk-YV7DO3YV.mjs +48 -0
  36. package/lib/{chunk-BSD5CIRU.mjs → chunk-YX5U7XDR.mjs} +11 -5
  37. package/lib/chunk-ZYAQRPUL.mjs +28 -0
  38. package/lib/clean-github-actions-caches.cjs +162 -0
  39. package/lib/clean-github-actions-caches.d.cts +1 -0
  40. package/lib/clean-github-actions-caches.d.mts +169 -0
  41. package/lib/clean-github-actions-caches.d.ts +169 -0
  42. package/lib/clean-github-actions-caches.mjs +132 -0
  43. package/lib/del-gradle.cjs +87 -3
  44. package/lib/del-gradle.js +1 -1
  45. package/lib/del-gradle.mjs +4 -6
  46. package/lib/del-node-modules.cjs +86 -2
  47. package/lib/del-node-modules.mjs +3 -5
  48. package/lib/del-ps.cjs +89 -5
  49. package/lib/del-ps.js +2 -2
  50. package/lib/del-ps.mjs +6 -8
  51. package/lib/del-yarn-caches.cjs +86 -2
  52. package/lib/del-yarn-caches.mjs +3 -5
  53. package/lib/find-node-modules-cli.cjs +8 -0
  54. package/lib/find-node-modules-cli.mjs +2 -3
  55. package/lib/find-node-modules.cjs +8 -0
  56. package/lib/find-node-modules.d.mts +3 -0
  57. package/lib/find-node-modules.d.ts +3 -0
  58. package/lib/find-node-modules.js +12 -0
  59. package/lib/find-node-modules.mjs +2 -3
  60. package/lib/git/gitattributes.cjs +171 -0
  61. package/lib/git/gitattributes.d.mts +35 -0
  62. package/lib/git/gitattributes.d.ts +33 -0
  63. package/lib/git/gitattributes.js +223 -0
  64. package/lib/git/gitattributes.mjs +6 -0
  65. package/lib/git/line-endings.cjs +74 -0
  66. package/lib/git/line-endings.d.cts +7 -0
  67. package/lib/git/line-endings.d.mts +83 -0
  68. package/lib/git/line-endings.d.ts +83 -0
  69. package/lib/git/line-endings.mjs +8 -0
  70. package/lib/git/normalize.cjs +42 -0
  71. package/lib/git/normalize.d.cts +6 -0
  72. package/lib/git/normalize.d.mts +43 -0
  73. package/lib/git/normalize.d.ts +43 -0
  74. package/lib/git/normalize.mjs +6 -0
  75. package/lib/git/permissions.cjs +15 -0
  76. package/lib/git/permissions.d.cts +6 -0
  77. package/lib/git/permissions.d.mts +17 -0
  78. package/lib/git/permissions.d.ts +17 -0
  79. package/lib/git/permissions.mjs +7 -0
  80. package/lib/git/pull-strategy.cjs +13 -0
  81. package/lib/git/pull-strategy.d.cts +5 -0
  82. package/lib/git/pull-strategy.d.mts +15 -0
  83. package/lib/git/pull-strategy.d.ts +15 -0
  84. package/lib/git/pull-strategy.mjs +7 -0
  85. package/lib/git/user-config.cjs +100 -0
  86. package/lib/git/user-config.d.cts +10 -0
  87. package/lib/git/user-config.d.mts +105 -0
  88. package/lib/git/user-config.d.ts +105 -0
  89. package/lib/git/user-config.mjs +8 -0
  90. package/lib/git/utils.cjs +70 -0
  91. package/lib/git/utils.d.cts +20 -0
  92. package/lib/git/utils.d.mts +69 -0
  93. package/lib/git/utils.d.ts +69 -0
  94. package/lib/git/utils.mjs +6 -0
  95. package/lib/git-diff.cjs +23 -24
  96. package/lib/git-diff.d.mts +25 -28
  97. package/lib/git-diff.d.ts +25 -28
  98. package/lib/git-diff.mjs +32 -27
  99. package/lib/git-fix.cjs +129 -0
  100. package/lib/git-fix.d.cts +2 -0
  101. package/lib/git-fix.d.mts +141 -0
  102. package/lib/git-fix.d.ts +141 -0
  103. package/lib/git-fix.mjs +151 -0
  104. package/lib/git-purge.cjs +86 -2
  105. package/lib/git-purge.mjs +3 -5
  106. package/lib/index.cjs +8 -0
  107. package/lib/index.mjs +3 -5
  108. package/lib/npm-run-series.cjs +140 -1
  109. package/lib/npm-run-series.js +2 -1
  110. package/lib/npm-run-series.mjs +7 -5
  111. package/lib/package-resolutions-updater.cjs +447 -0
  112. package/lib/package-resolutions-updater.d.mts +1 -0
  113. package/lib/package-resolutions-updater.d.ts +352 -0
  114. package/lib/package-resolutions-updater.mjs +339 -0
  115. package/lib/print-directory-tree.cjs +241 -0
  116. package/lib/print-directory-tree.d.cts +1 -0
  117. package/lib/print-directory-tree.d.mts +234 -0
  118. package/lib/print-directory-tree.d.ts +234 -0
  119. package/lib/print-directory-tree.mjs +182 -0
  120. package/lib/ps/connected-domain.mjs +2 -3
  121. package/lib/ps/index.cjs +3 -3
  122. package/lib/ps/index.d.mjs +1 -2
  123. package/lib/ps/index.js +6 -3
  124. package/lib/ps/index.mjs +9 -11
  125. package/lib/ps/isWin.mjs +2 -3
  126. package/lib/ps/table-parser.mjs +3 -4
  127. package/lib/submodule-install.cjs +18 -35
  128. package/lib/submodule-install.d.mts +17 -37
  129. package/lib/submodule-install.d.ts +17 -37
  130. package/lib/submodule-install.mjs +21 -29
  131. package/lib/utils.cjs +86 -2
  132. package/lib/utils.d.mts +29 -9
  133. package/lib/utils.d.ts +28 -8
  134. package/lib/utils.js +139 -8
  135. package/lib/utils.mjs +2 -3
  136. package/lib/yarn-reinstall.cjs +9 -7
  137. package/lib/yarn-reinstall.d.mts +12 -8
  138. package/lib/yarn-reinstall.d.ts +12 -8
  139. package/lib/yarn-reinstall.mjs +14 -10
  140. package/package.json +109 -80
  141. package/readme.md +74 -11
  142. package/src/package-resolutions-updater.mjs +350 -0
  143. package/src/print-directory-tree.cjs +234 -0
  144. package/src/ps/index.js +4 -3
  145. package/src/yarn-reinstall.cjs +49 -0
  146. package/test-project/package.json +16 -0
  147. package/tmp/test-repo/package.json +7 -0
  148. package/bin/git-fix-encoding.cmd +0 -6
  149. package/lib/chunk-OKYLF2MU.mjs +0 -53
  150. package/lib/chunk-VXZQNLPU.mjs +0 -23
  151. package/lib/package-resolutions.cjs +0 -28
  152. package/lib/package-resolutions.d.mts +0 -25
  153. package/lib/package-resolutions.d.ts +0 -25
  154. package/lib/package-resolutions.mjs +0 -31
  155. /package/bin/{submodule-install → submodule-install.txt} +0 -0
@@ -0,0 +1,352 @@
1
+ import ansiColors from 'ansi-colors';
2
+ import * as dotenv from 'dotenv';
3
+ import fs from 'fs';
4
+ import https from 'https';
5
+ import os from 'os';
6
+ import path from 'path';
7
+ import { getArgs } from './utils.js';
8
+ import 'minimist';
9
+
10
+ /**
11
+ * 📦 GitHub Package Resolver
12
+ *
13
+ * This script updates the commit hashes in `package.json`'s `resolutions` field
14
+ * for GitHub tarball URLs (typically using `raw/branch-name/...`) to point to the
15
+ * latest commit SHA of the corresponding repository and branch.
16
+ *
17
+ * 🔍 Features:
18
+ * - Parses GitHub URLs to extract repository owner, name, and branch.
19
+ * - Fetches the latest commit SHA across all branches using GitHub's API.
20
+ * - Replaces the old branch or commit in the URL with the latest SHA.
21
+ * - Overwrites `package.json` with the updated URLs.
22
+ *
23
+ * 🛠 Requirements:
24
+ * - GitHub Personal Access Token (GITHUB_TOKEN) via `.env`
25
+ * - ESM support (`type: "module"` in `package.json`)
26
+ * - Node.js v18+ recommended for ESM and `fetch` fallback compatibility
27
+ *
28
+ * 🧩 Dependencies:
29
+ * - `ansi-colors` – for styled terminal output
30
+ * - `dotenv` – to load GitHub token from `.env`
31
+ *
32
+ * ✅ Use case:
33
+ * - Ensures package resolutions always use immutable SHAs instead of mutable branch names.
34
+ * - Helps achieve deterministic builds in monorepos or projects with internal GitHub packages.
35
+ */
36
+
37
+
38
+ const projectDir = process.cwd();
39
+ const envPath = path.join(projectDir, ".env");
40
+ const args = getArgs();
41
+ const ACCESS_TOKEN = process.env.GITHUB_TOKEN || process.env.ACCESS_TOKEN;
42
+
43
+ // Show help if --help/-h is passed
44
+ if (args.help || args.h) {
45
+ showHelp();
46
+ }
47
+
48
+ /**
49
+ * Display help information for the package-resolutions-updater script.
50
+ */
51
+ function showHelp() {
52
+ const helpText = `\n\
53
+ GitHub Package Resolutions Updater\n\
54
+ Usage:\n node src/package-resolutions-updater.mjs [options]\n\
55
+ Options:\n --help, -h Show this help message\n\
56
+ Description:\n 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.\n\
57
+ Features:\n - Parses GitHub URLs to extract repository owner, name, and branch.\n - Fetches the latest commit SHA across all branches using GitHub's API.\n - Replaces the old branch or commit in the URL with the latest SHA.\n - Overwrites package.json with the updated URLs.\n\
58
+ Requirements:\n - GitHub Personal Access Token (GITHUB_TOKEN) via .env\n - ESM support (type: "module" in package.json)\n - Node.js v18+ recommended\n\
59
+ Dependencies:\n - ansi-colors – for styled terminal output\n - dotenv – to load GitHub token from .env\n\
60
+ Examples:\n node src/package-resolutions-updater.mjs\n node src/package-resolutions-updater.mjs --help\n\n`;
61
+ console.log(helpText);
62
+ process.exit(0);
63
+ }
64
+
65
+ // Load the .env file using dotenv (ESM import)
66
+ if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
67
+
68
+ // 📌 Static override rules
69
+ const specialPackageOverrides = [
70
+ // SBG packages
71
+ { pkg: "sbg-utility", branch: "sbg-utility", repo: "static-blog-generator", owner: "dimaslanjaka" },
72
+ { pkg: "sbg-api", branch: "sbg-api", repo: "static-blog-generator", owner: "dimaslanjaka" },
73
+ { pkg: "instant-indexing", branch: "instant-indexing", repo: "static-blog-generator", owner: "dimaslanjaka" },
74
+ { pkg: "sbg-server", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
75
+ { pkg: "sbg-cli", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
76
+ { pkg: "static-blog-generator", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
77
+ // Hexo family
78
+ { pkg: "hexo", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
79
+ { pkg: "hexo-util", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
80
+ { pkg: "warehouse", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
81
+ { pkg: "hexo-server", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
82
+ { pkg: "hexo-log", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
83
+ { pkg: "hexo-front-matter", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
84
+ { pkg: "hexo-cli", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
85
+ { pkg: "hexo-asset-link", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
86
+ { pkg: "hexo-post-parser", branch: "pre-release", repo: "hexo-post-parser", owner: "dimaslanjaka" },
87
+ { pkg: "hexo-seo", branch: "pre-release", repo: "hexo-seo", owner: "dimaslanjaka" },
88
+ { pkg: "hexo-is", branch: "master", repo: "hexo-is", owner: "dimaslanjaka" },
89
+ { pkg: "markdown-it", branch: "master", repo: "markdown-it", owner: "dimaslanjaka" },
90
+ { pkg: "hexo-renderers", branch: "pre-release", repo: "hexo-renderers", owner: "dimaslanjaka" },
91
+ { pkg: "hexo-shortcodes", branch: "pre-release", repo: "hexo-shortcodes", owner: "dimaslanjaka" },
92
+ { pkg: "google-news-sitemap", branch: "master", repo: "google-news-sitemap", owner: "dimaslanjaka" },
93
+ { pkg: "git-command-helper", branch: "pre-release", repo: "git-command-helper", owner: "dimaslanjaka" },
94
+ {
95
+ pkg: "nodejs-package-types",
96
+ branch: "main",
97
+ repo: "nodejs-package-types",
98
+ owner: "dimaslanjaka"
99
+ },
100
+ { pkg: "cross-spawn", branch: "private", repo: "node-cross-spawn", owner: "dimaslanjaka" },
101
+ { pkg: "hexo-generator-redirect", branch: "master", repo: "hexo-generator-redirect", owner: "dimaslanjaka" },
102
+ { pkg: "binary-collections", branch: "master", repo: "bin", owner: "dimaslanjaka" },
103
+ { pkg: "@types/hexo", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
104
+ { pkg: "@types/git-command-helper", branch: "pre-release", repo: "git-command-helper", owner: "dimaslanjaka" }
105
+ ];
106
+
107
+ // --- Optimized: Load package.json once at the top ---
108
+ const pkgPath = path.join(process.cwd(), "package.json");
109
+ let pkg;
110
+ try {
111
+ pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
112
+ } catch (e) {
113
+ console.error(ansiColors.red(`Failed to read package.json: ${e.message}`));
114
+ process.exit(1);
115
+ }
116
+
117
+ // --- Use a random User-Agent for GitHub API requests ---
118
+ const GITHUB_USER_AGENTS = [
119
+ "octokit-rest.js/19.0.7",
120
+ "GitHub CLI/2.40.0",
121
+ "Mozilla/5.0 (compatible; GitHubCopilot/1.0)",
122
+ "PostmanRuntime/7.32.3",
123
+ "binary-collections-resolver/1.0 (+https://github.com/dimaslanjaka/bin)"
124
+ ];
125
+
126
+ // --- User-Agent persistence in system temp folder ---
127
+ const userAgentDir = path.join(os.tmpdir(), "nodejs");
128
+ const userAgentFile = path.join(userAgentDir, "useragent.txt");
129
+ let selectedUserAgent;
130
+ try {
131
+ if (!fs.existsSync(userAgentDir)) fs.mkdirSync(userAgentDir, { recursive: true });
132
+ if (fs.existsSync(userAgentFile)) {
133
+ const fileAgent = fs.readFileSync(userAgentFile, "utf-8").trim();
134
+ if (GITHUB_USER_AGENTS.includes(fileAgent)) {
135
+ selectedUserAgent = fileAgent;
136
+ }
137
+ }
138
+ if (!selectedUserAgent) {
139
+ selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
140
+ fs.writeFileSync(userAgentFile, selectedUserAgent, "utf-8");
141
+ }
142
+ } catch (_e) {
143
+ // fallback to random if any error
144
+ selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
145
+ }
146
+
147
+ /**
148
+ * Fetch JSON from a URL with GitHub headers.
149
+ * @param {string} url
150
+ * @returns {Promise<any>}
151
+ */
152
+ function fetchJson(url) {
153
+ const headers = {
154
+ "User-Agent": selectedUserAgent,
155
+ Accept: "application/vnd.github.v3+json",
156
+ "X-GitHub-Api-Version": "2022-11-28",
157
+ ...(ACCESS_TOKEN ? { Authorization: `token ${ACCESS_TOKEN}` } : {})
158
+ };
159
+ return new Promise((resolve, reject) => {
160
+ https
161
+ .get(url, { headers }, (res) => {
162
+ let data = "";
163
+ res.on("data", (chunk) => (data += chunk));
164
+ res.on("end", () => {
165
+ try {
166
+ const json = JSON.parse(data);
167
+ if (res.statusCode < 200 || res.statusCode >= 300) {
168
+ return reject(
169
+ new Error(`GitHub API Error ${res.statusCode}: ${json.message || "Unknown error"}\nURL: ${url}`)
170
+ );
171
+ }
172
+ resolve(json);
173
+ } catch {
174
+ reject(new Error(`Invalid JSON from: ${url}`));
175
+ }
176
+ });
177
+ })
178
+ .on("error", reject);
179
+ });
180
+ }
181
+
182
+ /**
183
+ * Get latest commit SHA from a specific branch.
184
+ */
185
+ async function getLatestCommit(owner, repo, branch = "main") {
186
+ const url = `https://api.github.com/repos/${owner}/${repo}/commits/${branch}`;
187
+ const json = await fetchJson(url);
188
+
189
+ const sha = json.sha;
190
+ const dateStr = json.commit?.committer?.date || json.commit?.author?.date;
191
+
192
+ if (!sha || !dateStr) {
193
+ console.log(json);
194
+ throw new Error(`Missing SHA or date for ${owner}/${repo}@${branch}`);
195
+ }
196
+
197
+ return {
198
+ owner,
199
+ repo,
200
+ branch,
201
+ sha,
202
+ date: new Date(dateStr).toISOString()
203
+ };
204
+ }
205
+
206
+ /**
207
+ * Get latest commit SHA from all branches and pick the latest.
208
+ */
209
+ async function getLatestCommitAcrossBranches(owner, repo) {
210
+ const branches = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/branches`);
211
+
212
+ const commits = await Promise.all(
213
+ branches.map(async ({ name, commit }) => {
214
+ const commitSha = commit?.sha;
215
+ if (!commitSha) {
216
+ console.warn(`No commit SHA for '${owner}/${repo}' branch: ${name}`);
217
+ return { branch: name, sha: "", date: new Date(0) };
218
+ }
219
+
220
+ try {
221
+ const commitData = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}`);
222
+ const dateStr = commitData.commit?.committer?.date || commitData.commit?.author?.date;
223
+ const date = dateStr ? new Date(dateStr) : new Date(0);
224
+ return { branch: name, sha: commitData.sha, date };
225
+ } catch (e) {
226
+ console.warn(`Failed to fetch commit for ${name}: ${e.message}`);
227
+ return { branch: name, sha: commitSha, date: new Date(0) };
228
+ }
229
+ })
230
+ );
231
+
232
+ const latest = commits.reduce((a, b) => (a.date > b.date ? a : b), { date: new Date(0) });
233
+
234
+ return {
235
+ owner,
236
+ repo,
237
+ branch: latest.branch,
238
+ sha: latest.sha,
239
+ date: latest.date.toISOString()
240
+ };
241
+ }
242
+
243
+ /**
244
+ * Replace the branch or commit in a GitHub raw URL with the latest hash.
245
+ */
246
+ function replaceRawWithLatestHash(url, latestHash) {
247
+ const match = url.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+)\/raw\/([^/]+)\/(.+)$/);
248
+ if (!match) throw new Error("Invalid GitHub raw URL");
249
+
250
+ const [, owner, repo, _oldHash, path] = match;
251
+ return `https://github.com/${owner}/${repo}/raw/${latestHash}/${path}`;
252
+ }
253
+
254
+ /**
255
+ * Parse GitHub URLs and extract owner, repo, branch, and original URL.
256
+ */
257
+ function parseGitHubUrl(url) {
258
+ const ghRepoRoot = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/?$/;
259
+ const ghTreeOrBlob = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/(tree|blob)\/([^/]+(?:\/[^/]+)*)/;
260
+ const ghRaw = /^https:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/([^/]+)(\/.+)?$/;
261
+ const ghDotComRaw = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/raw\/([^/]+)\/.+/;
262
+
263
+ let match;
264
+
265
+ if ((match = url.match(ghRaw))) {
266
+ const [, owner, repo, branch] = match;
267
+ return { owner, repo, branch, url };
268
+ }
269
+
270
+ if ((match = url.match(ghDotComRaw))) {
271
+ const [, owner, repo, branch] = match;
272
+ return { owner, repo, branch, url };
273
+ }
274
+
275
+ if ((match = url.match(ghTreeOrBlob))) {
276
+ const [, owner, repo, , branchPath] = match;
277
+ return { owner, repo, branch: branchPath, url };
278
+ }
279
+
280
+ if ((match = url.match(ghRepoRoot))) {
281
+ const [, owner, repo] = match;
282
+ return { owner, repo, url };
283
+ }
284
+
285
+ throw new Error(`Unsupported GitHub URL: ${url}`);
286
+ }
287
+
288
+ // --- Main logic ---
289
+ (async () => {
290
+ const entries = Object.entries(pkg.resolutions || {});
291
+ if (entries.length === 0) {
292
+ console.log(ansiColors.yellow("No resolutions found in package.json"));
293
+ return;
294
+ }
295
+ console.log(`Processing ${entries.length} resolution(s)...`);
296
+ const updates = [];
297
+ for (const [currentPkgName, url] of entries) {
298
+ // Validate if URL is a GitHub URL
299
+ let repo;
300
+ try {
301
+ repo = parseGitHubUrl(url);
302
+ console.log(`✅ Valid GitHub URL for ${ansiColors.cyan(currentPkgName)}: ${url}`);
303
+ } catch (error) {
304
+ console.log(`⏭️ Skipping ${ansiColors.yellow(currentPkgName)}: ${error.message}`);
305
+ continue;
306
+ }
307
+ try {
308
+ const override = specialPackageOverrides.find((p) => p.pkg === currentPkgName);
309
+ const latest = override
310
+ ? await getLatestCommit(override.owner, override.repo, override.branch)
311
+ : await getLatestCommitAcrossBranches(repo.owner, repo.repo);
312
+ const new_url = replaceRawWithLatestHash(url, latest.sha);
313
+ updates.push({
314
+ currentPkgName,
315
+ url,
316
+ new_url,
317
+ repo,
318
+ latest
319
+ });
320
+ } catch (error) {
321
+ console.log(`❌ Failed to process ${ansiColors.red(currentPkgName)}: ${error.message}`);
322
+ }
323
+ }
324
+ if (updates.length === 0) {
325
+ console.log(ansiColors.yellow("No GitHub URLs were processed"));
326
+ return;
327
+ }
328
+ console.log(`\n📝 Applying updates to ${updates.length} GitHub URL(s)...`);
329
+ let changed = false;
330
+ for (const { currentPkgName, url, new_url, repo, latest } of updates) {
331
+ if (url !== new_url) {
332
+ console.log(`\n${ansiColors.cyan(currentPkgName)}:`);
333
+ console.log(" from:", url.replace(repo.branch, ansiColors.red(repo.branch)));
334
+ console.log(" to:", new_url.replace(latest.sha, ansiColors.green(latest.sha)));
335
+ pkg.resolutions[currentPkgName] = new_url;
336
+ changed = true;
337
+ } else {
338
+ console.log(`\n${ansiColors.cyan(currentPkgName)}: ${ansiColors.gray("already up-to-date")}`);
339
+ }
340
+ }
341
+ if (changed) {
342
+ try {
343
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
344
+ console.log(`\n✅ package.json updated successfully`);
345
+ } catch (e) {
346
+ console.error(ansiColors.red(`Failed to write package.json: ${e.message}`));
347
+ process.exit(1);
348
+ }
349
+ } else {
350
+ console.log(ansiColors.green("No changes to package.json were necessary."));
351
+ }
352
+ })();