@gajae-code/utils 0.12.6 → 0.12.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.
- package/package.json +2 -2
- package/src/glob.ts +13 -10
- package/src/postmortem.ts +6 -6
- package/src/which.ts +6 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@gajae-code/utils",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.8",
|
|
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.
|
|
34
|
+
"@gajae-code/natives": "0.12.8",
|
|
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
|
-
|
|
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
|
+
}
|
package/src/postmortem.ts
CHANGED
|
@@ -433,12 +433,12 @@ export function register(id: string, callback: (reason: Reason) => void | Promis
|
|
|
433
433
|
}
|
|
434
434
|
// If cleanup is already running/completed, warn and run on microtask.
|
|
435
435
|
logger.warn("Cleanup invoked recursively", { id });
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
436
|
+
queueMicrotask(() => {
|
|
437
|
+
void Promise.try(() => exec(Reason.MANUAL)).catch(error => {
|
|
438
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
439
|
+
logger.error("Cleanup callback failed", { err, id, stack: err.stack });
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
442
|
return () => {};
|
|
443
443
|
}
|
|
444
444
|
|
package/src/which.ts
CHANGED
|
@@ -183,9 +183,10 @@ export interface WhichOptions extends Bun.WhichOptions {
|
|
|
183
183
|
|
|
184
184
|
// Darwin-specific "which" shim: consult Xcode/CLT toolchain directories after $PATH.
|
|
185
185
|
// Uses cached directory listings instead of per-command existsSync or xcrun subprocesses.
|
|
186
|
-
function darwinWhich(command: string,
|
|
187
|
-
const regular = Bun.which(command);
|
|
186
|
+
function darwinWhich(command: string, options?: Bun.WhichOptions): string | null {
|
|
187
|
+
const regular = Bun.which(command, options);
|
|
188
188
|
if (regular) return regular;
|
|
189
|
+
if (options?.PATH !== undefined) return null;
|
|
189
190
|
if (isXcodeBin(command)) {
|
|
190
191
|
return getMacosToolPaths().get(command) ?? null;
|
|
191
192
|
}
|
|
@@ -198,10 +199,10 @@ export const whichFresh = os.platform() === "darwin" ? darwinWhich : Bun.which;
|
|
|
198
199
|
// Derive stable cache key from command and lookup options
|
|
199
200
|
function cacheKey(command: string, options?: Bun.WhichOptions): CacheKey {
|
|
200
201
|
if (!options) return command;
|
|
201
|
-
if (
|
|
202
|
+
if (options.cwd === undefined && options.PATH === undefined) return command;
|
|
202
203
|
let h = Bun.hash(command);
|
|
203
|
-
if (options.cwd) h = Bun.hash(options.cwd
|
|
204
|
-
if (options.PATH) h = Bun.hash(options.PATH
|
|
204
|
+
if (options.cwd !== undefined) h = Bun.hash(`cwd:${options.cwd}`, h);
|
|
205
|
+
if (options.PATH !== undefined) h = Bun.hash(`PATH:${options.PATH}`, h);
|
|
205
206
|
return h;
|
|
206
207
|
}
|
|
207
208
|
|