@gajae-code/utils 0.12.5 → 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.
- package/dist/types/env.d.ts +1 -1
- package/package.json +2 -2
- package/src/env.ts +12 -10
- package/src/fetch-retry.ts +1 -0
- package/src/glob.ts +13 -10
package/dist/types/env.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare function $credentialEnv(name: string): string | undefined;
|
|
|
31
31
|
export declare function $pickCredentialEnv(...keys: string[]): string | undefined;
|
|
32
32
|
/**
|
|
33
33
|
* Parses a positive decimal integer from `$env[name]`.
|
|
34
|
-
* Empty, invalid,
|
|
34
|
+
* Empty, invalid, unsafe, zero, or negative values return `defaultValue`.
|
|
35
35
|
*/
|
|
36
36
|
export declare function $envpos(name: string, defaultValue: number): number;
|
|
37
37
|
/** True when `BUN_ENV` or `NODE_ENV` is the string `test`. */
|
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.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.
|
|
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/env.ts
CHANGED
|
@@ -147,16 +147,20 @@ export function $pickCredentialEnv(...keys: string[]): string | undefined {
|
|
|
147
147
|
return undefined;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
function parsePositiveInteger(raw: string | undefined): number | undefined {
|
|
151
|
+
const value = raw?.trim();
|
|
152
|
+
if (!value || !/^\d+$/.test(value)) return undefined;
|
|
153
|
+
const parsed = Number(value);
|
|
154
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
150
157
|
/**
|
|
151
158
|
* Parses a positive decimal integer from `$env[name]`.
|
|
152
|
-
* Empty, invalid,
|
|
159
|
+
* Empty, invalid, unsafe, zero, or negative values return `defaultValue`.
|
|
153
160
|
*/
|
|
154
161
|
export function $envpos(name: string, defaultValue: number): number {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
const parsed = Number.parseInt(raw, 10);
|
|
158
|
-
if (Number.isNaN(parsed) || parsed <= 0) return defaultValue;
|
|
159
|
-
return parsed;
|
|
162
|
+
const parsed = parsePositiveInteger($env[name]);
|
|
163
|
+
return parsed ?? defaultValue;
|
|
160
164
|
}
|
|
161
165
|
|
|
162
166
|
/** True when `BUN_ENV` or `NODE_ENV` is the string `test`. */
|
|
@@ -200,10 +204,8 @@ export function $pickflag(...keys: string[]): boolean {
|
|
|
200
204
|
/** Resolve the first positive integer among keys, else defaultValue (GJC-first). Set-but-invalid keys are skipped. */
|
|
201
205
|
export function $pickenvpos(keys: string[], defaultValue: number): number {
|
|
202
206
|
for (const key of keys) {
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
205
|
-
const parsed = Number.parseInt(raw, 10);
|
|
206
|
-
if (!Number.isNaN(parsed) && parsed > 0) return parsed;
|
|
207
|
+
const parsed = parsePositiveInteger($env[key]);
|
|
208
|
+
if (parsed !== undefined) return parsed;
|
|
207
209
|
}
|
|
208
210
|
return defaultValue;
|
|
209
211
|
}
|
package/src/fetch-retry.ts
CHANGED
|
@@ -153,6 +153,7 @@ export async function fetchWithRetry(
|
|
|
153
153
|
if (hint !== undefined && hint > maxDelayMs) return response;
|
|
154
154
|
|
|
155
155
|
const delayMs = Math.min(hint ?? resolveDefaultDelay(defaultDelayMs, attempt, maxDelayMs), maxDelayMs);
|
|
156
|
+
void response.body?.cancel().catch(() => undefined);
|
|
156
157
|
await scheduler.wait(delayMs, { signal });
|
|
157
158
|
}
|
|
158
159
|
}
|
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
|
+
}
|