binary-collections 2.0.14 → 2.0.15

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 (145) hide show
  1. package/.opencode/plugins/opencode-request-logger/README.md +44 -0
  2. package/.venv/Lib/site-packages/pyarrow/tests/data/orc/README.md +22 -0
  3. package/docs-src/install-opencode-plugins.md +86 -0
  4. package/docs-src/opencode-cli.md +38 -10
  5. package/lib/binary-collections/config-types.cjs +17 -0
  6. package/lib/binary-collections/config-types.d.ts +12 -0
  7. package/lib/binary-collections/config-types.js +2 -0
  8. package/lib/binary-collections/config-types.mjs +7 -0
  9. package/lib/binary-collections/config.cjs +16 -8
  10. package/lib/binary-collections/config.d.cts +18 -10
  11. package/lib/binary-collections/config.mjs +1 -1
  12. package/lib/binary-collections/findScript.cjs +8 -6
  13. package/lib/binary-collections/findScript.mjs +2 -2
  14. package/lib/binary-collections/listScript.cjs +8 -6
  15. package/lib/binary-collections/listScript.mjs +2 -2
  16. package/lib/binary-collections.cjs +8 -6
  17. package/lib/binary-collections.mjs +3 -3
  18. package/lib/changelog.cjs +142 -4
  19. package/lib/changelog.mjs +9 -5
  20. package/lib/{chunk-SARIXFHP.mjs → chunk-3T6AMFI3.mjs} +16 -8
  21. package/lib/{chunk-3F6EIHYG.mjs → chunk-3ZF2QMDK.mjs} +3 -3
  22. package/lib/chunk-B77D3SR4.mjs +28 -0
  23. package/lib/chunk-BPED62FN.mjs +115 -0
  24. package/lib/{chunk-XI67TI46.mjs → chunk-DHFRWM2W.mjs} +1 -1
  25. package/lib/{chunk-2SJKVOTN.mjs → chunk-DPEE3FBB.mjs} +1 -1
  26. package/lib/{chunk-UYNBNLV5.mjs → chunk-H7AE4IO3.mjs} +1 -1
  27. package/lib/{chunk-YWSLMAQ7.mjs → chunk-KCJYREA2.mjs} +14 -12
  28. package/lib/{chunk-JK3MG2KF.mjs → chunk-NHD4HLSU.mjs} +1 -1
  29. package/lib/{chunk-I3O5ZRYU.mjs → chunk-OWNVMKAA.mjs} +1 -1
  30. package/lib/chunk-SKVF4TMD.mjs +59 -0
  31. package/lib/{chunk-SJYP66BO.mjs → chunk-TDUUOAQD.mjs} +1 -1
  32. package/lib/{chunk-D42YBRZW.mjs → chunk-UAEKSLAX.mjs} +1 -1
  33. package/lib/chunk-V6PTSDW5.mjs +82 -0
  34. package/lib/{chunk-AJ3OIYYP.mjs → chunk-WNUEY6VJ.mjs} +8 -6
  35. package/lib/{chunk-YLV4QATP.mjs → chunk-Z53IUBUN.mjs} +6 -5
  36. package/lib/{chunk-JMUFQSPE.mjs → chunk-Z7RM46Q4.mjs} +1 -1
  37. package/lib/cross-env/index.mjs +3 -3
  38. package/lib/git/git-diff-cli.cjs +16 -8
  39. package/lib/git/git-diff-cli.mjs +3 -3
  40. package/lib/git/git-diff.cjs +16 -8
  41. package/lib/git/git-diff.mjs +3 -3
  42. package/lib/git/git-fix.cjs +16 -8
  43. package/lib/git/git-fix.mjs +2 -2
  44. package/lib/git/user-config.cjs +16 -8
  45. package/lib/git/user-config.mjs +2 -2
  46. package/lib/github-workflows/clean-github-actions-caches-cli.cjs +16 -8
  47. package/lib/github-workflows/clean-github-actions-caches-cli.mjs +2 -2
  48. package/lib/github-workflows/clean-github-actions-caches.cjs +16 -8
  49. package/lib/github-workflows/clean-github-actions-caches.mjs +2 -2
  50. package/lib/github-workflows/get-latest-workflow-status-cli.cjs +16 -8
  51. package/lib/github-workflows/get-latest-workflow-status-cli.mjs +2 -2
  52. package/lib/github-workflows/utils.cjs +16 -8
  53. package/lib/github-workflows/utils.mjs +2 -2
  54. package/lib/github-workflows/workflow-badge-cli.cjs +16 -8
  55. package/lib/github-workflows/workflow-badge-cli.mjs +4 -4
  56. package/lib/node-cache-cleaner-cli.mjs +3 -3
  57. package/lib/opencode/cli/auth-rotate.cjs +343 -28
  58. package/lib/opencode/cli/auth-rotate.d.ts +3 -1
  59. package/lib/opencode/cli/auth-rotate.js +10 -15
  60. package/lib/opencode/cli/auth-rotate.mjs +6 -2
  61. package/lib/opencode/cli/auth-rotate.runner.cjs +454 -0
  62. package/lib/opencode/cli/auth-rotate.runner.d.ts +1 -0
  63. package/lib/opencode/cli/auth-rotate.runner.js +8 -0
  64. package/lib/opencode/cli/auth-rotate.runner.mjs +21 -0
  65. package/lib/opencode/install-opencode-plugins-cli.cjs +82 -0
  66. package/lib/opencode/install-opencode-plugins-cli.d.ts +1 -0
  67. package/lib/opencode/install-opencode-plugins-cli.js +78 -0
  68. package/lib/opencode/install-opencode-plugins-cli.mjs +65 -0
  69. package/lib/opencode/utils/check-api.cjs +332 -18
  70. package/lib/opencode/utils/check-api.d.ts +5 -1
  71. package/lib/opencode/utils/check-api.js +101 -15
  72. package/lib/opencode/utils/check-api.mjs +5 -1
  73. package/lib/opencode/utils/check-api.runner.cjs +0 -0
  74. package/lib/opencode/utils/check-api.runner.d.ts +0 -0
  75. package/lib/opencode/utils/check-api.runner.js +1 -0
  76. package/lib/opencode/utils/check-api.runner.mjs +7 -0
  77. package/lib/opencode-cli.cjs +352 -29
  78. package/lib/opencode-cli.js +3 -2
  79. package/lib/opencode-cli.mjs +11 -6
  80. package/lib/package-resolutions-updater-cli.cjs +16 -8
  81. package/lib/package-resolutions-updater-cli.mjs +2 -2
  82. package/lib/package-resolutions-updater.cjs +16 -8
  83. package/lib/package-resolutions-updater.mjs +2 -2
  84. package/lib/print-directory-tree.cjs +16 -8
  85. package/lib/print-directory-tree.mjs +1 -1
  86. package/lib/print-tarball-tree-cli.cjs +305 -0
  87. package/lib/print-tarball-tree-cli.d.mts +2 -0
  88. package/lib/print-tarball-tree-cli.mjs +54 -0
  89. package/lib/print-tarball-tree.cjs +43 -216
  90. package/lib/print-tarball-tree.d.mts +4 -1
  91. package/lib/print-tarball-tree.mjs +12 -66
  92. package/lib/rmpath-cli.cjs +16 -8
  93. package/lib/rmpath-cli.mjs +2 -2
  94. package/lib/rmpath.cjs +16 -8
  95. package/lib/rmpath.mjs +2 -2
  96. package/lib/run-by-checksum/hash.cjs +45 -67
  97. package/lib/run-by-checksum/{hash.d.ts → hash.d.cts} +9 -2
  98. package/lib/run-by-checksum/hash.mjs +3 -7
  99. package/lib/run-by-checksum/run.cjs +95 -58
  100. package/lib/run-by-checksum/run.js +3 -3
  101. package/lib/run-by-checksum/run.mjs +2 -2
  102. package/lib/run-by-checksum-cli.cjs +96 -74
  103. package/lib/run-by-checksum-cli.mjs +2 -2
  104. package/lib/submodule-install.cjs +16 -8
  105. package/lib/submodule-install.mjs +1 -1
  106. package/lib/submodule-remove-cli.cjs +16 -8
  107. package/lib/submodule-remove-cli.mjs +2 -2
  108. package/lib/submodule-remove.cjs +16 -8
  109. package/lib/submodule-remove.mjs +2 -2
  110. package/lib/utils/isDebug.cjs +13 -0
  111. package/lib/utils/isDebug.d.cts +9 -0
  112. package/lib/utils/isDebug.mjs +6 -0
  113. package/package.json +9 -7
  114. package/readme.md +63 -0
  115. package/releases/readme.md +1 -1
  116. package/lib/chunk-546KAIYT.mjs +0 -113
  117. package/lib/chunk-5WAOOOGZ.mjs +0 -77
  118. package/lib/chunk-72XTQ3CK.mjs +0 -45
  119. package/lib/chunk-7Q6YEUQF.mjs +0 -246
  120. package/lib/chunk-AQZ7LMFS.mjs +0 -100
  121. package/lib/chunk-BDCMTOZI.mjs +0 -246
  122. package/lib/chunk-BEUM4LH4.mjs +0 -184
  123. package/lib/chunk-BO4TZS4Q.mjs +0 -246
  124. package/lib/chunk-BZWVHODJ.mjs +0 -62
  125. package/lib/chunk-CM3IC5YC.mjs +0 -226
  126. package/lib/chunk-FR3DMHJC.mjs +0 -146
  127. package/lib/chunk-H44UWUFY.mjs +0 -105
  128. package/lib/chunk-JVMLKHD2.mjs +0 -62
  129. package/lib/chunk-KAT2JNLZ.mjs +0 -146
  130. package/lib/chunk-KRCPFWIF.mjs +0 -193
  131. package/lib/chunk-LVSPEFU2.mjs +0 -86
  132. package/lib/chunk-MCCMMZSM.mjs +0 -60
  133. package/lib/chunk-MGPYPKIE.mjs +0 -109
  134. package/lib/chunk-OA2RKEY3.mjs +0 -162
  135. package/lib/chunk-PAZH45HS.mjs +0 -41
  136. package/lib/chunk-QZMGBDSA.mjs +0 -32
  137. package/lib/chunk-RDGDLSPD.mjs +0 -76
  138. package/lib/chunk-RKPIBGKE.mjs +0 -61
  139. package/lib/chunk-SWUAEY4H.mjs +0 -44
  140. package/lib/chunk-UAIF5VIA.mjs +0 -89
  141. package/lib/chunk-UHPFLJXH.mjs +0 -227
  142. package/lib/chunk-WOC4FZ6F.mjs +0 -164
  143. package/lib/chunk-WSHVPGNM.mjs +0 -44
  144. package/lib/run-by-checksum/hash.js +0 -119
  145. package/readme.html +0 -784
@@ -1,246 +0,0 @@
1
- import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import {
3
- require_fetchResponse
4
- } from "./chunk-KLKAIFKI.mjs";
5
- import {
6
- require_config
7
- } from "./chunk-PAZH45HS.mjs";
8
- import {
9
- require_findEnvFiles
10
- } from "./chunk-H44UWUFY.mjs";
11
- import {
12
- require_utils
13
- } from "./chunk-6RK5UCTP.mjs";
14
- import {
15
- __toESM,
16
- init_esm_shims
17
- } from "./chunk-QQ4A6DLD.mjs";
18
-
19
- // src/package-resolutions-updater.mjs
20
- init_esm_shims();
21
- var utils = __toESM(require_utils(), 1);
22
- var import_config = __toESM(require_config(), 1);
23
- var import_fetchResponse = __toESM(require_fetchResponse(), 1);
24
- var import_findEnvFiles = __toESM(require_findEnvFiles(), 1);
25
- import * as dotenv from "dotenv";
26
- import fs from "fs";
27
- import os from "os";
28
- import path from "upath";
29
- import { parseGitHubUrl } from "git-command-helper";
30
- var projectDir = process.cwd();
31
- var envPath = path.join(projectDir, ".env");
32
- var args = utils.getArgs();
33
- if (!fs.existsSync(envPath)) {
34
- const envFiles = (0, import_findEnvFiles.findEnvFiles)(projectDir, (file) => {
35
- const content = fs.readFileSync(file, "utf-8");
36
- return /GITHUB_TOKEN|ACCESS_TOKEN/.test(content);
37
- });
38
- if (envFiles.length > 0) {
39
- envPath = envFiles[0];
40
- }
41
- }
42
- if (fs.existsSync(envPath)) {
43
- dotenv.config({ path: envPath, quiet: true, override: true });
44
- }
45
- if (args.help || args.h) {
46
- showHelp();
47
- }
48
- function showHelp() {
49
- const helpText = `
50
- GitHub Package Resolutions Updater
51
- Usage:
52
- node src/package-resolutions-updater.mjs [options]
53
- Options:
54
- --help, -h Show this help message
55
- Description:
56
- 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.
57
- Features:
58
- - Parses GitHub URLs to extract repository owner, name, and branch.
59
- - Fetches the latest commit SHA across all branches using GitHub's API.
60
- - Replaces the old branch or commit in the URL with the latest SHA.
61
- - Overwrites package.json with the updated URLs.
62
- Requirements:
63
- - GitHub Personal Access Token (GITHUB_TOKEN) via .env
64
- - ESM support (type: "module" in package.json)
65
- - Node.js v18+ recommended
66
- Dependencies:
67
- - ansi-colors \u2013 for styled terminal output
68
- - dotenv \u2013 to load GitHub token from .env
69
- Examples:
70
- node src/package-resolutions-updater.mjs
71
- node src/package-resolutions-updater.mjs --help
72
-
73
- `;
74
- console.log(helpText);
75
- process.exit(0);
76
- }
77
- var GITHUB_USER_AGENTS = [
78
- "octokit-rest.js/19.0.7",
79
- "GitHub CLI/2.40.0",
80
- "Mozilla/5.0 (compatible; GitHubCopilot/1.0)",
81
- "PostmanRuntime/7.32.3",
82
- "binary-collections-resolver/1.0 (+https://github.com/dimaslanjaka/bin)"
83
- ];
84
- var userAgentDir = path.join(os.tmpdir(), "nodejs");
85
- var userAgentFile = path.join(userAgentDir, "useragent.txt");
86
- var selectedUserAgent;
87
- try {
88
- if (!fs.existsSync(userAgentDir)) fs.mkdirSync(userAgentDir, { recursive: true });
89
- if (fs.existsSync(userAgentFile)) {
90
- const fileAgent = fs.readFileSync(userAgentFile, "utf-8").trim();
91
- if (GITHUB_USER_AGENTS.includes(fileAgent)) {
92
- selectedUserAgent = fileAgent;
93
- }
94
- }
95
- if (!selectedUserAgent) {
96
- selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
97
- fs.writeFileSync(userAgentFile, selectedUserAgent, "utf-8");
98
- }
99
- } catch (_e) {
100
- selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
101
- }
102
- async function fetchJson(url) {
103
- var _a;
104
- const response = await (0, import_fetchResponse.default)(url, {
105
- headers: {
106
- "User-Agent": selectedUserAgent,
107
- Accept: "application/vnd.github.v3+json",
108
- "X-GitHub-Api-Version": "2022-11-28",
109
- ...import_config.GITHUB_ACCESS_TOKEN ? { Authorization: `token ${import_config.GITHUB_ACCESS_TOKEN}` } : {}
110
- },
111
- responseType: "json"
112
- });
113
- if (response.status < 200 || response.status >= 300) {
114
- const message = ((_a = response.data) == null ? void 0 : _a.message) || "Unknown error";
115
- throw new Error(`GitHub API Error ${response.status}: ${message}
116
- URL: ${url}`);
117
- }
118
- return response.data;
119
- }
120
- async function getLatestCommit(owner, repo, branch = "main") {
121
- var _a, _b, _c, _d;
122
- const url = `https://api.github.com/repos/${owner}/${repo}/commits/${branch}`;
123
- const json = await fetchJson(url);
124
- const sha = json.sha;
125
- 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);
126
- if (!sha || !dateStr) {
127
- console.log(json);
128
- throw new Error(`Missing SHA or date for ${owner}/${repo}@${branch}`);
129
- }
130
- return {
131
- owner,
132
- repo,
133
- branch,
134
- sha,
135
- date: new Date(dateStr).toISOString()
136
- };
137
- }
138
- async function getLatestCommitAcrossBranches(owner, repo) {
139
- const branches = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/branches`);
140
- const commits = await Promise.all(
141
- branches.map(async ({ name, commit }) => {
142
- var _a, _b, _c, _d;
143
- const commitSha = commit == null ? void 0 : commit.sha;
144
- if (!commitSha) {
145
- console.warn(`No commit SHA for '${owner}/${repo}' branch: ${name}`);
146
- return { branch: name, sha: "", date: /* @__PURE__ */ new Date(0) };
147
- }
148
- try {
149
- const commitData = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}`);
150
- 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);
151
- const date = dateStr ? new Date(dateStr) : /* @__PURE__ */ new Date(0);
152
- return { branch: name, sha: commitData.sha, date };
153
- } catch (e) {
154
- console.warn(`Failed to fetch commit for ${name}: ${e.message}`);
155
- return { branch: name, sha: commitSha, date: /* @__PURE__ */ new Date(0) };
156
- }
157
- })
158
- );
159
- const latest = commits.reduce((a, b) => a.date > b.date ? a : b, { date: /* @__PURE__ */ new Date(0) });
160
- return {
161
- owner,
162
- repo,
163
- branch: latest.branch,
164
- sha: latest.sha,
165
- date: latest.date.toISOString()
166
- };
167
- }
168
- function replaceRawWithLatestHash(url, latestHash) {
169
- const parsed = parseGitHubUrl(url);
170
- if (!parsed || !parsed.owner || !parsed.repo || !parsed.branch) {
171
- throw new Error("Invalid GitHub raw URL");
172
- }
173
- const branchPrefix = `${parsed.branch}/`;
174
- const rawPrefix = parsed.host === "github.com" ? `raw/${branchPrefix}` : branchPrefix;
175
- const refsPrefix = `refs/heads/${branchPrefix}`;
176
- const path2 = parsed.path.startsWith(rawPrefix) ? parsed.path.slice(rawPrefix.length) : parsed.path.startsWith(refsPrefix) ? parsed.path.slice(refsPrefix.length) : parsed.path.startsWith(branchPrefix) ? parsed.path.slice(branchPrefix.length) : parsed.path;
177
- if (parsed.host === "github.com") {
178
- return `https://github.com/${parsed.owner}/${parsed.repo}/raw/${latestHash}/${path2}`;
179
- }
180
- if (parsed.host === "raw.githubusercontent.com") {
181
- return `https://raw.githubusercontent.com/${parsed.owner}/${parsed.repo}/${latestHash}/${path2}`;
182
- }
183
- throw new Error("Invalid GitHub raw URL");
184
- }
185
- async function resolvePackageResolutionUpdates(resolutions, specialPackageOverrides = []) {
186
- const updates = [];
187
- for (const [currentPkgName, url] of Object.entries(resolutions || {})) {
188
- let repo;
189
- try {
190
- repo = parseGitHubUrl(url);
191
- } catch (error) {
192
- updates.push({
193
- skipped: true,
194
- currentPkgName,
195
- url,
196
- error
197
- });
198
- continue;
199
- }
200
- try {
201
- const override = specialPackageOverrides.find((p) => p.pkg === currentPkgName);
202
- const latest = override ? await getLatestCommit(override.owner, override.repo, override.branch) : await getLatestCommitAcrossBranches(repo.owner, repo.repo);
203
- const new_url = replaceRawWithLatestHash(url, latest.sha);
204
- const response = await (0, import_fetchResponse.default)(new_url);
205
- if (response.status < 200 || response.status >= 300) {
206
- updates.push({
207
- failed: true,
208
- currentPkgName,
209
- url,
210
- new_url,
211
- repo,
212
- latest,
213
- error: new Error(`New URL not accessible (status ${response.status}).
214
- original: ${url}
215
- new: ${new_url}`)
216
- });
217
- continue;
218
- }
219
- updates.push({
220
- currentPkgName,
221
- url,
222
- new_url,
223
- repo,
224
- latest
225
- });
226
- } catch (error) {
227
- updates.push({
228
- failed: true,
229
- currentPkgName,
230
- url,
231
- repo,
232
- error
233
- });
234
- }
235
- }
236
- return updates;
237
- }
238
-
239
- export {
240
- parseGitHubUrl,
241
- fetchJson,
242
- getLatestCommit,
243
- getLatestCommitAcrossBranches,
244
- replaceRawWithLatestHash,
245
- resolvePackageResolutionUpdates
246
- };
@@ -1,62 +0,0 @@
1
- import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import {
3
- __commonJS,
4
- __require,
5
- init_esm_shims
6
- } from "./chunk-QQ4A6DLD.mjs";
7
-
8
- // src/submodule-remove.cjs
9
- var require_submodule_remove = __commonJS({
10
- "src/submodule-remove.cjs"(exports, module) {
11
- init_esm_shims();
12
- var { spawnAsync } = __require("cross-spawn");
13
- var path = __require("upath");
14
- var fs = __require("fs-extra");
15
- var dotenv = __require("dotenv");
16
- var envPath = path.resolve(process.cwd(), ".env");
17
- if (fs.existsSync(envPath)) {
18
- dotenv.config({ path: envPath, override: true, quiet: true });
19
- }
20
- async function removeSubmodule(submodulePath) {
21
- try {
22
- await spawnAsync("git", ["submodule", "deinit", "-f", submodulePath], { stdio: "inherit" });
23
- } catch (error) {
24
- console.warn(`Warning: Could not deinitialize submodule "${submodulePath}". It may not exist.`);
25
- console.warn(error.message);
26
- }
27
- try {
28
- await spawnAsync("git", ["config", "--remove-section", `submodule.${submodulePath}`], { stdio: "inherit" });
29
- } catch (error) {
30
- console.warn(`Warning: Could not remove git config section for submodule "${submodulePath}". It may not exist.`);
31
- console.warn(error.message);
32
- }
33
- const gitModulesPath = path.resolve(".git", "modules", submodulePath);
34
- if (fs.existsSync(gitModulesPath)) {
35
- fs.rmSync(gitModulesPath, { recursive: true, force: true });
36
- console.log(`Removed .git/modules entry for submodule "${submodulePath}".`);
37
- } else {
38
- console.warn(`Warning: The path "${gitModulesPath}" does not exist. Skipping removal of .git/modules entry.`);
39
- }
40
- const gitmodulesPath = path.resolve(".gitmodules");
41
- if (fs.existsSync(gitmodulesPath)) {
42
- let gitmodulesContent = fs.readFileSync(gitmodulesPath, "utf-8");
43
- const submoduleSectionRegex = new RegExp(
44
- `\\[submodule "${submodulePath.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")}"]([\\s\\S]*?)(?=\\[|$)`,
45
- "g"
46
- );
47
- gitmodulesContent = gitmodulesContent.replace(submoduleSectionRegex, "").trim();
48
- fs.writeFileSync(gitmodulesPath, gitmodulesContent);
49
- console.log(`Removed submodule "${submodulePath}" from .gitmodules.`);
50
- } else {
51
- console.warn(`Warning: The .gitmodules file does not exist. Skipping removal of submodule "${submodulePath}".`);
52
- }
53
- fs.rmSync(path.resolve(submodulePath), { recursive: true, force: true });
54
- console.log(`Submodule "${submodulePath}" has been removed.`);
55
- }
56
- module.exports = removeSubmodule;
57
- }
58
- });
59
-
60
- export {
61
- require_submodule_remove
62
- };
@@ -1,226 +0,0 @@
1
- import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import {
3
- require_fetchResponse
4
- } from "./chunk-KLKAIFKI.mjs";
5
- import {
6
- require_config
7
- } from "./chunk-SARIXFHP.mjs";
8
- import {
9
- require_utils
10
- } from "./chunk-6RK5UCTP.mjs";
11
- import {
12
- __toESM,
13
- init_esm_shims
14
- } from "./chunk-QQ4A6DLD.mjs";
15
-
16
- // src/package-resolutions-updater.mjs
17
- init_esm_shims();
18
- var import_config = __toESM(require_config(), 1);
19
- var import_fetchResponse = __toESM(require_fetchResponse(), 1);
20
- var utils = __toESM(require_utils(), 1);
21
- import fs from "fs";
22
- import { parseGitHubUrl } from "git-command-helper";
23
- import os from "os";
24
- import path from "upath";
25
- var args = utils.getArgs();
26
- if (args.help || args.h) {
27
- showHelp();
28
- }
29
- function showHelp() {
30
- const helpText = `
31
- GitHub Package Resolutions Updater
32
- Usage:
33
- node src/package-resolutions-updater.mjs [options]
34
- Options:
35
- --help, -h Show this help message
36
- Description:
37
- 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.
38
- Features:
39
- - Parses GitHub URLs to extract repository owner, name, and branch.
40
- - Fetches the latest commit SHA across all branches using GitHub's API.
41
- - Replaces the old branch or commit in the URL with the latest SHA.
42
- - Overwrites package.json with the updated URLs.
43
- Requirements:
44
- - GitHub Personal Access Token (GITHUB_TOKEN) via .env
45
- - ESM support (type: "module" in package.json)
46
- - Node.js v18+ recommended
47
- Dependencies:
48
- - ansi-colors \u2013 for styled terminal output
49
- Examples:
50
- node src/package-resolutions-updater.mjs
51
- node src/package-resolutions-updater.mjs --help
52
-
53
- `;
54
- console.log(helpText);
55
- process.exit(0);
56
- }
57
- var GITHUB_USER_AGENTS = [
58
- "octokit-rest.js/19.0.7",
59
- "GitHub CLI/2.40.0",
60
- "Mozilla/5.0 (compatible; GitHubCopilot/1.0)",
61
- "PostmanRuntime/7.32.3",
62
- "binary-collections-resolver/1.0 (+https://github.com/dimaslanjaka/bin)"
63
- ];
64
- var userAgentDir = path.join(os.tmpdir(), "nodejs");
65
- var userAgentFile = path.join(userAgentDir, "useragent.txt");
66
- var selectedUserAgent;
67
- try {
68
- if (!fs.existsSync(userAgentDir)) fs.mkdirSync(userAgentDir, { recursive: true });
69
- if (fs.existsSync(userAgentFile)) {
70
- const fileAgent = fs.readFileSync(userAgentFile, "utf-8").trim();
71
- if (GITHUB_USER_AGENTS.includes(fileAgent)) {
72
- selectedUserAgent = fileAgent;
73
- }
74
- }
75
- if (!selectedUserAgent) {
76
- selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
77
- fs.writeFileSync(userAgentFile, selectedUserAgent, "utf-8");
78
- }
79
- } catch (_e) {
80
- selectedUserAgent = GITHUB_USER_AGENTS[Math.floor(Math.random() * GITHUB_USER_AGENTS.length)];
81
- }
82
- async function fetchJson(url) {
83
- var _a;
84
- const response = await (0, import_fetchResponse.default)(url, {
85
- headers: {
86
- "User-Agent": selectedUserAgent,
87
- Accept: "application/vnd.github.v3+json",
88
- "X-GitHub-Api-Version": "2022-11-28",
89
- ...import_config.GITHUB_ACCESS_TOKEN ? { Authorization: `token ${import_config.GITHUB_ACCESS_TOKEN}` } : {}
90
- },
91
- responseType: "json"
92
- });
93
- if (response.status < 200 || response.status >= 300) {
94
- const message = ((_a = response.data) == null ? void 0 : _a.message) || "Unknown error";
95
- throw new Error(`GitHub API Error ${response.status}: ${message}
96
- URL: ${url}`);
97
- }
98
- return response.data;
99
- }
100
- async function getLatestCommit(owner, repo, branch = "main") {
101
- var _a, _b, _c, _d;
102
- const url = `https://api.github.com/repos/${owner}/${repo}/commits/${branch}`;
103
- const json = await fetchJson(url);
104
- const sha = json.sha;
105
- 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);
106
- if (!sha || !dateStr) {
107
- console.log(json);
108
- throw new Error(`Missing SHA or date for ${owner}/${repo}@${branch}`);
109
- }
110
- return {
111
- owner,
112
- repo,
113
- branch,
114
- sha,
115
- date: new Date(dateStr).toISOString()
116
- };
117
- }
118
- async function getLatestCommitAcrossBranches(owner, repo) {
119
- const branches = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/branches`);
120
- const commits = await Promise.all(
121
- branches.map(async ({ name, commit }) => {
122
- var _a, _b, _c, _d;
123
- const commitSha = commit == null ? void 0 : commit.sha;
124
- if (!commitSha) {
125
- console.warn(`No commit SHA for '${owner}/${repo}' branch: ${name}`);
126
- return { branch: name, sha: "", date: /* @__PURE__ */ new Date(0) };
127
- }
128
- try {
129
- const commitData = await fetchJson(`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}`);
130
- 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);
131
- const date = dateStr ? new Date(dateStr) : /* @__PURE__ */ new Date(0);
132
- return { branch: name, sha: commitData.sha, date };
133
- } catch (e) {
134
- console.warn(`Failed to fetch commit for ${name}: ${e.message}`);
135
- return { branch: name, sha: commitSha, date: /* @__PURE__ */ new Date(0) };
136
- }
137
- })
138
- );
139
- const latest = commits.reduce((a, b) => a.date > b.date ? a : b, { date: /* @__PURE__ */ new Date(0) });
140
- return {
141
- owner,
142
- repo,
143
- branch: latest.branch,
144
- sha: latest.sha,
145
- date: latest.date.toISOString()
146
- };
147
- }
148
- function replaceRawWithLatestHash(url, latestHash) {
149
- const parsed = parseGitHubUrl(url);
150
- if (!parsed || !parsed.owner || !parsed.repo || !parsed.branch) {
151
- throw new Error("Invalid GitHub raw URL");
152
- }
153
- const branchPrefix = `${parsed.branch}/`;
154
- const rawPrefix = parsed.host === "github.com" ? `raw/${branchPrefix}` : branchPrefix;
155
- const refsPrefix = `refs/heads/${branchPrefix}`;
156
- const path2 = parsed.path.startsWith(rawPrefix) ? parsed.path.slice(rawPrefix.length) : parsed.path.startsWith(refsPrefix) ? parsed.path.slice(refsPrefix.length) : parsed.path.startsWith(branchPrefix) ? parsed.path.slice(branchPrefix.length) : parsed.path;
157
- if (parsed.host === "github.com") {
158
- return `https://github.com/${parsed.owner}/${parsed.repo}/raw/${latestHash}/${path2}`;
159
- }
160
- if (parsed.host === "raw.githubusercontent.com") {
161
- return `https://raw.githubusercontent.com/${parsed.owner}/${parsed.repo}/${latestHash}/${path2}`;
162
- }
163
- throw new Error("Invalid GitHub raw URL");
164
- }
165
- async function resolvePackageResolutionUpdates(resolutions, specialPackageOverrides = []) {
166
- const updates = [];
167
- for (const [currentPkgName, url] of Object.entries(resolutions || {})) {
168
- let repo;
169
- try {
170
- repo = parseGitHubUrl(url);
171
- } catch (error) {
172
- updates.push({
173
- skipped: true,
174
- currentPkgName,
175
- url,
176
- error
177
- });
178
- continue;
179
- }
180
- try {
181
- const override = specialPackageOverrides.find((p) => p.pkg === currentPkgName);
182
- const latest = override ? await getLatestCommit(override.owner, override.repo, override.branch) : await getLatestCommitAcrossBranches(repo.owner, repo.repo);
183
- const new_url = replaceRawWithLatestHash(url, latest.sha);
184
- const response = await (0, import_fetchResponse.default)(new_url);
185
- if (response.status < 200 || response.status >= 300) {
186
- updates.push({
187
- failed: true,
188
- currentPkgName,
189
- url,
190
- new_url,
191
- repo,
192
- latest,
193
- error: new Error(`New URL not accessible (status ${response.status}).
194
- original: ${url}
195
- new: ${new_url}`)
196
- });
197
- continue;
198
- }
199
- updates.push({
200
- currentPkgName,
201
- url,
202
- new_url,
203
- repo,
204
- latest
205
- });
206
- } catch (error) {
207
- updates.push({
208
- failed: true,
209
- currentPkgName,
210
- url,
211
- repo,
212
- error
213
- });
214
- }
215
- }
216
- return updates;
217
- }
218
-
219
- export {
220
- parseGitHubUrl,
221
- fetchJson,
222
- getLatestCommit,
223
- getLatestCommitAcrossBranches,
224
- replaceRawWithLatestHash,
225
- resolvePackageResolutionUpdates
226
- };
@@ -1,146 +0,0 @@
1
- import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import {
3
- require_config
4
- } from "./chunk-PAZH45HS.mjs";
5
- import {
6
- __commonJS,
7
- __require,
8
- init_esm_shims
9
- } from "./chunk-QQ4A6DLD.mjs";
10
-
11
- // src/github-workflows/utils.cjs
12
- var require_utils = __commonJS({
13
- "src/github-workflows/utils.cjs"(exports, module) {
14
- init_esm_shims();
15
- var axios = __require("axios");
16
- var { spawn } = __require("cross-spawn");
17
- var { GITHUB_ACCESS_TOKEN: TOKEN } = require_config();
18
- if (!TOKEN) {
19
- console.error("Missing env var: ACCESS_TOKEN or GITHUB_TOKEN");
20
- process.exit(1);
21
- }
22
- var BASE = "https://api.github.com";
23
- var HEADERS = {
24
- Authorization: `Bearer ${TOKEN}`,
25
- Accept: "application/vnd.github+json",
26
- "X-GitHub-Api-Version": "2022-11-28"
27
- };
28
- async function request(url) {
29
- try {
30
- const res = await axios.get(url, { headers: HEADERS });
31
- return res.data;
32
- } catch (err) {
33
- if (err == null ? void 0 : err.response) {
34
- const statusText = err.response.statusText || "Request failed";
35
- const responseText = typeof err.response.data === "string" ? err.response.data : JSON.stringify(err.response.data);
36
- throw new Error(`${err.response.status} ${statusText}
37
- ${responseText}`);
38
- }
39
- throw err;
40
- }
41
- }
42
- function runGit(args) {
43
- return new Promise((resolve, reject) => {
44
- var _a, _b;
45
- const child = spawn("git", args, {
46
- cwd: process.cwd(),
47
- stdio: ["ignore", "pipe", "pipe"]
48
- });
49
- let stdout = "";
50
- let stderr = "";
51
- (_a = child.stdout) == null ? void 0 : _a.on("data", (chunk) => {
52
- stdout += chunk.toString();
53
- });
54
- (_b = child.stderr) == null ? void 0 : _b.on("data", (chunk) => {
55
- stderr += chunk.toString();
56
- });
57
- child.on("error", reject);
58
- child.on("close", (code) => {
59
- if (code === 0) return resolve(stdout.trim());
60
- reject(new Error(stderr.trim() || `git ${args.join(" ")} exited with code ${code}`));
61
- });
62
- });
63
- }
64
- function parseOwnerFromUrl(remoteUrl) {
65
- const normalized = remoteUrl.trim().replace(/\.git$/i, "");
66
- const match = normalized.match(/github\.com[:/](?<owner>[^/]+)\/(?<repo>[^/]+)$/i);
67
- return (match == null ? void 0 : match.groups) || null;
68
- }
69
- function getOwnerFromRemoteUrl(remoteUrl) {
70
- const parsed = parseOwnerFromUrl(remoteUrl);
71
- return (parsed == null ? void 0 : parsed.owner) || null;
72
- }
73
- function getRepoFromRemoteUrl(remoteUrl) {
74
- const parsed = parseOwnerFromUrl(remoteUrl);
75
- return (parsed == null ? void 0 : parsed.repo) || null;
76
- }
77
- async function getCurrentOwner() {
78
- const commands = [
79
- ["config", "--local", "--get", "remote.origin.url"],
80
- ["remote", "get-url", "origin"]
81
- ];
82
- for (const args of commands) {
83
- try {
84
- const remoteUrl = await runGit(args);
85
- const owner = getOwnerFromRemoteUrl(remoteUrl);
86
- if (owner) return owner;
87
- } catch {
88
- }
89
- }
90
- throw new Error("Unable to determine repository owner from git remote.origin.url");
91
- }
92
- async function getCurrentRepo() {
93
- const commands = [
94
- ["config", "--local", "--get", "remote.origin.url"],
95
- ["remote", "get-url", "origin"]
96
- ];
97
- for (const args of commands) {
98
- try {
99
- const remoteUrl = await runGit(args);
100
- const repo = getRepoFromRemoteUrl(remoteUrl);
101
- if (repo) return repo;
102
- } catch {
103
- }
104
- }
105
- throw new Error("Unable to determine repository name from git remote.origin.url");
106
- }
107
- async function getOwnerRepo() {
108
- const owner = await getCurrentOwner();
109
- const repo = await getCurrentRepo();
110
- return { owner, repo };
111
- }
112
- async function getLatestRun(owner, repo, workflowId) {
113
- var _a;
114
- let url;
115
- if (workflowId) {
116
- url = `${BASE}/repos/${owner}/${repo}/actions/workflows/${encodeURIComponent(workflowId)}/runs?per_page=1`;
117
- } else {
118
- url = `${BASE}/repos/${owner}/${repo}/actions/runs?per_page=1`;
119
- }
120
- const data = await request(url);
121
- return (_a = data.workflow_runs) == null ? void 0 : _a[0];
122
- }
123
- async function getJobs(owner, repo, runId) {
124
- const data = await request(`${BASE}/repos/${owner}/${repo}/actions/runs/${runId}/jobs`);
125
- return data.jobs || [];
126
- }
127
- module.exports = {
128
- BASE,
129
- HEADERS,
130
- request,
131
- runGit,
132
- parseOwnerFromUrl,
133
- getOwnerFromRemoteUrl,
134
- getRepoFromRemoteUrl,
135
- getCurrentOwner,
136
- getCurrentRepo,
137
- getOwnerRepo,
138
- getLatestRun,
139
- getJobs
140
- };
141
- }
142
- });
143
-
144
- export {
145
- require_utils
146
- };