@osdlc/typed-git 0.6.0 → 0.7.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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/async.js +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/failure.d.ts +9 -1
- package/dist/failure.js +32 -3
- package/dist/outcome.d.ts +1 -1
- package/dist/sync.js +1 -0
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @osdlc/typed-git
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b5aac07: When a git call fails and throws a `FailureError`, the error's `message` now starts with the git command, for example `git push: The remote 'origin' does not exist or is not a git repository.`, followed by the hint. Before, the message had no command, so code that ran several git calls in one `try` could not tell which one failed. `failure.message` is unchanged.
|
|
8
|
+
|
|
9
|
+
The new `describeGitFailure(failure)` builds the same `git <verb>: <message> <hint>` line for a failure returned by `git.try.*`.
|
|
10
|
+
|
|
11
|
+
If your code matches on the text of a thrown git error's `message`, it will now see the `git <verb>: ` prefix. Match on `error.failure.kind` instead.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 41ef520: Fix two type errors under TypeScript 5.9. The emitted `outcome.d.ts` failed with TS2536, because `Soft<C>` used a key on `Triable<C>` that TS 5.x could not prove valid. The source failed with TS2322, because `Git.soft` and `AsyncGit.soft` inferred `this` instead of the class type. A new `typecheck:ts59` script checks the package under 5.9.
|
|
16
|
+
|
|
3
17
|
## 0.6.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -140,7 +140,7 @@ use(r.value);
|
|
|
140
140
|
The error is a `GitFailure`: a `Failure` from `@osdlc/result` with a `kind` to
|
|
141
141
|
branch on, a one-line `message` and a `hint` for a person (`describe(error)`
|
|
142
142
|
joins them), git's own output in `detail`, the `argv` and `exitCode`, and the
|
|
143
|
-
`CommandFailed` it was read from in `cause`. The plain door throws the same failure, wrapped in a `FailureError` (`error.failure`), so a CLI that reports a thrown failure, such as `runMain` from `@osdlc/cli-tool`, shows "The remote refused the credentials" and exits 23 for a signed-out `git push`, as it does for a read.
|
|
143
|
+
`CommandFailed` it was read from in `cause`. The plain door throws the same failure, wrapped in a `FailureError` (`error.failure`), so a CLI that reports a thrown failure, such as `runMain` from `@osdlc/cli-tool`, shows "The remote refused the credentials" and exits 23 for a signed-out `git push`, as it does for a read. The thrown `message` names the command (`git push: The remote refused the credentials. …`); `failure.message` is the bare sentence, and `describeGitFailure(failure)` renders the same `git <verb>: <message> <hint>` line for a failure from `git.try.*`.
|
|
144
144
|
|
|
145
145
|
| `kind` | When | `message` / `hint` |
|
|
146
146
|
| --- | --- | --- |
|
package/dist/async.js
CHANGED
|
@@ -78,6 +78,7 @@ export class AsyncGit {
|
|
|
78
78
|
* runtime, though the type leaves them out.
|
|
79
79
|
*/
|
|
80
80
|
get soft() {
|
|
81
|
+
// Explicit type argument: otherwise TS 5.x infers the polymorphic `this`.
|
|
81
82
|
return (this.softened ??= softAsync(this, SOFT_TABLE));
|
|
82
83
|
}
|
|
83
84
|
// ── escape hatch ──────────────────────────────────────────────────────────
|
package/dist/client.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export { Git, type GitSyncCallOptions } from './sync.ts';
|
|
|
18
18
|
export { AsyncGit } from './async.ts';
|
|
19
19
|
export { parseRemoteUrl, type RemoteCoordinate } from './remote-url.ts';
|
|
20
20
|
export { cliBackend, partialBackend, UnsupportedRequest, type GitBackend, type GitCallOptions, type GitRequest, type GitRequestKind, type GitResults, } from './backend.ts';
|
|
21
|
-
export { classifyGitFailure, type GitFailure, type GitFailureKind } from './failure.ts';
|
|
21
|
+
export { classifyGitFailure, describeGitFailure, type GitFailure, type GitFailureKind, } from './failure.ts';
|
|
22
22
|
export { type Soft, type TriedAsync, type TriedSync } from './outcome.ts';
|
|
23
23
|
export { forceWithLeaseArg, parseRefRows, REF_FORMAT, type AddOptions, type AheadBehind, type CheckoutOptions, type CleanOptions, type CloneOptions, type CommitFlags, type CommitOptions, type ConfigGetOptions, type ConfigScope, type ConfigSetOptions, type ConflictSide, type DiffCheckOptions, type DiffCheckResult, type DiffEntry, type DiffNameOnlyOptions, type DiffNameStatusOptions, type DiffStatOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type ForceLease, type GrepOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type NumstatEntry, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type StatusEntry, type StatusPorcelainOptions, type TaggedFile, type TreeEntry, type UnmergedEntry, type Worktree, type WorktreeMoveOptions, } from './verbs.ts';
|
|
24
24
|
export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, type AsyncCommandRunner, type AsyncCommandRunOptions, type CommandResult, type CommandRunner, type CommandRunOptions, } from '@osdlc/command-seam';
|
package/dist/client.js
CHANGED
|
@@ -18,7 +18,7 @@ export { Git } from "./sync.js";
|
|
|
18
18
|
export { AsyncGit } from "./async.js";
|
|
19
19
|
export { parseRemoteUrl } from "./remote-url.js";
|
|
20
20
|
export { cliBackend, partialBackend, UnsupportedRequest, } from "./backend.js";
|
|
21
|
-
export { classifyGitFailure } from "./failure.js";
|
|
21
|
+
export { classifyGitFailure, describeGitFailure, } from "./failure.js";
|
|
22
22
|
export {} from "./outcome.js";
|
|
23
23
|
export { forceWithLeaseArg, parseRefRows, REF_FORMAT, } from "./verbs.js";
|
|
24
24
|
// The subprocess seam is re-exported so a caller wiring a runner or catching
|
package/dist/failure.d.ts
CHANGED
|
@@ -47,10 +47,18 @@ export interface GitFailure extends Failure<GitFailureKind> {
|
|
|
47
47
|
}
|
|
48
48
|
/** The git failure for a failed `git` run. */
|
|
49
49
|
export declare function classifyGitFailure(failed: CommandFailed): GitFailure;
|
|
50
|
+
/**
|
|
51
|
+
* One line for a person that names the git command: `git <verb>: <message>`,
|
|
52
|
+
* then the hint when there is one. The classified `message` alone does not say
|
|
53
|
+
* which command failed, so use this when the failure reaches a log or a status
|
|
54
|
+
* file without its surrounding code.
|
|
55
|
+
*/
|
|
56
|
+
export declare function describeGitFailure(failure: GitFailure): string;
|
|
50
57
|
/**
|
|
51
58
|
* What the plain door throws for a failed git call: a `FailureError` carrying
|
|
52
59
|
* the {@link GitFailure} that {@link classifyGitFailure} reads from it, with the
|
|
53
|
-
* `CommandFailed` as its `cause`.
|
|
60
|
+
* `CommandFailed` as its `cause`. Its `message` is {@link describeGitFailure},
|
|
61
|
+
* so it names the command that failed. Anything else is returned as it is. The
|
|
54
62
|
* classified kind (a signed-out remote, an unreachable one) is what lets a CLI
|
|
55
63
|
* that reports a thrown failure number it, which a bare `CommandFailed` with
|
|
56
64
|
* only command-seam's kinds cannot.
|
package/dist/failure.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* git's first stderr line as its message, never a wrong git kind.
|
|
10
10
|
*/
|
|
11
11
|
import { classifyFailure, isCommandFailed, } from '@osdlc/command-seam';
|
|
12
|
-
import { FailureError, isFailure } from '@osdlc/result';
|
|
12
|
+
import { describe, FailureError, isFailure } from '@osdlc/result';
|
|
13
13
|
const INSTALL_HINT = 'Install git from https://git-scm.com.';
|
|
14
14
|
/** The git failure for a failed `git` run. */
|
|
15
15
|
export function classifyGitFailure(failed) {
|
|
@@ -98,16 +98,45 @@ export function classifyGitFailure(failed) {
|
|
|
98
98
|
}
|
|
99
99
|
return base;
|
|
100
100
|
}
|
|
101
|
+
/** The git verb a failure ran, past any leading `-c <k=v>` / `-C <dir>` options (other global options are expected in their `--opt=value` form); `undefined` when argv has none. */
|
|
102
|
+
function gitVerb(argv) {
|
|
103
|
+
for (let i = 0; i < argv.length; i++) {
|
|
104
|
+
const arg = argv[i];
|
|
105
|
+
if (arg === '-c' || arg === '-C')
|
|
106
|
+
i++;
|
|
107
|
+
else if (!arg.startsWith('-'))
|
|
108
|
+
return arg;
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* One line for a person that names the git command: `git <verb>: <message>`,
|
|
114
|
+
* then the hint when there is one. The classified `message` alone does not say
|
|
115
|
+
* which command failed, so use this when the failure reaches a log or a status
|
|
116
|
+
* file without its surrounding code.
|
|
117
|
+
*/
|
|
118
|
+
export function describeGitFailure(failure) {
|
|
119
|
+
const verb = gitVerb(failure.argv);
|
|
120
|
+
const line = describe(failure);
|
|
121
|
+
return verb === undefined ? `git: ${line}` : `git ${verb}: ${line}`;
|
|
122
|
+
}
|
|
101
123
|
/**
|
|
102
124
|
* What the plain door throws for a failed git call: a `FailureError` carrying
|
|
103
125
|
* the {@link GitFailure} that {@link classifyGitFailure} reads from it, with the
|
|
104
|
-
* `CommandFailed` as its `cause`.
|
|
126
|
+
* `CommandFailed` as its `cause`. Its `message` is {@link describeGitFailure},
|
|
127
|
+
* so it names the command that failed. Anything else is returned as it is. The
|
|
105
128
|
* classified kind (a signed-out remote, an unreachable one) is what lets a CLI
|
|
106
129
|
* that reports a thrown failure number it, which a bare `CommandFailed` with
|
|
107
130
|
* only command-seam's kinds cannot.
|
|
108
131
|
*/
|
|
109
132
|
export function gitFailureError(error) {
|
|
110
|
-
|
|
133
|
+
if (!isCommandFailed(error))
|
|
134
|
+
return error;
|
|
135
|
+
const failure = classifyGitFailure(error);
|
|
136
|
+
// FailureError's message is the bare sentence; this door adds the command.
|
|
137
|
+
const thrown = new FailureError(failure);
|
|
138
|
+
thrown.message = describeGitFailure(failure);
|
|
139
|
+
return thrown;
|
|
111
140
|
}
|
|
112
141
|
/**
|
|
113
142
|
* The failure a thrown value carries, recognised by shape so two installed
|
package/dist/outcome.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export type SoftKinds<C> = {
|
|
|
65
65
|
* awaitable method already returns a `Promise`.
|
|
66
66
|
*/
|
|
67
67
|
export type Soft<C> = {
|
|
68
|
-
[K in keyof SoftKinds<C>]: Triable<C>[K] extends (...a: infer A) => infer R ? (...a: A) => R : never;
|
|
68
|
+
[K in keyof SoftKinds<C>]: Triable<C>[K & keyof Triable<C>] extends (...a: infer A) => infer R ? (...a: A) => R : never;
|
|
69
69
|
};
|
|
70
70
|
/**
|
|
71
71
|
* The soft door's table type: which absence value each softable verb falls back
|
package/dist/sync.js
CHANGED
|
@@ -96,6 +96,7 @@ export class Git {
|
|
|
96
96
|
* runtime, though the type leaves them out.
|
|
97
97
|
*/
|
|
98
98
|
get soft() {
|
|
99
|
+
// Explicit type argument: otherwise TS 5.x infers the polymorphic `this`.
|
|
99
100
|
return (this.softened ??= softSync(this, SOFT_TABLE));
|
|
100
101
|
}
|
|
101
102
|
// ── escape hatch ──────────────────────────────────────────────────────────
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdlc/typed-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A typed git client for TypeScript, sync and awaitable. Each verb declares what absence means for it; every other failure throws. git.try.* inspects, raw() bypasses — over an injectable backend that drives the git CLI or any other implementation.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "sksizer",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"hosted-git-info": "^10.1.1",
|
|
55
|
-
"@osdlc/
|
|
56
|
-
"@osdlc/
|
|
55
|
+
"@osdlc/command-seam": "^0.9.1",
|
|
56
|
+
"@osdlc/result": "^0.1.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node": "^26.1.0",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"oxlint": "^1.65.0",
|
|
62
62
|
"prettier": "3.9.6",
|
|
63
63
|
"typescript": "~6.0.3",
|
|
64
|
+
"typescript59": "npm:typescript@5.9.3",
|
|
64
65
|
"vitest": "^5.0.5",
|
|
65
66
|
"@osdlc/prettier-config": "^0.3.1",
|
|
66
67
|
"@osdlc/tsconfig": "^0.4.1"
|
|
@@ -74,6 +75,8 @@
|
|
|
74
75
|
"format:check": "prettier --check .",
|
|
75
76
|
"lint": "oxlint .",
|
|
76
77
|
"typecheck": "tsc --noEmit && tsc -p tsconfig.build.json --noEmit",
|
|
78
|
+
"typecheck:ts59": "node node_modules/typescript59/bin/tsc -p tsconfig.build.json --noEmit",
|
|
79
|
+
"check:extra": "pnpm run typecheck:ts59",
|
|
77
80
|
"coverage": "vitest run --coverage"
|
|
78
81
|
}
|
|
79
82
|
}
|