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.
Files changed (150) 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 +105 -0
  15. package/lib/binary-collections.d.cts +2 -0
  16. package/lib/binary-collections.d.mts +121 -0
  17. package/lib/binary-collections.d.ts +121 -0
  18. package/lib/binary-collections.mjs +108 -0
  19. package/lib/chunk-4BYBVEYC.mjs +30 -0
  20. package/lib/{chunk-FB6YIQYR.mjs → chunk-AASHBCRW.mjs} +17 -2
  21. package/lib/chunk-APBWENF6.mjs +135 -0
  22. package/lib/{chunk-4LEXWIIF.mjs → chunk-DPKAJKFO.mjs} +2 -4
  23. package/lib/chunk-EGSSKVDH.mjs +66 -0
  24. package/lib/{chunk-3LOB2P54.mjs → chunk-G3THLIDT.mjs} +3 -5
  25. package/lib/chunk-JGR2NW6D.mjs +187 -0
  26. package/lib/chunk-ONIBBBQ3.mjs +108 -0
  27. package/lib/chunk-SH3L6HHV.mjs +27 -0
  28. package/lib/chunk-VVEZVNIV.mjs +81 -0
  29. package/lib/{chunk-JL32QDSH.mjs → chunk-W3ENOM53.mjs} +2 -4
  30. package/lib/chunk-YV7DO3YV.mjs +48 -0
  31. package/lib/{chunk-BSD5CIRU.mjs → chunk-YX5U7XDR.mjs} +11 -5
  32. package/lib/chunk-ZYAQRPUL.mjs +28 -0
  33. package/lib/clean-github-actions-caches.cjs +162 -0
  34. package/lib/clean-github-actions-caches.d.cts +1 -0
  35. package/lib/clean-github-actions-caches.d.mts +169 -0
  36. package/lib/clean-github-actions-caches.d.ts +169 -0
  37. package/lib/clean-github-actions-caches.mjs +132 -0
  38. package/lib/del-gradle.cjs +87 -3
  39. package/lib/del-gradle.js +1 -1
  40. package/lib/del-gradle.mjs +4 -6
  41. package/lib/del-node-modules.cjs +86 -2
  42. package/lib/del-node-modules.mjs +3 -5
  43. package/lib/del-ps.cjs +89 -5
  44. package/lib/del-ps.js +2 -2
  45. package/lib/del-ps.mjs +6 -8
  46. package/lib/del-yarn-caches.cjs +86 -2
  47. package/lib/del-yarn-caches.mjs +3 -5
  48. package/lib/find-node-modules-cli.cjs +8 -0
  49. package/lib/find-node-modules-cli.mjs +2 -3
  50. package/lib/find-node-modules.cjs +8 -0
  51. package/lib/find-node-modules.d.mts +3 -0
  52. package/lib/find-node-modules.d.ts +3 -0
  53. package/lib/find-node-modules.js +12 -0
  54. package/lib/find-node-modules.mjs +2 -3
  55. package/lib/git/gitattributes.cjs +171 -0
  56. package/lib/git/gitattributes.d.mts +35 -0
  57. package/lib/git/gitattributes.d.ts +33 -0
  58. package/lib/git/gitattributes.js +223 -0
  59. package/lib/git/gitattributes.mjs +6 -0
  60. package/lib/git/line-endings.cjs +74 -0
  61. package/lib/git/line-endings.d.cts +7 -0
  62. package/lib/git/line-endings.d.mts +83 -0
  63. package/lib/git/line-endings.d.ts +83 -0
  64. package/lib/git/line-endings.mjs +8 -0
  65. package/lib/git/normalize.cjs +42 -0
  66. package/lib/git/normalize.d.cts +6 -0
  67. package/lib/git/normalize.d.mts +43 -0
  68. package/lib/git/normalize.d.ts +43 -0
  69. package/lib/git/normalize.mjs +6 -0
  70. package/lib/git/permissions.cjs +15 -0
  71. package/lib/git/permissions.d.cts +6 -0
  72. package/lib/git/permissions.d.mts +17 -0
  73. package/lib/git/permissions.d.ts +17 -0
  74. package/lib/git/permissions.mjs +7 -0
  75. package/lib/git/pull-strategy.cjs +13 -0
  76. package/lib/git/pull-strategy.d.cts +5 -0
  77. package/lib/git/pull-strategy.d.mts +15 -0
  78. package/lib/git/pull-strategy.d.ts +15 -0
  79. package/lib/git/pull-strategy.mjs +7 -0
  80. package/lib/git/user-config.cjs +100 -0
  81. package/lib/git/user-config.d.cts +10 -0
  82. package/lib/git/user-config.d.mts +105 -0
  83. package/lib/git/user-config.d.ts +105 -0
  84. package/lib/git/user-config.mjs +8 -0
  85. package/lib/git/utils.cjs +70 -0
  86. package/lib/git/utils.d.cts +20 -0
  87. package/lib/git/utils.d.mts +69 -0
  88. package/lib/git/utils.d.ts +69 -0
  89. package/lib/git/utils.mjs +6 -0
  90. package/lib/git-diff.cjs +23 -24
  91. package/lib/git-diff.d.mts +25 -28
  92. package/lib/git-diff.d.ts +25 -28
  93. package/lib/git-diff.mjs +32 -27
  94. package/lib/git-fix.cjs +129 -0
  95. package/lib/git-fix.d.cts +2 -0
  96. package/lib/git-fix.d.mts +141 -0
  97. package/lib/git-fix.d.ts +141 -0
  98. package/lib/git-fix.mjs +151 -0
  99. package/lib/git-purge.cjs +86 -2
  100. package/lib/git-purge.mjs +3 -5
  101. package/lib/index.cjs +8 -0
  102. package/lib/index.mjs +3 -5
  103. package/lib/npm-run-series.cjs +140 -1
  104. package/lib/npm-run-series.js +2 -1
  105. package/lib/npm-run-series.mjs +7 -5
  106. package/lib/package-resolutions-updater.cjs +274 -0
  107. package/lib/package-resolutions-updater.d.mts +1 -0
  108. package/lib/package-resolutions-updater.d.ts +326 -0
  109. package/lib/package-resolutions-updater.mjs +316 -0
  110. package/lib/print-directory-tree.cjs +241 -0
  111. package/lib/print-directory-tree.d.cts +1 -0
  112. package/lib/print-directory-tree.d.mts +234 -0
  113. package/lib/print-directory-tree.d.ts +234 -0
  114. package/lib/print-directory-tree.mjs +182 -0
  115. package/lib/ps/connected-domain.mjs +2 -3
  116. package/lib/ps/index.cjs +3 -3
  117. package/lib/ps/index.d.mjs +1 -2
  118. package/lib/ps/index.js +6 -3
  119. package/lib/ps/index.mjs +9 -11
  120. package/lib/ps/isWin.mjs +2 -3
  121. package/lib/ps/table-parser.mjs +3 -4
  122. package/lib/submodule-install.cjs +13 -31
  123. package/lib/submodule-install.d.mts +12 -32
  124. package/lib/submodule-install.d.ts +12 -32
  125. package/lib/submodule-install.mjs +16 -25
  126. package/lib/utils.cjs +86 -2
  127. package/lib/utils.d.mts +29 -9
  128. package/lib/utils.d.ts +28 -8
  129. package/lib/utils.js +139 -8
  130. package/lib/utils.mjs +2 -3
  131. package/lib/yarn-reinstall.cjs +9 -7
  132. package/lib/yarn-reinstall.d.mts +12 -8
  133. package/lib/yarn-reinstall.d.ts +12 -8
  134. package/lib/yarn-reinstall.mjs +14 -10
  135. package/package.json +109 -80
  136. package/readme.md +74 -11
  137. package/src/package-resolutions-updater.mjs +325 -0
  138. package/src/print-directory-tree.cjs +234 -0
  139. package/src/ps/index.js +4 -3
  140. package/src/yarn-reinstall.cjs +49 -0
  141. package/test-project/package.json +16 -0
  142. package/tmp/test-repo/package.json +7 -0
  143. package/bin/git-fix-encoding.cmd +0 -6
  144. package/lib/chunk-OKYLF2MU.mjs +0 -53
  145. package/lib/chunk-VXZQNLPU.mjs +0 -23
  146. package/lib/package-resolutions.cjs +0 -28
  147. package/lib/package-resolutions.d.mts +0 -25
  148. package/lib/package-resolutions.d.ts +0 -25
  149. package/lib/package-resolutions.mjs +0 -31
  150. /package/bin/{submodule-install → submodule-install.txt} +0 -0
@@ -16,11 +16,56 @@ var init_cjs_shims = __esm({
16
16
  var require_utils = __commonJS({
17
17
  "src/utils.js"(exports2, module2) {
18
18
  init_cjs_shims();
19
- var { fs, path } = require("sbg-utility");
19
+ var fs = require("fs");
20
+ var path = require("upath");
20
21
  var argv = require("minimist")(process.argv.slice(2));
22
+ var { exec } = require("child_process");
23
+ var { URL: URL2 } = require("url");
24
+ var { promisify } = require("util");
25
+ var execAsync = promisify(exec);
26
+ async function parseGitRemotes() {
27
+ try {
28
+ const { stdout } = await execAsync("git remote -v");
29
+ const lines = stdout.split("\n");
30
+ const remotes = {};
31
+ lines.forEach((line) => {
32
+ const [name, url] = line.split(" ");
33
+ if (name && url) {
34
+ const [repoUrl] = url.split(" ");
35
+ try {
36
+ const parsedUrl = new URL2(repoUrl);
37
+ const pathParts = parsedUrl.pathname.split("/").filter(Boolean);
38
+ if (parsedUrl.hostname === "github.com" && pathParts.length === 2) {
39
+ let repoPath = pathParts.join("/");
40
+ if (repoPath.endsWith(".git")) {
41
+ repoPath = repoPath.slice(0, -4);
42
+ }
43
+ remotes[name] = repoPath;
44
+ }
45
+ } catch (e) {
46
+ console.error("URL Parsing Error:", e.message);
47
+ }
48
+ }
49
+ });
50
+ return remotes;
51
+ } catch (error) {
52
+ console.error("Error:", error.message);
53
+ return {};
54
+ }
55
+ }
56
+ module2.exports.parseGitRemotes = parseGitRemotes;
57
+ function joinPathPreserveDriveLetter(...segments) {
58
+ let fullPath = require("path").join(...segments);
59
+ if (/^[a-z]:\\/.test(fullPath)) {
60
+ fullPath = fullPath.charAt(0).toUpperCase() + fullPath.slice(1);
61
+ }
62
+ return fullPath;
63
+ }
64
+ module2.exports.joinPathPreserveDriveLetter = joinPathPreserveDriveLetter;
21
65
  function getArgs() {
22
66
  return argv;
23
67
  }
68
+ module2.exports.getArgs = getArgs;
24
69
  function del(fullPath) {
25
70
  if (fs.statSync(fullPath).isDirectory()) {
26
71
  const subdir = fs.readdirSync(fullPath).map((dirPath) => path.resolve(fullPath, dirPath));
@@ -36,6 +81,7 @@ var require_utils = __commonJS({
36
81
  }
37
82
  }
38
83
  }
84
+ module2.exports.del = del;
39
85
  function delStream2(globStream) {
40
86
  globStream.stream().on("data", (result) => {
41
87
  const fullPath = path.resolve(process.cwd(), result);
@@ -48,8 +94,46 @@ var require_utils = __commonJS({
48
94
  del(fullPath);
49
95
  });
50
96
  }
97
+ module2.exports.delStream = delStream2;
98
+ function getFileTreeString(hashArray) {
99
+ const tree = {};
100
+ const hashMap = {};
101
+ for (const entry of hashArray) {
102
+ const [filePath, hash] = entry.split(" ");
103
+ hashMap[filePath] = hash;
104
+ const parts = filePath.split("/");
105
+ let current = tree;
106
+ for (let i = 0; i < parts.length; i++) {
107
+ const part = parts[i];
108
+ if (i === parts.length - 1) {
109
+ current[part] = null;
110
+ } else {
111
+ current[part] = current[part] || {};
112
+ current = current[part];
113
+ }
114
+ }
115
+ }
116
+ function printNode(node, prefix = "", parentPath = "") {
117
+ const keys = Object.keys(node).sort();
118
+ let lines = [];
119
+ keys.forEach((key, idx) => {
120
+ const isLast = idx === keys.length - 1;
121
+ const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
122
+ const currentPath = parentPath ? parentPath + "/" + key : key;
123
+ if (node[key] === null) {
124
+ lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
125
+ } else {
126
+ lines.push(prefix + branch + key + "/");
127
+ lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "\u2502 "), currentPath));
128
+ }
129
+ });
130
+ return lines;
131
+ }
132
+ return printNode(tree, "", "").join("\n");
133
+ }
134
+ module2.exports.getFileTreeString = getFileTreeString;
51
135
  var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
52
- module2.exports = { del, delStream: delStream2, getArgs, delay };
136
+ module2.exports.delay = delay;
53
137
  }
54
138
  });
55
139
 
@@ -1,13 +1,11 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
2
  import {
3
3
  require_utils
4
- } from "./chunk-OKYLF2MU.mjs";
4
+ } from "./chunk-APBWENF6.mjs";
5
5
  import {
6
+ __require,
6
7
  init_esm_shims
7
- } from "./chunk-VXZQNLPU.mjs";
8
- import {
9
- __require
10
- } from "./chunk-FB6YIQYR.mjs";
8
+ } from "./chunk-AASHBCRW.mjs";
11
9
 
12
10
  // src/del-yarn-caches.js
13
11
  init_esm_shims();
@@ -49,7 +49,15 @@ var require_find_node_modules = __commonJS({
49
49
  });
50
50
  });
51
51
  }
52
+ if (typeof module2 !== "undefined" && require.main === module2) {
53
+ findNodeModules2(null, console.log).then((dirs) => {
54
+ console.log(`Found ${dirs.length} node_modules directories.`);
55
+ }).catch((err) => {
56
+ console.error("Error finding node_modules directories:", err);
57
+ });
58
+ }
52
59
  module2.exports = findNodeModules2;
60
+ module2.exports.default = findNodeModules2;
53
61
  }
54
62
  });
55
63
 
@@ -2,11 +2,10 @@
2
2
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
3
3
  import {
4
4
  require_find_node_modules
5
- } from "./chunk-BSD5CIRU.mjs";
5
+ } from "./chunk-YX5U7XDR.mjs";
6
6
  import {
7
7
  init_esm_shims
8
- } from "./chunk-VXZQNLPU.mjs";
9
- import "./chunk-FB6YIQYR.mjs";
8
+ } from "./chunk-AASHBCRW.mjs";
10
9
 
11
10
  // src/find-node-modules-cli.js
12
11
  init_esm_shims();
@@ -31,4 +31,12 @@ function findNodeModules(dir = process.cwd(), callback = null) {
31
31
  });
32
32
  });
33
33
  }
34
+ if (typeof module !== "undefined" && require.main === module) {
35
+ findNodeModules(null, console.log).then((dirs) => {
36
+ console.log(`Found ${dirs.length} node_modules directories.`);
37
+ }).catch((err) => {
38
+ console.error("Error finding node_modules directories:", err);
39
+ });
40
+ }
34
41
  module.exports = findNodeModules;
42
+ module.exports.default = findNodeModules;
@@ -6,5 +6,8 @@
6
6
  * @returns {Promise<string[]>} - A promise that resolves to an array of full paths to "node_modules" directories.
7
7
  */
8
8
  declare function findNodeModules(dir?: string, callback?: Function): Promise<string[]>;
9
+ declare namespace findNodeModules {
10
+ export { findNodeModules as default };
11
+ }
9
12
 
10
13
  export { findNodeModules as default };
@@ -7,3 +7,6 @@ export = findNodeModules;
7
7
  * @returns {Promise<string[]>} - A promise that resolves to an array of full paths to "node_modules" directories.
8
8
  */
9
9
  declare function findNodeModules(dir?: string, callback?: Function): Promise<string[]>;
10
+ declare namespace findNodeModules {
11
+ export { findNodeModules as default };
12
+ }
@@ -38,4 +38,16 @@ function findNodeModules(dir = process.cwd(), callback = null) {
38
38
  });
39
39
  });
40
40
  }
41
+ // Support both CommonJS and ESM usage
42
+ if (typeof module !== "undefined" && require.main === module) {
43
+ findNodeModules(null, console.log)
44
+ .then((dirs) => {
45
+ console.log(`Found ${dirs.length} node_modules directories.`);
46
+ })
47
+ .catch((err) => {
48
+ console.error("Error finding node_modules directories:", err);
49
+ });
50
+ }
51
+ // ESM export support
41
52
  module.exports = findNodeModules;
53
+ module.exports.default = findNodeModules;
@@ -1,7 +1,6 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
2
  import {
3
3
  require_find_node_modules
4
- } from "./chunk-BSD5CIRU.mjs";
5
- import "./chunk-VXZQNLPU.mjs";
6
- import "./chunk-FB6YIQYR.mjs";
4
+ } from "./chunk-YX5U7XDR.mjs";
5
+ import "./chunk-AASHBCRW.mjs";
7
6
  export default require_find_node_modules();
@@ -0,0 +1,171 @@
1
+ // src/git/gitattributes.js
2
+ var fs = require("fs");
3
+ function parseGitAttributes(gitattributesPath) {
4
+ const rules = [];
5
+ if (!fs.existsSync(gitattributesPath)) {
6
+ return rules;
7
+ }
8
+ const content = fs.readFileSync(gitattributesPath, "utf8");
9
+ const lines = content.split("\n");
10
+ lines.forEach((line, index) => {
11
+ const trimmedLine = line.trim();
12
+ if (!trimmedLine || trimmedLine.startsWith("#")) {
13
+ rules.push({
14
+ type: trimmedLine.startsWith("#") ? "comment" : "empty",
15
+ content: line,
16
+ lineNumber: index + 1
17
+ });
18
+ return;
19
+ }
20
+ const parts = trimmedLine.split(/\s+/);
21
+ if (parts.length >= 2) {
22
+ const pattern = parts[0];
23
+ const attributes = parts.slice(1).join(" ");
24
+ rules.push({
25
+ type: "rule",
26
+ pattern,
27
+ attributes,
28
+ content: line,
29
+ lineNumber: index + 1
30
+ });
31
+ } else {
32
+ rules.push({
33
+ type: "invalid",
34
+ content: line,
35
+ lineNumber: index + 1
36
+ });
37
+ }
38
+ });
39
+ return rules;
40
+ }
41
+ function patternsConflict(pattern1, pattern2) {
42
+ if (pattern1 === pattern2) {
43
+ return true;
44
+ }
45
+ if (pattern1 === "*" || pattern2 === "*") {
46
+ return pattern1 !== pattern2;
47
+ }
48
+ const normalize = (p) => p.replace(/\{[^}]+\}/g, "*").replace(/\*+/g, "*");
49
+ const norm1 = normalize(pattern1);
50
+ const norm2 = normalize(pattern2);
51
+ return norm1 === norm2;
52
+ }
53
+ function mergeGitAttributeRules(existingRules, desiredRules) {
54
+ let mergedRules;
55
+ if (existingRules.length === 0) {
56
+ mergedRules = desiredRules.map((desired, idx) => ({
57
+ type: "rule",
58
+ pattern: desired.pattern,
59
+ attributes: desired.attributes,
60
+ content: `${desired.pattern} ${desired.attributes}`,
61
+ lineNumber: idx + 1,
62
+ added: true
63
+ }));
64
+ return {
65
+ mergedRules,
66
+ conflicts: [],
67
+ changes: desiredRules.map((rule) => ({ action: "added", pattern: rule.pattern, attributes: rule.attributes }))
68
+ };
69
+ } else {
70
+ mergedRules = [...existingRules];
71
+ }
72
+ const conflicts = [];
73
+ const changes = [];
74
+ desiredRules.forEach((desired) => {
75
+ const existingIdx = mergedRules.findIndex((r) => r.type === "rule" && r.pattern === desired.pattern);
76
+ if (existingIdx !== -1) {
77
+ const existing = mergedRules[existingIdx];
78
+ if (existing.attributes === desired.attributes) {
79
+ conflicts.push({
80
+ pattern: desired.pattern,
81
+ existing: existing.attributes,
82
+ proposed: desired.attributes,
83
+ action: "kept existing (identical)"
84
+ });
85
+ } else if (desired.priority > (existing.priority || 0)) {
86
+ mergedRules[existingIdx] = {
87
+ type: "rule",
88
+ pattern: desired.pattern,
89
+ attributes: desired.attributes,
90
+ content: `${desired.pattern} ${desired.attributes}`,
91
+ lineNumber: existing.lineNumber,
92
+ replaced: true
93
+ };
94
+ conflicts.push({
95
+ pattern: desired.pattern,
96
+ existing: existing.attributes,
97
+ proposed: desired.attributes,
98
+ action: "replaced (higher priority)"
99
+ });
100
+ changes.push({
101
+ action: "replaced",
102
+ pattern: desired.pattern,
103
+ attributes: desired.attributes,
104
+ oldAttributes: existing.attributes
105
+ });
106
+ } else {
107
+ conflicts.push({
108
+ pattern: desired.pattern,
109
+ existing: existing.attributes,
110
+ proposed: desired.attributes,
111
+ action: "kept existing (lower priority)"
112
+ });
113
+ }
114
+ } else {
115
+ mergedRules.push({
116
+ type: "rule",
117
+ pattern: desired.pattern,
118
+ attributes: desired.attributes,
119
+ content: `${desired.pattern} ${desired.attributes}`,
120
+ lineNumber: mergedRules.length + 1,
121
+ added: true
122
+ });
123
+ changes.push({
124
+ action: "added",
125
+ pattern: desired.pattern,
126
+ attributes: desired.attributes
127
+ });
128
+ }
129
+ });
130
+ return { mergedRules, conflicts, changes };
131
+ }
132
+ function formatGitAttributes(rules) {
133
+ return rules.map((rule) => {
134
+ if (rule.type === "rule") {
135
+ return `${rule.pattern} ${rule.attributes}`;
136
+ }
137
+ return rule.content;
138
+ }).join("\n") + "\n";
139
+ }
140
+ function updateGitAttributes(gitattributesPath, desiredRules) {
141
+ try {
142
+ const existingRules = parseGitAttributes(gitattributesPath);
143
+ const { mergedRules, conflicts, changes } = mergeGitAttributeRules(existingRules, desiredRules);
144
+ let success = false;
145
+ if (changes.length > 0) {
146
+ const newContent = formatGitAttributes(mergedRules);
147
+ fs.writeFileSync(gitattributesPath, newContent);
148
+ success = true;
149
+ }
150
+ return {
151
+ success,
152
+ conflicts,
153
+ changes,
154
+ message: success ? `Updated .gitattributes with ${changes.length} changes` : "No changes needed - all rules already present"
155
+ };
156
+ } catch (error) {
157
+ return {
158
+ success: false,
159
+ error: error.message,
160
+ conflicts: [],
161
+ changes: []
162
+ };
163
+ }
164
+ }
165
+ module.exports = {
166
+ parseGitAttributes,
167
+ patternsConflict,
168
+ mergeGitAttributeRules,
169
+ formatGitAttributes,
170
+ updateGitAttributes
171
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Parse existing .gitattributes file into structured rules
3
+ * @param {string} gitattributesPath - Path to .gitattributes file
4
+ * @returns {Array} Array of parsed rules
5
+ */
6
+ declare function parseGitAttributes(gitattributesPath: string): any[];
7
+ /**
8
+ * Check if two patterns conflict (same or overlapping file patterns)
9
+ * @param {string} pattern1 - First pattern
10
+ * @param {string} pattern2 - Second pattern
11
+ * @returns {boolean} True if patterns conflict
12
+ */
13
+ declare function patternsConflict(pattern1: string, pattern2: string): boolean;
14
+ /**
15
+ * Merge existing rules with desired rules, detecting conflicts
16
+ * @param {Array} existingRules - Parsed existing rules
17
+ * @param {Array} desiredRules - Desired rules to add
18
+ * @returns {Object} Result with mergedRules, conflicts, and changes
19
+ */
20
+ declare function mergeGitAttributeRules(existingRules: any[], desiredRules: any[]): any;
21
+ /**
22
+ * Format merged rules back into .gitattributes content
23
+ * @param {Array} rules - Merged rules array
24
+ * @returns {string} Formatted .gitattributes content
25
+ */
26
+ declare function formatGitAttributes(rules: any[]): string;
27
+ /**
28
+ * Update .gitattributes file with new rules, handling conflicts intelligently
29
+ * @param {string} gitattributesPath - Path to .gitattributes file
30
+ * @param {Array} desiredRules - Array of desired rules to add/merge
31
+ * @returns {Object} Result with success status, conflicts, and changes
32
+ */
33
+ declare function updateGitAttributes(gitattributesPath: string, desiredRules: any[]): any;
34
+
35
+ export { formatGitAttributes, mergeGitAttributeRules, parseGitAttributes, patternsConflict, updateGitAttributes };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Parse existing .gitattributes file into structured rules
3
+ * @param {string} gitattributesPath - Path to .gitattributes file
4
+ * @returns {Array} Array of parsed rules
5
+ */
6
+ export function parseGitAttributes(gitattributesPath: string): any[];
7
+ /**
8
+ * Check if two patterns conflict (same or overlapping file patterns)
9
+ * @param {string} pattern1 - First pattern
10
+ * @param {string} pattern2 - Second pattern
11
+ * @returns {boolean} True if patterns conflict
12
+ */
13
+ export function patternsConflict(pattern1: string, pattern2: string): boolean;
14
+ /**
15
+ * Merge existing rules with desired rules, detecting conflicts
16
+ * @param {Array} existingRules - Parsed existing rules
17
+ * @param {Array} desiredRules - Desired rules to add
18
+ * @returns {Object} Result with mergedRules, conflicts, and changes
19
+ */
20
+ export function mergeGitAttributeRules(existingRules: any[], desiredRules: any[]): any;
21
+ /**
22
+ * Format merged rules back into .gitattributes content
23
+ * @param {Array} rules - Merged rules array
24
+ * @returns {string} Formatted .gitattributes content
25
+ */
26
+ export function formatGitAttributes(rules: any[]): string;
27
+ /**
28
+ * Update .gitattributes file with new rules, handling conflicts intelligently
29
+ * @param {string} gitattributesPath - Path to .gitattributes file
30
+ * @param {Array} desiredRules - Array of desired rules to add/merge
31
+ * @returns {Object} Result with success status, conflicts, and changes
32
+ */
33
+ export function updateGitAttributes(gitattributesPath: string, desiredRules: any[]): any;
@@ -0,0 +1,223 @@
1
+ const fs = require("fs");
2
+ /**
3
+ * Parse existing .gitattributes file into structured rules
4
+ * @param {string} gitattributesPath - Path to .gitattributes file
5
+ * @returns {Array} Array of parsed rules
6
+ */
7
+ function parseGitAttributes(gitattributesPath) {
8
+ const rules = [];
9
+ if (!fs.existsSync(gitattributesPath)) {
10
+ return rules;
11
+ }
12
+ const content = fs.readFileSync(gitattributesPath, "utf8");
13
+ const lines = content.split("\n");
14
+ lines.forEach((line, index) => {
15
+ const trimmedLine = line.trim();
16
+ // Skip empty lines and comments
17
+ if (!trimmedLine || trimmedLine.startsWith("#")) {
18
+ rules.push({
19
+ type: trimmedLine.startsWith("#") ? "comment" : "empty",
20
+ content: line,
21
+ lineNumber: index + 1
22
+ });
23
+ return;
24
+ }
25
+ // Parse rule line
26
+ const parts = trimmedLine.split(/\s+/);
27
+ if (parts.length >= 2) {
28
+ const pattern = parts[0];
29
+ const attributes = parts.slice(1).join(" ");
30
+ rules.push({
31
+ type: "rule",
32
+ pattern,
33
+ attributes,
34
+ content: line,
35
+ lineNumber: index + 1
36
+ });
37
+ }
38
+ else {
39
+ // Invalid line, keep as-is
40
+ rules.push({
41
+ type: "invalid",
42
+ content: line,
43
+ lineNumber: index + 1
44
+ });
45
+ }
46
+ });
47
+ return rules;
48
+ }
49
+ /**
50
+ * Check if two patterns conflict (same or overlapping file patterns)
51
+ * @param {string} pattern1 - First pattern
52
+ * @param {string} pattern2 - Second pattern
53
+ * @returns {boolean} True if patterns conflict
54
+ */
55
+ function patternsConflict(pattern1, pattern2) {
56
+ // Exact match
57
+ if (pattern1 === pattern2) {
58
+ return true;
59
+ }
60
+ // Universal pattern conflicts with everything
61
+ if (pattern1 === "*" || pattern2 === "*") {
62
+ return pattern1 !== pattern2;
63
+ }
64
+ // Simple glob overlap detection
65
+ const normalize = (p) => p.replace(/\{[^}]+\}/g, "*").replace(/\*+/g, "*");
66
+ const norm1 = normalize(pattern1);
67
+ const norm2 = normalize(pattern2);
68
+ return norm1 === norm2;
69
+ }
70
+ /**
71
+ * Merge existing rules with desired rules, detecting conflicts
72
+ * @param {Array} existingRules - Parsed existing rules
73
+ * @param {Array} desiredRules - Desired rules to add
74
+ * @returns {Object} Result with mergedRules, conflicts, and changes
75
+ */
76
+ function mergeGitAttributeRules(existingRules, desiredRules) {
77
+ let mergedRules;
78
+ if (existingRules.length === 0) {
79
+ // If no existing rules, just add all desired rules in order
80
+ mergedRules = desiredRules.map((desired, idx) => ({
81
+ type: "rule",
82
+ pattern: desired.pattern,
83
+ attributes: desired.attributes,
84
+ content: `${desired.pattern} ${desired.attributes}`,
85
+ lineNumber: idx + 1,
86
+ added: true
87
+ }));
88
+ return {
89
+ mergedRules,
90
+ conflicts: [],
91
+ changes: desiredRules.map((rule) => ({ action: "added", pattern: rule.pattern, attributes: rule.attributes }))
92
+ };
93
+ }
94
+ else {
95
+ mergedRules = [...existingRules];
96
+ }
97
+ const conflicts = [];
98
+ const changes = [];
99
+ desiredRules.forEach((desired) => {
100
+ // Look for an exact pattern match in existing rules
101
+ const existingIdx = mergedRules.findIndex((r) => r.type === "rule" && r.pattern === desired.pattern);
102
+ if (existingIdx !== -1) {
103
+ const existing = mergedRules[existingIdx];
104
+ if (existing.attributes === desired.attributes) {
105
+ // Already present, do nothing
106
+ conflicts.push({
107
+ pattern: desired.pattern,
108
+ existing: existing.attributes,
109
+ proposed: desired.attributes,
110
+ action: "kept existing (identical)"
111
+ });
112
+ }
113
+ else if (desired.priority > (existing.priority || 0)) {
114
+ // Replace with higher priority rule
115
+ mergedRules[existingIdx] = {
116
+ type: "rule",
117
+ pattern: desired.pattern,
118
+ attributes: desired.attributes,
119
+ content: `${desired.pattern} ${desired.attributes}`,
120
+ lineNumber: existing.lineNumber,
121
+ replaced: true
122
+ };
123
+ conflicts.push({
124
+ pattern: desired.pattern,
125
+ existing: existing.attributes,
126
+ proposed: desired.attributes,
127
+ action: "replaced (higher priority)"
128
+ });
129
+ changes.push({
130
+ action: "replaced",
131
+ pattern: desired.pattern,
132
+ attributes: desired.attributes,
133
+ oldAttributes: existing.attributes
134
+ });
135
+ }
136
+ else {
137
+ // Keep existing rule
138
+ conflicts.push({
139
+ pattern: desired.pattern,
140
+ existing: existing.attributes,
141
+ proposed: desired.attributes,
142
+ action: "kept existing (lower priority)"
143
+ });
144
+ }
145
+ }
146
+ else {
147
+ // No exact pattern match, add new rule
148
+ mergedRules.push({
149
+ type: "rule",
150
+ pattern: desired.pattern,
151
+ attributes: desired.attributes,
152
+ content: `${desired.pattern} ${desired.attributes}`,
153
+ lineNumber: mergedRules.length + 1,
154
+ added: true
155
+ });
156
+ changes.push({
157
+ action: "added",
158
+ pattern: desired.pattern,
159
+ attributes: desired.attributes
160
+ });
161
+ }
162
+ });
163
+ return { mergedRules, conflicts, changes };
164
+ }
165
+ /**
166
+ * Format merged rules back into .gitattributes content
167
+ * @param {Array} rules - Merged rules array
168
+ * @returns {string} Formatted .gitattributes content
169
+ */
170
+ function formatGitAttributes(rules) {
171
+ return (rules
172
+ .map((rule) => {
173
+ if (rule.type === "rule") {
174
+ return `${rule.pattern} ${rule.attributes}`;
175
+ }
176
+ return rule.content;
177
+ })
178
+ .join("\n") + "\n");
179
+ }
180
+ /**
181
+ * Update .gitattributes file with new rules, handling conflicts intelligently
182
+ * @param {string} gitattributesPath - Path to .gitattributes file
183
+ * @param {Array} desiredRules - Array of desired rules to add/merge
184
+ * @returns {Object} Result with success status, conflicts, and changes
185
+ */
186
+ function updateGitAttributes(gitattributesPath, desiredRules) {
187
+ try {
188
+ // Parse existing .gitattributes
189
+ const existingRules = parseGitAttributes(gitattributesPath);
190
+ // Merge rules and detect conflicts
191
+ const { mergedRules, conflicts, changes } = mergeGitAttributeRules(existingRules, desiredRules);
192
+ // Write updated .gitattributes if changes were made
193
+ let success = false;
194
+ if (changes.length > 0) {
195
+ const newContent = formatGitAttributes(mergedRules);
196
+ fs.writeFileSync(gitattributesPath, newContent);
197
+ success = true;
198
+ }
199
+ return {
200
+ success,
201
+ conflicts,
202
+ changes,
203
+ message: success
204
+ ? `Updated .gitattributes with ${changes.length} changes`
205
+ : "No changes needed - all rules already present"
206
+ };
207
+ }
208
+ catch (error) {
209
+ return {
210
+ success: false,
211
+ error: error.message,
212
+ conflicts: [],
213
+ changes: []
214
+ };
215
+ }
216
+ }
217
+ module.exports = {
218
+ parseGitAttributes,
219
+ patternsConflict,
220
+ mergeGitAttributeRules,
221
+ formatGitAttributes,
222
+ updateGitAttributes
223
+ };