binary-collections 2.0.7 → 2.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/bin/dir-tree.cmd +7 -0
  2. package/bin/git-diff +4 -0
  3. package/bin/git-diff.cmd +5 -2
  4. package/bin/{git-fix-encoding → git-fix} +1 -4
  5. package/bin/git-fix.cmd +7 -0
  6. package/bin/nodekill +0 -0
  7. package/bin/nodekill.ps1 +0 -0
  8. package/bin/{submodule → submodule.txt} +0 -0
  9. package/lib/binary-collections-config.cjs +14 -0
  10. package/lib/binary-collections-config.d.mts +18 -0
  11. package/lib/binary-collections-config.d.ts +16 -0
  12. package/lib/binary-collections-config.js +39 -0
  13. package/lib/binary-collections-config.mjs +6 -0
  14. package/lib/binary-collections.cjs +123 -0
  15. package/lib/binary-collections.d.cts +2 -0
  16. package/lib/binary-collections.d.mts +137 -0
  17. package/lib/binary-collections.d.ts +137 -0
  18. package/lib/binary-collections.mjs +300 -0
  19. package/lib/changelog.cjs +328 -0
  20. package/lib/changelog.d.mts +2 -0
  21. package/lib/changelog.d.ts +1 -0
  22. package/lib/changelog.js +226 -0
  23. package/lib/changelog.mjs +199 -0
  24. package/lib/chunk-4BYBVEYC.mjs +30 -0
  25. package/lib/{chunk-FB6YIQYR.mjs → chunk-AASHBCRW.mjs} +17 -2
  26. package/lib/chunk-APBWENF6.mjs +135 -0
  27. package/lib/{chunk-4LEXWIIF.mjs → chunk-DPKAJKFO.mjs} +2 -4
  28. package/lib/chunk-EGSSKVDH.mjs +66 -0
  29. package/lib/{chunk-3LOB2P54.mjs → chunk-G3THLIDT.mjs} +3 -5
  30. package/lib/chunk-JGR2NW6D.mjs +187 -0
  31. package/lib/chunk-ONIBBBQ3.mjs +108 -0
  32. package/lib/chunk-SH3L6HHV.mjs +27 -0
  33. package/lib/chunk-VVEZVNIV.mjs +81 -0
  34. package/lib/{chunk-JL32QDSH.mjs → chunk-W3ENOM53.mjs} +2 -4
  35. package/lib/chunk-YV7DO3YV.mjs +48 -0
  36. package/lib/{chunk-BSD5CIRU.mjs → chunk-YX5U7XDR.mjs} +11 -5
  37. package/lib/chunk-ZYAQRPUL.mjs +28 -0
  38. package/lib/clean-github-actions-caches.cjs +162 -0
  39. package/lib/clean-github-actions-caches.d.cts +1 -0
  40. package/lib/clean-github-actions-caches.d.mts +169 -0
  41. package/lib/clean-github-actions-caches.d.ts +169 -0
  42. package/lib/clean-github-actions-caches.mjs +132 -0
  43. package/lib/del-gradle.cjs +87 -3
  44. package/lib/del-gradle.js +1 -1
  45. package/lib/del-gradle.mjs +4 -6
  46. package/lib/del-node-modules.cjs +86 -2
  47. package/lib/del-node-modules.mjs +3 -5
  48. package/lib/del-ps.cjs +89 -5
  49. package/lib/del-ps.js +2 -2
  50. package/lib/del-ps.mjs +6 -8
  51. package/lib/del-yarn-caches.cjs +86 -2
  52. package/lib/del-yarn-caches.mjs +3 -5
  53. package/lib/find-node-modules-cli.cjs +8 -0
  54. package/lib/find-node-modules-cli.mjs +2 -3
  55. package/lib/find-node-modules.cjs +8 -0
  56. package/lib/find-node-modules.d.mts +3 -0
  57. package/lib/find-node-modules.d.ts +3 -0
  58. package/lib/find-node-modules.js +12 -0
  59. package/lib/find-node-modules.mjs +2 -3
  60. package/lib/git/gitattributes.cjs +171 -0
  61. package/lib/git/gitattributes.d.mts +35 -0
  62. package/lib/git/gitattributes.d.ts +33 -0
  63. package/lib/git/gitattributes.js +223 -0
  64. package/lib/git/gitattributes.mjs +6 -0
  65. package/lib/git/line-endings.cjs +74 -0
  66. package/lib/git/line-endings.d.cts +7 -0
  67. package/lib/git/line-endings.d.mts +83 -0
  68. package/lib/git/line-endings.d.ts +83 -0
  69. package/lib/git/line-endings.mjs +8 -0
  70. package/lib/git/normalize.cjs +42 -0
  71. package/lib/git/normalize.d.cts +6 -0
  72. package/lib/git/normalize.d.mts +43 -0
  73. package/lib/git/normalize.d.ts +43 -0
  74. package/lib/git/normalize.mjs +6 -0
  75. package/lib/git/permissions.cjs +15 -0
  76. package/lib/git/permissions.d.cts +6 -0
  77. package/lib/git/permissions.d.mts +17 -0
  78. package/lib/git/permissions.d.ts +17 -0
  79. package/lib/git/permissions.mjs +7 -0
  80. package/lib/git/pull-strategy.cjs +13 -0
  81. package/lib/git/pull-strategy.d.cts +5 -0
  82. package/lib/git/pull-strategy.d.mts +15 -0
  83. package/lib/git/pull-strategy.d.ts +15 -0
  84. package/lib/git/pull-strategy.mjs +7 -0
  85. package/lib/git/user-config.cjs +100 -0
  86. package/lib/git/user-config.d.cts +10 -0
  87. package/lib/git/user-config.d.mts +105 -0
  88. package/lib/git/user-config.d.ts +105 -0
  89. package/lib/git/user-config.mjs +8 -0
  90. package/lib/git/utils.cjs +70 -0
  91. package/lib/git/utils.d.cts +20 -0
  92. package/lib/git/utils.d.mts +69 -0
  93. package/lib/git/utils.d.ts +69 -0
  94. package/lib/git/utils.mjs +6 -0
  95. package/lib/git-diff.cjs +23 -24
  96. package/lib/git-diff.d.mts +25 -28
  97. package/lib/git-diff.d.ts +25 -28
  98. package/lib/git-diff.mjs +32 -27
  99. package/lib/git-fix.cjs +129 -0
  100. package/lib/git-fix.d.cts +2 -0
  101. package/lib/git-fix.d.mts +141 -0
  102. package/lib/git-fix.d.ts +141 -0
  103. package/lib/git-fix.mjs +151 -0
  104. package/lib/git-purge.cjs +86 -2
  105. package/lib/git-purge.mjs +3 -5
  106. package/lib/index.cjs +8 -0
  107. package/lib/index.mjs +3 -5
  108. package/lib/npm-run-series.cjs +140 -1
  109. package/lib/npm-run-series.js +2 -1
  110. package/lib/npm-run-series.mjs +7 -5
  111. package/lib/package-resolutions-updater.cjs +447 -0
  112. package/lib/package-resolutions-updater.d.mts +1 -0
  113. package/lib/package-resolutions-updater.d.ts +352 -0
  114. package/lib/package-resolutions-updater.mjs +339 -0
  115. package/lib/print-directory-tree.cjs +241 -0
  116. package/lib/print-directory-tree.d.cts +1 -0
  117. package/lib/print-directory-tree.d.mts +234 -0
  118. package/lib/print-directory-tree.d.ts +234 -0
  119. package/lib/print-directory-tree.mjs +182 -0
  120. package/lib/ps/connected-domain.mjs +2 -3
  121. package/lib/ps/index.cjs +3 -3
  122. package/lib/ps/index.d.mjs +1 -2
  123. package/lib/ps/index.js +6 -3
  124. package/lib/ps/index.mjs +9 -11
  125. package/lib/ps/isWin.mjs +2 -3
  126. package/lib/ps/table-parser.mjs +3 -4
  127. package/lib/submodule-install.cjs +18 -35
  128. package/lib/submodule-install.d.mts +17 -37
  129. package/lib/submodule-install.d.ts +17 -37
  130. package/lib/submodule-install.mjs +21 -29
  131. package/lib/utils.cjs +86 -2
  132. package/lib/utils.d.mts +29 -9
  133. package/lib/utils.d.ts +28 -8
  134. package/lib/utils.js +139 -8
  135. package/lib/utils.mjs +2 -3
  136. package/lib/yarn-reinstall.cjs +9 -7
  137. package/lib/yarn-reinstall.d.mts +12 -8
  138. package/lib/yarn-reinstall.d.ts +12 -8
  139. package/lib/yarn-reinstall.mjs +14 -10
  140. package/package.json +109 -80
  141. package/readme.md +74 -11
  142. package/src/package-resolutions-updater.mjs +350 -0
  143. package/src/print-directory-tree.cjs +234 -0
  144. package/src/ps/index.js +4 -3
  145. package/src/yarn-reinstall.cjs +49 -0
  146. package/test-project/package.json +16 -0
  147. package/tmp/test-repo/package.json +7 -0
  148. package/bin/git-fix-encoding.cmd +0 -6
  149. package/lib/chunk-OKYLF2MU.mjs +0 -53
  150. package/lib/chunk-VXZQNLPU.mjs +0 -23
  151. package/lib/package-resolutions.cjs +0 -28
  152. package/lib/package-resolutions.d.mts +0 -25
  153. package/lib/package-resolutions.d.ts +0 -25
  154. package/lib/package-resolutions.mjs +0 -31
  155. /package/bin/{submodule-install → submodule-install.txt} +0 -0
@@ -0,0 +1,83 @@
1
+ const path = require("upath");
2
+ const fs = require("fs");
3
+ const { runGitCommand } = require("./utils.cjs");
4
+ const { updateGitAttributes } = require("./gitattributes.js");
5
+
6
+ /**
7
+ * Force LF line endings configuration
8
+ * - Sets core.autocrlf = false
9
+ * - Sets core.eol = lf
10
+ * - Creates/updates .gitattributes with proper line ending rules
11
+ */
12
+ function forceLfLineEndings() {
13
+ console.log("\n=== Configuring LF Line Endings ===");
14
+
15
+ // Force LF line endings
16
+ runGitCommand(["config", "core.autocrlf", "false"], "Disable automatic CRLF conversion");
17
+ runGitCommand(["config", "core.eol", "lf"], "Set end-of-line to LF");
18
+
19
+ // Create or update .gitattributes
20
+ const gitattributesPath = path.join(process.cwd(), ".gitattributes");
21
+
22
+ // Always ensure the universal LF rule is present, even if file exists
23
+ if (fs.existsSync(gitattributesPath)) {
24
+ let content = fs.readFileSync(gitattributesPath, "utf8");
25
+ // Match * text=auto eol=lf with any whitespace (space or tab) between tokens
26
+ if (!/^\*\s+text=auto\s+eol=lf/m.test(content)) {
27
+ content = `* text=auto eol=lf\n` + content;
28
+ fs.writeFileSync(gitattributesPath, content);
29
+ }
30
+ }
31
+
32
+ // Define desired rules with priorities
33
+ const desiredRules = [
34
+ { pattern: "*", attributes: "text=auto eol=lf", priority: 1 },
35
+ {
36
+ pattern: "*.{cmd,bat,ps1,sh,cmd1,cmd2,bat1,bat2,vbs}",
37
+ attributes: "text eol=crlf",
38
+ priority: 2
39
+ },
40
+ {
41
+ pattern: "*.{png,jpg,jpeg,gif,ico,svg,bmp,webp,avif,tiff,tif,psd,ai,eps,raw}",
42
+ attributes: "binary",
43
+ priority: 3
44
+ },
45
+ {
46
+ pattern:
47
+ "*.{zip,tar,gz,7z,rar,exe,dll,so,bin,jar,war,ear,apk,msi,deb,rpm,iso,img,dmg,pdf,mp3,mp4,mov,avi,mkv,flv,wmv,ogg,webm,wav,aac,m4a,otf,ttf,woff,woff2,eot}",
48
+ attributes: "binary",
49
+ priority: 3
50
+ }
51
+ ];
52
+
53
+ // Update .gitattributes using the dedicated module
54
+ const result = updateGitAttributes(gitattributesPath, desiredRules);
55
+
56
+ // Report results
57
+ if (result.error) {
58
+ console.log(`[✗] Error updating .gitattributes: ${result.error}`);
59
+ return;
60
+ }
61
+
62
+ // Report conflicts if any
63
+ if (result.conflicts.length > 0) {
64
+ console.log("\n[!] Detected conflicts in .gitattributes:");
65
+ result.conflicts.forEach((conflict) => {
66
+ console.log(` ${conflict.pattern}: ${conflict.existing} -> ${conflict.proposed} (${conflict.action})`);
67
+ });
68
+ }
69
+
70
+ // Report changes
71
+ if (result.success) {
72
+ console.log(`[✓] ${result.message}:`);
73
+ result.changes.forEach((change) => {
74
+ console.log(` ${change.action}: ${change.pattern} ${change.attributes}`);
75
+ });
76
+ } else {
77
+ console.log(`[i] ${result.message}`);
78
+ }
79
+ }
80
+
81
+ module.exports = {
82
+ forceLfLineEndings
83
+ };
@@ -0,0 +1,8 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_line_endings
4
+ } from "../chunk-VVEZVNIV.mjs";
5
+ import "../chunk-JGR2NW6D.mjs";
6
+ import "../chunk-EGSSKVDH.mjs";
7
+ import "../chunk-AASHBCRW.mjs";
8
+ export default require_line_endings();
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ const { execSync } = require("child_process");
3
+ /**
4
+ * Normalize line endings in existing tracked files
5
+ * - Refreshes the git index to detect line ending changes
6
+ * - Applies renormalization to all tracked files
7
+ */
8
+ function normalizeLineEndings() {
9
+ console.log("\n=== Normalizing Existing Files ===");
10
+ try {
11
+ // Check if there are any tracked files
12
+ const result = execSync("git ls-files", { encoding: "utf-8", stdio: "pipe" });
13
+ if (!result.trim()) {
14
+ console.log("[i] No tracked files to normalize");
15
+ return;
16
+ }
17
+ console.log("[i] Refreshing index to detect line ending changes...");
18
+ execSync("git add --renormalize .", { stdio: "pipe" });
19
+ // Check if there are changes after normalization
20
+ try {
21
+ const statusResult = execSync("git status --porcelain", { encoding: "utf-8", stdio: "pipe" });
22
+ if (statusResult.trim()) {
23
+ console.log("[✓] Line endings normalized for tracked files");
24
+ console.log("[i] Files with updated line endings are now staged");
25
+ console.log("[i] Run 'git status' to see the changes");
26
+ }
27
+ else {
28
+ console.log("[✓] All files already have correct line endings");
29
+ }
30
+ }
31
+ catch (_a) {
32
+ console.log("[✓] Line ending normalization completed");
33
+ }
34
+ }
35
+ catch (error) {
36
+ console.error("[✗] Failed to normalize line endings");
37
+ console.error(`Error: ${error.message}`);
38
+ }
39
+ }
40
+ module.exports = {
41
+ normalizeLineEndings
42
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Normalize line endings in existing tracked files
3
+ * - Refreshes the git index to detect line ending changes
4
+ * - Applies renormalization to all tracked files
5
+ */
6
+ export function normalizeLineEndings(): void;
@@ -0,0 +1,43 @@
1
+ const { execSync } = require("child_process");
2
+
3
+ /**
4
+ * Normalize line endings in existing tracked files
5
+ * - Refreshes the git index to detect line ending changes
6
+ * - Applies renormalization to all tracked files
7
+ */
8
+ function normalizeLineEndings() {
9
+ console.log("\n=== Normalizing Existing Files ===");
10
+
11
+ try {
12
+ // Check if there are any tracked files
13
+ const result = execSync("git ls-files", { encoding: "utf-8", stdio: "pipe" });
14
+ if (!result.trim()) {
15
+ console.log("[i] No tracked files to normalize");
16
+ return;
17
+ }
18
+
19
+ console.log("[i] Refreshing index to detect line ending changes...");
20
+ execSync("git add --renormalize .", { stdio: "pipe" });
21
+
22
+ // Check if there are changes after normalization
23
+ try {
24
+ const statusResult = execSync("git status --porcelain", { encoding: "utf-8", stdio: "pipe" });
25
+ if (statusResult.trim()) {
26
+ console.log("[✓] Line endings normalized for tracked files");
27
+ console.log("[i] Files with updated line endings are now staged");
28
+ console.log("[i] Run 'git status' to see the changes");
29
+ } else {
30
+ console.log("[✓] All files already have correct line endings");
31
+ }
32
+ } catch {
33
+ console.log("[✓] Line ending normalization completed");
34
+ }
35
+ } catch (error) {
36
+ console.error("[✗] Failed to normalize line endings");
37
+ console.error(`Error: ${error.message}`);
38
+ }
39
+ }
40
+
41
+ module.exports = {
42
+ normalizeLineEndings
43
+ };
@@ -0,0 +1,43 @@
1
+ const { execSync } = require("child_process");
2
+
3
+ /**
4
+ * Normalize line endings in existing tracked files
5
+ * - Refreshes the git index to detect line ending changes
6
+ * - Applies renormalization to all tracked files
7
+ */
8
+ function normalizeLineEndings() {
9
+ console.log("\n=== Normalizing Existing Files ===");
10
+
11
+ try {
12
+ // Check if there are any tracked files
13
+ const result = execSync("git ls-files", { encoding: "utf-8", stdio: "pipe" });
14
+ if (!result.trim()) {
15
+ console.log("[i] No tracked files to normalize");
16
+ return;
17
+ }
18
+
19
+ console.log("[i] Refreshing index to detect line ending changes...");
20
+ execSync("git add --renormalize .", { stdio: "pipe" });
21
+
22
+ // Check if there are changes after normalization
23
+ try {
24
+ const statusResult = execSync("git status --porcelain", { encoding: "utf-8", stdio: "pipe" });
25
+ if (statusResult.trim()) {
26
+ console.log("[✓] Line endings normalized for tracked files");
27
+ console.log("[i] Files with updated line endings are now staged");
28
+ console.log("[i] Run 'git status' to see the changes");
29
+ } else {
30
+ console.log("[✓] All files already have correct line endings");
31
+ }
32
+ } catch {
33
+ console.log("[✓] Line ending normalization completed");
34
+ }
35
+ } catch (error) {
36
+ console.error("[✗] Failed to normalize line endings");
37
+ console.error(`Error: ${error.message}`);
38
+ }
39
+ }
40
+
41
+ module.exports = {
42
+ normalizeLineEndings
43
+ };
@@ -0,0 +1,6 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_normalize
4
+ } from "../chunk-YV7DO3YV.mjs";
5
+ import "../chunk-AASHBCRW.mjs";
6
+ export default require_normalize();
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ const { runGitCommand } = require("./utils.cjs");
3
+ /**
4
+ * Configure git to ignore file permission changes
5
+ * - Sets core.filemode = false
6
+ * - Sets diff.ignoreSubmodules = dirty
7
+ */
8
+ function ignoreFilePermissions() {
9
+ console.log("\n=== Configuring File Permissions ===");
10
+ runGitCommand(["config", "core.filemode", "false"], "Ignore file permission changes");
11
+ runGitCommand(["config", "diff.ignoreSubmodules", "dirty"], "Ignore submodule permission changes");
12
+ }
13
+ module.exports = {
14
+ ignoreFilePermissions
15
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Configure git to ignore file permission changes
3
+ * - Sets core.filemode = false
4
+ * - Sets diff.ignoreSubmodules = dirty
5
+ */
6
+ export function ignoreFilePermissions(): void;
@@ -0,0 +1,17 @@
1
+ const { runGitCommand } = require("./utils.cjs");
2
+
3
+ /**
4
+ * Configure git to ignore file permission changes
5
+ * - Sets core.filemode = false
6
+ * - Sets diff.ignoreSubmodules = dirty
7
+ */
8
+ function ignoreFilePermissions() {
9
+ console.log("\n=== Configuring File Permissions ===");
10
+
11
+ runGitCommand(["config", "core.filemode", "false"], "Ignore file permission changes");
12
+ runGitCommand(["config", "diff.ignoreSubmodules", "dirty"], "Ignore submodule permission changes");
13
+ }
14
+
15
+ module.exports = {
16
+ ignoreFilePermissions
17
+ };
@@ -0,0 +1,17 @@
1
+ const { runGitCommand } = require("./utils.cjs");
2
+
3
+ /**
4
+ * Configure git to ignore file permission changes
5
+ * - Sets core.filemode = false
6
+ * - Sets diff.ignoreSubmodules = dirty
7
+ */
8
+ function ignoreFilePermissions() {
9
+ console.log("\n=== Configuring File Permissions ===");
10
+
11
+ runGitCommand(["config", "core.filemode", "false"], "Ignore file permission changes");
12
+ runGitCommand(["config", "diff.ignoreSubmodules", "dirty"], "Ignore submodule permission changes");
13
+ }
14
+
15
+ module.exports = {
16
+ ignoreFilePermissions
17
+ };
@@ -0,0 +1,7 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_permissions
4
+ } from "../chunk-ZYAQRPUL.mjs";
5
+ import "../chunk-EGSSKVDH.mjs";
6
+ import "../chunk-AASHBCRW.mjs";
7
+ export default require_permissions();
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ const { runGitCommand } = require("./utils.cjs");
3
+ /**
4
+ * Set git pull strategy to disable automatic rebase
5
+ * - Sets pull.rebase = false
6
+ */
7
+ function setPullStrategy() {
8
+ console.log("\n=== Configuring Pull Strategy ===");
9
+ runGitCommand(["config", "pull.rebase", "false"], "Disable automatic rebase on pull");
10
+ }
11
+ module.exports = {
12
+ setPullStrategy
13
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Set git pull strategy to disable automatic rebase
3
+ * - Sets pull.rebase = false
4
+ */
5
+ export function setPullStrategy(): void;
@@ -0,0 +1,15 @@
1
+ const { runGitCommand } = require("./utils.cjs");
2
+
3
+ /**
4
+ * Set git pull strategy to disable automatic rebase
5
+ * - Sets pull.rebase = false
6
+ */
7
+ function setPullStrategy() {
8
+ console.log("\n=== Configuring Pull Strategy ===");
9
+
10
+ runGitCommand(["config", "pull.rebase", "false"], "Disable automatic rebase on pull");
11
+ }
12
+
13
+ module.exports = {
14
+ setPullStrategy
15
+ };
@@ -0,0 +1,15 @@
1
+ const { runGitCommand } = require("./utils.cjs");
2
+
3
+ /**
4
+ * Set git pull strategy to disable automatic rebase
5
+ * - Sets pull.rebase = false
6
+ */
7
+ function setPullStrategy() {
8
+ console.log("\n=== Configuring Pull Strategy ===");
9
+
10
+ runGitCommand(["config", "pull.rebase", "false"], "Disable automatic rebase on pull");
11
+ }
12
+
13
+ module.exports = {
14
+ setPullStrategy
15
+ };
@@ -0,0 +1,7 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_pull_strategy
4
+ } from "../chunk-SH3L6HHV.mjs";
5
+ import "../chunk-EGSSKVDH.mjs";
6
+ import "../chunk-AASHBCRW.mjs";
7
+ export default require_pull_strategy();
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ const gch = require("git-command-helper");
3
+ const { runGitCommand, runGitCommandOutput } = require("./utils.cjs");
4
+ const { getArgs } = require("../utils.js");
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
+ // Determine user and email with CLI args taking precedence
15
+ let username, email;
16
+ if (cliUser && cliEmail) {
17
+ username = cliUser.trim();
18
+ email = cliEmail.trim();
19
+ console.log("[i] Using CLI-provided user configuration");
20
+ }
21
+ else {
22
+ username = process.env.GITHUB_USER ? process.env.GITHUB_USER.trim() : undefined;
23
+ email = process.env.GITHUB_EMAIL ? process.env.GITHUB_EMAIL.trim() : undefined;
24
+ if (username || email) {
25
+ console.log("[i] Using environment variable user configuration");
26
+ }
27
+ }
28
+ if (!username && !email) {
29
+ console.log("[i] No Git user configuration needed (no CLI args or environment variables set)");
30
+ return;
31
+ }
32
+ if (username) {
33
+ const success = runGitCommand(["config", "user.name", username], `Set Git username to "${username}"`);
34
+ if (!success) {
35
+ console.log("[i] Failed to set Git username, but continuing...");
36
+ }
37
+ }
38
+ else {
39
+ console.log("[i] No username provided, skipping username configuration");
40
+ }
41
+ if (email) {
42
+ const success = runGitCommand(["config", "user.email", email], `Set Git email to "${email}"`);
43
+ if (!success) {
44
+ console.log("[i] Failed to set Git email, but continuing...");
45
+ }
46
+ }
47
+ else {
48
+ console.log("[i] No email provided, skipping email configuration");
49
+ }
50
+ if (username || email) {
51
+ console.log("[✓] Git user configuration completed");
52
+ }
53
+ if (username) {
54
+ // Ask user to modify the origin remote URL if it doesn't match the username
55
+ const remoteUrl = runGitCommandOutput(["remote", "get-url", "origin"], "Fetching remote URL for verification");
56
+ if (remoteUrl) {
57
+ console.log(`[i] Remote URL: ${remoteUrl}`);
58
+ const parsedUrl = gch.parseGitHubUrl(remoteUrl);
59
+ if (parsedUrl && parsedUrl.owner && username && parsedUrl.owner.toLowerCase() !== username.toLowerCase()) {
60
+ console.warn(`\n[!] The GitHub remote owner ("${parsedUrl.owner}") does not match the configured username ("${username}").`);
61
+ console.warn(`[!] If this is not intentional, consider updating the remote URL to use your username.`);
62
+ console.warn(`[!] Example: git remote set-url origin https://github.com/${username}/<repo>.git\n`);
63
+ // Check for --update-remote CLI argument or options.updateRemote
64
+ const args = getArgs();
65
+ const updateRemote = options.updateRemote || args["update-remote"] === true;
66
+ if (updateRemote) {
67
+ // Only update the username in the URL, not the repo path
68
+ let newUrl = remoteUrl;
69
+ // Handle https:// and git@ URLs
70
+ if (/^https:\/\//.test(remoteUrl)) {
71
+ newUrl = remoteUrl.replace(/https:\/\/(?:[^@]+@)?github.com/, `https://${username}@github.com`);
72
+ }
73
+ else if (/^git@github.com:/.test(remoteUrl)) {
74
+ // For git@github.com:user/repo.git, do not change path, just warn user to use HTTPS with username if needed
75
+ console.warn(`[!] For SSH remotes, set your SSH config or use HTTPS with username if you want to change authentication user.`);
76
+ return;
77
+ }
78
+ if (newUrl !== remoteUrl) {
79
+ const updated = runGitCommand(["remote", "set-url", "origin", newUrl], `Set origin to ${newUrl}`);
80
+ if (updated) {
81
+ console.log(`[✓] Remote URL updated to: ${newUrl}`);
82
+ }
83
+ else {
84
+ console.warn(`[!] Failed to update remote URL. Please update it manually if needed.`);
85
+ }
86
+ }
87
+ else {
88
+ console.log(`[i] Remote URL does not use HTTPS or already contains the username.`);
89
+ }
90
+ }
91
+ else {
92
+ console.log(`[i] Remote URL not changed. Use --update-remote to update automatically.`);
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ module.exports = {
99
+ configureGitUser
100
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Configure Git user from CLI arguments or environment variables
3
+ * @param {string|null} cliUser - Username from CLI arguments
4
+ * @param {string|null} cliEmail - Email from CLI arguments
5
+ * @param {object} [options] - Options object
6
+ * @param {boolean} [options.updateRemote] - If true, update remote URL without prompt
7
+ */
8
+ export function configureGitUser(cliUser?: string | null, cliEmail?: string | null, options?: {
9
+ updateRemote?: boolean;
10
+ }): void;
@@ -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
+ };