type-git 0.1.1 → 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.cjs +21 -2
- package/dist/adapters/bun/index.cjs.map +1 -1
- package/dist/adapters/bun/index.d.cts +1 -1
- package/dist/adapters/bun/index.d.ts +1 -1
- package/dist/adapters/bun/index.js +21 -2
- package/dist/adapters/bun/index.js.map +1 -1
- package/dist/adapters/deno/index.cjs +29 -2
- package/dist/adapters/deno/index.cjs.map +1 -1
- package/dist/adapters/deno/index.d.cts +1 -1
- package/dist/adapters/deno/index.d.ts +1 -1
- package/dist/adapters/deno/index.js +29 -2
- package/dist/adapters/deno/index.js.map +1 -1
- package/dist/adapters/node/index.cjs +136 -30
- 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 +136 -30
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/{adapters-DehG3CsV.d.cts → adapters-BEKkCViX.d.cts} +160 -3
- package/dist/{adapters-DehG3CsV.d.ts → adapters-BEKkCViX.d.ts} +160 -3
- package/dist/index.cjs +136 -30
- 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 +136 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -459,6 +459,7 @@ var import_node_process = __toESM(require("process"), 1);
|
|
|
459
459
|
var FATAL_ERROR_PATTERN = /fatal:\s*(.+)/i;
|
|
460
460
|
var ERROR_PATTERN = /error:\s*(.+)/i;
|
|
461
461
|
var LINE_SEPARATOR_PATTERN = /\r|\n/;
|
|
462
|
+
var GIT_TRACE_PATTERN = /^\d{2}:\d{2}:\d{2}\.\d+\s+(?:trace:|[A-Za-z0-9_.-]+\.c:)/;
|
|
462
463
|
function toLfsProgress(info) {
|
|
463
464
|
if (!info) {
|
|
464
465
|
return null;
|
|
@@ -511,6 +512,7 @@ var CliRunner = class _CliRunner {
|
|
|
511
512
|
pathPrefix;
|
|
512
513
|
home;
|
|
513
514
|
credential;
|
|
515
|
+
audit;
|
|
514
516
|
constructor(adapters, options) {
|
|
515
517
|
this.exec = adapters.exec;
|
|
516
518
|
this.gitBinary = options?.gitBinary ?? "git";
|
|
@@ -518,6 +520,7 @@ var CliRunner = class _CliRunner {
|
|
|
518
520
|
this.pathPrefix = options?.pathPrefix ?? [];
|
|
519
521
|
this.home = options?.home;
|
|
520
522
|
this.credential = options?.credential;
|
|
523
|
+
this.audit = options?.audit;
|
|
521
524
|
}
|
|
522
525
|
/**
|
|
523
526
|
* Create a new CliRunner with additional options merged
|
|
@@ -529,6 +532,7 @@ var CliRunner = class _CliRunner {
|
|
|
529
532
|
const mergedPathPrefix = [...this.pathPrefix, ...options.pathPrefix ?? []];
|
|
530
533
|
const home = options.home ?? this.home;
|
|
531
534
|
const credential = options.credential ?? this.credential;
|
|
535
|
+
const audit = options.audit ?? this.audit;
|
|
532
536
|
return new _CliRunner(
|
|
533
537
|
{
|
|
534
538
|
exec: this.exec,
|
|
@@ -545,7 +549,8 @@ var CliRunner = class _CliRunner {
|
|
|
545
549
|
env: mergedEnv,
|
|
546
550
|
pathPrefix: mergedPathPrefix,
|
|
547
551
|
home,
|
|
548
|
-
credential
|
|
552
|
+
credential,
|
|
553
|
+
audit
|
|
549
554
|
}
|
|
550
555
|
);
|
|
551
556
|
}
|
|
@@ -593,6 +598,15 @@ var CliRunner = class _CliRunner {
|
|
|
593
598
|
const currentPath = import_node_process.default.env.PATH ?? "";
|
|
594
599
|
env.PATH = [...allPathPrefixes, currentPath].join(separator);
|
|
595
600
|
}
|
|
601
|
+
if (this.audit?.onTrace) {
|
|
602
|
+
if (env.GIT_TRACE === void 0) {
|
|
603
|
+
env.GIT_TRACE = "1";
|
|
604
|
+
} else if (!env.GIT_TRACE || env.GIT_TRACE === "0") {
|
|
605
|
+
console.warn(
|
|
606
|
+
"type-git: onTrace callback provided but GIT_TRACE is disabled. Trace events will not be emitted."
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
596
610
|
return env;
|
|
597
611
|
}
|
|
598
612
|
/**
|
|
@@ -616,27 +630,70 @@ var CliRunner = class _CliRunner {
|
|
|
616
630
|
if (onLfsProgress) {
|
|
617
631
|
env.GIT_LFS_FORCE_PROGRESS = "1";
|
|
618
632
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
{
|
|
633
|
+
const startTimestamp = Date.now();
|
|
634
|
+
if (this.audit?.onAudit) {
|
|
635
|
+
this.audit.onAudit({
|
|
636
|
+
type: "start",
|
|
637
|
+
timestamp: startTimestamp,
|
|
622
638
|
argv,
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
639
|
+
context
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
let stderrBuffer = "";
|
|
643
|
+
const needsStderrStreaming = onProgress || onLfsProgress || this.audit?.onTrace;
|
|
644
|
+
let result;
|
|
645
|
+
try {
|
|
646
|
+
result = await this.exec.spawn(
|
|
647
|
+
{
|
|
648
|
+
argv,
|
|
649
|
+
env,
|
|
650
|
+
cwd: context.type === "worktree" ? context.workdir : void 0,
|
|
651
|
+
signal
|
|
652
|
+
},
|
|
653
|
+
needsStderrStreaming ? {
|
|
654
|
+
onStderr: (chunk) => {
|
|
655
|
+
stderrBuffer += chunk;
|
|
656
|
+
const lines = stderrBuffer.split(LINE_SEPARATOR_PATTERN);
|
|
657
|
+
stderrBuffer = lines.pop() ?? "";
|
|
658
|
+
for (const line of lines) {
|
|
659
|
+
this.processStderrLine(line, onProgress, onLfsProgress);
|
|
660
|
+
}
|
|
634
661
|
}
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
662
|
+
} : void 0
|
|
663
|
+
);
|
|
664
|
+
if (stderrBuffer.trim() && needsStderrStreaming) {
|
|
665
|
+
this.processStderrLine(stderrBuffer, onProgress, onLfsProgress);
|
|
666
|
+
}
|
|
667
|
+
} catch (error) {
|
|
668
|
+
if (this.audit?.onAudit) {
|
|
669
|
+
const endTimestamp = Date.now();
|
|
670
|
+
this.audit.onAudit({
|
|
671
|
+
type: "end",
|
|
672
|
+
timestamp: endTimestamp,
|
|
673
|
+
argv,
|
|
674
|
+
context,
|
|
675
|
+
stdout: "",
|
|
676
|
+
stderr: error instanceof Error ? error.message : String(error),
|
|
677
|
+
exitCode: -1,
|
|
678
|
+
aborted: signal?.aborted ?? false,
|
|
679
|
+
duration: endTimestamp - startTimestamp
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
throw error;
|
|
683
|
+
}
|
|
684
|
+
if (this.audit?.onAudit) {
|
|
685
|
+
const endTimestamp = Date.now();
|
|
686
|
+
this.audit.onAudit({
|
|
687
|
+
type: "end",
|
|
688
|
+
timestamp: endTimestamp,
|
|
689
|
+
argv,
|
|
690
|
+
context,
|
|
691
|
+
stdout: result.stdout,
|
|
692
|
+
stderr: result.stderr,
|
|
693
|
+
exitCode: result.exitCode,
|
|
694
|
+
aborted: result.aborted,
|
|
695
|
+
duration: endTimestamp - startTimestamp
|
|
696
|
+
});
|
|
640
697
|
}
|
|
641
698
|
return {
|
|
642
699
|
stdout: result.stdout,
|
|
@@ -645,6 +702,23 @@ var CliRunner = class _CliRunner {
|
|
|
645
702
|
aborted: result.aborted
|
|
646
703
|
};
|
|
647
704
|
}
|
|
705
|
+
/**
|
|
706
|
+
* Process a single line from stderr for progress and trace callbacks
|
|
707
|
+
*/
|
|
708
|
+
processStderrLine(line, onProgress, onLfsProgress) {
|
|
709
|
+
const trimmed = line.trim();
|
|
710
|
+
if (!trimmed) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
if (this.audit?.onTrace && GIT_TRACE_PATTERN.test(trimmed)) {
|
|
714
|
+
this.audit.onTrace({
|
|
715
|
+
timestamp: Date.now(),
|
|
716
|
+
line: trimmed
|
|
717
|
+
});
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
processProgressLine(line, onProgress, onLfsProgress);
|
|
721
|
+
}
|
|
648
722
|
/**
|
|
649
723
|
* Map Git result to GitError if needed
|
|
650
724
|
*/
|
|
@@ -1138,7 +1212,8 @@ var BareRepoImpl = class {
|
|
|
1138
1212
|
}
|
|
1139
1213
|
await this.runner.runOrThrow(this.context, args, {
|
|
1140
1214
|
signal: opts?.signal,
|
|
1141
|
-
onProgress: opts?.onProgress
|
|
1215
|
+
onProgress: opts?.onProgress,
|
|
1216
|
+
onLfsProgress: opts?.onLfsProgress
|
|
1142
1217
|
});
|
|
1143
1218
|
}
|
|
1144
1219
|
// ==========================================================================
|
|
@@ -2109,7 +2184,8 @@ var WorktreeRepoImpl = class _WorktreeRepoImpl {
|
|
|
2109
2184
|
}
|
|
2110
2185
|
await this.runner.runOrThrow(this.context, args, {
|
|
2111
2186
|
signal: opts?.signal,
|
|
2112
|
-
onProgress: opts?.onProgress
|
|
2187
|
+
onProgress: opts?.onProgress,
|
|
2188
|
+
onLfsProgress: opts?.onLfsProgress
|
|
2113
2189
|
});
|
|
2114
2190
|
}
|
|
2115
2191
|
/**
|
|
@@ -5453,7 +5529,8 @@ var GitImpl = class {
|
|
|
5453
5529
|
try {
|
|
5454
5530
|
await this.runner.runOrThrow({ type: "global" }, args, {
|
|
5455
5531
|
signal: opts?.signal,
|
|
5456
|
-
onProgress: opts?.onProgress
|
|
5532
|
+
onProgress: opts?.onProgress,
|
|
5533
|
+
onLfsProgress: opts?.onLfsProgress
|
|
5457
5534
|
});
|
|
5458
5535
|
} catch (error) {
|
|
5459
5536
|
if (error instanceof GitError && error.kind === "Aborted" && opts?.cleanupOnAbort !== false) {
|
|
@@ -5933,6 +6010,13 @@ var NodeExecAdapter = class {
|
|
|
5933
6010
|
wait: () => waitPromise,
|
|
5934
6011
|
kill: (sig) => {
|
|
5935
6012
|
child.kill(sig ?? "SIGTERM");
|
|
6013
|
+
},
|
|
6014
|
+
[Symbol.asyncDispose]: async () => {
|
|
6015
|
+
if (child.exitCode === null) {
|
|
6016
|
+
child.kill("SIGTERM");
|
|
6017
|
+
}
|
|
6018
|
+
await waitPromise.catch(() => {
|
|
6019
|
+
});
|
|
5936
6020
|
}
|
|
5937
6021
|
};
|
|
5938
6022
|
}
|
|
@@ -5980,7 +6064,8 @@ function createTailPolling(options) {
|
|
|
5980
6064
|
state.resolveNext = null;
|
|
5981
6065
|
}
|
|
5982
6066
|
};
|
|
5983
|
-
startPollingLoop(adapter, state, signal, pollInterval, stop)
|
|
6067
|
+
const pollingPromise = startPollingLoop(adapter, state, signal, pollInterval, stop);
|
|
6068
|
+
pollingPromise.catch(() => {
|
|
5984
6069
|
});
|
|
5985
6070
|
const lines = {
|
|
5986
6071
|
[Symbol.asyncIterator]() {
|
|
@@ -6002,7 +6087,15 @@ function createTailPolling(options) {
|
|
|
6002
6087
|
};
|
|
6003
6088
|
}
|
|
6004
6089
|
};
|
|
6005
|
-
return {
|
|
6090
|
+
return {
|
|
6091
|
+
lines,
|
|
6092
|
+
stop,
|
|
6093
|
+
[Symbol.asyncDispose]: async () => {
|
|
6094
|
+
stop();
|
|
6095
|
+
await pollingPromise.catch(() => {
|
|
6096
|
+
});
|
|
6097
|
+
}
|
|
6098
|
+
};
|
|
6006
6099
|
}
|
|
6007
6100
|
async function startPollingLoop(adapter, state, signal, pollInterval, stop) {
|
|
6008
6101
|
let position = 0;
|
|
@@ -6026,6 +6119,9 @@ async function startPollingLoop(adapter, state, signal, pollInterval, stop) {
|
|
|
6026
6119
|
}
|
|
6027
6120
|
}
|
|
6028
6121
|
}
|
|
6122
|
+
if (state.stopped || signal?.aborted) {
|
|
6123
|
+
break;
|
|
6124
|
+
}
|
|
6029
6125
|
await adapter.sleep(pollInterval);
|
|
6030
6126
|
}
|
|
6031
6127
|
stop();
|
|
@@ -6114,16 +6210,26 @@ var NodeFsAdapter = class {
|
|
|
6114
6210
|
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
6115
6211
|
};
|
|
6116
6212
|
const polling = createTailPolling({ adapter, signal, pollInterval });
|
|
6117
|
-
const
|
|
6118
|
-
const enhancedStop = () => {
|
|
6119
|
-
originalStop();
|
|
6213
|
+
const closeFileHandle = async () => {
|
|
6120
6214
|
if (state.file) {
|
|
6121
|
-
state.file.close().catch(() => {
|
|
6215
|
+
await state.file.close().catch(() => {
|
|
6122
6216
|
});
|
|
6123
6217
|
state.file = null;
|
|
6124
6218
|
}
|
|
6125
6219
|
};
|
|
6126
|
-
|
|
6220
|
+
const originalStop = polling.stop;
|
|
6221
|
+
const enhancedStop = () => {
|
|
6222
|
+
originalStop();
|
|
6223
|
+
void closeFileHandle();
|
|
6224
|
+
};
|
|
6225
|
+
return {
|
|
6226
|
+
lines: polling.lines,
|
|
6227
|
+
stop: enhancedStop,
|
|
6228
|
+
[Symbol.asyncDispose]: async () => {
|
|
6229
|
+
await polling[Symbol.asyncDispose]();
|
|
6230
|
+
await closeFileHandle();
|
|
6231
|
+
}
|
|
6232
|
+
};
|
|
6127
6233
|
}
|
|
6128
6234
|
};
|
|
6129
6235
|
|