type-git 0.5.0 → 0.6.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 +4 -0
- package/dist/adapters/bun/index.cjs +81 -13348
- package/dist/adapters/bun/index.d.cts +6 -1
- package/dist/adapters/bun/index.d.ts +6 -1
- package/dist/adapters/bun/index.js +48 -13275
- package/dist/adapters/deno/index.cjs +75 -13344
- package/dist/adapters/deno/index.d.cts +6 -1
- package/dist/adapters/deno/index.d.ts +6 -1
- package/dist/adapters/deno/index.js +43 -13272
- package/dist/adapters/node/index.cjs +4 -13617
- package/dist/adapters/node/index.d.cts +43 -6
- package/dist/adapters/node/index.d.ts +43 -6
- package/dist/adapters/node/index.js +7 -13580
- package/dist/chunk-BRFWPLJ7.cjs +13025 -0
- package/dist/chunk-DDWWKTAE.cjs +392 -0
- package/dist/chunk-FHV2WOQG.js +392 -0
- package/dist/chunk-IYOGHATP.js +13025 -0
- package/dist/client.d-D9Lqi1a2.d.cts +140336 -0
- package/dist/index.cjs +36 -13717
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +32 -13649
- package/docs/adapters.md +168 -0
- package/package.json +47 -21
- package/dist/adapters/bun/index.cjs.map +0 -1
- package/dist/adapters/bun/index.js.map +0 -1
- package/dist/adapters/deno/index.cjs.map +0 -1
- package/dist/adapters/deno/index.js.map +0 -1
- package/dist/adapters/node/index.cjs.map +0 -1
- package/dist/adapters/node/index.js.map +0 -1
- package/dist/client-KHa1WMIH.d.cts +0 -12041
- package/dist/client-KHa1WMIH.d.ts +0 -12041
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/docs/adapters.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Execution adapter contract
|
|
2
|
+
|
|
3
|
+
type-git never spawns processes itself. Every Git (and companion program) invocation goes
|
|
4
|
+
through the `ExecAdapter` passed to `createGit({ adapters })`. This page describes what the
|
|
5
|
+
built-in runner asks of an adapter, so that a custom adapter (for example one that restricts
|
|
6
|
+
which processes may start) knows which calls to accept and how to answer them.
|
|
7
|
+
|
|
8
|
+
The built-in adapters are `NodeExecAdapter` (`type-git/node`), `BunExecAdapter`
|
|
9
|
+
(`type-git/bun`) and `DenoExecAdapter` (`type-git/deno`).
|
|
10
|
+
|
|
11
|
+
## Methods the runner calls
|
|
12
|
+
|
|
13
|
+
| Method | Called by the runner | Notes |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| `spawn(options, handlers?)` | Yes, for every text-output command and every internal probe | Required. |
|
|
16
|
+
| `spawnBytes(options, handlers?)` | Only for `command(..., { stdout: 'bytes' })` | Optional. See [Without `spawnBytes`](#without-spawnbytes). |
|
|
17
|
+
| `spawnStreaming(options)` | No | Optional; offered to callers of the adapter only. |
|
|
18
|
+
| `getCapabilities()` | No | Required by the interface; informational. |
|
|
19
|
+
|
|
20
|
+
## `SpawnOptions` as the runner sends them
|
|
21
|
+
|
|
22
|
+
- `argv`: `[gitBinary, ...]` (or a companion program path). The first element is the program;
|
|
23
|
+
arguments are never passed through a shell. Do not join them into a command line.
|
|
24
|
+
- `env`: the **complete** environment for the child. The runner has already resolved the
|
|
25
|
+
inherited variables (see `inheritEnv` on `createGit`/`open`), layered `env`, `home` and
|
|
26
|
+
`pathPrefix` on top, and applied any per-call overrides.
|
|
27
|
+
- `inheritEnv`: always `false` from the runner. The adapter must not merge the parent process
|
|
28
|
+
environment underneath `env`; doing so would defeat the environment allowlist.
|
|
29
|
+
- `stdin`: `undefined`, a UTF-8 `string`, or a `Uint8Array`. When present, write all of it and
|
|
30
|
+
then close standard input. When absent, the child's standard input should be closed or
|
|
31
|
+
ignored (Node and Bun use `'ignore'`, Deno uses `'null'`). Since 0.6.0 the type is
|
|
32
|
+
`string | Uint8Array`; earlier releases only sent strings.
|
|
33
|
+
- `cwd`: see [Working directory](#working-directory).
|
|
34
|
+
- `signal`: see [Cancellation](#cancellation).
|
|
35
|
+
- `killSignal`: currently never set by the runner, and ignored by the built-in adapters.
|
|
36
|
+
|
|
37
|
+
## Working directory
|
|
38
|
+
|
|
39
|
+
Git commands select the repository with an explicit flag. Companion programs (`scalar`,
|
|
40
|
+
`gitk`, `gitweb`) take no such flag, so for them the runner selects the repository through
|
|
41
|
+
`cwd` instead:
|
|
42
|
+
|
|
43
|
+
| Context | argv | `cwd` sent to the adapter |
|
|
44
|
+
| --- | --- | --- |
|
|
45
|
+
| Repository-agnostic (`git.raw`, `git.version`, `clone`, `init`, …) | `git …` | `undefined` |
|
|
46
|
+
| Worktree repository | `git -C <workdir> …` | `<workdir>` |
|
|
47
|
+
| Bare repository | `git --git-dir <gitDir> …` | `undefined` |
|
|
48
|
+
| Companion program, repository-agnostic | `<program> …` | `undefined` |
|
|
49
|
+
| Companion program, worktree repository | `<program> …` | `<workdir>` |
|
|
50
|
+
| Companion program, bare repository | `<program> …` | `<gitDir>` |
|
|
51
|
+
|
|
52
|
+
When a credential helper is configured, Git argv starts with
|
|
53
|
+
`git -c credential.helper=<helper>` before the context flag.
|
|
54
|
+
|
|
55
|
+
`undefined` means "do not set one"; the child then inherits the host process's current
|
|
56
|
+
directory. The runner passes repository paths unchanged, as the table shows: worktree Git
|
|
57
|
+
commands get the path in `-C` and as `cwd`, worktree companion programs only as `cwd`, bare Git
|
|
58
|
+
commands only in `--git-dir` (`cwd: undefined`), and bare companion programs only as `cwd`.
|
|
59
|
+
`clone` and `init` are repository-agnostic: the destination is a positional argument. For
|
|
60
|
+
worktree calls, use absolute worktree paths: then the selected repository does not depend on the
|
|
61
|
+
inherited directory. A relative worktree path is resolved twice (once by `cwd`, again by `-C`),
|
|
62
|
+
so it can fail even with the built-in adapters: `'.'` works, but `'repo'` resolves to
|
|
63
|
+
`repo/repo` (#329). Bare Git commands, `clone`, `init` and repository-agnostic calls get
|
|
64
|
+
`cwd: undefined` whatever path is used, so an adapter that requires a working directory must
|
|
65
|
+
handle `undefined` (for example by using the host's current directory) instead of rejecting
|
|
66
|
+
these calls. Repository-agnostic calls are different: `git.raw()`, `git.command()` and repository-agnostic companion programs run with
|
|
67
|
+
`cwd: undefined`, so a command that needs a repository (for example `git.raw(['status'])`)
|
|
68
|
+
resolves it from the host process's current directory, as the Git CLI would. Open a repository
|
|
69
|
+
and use `repo.raw()` to avoid that.
|
|
70
|
+
|
|
71
|
+
## Processes started by common operations
|
|
72
|
+
|
|
73
|
+
- `createGit()`: `git --version` (repository-agnostic) unless `skipVersionCheck` is set.
|
|
74
|
+
The result is cached per `Git` instance.
|
|
75
|
+
- `git.open(path)`, `git.openBare(path)`, `git.openRaw(path)`:
|
|
76
|
+
1. `git -C <path> rev-parse --is-bare-repository` with `cwd: <path>`.
|
|
77
|
+
2. Only if step 1 exits non-zero: `git --git-dir <path> rev-parse --is-bare-repository` with
|
|
78
|
+
no `cwd`. The error thrown when both fail carries step 2's exit code and stderr.
|
|
79
|
+
|
|
80
|
+
If `<path>` does not exist, step 1 fails to start (the built-in Node adapter reports
|
|
81
|
+
`spawn git ENOENT` because the working directory is missing) and `open` throws a
|
|
82
|
+
`GitError` with kind `SpawnFailed`; step 2 does not run.
|
|
83
|
+
- Typed `command()` calls may start **internal probes** before the real command when the
|
|
84
|
+
result depends on how the installed Git parses an argument (for example `git <command> -h`,
|
|
85
|
+
`git --exec-path`, or a probe inside a throwaway bare repository created with
|
|
86
|
+
`git init --bare --quiet <tempdir>` in a fresh temporary directory). Probes use the same
|
|
87
|
+
`env` overrides and `signal` as the call, but `GIT_TRACE*` variables are removed and audit
|
|
88
|
+
hooks are not notified. Most calls need no probe.
|
|
89
|
+
- Typed high-level methods (`status()`, `log()`, …) start the Git command they wrap, and
|
|
90
|
+
sometimes a short query such as `rev-parse`.
|
|
91
|
+
|
|
92
|
+
## Results and errors
|
|
93
|
+
|
|
94
|
+
Resolve with `SpawnResult`:
|
|
95
|
+
|
|
96
|
+
- `exitCode`: the process exit code, or `-1` when unknown (for example, killed by a signal).
|
|
97
|
+
- `signal`: the terminating signal name, if any.
|
|
98
|
+
- `aborted`: `true` when the process was stopped because `signal` fired.
|
|
99
|
+
- `stdout` / `stderr`: the complete output. `stderr` is always text.
|
|
100
|
+
|
|
101
|
+
A non-zero exit is **not** an adapter error: resolve normally and let the caller decide.
|
|
102
|
+
Reject only when the process could not be started or driven (the runner wraps the rejection
|
|
103
|
+
in a `GitError` with kind `SpawnFailed`, or `Aborted` if the call's signal had fired).
|
|
104
|
+
|
|
105
|
+
`handlers.onStderr` is supplied only when progress callbacks or trace hooks need incremental
|
|
106
|
+
stderr; call it with each chunk as it arrives. `handlers.onStdout` is not used by the runner.
|
|
107
|
+
|
|
108
|
+
### Standard input write failures
|
|
109
|
+
|
|
110
|
+
When Git exits before reading all of standard input, writing fails. The built-in adapters
|
|
111
|
+
ignore that early-close error (`EPIPE`, or `EOF` on Windows, in Node; `BrokenPipe` in Deno;
|
|
112
|
+
Bun hands the input to `Bun.spawn` and reports no write error) and report Git's own exit
|
|
113
|
+
result. In Node and Deno any other stdin error rejects the spawn. A caller that must treat a partially consumed input
|
|
114
|
+
as a failure needs to check the exit code and output of the command (or use a custom adapter).
|
|
115
|
+
|
|
116
|
+
## Cancellation
|
|
117
|
+
|
|
118
|
+
- If the call's `AbortSignal` is already aborted, the runner returns
|
|
119
|
+
`{ exitCode: -1, aborted: true }` without calling the adapter.
|
|
120
|
+
- Otherwise the adapter should stop the child when the signal fires and resolve with
|
|
121
|
+
`aborted: true`. The built-in adapters send `SIGTERM` and remove their abort listener when
|
|
122
|
+
the process closes.
|
|
123
|
+
|
|
124
|
+
## Without `spawnBytes`
|
|
125
|
+
|
|
126
|
+
`spawnBytes` is optional. Without it, any call that requests byte output
|
|
127
|
+
(`command(..., { stdout: 'bytes' })`) throws a `GitError` with kind `CapabilityMissing`
|
|
128
|
+
("The selected execution adapter does not support binary stdout") instead of starting the
|
|
129
|
+
command. Text-mode probes may still run before that error, and a call whose `AbortSignal` is
|
|
130
|
+
already aborted returns `aborted: true` first. Text-output calls are unaffected.
|
|
131
|
+
|
|
132
|
+
## `FsAdapter`
|
|
133
|
+
|
|
134
|
+
The runner and repository methods call these `FsAdapter` methods:
|
|
135
|
+
|
|
136
|
+
- `exists` / `deleteDirectory`: `clone` and `init` check whether the destination already
|
|
137
|
+
exists, and remove a destination they created if the call is aborted.
|
|
138
|
+
|
|
139
|
+
- `createTempFile` / `deleteFile`: `deleteFile` on a path returned by `createTempFile` should
|
|
140
|
+
release everything that call allocated (the built-in adapters also remove the private
|
|
141
|
+
directory holding the file).
|
|
142
|
+
- `createTempDirectory` (optional, since 0.6.0) / `deleteDirectory`: used for probes that
|
|
143
|
+
need an empty repository. When it is missing, the runner creates a temp file with
|
|
144
|
+
`createTempFile` and uses the sibling path `<file>-repo`, removing both afterward.
|
|
145
|
+
`deleteDirectory` is also called when `git init` failed before creating that directory, so
|
|
146
|
+
it must succeed when the path does not exist (the built-in adapters ignore a missing path).
|
|
147
|
+
- `readFile` / `writeFile` (optional): when missing, the probes that need them are skipped and
|
|
148
|
+
the command runs without that extra validation.
|
|
149
|
+
|
|
150
|
+
`tail` and `tailStreaming` are part of the interface but are not called by the runner.
|
|
151
|
+
|
|
152
|
+
## Node-specific options
|
|
153
|
+
|
|
154
|
+
`NodeExecAdapter` accepts a small, vetted set of `child_process.spawn` options:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { TypeGit, createNodeAdapters, NodeExecAdapter } from 'type-git/node';
|
|
158
|
+
|
|
159
|
+
const git = await TypeGit.create({ windowsHide: true });
|
|
160
|
+
// or
|
|
161
|
+
const adapters = createNodeAdapters({ windowsHide: true });
|
|
162
|
+
// or
|
|
163
|
+
const exec = new NodeExecAdapter({ windowsHide: true });
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`windowsHide` hides the console window Windows would otherwise open for each Git process. It
|
|
167
|
+
defaults to Node's default (`false`). Options such as `shell` are intentionally not exposed,
|
|
168
|
+
because they would let Git arguments be reinterpreted.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Type-safe Git wrapper library with LFS support, progress tracking, and abort control for Node.js/Deno/Bun",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -8,25 +8,46 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
14
19
|
},
|
|
15
20
|
"./node": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/adapters/node/index.d.ts",
|
|
23
|
+
"default": "./dist/adapters/node/index.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/adapters/node/index.d.cts",
|
|
27
|
+
"default": "./dist/adapters/node/index.cjs"
|
|
28
|
+
}
|
|
19
29
|
},
|
|
20
30
|
"./bun": {
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/adapters/bun/index.d.ts",
|
|
33
|
+
"default": "./dist/adapters/bun/index.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/adapters/bun/index.d.cts",
|
|
37
|
+
"default": "./dist/adapters/bun/index.cjs"
|
|
38
|
+
}
|
|
24
39
|
},
|
|
25
40
|
"./deno": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/adapters/deno/index.d.ts",
|
|
43
|
+
"default": "./dist/adapters/deno/index.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/adapters/deno/index.d.cts",
|
|
47
|
+
"default": "./dist/adapters/deno/index.cjs"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./package.json": "./package.json"
|
|
30
51
|
},
|
|
31
52
|
"engines": {
|
|
32
53
|
"node": ">=20.0.0"
|
|
@@ -58,9 +79,11 @@
|
|
|
58
79
|
},
|
|
59
80
|
"files": [
|
|
60
81
|
"dist",
|
|
82
|
+
"!dist/**/*.map",
|
|
61
83
|
"README.md",
|
|
62
84
|
"LICENSE",
|
|
63
|
-
"docs/migrations"
|
|
85
|
+
"docs/migrations",
|
|
86
|
+
"docs/adapters.md"
|
|
64
87
|
],
|
|
65
88
|
"repository": {
|
|
66
89
|
"type": "git",
|
|
@@ -76,7 +99,7 @@
|
|
|
76
99
|
]
|
|
77
100
|
},
|
|
78
101
|
"scripts": {
|
|
79
|
-
"build": "
|
|
102
|
+
"build": "node scripts/build.mjs",
|
|
80
103
|
"test": "vitest",
|
|
81
104
|
"test:ci": "vitest run",
|
|
82
105
|
"test:bun": "bun test test/bun/",
|
|
@@ -92,13 +115,16 @@
|
|
|
92
115
|
"docs:dev": "pnpm --filter type-git-docs dev",
|
|
93
116
|
"docs:build": "pnpm --filter type-git-docs build",
|
|
94
117
|
"docs:preview": "pnpm --filter type-git-docs preview",
|
|
118
|
+
"verify": "pnpm check && pnpm typecheck && pnpm test:ci && pnpm build",
|
|
95
119
|
"changeset": "changeset",
|
|
96
120
|
"version-packages": "changeset version",
|
|
97
121
|
"release": "changeset publish",
|
|
98
|
-
"test:types": "
|
|
99
|
-
"constraints:generate": "node scripts/constraints.mjs && node scripts/command-coverage.mjs",
|
|
100
|
-
"constraints:check": "node scripts/constraints.mjs --check && node scripts/command-coverage.mjs --check",
|
|
101
|
-
"commands:generate": "node scripts/commands.mjs",
|
|
102
|
-
"commands:check": "node scripts/commands.mjs --check"
|
|
122
|
+
"test:types": "node scripts/test-types.mjs",
|
|
123
|
+
"constraints:generate": "node scripts/string-callbacks.mjs && node scripts/compound-decimals.mjs && node scripts/boolean-callbacks.mjs && node scripts/numeric-callbacks.mjs && node scripts/constraints.mjs && node scripts/command-coverage.mjs",
|
|
124
|
+
"constraints:check": "node scripts/string-callbacks.mjs --check && node scripts/compound-decimals.mjs --check && node scripts/boolean-callbacks.mjs --check && node scripts/numeric-callbacks.mjs --check && node scripts/constraints.mjs --check && node scripts/command-coverage.mjs --check",
|
|
125
|
+
"commands:generate": "node scripts/string-callbacks.mjs && node scripts/compound-decimals.mjs && node scripts/boolean-callbacks.mjs && node scripts/numeric-callbacks.mjs && node scripts/integer-type-tables.mjs && node scripts/url-byte-types.mjs && node scripts/commands.mjs",
|
|
126
|
+
"commands:check": "node scripts/string-callbacks.mjs --check && node scripts/compound-decimals.mjs --check && node scripts/boolean-callbacks.mjs --check && node scripts/numeric-callbacks.mjs --check && node scripts/integer-type-tables.mjs --check && node scripts/url-byte-types.mjs --check && node scripts/commands.mjs --check",
|
|
127
|
+
"commands:upstream-check": "node scripts/verify-upstream.mjs",
|
|
128
|
+
"commands:progress": "node scripts/command-progress.mjs"
|
|
103
129
|
}
|
|
104
130
|
}
|