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
@@ -0,0 +1,234 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+ const crypto = require("crypto");
4
+ const { execSync } = require("child_process");
5
+ const glob = require("glob");
6
+ const { getArgs } = require("./utils.js");
7
+ const sbgUtil = require("sbg-utility");
8
+ const dotenv = require("dotenv");
9
+
10
+ const projectDir = process.cwd();
11
+ const envPath = path.join(projectDir, ".env");
12
+
13
+ // Load the .env file using dotenv (ESM import)
14
+ if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
15
+
16
+ // Parse CLI arguments
17
+ const argv = getArgs();
18
+
19
+ // Main logic wrapped in an async function
20
+ async function main() {
21
+ // Determine output file from CLI args
22
+ let relativeOutputFile = "tmp/directory-structure.txt";
23
+ if (argv.output || argv.o) {
24
+ relativeOutputFile = argv.output || argv.o;
25
+ }
26
+ // If not absolute, resolve relative to projectDir
27
+ const outputFile = path.isAbsolute(relativeOutputFile)
28
+ ? relativeOutputFile
29
+ : path.join(projectDir, relativeOutputFile);
30
+
31
+ // Create or clear the hash file
32
+ sbgUtil.writefile(outputFile, "");
33
+
34
+ /**
35
+ * List of file extensions to include
36
+ * @type {string[]}
37
+ */
38
+ let extensions = [];
39
+ if (argv.ext) {
40
+ extensions = argv.ext
41
+ .split(",")
42
+ .map((e) => e.trim().replace(/^\./, ""))
43
+ .filter(Boolean);
44
+ }
45
+
46
+ // Directories to exclude
47
+ let excludeDirs = [
48
+ "node_modules",
49
+ "vendor",
50
+ "venv",
51
+ ".venv",
52
+ ".git",
53
+ ".hg",
54
+ ".svn",
55
+ ".idea",
56
+ ".vscode",
57
+ "dist",
58
+ "build",
59
+ "out",
60
+ "coverage",
61
+ ".DS_Store"
62
+ ];
63
+ if (argv.exclude) {
64
+ const userExcludes = argv.exclude
65
+ .split(",")
66
+ .map((d) => d.trim())
67
+ .filter(Boolean);
68
+ if (argv["override-exclude"] || argv.we) {
69
+ // Override the default excludes with user-provided ones
70
+ excludeDirs = userExcludes;
71
+ } else {
72
+ // Append user-provided excludes to the default ones
73
+ excludeDirs = excludeDirs.concat(userExcludes);
74
+ }
75
+ }
76
+
77
+ // Convert excludeDirs into glob ignore patterns
78
+ const ignorePatterns = excludeDirs.map((dir) => `**/${dir}/**`);
79
+
80
+ // Initialize an array to hold the formatted outputs
81
+ let hashArray = [];
82
+
83
+ // Helper function to hash and add file if not already processed
84
+ const processedFiles = new Set();
85
+ /**
86
+ * Hashes a file and pushes its relative path and hash to the hashArray.
87
+ * @param {string} file - The absolute path to the file.
88
+ * @returns {Promise<void>} Resolves when the file has been processed and added to hashArray.
89
+ */
90
+ async function hashAndPush(file) {
91
+ if (processedFiles.has(file)) return;
92
+ processedFiles.add(file);
93
+ let relativePath = path.relative(projectDir, file);
94
+ relativePath = relativePath.split(path.sep).join("/");
95
+ try {
96
+ const stats = await fs.stat(file);
97
+ const pseudoHash = `${stats.size}-${stats.mtimeMs}`;
98
+ const hash = crypto.createHash("sha256").update(pseudoHash).digest("hex");
99
+ hashArray.push(`${relativePath} ${hash.slice(0, 8)}`);
100
+ } catch (err) {
101
+ console.error(`Error processing file: ${file}`, err instanceof Error ? err.message : "<unknown error>");
102
+ if (err && err.code === "ENOENT") {
103
+ hashArray.push(`${relativePath} <file not found>`);
104
+ } else {
105
+ hashArray.push(`${relativePath} <error: ${err && err.code ? `code ${err.code}` : "unknown"}>`);
106
+ }
107
+ }
108
+ }
109
+
110
+ // Collect all files to process (extensions + special files)
111
+ const initialFiles = [
112
+ path.join(projectDir, "package.json"),
113
+ path.join(projectDir, "composer.json"),
114
+ path.join(projectDir, "requirements.txt")
115
+ ];
116
+ let patterns = [];
117
+ if (argv.pattern) {
118
+ if (Array.isArray(argv.pattern)) {
119
+ patterns = argv.pattern.map((p) => p.trim()).filter(Boolean);
120
+ } else {
121
+ patterns = [argv.pattern.trim()];
122
+ }
123
+ } else if (extensions.length === 0) {
124
+ patterns = ["**/*.*"];
125
+ } else {
126
+ patterns = extensions.map((ext) => `**/*.${ext}`);
127
+ }
128
+ const globFiles = glob.sync(patterns.length === 1 ? patterns[0] : `{${patterns.join(",")}}`, {
129
+ cwd: projectDir,
130
+ ignore: ignorePatterns,
131
+ absolute: true,
132
+ nodir: true
133
+ });
134
+ const allFiles = new Set([...initialFiles, ...globFiles]);
135
+
136
+ // Hash all unique files
137
+ await Promise.all(Array.from(allFiles).map(hashAndPush));
138
+
139
+ // Sort the hashArray by file paths
140
+ hashArray.sort((a, b) => a.localeCompare(b));
141
+
142
+ /**
143
+ * Generates a directory/file tree string from a hash array of file paths and hashes.
144
+ *
145
+ * @param {string[]} hashArray - Array of strings in the format 'relative/path/to/file hash'.
146
+ * @returns {string} The directory/file tree as a string, with file hashes.
147
+ */
148
+ function getFileTreeString(hashArray) {
149
+ const tree = {};
150
+ // Map file paths to hashes for quick lookup
151
+ const hashMap = {};
152
+ for (const entry of hashArray) {
153
+ const [filePath, hash] = entry.split(" ");
154
+ hashMap[filePath] = hash;
155
+ const parts = filePath.split("/");
156
+ let current = tree;
157
+ for (let i = 0; i < parts.length; i++) {
158
+ const part = parts[i];
159
+ if (i === parts.length - 1) {
160
+ current[part] = null; // file
161
+ } else {
162
+ current[part] = current[part] || {};
163
+ current = current[part];
164
+ }
165
+ }
166
+ }
167
+ /**
168
+ * Recursively builds the tree string for a given node.
169
+ *
170
+ * @param {Object} node - The current node in the tree.
171
+ * @param {string} prefix - The prefix for the current tree level.
172
+ * @param {string} parentPath - The path to the current node.
173
+ * @returns {string[]} Array of lines representing the tree structure.
174
+ */
175
+ function printNode(node, prefix = "", parentPath = "") {
176
+ const keys = Object.keys(node).sort();
177
+ let lines = [];
178
+ keys.forEach((key, idx) => {
179
+ const isLast = idx === keys.length - 1;
180
+ const branch = isLast ? "└── " : "├── ";
181
+ const currentPath = parentPath ? parentPath + "/" + key : key;
182
+ if (node[key] === null) {
183
+ // file: show hash
184
+ lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
185
+ } else {
186
+ lines.push(prefix + branch + key + "/");
187
+ lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "│ "), currentPath));
188
+ }
189
+ });
190
+ return lines;
191
+ }
192
+ return printNode(tree, "", "").join("\n");
193
+ }
194
+
195
+ // Write directory/file tree to the output file (hashes are included in the tree)
196
+ const fileTreeString = getFileTreeString(hashArray);
197
+ await fs.writeFile(outputFile, fileTreeString + "\n", "utf-8");
198
+
199
+ // Add the hash file to the commit if --git-add is present
200
+ if (argv["git-add"]) {
201
+ execSync(`git add ${relativeOutputFile}`);
202
+ console.log(`Directory tree written to ${relativeOutputFile} and staged for git.`);
203
+ } else {
204
+ console.log(`Directory tree written to ${relativeOutputFile}.`);
205
+ }
206
+ }
207
+
208
+ if (argv.help || argv.h) {
209
+ console.log(`
210
+ Usage: node print-directory-tree.cjs [options]
211
+
212
+ Options:
213
+ --output, -o <file> Output file path (default: tmp/directory-structure.txt)
214
+ --ext <exts> Comma-separated list of file extensions (no dot, e.g. js,ts)
215
+ --pattern <glob> Glob pattern(s) for files (can be repeated)
216
+ --exclude <dirs> Comma-separated list of directories to exclude (appends to default)
217
+ --override-exclude, -we Override default exclude directories with --exclude
218
+ --git-add Add output file to git after writing
219
+ --help, -h Show this help message
220
+
221
+ Examples:
222
+ node print-directory-tree.cjs --ext=js,ts
223
+ node print-directory-tree.cjs --pattern=src/**/*.js --pattern=test/**/*.js
224
+ node print-directory-tree.cjs --exclude=dist,build
225
+ node print-directory-tree.cjs --output=tmp/tree.txt
226
+ `);
227
+ process.exit(0);
228
+ }
229
+
230
+ // Execute the main function
231
+ main().catch((err) => {
232
+ console.error(err);
233
+ process.exit(1);
234
+ });
@@ -0,0 +1,234 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+ const crypto = require("crypto");
4
+ const { execSync } = require("child_process");
5
+ const glob = require("glob");
6
+ const { getArgs } = require("./utils.js");
7
+ const sbgUtil = require("sbg-utility");
8
+ const dotenv = require("dotenv");
9
+
10
+ const projectDir = process.cwd();
11
+ const envPath = path.join(projectDir, ".env");
12
+
13
+ // Load the .env file using dotenv (ESM import)
14
+ if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
15
+
16
+ // Parse CLI arguments
17
+ const argv = getArgs();
18
+
19
+ // Main logic wrapped in an async function
20
+ async function main() {
21
+ // Determine output file from CLI args
22
+ let relativeOutputFile = "tmp/directory-structure.txt";
23
+ if (argv.output || argv.o) {
24
+ relativeOutputFile = argv.output || argv.o;
25
+ }
26
+ // If not absolute, resolve relative to projectDir
27
+ const outputFile = path.isAbsolute(relativeOutputFile)
28
+ ? relativeOutputFile
29
+ : path.join(projectDir, relativeOutputFile);
30
+
31
+ // Create or clear the hash file
32
+ sbgUtil.writefile(outputFile, "");
33
+
34
+ /**
35
+ * List of file extensions to include
36
+ * @type {string[]}
37
+ */
38
+ let extensions = [];
39
+ if (argv.ext) {
40
+ extensions = argv.ext
41
+ .split(",")
42
+ .map((e) => e.trim().replace(/^\./, ""))
43
+ .filter(Boolean);
44
+ }
45
+
46
+ // Directories to exclude
47
+ let excludeDirs = [
48
+ "node_modules",
49
+ "vendor",
50
+ "venv",
51
+ ".venv",
52
+ ".git",
53
+ ".hg",
54
+ ".svn",
55
+ ".idea",
56
+ ".vscode",
57
+ "dist",
58
+ "build",
59
+ "out",
60
+ "coverage",
61
+ ".DS_Store"
62
+ ];
63
+ if (argv.exclude) {
64
+ const userExcludes = argv.exclude
65
+ .split(",")
66
+ .map((d) => d.trim())
67
+ .filter(Boolean);
68
+ if (argv["override-exclude"] || argv.we) {
69
+ // Override the default excludes with user-provided ones
70
+ excludeDirs = userExcludes;
71
+ } else {
72
+ // Append user-provided excludes to the default ones
73
+ excludeDirs = excludeDirs.concat(userExcludes);
74
+ }
75
+ }
76
+
77
+ // Convert excludeDirs into glob ignore patterns
78
+ const ignorePatterns = excludeDirs.map((dir) => `**/${dir}/**`);
79
+
80
+ // Initialize an array to hold the formatted outputs
81
+ let hashArray = [];
82
+
83
+ // Helper function to hash and add file if not already processed
84
+ const processedFiles = new Set();
85
+ /**
86
+ * Hashes a file and pushes its relative path and hash to the hashArray.
87
+ * @param {string} file - The absolute path to the file.
88
+ * @returns {Promise<void>} Resolves when the file has been processed and added to hashArray.
89
+ */
90
+ async function hashAndPush(file) {
91
+ if (processedFiles.has(file)) return;
92
+ processedFiles.add(file);
93
+ let relativePath = path.relative(projectDir, file);
94
+ relativePath = relativePath.split(path.sep).join("/");
95
+ try {
96
+ const stats = await fs.stat(file);
97
+ const pseudoHash = `${stats.size}-${stats.mtimeMs}`;
98
+ const hash = crypto.createHash("sha256").update(pseudoHash).digest("hex");
99
+ hashArray.push(`${relativePath} ${hash.slice(0, 8)}`);
100
+ } catch (err) {
101
+ console.error(`Error processing file: ${file}`, err instanceof Error ? err.message : "<unknown error>");
102
+ if (err && err.code === "ENOENT") {
103
+ hashArray.push(`${relativePath} <file not found>`);
104
+ } else {
105
+ hashArray.push(`${relativePath} <error: ${err && err.code ? `code ${err.code}` : "unknown"}>`);
106
+ }
107
+ }
108
+ }
109
+
110
+ // Collect all files to process (extensions + special files)
111
+ const initialFiles = [
112
+ path.join(projectDir, "package.json"),
113
+ path.join(projectDir, "composer.json"),
114
+ path.join(projectDir, "requirements.txt")
115
+ ];
116
+ let patterns = [];
117
+ if (argv.pattern) {
118
+ if (Array.isArray(argv.pattern)) {
119
+ patterns = argv.pattern.map((p) => p.trim()).filter(Boolean);
120
+ } else {
121
+ patterns = [argv.pattern.trim()];
122
+ }
123
+ } else if (extensions.length === 0) {
124
+ patterns = ["**/*.*"];
125
+ } else {
126
+ patterns = extensions.map((ext) => `**/*.${ext}`);
127
+ }
128
+ const globFiles = glob.sync(patterns.length === 1 ? patterns[0] : `{${patterns.join(",")}}`, {
129
+ cwd: projectDir,
130
+ ignore: ignorePatterns,
131
+ absolute: true,
132
+ nodir: true
133
+ });
134
+ const allFiles = new Set([...initialFiles, ...globFiles]);
135
+
136
+ // Hash all unique files
137
+ await Promise.all(Array.from(allFiles).map(hashAndPush));
138
+
139
+ // Sort the hashArray by file paths
140
+ hashArray.sort((a, b) => a.localeCompare(b));
141
+
142
+ /**
143
+ * Generates a directory/file tree string from a hash array of file paths and hashes.
144
+ *
145
+ * @param {string[]} hashArray - Array of strings in the format 'relative/path/to/file hash'.
146
+ * @returns {string} The directory/file tree as a string, with file hashes.
147
+ */
148
+ function getFileTreeString(hashArray) {
149
+ const tree = {};
150
+ // Map file paths to hashes for quick lookup
151
+ const hashMap = {};
152
+ for (const entry of hashArray) {
153
+ const [filePath, hash] = entry.split(" ");
154
+ hashMap[filePath] = hash;
155
+ const parts = filePath.split("/");
156
+ let current = tree;
157
+ for (let i = 0; i < parts.length; i++) {
158
+ const part = parts[i];
159
+ if (i === parts.length - 1) {
160
+ current[part] = null; // file
161
+ } else {
162
+ current[part] = current[part] || {};
163
+ current = current[part];
164
+ }
165
+ }
166
+ }
167
+ /**
168
+ * Recursively builds the tree string for a given node.
169
+ *
170
+ * @param {Object} node - The current node in the tree.
171
+ * @param {string} prefix - The prefix for the current tree level.
172
+ * @param {string} parentPath - The path to the current node.
173
+ * @returns {string[]} Array of lines representing the tree structure.
174
+ */
175
+ function printNode(node, prefix = "", parentPath = "") {
176
+ const keys = Object.keys(node).sort();
177
+ let lines = [];
178
+ keys.forEach((key, idx) => {
179
+ const isLast = idx === keys.length - 1;
180
+ const branch = isLast ? "└── " : "├── ";
181
+ const currentPath = parentPath ? parentPath + "/" + key : key;
182
+ if (node[key] === null) {
183
+ // file: show hash
184
+ lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
185
+ } else {
186
+ lines.push(prefix + branch + key + "/");
187
+ lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "│ "), currentPath));
188
+ }
189
+ });
190
+ return lines;
191
+ }
192
+ return printNode(tree, "", "").join("\n");
193
+ }
194
+
195
+ // Write directory/file tree to the output file (hashes are included in the tree)
196
+ const fileTreeString = getFileTreeString(hashArray);
197
+ await fs.writeFile(outputFile, fileTreeString + "\n", "utf-8");
198
+
199
+ // Add the hash file to the commit if --git-add is present
200
+ if (argv["git-add"]) {
201
+ execSync(`git add ${relativeOutputFile}`);
202
+ console.log(`Directory tree written to ${relativeOutputFile} and staged for git.`);
203
+ } else {
204
+ console.log(`Directory tree written to ${relativeOutputFile}.`);
205
+ }
206
+ }
207
+
208
+ if (argv.help || argv.h) {
209
+ console.log(`
210
+ Usage: node print-directory-tree.cjs [options]
211
+
212
+ Options:
213
+ --output, -o <file> Output file path (default: tmp/directory-structure.txt)
214
+ --ext <exts> Comma-separated list of file extensions (no dot, e.g. js,ts)
215
+ --pattern <glob> Glob pattern(s) for files (can be repeated)
216
+ --exclude <dirs> Comma-separated list of directories to exclude (appends to default)
217
+ --override-exclude, -we Override default exclude directories with --exclude
218
+ --git-add Add output file to git after writing
219
+ --help, -h Show this help message
220
+
221
+ Examples:
222
+ node print-directory-tree.cjs --ext=js,ts
223
+ node print-directory-tree.cjs --pattern=src/**/*.js --pattern=test/**/*.js
224
+ node print-directory-tree.cjs --exclude=dist,build
225
+ node print-directory-tree.cjs --output=tmp/tree.txt
226
+ `);
227
+ process.exit(0);
228
+ }
229
+
230
+ // Execute the main function
231
+ main().catch((err) => {
232
+ console.error(err);
233
+ process.exit(1);
234
+ });
@@ -0,0 +1,182 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ require_utils
4
+ } from "./chunk-APBWENF6.mjs";
5
+ import {
6
+ __commonJS,
7
+ __require,
8
+ init_esm_shims
9
+ } from "./chunk-AASHBCRW.mjs";
10
+
11
+ // src/print-directory-tree.cjs
12
+ var require_print_directory_tree = __commonJS({
13
+ "src/print-directory-tree.cjs"() {
14
+ init_esm_shims();
15
+ var fs = __require("fs").promises;
16
+ var path = __require("path");
17
+ var crypto = __require("crypto");
18
+ var { execSync } = __require("child_process");
19
+ var glob = __require("glob");
20
+ var { getArgs } = require_utils();
21
+ var sbgUtil = __require("sbg-utility");
22
+ var dotenv = __require("dotenv");
23
+ var projectDir = process.cwd();
24
+ var envPath = path.join(projectDir, ".env");
25
+ if (fs.existsSync(envPath)) dotenv.config({ path: envPath });
26
+ var argv = getArgs();
27
+ async function main() {
28
+ let relativeOutputFile = "tmp/directory-structure.txt";
29
+ if (argv.output || argv.o) {
30
+ relativeOutputFile = argv.output || argv.o;
31
+ }
32
+ const outputFile = path.isAbsolute(relativeOutputFile) ? relativeOutputFile : path.join(projectDir, relativeOutputFile);
33
+ sbgUtil.writefile(outputFile, "");
34
+ let extensions = [];
35
+ if (argv.ext) {
36
+ extensions = argv.ext.split(",").map((e) => e.trim().replace(/^\./, "")).filter(Boolean);
37
+ }
38
+ let excludeDirs = [
39
+ "node_modules",
40
+ "vendor",
41
+ "venv",
42
+ ".venv",
43
+ ".git",
44
+ ".hg",
45
+ ".svn",
46
+ ".idea",
47
+ ".vscode",
48
+ "dist",
49
+ "build",
50
+ "out",
51
+ "coverage",
52
+ ".DS_Store"
53
+ ];
54
+ if (argv.exclude) {
55
+ const userExcludes = argv.exclude.split(",").map((d) => d.trim()).filter(Boolean);
56
+ if (argv["override-exclude"] || argv.we) {
57
+ excludeDirs = userExcludes;
58
+ } else {
59
+ excludeDirs = excludeDirs.concat(userExcludes);
60
+ }
61
+ }
62
+ const ignorePatterns = excludeDirs.map((dir) => `**/${dir}/**`);
63
+ let hashArray = [];
64
+ const processedFiles = /* @__PURE__ */ new Set();
65
+ async function hashAndPush(file) {
66
+ if (processedFiles.has(file)) return;
67
+ processedFiles.add(file);
68
+ let relativePath = path.relative(projectDir, file);
69
+ relativePath = relativePath.split(path.sep).join("/");
70
+ try {
71
+ const stats = await fs.stat(file);
72
+ const pseudoHash = `${stats.size}-${stats.mtimeMs}`;
73
+ const hash = crypto.createHash("sha256").update(pseudoHash).digest("hex");
74
+ hashArray.push(`${relativePath} ${hash.slice(0, 8)}`);
75
+ } catch (err) {
76
+ console.error(`Error processing file: ${file}`, err instanceof Error ? err.message : "<unknown error>");
77
+ if (err && err.code === "ENOENT") {
78
+ hashArray.push(`${relativePath} <file not found>`);
79
+ } else {
80
+ hashArray.push(`${relativePath} <error: ${err && err.code ? `code ${err.code}` : "unknown"}>`);
81
+ }
82
+ }
83
+ }
84
+ const initialFiles = [
85
+ path.join(projectDir, "package.json"),
86
+ path.join(projectDir, "composer.json"),
87
+ path.join(projectDir, "requirements.txt")
88
+ ];
89
+ let patterns = [];
90
+ if (argv.pattern) {
91
+ if (Array.isArray(argv.pattern)) {
92
+ patterns = argv.pattern.map((p) => p.trim()).filter(Boolean);
93
+ } else {
94
+ patterns = [argv.pattern.trim()];
95
+ }
96
+ } else if (extensions.length === 0) {
97
+ patterns = ["**/*.*"];
98
+ } else {
99
+ patterns = extensions.map((ext) => `**/*.${ext}`);
100
+ }
101
+ const globFiles = glob.sync(patterns.length === 1 ? patterns[0] : `{${patterns.join(",")}}`, {
102
+ cwd: projectDir,
103
+ ignore: ignorePatterns,
104
+ absolute: true,
105
+ nodir: true
106
+ });
107
+ const allFiles = /* @__PURE__ */ new Set([...initialFiles, ...globFiles]);
108
+ await Promise.all(Array.from(allFiles).map(hashAndPush));
109
+ hashArray.sort((a, b) => a.localeCompare(b));
110
+ function getFileTreeString(hashArray2) {
111
+ const tree = {};
112
+ const hashMap = {};
113
+ for (const entry of hashArray2) {
114
+ const [filePath, hash] = entry.split(" ");
115
+ hashMap[filePath] = hash;
116
+ const parts = filePath.split("/");
117
+ let current = tree;
118
+ for (let i = 0; i < parts.length; i++) {
119
+ const part = parts[i];
120
+ if (i === parts.length - 1) {
121
+ current[part] = null;
122
+ } else {
123
+ current[part] = current[part] || {};
124
+ current = current[part];
125
+ }
126
+ }
127
+ }
128
+ function printNode(node, prefix = "", parentPath = "") {
129
+ const keys = Object.keys(node).sort();
130
+ let lines = [];
131
+ keys.forEach((key, idx) => {
132
+ const isLast = idx === keys.length - 1;
133
+ const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
134
+ const currentPath = parentPath ? parentPath + "/" + key : key;
135
+ if (node[key] === null) {
136
+ lines.push(prefix + branch + key + " [" + (hashMap[currentPath] || "") + "]");
137
+ } else {
138
+ lines.push(prefix + branch + key + "/");
139
+ lines = lines.concat(printNode(node[key], prefix + (isLast ? " " : "\u2502 "), currentPath));
140
+ }
141
+ });
142
+ return lines;
143
+ }
144
+ return printNode(tree, "", "").join("\n");
145
+ }
146
+ const fileTreeString = getFileTreeString(hashArray);
147
+ await fs.writeFile(outputFile, fileTreeString + "\n", "utf-8");
148
+ if (argv["git-add"]) {
149
+ execSync(`git add ${relativeOutputFile}`);
150
+ console.log(`Directory tree written to ${relativeOutputFile} and staged for git.`);
151
+ } else {
152
+ console.log(`Directory tree written to ${relativeOutputFile}.`);
153
+ }
154
+ }
155
+ if (argv.help || argv.h) {
156
+ console.log(`
157
+ Usage: node print-directory-tree.cjs [options]
158
+
159
+ Options:
160
+ --output, -o <file> Output file path (default: tmp/directory-structure.txt)
161
+ --ext <exts> Comma-separated list of file extensions (no dot, e.g. js,ts)
162
+ --pattern <glob> Glob pattern(s) for files (can be repeated)
163
+ --exclude <dirs> Comma-separated list of directories to exclude (appends to default)
164
+ --override-exclude, -we Override default exclude directories with --exclude
165
+ --git-add Add output file to git after writing
166
+ --help, -h Show this help message
167
+
168
+ Examples:
169
+ node print-directory-tree.cjs --ext=js,ts
170
+ node print-directory-tree.cjs --pattern=src/**/*.js --pattern=test/**/*.js
171
+ node print-directory-tree.cjs --exclude=dist,build
172
+ node print-directory-tree.cjs --output=tmp/tree.txt
173
+ `);
174
+ process.exit(0);
175
+ }
176
+ main().catch((err) => {
177
+ console.error(err);
178
+ process.exit(1);
179
+ });
180
+ }
181
+ });
182
+ export default require_print_directory_tree();
@@ -1,7 +1,6 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
2
  import {
3
3
  require_connected_domain
4
- } from "../chunk-4LEXWIIF.mjs";
5
- import "../chunk-VXZQNLPU.mjs";
6
- import "../chunk-FB6YIQYR.mjs";
4
+ } from "../chunk-DPKAJKFO.mjs";
5
+ import "../chunk-AASHBCRW.mjs";
7
6
  export default require_connected_domain();
package/lib/ps/index.cjs CHANGED
@@ -504,7 +504,7 @@ exports.kill = function(pid, signal, next) {
504
504
  if (checkIsTimeout) return;
505
505
  if (err) {
506
506
  clearTimeout(checkTimeoutTimer);
507
- finishCallback && finishCallback(err);
507
+ if (finishCallback) finishCallback(err);
508
508
  } else if (list.length > 0) {
509
509
  checkConfident = checkConfident - 1 || 0;
510
510
  checkKilled(finishCallback);
@@ -512,14 +512,14 @@ exports.kill = function(pid, signal, next) {
512
512
  checkConfident++;
513
513
  if (checkConfident === 5) {
514
514
  clearTimeout(checkTimeoutTimer);
515
- finishCallback && finishCallback();
515
+ if (finishCallback) finishCallback();
516
516
  } else {
517
517
  checkKilled(finishCallback);
518
518
  }
519
519
  }
520
520
  });
521
521
  }
522
- next && checkKilled(next);
522
+ if (next) checkKilled(next);
523
523
  checkTimeoutTimer = next && setTimeout(function() {
524
524
  checkIsTimeout = true;
525
525
  next(new Error("Kill process timeout"));
@@ -1,8 +1,7 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
2
  import {
3
3
  init_esm_shims
4
- } from "../chunk-VXZQNLPU.mjs";
5
- import "../chunk-FB6YIQYR.mjs";
4
+ } from "../chunk-AASHBCRW.mjs";
6
5
 
7
6
  // src/ps/index.d.ts
8
7
  init_esm_shims();