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