binary-collections 2.0.6 → 2.0.8

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