binary-collections 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dir-tree.cmd +7 -0
- package/bin/git-diff +4 -0
- package/bin/git-diff.cmd +5 -2
- package/bin/{git-fix-encoding → git-fix} +1 -4
- package/bin/git-fix.cmd +7 -0
- package/bin/nodekill +0 -0
- package/bin/nodekill.ps1 +0 -0
- package/bin/{submodule → submodule.txt} +0 -0
- package/lib/binary-collections-config.cjs +14 -0
- package/lib/binary-collections-config.d.mts +18 -0
- package/lib/binary-collections-config.d.ts +16 -0
- package/lib/binary-collections-config.js +39 -0
- package/lib/binary-collections-config.mjs +6 -0
- package/lib/binary-collections.cjs +105 -0
- package/lib/binary-collections.d.cts +2 -0
- package/lib/binary-collections.d.mts +121 -0
- package/lib/binary-collections.d.ts +121 -0
- package/lib/binary-collections.mjs +108 -0
- package/lib/chunk-4BYBVEYC.mjs +30 -0
- package/lib/{chunk-FB6YIQYR.mjs → chunk-AASHBCRW.mjs} +17 -2
- package/lib/chunk-APBWENF6.mjs +135 -0
- package/lib/{chunk-4LEXWIIF.mjs → chunk-DPKAJKFO.mjs} +2 -4
- package/lib/chunk-EGSSKVDH.mjs +66 -0
- package/lib/{chunk-3LOB2P54.mjs → chunk-G3THLIDT.mjs} +3 -5
- package/lib/chunk-JGR2NW6D.mjs +187 -0
- package/lib/chunk-ONIBBBQ3.mjs +108 -0
- package/lib/chunk-SH3L6HHV.mjs +27 -0
- package/lib/chunk-VVEZVNIV.mjs +81 -0
- package/lib/{chunk-JL32QDSH.mjs → chunk-W3ENOM53.mjs} +2 -4
- package/lib/chunk-YV7DO3YV.mjs +48 -0
- package/lib/{chunk-BSD5CIRU.mjs → chunk-YX5U7XDR.mjs} +11 -5
- package/lib/chunk-ZYAQRPUL.mjs +28 -0
- package/lib/clean-github-actions-caches.cjs +162 -0
- package/lib/clean-github-actions-caches.d.cts +1 -0
- package/lib/clean-github-actions-caches.d.mts +169 -0
- package/lib/clean-github-actions-caches.d.ts +169 -0
- package/lib/clean-github-actions-caches.mjs +132 -0
- package/lib/del-gradle.cjs +87 -3
- package/lib/del-gradle.js +1 -1
- package/lib/del-gradle.mjs +4 -6
- package/lib/del-node-modules.cjs +86 -2
- package/lib/del-node-modules.mjs +3 -5
- package/lib/del-ps.cjs +89 -5
- package/lib/del-ps.js +2 -2
- package/lib/del-ps.mjs +6 -8
- package/lib/del-yarn-caches.cjs +86 -2
- package/lib/del-yarn-caches.mjs +3 -5
- package/lib/find-node-modules-cli.cjs +8 -0
- package/lib/find-node-modules-cli.mjs +2 -3
- package/lib/find-node-modules.cjs +8 -0
- package/lib/find-node-modules.d.mts +3 -0
- package/lib/find-node-modules.d.ts +3 -0
- package/lib/find-node-modules.js +12 -0
- package/lib/find-node-modules.mjs +2 -3
- package/lib/git/gitattributes.cjs +171 -0
- package/lib/git/gitattributes.d.mts +35 -0
- package/lib/git/gitattributes.d.ts +33 -0
- package/lib/git/gitattributes.js +223 -0
- package/lib/git/gitattributes.mjs +6 -0
- package/lib/git/line-endings.cjs +74 -0
- package/lib/git/line-endings.d.cts +7 -0
- package/lib/git/line-endings.d.mts +83 -0
- package/lib/git/line-endings.d.ts +83 -0
- package/lib/git/line-endings.mjs +8 -0
- package/lib/git/normalize.cjs +42 -0
- package/lib/git/normalize.d.cts +6 -0
- package/lib/git/normalize.d.mts +43 -0
- package/lib/git/normalize.d.ts +43 -0
- package/lib/git/normalize.mjs +6 -0
- package/lib/git/permissions.cjs +15 -0
- package/lib/git/permissions.d.cts +6 -0
- package/lib/git/permissions.d.mts +17 -0
- package/lib/git/permissions.d.ts +17 -0
- package/lib/git/permissions.mjs +7 -0
- package/lib/git/pull-strategy.cjs +13 -0
- package/lib/git/pull-strategy.d.cts +5 -0
- package/lib/git/pull-strategy.d.mts +15 -0
- package/lib/git/pull-strategy.d.ts +15 -0
- package/lib/git/pull-strategy.mjs +7 -0
- package/lib/git/user-config.cjs +100 -0
- package/lib/git/user-config.d.cts +10 -0
- package/lib/git/user-config.d.mts +105 -0
- package/lib/git/user-config.d.ts +105 -0
- package/lib/git/user-config.mjs +8 -0
- package/lib/git/utils.cjs +70 -0
- package/lib/git/utils.d.cts +20 -0
- package/lib/git/utils.d.mts +69 -0
- package/lib/git/utils.d.ts +69 -0
- package/lib/git/utils.mjs +6 -0
- package/lib/git-diff.cjs +23 -24
- package/lib/git-diff.d.mts +25 -28
- package/lib/git-diff.d.ts +25 -28
- package/lib/git-diff.mjs +32 -27
- package/lib/git-fix.cjs +129 -0
- package/lib/git-fix.d.cts +2 -0
- package/lib/git-fix.d.mts +141 -0
- package/lib/git-fix.d.ts +141 -0
- package/lib/git-fix.mjs +151 -0
- package/lib/git-purge.cjs +86 -2
- package/lib/git-purge.mjs +3 -5
- package/lib/index.cjs +8 -0
- package/lib/index.mjs +3 -5
- package/lib/npm-run-series.cjs +140 -1
- package/lib/npm-run-series.js +2 -1
- package/lib/npm-run-series.mjs +7 -5
- package/lib/package-resolutions-updater.cjs +274 -0
- package/lib/package-resolutions-updater.d.mts +1 -0
- package/lib/package-resolutions-updater.d.ts +326 -0
- package/lib/package-resolutions-updater.mjs +316 -0
- package/lib/print-directory-tree.cjs +241 -0
- package/lib/print-directory-tree.d.cts +1 -0
- package/lib/print-directory-tree.d.mts +234 -0
- package/lib/print-directory-tree.d.ts +234 -0
- package/lib/print-directory-tree.mjs +182 -0
- package/lib/ps/connected-domain.mjs +2 -3
- package/lib/ps/index.cjs +3 -3
- package/lib/ps/index.d.mjs +1 -2
- package/lib/ps/index.js +6 -3
- package/lib/ps/index.mjs +9 -11
- package/lib/ps/isWin.mjs +2 -3
- package/lib/ps/table-parser.mjs +3 -4
- package/lib/submodule-install.cjs +13 -31
- package/lib/submodule-install.d.mts +12 -32
- package/lib/submodule-install.d.ts +12 -32
- package/lib/submodule-install.mjs +16 -25
- package/lib/utils.cjs +86 -2
- package/lib/utils.d.mts +29 -9
- package/lib/utils.d.ts +28 -8
- package/lib/utils.js +139 -8
- package/lib/utils.mjs +2 -3
- package/lib/yarn-reinstall.cjs +9 -7
- package/lib/yarn-reinstall.d.mts +12 -8
- package/lib/yarn-reinstall.d.ts +12 -8
- package/lib/yarn-reinstall.mjs +14 -10
- package/package.json +109 -80
- package/readme.md +74 -11
- package/src/package-resolutions-updater.mjs +325 -0
- package/src/print-directory-tree.cjs +234 -0
- package/src/ps/index.js +4 -3
- package/src/yarn-reinstall.cjs +49 -0
- package/test-project/package.json +16 -0
- package/tmp/test-repo/package.json +7 -0
- package/bin/git-fix-encoding.cmd +0 -6
- package/lib/chunk-OKYLF2MU.mjs +0 -53
- package/lib/chunk-VXZQNLPU.mjs +0 -23
- package/lib/package-resolutions.cjs +0 -28
- package/lib/package-resolutions.d.mts +0 -25
- package/lib/package-resolutions.d.ts +0 -25
- package/lib/package-resolutions.mjs +0 -31
- /package/bin/{submodule-install → submodule-install.txt} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const gch = require("git-command-helper");
|
|
2
|
+
const { runGitCommand, runGitCommandOutput } = require("./utils.cjs");
|
|
3
|
+
const { getArgs } = require("../utils.js");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configure Git user from CLI arguments or environment variables
|
|
7
|
+
* @param {string|null} cliUser - Username from CLI arguments
|
|
8
|
+
* @param {string|null} cliEmail - Email from CLI arguments
|
|
9
|
+
* @param {object} [options] - Options object
|
|
10
|
+
* @param {boolean} [options.updateRemote] - If true, update remote URL without prompt
|
|
11
|
+
*/
|
|
12
|
+
function configureGitUser(cliUser = null, cliEmail = null, options = {}) {
|
|
13
|
+
console.log("\n=== Configuring Git User ===");
|
|
14
|
+
|
|
15
|
+
// Determine user and email with CLI args taking precedence
|
|
16
|
+
let username, email;
|
|
17
|
+
|
|
18
|
+
if (cliUser && cliEmail) {
|
|
19
|
+
username = cliUser.trim();
|
|
20
|
+
email = cliEmail.trim();
|
|
21
|
+
console.log("[i] Using CLI-provided user configuration");
|
|
22
|
+
} else {
|
|
23
|
+
username = process.env.GITHUB_USER ? process.env.GITHUB_USER.trim() : undefined;
|
|
24
|
+
email = process.env.GITHUB_EMAIL ? process.env.GITHUB_EMAIL.trim() : undefined;
|
|
25
|
+
if (username || email) {
|
|
26
|
+
console.log("[i] Using environment variable user configuration");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!username && !email) {
|
|
31
|
+
console.log("[i] No Git user configuration needed (no CLI args or environment variables set)");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (username) {
|
|
36
|
+
const success = runGitCommand(["config", "user.name", username], `Set Git username to "${username}"`);
|
|
37
|
+
if (!success) {
|
|
38
|
+
console.log("[i] Failed to set Git username, but continuing...");
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
console.log("[i] No username provided, skipping username configuration");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (email) {
|
|
45
|
+
const success = runGitCommand(["config", "user.email", email], `Set Git email to "${email}"`);
|
|
46
|
+
if (!success) {
|
|
47
|
+
console.log("[i] Failed to set Git email, but continuing...");
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
console.log("[i] No email provided, skipping email configuration");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (username || email) {
|
|
54
|
+
console.log("[✓] Git user configuration completed");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (username) {
|
|
58
|
+
// Ask user to modify the origin remote URL if it doesn't match the username
|
|
59
|
+
const remoteUrl = runGitCommandOutput(["remote", "get-url", "origin"], "Fetching remote URL for verification");
|
|
60
|
+
if (remoteUrl) {
|
|
61
|
+
console.log(`[i] Remote URL: ${remoteUrl}`);
|
|
62
|
+
const parsedUrl = gch.parseGitHubUrl(remoteUrl);
|
|
63
|
+
if (parsedUrl && parsedUrl.owner && username && parsedUrl.owner.toLowerCase() !== username.toLowerCase()) {
|
|
64
|
+
console.warn(
|
|
65
|
+
`\n[!] The GitHub remote owner ("${parsedUrl.owner}") does not match the configured username ("${username}").`
|
|
66
|
+
);
|
|
67
|
+
console.warn(`[!] If this is not intentional, consider updating the remote URL to use your username.`);
|
|
68
|
+
console.warn(`[!] Example: git remote set-url origin https://github.com/${username}/<repo>.git\n`);
|
|
69
|
+
// Check for --update-remote CLI argument or options.updateRemote
|
|
70
|
+
const args = getArgs();
|
|
71
|
+
const updateRemote = options.updateRemote || args["update-remote"] === true;
|
|
72
|
+
if (updateRemote) {
|
|
73
|
+
// Only update the username in the URL, not the repo path
|
|
74
|
+
let newUrl = remoteUrl;
|
|
75
|
+
// Handle https:// and git@ URLs
|
|
76
|
+
if (/^https:\/\//.test(remoteUrl)) {
|
|
77
|
+
newUrl = remoteUrl.replace(/https:\/\/(?:[^@]+@)?github.com/, `https://${username}@github.com`);
|
|
78
|
+
} else if (/^git@github.com:/.test(remoteUrl)) {
|
|
79
|
+
// For git@github.com:user/repo.git, do not change path, just warn user to use HTTPS with username if needed
|
|
80
|
+
console.warn(
|
|
81
|
+
`[!] For SSH remotes, set your SSH config or use HTTPS with username if you want to change authentication user.`
|
|
82
|
+
);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (newUrl !== remoteUrl) {
|
|
86
|
+
const updated = runGitCommand(["remote", "set-url", "origin", newUrl], `Set origin to ${newUrl}`);
|
|
87
|
+
if (updated) {
|
|
88
|
+
console.log(`[✓] Remote URL updated to: ${newUrl}`);
|
|
89
|
+
} else {
|
|
90
|
+
console.warn(`[!] Failed to update remote URL. Please update it manually if needed.`);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
console.log(`[i] Remote URL does not use HTTPS or already contains the username.`);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
console.log(`[i] Remote URL not changed. Use --update-remote to update automatically.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
configureGitUser
|
|
105
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const gch = require("git-command-helper");
|
|
2
|
+
const { runGitCommand, runGitCommandOutput } = require("./utils.cjs");
|
|
3
|
+
const { getArgs } = require("../utils.js");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configure Git user from CLI arguments or environment variables
|
|
7
|
+
* @param {string|null} cliUser - Username from CLI arguments
|
|
8
|
+
* @param {string|null} cliEmail - Email from CLI arguments
|
|
9
|
+
* @param {object} [options] - Options object
|
|
10
|
+
* @param {boolean} [options.updateRemote] - If true, update remote URL without prompt
|
|
11
|
+
*/
|
|
12
|
+
function configureGitUser(cliUser = null, cliEmail = null, options = {}) {
|
|
13
|
+
console.log("\n=== Configuring Git User ===");
|
|
14
|
+
|
|
15
|
+
// Determine user and email with CLI args taking precedence
|
|
16
|
+
let username, email;
|
|
17
|
+
|
|
18
|
+
if (cliUser && cliEmail) {
|
|
19
|
+
username = cliUser.trim();
|
|
20
|
+
email = cliEmail.trim();
|
|
21
|
+
console.log("[i] Using CLI-provided user configuration");
|
|
22
|
+
} else {
|
|
23
|
+
username = process.env.GITHUB_USER ? process.env.GITHUB_USER.trim() : undefined;
|
|
24
|
+
email = process.env.GITHUB_EMAIL ? process.env.GITHUB_EMAIL.trim() : undefined;
|
|
25
|
+
if (username || email) {
|
|
26
|
+
console.log("[i] Using environment variable user configuration");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!username && !email) {
|
|
31
|
+
console.log("[i] No Git user configuration needed (no CLI args or environment variables set)");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (username) {
|
|
36
|
+
const success = runGitCommand(["config", "user.name", username], `Set Git username to "${username}"`);
|
|
37
|
+
if (!success) {
|
|
38
|
+
console.log("[i] Failed to set Git username, but continuing...");
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
console.log("[i] No username provided, skipping username configuration");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (email) {
|
|
45
|
+
const success = runGitCommand(["config", "user.email", email], `Set Git email to "${email}"`);
|
|
46
|
+
if (!success) {
|
|
47
|
+
console.log("[i] Failed to set Git email, but continuing...");
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
console.log("[i] No email provided, skipping email configuration");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (username || email) {
|
|
54
|
+
console.log("[✓] Git user configuration completed");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (username) {
|
|
58
|
+
// Ask user to modify the origin remote URL if it doesn't match the username
|
|
59
|
+
const remoteUrl = runGitCommandOutput(["remote", "get-url", "origin"], "Fetching remote URL for verification");
|
|
60
|
+
if (remoteUrl) {
|
|
61
|
+
console.log(`[i] Remote URL: ${remoteUrl}`);
|
|
62
|
+
const parsedUrl = gch.parseGitHubUrl(remoteUrl);
|
|
63
|
+
if (parsedUrl && parsedUrl.owner && username && parsedUrl.owner.toLowerCase() !== username.toLowerCase()) {
|
|
64
|
+
console.warn(
|
|
65
|
+
`\n[!] The GitHub remote owner ("${parsedUrl.owner}") does not match the configured username ("${username}").`
|
|
66
|
+
);
|
|
67
|
+
console.warn(`[!] If this is not intentional, consider updating the remote URL to use your username.`);
|
|
68
|
+
console.warn(`[!] Example: git remote set-url origin https://github.com/${username}/<repo>.git\n`);
|
|
69
|
+
// Check for --update-remote CLI argument or options.updateRemote
|
|
70
|
+
const args = getArgs();
|
|
71
|
+
const updateRemote = options.updateRemote || args["update-remote"] === true;
|
|
72
|
+
if (updateRemote) {
|
|
73
|
+
// Only update the username in the URL, not the repo path
|
|
74
|
+
let newUrl = remoteUrl;
|
|
75
|
+
// Handle https:// and git@ URLs
|
|
76
|
+
if (/^https:\/\//.test(remoteUrl)) {
|
|
77
|
+
newUrl = remoteUrl.replace(/https:\/\/(?:[^@]+@)?github.com/, `https://${username}@github.com`);
|
|
78
|
+
} else if (/^git@github.com:/.test(remoteUrl)) {
|
|
79
|
+
// For git@github.com:user/repo.git, do not change path, just warn user to use HTTPS with username if needed
|
|
80
|
+
console.warn(
|
|
81
|
+
`[!] For SSH remotes, set your SSH config or use HTTPS with username if you want to change authentication user.`
|
|
82
|
+
);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (newUrl !== remoteUrl) {
|
|
86
|
+
const updated = runGitCommand(["remote", "set-url", "origin", newUrl], `Set origin to ${newUrl}`);
|
|
87
|
+
if (updated) {
|
|
88
|
+
console.log(`[✓] Remote URL updated to: ${newUrl}`);
|
|
89
|
+
} else {
|
|
90
|
+
console.warn(`[!] Failed to update remote URL. Please update it manually if needed.`);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
console.log(`[i] Remote URL does not use HTTPS or already contains the username.`);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
console.log(`[i] Remote URL not changed. Use --update-remote to update automatically.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
configureGitUser
|
|
105
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
require_user_config
|
|
4
|
+
} from "../chunk-ONIBBBQ3.mjs";
|
|
5
|
+
import "../chunk-EGSSKVDH.mjs";
|
|
6
|
+
import "../chunk-APBWENF6.mjs";
|
|
7
|
+
import "../chunk-AASHBCRW.mjs";
|
|
8
|
+
export default require_user_config();
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { execSync, spawnSync } = require("child_process");
|
|
3
|
+
/**
|
|
4
|
+
* Execute a git command with proper error handling and logging
|
|
5
|
+
* @param {string[]} args - Git command arguments
|
|
6
|
+
* @param {string} description - Description of the operation for logging
|
|
7
|
+
* @returns {boolean} - True if successful, false otherwise
|
|
8
|
+
*/
|
|
9
|
+
function runGitCommand(args, description) {
|
|
10
|
+
try {
|
|
11
|
+
console.log(`[i] ${description}`);
|
|
12
|
+
const result = spawnSync("git", args, { encoding: "utf-8" });
|
|
13
|
+
if (result.status !== 0) {
|
|
14
|
+
console.error(`[✗] Failed: ${description}`);
|
|
15
|
+
console.error(`Error: ${result.stderr || result.stdout}`);
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
console.log(`[✓] ${description}`);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error(`[✗] Failed: ${description}`);
|
|
23
|
+
console.error(`Error: ${error.message}`);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if the given cwd (or current directory) is a git repository
|
|
29
|
+
* @param {string} [cwd] - Directory to check (defaults to current directory at call time)
|
|
30
|
+
* @returns {boolean} - True if in a git repository, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
function isGitRepository(cwd) {
|
|
33
|
+
const dir = typeof cwd === "string" ? cwd : process.cwd();
|
|
34
|
+
try {
|
|
35
|
+
execSync("git rev-parse --git-dir", { stdio: "pipe", cwd: dir });
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
catch (_a) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Execute a git command and return stdout (or null on error)
|
|
44
|
+
* @param {string[]} args - Git command arguments
|
|
45
|
+
* @param {string} description - Description of the operation for logging
|
|
46
|
+
* @returns {string|null} - stdout string if successful, null otherwise
|
|
47
|
+
*/
|
|
48
|
+
function runGitCommandOutput(args, description) {
|
|
49
|
+
try {
|
|
50
|
+
console.log(`[i] ${description}`);
|
|
51
|
+
const result = spawnSync("git", args, { encoding: "utf-8" });
|
|
52
|
+
if (result.status !== 0) {
|
|
53
|
+
console.error(`[✗] Failed: ${description}`);
|
|
54
|
+
console.error(`Error: ${result.stderr || result.stdout}`);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
console.log(`[✓] ${description}`);
|
|
58
|
+
return result.stdout.trim();
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error(`[✗] Failed: ${description}`);
|
|
62
|
+
console.error(`Error: ${error.message}`);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
module.exports = {
|
|
67
|
+
runGitCommand,
|
|
68
|
+
runGitCommandOutput,
|
|
69
|
+
isGitRepository
|
|
70
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a git command with proper error handling and logging
|
|
3
|
+
* @param {string[]} args - Git command arguments
|
|
4
|
+
* @param {string} description - Description of the operation for logging
|
|
5
|
+
* @returns {boolean} - True if successful, false otherwise
|
|
6
|
+
*/
|
|
7
|
+
export function runGitCommand(args: string[], description: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Execute a git command and return stdout (or null on error)
|
|
10
|
+
* @param {string[]} args - Git command arguments
|
|
11
|
+
* @param {string} description - Description of the operation for logging
|
|
12
|
+
* @returns {string|null} - stdout string if successful, null otherwise
|
|
13
|
+
*/
|
|
14
|
+
export function runGitCommandOutput(args: string[], description: string): string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Check if the given cwd (or current directory) is a git repository
|
|
17
|
+
* @param {string} [cwd] - Directory to check (defaults to current directory at call time)
|
|
18
|
+
* @returns {boolean} - True if in a git repository, false otherwise
|
|
19
|
+
*/
|
|
20
|
+
export function isGitRepository(cwd?: string): boolean;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const { execSync, spawnSync } = require("child_process");
|
|
2
|
+
/**
|
|
3
|
+
* Execute a git command with proper error handling and logging
|
|
4
|
+
* @param {string[]} args - Git command arguments
|
|
5
|
+
* @param {string} description - Description of the operation for logging
|
|
6
|
+
* @returns {boolean} - True if successful, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
function runGitCommand(args, description) {
|
|
9
|
+
try {
|
|
10
|
+
console.log(`[i] ${description}`);
|
|
11
|
+
const result = spawnSync("git", args, { encoding: "utf-8" });
|
|
12
|
+
if (result.status !== 0) {
|
|
13
|
+
console.error(`[✗] Failed: ${description}`);
|
|
14
|
+
console.error(`Error: ${result.stderr || result.stdout}`);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
console.log(`[✓] ${description}`);
|
|
18
|
+
return true;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(`[✗] Failed: ${description}`);
|
|
21
|
+
console.error(`Error: ${error.message}`);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if the given cwd (or current directory) is a git repository
|
|
28
|
+
* @param {string} [cwd] - Directory to check (defaults to current directory at call time)
|
|
29
|
+
* @returns {boolean} - True if in a git repository, false otherwise
|
|
30
|
+
*/
|
|
31
|
+
function isGitRepository(cwd) {
|
|
32
|
+
const dir = typeof cwd === "string" ? cwd : process.cwd();
|
|
33
|
+
try {
|
|
34
|
+
execSync("git rev-parse --git-dir", { stdio: "pipe", cwd: dir });
|
|
35
|
+
return true;
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Execute a git command and return stdout (or null on error)
|
|
43
|
+
* @param {string[]} args - Git command arguments
|
|
44
|
+
* @param {string} description - Description of the operation for logging
|
|
45
|
+
* @returns {string|null} - stdout string if successful, null otherwise
|
|
46
|
+
*/
|
|
47
|
+
function runGitCommandOutput(args, description) {
|
|
48
|
+
try {
|
|
49
|
+
console.log(`[i] ${description}`);
|
|
50
|
+
const result = spawnSync("git", args, { encoding: "utf-8" });
|
|
51
|
+
if (result.status !== 0) {
|
|
52
|
+
console.error(`[✗] Failed: ${description}`);
|
|
53
|
+
console.error(`Error: ${result.stderr || result.stdout}`);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
console.log(`[✓] ${description}`);
|
|
57
|
+
return result.stdout.trim();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error(`[✗] Failed: ${description}`);
|
|
60
|
+
console.error(`Error: ${error.message}`);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = {
|
|
66
|
+
runGitCommand,
|
|
67
|
+
runGitCommandOutput,
|
|
68
|
+
isGitRepository
|
|
69
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const { execSync, spawnSync } = require("child_process");
|
|
2
|
+
/**
|
|
3
|
+
* Execute a git command with proper error handling and logging
|
|
4
|
+
* @param {string[]} args - Git command arguments
|
|
5
|
+
* @param {string} description - Description of the operation for logging
|
|
6
|
+
* @returns {boolean} - True if successful, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
function runGitCommand(args, description) {
|
|
9
|
+
try {
|
|
10
|
+
console.log(`[i] ${description}`);
|
|
11
|
+
const result = spawnSync("git", args, { encoding: "utf-8" });
|
|
12
|
+
if (result.status !== 0) {
|
|
13
|
+
console.error(`[✗] Failed: ${description}`);
|
|
14
|
+
console.error(`Error: ${result.stderr || result.stdout}`);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
console.log(`[✓] ${description}`);
|
|
18
|
+
return true;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(`[✗] Failed: ${description}`);
|
|
21
|
+
console.error(`Error: ${error.message}`);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if the given cwd (or current directory) is a git repository
|
|
28
|
+
* @param {string} [cwd] - Directory to check (defaults to current directory at call time)
|
|
29
|
+
* @returns {boolean} - True if in a git repository, false otherwise
|
|
30
|
+
*/
|
|
31
|
+
function isGitRepository(cwd) {
|
|
32
|
+
const dir = typeof cwd === "string" ? cwd : process.cwd();
|
|
33
|
+
try {
|
|
34
|
+
execSync("git rev-parse --git-dir", { stdio: "pipe", cwd: dir });
|
|
35
|
+
return true;
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Execute a git command and return stdout (or null on error)
|
|
43
|
+
* @param {string[]} args - Git command arguments
|
|
44
|
+
* @param {string} description - Description of the operation for logging
|
|
45
|
+
* @returns {string|null} - stdout string if successful, null otherwise
|
|
46
|
+
*/
|
|
47
|
+
function runGitCommandOutput(args, description) {
|
|
48
|
+
try {
|
|
49
|
+
console.log(`[i] ${description}`);
|
|
50
|
+
const result = spawnSync("git", args, { encoding: "utf-8" });
|
|
51
|
+
if (result.status !== 0) {
|
|
52
|
+
console.error(`[✗] Failed: ${description}`);
|
|
53
|
+
console.error(`Error: ${result.stderr || result.stdout}`);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
console.log(`[✓] ${description}`);
|
|
57
|
+
return result.stdout.trim();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error(`[✗] Failed: ${description}`);
|
|
60
|
+
console.error(`Error: ${error.message}`);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = {
|
|
66
|
+
runGitCommand,
|
|
67
|
+
runGitCommandOutput,
|
|
68
|
+
isGitRepository
|
|
69
|
+
};
|
package/lib/git-diff.cjs
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
const { execSync } = require("child_process");
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const OUTPUT =
|
|
6
|
+
const { getTempPath } = require("./binary-collections-config");
|
|
7
|
+
// Output path using centralized temp directory configuration
|
|
8
|
+
const OUTPUT = getTempPath("git-diff.txt");
|
|
9
|
+
const CACHE_DIR = path.dirname(OUTPUT);
|
|
9
10
|
// Ensure output directory exists
|
|
10
11
|
if (!fs.existsSync(CACHE_DIR)) {
|
|
11
12
|
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
|
@@ -25,7 +26,10 @@ function showHelp() {
|
|
|
25
26
|
function runGitDiff(command, successMessage, errorMessage) {
|
|
26
27
|
try {
|
|
27
28
|
console.log(`[i] Running command: ${command}`);
|
|
28
|
-
const result = execSync(command, {
|
|
29
|
+
const result = execSync(command, {
|
|
30
|
+
encoding: "utf8",
|
|
31
|
+
maxBuffer: 1024 * 1024 * 10 // 10MB buffer to handle large diffs
|
|
32
|
+
});
|
|
29
33
|
// If result is empty, inform user but don't treat as error
|
|
30
34
|
if (!result || result.trim() === "") {
|
|
31
35
|
console.log(`[i] No changes found for the specified criteria`);
|
|
@@ -47,28 +51,23 @@ function runGitDiff(command, successMessage, errorMessage) {
|
|
|
47
51
|
process.exit(1);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
|
-
|
|
51
|
-
const args =
|
|
54
|
+
const { getArgs } = require("./utils.js");
|
|
55
|
+
const args = getArgs();
|
|
56
|
+
const positional = args._ || [];
|
|
52
57
|
// Show help if no arguments or --help/-h is passed
|
|
53
|
-
if (args
|
|
58
|
+
if (args.help || args.h) {
|
|
54
59
|
showHelp();
|
|
55
60
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
runGitDiff("git --no-pager diff", `Full staged diff saved to "${OUTPUT}"`, "Failed to save all diff's");
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
runGitDiff(`git --no-pager diff --cached -- "${file}"`, `Staged diff of "${file}" saved to "${OUTPUT}"`, `Failed to generate diff for "${file}"`);
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
61
|
+
if (args["staged-only"] || args.s || args.S) {
|
|
62
|
+
runGitDiff("git --no-pager diff --staged", `Full staged diff saved to "${OUTPUT}"`, "Failed to save staged diff");
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Handle specific file diff
|
|
66
|
+
const file = positional[0];
|
|
67
|
+
if (!file) {
|
|
68
|
+
runGitDiff("git --no-pager diff", `Full staged diff saved to "${OUTPUT}"`, "Failed to save all diff's");
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
runGitDiff(`git --no-pager diff --cached -- "${file}"`, `Staged diff of "${file}" saved to "${OUTPUT}"`, `Failed to generate diff for "${file}"`);
|
|
73
72
|
}
|
|
74
73
|
}
|
package/lib/git-diff.d.mts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
const { execSync } = require("child_process");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
+
const { getTempPath } = require("./binary-collections-config");
|
|
5
6
|
|
|
6
|
-
// Output path
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
// Output path using centralized temp directory configuration
|
|
8
|
+
const OUTPUT = getTempPath("git-diff.txt");
|
|
9
|
+
const CACHE_DIR = path.dirname(OUTPUT);
|
|
9
10
|
|
|
10
11
|
// Ensure output directory exists
|
|
11
12
|
if (!fs.existsSync(CACHE_DIR)) {
|
|
@@ -28,7 +29,10 @@ function showHelp() {
|
|
|
28
29
|
function runGitDiff(command, successMessage, errorMessage) {
|
|
29
30
|
try {
|
|
30
31
|
console.log(`[i] Running command: ${command}`);
|
|
31
|
-
const result = execSync(command, {
|
|
32
|
+
const result = execSync(command, {
|
|
33
|
+
encoding: "utf8",
|
|
34
|
+
maxBuffer: 1024 * 1024 * 10 // 10MB buffer to handle large diffs
|
|
35
|
+
});
|
|
32
36
|
|
|
33
37
|
// If result is empty, inform user but don't treat as error
|
|
34
38
|
if (!result || result.trim() === "") {
|
|
@@ -54,34 +58,27 @@ function runGitDiff(command, successMessage, errorMessage) {
|
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
const args =
|
|
61
|
+
const { getArgs } = require("./utils.js");
|
|
62
|
+
const args = getArgs();
|
|
63
|
+
const positional = args._ || [];
|
|
59
64
|
|
|
60
65
|
// Show help if no arguments or --help/-h is passed
|
|
61
|
-
if (args
|
|
66
|
+
if (args.help || args.h) {
|
|
62
67
|
showHelp();
|
|
63
68
|
}
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
} else {
|
|
79
|
-
runGitDiff(
|
|
80
|
-
`git --no-pager diff --cached -- "${file}"`,
|
|
81
|
-
`Staged diff of "${file}" saved to "${OUTPUT}"`,
|
|
82
|
-
`Failed to generate diff for "${file}"`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
70
|
+
if (args["staged-only"] || args.s || args.S) {
|
|
71
|
+
runGitDiff("git --no-pager diff --staged", `Full staged diff saved to "${OUTPUT}"`, "Failed to save staged diff");
|
|
72
|
+
} else {
|
|
73
|
+
// Handle specific file diff
|
|
74
|
+
const file = positional[0];
|
|
75
|
+
if (!file) {
|
|
76
|
+
runGitDiff("git --no-pager diff", `Full staged diff saved to "${OUTPUT}"`, "Failed to save all diff's");
|
|
77
|
+
} else {
|
|
78
|
+
runGitDiff(
|
|
79
|
+
`git --no-pager diff --cached -- "${file}"`,
|
|
80
|
+
`Staged diff of "${file}" saved to "${OUTPUT}"`,
|
|
81
|
+
`Failed to generate diff for "${file}"`
|
|
82
|
+
);
|
|
86
83
|
}
|
|
87
84
|
}
|