type-git 0.2.0 → 0.3.0-alpha.0
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/README.md +38 -0
- package/dist/adapters/bun/index.d.cts +1 -1
- package/dist/adapters/bun/index.d.ts +1 -1
- package/dist/adapters/deno/index.d.cts +1 -1
- package/dist/adapters/deno/index.d.ts +1 -1
- package/dist/adapters/node/index.cjs +100 -23
- package/dist/adapters/node/index.cjs.map +1 -1
- package/dist/adapters/node/index.d.cts +8 -1
- package/dist/adapters/node/index.d.ts +8 -1
- package/dist/adapters/node/index.js +100 -23
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/{adapters-BFRtEriX.d.cts → adapters-BEKkCViX.d.cts} +123 -1
- package/dist/{adapters-BFRtEriX.d.ts → adapters-BEKkCViX.d.ts} +123 -1
- package/dist/index.cjs +100 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +100 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, R as RuntimeAdapters, i as ExecutionContext, j as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-
|
|
1
|
+
import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, A as AuditConfig, R as RuntimeAdapters, i as ExecutionContext, j as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-BEKkCViX.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* stdout parsing utilities for Git output
|
|
@@ -3946,6 +3946,8 @@ type CliRunnerOptions = {
|
|
|
3946
3946
|
home?: string;
|
|
3947
3947
|
/** Credential helper configuration */
|
|
3948
3948
|
credential?: CredentialHelperConfig;
|
|
3949
|
+
/** Audit configuration for command tracking and tracing */
|
|
3950
|
+
audit?: AuditConfig;
|
|
3949
3951
|
};
|
|
3950
3952
|
/**
|
|
3951
3953
|
* CLI Runner for executing Git commands
|
|
@@ -3963,6 +3965,7 @@ declare class CliRunner {
|
|
|
3963
3965
|
private readonly pathPrefix;
|
|
3964
3966
|
private readonly home;
|
|
3965
3967
|
private readonly credential;
|
|
3968
|
+
private readonly audit;
|
|
3966
3969
|
constructor(adapters: RuntimeAdapters, options?: CliRunnerOptions);
|
|
3967
3970
|
/**
|
|
3968
3971
|
* Create a new CliRunner with additional options merged
|
|
@@ -3988,6 +3991,10 @@ declare class CliRunner {
|
|
|
3988
3991
|
* Run a Git command
|
|
3989
3992
|
*/
|
|
3990
3993
|
run(context: ExecutionContext, args: string[], opts?: ExecOpts): Promise<RawResult>;
|
|
3994
|
+
/**
|
|
3995
|
+
* Process a single line from stderr for progress and trace callbacks
|
|
3996
|
+
*/
|
|
3997
|
+
private processStderrLine;
|
|
3991
3998
|
/**
|
|
3992
3999
|
* Map Git result to GitError if needed
|
|
3993
4000
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, R as RuntimeAdapters, i as ExecutionContext, j as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-
|
|
1
|
+
import { G as GitErrorCategory, e as ExecOpts, f as RawResult, L as LfsMode, g as GitProgress, h as GitOpenOptions, A as AuditConfig, R as RuntimeAdapters, i as ExecutionContext, j as GitError, E as ExecAdapter, C as Capabilities, S as SpawnOptions, a as StreamHandler, b as SpawnResult, c as SpawnHandle, F as FsAdapter, T as TailOptions, d as TailHandle } from '../../adapters-BEKkCViX.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* stdout parsing utilities for Git output
|
|
@@ -3946,6 +3946,8 @@ type CliRunnerOptions = {
|
|
|
3946
3946
|
home?: string;
|
|
3947
3947
|
/** Credential helper configuration */
|
|
3948
3948
|
credential?: CredentialHelperConfig;
|
|
3949
|
+
/** Audit configuration for command tracking and tracing */
|
|
3950
|
+
audit?: AuditConfig;
|
|
3949
3951
|
};
|
|
3950
3952
|
/**
|
|
3951
3953
|
* CLI Runner for executing Git commands
|
|
@@ -3963,6 +3965,7 @@ declare class CliRunner {
|
|
|
3963
3965
|
private readonly pathPrefix;
|
|
3964
3966
|
private readonly home;
|
|
3965
3967
|
private readonly credential;
|
|
3968
|
+
private readonly audit;
|
|
3966
3969
|
constructor(adapters: RuntimeAdapters, options?: CliRunnerOptions);
|
|
3967
3970
|
/**
|
|
3968
3971
|
* Create a new CliRunner with additional options merged
|
|
@@ -3988,6 +3991,10 @@ declare class CliRunner {
|
|
|
3988
3991
|
* Run a Git command
|
|
3989
3992
|
*/
|
|
3990
3993
|
run(context: ExecutionContext, args: string[], opts?: ExecOpts): Promise<RawResult>;
|
|
3994
|
+
/**
|
|
3995
|
+
* Process a single line from stderr for progress and trace callbacks
|
|
3996
|
+
*/
|
|
3997
|
+
private processStderrLine;
|
|
3991
3998
|
/**
|
|
3992
3999
|
* Map Git result to GitError if needed
|
|
3993
4000
|
*/
|
|
@@ -420,6 +420,7 @@ import process2 from "process";
|
|
|
420
420
|
var FATAL_ERROR_PATTERN = /fatal:\s*(.+)/i;
|
|
421
421
|
var ERROR_PATTERN = /error:\s*(.+)/i;
|
|
422
422
|
var LINE_SEPARATOR_PATTERN = /\r|\n/;
|
|
423
|
+
var GIT_TRACE_PATTERN = /^\d{2}:\d{2}:\d{2}\.\d+\s+(?:trace:|[A-Za-z0-9_.-]+\.c:)/;
|
|
423
424
|
function toLfsProgress(info) {
|
|
424
425
|
if (!info) {
|
|
425
426
|
return null;
|
|
@@ -472,6 +473,7 @@ var CliRunner = class _CliRunner {
|
|
|
472
473
|
pathPrefix;
|
|
473
474
|
home;
|
|
474
475
|
credential;
|
|
476
|
+
audit;
|
|
475
477
|
constructor(adapters, options) {
|
|
476
478
|
this.exec = adapters.exec;
|
|
477
479
|
this.gitBinary = options?.gitBinary ?? "git";
|
|
@@ -479,6 +481,7 @@ var CliRunner = class _CliRunner {
|
|
|
479
481
|
this.pathPrefix = options?.pathPrefix ?? [];
|
|
480
482
|
this.home = options?.home;
|
|
481
483
|
this.credential = options?.credential;
|
|
484
|
+
this.audit = options?.audit;
|
|
482
485
|
}
|
|
483
486
|
/**
|
|
484
487
|
* Create a new CliRunner with additional options merged
|
|
@@ -490,6 +493,7 @@ var CliRunner = class _CliRunner {
|
|
|
490
493
|
const mergedPathPrefix = [...this.pathPrefix, ...options.pathPrefix ?? []];
|
|
491
494
|
const home = options.home ?? this.home;
|
|
492
495
|
const credential = options.credential ?? this.credential;
|
|
496
|
+
const audit = options.audit ?? this.audit;
|
|
493
497
|
return new _CliRunner(
|
|
494
498
|
{
|
|
495
499
|
exec: this.exec,
|
|
@@ -506,7 +510,8 @@ var CliRunner = class _CliRunner {
|
|
|
506
510
|
env: mergedEnv,
|
|
507
511
|
pathPrefix: mergedPathPrefix,
|
|
508
512
|
home,
|
|
509
|
-
credential
|
|
513
|
+
credential,
|
|
514
|
+
audit
|
|
510
515
|
}
|
|
511
516
|
);
|
|
512
517
|
}
|
|
@@ -554,6 +559,15 @@ var CliRunner = class _CliRunner {
|
|
|
554
559
|
const currentPath = process2.env.PATH ?? "";
|
|
555
560
|
env.PATH = [...allPathPrefixes, currentPath].join(separator);
|
|
556
561
|
}
|
|
562
|
+
if (this.audit?.onTrace) {
|
|
563
|
+
if (env.GIT_TRACE === void 0) {
|
|
564
|
+
env.GIT_TRACE = "1";
|
|
565
|
+
} else if (!env.GIT_TRACE || env.GIT_TRACE === "0") {
|
|
566
|
+
console.warn(
|
|
567
|
+
"type-git: onTrace callback provided but GIT_TRACE is disabled. Trace events will not be emitted."
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
557
571
|
return env;
|
|
558
572
|
}
|
|
559
573
|
/**
|
|
@@ -577,27 +591,70 @@ var CliRunner = class _CliRunner {
|
|
|
577
591
|
if (onLfsProgress) {
|
|
578
592
|
env.GIT_LFS_FORCE_PROGRESS = "1";
|
|
579
593
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
{
|
|
594
|
+
const startTimestamp = Date.now();
|
|
595
|
+
if (this.audit?.onAudit) {
|
|
596
|
+
this.audit.onAudit({
|
|
597
|
+
type: "start",
|
|
598
|
+
timestamp: startTimestamp,
|
|
583
599
|
argv,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
600
|
+
context
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
let stderrBuffer = "";
|
|
604
|
+
const needsStderrStreaming = onProgress || onLfsProgress || this.audit?.onTrace;
|
|
605
|
+
let result;
|
|
606
|
+
try {
|
|
607
|
+
result = await this.exec.spawn(
|
|
608
|
+
{
|
|
609
|
+
argv,
|
|
610
|
+
env,
|
|
611
|
+
cwd: context.type === "worktree" ? context.workdir : void 0,
|
|
612
|
+
signal
|
|
613
|
+
},
|
|
614
|
+
needsStderrStreaming ? {
|
|
615
|
+
onStderr: (chunk) => {
|
|
616
|
+
stderrBuffer += chunk;
|
|
617
|
+
const lines = stderrBuffer.split(LINE_SEPARATOR_PATTERN);
|
|
618
|
+
stderrBuffer = lines.pop() ?? "";
|
|
619
|
+
for (const line of lines) {
|
|
620
|
+
this.processStderrLine(line, onProgress, onLfsProgress);
|
|
621
|
+
}
|
|
595
622
|
}
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
623
|
+
} : void 0
|
|
624
|
+
);
|
|
625
|
+
if (stderrBuffer.trim() && needsStderrStreaming) {
|
|
626
|
+
this.processStderrLine(stderrBuffer, onProgress, onLfsProgress);
|
|
627
|
+
}
|
|
628
|
+
} catch (error) {
|
|
629
|
+
if (this.audit?.onAudit) {
|
|
630
|
+
const endTimestamp = Date.now();
|
|
631
|
+
this.audit.onAudit({
|
|
632
|
+
type: "end",
|
|
633
|
+
timestamp: endTimestamp,
|
|
634
|
+
argv,
|
|
635
|
+
context,
|
|
636
|
+
stdout: "",
|
|
637
|
+
stderr: error instanceof Error ? error.message : String(error),
|
|
638
|
+
exitCode: -1,
|
|
639
|
+
aborted: signal?.aborted ?? false,
|
|
640
|
+
duration: endTimestamp - startTimestamp
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
throw error;
|
|
644
|
+
}
|
|
645
|
+
if (this.audit?.onAudit) {
|
|
646
|
+
const endTimestamp = Date.now();
|
|
647
|
+
this.audit.onAudit({
|
|
648
|
+
type: "end",
|
|
649
|
+
timestamp: endTimestamp,
|
|
650
|
+
argv,
|
|
651
|
+
context,
|
|
652
|
+
stdout: result.stdout,
|
|
653
|
+
stderr: result.stderr,
|
|
654
|
+
exitCode: result.exitCode,
|
|
655
|
+
aborted: result.aborted,
|
|
656
|
+
duration: endTimestamp - startTimestamp
|
|
657
|
+
});
|
|
601
658
|
}
|
|
602
659
|
return {
|
|
603
660
|
stdout: result.stdout,
|
|
@@ -606,6 +663,23 @@ var CliRunner = class _CliRunner {
|
|
|
606
663
|
aborted: result.aborted
|
|
607
664
|
};
|
|
608
665
|
}
|
|
666
|
+
/**
|
|
667
|
+
* Process a single line from stderr for progress and trace callbacks
|
|
668
|
+
*/
|
|
669
|
+
processStderrLine(line, onProgress, onLfsProgress) {
|
|
670
|
+
const trimmed = line.trim();
|
|
671
|
+
if (!trimmed) {
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
if (this.audit?.onTrace && GIT_TRACE_PATTERN.test(trimmed)) {
|
|
675
|
+
this.audit.onTrace({
|
|
676
|
+
timestamp: Date.now(),
|
|
677
|
+
line: trimmed
|
|
678
|
+
});
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
processProgressLine(line, onProgress, onLfsProgress);
|
|
682
|
+
}
|
|
609
683
|
/**
|
|
610
684
|
* Map Git result to GitError if needed
|
|
611
685
|
*/
|
|
@@ -1099,7 +1173,8 @@ var BareRepoImpl = class {
|
|
|
1099
1173
|
}
|
|
1100
1174
|
await this.runner.runOrThrow(this.context, args, {
|
|
1101
1175
|
signal: opts?.signal,
|
|
1102
|
-
onProgress: opts?.onProgress
|
|
1176
|
+
onProgress: opts?.onProgress,
|
|
1177
|
+
onLfsProgress: opts?.onLfsProgress
|
|
1103
1178
|
});
|
|
1104
1179
|
}
|
|
1105
1180
|
// ==========================================================================
|
|
@@ -2070,7 +2145,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2070
2145
|
}
|
|
2071
2146
|
await this.runner.runOrThrow(this.context, args, {
|
|
2072
2147
|
signal: opts?.signal,
|
|
2073
|
-
onProgress: opts?.onProgress
|
|
2148
|
+
onProgress: opts?.onProgress,
|
|
2149
|
+
onLfsProgress: opts?.onLfsProgress
|
|
2074
2150
|
});
|
|
2075
2151
|
}
|
|
2076
2152
|
/**
|
|
@@ -5414,7 +5490,8 @@ var GitImpl = class {
|
|
|
5414
5490
|
try {
|
|
5415
5491
|
await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5416
5492
|
signal: opts?.signal,
|
|
5417
|
-
onProgress: opts?.onProgress
|
|
5493
|
+
onProgress: opts?.onProgress,
|
|
5494
|
+
onLfsProgress: opts?.onLfsProgress
|
|
5418
5495
|
});
|
|
5419
5496
|
} catch (error) {
|
|
5420
5497
|
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
|