@optique/git 0.9.0-dev.264 → 0.9.0-dev.266
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/index.cjs +56 -42
- package/dist/index.js +56 -42
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,14 @@ const node_fs_promises = __toESM(require("node:fs/promises"));
|
|
|
28
28
|
const node_process = __toESM(require("node:process"));
|
|
29
29
|
|
|
30
30
|
//#region src/index.ts
|
|
31
|
+
/**
|
|
32
|
+
* Filesystem interface passed to isomorphic-git.
|
|
33
|
+
*
|
|
34
|
+
* Although this package only performs read operations (validation and listing),
|
|
35
|
+
* isomorphic-git's FsClient type requires write methods to be present.
|
|
36
|
+
* These methods are included for type compatibility but are never called
|
|
37
|
+
* by our read-only operations.
|
|
38
|
+
*/
|
|
31
39
|
const gitFs = {
|
|
32
40
|
readFile: node_fs_promises.readFile,
|
|
33
41
|
writeFile: node_fs_promises.writeFile,
|
|
@@ -301,26 +309,14 @@ function gitRemote(options) {
|
|
|
301
309
|
function gitCommit(options) {
|
|
302
310
|
const metavar = options?.metavar ?? "COMMIT";
|
|
303
311
|
return createAsyncValueParser(options, metavar, async (dir, input, errors) => {
|
|
304
|
-
|
|
305
|
-
(0, __optique_core_nonempty.ensureNonEmptyString)(input);
|
|
306
|
-
} catch {
|
|
312
|
+
if (!/^[0-9a-f]{4,40}$/i.test(input)) {
|
|
307
313
|
if (errors?.invalidFormat) return {
|
|
308
314
|
success: false,
|
|
309
315
|
error: errors.invalidFormat(input)
|
|
310
316
|
};
|
|
311
317
|
return {
|
|
312
318
|
success: false,
|
|
313
|
-
error: __optique_core_message.message`Invalid commit SHA: ${(0, __optique_core_message.value)(input)}
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
if (input.length < 4 || input.length > 40) {
|
|
317
|
-
if (errors?.invalidFormat) return {
|
|
318
|
-
success: false,
|
|
319
|
-
error: errors.invalidFormat(input)
|
|
320
|
-
};
|
|
321
|
-
return {
|
|
322
|
-
success: false,
|
|
323
|
-
error: __optique_core_message.message`Commit ${(0, __optique_core_message.value)(input)} must be between 4 and 40 characters.`
|
|
319
|
+
error: __optique_core_message.message`Invalid commit SHA: ${(0, __optique_core_message.value)(input)}. Commits must be 4–40 hexadecimal characters.`
|
|
324
320
|
};
|
|
325
321
|
}
|
|
326
322
|
try {
|
|
@@ -375,37 +371,37 @@ function gitCommit(options) {
|
|
|
375
371
|
function gitRef(options) {
|
|
376
372
|
const metavar = options?.metavar ?? "REF";
|
|
377
373
|
return createAsyncValueParser(options, metavar, async (dir, input, errors) => {
|
|
374
|
+
let resolved;
|
|
378
375
|
try {
|
|
379
|
-
|
|
376
|
+
resolved = await isomorphic_git.resolveRef({
|
|
380
377
|
fs: gitFs,
|
|
381
378
|
dir,
|
|
382
379
|
ref: input
|
|
383
380
|
});
|
|
381
|
+
} catch {}
|
|
382
|
+
if (resolved) return {
|
|
383
|
+
success: true,
|
|
384
|
+
value: resolved
|
|
385
|
+
};
|
|
386
|
+
try {
|
|
387
|
+
const oid = await isomorphic_git.expandOid({
|
|
388
|
+
fs: gitFs,
|
|
389
|
+
dir,
|
|
390
|
+
oid: input
|
|
391
|
+
});
|
|
384
392
|
return {
|
|
385
393
|
success: true,
|
|
386
|
-
value:
|
|
394
|
+
value: oid
|
|
387
395
|
};
|
|
388
396
|
} catch {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
value: oid
|
|
398
|
-
};
|
|
399
|
-
} catch {
|
|
400
|
-
if (errors?.notFound) return {
|
|
401
|
-
success: false,
|
|
402
|
-
error: errors.notFound(input)
|
|
403
|
-
};
|
|
404
|
-
return {
|
|
405
|
-
success: false,
|
|
406
|
-
error: __optique_core_message.message`Reference ${(0, __optique_core_message.value)(input)} does not exist. Provide a valid branch, tag, or commit SHA.`
|
|
407
|
-
};
|
|
408
|
-
}
|
|
397
|
+
if (errors?.notFound) return {
|
|
398
|
+
success: false,
|
|
399
|
+
error: errors.notFound(input)
|
|
400
|
+
};
|
|
401
|
+
return {
|
|
402
|
+
success: false,
|
|
403
|
+
error: __optique_core_message.message`Reference ${(0, __optique_core_message.value)(input)} does not exist. Provide a valid branch, tag, or commit SHA.`
|
|
404
|
+
};
|
|
409
405
|
}
|
|
410
406
|
}, async function* suggestRef(dir, prefix) {
|
|
411
407
|
try {
|
|
@@ -453,12 +449,30 @@ function gitRef(options) {
|
|
|
453
449
|
*/
|
|
454
450
|
function createGitParsers(options) {
|
|
455
451
|
return {
|
|
456
|
-
branch: (branchOptions) => gitBranch(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
452
|
+
branch: (branchOptions) => gitBranch({
|
|
453
|
+
...options,
|
|
454
|
+
...branchOptions
|
|
455
|
+
}),
|
|
456
|
+
remoteBranch: (remote, branchOptions) => gitRemoteBranch(remote, {
|
|
457
|
+
...options,
|
|
458
|
+
...branchOptions
|
|
459
|
+
}),
|
|
460
|
+
tag: (tagOptions) => gitTag({
|
|
461
|
+
...options,
|
|
462
|
+
...tagOptions
|
|
463
|
+
}),
|
|
464
|
+
remote: (remoteOptions) => gitRemote({
|
|
465
|
+
...options,
|
|
466
|
+
...remoteOptions
|
|
467
|
+
}),
|
|
468
|
+
commit: (commitOptions) => gitCommit({
|
|
469
|
+
...options,
|
|
470
|
+
...commitOptions
|
|
471
|
+
}),
|
|
472
|
+
ref: (refOptions) => gitRef({
|
|
473
|
+
...options,
|
|
474
|
+
...refOptions
|
|
475
|
+
})
|
|
462
476
|
};
|
|
463
477
|
}
|
|
464
478
|
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,14 @@ import * as fs from "node:fs/promises";
|
|
|
6
6
|
import process from "node:process";
|
|
7
7
|
|
|
8
8
|
//#region src/index.ts
|
|
9
|
+
/**
|
|
10
|
+
* Filesystem interface passed to isomorphic-git.
|
|
11
|
+
*
|
|
12
|
+
* Although this package only performs read operations (validation and listing),
|
|
13
|
+
* isomorphic-git's FsClient type requires write methods to be present.
|
|
14
|
+
* These methods are included for type compatibility but are never called
|
|
15
|
+
* by our read-only operations.
|
|
16
|
+
*/
|
|
9
17
|
const gitFs = {
|
|
10
18
|
readFile: fs.readFile,
|
|
11
19
|
writeFile: fs.writeFile,
|
|
@@ -279,26 +287,14 @@ function gitRemote(options) {
|
|
|
279
287
|
function gitCommit(options) {
|
|
280
288
|
const metavar = options?.metavar ?? "COMMIT";
|
|
281
289
|
return createAsyncValueParser(options, metavar, async (dir, input, errors) => {
|
|
282
|
-
|
|
283
|
-
ensureNonEmptyString(input);
|
|
284
|
-
} catch {
|
|
290
|
+
if (!/^[0-9a-f]{4,40}$/i.test(input)) {
|
|
285
291
|
if (errors?.invalidFormat) return {
|
|
286
292
|
success: false,
|
|
287
293
|
error: errors.invalidFormat(input)
|
|
288
294
|
};
|
|
289
295
|
return {
|
|
290
296
|
success: false,
|
|
291
|
-
error: message`Invalid commit SHA: ${value(input)}
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
if (input.length < 4 || input.length > 40) {
|
|
295
|
-
if (errors?.invalidFormat) return {
|
|
296
|
-
success: false,
|
|
297
|
-
error: errors.invalidFormat(input)
|
|
298
|
-
};
|
|
299
|
-
return {
|
|
300
|
-
success: false,
|
|
301
|
-
error: message`Commit ${value(input)} must be between 4 and 40 characters.`
|
|
297
|
+
error: message`Invalid commit SHA: ${value(input)}. Commits must be 4–40 hexadecimal characters.`
|
|
302
298
|
};
|
|
303
299
|
}
|
|
304
300
|
try {
|
|
@@ -353,37 +349,37 @@ function gitCommit(options) {
|
|
|
353
349
|
function gitRef(options) {
|
|
354
350
|
const metavar = options?.metavar ?? "REF";
|
|
355
351
|
return createAsyncValueParser(options, metavar, async (dir, input, errors) => {
|
|
352
|
+
let resolved;
|
|
356
353
|
try {
|
|
357
|
-
|
|
354
|
+
resolved = await git.resolveRef({
|
|
358
355
|
fs: gitFs,
|
|
359
356
|
dir,
|
|
360
357
|
ref: input
|
|
361
358
|
});
|
|
359
|
+
} catch {}
|
|
360
|
+
if (resolved) return {
|
|
361
|
+
success: true,
|
|
362
|
+
value: resolved
|
|
363
|
+
};
|
|
364
|
+
try {
|
|
365
|
+
const oid = await git.expandOid({
|
|
366
|
+
fs: gitFs,
|
|
367
|
+
dir,
|
|
368
|
+
oid: input
|
|
369
|
+
});
|
|
362
370
|
return {
|
|
363
371
|
success: true,
|
|
364
|
-
value:
|
|
372
|
+
value: oid
|
|
365
373
|
};
|
|
366
374
|
} catch {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
value: oid
|
|
376
|
-
};
|
|
377
|
-
} catch {
|
|
378
|
-
if (errors?.notFound) return {
|
|
379
|
-
success: false,
|
|
380
|
-
error: errors.notFound(input)
|
|
381
|
-
};
|
|
382
|
-
return {
|
|
383
|
-
success: false,
|
|
384
|
-
error: message`Reference ${value(input)} does not exist. Provide a valid branch, tag, or commit SHA.`
|
|
385
|
-
};
|
|
386
|
-
}
|
|
375
|
+
if (errors?.notFound) return {
|
|
376
|
+
success: false,
|
|
377
|
+
error: errors.notFound(input)
|
|
378
|
+
};
|
|
379
|
+
return {
|
|
380
|
+
success: false,
|
|
381
|
+
error: message`Reference ${value(input)} does not exist. Provide a valid branch, tag, or commit SHA.`
|
|
382
|
+
};
|
|
387
383
|
}
|
|
388
384
|
}, async function* suggestRef(dir, prefix) {
|
|
389
385
|
try {
|
|
@@ -431,12 +427,30 @@ function gitRef(options) {
|
|
|
431
427
|
*/
|
|
432
428
|
function createGitParsers(options) {
|
|
433
429
|
return {
|
|
434
|
-
branch: (branchOptions) => gitBranch(
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
430
|
+
branch: (branchOptions) => gitBranch({
|
|
431
|
+
...options,
|
|
432
|
+
...branchOptions
|
|
433
|
+
}),
|
|
434
|
+
remoteBranch: (remote, branchOptions) => gitRemoteBranch(remote, {
|
|
435
|
+
...options,
|
|
436
|
+
...branchOptions
|
|
437
|
+
}),
|
|
438
|
+
tag: (tagOptions) => gitTag({
|
|
439
|
+
...options,
|
|
440
|
+
...tagOptions
|
|
441
|
+
}),
|
|
442
|
+
remote: (remoteOptions) => gitRemote({
|
|
443
|
+
...options,
|
|
444
|
+
...remoteOptions
|
|
445
|
+
}),
|
|
446
|
+
commit: (commitOptions) => gitCommit({
|
|
447
|
+
...options,
|
|
448
|
+
...commitOptions
|
|
449
|
+
}),
|
|
450
|
+
ref: (refOptions) => gitRef({
|
|
451
|
+
...options,
|
|
452
|
+
...refOptions
|
|
453
|
+
})
|
|
440
454
|
};
|
|
441
455
|
}
|
|
442
456
|
|