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,325 @@
1
+ /**
2
+ * 📦 GitHub Package Resolver
3
+ *
4
+ * This script updates the commit hashes in `package.json`'s `resolutions` field
5
+ * for GitHub tarball URLs (typically using `raw/branch-name/...`) to point to the
6
+ * latest commit SHA of the corresponding repository and branch.
7
+ *
8
+ * 🔍 Features:
9
+ * - Parses GitHub URLs to extract repository owner, name, and branch.
10
+ * - Fetches the latest commit SHA across all branches using GitHub's API.
11
+ * - Replaces the old branch or commit in the URL with the latest SHA.
12
+ * - Overwrites `package.json` with the updated URLs.
13
+ *
14
+ * 🛠 Requirements:
15
+ * - GitHub Personal Access Token (GITHUB_TOKEN) via `.env`
16
+ * - ESM support (`type: "module"` in `package.json`)
17
+ * - Node.js v18+ recommended for ESM and `fetch` fallback compatibility
18
+ *
19
+ * 🧩 Dependencies:
20
+ * - `ansi-colors` – for styled terminal output
21
+ * - `dotenv` – to load GitHub token from `.env`
22
+ *
23
+ * ✅ Use case:
24
+ * - Ensures package resolutions always use immutable SHAs instead of mutable branch names.
25
+ * - Helps achieve deterministic builds in monorepos or projects with internal GitHub packages.
26
+ */
27
+
28
+ import ansiColors from "ansi-colors";
29
+ import * as dotenv from "dotenv";
30
+ import fs from "fs";
31
+ import https from "https";
32
+ import os from "os";
33
+ import path from "path";
34
+
35
+ const projectDir = process.cwd();
36
+ const envPath = path.join(projectDir, ".env");
37
+
38
+ // Load the .env file using dotenv (ESM import)
39
+ if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
40
+
41
+ // 📌 Static override rules
42
+ const specialPackageOverrides = [
43
+ // SBG packages
44
+ { pkg: "sbg-utility", branch: "sbg-utility", repo: "static-blog-generator", owner: "dimaslanjaka" },
45
+ { pkg: "sbg-api", branch: "sbg-api", repo: "static-blog-generator", owner: "dimaslanjaka" },
46
+ { pkg: "instant-indexing", branch: "instant-indexing", repo: "static-blog-generator", owner: "dimaslanjaka" },
47
+ { pkg: "sbg-server", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
48
+ { pkg: "sbg-cli", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
49
+ { pkg: "static-blog-generator", branch: "master", repo: "static-blog-generator", owner: "dimaslanjaka" },
50
+ // Hexo family
51
+ { pkg: "hexo", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
52
+ { pkg: "hexo-util", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
53
+ { pkg: "warehouse", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
54
+ { pkg: "hexo-server", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
55
+ { pkg: "hexo-log", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
56
+ { pkg: "hexo-front-matter", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
57
+ { pkg: "hexo-cli", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
58
+ { pkg: "hexo-asset-link", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
59
+ { pkg: "hexo-post-parser", branch: "pre-release", repo: "hexo-post-parser", owner: "dimaslanjaka" },
60
+ { pkg: "hexo-seo", branch: "pre-release", repo: "hexo-seo", owner: "dimaslanjaka" },
61
+ { pkg: "hexo-is", branch: "master", repo: "hexo-is", owner: "dimaslanjaka" },
62
+ { pkg: "markdown-it", branch: "master", repo: "markdown-it", owner: "dimaslanjaka" },
63
+ { pkg: "hexo-renderers", branch: "pre-release", repo: "hexo-renderers", owner: "dimaslanjaka" },
64
+ { pkg: "hexo-shortcodes", branch: "pre-release", repo: "hexo-shortcodes", owner: "dimaslanjaka" },
65
+ { pkg: "google-news-sitemap", branch: "master", repo: "google-news-sitemap", owner: "dimaslanjaka" },
66
+ { pkg: "git-command-helper", branch: "pre-release", repo: "git-command-helper", owner: "dimaslanjaka" },
67
+ {
68
+ pkg: "nodejs-package-types",
69
+ branch: "main",
70
+ repo: "nodejs-package-types",
71
+ owner: "dimaslanjaka"
72
+ },
73
+ { pkg: "cross-spawn", branch: "private", repo: "node-cross-spawn", owner: "dimaslanjaka" },
74
+ { pkg: "hexo-generator-redirect", branch: "master", repo: "hexo-generator-redirect", owner: "dimaslanjaka" },
75
+ { pkg: "binary-collections", branch: "master", repo: "bin", owner: "dimaslanjaka" },
76
+ { pkg: "@types/hexo", branch: "monorepo-v7", repo: "hexo", owner: "dimaslanjaka" },
77
+ { pkg: "@types/git-command-helper", branch: "pre-release", repo: "git-command-helper", owner: "dimaslanjaka" }
78
+ ];
79
+
80
+ // --- Optimized: Load package.json once at the top ---
81
+ const pkgPath = path.join(process.cwd(), "package.json");
82
+ let pkg;
83
+ try {
84
+ pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
85
+ } catch (e) {
86
+ console.error(ansiColors.red(`Failed to read package.json: ${e.message}`));
87
+ process.exit(1);
88
+ }
89
+
90
+ // --- Use a random User-Agent for GitHub API requests ---
91
+ const GITHUB_USER_AGENTS = [
92
+ "octokit-rest.js/19.0.7",
93
+ "GitHub CLI/2.40.0",
94
+ "Mozilla/5.0 (compatible; GitHubCopilot/1.0)",
95
+ "PostmanRuntime/7.32.3",
96
+ "binary-collections-resolver/1.0 (+https://github.com/dimaslanjaka/bin)"
97
+ ];
98
+
99
+ // --- User-Agent persistence in system temp folder ---
100
+ const userAgentDir = path.join(os.tmpdir(), "nodejs");
101
+ const userAgentFile = path.join(userAgentDir, "useragent.txt");
102
+ let selectedUserAgent;
103
+ try {
104
+ if (!fs.existsSync(userAgentDir)) fs.mkdirSync(userAgentDir, { recursive: true });
105
+ if (fs.existsSync(userAgentFile)) {
106
+ const fileAgent = fs.readFileSync(userAgentFile, "utf-8").trim();
107
+ if (GITHUB_USER_AGENTS.includes(fileAgent)) {
108
+ selectedUserAgent = fileAgent;
109
+ }
110
+ }
111
+ if (!selectedUserAgent) {
112
+ selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
113
+ fs.writeFileSync(userAgentFile, selectedUserAgent, "utf-8");
114
+ }
115
+ } catch (_e) {
116
+ // fallback to random if any error
117
+ selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
118
+ }
119
+
120
+ /**
121
+ * Fetch JSON from a URL with GitHub headers.
122
+ * @param {string} url
123
+ * @returns {Promise<any>}
124
+ */
125
+ function fetchJson(url) {
126
+ const headers = {
127
+ "User-Agent": selectedUserAgent,
128
+ Accept: "application/vnd.github.v3+json",
129
+ "X-GitHub-Api-Version": "2022-11-28",
130
+ ...(process.env.GITHUB_TOKEN ? { Authorization: `token ${process.env.GITHUB_TOKEN}` } : {})
131
+ };
132
+ return new Promise((resolve, reject) => {
133
+ https
134
+ .get(url, { headers }, (res) => {
135
+ let data = "";
136
+ res.on("data", (chunk) => (data += chunk));
137
+ res.on("end", () => {
138
+ try {
139
+ const json = JSON.parse(data);
140
+ if (res.statusCode < 200 || res.statusCode >= 300) {
141
+ return reject(
142
+ new Error(`GitHub API Error ${res.statusCode}: ${json.message || "Unknown error"}\nURL: ${url}`)
143
+ );
144
+ }
145
+ resolve(json);
146
+ } catch {
147
+ reject(new Error(`Invalid JSON from: ${url}`));
148
+ }
149
+ });
150
+ })
151
+ .on("error", reject);
152
+ });
153
+ }
154
+
155
+ /**
156
+ * Get latest commit SHA from a specific branch.
157
+ */
158
+ async function getLatestCommit(owner, repo, branch = "main") {
159
+ const url = `https://api.github.com/repos/${owner}/${repo}/commits/${branch}`;
160
+ const json = await fetchJson(url);
161
+
162
+ const sha = json.sha;
163
+ const dateStr = json.commit?.committer?.date || json.commit?.author?.date;
164
+
165
+ if (!sha || !dateStr) {
166
+ console.log(json);
167
+ throw new Error(`Missing SHA or date for ${owner}/${repo}@${branch}`);
168
+ }
169
+
170
+ return {
171
+ owner,
172
+ repo,
173
+ branch,
174
+ sha,
175
+ date: new Date(dateStr).toISOString()
176
+ };
177
+ }
178
+
179
+ /**
180
+ * Get latest commit SHA from all branches and pick the latest.
181
+ */
182
+ async function getLatestCommitAcrossBranches(owner, repo) {
183
+ const branches = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/branches`);
184
+
185
+ const commits = await Promise.all(
186
+ branches.map(async ({ name, commit }) => {
187
+ const commitSha = commit?.sha;
188
+ if (!commitSha) {
189
+ console.warn(`No commit SHA for '${owner}/${repo}' branch: ${name}`);
190
+ return { branch: name, sha: "", date: new Date(0) };
191
+ }
192
+
193
+ try {
194
+ const commitData = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}`);
195
+ const dateStr = commitData.commit?.committer?.date || commitData.commit?.author?.date;
196
+ const date = dateStr ? new Date(dateStr) : new Date(0);
197
+ return { branch: name, sha: commitData.sha, date };
198
+ } catch (e) {
199
+ console.warn(`Failed to fetch commit for ${name}: ${e.message}`);
200
+ return { branch: name, sha: commitSha, date: new Date(0) };
201
+ }
202
+ })
203
+ );
204
+
205
+ const latest = commits.reduce((a, b) => (a.date > b.date ? a : b), { date: new Date(0) });
206
+
207
+ return {
208
+ owner,
209
+ repo,
210
+ branch: latest.branch,
211
+ sha: latest.sha,
212
+ date: latest.date.toISOString()
213
+ };
214
+ }
215
+
216
+ /**
217
+ * Replace the branch or commit in a GitHub raw URL with the latest hash.
218
+ */
219
+ function replaceRawWithLatestHash(url, latestHash) {
220
+ const match = url.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+)\/raw\/([^/]+)\/(.+)$/);
221
+ if (!match) throw new Error("Invalid GitHub raw URL");
222
+
223
+ const [, owner, repo, _oldHash, path] = match;
224
+ return `https://github.com/${owner}/${repo}/raw/${latestHash}/${path}`;
225
+ }
226
+
227
+ /**
228
+ * Parse GitHub URLs and extract owner, repo, branch, and original URL.
229
+ */
230
+ function parseGitHubUrl(url) {
231
+ const ghRepoRoot = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/?$/;
232
+ const ghTreeOrBlob = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/(tree|blob)\/([^/]+(?:\/[^/]+)*)/;
233
+ const ghRaw = /^https:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/([^/]+)(\/.+)?$/;
234
+ const ghDotComRaw = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/raw\/([^/]+)\/.+/;
235
+
236
+ let match;
237
+
238
+ if ((match = url.match(ghRaw))) {
239
+ const [, owner, repo, branch] = match;
240
+ return { owner, repo, branch, url };
241
+ }
242
+
243
+ if ((match = url.match(ghDotComRaw))) {
244
+ const [, owner, repo, branch] = match;
245
+ return { owner, repo, branch, url };
246
+ }
247
+
248
+ if ((match = url.match(ghTreeOrBlob))) {
249
+ const [, owner, repo, , branchPath] = match;
250
+ return { owner, repo, branch: branchPath, url };
251
+ }
252
+
253
+ if ((match = url.match(ghRepoRoot))) {
254
+ const [, owner, repo] = match;
255
+ return { owner, repo, url };
256
+ }
257
+
258
+ throw new Error(`Unsupported GitHub URL: ${url}`);
259
+ }
260
+
261
+ // --- Main logic ---
262
+ (async () => {
263
+ const entries = Object.entries(pkg.resolutions || {});
264
+ if (entries.length === 0) {
265
+ console.log(ansiColors.yellow("No resolutions found in package.json"));
266
+ return;
267
+ }
268
+ console.log(`Processing ${entries.length} resolution(s)...`);
269
+ const updates = [];
270
+ for (const [currentPkgName, url] of entries) {
271
+ // Validate if URL is a GitHub URL
272
+ let repo;
273
+ try {
274
+ repo = parseGitHubUrl(url);
275
+ console.log(`✅ Valid GitHub URL for ${ansiColors.cyan(currentPkgName)}: ${url}`);
276
+ } catch (error) {
277
+ console.log(`⏭️ Skipping ${ansiColors.yellow(currentPkgName)}: ${error.message}`);
278
+ continue;
279
+ }
280
+ try {
281
+ const override = specialPackageOverrides.find((p) => p.pkg === currentPkgName);
282
+ const latest = override
283
+ ? await getLatestCommit(override.owner, override.repo, override.branch)
284
+ : await getLatestCommitAcrossBranches(repo.owner, repo.repo);
285
+ const new_url = replaceRawWithLatestHash(url, latest.sha);
286
+ updates.push({
287
+ currentPkgName,
288
+ url,
289
+ new_url,
290
+ repo,
291
+ latest
292
+ });
293
+ } catch (error) {
294
+ console.log(`❌ Failed to process ${ansiColors.red(currentPkgName)}: ${error.message}`);
295
+ }
296
+ }
297
+ if (updates.length === 0) {
298
+ console.log(ansiColors.yellow("No GitHub URLs were processed"));
299
+ return;
300
+ }
301
+ console.log(`\n📝 Applying updates to ${updates.length} GitHub URL(s)...`);
302
+ let changed = false;
303
+ for (const { currentPkgName, url, new_url, repo, latest } of updates) {
304
+ if (url !== new_url) {
305
+ console.log(`\n${ansiColors.cyan(currentPkgName)}:`);
306
+ console.log(" from:", url.replace(repo.branch, ansiColors.red(repo.branch)));
307
+ console.log(" to:", new_url.replace(latest.sha, ansiColors.green(latest.sha)));
308
+ pkg.resolutions[currentPkgName] = new_url;
309
+ changed = true;
310
+ } else {
311
+ console.log(`\n${ansiColors.cyan(currentPkgName)}: ${ansiColors.gray("already up-to-date")}`);
312
+ }
313
+ }
314
+ if (changed) {
315
+ try {
316
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
317
+ console.log(`\n✅ package.json updated successfully`);
318
+ } catch (e) {
319
+ console.error(ansiColors.red(`Failed to write package.json: ${e.message}`));
320
+ process.exit(1);
321
+ }
322
+ } else {
323
+ console.log(ansiColors.green("No changes to package.json were necessary."));
324
+ }
325
+ })();
@@ -0,0 +1,234 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+ const crypto = require("crypto");
4
+ const { execSync } = require("child_process");
5
+ const glob = require("glob");
6
+ const { getArgs } = require("./utils.js");
7
+ const sbgUtil = require("sbg-utility");
8
+ const dotenv = require("dotenv");
9
+
10
+ const projectDir = process.cwd();
11
+ const envPath = path.join(projectDir, ".env");
12
+
13
+ // Load the .env file using dotenv (ESM import)
14
+ if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
15
+
16
+ // Parse CLI arguments
17
+ const argv = getArgs();
18
+
19
+ // Main logic wrapped in an async function
20
+ async function main() {
21
+ // Determine output file from CLI args
22
+ let relativeOutputFile = "tmp/directory-structure.txt";
23
+ if (argv.output || argv.o) {
24
+ relativeOutputFile = argv.output || argv.o;
25
+ }
26
+ // If not absolute, resolve relative to projectDir
27
+ const outputFile = path.isAbsolute(relativeOutputFile)
28
+ ? relativeOutputFile
29
+ : path.join(projectDir, relativeOutputFile);
30
+
31
+ // Create or clear the hash file
32
+ sbgUtil.writefile(outputFile, "");
33
+
34
+ /**
35
+ * List of file extensions to include
36
+ * @type {string[]}
37
+ */
38
+ let extensions = [];
39
+ if (argv.ext) {
40
+ extensions = argv.ext
41
+ .split(",")
42
+ .map((e) => e.trim().replace(/^\./, ""))
43
+ .filter(Boolean);
44
+ }
45
+
46
+ // Directories to exclude
47
+ let excludeDirs = [
48
+ "node_modules",
49
+ "vendor",
50
+ "venv",
51
+ ".venv",
52
+ ".git",
53
+ ".hg",
54
+ ".svn",
55
+ ".idea",
56
+ ".vscode",
57
+ "dist",
58
+ "build",
59
+ "out",
60
+ "coverage",
61
+ ".DS_Store"
62
+ ];
63
+ if (argv.exclude) {
64
+ const userExcludes = argv.exclude
65
+ .split(",")
66
+ .map((d) => d.trim())
67
+ .filter(Boolean);
68
+ if (argv["override-exclude"] || argv.we) {
69
+ // Override the default excludes with user-provided ones
70
+ excludeDirs = userExcludes;
71
+ } else {
72
+ // Append user-provided excludes to the default ones
73
+ excludeDirs = excludeDirs.concat(userExcludes);
74
+ }
75
+ }
76
+
77
+ // Convert excludeDirs into glob ignore patterns
78
+ const ignorePatterns = excludeDirs.map((dir) => `**/${dir}/**`);
79
+
80
+ // Initialize an array to hold the formatted outputs
81
+ let hashArray = [];
82
+
83
+ // Helper function to hash and add file if not already processed
84
+ const processedFiles = new Set();
85
+ /**
86
+ * Hashes a file and pushes its relative path and hash to the hashArray.
87
+ * @param {string} file - The absolute path to the file.
88
+ * @returns {Promise<void>} Resolves when the file has been processed and added to hashArray.
89
+ */
90
+ async function hashAndPush(file) {
91
+ if (processedFiles.has(file)) return;
92
+ processedFiles.add(file);
93
+ let relativePath = path.relative(projectDir, file);
94
+ relativePath = relativePath.split(path.sep).join("/");
95
+ try {
96
+ const stats = await fs.stat(file);
97
+ const pseudoHash = `${stats.size}-${stats.mtimeMs}`;
98
+ const hash = crypto.createHash("sha256").update(pseudoHash).digest("hex");
99
+ hashArray.push(`${relativePath} ${hash.slice(0, 8)}`);
100
+ } catch (err) {
101
+ console.error(`Error processing file: ${file}`, err instanceof Error ? err.message : "<unknown error>");
102
+ if (err && err.code === "ENOENT") {
103
+ hashArray.push(`${relativePath} <file not found>`);
104
+ } else {
105
+ hashArray.push(`${relativePath} <error: ${err && err.code ? `code ${err.code}` : "unknown"}>`);
106
+ }
107
+ }
108
+ }
109
+
110
+ // Collect all files to process (extensions + special files)
111
+ const initialFiles = [
112
+ path.join(projectDir, "package.json"),
113
+ path.join(projectDir, "composer.json"),
114
+ path.join(projectDir, "requirements.txt")
115
+ ];
116
+ let patterns = [];
117
+ if (argv.pattern) {
118
+ if (Array.isArray(argv.pattern)) {
119
+ patterns = argv.pattern.map((p) => p.trim()).filter(Boolean);
120
+ } else {
121
+ patterns = [argv.pattern.trim()];
122
+ }
123
+ } else if (extensions.length === 0) {
124
+ patterns = ["**/*.*"];
125
+ } else {
126
+ patterns = extensions.map((ext) => `**/*.${ext}`);
127
+ }
128
+ const globFiles = glob.sync(patterns.length === 1 ? patterns[0] : `{${patterns.join(",")}}`, {
129
+ cwd: projectDir,
130
+ ignore: ignorePatterns,
131
+ absolute: true,
132
+ nodir: true
133
+ });
134
+ const allFiles = new Set([...initialFiles, ...globFiles]);
135
+
136
+ // Hash all unique files
137
+ await Promise.all(Array.from(allFiles).map(hashAndPush));
138
+
139
+ // Sort the hashArray by file paths
140
+ hashArray.sort((a, b) => a.localeCompare(b));
141
+
142
+ /**
143
+ * Generates a directory/file tree string from a hash array of file paths and hashes.
144
+ *
145
+ * @param {string[]} hashArray - Array of strings in the format 'relative/path/to/file hash'.
146
+ * @returns {string} The directory/file tree as a string, with file hashes.
147
+ */
148
+ function getFileTreeString(hashArray) {
149
+ const tree = {};
150
+ // Map file paths to hashes for quick lookup
151
+ const hashMap = {};
152
+ for (const entry of hashArray) {
153
+ const [filePath, hash] = entry.split(" ");
154
+ hashMap[filePath] = hash;
155
+ const parts = filePath.split("/");
156
+ let current = tree;
157
+ for (let i = 0; i < parts.length; i++) {
158
+ const part = parts[i];
159
+ if (i === parts.length - 1) {
160
+ current[part] = null; // file
161
+ } else {
162
+ current[part] = current[part] || {};
163
+ current = current[part];
164
+ }
165
+ }
166
+ }
167
+ /**
168
+ * Recursively builds the tree string for a given node.
169
+ *
170
+ * @param {Object} node - The current node in the tree.
171
+ * @param {string} prefix - The prefix for the current tree level.
172
+ * @param {string} parentPath - The path to the current node.
173
+ * @returns {string[]} Array of lines representing the tree structure.
174
+ */
175
+ function printNode(node, prefix = "", parentPath = "") {
176
+ const keys = Object.keys(node).sort();
177
+ let lines = [];
178
+ keys.forEach((key, idx) => {
179
+ const isLast = idx === keys.length - 1;
180
+ const branch = isLast ? "└── " : "├── ";
181
+ const currentPath = parentPath ? parentPath + "/" + key : key;
182
+ if (node[key] === null) {
183
+ // file: show hash
184
+ lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
185
+ } else {
186
+ lines.push(prefix + branch + key + "/");
187
+ lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "│ "), currentPath));
188
+ }
189
+ });
190
+ return lines;
191
+ }
192
+ return printNode(tree, "", "").join("\n");
193
+ }
194
+
195
+ // Write directory/file tree to the output file (hashes are included in the tree)
196
+ const fileTreeString = getFileTreeString(hashArray);
197
+ await fs.writeFile(outputFile, fileTreeString + "\n", "utf-8");
198
+
199
+ // Add the hash file to the commit if --git-add is present
200
+ if (argv["git-add"]) {
201
+ execSync(`git add ${relativeOutputFile}`);
202
+ console.log(`Directory tree written to ${relativeOutputFile} and staged for git.`);
203
+ } else {
204
+ console.log(`Directory tree written to ${relativeOutputFile}.`);
205
+ }
206
+ }
207
+
208
+ if (argv.help || argv.h) {
209
+ console.log(`
210
+ Usage: node print-directory-tree.cjs [options]
211
+
212
+ Options:
213
+ --output, -o <file> Output file path (default: tmp/directory-structure.txt)
214
+ --ext <exts> Comma-separated list of file extensions (no dot, e.g. js,ts)
215
+ --pattern <glob> Glob pattern(s) for files (can be repeated)
216
+ --exclude <dirs> Comma-separated list of directories to exclude (appends to default)
217
+ --override-exclude, -we Override default exclude directories with --exclude
218
+ --git-add Add output file to git after writing
219
+ --help, -h Show this help message
220
+
221
+ Examples:
222
+ node print-directory-tree.cjs --ext=js,ts
223
+ node print-directory-tree.cjs --pattern=src/**/*.js --pattern=test/**/*.js
224
+ node print-directory-tree.cjs --exclude=dist,build
225
+ node print-directory-tree.cjs --output=tmp/tree.txt
226
+ `);
227
+ process.exit(0);
228
+ }
229
+
230
+ // Execute the main function
231
+ main().catch((err) => {
232
+ console.error(err);
233
+ process.exit(1);
234
+ });
package/src/ps/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  var ChildProcess = require("child_process");
2
2
  var IS_WIN = require("./isWin");
3
3
  var TableParser = require("./table-parser");
4
+
4
5
  /**
5
6
  * End of line.
6
7
  * Basically, the EOL should be:
@@ -213,7 +214,7 @@ exports.kill = function (pid, signal, next) {
213
214
 
214
215
  if (err) {
215
216
  clearTimeout(checkTimeoutTimer);
216
- finishCallback && finishCallback(err);
217
+ if (finishCallback) finishCallback(err);
217
218
  } else if (list.length > 0) {
218
219
  checkConfident = checkConfident - 1 || 0;
219
220
  checkKilled(finishCallback);
@@ -221,7 +222,7 @@ exports.kill = function (pid, signal, next) {
221
222
  checkConfident++;
222
223
  if (checkConfident === 5) {
223
224
  clearTimeout(checkTimeoutTimer);
224
- finishCallback && finishCallback();
225
+ if (finishCallback) finishCallback();
225
226
  } else {
226
227
  checkKilled(finishCallback);
227
228
  }
@@ -229,7 +230,7 @@ exports.kill = function (pid, signal, next) {
229
230
  });
230
231
  }
231
232
 
232
- next && checkKilled(next);
233
+ if (next) checkKilled(next);
233
234
 
234
235
  checkTimeoutTimer =
235
236
  next &&
@@ -0,0 +1,49 @@
1
+ const { execSync } = require("child_process");
2
+ const { getArgs } = require("./utils.js");
3
+ const args = getArgs();
4
+ const positional = args._ || [];
5
+
6
+ if (positional.length === 0) {
7
+ console.error("Usage: yarn-reinstall <packageName> [--dev|-D|--peer|-P|--optional|-O]");
8
+ process.exit(1);
9
+ }
10
+
11
+ const packageName = positional[0];
12
+ const flags = positional.slice(1).concat(
13
+ Object.keys(args)
14
+ .filter((k) => k !== "_" && args[k] === true)
15
+ .map((k) => `--${k}`)
16
+ );
17
+
18
+ if (!packageName) {
19
+ console.error("Please provide a package name.");
20
+ process.exit(1);
21
+ }
22
+
23
+ // Remove and add commands
24
+ const removeCmd = `yarn remove ${packageName}`;
25
+ const addCmd = `yarn add ${packageName} ${flags.join(" ")}`.trim();
26
+
27
+ try {
28
+ // Check if the package is installed before removing
29
+ let isInstalled = false;
30
+ try {
31
+ const listOutput = execSync(`yarn list --pattern "${packageName}" --depth=0`, { encoding: "utf8" });
32
+ isInstalled = listOutput.includes(packageName + "@");
33
+ } catch (_e) {
34
+ // If yarn list fails, assume not installed
35
+ isInstalled = false;
36
+ }
37
+
38
+ if (isInstalled) {
39
+ console.log(`Running: ${removeCmd}`);
40
+ execSync(removeCmd, { stdio: "inherit" });
41
+ } else {
42
+ console.warn(`Package "${packageName}" was not installed or not referenced, skipping remove.`);
43
+ }
44
+
45
+ console.log(`Running: ${addCmd}`);
46
+ execSync(addCmd, { stdio: "inherit" });
47
+ } catch (err) {
48
+ process.exit(err.status || 1);
49
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "test-binary-collections",
3
+ "version": "1.0.0",
4
+ "description": "Test project for binary-collections",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "init-lock": "echo > yarn.lock"
8
+ },
9
+ "keywords": [],
10
+ "author": "dimaslanjaka@gmail.com",
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "binary-collections": "file:../releases/bin.tgz"
14
+ },
15
+ "packageManager": "yarn@4.9.2"
16
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "test-repo",
3
+ "packageManager": "yarn@4.9.2",
4
+ "dependencies": {
5
+ "binary-collections": "D:/Repositories/binary-collections/releases/bin.tgz"
6
+ }
7
+ }
@@ -1,6 +0,0 @@
1
- @echo off
2
-
3
- echo "fix auto rebase"
4
- git config config.pull false
5
- echo "force LF end of line"
6
- git config core.autocrlf false