@sidekick-coder/zenith-kit 0.0.5 → 0.0.6

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.
@@ -11,14 +11,21 @@ interface GitRepoInfo {
11
11
  interface GitGatewayOptions {
12
12
  cwd: string;
13
13
  sshKey?: string;
14
+ sshKeyFile?: string;
15
+ sshKeyTmpFileName?: string;
14
16
  }
15
17
  declare class GitGateway {
16
18
  private readonly cwd;
17
- private readonly env?;
19
+ private readonly sshKey?;
20
+ private readonly sshKeyFile?;
21
+ private readonly sshKeyTmpFileName?;
18
22
  constructor({
19
23
  cwd,
20
- sshKey
24
+ sshKey,
25
+ sshKeyFile,
26
+ sshKeyTmpFileName
21
27
  }: GitGatewayOptions);
28
+ private buildEnv;
22
29
  run(args: string): Promise<string>;
23
30
  tryRun(args: string): Promise<string | null>;
24
31
  checkout(ref: string): Promise<void>;
@@ -1,5 +1,9 @@
1
1
  import { exec } from "node:child_process";
2
2
  import { promisify } from "node:util";
3
+ import { unlink, writeFile } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { randomUUID } from "node:crypto";
3
7
  //#region src/server/services/GitBranchRepository.ts
4
8
  var GitBranchRepository = class {
5
9
  constructor(gateway) {
@@ -280,20 +284,52 @@ function escapeShellArgument(value) {
280
284
  }
281
285
  var GitGateway = class {
282
286
  cwd;
283
- env;
284
- constructor({ cwd, sshKey }) {
287
+ sshKey;
288
+ sshKeyFile;
289
+ sshKeyTmpFileName;
290
+ constructor({ cwd, sshKey, sshKeyFile, sshKeyTmpFileName }) {
285
291
  this.cwd = cwd;
286
- this.env = sshKey ? {
287
- ...process.env,
288
- GIT_SSH_COMMAND: `ssh -i ${escapeShellArgument(sshKey)} -o StrictHostKeyChecking=no`
289
- } : void 0;
292
+ this.sshKey = sshKey;
293
+ this.sshKeyFile = sshKeyFile;
294
+ this.sshKeyTmpFileName = sshKeyTmpFileName;
295
+ }
296
+ async buildEnv() {
297
+ if (this.sshKeyFile) return {
298
+ env: {
299
+ ...process.env,
300
+ GIT_SSH_COMMAND: `ssh -i ${escapeShellArgument(this.sshKeyFile)} -o StrictHostKeyChecking=no`
301
+ },
302
+ cleanup: async () => {}
303
+ };
304
+ if (this.sshKey) {
305
+ const tempFile = this.sshKeyTmpFileName ?? join(tmpdir(), `git-ssh-key-${randomUUID()}`);
306
+ await writeFile(tempFile, this.sshKey, { mode: 384 });
307
+ return {
308
+ env: {
309
+ ...process.env,
310
+ GIT_SSH_COMMAND: `ssh -i ${escapeShellArgument(tempFile)} -o StrictHostKeyChecking=no`
311
+ },
312
+ cleanup: async () => {
313
+ await unlink(tempFile).catch(() => {});
314
+ }
315
+ };
316
+ }
317
+ return {
318
+ env: process.env,
319
+ cleanup: async () => {}
320
+ };
290
321
  }
291
322
  async run(args) {
292
- const { stdout } = await execAsync(`git ${args}`, {
293
- cwd: this.cwd,
294
- env: this.env
295
- });
296
- return stdout.trim();
323
+ const { env, cleanup } = await this.buildEnv();
324
+ try {
325
+ const { stdout } = await execAsync(`git ${args}`, {
326
+ cwd: this.cwd,
327
+ env
328
+ });
329
+ return stdout.trim();
330
+ } finally {
331
+ await cleanup();
332
+ }
297
333
  }
298
334
  async tryRun(args) {
299
335
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sidekick-coder/zenith-kit",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "license": "MIT",
5
5
  "description": "A collection of utilities and tools for building language servers and related applications.",
6
6
  "keywords": [],