type-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/docs/adapters.md CHANGED
@@ -13,7 +13,7 @@ The built-in adapters are `NodeExecAdapter` (`type-git/node`), `BunExecAdapter`
13
13
  | Method | Called by the runner | Notes |
14
14
  | --- | --- | --- |
15
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). |
16
+ | `spawnBytes(options, handlers?)` | Only for `strict(...).command(..., { stdout: 'bytes' })` | Optional. See [Without `spawnBytes`](#without-spawnbytes). |
17
17
  | `spawnStreaming(options)` | No | Optional; offered to callers of the adapter only. |
18
18
  | `getCapabilities()` | No | Required by the interface; informational. |
19
19
 
@@ -63,10 +63,10 @@ so it can fail even with the built-in adapters: `'.'` works, but `'repo'` resolv
63
63
  `repo/repo` (#329). Bare Git commands, `clone`, `init` and repository-agnostic calls get
64
64
  `cwd: undefined` whatever path is used, so an adapter that requires a working directory must
65
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.
66
+ these calls. Repository-agnostic calls are different: `git.raw()`, `strict(git).command()`
67
+ and repository-agnostic companion programs run with `cwd: undefined`, so a command that needs a
68
+ repository (for example `git.raw(['status'])`) resolves it from the host process's current
69
+ directory, as the Git CLI would. Open a repository and use `repo.raw()` to avoid that.
70
70
 
71
71
  ## Processes started by common operations
72
72
 
@@ -80,7 +80,7 @@ and use `repo.raw()` to avoid that.
80
80
  If `<path>` does not exist, step 1 fails to start (the built-in Node adapter reports
81
81
  `spawn git ENOENT` because the working directory is missing) and `open` throws a
82
82
  `GitError` with kind `SpawnFailed`; step 2 does not run.
83
- - Typed `command()` calls may start **internal probes** before the real command when the
83
+ - Typed `strict(...).command()` calls may start **internal probes** before the real command when the
84
84
  result depends on how the installed Git parses an argument (for example `git <command> -h`,
85
85
  `git --exec-path`, or a probe inside a throwaway bare repository created with
86
86
  `git init --bare --quiet <tempdir>` in a fresh temporary directory). Probes use the same
@@ -124,7 +124,7 @@ as a failure needs to check the exit code and output of the command (or use a cu
124
124
  ## Without `spawnBytes`
125
125
 
126
126
  `spawnBytes` is optional. Without it, any call that requests byte output
127
- (`command(..., { stdout: 'bytes' })`) throws a `GitError` with kind `CapabilityMissing`
127
+ (`strict(...).command(..., { stdout: 'bytes' })`) throws a `GitError` with kind `CapabilityMissing`
128
128
  ("The selected execution adapter does not support binary stdout") instead of starting the
129
129
  command. Text-mode probes may still run before that error, and a call whose `AbortSignal` is
130
130
  already aborted returns `aborted: true` first. Text-output calls are unaffected.
@@ -0,0 +1,152 @@
1
+ # Migrating to 0.7.0
2
+
3
+ 0.7.0 splits type-git into a lightweight main entry point and an opt-in strict entry point.
4
+ The grammar-checked `command()` moves from `Git`, `WorktreeRepo`, `BareRepo` and `TypeGit` to
5
+ `type-git/strict`. Three other changes can break existing code:
6
+ [`clone()` accepts only data-only config keys](#clone-config-keys),
7
+ [`GIT_SSH` and `GIT_SSH_COMMAND` are no longer inherited](#git_ssh-and-git_ssh_command), and
8
+ [`repo.show()` refuses conflicting output options](#reposhow-output-options). The other public
9
+ names and shapes are unchanged.
10
+
11
+ ## Why
12
+
13
+ In 0.6.0 `command()` grew a catalogue of Git's option grammar for 428 command scopes. The
14
+ catalogue made `command()` far more accurate, but every user paid for it, including those that
15
+ never call `command()`:
16
+
17
+ | Measured on an application that only calls `repo.status()` | 0.6.0 | 0.7.0 |
18
+ | --- | --- | --- |
19
+ | Bundle (esbuild, minified) | about 1.6 MB | about 180 KB |
20
+ | Bundle, gzip | about 210 KB | about 45 KB |
21
+ | Type declarations loaded by the main entry | about 5 MB | about 350 KB |
22
+
23
+ The catalogue, the native parser probes that support it, and the literal grammar types now load
24
+ only when `type-git/strict` is imported.
25
+
26
+ ## What stays in the main entry point
27
+
28
+ - `raw()` on clients and repositories.
29
+ - The high-level API (`status()`, `log()`, `commit()`, `branch.create()`, `lfs.*`, and so on),
30
+ with the same option types and runtime option checks as 0.6.0, except for the `clone()` and
31
+ `show()` changes below.
32
+ - The checks against argument injection: operands that Git would read as options, NUL
33
+ characters in arguments, and empty pathspecs are still rejected before Git runs. They are not
34
+ opt-in.
35
+ - Parsers, adapters, `GitError` and `GitArgumentError`.
36
+
37
+ ## Moving `command()` calls
38
+
39
+ Wrap the client or repository with `strict()`. The wrapper keeps every original member, so it
40
+ can replace the original object:
41
+
42
+ ```ts
43
+ // 0.6.0
44
+ const repo = await git.open(path);
45
+ await repo.command('log', [['--oneline'], ['-n', '5']]);
46
+ await git.command('hash-object', [['--stdin']], { stdin: 'hello' });
47
+
48
+ // 0.7.0
49
+ import { strict } from 'type-git/strict';
50
+
51
+ const repo = strict(await git.open(path));
52
+ await repo.command('log', [['--oneline'], ['-n', '5']]);
53
+ await repo.status();
54
+ await strict(git).command('hash-object', [['--stdin']], { stdin: 'hello' });
55
+ ```
56
+
57
+ `strict()` accepts objects created by type-git: `createGit()`, `createGitSync()`, `TypeGit`
58
+ from any runtime entry point, and the repositories returned by `open()`, `openBare()`,
59
+ `openRaw()`, `init()` and `clone()`. It throws `GitArgumentError` for other objects. Arguments,
60
+ options, results and errors of `command()` are unchanged.
61
+
62
+ If you do not need grammar checks, `raw()` runs any Git command without them:
63
+
64
+ ```ts
65
+ await repo.raw(['log', '--oneline', '-n', '5']);
66
+ ```
67
+
68
+ ## Moved types
69
+
70
+ These types are exported from `type-git/strict` instead of `type-git`:
71
+
72
+ - `GitCommandArgument`, `GitCommandClient`, `GitCommandExecOpts`, `GitCommandName`
73
+
74
+ `type-git/strict` also exports `CheckedCommandArguments` and the wrapper types `Strict<T>`,
75
+ `StrictGit`, `StrictWorktreeRepo` and `StrictBareRepo`. Code that declared a variable with
76
+ `command()` as `Git` or `WorktreeRepo` can use these instead:
77
+
78
+ ```ts
79
+ import type { StrictWorktreeRepo } from 'type-git/strict';
80
+
81
+ async function lastCommits(repo: StrictWorktreeRepo) {
82
+ return await repo.command('log', [['--oneline'], ['-n', '5']]);
83
+ }
84
+ ```
85
+
86
+ ## `CliRunner.runCommand()`
87
+
88
+ `CliRunner` is still exported, with `run()`, `runOrThrow()` and the other execution methods, but
89
+ its grammar-checked `runCommand()` is removed. Create a client with `createGit()` or `TypeGit`
90
+ and call `strict(client).command()` instead.
91
+
92
+ ## Custom adapters
93
+
94
+ The adapter contract is unchanged. `spawnBytes` is still needed only for
95
+ `strict(...).command(..., { stdout: 'bytes' })`.
96
+
97
+ ## Clone config keys
98
+
99
+ `git.clone(url, path, { config })` now accepts only keys that hold data, declared by the
100
+ `CloneConfig` type: for example `user.name`, `user.email`, `core.autocrlf`,
101
+ `protocol.version` and `http.*` / `http.<url>.*` transport settings such as `extraHeader`,
102
+ `proxy` and `sslVerify`. Other keys, including keys that run a program (`core.sshCommand`,
103
+ `core.fsmonitor`, `include.path`, `protocol.ext.allow`) and keys that turn off Git's
104
+ protections (`core.protectNTFS`, `core.protectHFS`, `*.fsckObjects`), are refused with
105
+ `GitArgumentError` before Git starts. In an object literal they are also a type error.
106
+
107
+ To keep using such a key, pass a trusted value through `raw()`, or set it after cloning with `repo.config.setRaw()`:
108
+
109
+ ```ts
110
+ // 0.6.0
111
+ const repo = await git.clone(url, path, { config: { 'core.sshCommand': sshCommand } });
112
+
113
+ // 0.7.0: configure the clone itself through raw()
114
+ const result = await git.raw(['clone', '-c', `core.sshCommand=${sshCommand}`, '--', url, path]);
115
+ if (result.exitCode !== 0) throw new Error(result.stderr);
116
+ const repo = await git.open(path);
117
+ ```
118
+
119
+ If only the new repository needs the key, not the clone itself, set it after cloning:
120
+
121
+ ```ts
122
+ const repo = await git.clone(url, path);
123
+ await repo.config.setRaw('core.fsmonitor', 'true');
124
+ ```
125
+
126
+ ## `GIT_SSH` and `GIT_SSH_COMMAND`
127
+
128
+ The default environment allowlist no longer includes `GIT_SSH` or `GIT_SSH_COMMAND`, because
129
+ both name a program that Git runs for every SSH fetch, push and ls-remote. If your process sets
130
+ one of them for Git, SSH operations now use plain `ssh` instead, and can fail with
131
+ authentication or host key errors. Opt back in when you create the client:
132
+
133
+ ```ts
134
+ // Inherit the variable from the parent environment
135
+ // (or: inheritEnv: { add: ['GIT_SSH_COMMAND'] })
136
+ const git = await createGit({ adapters, inheritEnv: ['GIT_SSH_COMMAND'] });
137
+ ```
138
+
139
+ Or pass the value explicitly:
140
+
141
+ ```ts
142
+ const git = await createGit({ adapters, env: { GIT_SSH_COMMAND: 'ssh -i /path/to/deploy_key' } });
143
+ ```
144
+
145
+ `GIT_SSH_VARIANT`, the SSH agent variables and the TLS settings are still inherited.
146
+
147
+ ## `repo.show()` output options
148
+
149
+ `repo.show()` now checks combinations of `stat`, `nameOnly`, `nameStatus` and `quiet`, both in
150
+ its option types and at runtime. `nameOnly` with `nameStatus` is refused (0.6.0 silently dropped
151
+ `nameStatus`), and so is `quiet` with `nameOnly` or `nameStatus`. Keep only the option whose
152
+ output you read.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-git",
3
- "version": "0.6.0",
3
+ "version": "0.7.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",
@@ -47,6 +47,16 @@
47
47
  "default": "./dist/adapters/deno/index.cjs"
48
48
  }
49
49
  },
50
+ "./strict": {
51
+ "import": {
52
+ "types": "./dist/strict/index.d.ts",
53
+ "default": "./dist/strict/index.js"
54
+ },
55
+ "require": {
56
+ "types": "./dist/strict/index.d.cts",
57
+ "default": "./dist/strict/index.cjs"
58
+ }
59
+ },
50
60
  "./package.json": "./package.json"
51
61
  },
52
62
  "engines": {
@@ -100,6 +110,7 @@
100
110
  },
101
111
  "scripts": {
102
112
  "build": "node scripts/build.mjs",
113
+ "size:check": "node scripts/size-budget.mjs",
103
114
  "test": "vitest",
104
115
  "test:ci": "vitest run",
105
116
  "test:bun": "bun test test/bun/",