binary-collections 2.0.13 → 2.0.14
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.
- package/binaries/binary-executor.cjs +307 -238
- package/binaries/clean-nodemodule.cjs +307 -238
- package/binaries/clean-nodemodules.cjs +307 -238
- package/binaries/composer.cjs +323 -0
- package/binaries/composer.cmd +2 -0
- package/binaries/composer.phar +0 -0
- package/binaries/dev.cjs +307 -238
- package/binaries/empty.cjs +307 -238
- package/binaries/git-reduce-size.cjs +307 -238
- package/binaries/javakill.cjs +307 -238
- package/binaries/kill-process.cjs +307 -238
- package/binaries/nodekill.cjs +307 -238
- package/binaries/prod.cjs +307 -238
- package/binaries/py.cjs +307 -238
- package/binaries/rmfind.cjs +307 -238
- package/binaries/rmx.cjs +307 -238
- package/binaries/submodule-token.cjs +307 -238
- package/binaries/test-cjs.cjs +307 -238
- package/binaries/test-esm.cjs +307 -238
- package/binaries/yarn-clean.cjs +307 -238
- package/binaries/yc.cjs +307 -238
- package/binaries/ycw.cjs +307 -238
- package/docs-src/binary-collections.md +1 -1
- package/docs-src/clean-github-actions-caches.md +1 -1
- package/docs-src/copy-move-file.md +1 -4
- package/docs-src/del-ps.md +1 -1
- package/docs-src/find-node-modules.md +1 -1
- package/docs-src/generate-test-ci.md +56 -0
- package/docs-src/get-latest-workflow-status.md +100 -0
- package/docs-src/git-diff.md +1 -1
- package/docs-src/git-fix.md +1 -1
- package/docs-src/git-purge.md +1 -1
- package/docs-src/kill-night-crows.md +1 -1
- package/docs-src/node-cache-cleaner.md +2 -2
- package/docs-src/node-package-packer.md +1 -1
- package/docs-src/opencode-cli.md +127 -0
- package/docs-src/package-resolutions-updater.md +1 -1
- package/docs-src/rmpath.md +1 -1
- package/docs-src/run-by-checksum.md +1 -1
- package/docs-src/submodule-remove.md +1 -1
- package/docs-src/upload-backend.md +29 -0
- package/docs-src/vscode-cli.md +84 -0
- package/docs-src/workflow-badge.md +120 -0
- package/lib/binary-collections/config.cjs +14 -2
- package/lib/binary-collections/config.d.cts +10 -0
- package/lib/binary-collections/config.mjs +2 -2
- package/lib/binary-collections/findScript.cjs +43 -21
- package/lib/binary-collections/findScript.mjs +2 -2
- package/lib/binary-collections/listScript.cjs +43 -21
- package/lib/binary-collections/listScript.mjs +2 -2
- package/lib/binary-collections.cjs +43 -21
- package/lib/binary-collections.mjs +6 -6
- package/lib/chunk-2SJKVOTN.mjs +146 -0
- package/lib/{chunk-2MN4VPV2.mjs → chunk-3F6EIHYG.mjs} +2 -2
- package/lib/chunk-546KAIYT.mjs +113 -0
- package/lib/chunk-56BVU63B.mjs +86 -0
- package/lib/chunk-5WAOOOGZ.mjs +77 -0
- package/lib/chunk-72XTQ3CK.mjs +45 -0
- package/lib/chunk-7N52Z4IJ.mjs +39 -0
- package/lib/chunk-7Q6YEUQF.mjs +246 -0
- package/lib/{chunk-NQXUYO67.mjs → chunk-AJ3OIYYP.mjs} +43 -21
- package/lib/chunk-AQZ7LMFS.mjs +100 -0
- package/lib/chunk-BDCMTOZI.mjs +246 -0
- package/lib/chunk-BEUM4LH4.mjs +184 -0
- package/lib/{chunk-TBWXE7ST.mjs → chunk-BO4TZS4Q.mjs} +5 -2
- package/lib/chunk-CM3IC5YC.mjs +226 -0
- package/lib/{chunk-FLYSZFLW.mjs → chunk-D42YBRZW.mjs} +1 -1
- package/lib/chunk-FR3DMHJC.mjs +146 -0
- package/lib/chunk-I3O5ZRYU.mjs +77 -0
- package/lib/chunk-J4M5EL5P.mjs +108 -0
- package/lib/chunk-JK3MG2KF.mjs +236 -0
- package/lib/chunk-JMUFQSPE.mjs +184 -0
- package/lib/chunk-JVMLKHD2.mjs +62 -0
- package/lib/chunk-KAT2JNLZ.mjs +146 -0
- package/lib/{chunk-CD3HF3LK.mjs → chunk-KRCPFWIF.mjs} +6 -3
- package/lib/chunk-LACQTD5V.mjs +225 -0
- package/lib/chunk-MCCMMZSM.mjs +60 -0
- package/lib/chunk-OA2RKEY3.mjs +162 -0
- package/lib/{chunk-X2B3X7D4.mjs → chunk-PAZH45HS.mjs} +7 -1
- package/lib/chunk-QZMGBDSA.mjs +32 -0
- package/lib/chunk-RKPIBGKE.mjs +61 -0
- package/lib/chunk-SARIXFHP.mjs +44 -0
- package/lib/chunk-SJYP66BO.mjs +62 -0
- package/lib/chunk-SWUAEY4H.mjs +44 -0
- package/lib/chunk-TP3O2JGW.mjs +88 -0
- package/lib/chunk-UAIF5VIA.mjs +89 -0
- package/lib/chunk-UDZBVKXH.mjs +94 -0
- package/lib/chunk-UEOWRYAN.mjs +32 -0
- package/lib/chunk-UHPFLJXH.mjs +227 -0
- package/lib/chunk-UYNBNLV5.mjs +113 -0
- package/lib/chunk-WOC4FZ6F.mjs +164 -0
- package/lib/chunk-X7UVQ6ZC.mjs +183 -0
- package/lib/{chunk-RDN6HF5Z.mjs → chunk-XI67TI46.mjs} +1 -1
- package/lib/chunk-XW5NZAKI.mjs +82 -0
- package/lib/chunk-YLV4QATP.mjs +86 -0
- package/lib/chunk-YWSLMAQ7.mjs +65 -0
- package/lib/chunk-ZB4IQ6VJ.mjs +46 -0
- package/lib/cross-env/index.mjs +3 -3
- package/lib/del-gradle.cjs +1 -1
- package/lib/del-gradle.mjs +22 -16
- package/lib/del-node-modules.cjs +1 -1
- package/lib/del-node-modules.mjs +148 -142
- package/lib/find-node-modules-cli.cjs +1 -1
- package/lib/find-node-modules-cli.mjs +10 -4
- package/lib/{git-diff-cli.cjs → git/git-diff-cli.cjs} +18 -6
- package/lib/{git-diff-cli.mjs → git/git-diff-cli.mjs} +7 -7
- package/lib/{git-diff.cjs → git/git-diff.cjs} +16 -4
- package/lib/{git-diff.js → git/git-diff.js} +3 -3
- package/lib/{git-diff.mjs → git/git-diff.mjs} +6 -6
- package/lib/{git-fix.cjs → git/git-fix.cjs} +134 -3
- package/lib/{git-fix.mjs → git/git-fix.mjs} +19 -14
- package/lib/{git-purge.cjs → git/git-purge.cjs} +1 -1
- package/lib/{git-purge.mjs → git/git-purge.mjs} +4 -4
- package/lib/git/user-config.cjs +131 -1
- package/lib/git/user-config.mjs +3 -1
- package/lib/{clean-github-actions-caches-cli.cjs → github-workflows/clean-github-actions-caches-cli.cjs} +38 -10
- package/lib/{clean-github-actions-caches-cli.mjs → github-workflows/clean-github-actions-caches-cli.mjs} +7 -6
- package/lib/{clean-github-actions-caches.cjs → github-workflows/clean-github-actions-caches.cjs} +38 -10
- package/lib/{clean-github-actions-caches.mjs → github-workflows/clean-github-actions-caches.mjs} +5 -4
- package/lib/github-workflows/generate-test-ci-step-cli.cjs +240 -0
- package/lib/github-workflows/generate-test-ci-step-cli.d.mts +2 -0
- package/lib/github-workflows/generate-test-ci-step-cli.mjs +132 -0
- package/lib/github-workflows/get-latest-workflow-status-cli.cjs +541 -0
- package/lib/github-workflows/get-latest-workflow-status-cli.d.mts +2 -0
- package/lib/github-workflows/get-latest-workflow-status-cli.mjs +61 -0
- package/lib/github-workflows/get-latest-workflow-status.cjs +56 -0
- package/lib/github-workflows/get-latest-workflow-status.d.mts +1 -0
- package/lib/github-workflows/get-latest-workflow-status.mjs +8 -0
- package/lib/github-workflows/utils.cjs +271 -0
- package/lib/github-workflows/utils.d.cts +76 -0
- package/lib/github-workflows/utils.mjs +8 -0
- package/lib/github-workflows/workflow-badge-cli.cjs +722 -0
- package/lib/github-workflows/workflow-badge-cli.d.mts +2 -0
- package/lib/github-workflows/workflow-badge-cli.mjs +98 -0
- package/lib/github-workflows/workflow-badge-generator.cjs +200 -0
- package/lib/github-workflows/workflow-badge-generator.d.mts +14 -0
- package/lib/github-workflows/workflow-badge-generator.mjs +8 -0
- package/lib/github-workflows/workflow-test-data.cjs +73 -0
- package/lib/github-workflows/workflow-test-data.d.cts +63 -0
- package/lib/github-workflows/workflow-test-data.mjs +6 -0
- package/lib/opencode/cli/auth-rotate.cjs +143 -0
- package/lib/opencode/cli/auth-rotate.d.ts +1 -0
- package/lib/opencode/cli/auth-rotate.js +70 -0
- package/lib/opencode/cli/auth-rotate.mjs +10 -0
- package/lib/opencode/cli/list-projects.cjs +184 -0
- package/lib/opencode/cli/list-projects.d.ts +1 -0
- package/lib/opencode/cli/list-projects.js +32 -0
- package/lib/opencode/cli/list-projects.mjs +11 -0
- package/lib/opencode/cli/list-sessions.cjs +215 -0
- package/lib/opencode/cli/list-sessions.d.ts +1 -0
- package/lib/opencode/cli/list-sessions.js +45 -0
- package/lib/opencode/cli/list-sessions.mjs +11 -0
- package/lib/opencode/database.cjs +349 -0
- package/lib/opencode/database.d.ts +91 -0
- package/lib/opencode/database.js +252 -0
- package/lib/opencode/database.mjs +28 -0
- package/lib/opencode/database.runner.cjs +145 -0
- package/lib/opencode/database.runner.d.ts +1 -0
- package/lib/opencode/database.runner.js +56 -0
- package/lib/opencode/database.runner.mjs +37 -0
- package/lib/opencode/opencode-zen.runner.cjs +48 -0
- package/lib/opencode/opencode-zen.runner.d.mts +1 -0
- package/lib/opencode/opencode-zen.runner.mjs +31 -0
- package/lib/opencode/sqlite.cjs +114 -0
- package/lib/opencode/sqlite.d.ts +18 -0
- package/lib/opencode/sqlite.js +82 -0
- package/lib/opencode/sqlite.mjs +10 -0
- package/lib/opencode/storage.cjs +124 -0
- package/lib/opencode/storage.d.ts +27 -0
- package/lib/opencode/storage.js +101 -0
- package/lib/opencode/storage.mjs +38 -0
- package/lib/opencode/storage.runner.cjs +50 -0
- package/lib/opencode/storage.runner.d.ts +1 -0
- package/lib/opencode/storage.runner.js +13 -0
- package/lib/opencode/storage.runner.mjs +29 -0
- package/lib/opencode/types.cjs +17 -0
- package/lib/opencode/types.d.ts +31 -0
- package/lib/opencode/types.js +2 -0
- package/lib/opencode/types.mjs +7 -0
- package/lib/opencode/utils/check-api.cjs +59 -0
- package/lib/opencode/utils/check-api.d.ts +12 -0
- package/lib/opencode/utils/check-api.js +46 -0
- package/lib/opencode/utils/check-api.mjs +8 -0
- package/lib/opencode-cli.cjs +473 -0
- package/lib/opencode-cli.d.ts +2 -0
- package/lib/opencode-cli.js +115 -0
- package/lib/opencode-cli.mjs +111 -0
- package/lib/package-resolutions-updater-cli.cjs +181 -154
- package/lib/package-resolutions-updater-cli.mjs +3 -2
- package/lib/package-resolutions-updater.cjs +181 -154
- package/lib/package-resolutions-updater.d.mts +12 -3
- package/lib/package-resolutions-updater.mjs +3 -2
- package/lib/print-directory-tree.cjs +131 -3
- package/lib/print-directory-tree.mjs +6 -3
- package/lib/rmpath-cli.cjs +131 -5
- package/lib/rmpath-cli.mjs +3 -1
- package/lib/rmpath.cjs +147 -11
- package/lib/rmpath.mjs +3 -1
- package/lib/run-by-checksum/hash.cjs +18 -2
- package/lib/run-by-checksum/hash.d.ts +4 -1
- package/lib/run-by-checksum/hash.js +38 -4
- package/lib/run-by-checksum/hash.mjs +1 -1
- package/lib/run-by-checksum/run.cjs +18 -2
- package/lib/run-by-checksum/run.mjs +2 -2
- package/lib/run-by-checksum-cli.cjs +18 -2
- package/lib/run-by-checksum-cli.mjs +2 -2
- package/lib/submodule-install.cjs +130 -4
- package/lib/submodule-install.mjs +5 -4
- package/lib/submodule-remove-cli.cjs +131 -5
- package/lib/submodule-remove-cli.mjs +3 -1
- package/lib/submodule-remove.cjs +146 -5
- package/lib/submodule-remove.mjs +3 -1
- package/lib/utils/findEnvFiles.cjs +3 -0
- package/lib/utils/findEnvFiles.d.cts +2 -2
- package/lib/utils/findEnvFiles.mjs +1 -1
- package/lib/vscode/project.cjs +0 -0
- package/lib/vscode/project.d.ts +0 -0
- package/lib/vscode/project.js +1 -0
- package/lib/vscode/project.mjs +7 -0
- package/lib/vscode/storage.cjs +138 -0
- package/lib/vscode/storage.d.ts +51 -0
- package/lib/vscode/storage.js +169 -0
- package/lib/vscode/storage.mjs +42 -0
- package/lib/vscode/storage.runner.cjs +125 -0
- package/lib/vscode/storage.runner.d.ts +1 -0
- package/lib/vscode/storage.runner.js +47 -0
- package/lib/vscode/storage.runner.mjs +60 -0
- package/lib/vscode-cli.cjs +155 -0
- package/lib/vscode-cli.d.ts +2 -0
- package/lib/vscode-cli.js +80 -0
- package/lib/vscode-cli.mjs +71 -0
- package/package.json +43 -21
- package/readme.md +41 -8
- package/releases/readme.md +1 -1
- package/src/github-workflows/generate-test-ci-step-cli.mjs +126 -0
- package/vendor/clue/ndjson-react/README.md +365 -0
- package/vendor/composer/pcre/README.md +189 -0
- package/vendor/composer/semver/README.md +99 -0
- package/vendor/composer/xdebug-handler/README.md +305 -0
- package/vendor/ergebnis/agent-detector/README.md +107 -0
- package/vendor/evenement/evenement/README.md +64 -0
- package/vendor/fidry/cpu-core-counter/README.md +138 -0
- package/vendor/friendsofphp/php-cs-fixer/README.md +97 -0
- package/vendor/psr/container/README.md +13 -0
- package/vendor/psr/event-dispatcher/README.md +6 -0
- package/vendor/psr/log/README.md +58 -0
- package/vendor/react/cache/README.md +367 -0
- package/vendor/react/child-process/README.md +619 -0
- package/vendor/react/dns/README.md +453 -0
- package/vendor/react/event-loop/README.md +930 -0
- package/vendor/react/promise/README.md +722 -0
- package/vendor/react/socket/README.md +1564 -0
- package/vendor/react/stream/README.md +1249 -0
- package/vendor/sebastian/diff/README.md +151 -0
- package/vendor/symfony/console/README.md +30 -0
- package/vendor/symfony/deprecation-contracts/README.md +26 -0
- package/vendor/symfony/event-dispatcher/README.md +25 -0
- package/vendor/symfony/event-dispatcher-contracts/README.md +9 -0
- package/vendor/symfony/filesystem/README.md +23 -0
- package/vendor/symfony/finder/README.md +24 -0
- package/vendor/symfony/options-resolver/README.md +25 -0
- package/vendor/symfony/polyfill-ctype/README.md +12 -0
- package/vendor/symfony/polyfill-intl-grapheme/README.md +32 -0
- package/vendor/symfony/polyfill-intl-normalizer/README.md +14 -0
- package/vendor/symfony/polyfill-mbstring/README.md +13 -0
- package/vendor/symfony/polyfill-php80/README.md +25 -0
- package/vendor/symfony/polyfill-php81/README.md +18 -0
- package/vendor/symfony/polyfill-php84/README.md +23 -0
- package/vendor/symfony/polyfill-php85/README.md +20 -0
- package/vendor/symfony/process/README.md +23 -0
- package/vendor/symfony/service-contracts/README.md +9 -0
- package/vendor/symfony/stopwatch/README.md +52 -0
- package/vendor/symfony/string/README.md +24 -0
- package/lib/del-gradle.js +0 -16
- package/lib/del-node-modules.js +0 -211
- package/lib/find-node-modules-cli.js +0 -4
- /package/lib/{clean-github-actions-caches-cli.d.cts → del-gradle.d.cts} +0 -0
- /package/lib/{del-gradle.d.ts → del-node-modules.d.cts} +0 -0
- /package/lib/{find-node-modules-cli.d.ts → find-node-modules-cli.d.cts} +0 -0
- /package/lib/{git-diff-cli.d.ts → git/git-diff-cli.d.ts} +0 -0
- /package/lib/{git-diff-cli.js → git/git-diff-cli.js} +0 -0
- /package/lib/{git-diff.d.ts → git/git-diff.d.ts} +0 -0
- /package/lib/{git-fix.d.cts → git/git-fix.d.cts} +0 -0
- /package/lib/{git-purge.d.cts → git/git-purge.d.cts} +0 -0
- /package/lib/{del-node-modules.d.ts → github-workflows/clean-github-actions-caches-cli.d.cts} +0 -0
- /package/lib/{clean-github-actions-caches.d.cts → github-workflows/clean-github-actions-caches.d.cts} +0 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
require_config
|
|
4
|
+
} from "./chunk-SWUAEY4H.mjs";
|
|
5
|
+
import {
|
|
6
|
+
runChatGpt
|
|
7
|
+
} from "./chunk-GAGABICI.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/git/git-diff.js
|
|
17
|
+
init_esm_shims();
|
|
18
|
+
var import_config = __toESM(require_config(), 1);
|
|
19
|
+
import ansiColors from "ansi-colors";
|
|
20
|
+
import { execSync } from "child_process";
|
|
21
|
+
import fs from "fs-extra";
|
|
22
|
+
import { md5, writefile } from "sbg-utility";
|
|
23
|
+
import path from "upath";
|
|
24
|
+
import { fileURLToPath } from "url";
|
|
25
|
+
var import_utils = __toESM(require_utils(), 1);
|
|
26
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
27
|
+
var __dirname = path.dirname(__filename);
|
|
28
|
+
var args = (0, import_utils.getArgs)();
|
|
29
|
+
var positional = args._ || [];
|
|
30
|
+
var FILENAME = md5((positional[0] || "default") + JSON.stringify(args));
|
|
31
|
+
var DIFF_OUTPUT = (0, import_config.getTempPath)(`git-diff/${FILENAME}.txt`);
|
|
32
|
+
var GPT_DIFF_OUTPUT = (0, import_config.getTempPath)(`git-diff/gpt-${FILENAME}.txt`);
|
|
33
|
+
var CACHE_DIR = path.dirname(DIFF_OUTPUT);
|
|
34
|
+
var DIFF_OUTPUT_RELATIVE = path.relative(process.cwd(), DIFF_OUTPUT);
|
|
35
|
+
var GPT_DIFF_OUTPUT_RELATIVE = path.relative(process.cwd(), GPT_DIFF_OUTPUT);
|
|
36
|
+
fs.ensureDirSync(CACHE_DIR, { mode: 493 });
|
|
37
|
+
function showHelp() {
|
|
38
|
+
console.log("\u{1F4CB} Git Diff Helper");
|
|
39
|
+
console.log("Usage:");
|
|
40
|
+
console.log(" git-diff FILE Show staged diff of specified file");
|
|
41
|
+
console.log(" git-diff --staged-only Show staged diff of all files");
|
|
42
|
+
console.log(" git-diff -s | -S Same as --staged-only");
|
|
43
|
+
console.log(" git-diff --unstaged FILE Show unstaged diff of specified file");
|
|
44
|
+
console.log(" git-diff --unstaged Show unstaged diff of all files");
|
|
45
|
+
console.log(" git-diff -u Same as --unstaged");
|
|
46
|
+
console.log(" git-diff --ai Run ChatGPT automation for commit message");
|
|
47
|
+
console.log(" git-diff --help | -h Show this help message");
|
|
48
|
+
console.log("");
|
|
49
|
+
console.log(`\u{1F4BE} Output is saved to: ${DIFF_OUTPUT_RELATIVE}`);
|
|
50
|
+
console.log(`\u{1F916} GPT prompt is saved to: ${GPT_DIFF_OUTPUT_RELATIVE}`);
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
function runGitDiff(command, successMessage, errorMessage) {
|
|
54
|
+
try {
|
|
55
|
+
console.log(`\u2139\uFE0F Running command: ${command}`);
|
|
56
|
+
const result = execSync(command, {
|
|
57
|
+
encoding: "utf8",
|
|
58
|
+
maxBuffer: 1024 * 1024 * 10
|
|
59
|
+
// 10MB buffer to handle large diffs
|
|
60
|
+
});
|
|
61
|
+
if (!result || result.trim() === "") {
|
|
62
|
+
console.log(`\u2139\uFE0F No changes found for the specified criteria`);
|
|
63
|
+
writefile(DIFF_OUTPUT, "# No changes found\n");
|
|
64
|
+
console.log(`\u2705 Empty diff saved to "${DIFF_OUTPUT_RELATIVE}"`);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
writefile(DIFF_OUTPUT, result);
|
|
68
|
+
writefile(
|
|
69
|
+
GPT_DIFF_OUTPUT,
|
|
70
|
+
`Hello!
|
|
71
|
+
Can you create a conventional commit message by diff content below:
|
|
72
|
+
|
|
73
|
+
\`\`\`${result}
|
|
74
|
+
\`\`\`
|
|
75
|
+
|
|
76
|
+
Give me result as codeblock with language "text" only.
|
|
77
|
+
|
|
78
|
+
Thank you!`
|
|
79
|
+
);
|
|
80
|
+
console.log(`\u2705 ${successMessage}`);
|
|
81
|
+
console.log(`\u{1F4BE} GPT diff prompt saved to "${ansiColors.green(GPT_DIFF_OUTPUT_RELATIVE)}"`);
|
|
82
|
+
return true;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error(`\u274C ${errorMessage}`);
|
|
85
|
+
console.error(`\u274C Command: ${command}`);
|
|
86
|
+
console.error(`\u274C Error: ${error.message}`);
|
|
87
|
+
if (error.message.includes("not a git repository")) {
|
|
88
|
+
console.error("\u274C Make sure you are in a git repository");
|
|
89
|
+
}
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function getUntrackedDiff() {
|
|
94
|
+
try {
|
|
95
|
+
const untrackedStr = execSync("git ls-files --others --exclude-standard", {
|
|
96
|
+
encoding: "utf8",
|
|
97
|
+
maxBuffer: 1024 * 1024 * 10
|
|
98
|
+
}).trim();
|
|
99
|
+
if (!untrackedStr) return "";
|
|
100
|
+
const untrackedFiles = untrackedStr.split("\n").filter(function(f) {
|
|
101
|
+
return f;
|
|
102
|
+
});
|
|
103
|
+
if (untrackedFiles.length === 0) return "";
|
|
104
|
+
var result = "\n# Untracked files:\n";
|
|
105
|
+
for (var i = 0; i < untrackedFiles.length; i++) {
|
|
106
|
+
var file = untrackedFiles[i];
|
|
107
|
+
if (!fs.existsSync(file)) continue;
|
|
108
|
+
var stat = fs.statSync(file);
|
|
109
|
+
if (!stat.isFile()) continue;
|
|
110
|
+
var content;
|
|
111
|
+
try {
|
|
112
|
+
content = fs.readFileSync(file, "utf8");
|
|
113
|
+
} catch (_a) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
var lines = content.split("\n");
|
|
117
|
+
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
118
|
+
lines.pop();
|
|
119
|
+
}
|
|
120
|
+
result += "diff --git a/" + file + " b/" + file + "\n";
|
|
121
|
+
result += "new file mode 100644\n";
|
|
122
|
+
result += "index 0000000..0000000\n";
|
|
123
|
+
result += "--- /dev/null\n";
|
|
124
|
+
result += "+++ b/" + file + "\n";
|
|
125
|
+
result += "@@ -0,0 +1," + (lines.length || 0) + " @@\n";
|
|
126
|
+
for (var j = 0; j < lines.length; j++) {
|
|
127
|
+
result += "+" + lines[j] + "\n";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
} catch (_b) {
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function fileHasChanges(file, mode) {
|
|
136
|
+
const command = mode === "staged" ? `git diff --cached --quiet -- "${file}"` : `git diff --quiet -- "${file}"`;
|
|
137
|
+
try {
|
|
138
|
+
execSync(command, { stdio: "ignore" });
|
|
139
|
+
return false;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (error.status === 1) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async function mainGitDiff() {
|
|
148
|
+
if (args.help || args.h) {
|
|
149
|
+
showHelp();
|
|
150
|
+
}
|
|
151
|
+
const useUnstaged = args.unstaged || args.u;
|
|
152
|
+
const fileFromFlag = typeof args.unstaged === "string" ? args.unstaged : typeof args.u === "string" ? args.u : null;
|
|
153
|
+
let hasDiff = false;
|
|
154
|
+
if (args["staged-only"] || args.s || args.S) {
|
|
155
|
+
hasDiff = runGitDiff(
|
|
156
|
+
"git --no-pager diff --staged",
|
|
157
|
+
`Full staged diff saved to "${ansiColors.green(DIFF_OUTPUT_RELATIVE)}"`,
|
|
158
|
+
"Failed to save staged diff"
|
|
159
|
+
);
|
|
160
|
+
} else {
|
|
161
|
+
const file = positional[0] || fileFromFlag;
|
|
162
|
+
if (!file) {
|
|
163
|
+
const fullDiffModeLabel = useUnstaged ? "unstaged" : "unstaged";
|
|
164
|
+
hasDiff = runGitDiff(
|
|
165
|
+
"git --no-pager diff",
|
|
166
|
+
`Full ${fullDiffModeLabel} diff saved to "${ansiColors.green(DIFF_OUTPUT_RELATIVE)}"`,
|
|
167
|
+
"Failed to save all diff's"
|
|
168
|
+
);
|
|
169
|
+
const untrackedDiff = getUntrackedDiff();
|
|
170
|
+
if (untrackedDiff) {
|
|
171
|
+
const UNTRACKED_DIFF_OUTPUT = (0, import_config.getTempPath)(`git-diff/untracked-${FILENAME}.txt`);
|
|
172
|
+
const UNTRACKED_GPT_DIFF_OUTPUT = (0, import_config.getTempPath)(`git-diff/gpt-untracked-${FILENAME}.txt`);
|
|
173
|
+
const UNTRACKED_DIFF_OUTPUT_RELATIVE = path.relative(process.cwd(), UNTRACKED_DIFF_OUTPUT);
|
|
174
|
+
writefile(UNTRACKED_DIFF_OUTPUT, untrackedDiff);
|
|
175
|
+
writefile(
|
|
176
|
+
UNTRACKED_GPT_DIFF_OUTPUT,
|
|
177
|
+
`Hello!
|
|
178
|
+
Can you create a conventional commit message by diff content below:
|
|
179
|
+
|
|
180
|
+
\`\`\`${untrackedDiff}
|
|
181
|
+
\`\`\`
|
|
182
|
+
|
|
183
|
+
Give me result as codeblock with language "text" only.
|
|
184
|
+
|
|
185
|
+
Thank you!`
|
|
186
|
+
);
|
|
187
|
+
console.log(`\u2705 Untracked file diff saved to "${ansiColors.green(UNTRACKED_DIFF_OUTPUT_RELATIVE)}"`);
|
|
188
|
+
console.log(
|
|
189
|
+
`\u{1F4BE} AI diff prompt saved to "${ansiColors.green(path.relative(process.cwd(), UNTRACKED_GPT_DIFF_OUTPUT))}"`
|
|
190
|
+
);
|
|
191
|
+
hasDiff = true;
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
let fileDiffMode = useUnstaged ? "unstaged" : "staged";
|
|
195
|
+
if (!useUnstaged && !fileHasChanges(file, "staged") && fileHasChanges(file, "unstaged")) {
|
|
196
|
+
fileDiffMode = "unstaged";
|
|
197
|
+
}
|
|
198
|
+
hasDiff = runGitDiff(
|
|
199
|
+
fileDiffMode === "unstaged" ? `git --no-pager diff -- "${file}"` : `git --no-pager diff --cached -- "${file}"`,
|
|
200
|
+
`${fileDiffMode[0].toUpperCase() + fileDiffMode.slice(1)} diff of "${file}" saved to "${ansiColors.green(
|
|
201
|
+
DIFF_OUTPUT_RELATIVE
|
|
202
|
+
)}"`,
|
|
203
|
+
`Failed to generate ${fileDiffMode} diff for "${file}"`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (hasDiff) {
|
|
208
|
+
const opencodePrompt = [
|
|
209
|
+
"",
|
|
210
|
+
"\u{1F916} OpenCode Prompt Helper",
|
|
211
|
+
"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
|
|
212
|
+
"",
|
|
213
|
+
"\u{1F4C4} App Prompt:",
|
|
214
|
+
` Generate a conventional commit message from diff file: ${DIFF_OUTPUT}`,
|
|
215
|
+
"",
|
|
216
|
+
"\u{1F4BB} CLI Command:",
|
|
217
|
+
` opencode run "Generate a conventional commit message from diff file ${DIFF_OUTPUT}"`,
|
|
218
|
+
""
|
|
219
|
+
];
|
|
220
|
+
const opencodePromptPath = (0, import_config.getTempPath)(`git-diff/opencode-${FILENAME}.txt`);
|
|
221
|
+
writefile(opencodePromptPath, opencodePrompt.join("\n"));
|
|
222
|
+
console.log(`\u2705 OpenCode prompt saved to "${ansiColors.green(path.relative(process.cwd(), opencodePromptPath))}"`);
|
|
223
|
+
}
|
|
224
|
+
if (args.ai) {
|
|
225
|
+
try {
|
|
226
|
+
await runChatGpt({ headless: true, questionFile: GPT_DIFF_OUTPUT });
|
|
227
|
+
} catch (error) {
|
|
228
|
+
console.error("\u274C Error running ChatGPT:", error.message);
|
|
229
|
+
console.error("\u{1F4A1} Try running with visible browser mode or check if Chrome is installed");
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
console.log("\u{1F4A1} Use --ai flag to generate commit message with ChatGPT");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
var git_diff_default = runGitDiff;
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
DIFF_OUTPUT,
|
|
239
|
+
GPT_DIFF_OUTPUT,
|
|
240
|
+
CACHE_DIR,
|
|
241
|
+
DIFF_OUTPUT_RELATIVE,
|
|
242
|
+
GPT_DIFF_OUTPUT_RELATIVE,
|
|
243
|
+
runGitDiff,
|
|
244
|
+
mainGitDiff,
|
|
245
|
+
git_diff_default
|
|
246
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
require_config
|
|
4
|
+
} from "./chunk-SARIXFHP.mjs";
|
|
5
|
+
import {
|
|
6
|
+
require_utils
|
|
7
|
+
} from "./chunk-6RK5UCTP.mjs";
|
|
8
|
+
import {
|
|
9
|
+
__commonJS,
|
|
10
|
+
__require,
|
|
11
|
+
init_esm_shims
|
|
12
|
+
} from "./chunk-QQ4A6DLD.mjs";
|
|
13
|
+
|
|
14
|
+
// src/github-workflows/clean-github-actions-caches.cjs
|
|
15
|
+
var require_clean_github_actions_caches = __commonJS({
|
|
16
|
+
"src/github-workflows/clean-github-actions-caches.cjs"(exports, module) {
|
|
17
|
+
init_esm_shims();
|
|
18
|
+
var axios = __require("axios");
|
|
19
|
+
var { getArgs } = require_utils();
|
|
20
|
+
var { GITHUB_ACCESS_TOKEN: ACCESS_TOKEN } = require_config();
|
|
21
|
+
if (!ACCESS_TOKEN) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"Access token is not provided. Please set ACCESS_TOKEN or GITHUB_TOKEN in your environment variables."
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function printHelp() {
|
|
27
|
+
console.log(`
|
|
28
|
+
GitHub Actions Cache Cleaner
|
|
29
|
+
|
|
30
|
+
Description:
|
|
31
|
+
Removes outdated GitHub Actions caches for a repository, keeping only the newest
|
|
32
|
+
cache for each cache-key prefix. Authenticates via ACCESS_TOKEN or GITHUB_TOKEN
|
|
33
|
+
from your environment or .env file.
|
|
34
|
+
|
|
35
|
+
Usage:
|
|
36
|
+
clean-github-actions-caches [options]
|
|
37
|
+
|
|
38
|
+
Options:
|
|
39
|
+
-h, --help Show this help message
|
|
40
|
+
-r, --repo <repo> GitHub repository (owner/repo). If omitted, the tool will
|
|
41
|
+
attempt to infer the repository from the current working
|
|
42
|
+
directory's git remotes.
|
|
43
|
+
-p, --prefix-depth <n>
|
|
44
|
+
Number of leading cache key segments to use as the
|
|
45
|
+
grouping prefix when splitting on /[-_]/. Default: 3.
|
|
46
|
+
|
|
47
|
+
Environment Variables:
|
|
48
|
+
ACCESS_TOKEN GitHub access token (preferred)
|
|
49
|
+
GITHUB_TOKEN GitHub access token (fallback)
|
|
50
|
+
|
|
51
|
+
Behavior & Safety:
|
|
52
|
+
- Groups caches by a derived prefix from the cache key and keeps the most
|
|
53
|
+
recently created cache for each group.
|
|
54
|
+
- Deletes only caches older than the latest per prefix to reduce risk of
|
|
55
|
+
removing needed artifacts.
|
|
56
|
+
|
|
57
|
+
Examples:
|
|
58
|
+
# Run against a specific repo (owner/repo)
|
|
59
|
+
clean-github-actions-caches --repo octocat/hello-world
|
|
60
|
+
|
|
61
|
+
# Run via npx without installing
|
|
62
|
+
npx --legacy-peer-deps -y binary-collections@https://raw.githubusercontent.com/dimaslanjaka/bin/master/releases/bin.tgz clean-github-actions-caches --repo owner/repo --prefix-depth 3
|
|
63
|
+
|
|
64
|
+
# Run via yarn dlx
|
|
65
|
+
yarn dlx binary-collections@https://raw.githubusercontent.com/dimaslanjaka/bin/master/releases/bin.tgz clean-github-actions-caches --prefix-depth 3
|
|
66
|
+
|
|
67
|
+
Notes:
|
|
68
|
+
- Ensure ACCESS_TOKEN or GITHUB_TOKEN is set and has permissions to manage Actions caches.
|
|
69
|
+
- Intended for repository maintainers with appropriate permissions.
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
var argv = getArgs({
|
|
73
|
+
alias: {
|
|
74
|
+
h: "help",
|
|
75
|
+
p: "prefix-depth",
|
|
76
|
+
r: "repo"
|
|
77
|
+
},
|
|
78
|
+
string: ["prefix-depth", "repo"],
|
|
79
|
+
boolean: ["help"]
|
|
80
|
+
});
|
|
81
|
+
if (argv.help) {
|
|
82
|
+
printHelp();
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
function deleteGitHubActionsCache(GH_REPO, cacheId) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches/${cacheId}`;
|
|
88
|
+
const token = ACCESS_TOKEN;
|
|
89
|
+
if (!token) {
|
|
90
|
+
return reject(new Error("Access token is not provided"));
|
|
91
|
+
}
|
|
92
|
+
axios.delete(url, {
|
|
93
|
+
headers: {
|
|
94
|
+
Authorization: `token ${token}`,
|
|
95
|
+
Accept: "application/vnd.github.v3+json"
|
|
96
|
+
}
|
|
97
|
+
}).then((response) => {
|
|
98
|
+
console.log(`Cache (${cacheId}) deleted successfully`, response.data);
|
|
99
|
+
resolve(response.data);
|
|
100
|
+
}).catch((error) => {
|
|
101
|
+
var _a;
|
|
102
|
+
console.error("Error deleting cache:", ((_a = error.response) == null ? void 0 : _a.data) || error.message || "Unknown error");
|
|
103
|
+
reject(error);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function normalizePrefixDepth(prefixDepth) {
|
|
108
|
+
const parsed = Number(prefixDepth);
|
|
109
|
+
if (!Number.isFinite(parsed) || parsed < 1) {
|
|
110
|
+
return 3;
|
|
111
|
+
}
|
|
112
|
+
return Math.floor(parsed);
|
|
113
|
+
}
|
|
114
|
+
function isChecksumSegment(segment) {
|
|
115
|
+
return /^[a-f0-9]{32,}$/i.test(segment);
|
|
116
|
+
}
|
|
117
|
+
function getMeaningfulCacheKeyParts(key) {
|
|
118
|
+
return String(key).split(/[-_]/).filter(Boolean).filter((segment) => !isChecksumSegment(segment));
|
|
119
|
+
}
|
|
120
|
+
function getCachePrefix(key, prefixDepth = 3) {
|
|
121
|
+
const normalizedDepth = normalizePrefixDepth(prefixDepth);
|
|
122
|
+
const parts = String(key).split(/[-_]/).filter(Boolean);
|
|
123
|
+
const meaningfulParts = getMeaningfulCacheKeyParts(key);
|
|
124
|
+
if (meaningfulParts.length !== parts.length) {
|
|
125
|
+
if (meaningfulParts.length < normalizedDepth) {
|
|
126
|
+
return `${meaningfulParts.join("-")}-`;
|
|
127
|
+
}
|
|
128
|
+
return meaningfulParts.join("-");
|
|
129
|
+
}
|
|
130
|
+
if (parts.length <= normalizedDepth) {
|
|
131
|
+
return parts.join("-");
|
|
132
|
+
}
|
|
133
|
+
return parts.slice(0, normalizedDepth).join("-");
|
|
134
|
+
}
|
|
135
|
+
function groupCachesByPrefix(caches, prefixDepth = 3) {
|
|
136
|
+
return caches.reduce(
|
|
137
|
+
/**
|
|
138
|
+
* @param {Record<string, Record<string, any>[]>} acc
|
|
139
|
+
* @param {Record<string, any>} item
|
|
140
|
+
* @returns {Record<string, Record<string, any>[]>}
|
|
141
|
+
*/
|
|
142
|
+
(acc, item) => {
|
|
143
|
+
const prefix = getCachePrefix(item.key, prefixDepth);
|
|
144
|
+
if (!acc[prefix]) {
|
|
145
|
+
acc[prefix] = [];
|
|
146
|
+
}
|
|
147
|
+
acc[prefix].push(item);
|
|
148
|
+
return acc;
|
|
149
|
+
},
|
|
150
|
+
{}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
function get_caches(GH_REPO, prefixDepth = 3) {
|
|
154
|
+
const url = `https://api.github.com/repos/${GH_REPO}/actions/caches`;
|
|
155
|
+
return new Promise((resolve, reject) => {
|
|
156
|
+
axios.get(url, {
|
|
157
|
+
headers: {
|
|
158
|
+
Accept: "application/vnd.github.v3+json",
|
|
159
|
+
Authorization: `token ${ACCESS_TOKEN}`
|
|
160
|
+
}
|
|
161
|
+
}).then((response) => {
|
|
162
|
+
const data = response.data.actions_caches;
|
|
163
|
+
const grouped = groupCachesByPrefix(data, prefixDepth);
|
|
164
|
+
resolve(grouped);
|
|
165
|
+
}).catch((error) => {
|
|
166
|
+
reject(error);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
module.exports = {
|
|
171
|
+
deleteGitHubActionsCache,
|
|
172
|
+
getCachePrefix,
|
|
173
|
+
getMeaningfulCacheKeyParts,
|
|
174
|
+
get_caches,
|
|
175
|
+
groupCachesByPrefix,
|
|
176
|
+
isChecksumSegment,
|
|
177
|
+
normalizePrefixDepth
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export {
|
|
183
|
+
require_clean_github_actions_caches
|
|
184
|
+
};
|
|
@@ -2,6 +2,9 @@ import { createRequire } from 'module'; const require = createRequire(import.met
|
|
|
2
2
|
import {
|
|
3
3
|
require_fetchResponse
|
|
4
4
|
} from "./chunk-KLKAIFKI.mjs";
|
|
5
|
+
import {
|
|
6
|
+
require_config
|
|
7
|
+
} from "./chunk-PAZH45HS.mjs";
|
|
5
8
|
import {
|
|
6
9
|
require_findEnvFiles
|
|
7
10
|
} from "./chunk-H44UWUFY.mjs";
|
|
@@ -16,6 +19,7 @@ import {
|
|
|
16
19
|
// src/package-resolutions-updater.mjs
|
|
17
20
|
init_esm_shims();
|
|
18
21
|
var utils = __toESM(require_utils(), 1);
|
|
22
|
+
var import_config = __toESM(require_config(), 1);
|
|
19
23
|
var import_fetchResponse = __toESM(require_fetchResponse(), 1);
|
|
20
24
|
var import_findEnvFiles = __toESM(require_findEnvFiles(), 1);
|
|
21
25
|
import * as dotenv from "dotenv";
|
|
@@ -38,7 +42,6 @@ if (!fs.existsSync(envPath)) {
|
|
|
38
42
|
if (fs.existsSync(envPath)) {
|
|
39
43
|
dotenv.config({ path: envPath, quiet: true, override: true });
|
|
40
44
|
}
|
|
41
|
-
var ACCESS_TOKEN = process.env.ACCESS_TOKEN || process.env.GITHUB_TOKEN;
|
|
42
45
|
if (args.help || args.h) {
|
|
43
46
|
showHelp();
|
|
44
47
|
}
|
|
@@ -103,7 +106,7 @@ async function fetchJson(url) {
|
|
|
103
106
|
"User-Agent": selectedUserAgent,
|
|
104
107
|
Accept: "application/vnd.github.v3+json",
|
|
105
108
|
"X-GitHub-Api-Version": "2022-11-28",
|
|
106
|
-
...
|
|
109
|
+
...import_config.GITHUB_ACCESS_TOKEN ? { Authorization: `token ${import_config.GITHUB_ACCESS_TOKEN}` } : {}
|
|
107
110
|
},
|
|
108
111
|
responseType: "json"
|
|
109
112
|
});
|
|
@@ -0,0 +1,226 @@
|
|
|
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
|
+
};
|