@gajae-code/utils 0.12.6 → 0.12.7

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/glob.ts +13 -10
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@gajae-code/utils",
4
- "version": "0.12.6",
4
+ "version": "0.12.7",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://gajae-code.com",
7
7
  "author": "Yeachan-Heo",
@@ -31,7 +31,7 @@
31
31
  "fmt": "biome format --write ."
32
32
  },
33
33
  "dependencies": {
34
- "@gajae-code/natives": "0.12.6",
34
+ "@gajae-code/natives": "0.12.7",
35
35
  "beautiful-mermaid": "^1.1.3",
36
36
  "handlebars": "^4.7.9",
37
37
  "winston": "^3.19.0",
package/src/glob.ts CHANGED
@@ -137,6 +137,10 @@ export async function loadGitignorePatterns(baseDir: string): Promise<string[]>
137
137
  */
138
138
  export async function globPaths(patterns: string | string[], options: GlobPathsOptions = {}): Promise<string[]> {
139
139
  const { cwd, exclude, signal, timeoutMs, dot, onlyFiles = true, gitignore } = options;
140
+ const timeoutSignal = timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined;
141
+ const combinedSignal =
142
+ signal && timeoutSignal ? AbortSignal.any([signal, timeoutSignal]) : (signal ?? timeoutSignal);
143
+ throwIfGlobAborted(combinedSignal);
140
144
 
141
145
  // Build exclude list: always exclude .git, exclude node_modules unless pattern references it
142
146
  const patternArray = Array.isArray(patterns) ? patterns : [patterns];
@@ -147,6 +151,7 @@ export async function globPaths(patterns: string | string[], options: GlobPathsO
147
151
 
148
152
  if (gitignore) {
149
153
  const gitignorePatterns = await loadGitignorePatterns(cwd ?? getProjectDir());
154
+ throwIfGlobAborted(combinedSignal);
150
155
  effectiveExclude = [...effectiveExclude, ...gitignorePatterns];
151
156
  }
152
157
 
@@ -158,11 +163,6 @@ export async function globPaths(patterns: string | string[], options: GlobPathsO
158
163
  // file; dedupe so a path is returned at most once regardless of pattern overlap.
159
164
  const seen = new Set<string>();
160
165
 
161
- // Combine timeout and abort signals
162
- const timeoutSignal = timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined;
163
- const combinedSignal =
164
- signal && timeoutSignal ? AbortSignal.any([signal, timeoutSignal]) : (signal ?? timeoutSignal);
165
-
166
166
  for (const pattern of patternArray) {
167
167
  const glob = new Glob(pattern);
168
168
  const scanOptions = {
@@ -173,11 +173,7 @@ export async function globPaths(patterns: string | string[], options: GlobPathsO
173
173
  };
174
174
 
175
175
  for await (const entry of glob.scan(scanOptions)) {
176
- if (combinedSignal?.aborted) {
177
- const reason = combinedSignal.reason;
178
- if (reason instanceof Error) throw reason;
179
- throw new DOMException("Aborted", "AbortError");
180
- }
176
+ throwIfGlobAborted(combinedSignal);
181
177
 
182
178
  // Check exclusion patterns
183
179
  const normalized = entry.replace(/\\/g, "/");
@@ -190,7 +186,14 @@ export async function globPaths(patterns: string | string[], options: GlobPathsO
190
186
  seen.add(normalized);
191
187
  allResults.push(normalized);
192
188
  }
189
+ throwIfGlobAborted(combinedSignal);
193
190
  }
194
191
 
195
192
  return allResults;
196
193
  }
194
+
195
+ function throwIfGlobAborted(signal: AbortSignal | undefined): void {
196
+ if (!signal?.aborted) return;
197
+ if (signal.reason instanceof Error) throw signal.reason;
198
+ throw new DOMException("Aborted", "AbortError");
199
+ }