@linxiraos/pi-utils 1.1.15 → 1.1.16

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 (51) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/THIRD-PARTY-NOTICES.txt +54 -25
  3. package/dist/types/async.d.ts +18 -0
  4. package/dist/types/browsers.d.ts +2 -30
  5. package/dist/types/color.d.ts +2 -0
  6. package/dist/types/dirs.d.ts +18 -1
  7. package/dist/types/env.d.ts +12 -2
  8. package/dist/types/executable.d.ts +4 -0
  9. package/dist/types/fetch-retry.d.ts +8 -2
  10. package/dist/types/file-lock.d.ts +6 -0
  11. package/dist/types/format.d.ts +7 -0
  12. package/dist/types/index.d.ts +2 -1
  13. package/dist/types/mime.d.ts +1 -0
  14. package/dist/types/path.d.ts +6 -0
  15. package/dist/types/peek-file.d.ts +2 -3
  16. package/dist/types/postmortem.d.ts +26 -5
  17. package/dist/types/procmgr.d.ts +2 -4
  18. package/dist/types/snowflake.d.ts +1 -0
  19. package/dist/types/sqlite.d.ts +27 -7
  20. package/dist/types/stream.d.ts +76 -1
  21. package/dist/types/which.d.ts +8 -2
  22. package/dist/types/yaml-config.d.ts +2 -0
  23. package/package.json +2 -2
  24. package/src/acp/transport.ts +37 -3
  25. package/src/async.ts +31 -0
  26. package/src/browsers.ts +10 -169
  27. package/src/color.ts +1 -1
  28. package/src/dirs.ts +28 -6
  29. package/src/env.ts +81 -34
  30. package/src/executable.ts +17 -0
  31. package/src/fetch-retry.ts +72 -13
  32. package/src/file-lock.ts +28 -0
  33. package/src/format.ts +16 -0
  34. package/src/index.ts +2 -1
  35. package/src/json.ts +12 -1
  36. package/src/logger/rotating-file.ts +40 -3
  37. package/src/logger.ts +16 -4
  38. package/src/mime.ts +3 -7
  39. package/src/path.ts +14 -0
  40. package/src/peek-file.ts +17 -67
  41. package/src/postmortem.ts +95 -47
  42. package/src/procmgr.ts +2 -12
  43. package/src/ptree.ts +36 -5
  44. package/src/snowflake.ts +12 -1
  45. package/src/sqlite.ts +242 -7
  46. package/src/stream.ts +167 -35
  47. package/src/which.ts +38 -14
  48. package/src/xml.ts +16 -0
  49. package/src/yaml-config.ts +8 -0
  50. package/dist/types/glob.d.ts +0 -28
  51. package/src/glob.ts +0 -189
package/src/glob.ts DELETED
@@ -1,189 +0,0 @@
1
- import * as path from "node:path";
2
- import { Glob } from "bun";
3
- import { getProjectDir } from "./dirs";
4
-
5
- export interface GlobPathsOptions {
6
- /** Base directory for glob patterns. Defaults to getProjectDir(). */
7
- cwd?: string;
8
- /** Glob exclusion patterns. */
9
- exclude?: string[];
10
- /** Abort signal to cancel the glob. */
11
- signal?: AbortSignal;
12
- /** Timeout in milliseconds for the glob operation. */
13
- timeoutMs?: number;
14
- /** Include dotfiles when true. */
15
- dot?: boolean;
16
- /** Only return files (skip directories). Default: true. */
17
- onlyFiles?: boolean;
18
- /** Respect .gitignore files when true. Walks up directory tree to find all applicable .gitignore files. */
19
- gitignore?: boolean;
20
- }
21
-
22
- /** Patterns always excluded (.git is never useful in glob results). */
23
- const ALWAYS_IGNORED = ["**/.git", "**/.git/**"];
24
-
25
- /** node_modules exclusion patterns (skipped if pattern explicitly references node_modules). */
26
- const NODE_MODULES_IGNORED = ["**/node_modules", "**/node_modules/**"];
27
-
28
- /**
29
- * Parse a single .gitignore file and return glob-compatible exclude patterns.
30
- * @param content - Raw content of the .gitignore file
31
- * @param gitignoreDir - Absolute path to the directory containing the .gitignore
32
- * @param baseDir - Absolute path to the glob's cwd (for relativizing rooted patterns)
33
- */
34
- function parseGitignorePatterns(content: string, gitignoreDir: string, baseDir: string): string[] {
35
- const patterns: string[] = [];
36
-
37
- for (const rawLine of content.split("\n")) {
38
- const line = rawLine.trim();
39
- // Skip empty lines and comments
40
- if (!line || line.startsWith("#")) {
41
- continue;
42
- }
43
- // Skip negation patterns (unsupported for simple exclude)
44
- if (line.startsWith("!")) {
45
- continue;
46
- }
47
-
48
- let pattern = line;
49
-
50
- // Handle trailing slash (directory-only match)
51
- // For glob exclude, we treat it as matching the dir and its contents
52
- const isDirectoryOnly = pattern.endsWith("/");
53
- if (isDirectoryOnly) {
54
- pattern = pattern.slice(0, -1);
55
- }
56
-
57
- // Handle rooted patterns (start with /)
58
- if (pattern.startsWith("/")) {
59
- // Rooted pattern: relative to the .gitignore location
60
- const absolutePattern = path.join(gitignoreDir, pattern.slice(1));
61
- const relativeToBase = path.relative(baseDir, absolutePattern);
62
- if (relativeToBase.startsWith("..")) {
63
- // Pattern is outside the search directory, skip
64
- continue;
65
- }
66
- pattern = relativeToBase.replace(/\\/g, "/");
67
- if (isDirectoryOnly) {
68
- patterns.push(pattern);
69
- patterns.push(`${pattern}/**`);
70
- } else {
71
- patterns.push(pattern);
72
- }
73
- } else {
74
- // Unrooted pattern: match anywhere in the tree
75
- if (pattern.includes("/")) {
76
- // Contains slash: match from any directory level
77
- patterns.push(`**/${pattern}`);
78
- if (isDirectoryOnly) {
79
- patterns.push(`**/${pattern}/**`);
80
- }
81
- } else {
82
- // No slash: match file/dir name anywhere
83
- patterns.push(`**/${pattern}`);
84
- if (isDirectoryOnly) {
85
- patterns.push(`**/${pattern}/**`);
86
- }
87
- }
88
- }
89
- }
90
-
91
- return patterns;
92
- }
93
-
94
- /**
95
- * Load .gitignore patterns from a directory and its parents.
96
- * Walks up the directory tree to find all applicable .gitignore files.
97
- * Returns glob-compatible exclude patterns.
98
- */
99
- export async function loadGitignorePatterns(baseDir: string): Promise<string[]> {
100
- const patterns: string[] = [];
101
- const absoluteBase = path.resolve(baseDir);
102
-
103
- let current = absoluteBase;
104
- const maxDepth = 50; // Prevent infinite loops
105
-
106
- for (let i = 0; i < maxDepth; i++) {
107
- const gitignorePath = path.join(current, ".gitignore");
108
-
109
- try {
110
- const content = await Bun.file(gitignorePath).text();
111
- const filePatterns = parseGitignorePatterns(content, current, absoluteBase);
112
- patterns.push(...filePatterns);
113
- } catch {
114
- // .gitignore doesn't exist or can't be read, continue
115
- }
116
-
117
- const parent = path.dirname(current);
118
- if (parent === current) {
119
- // Reached filesystem root
120
- break;
121
- }
122
- current = parent;
123
- }
124
-
125
- return patterns;
126
- }
127
-
128
- /**
129
- * Resolve filesystem paths matching glob patterns with optional exclude filters.
130
- * Returns paths relative to the provided cwd (or getProjectDir()).
131
- * Errors and abort/timeouts are surfaced to the caller.
132
- */
133
- export async function globPaths(patterns: string | string[], options: GlobPathsOptions = {}): Promise<string[]> {
134
- const { cwd, exclude, signal, timeoutMs, dot, onlyFiles = true, gitignore } = options;
135
-
136
- // Build exclude list: always exclude .git, exclude node_modules unless pattern references it
137
- const patternArray = Array.isArray(patterns) ? patterns : [patterns];
138
- const mentionsNodeModules = patternArray.some(p => p.includes("node_modules"));
139
-
140
- const baseExclude = mentionsNodeModules ? [...ALWAYS_IGNORED] : [...ALWAYS_IGNORED, ...NODE_MODULES_IGNORED];
141
- let effectiveExclude = exclude ? [...baseExclude, ...exclude] : baseExclude;
142
-
143
- if (gitignore) {
144
- const gitignorePatterns = await loadGitignorePatterns(cwd ?? getProjectDir());
145
- effectiveExclude = [...effectiveExclude, ...gitignorePatterns];
146
- }
147
-
148
- const base = cwd ?? getProjectDir();
149
- const allResults: string[] = [];
150
-
151
- // Combine timeout and abort signals
152
- const timeoutSignal = timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined;
153
- const combinedSignal =
154
- signal && timeoutSignal ? AbortSignal.any([signal, timeoutSignal]) : (signal ?? timeoutSignal);
155
-
156
- for (const pattern of patternArray) {
157
- const glob = new Glob(pattern);
158
- const scanOptions = {
159
- cwd: base,
160
- dot,
161
- onlyFiles,
162
- throwErrorOnBrokenSymlink: false,
163
- };
164
-
165
- for await (const entry of glob.scan(scanOptions)) {
166
- if (combinedSignal?.aborted) {
167
- const reason = combinedSignal.reason;
168
- if (reason instanceof Error) throw reason;
169
- throw new DOMException("Aborted", "AbortError");
170
- }
171
-
172
- // Check exclusion patterns
173
- const normalized = entry.replace(/\\/g, "/");
174
- let excluded = false;
175
- for (const excludePattern of effectiveExclude) {
176
- const excludeGlob = new Glob(excludePattern);
177
- if (excludeGlob.match(normalized)) {
178
- excluded = true;
179
- break;
180
- }
181
- }
182
- if (!excluded) {
183
- allResults.push(normalized);
184
- }
185
- }
186
- }
187
-
188
- return allResults;
189
- }