@sidekick-coder/zenith-kit 0.0.5 → 0.0.8

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.
@@ -1,5 +1,14 @@
1
1
  import { ChildProcess } from "node:child_process";
2
2
 
3
+ //#region src/shared/services/LoggerService.d.ts
4
+ declare class LoggerService {
5
+ info(message: string, meta?: any): void;
6
+ debug(message: string, meta?: any): void;
7
+ warn(message: string, meta?: any): void;
8
+ error(message: string, meta?: any): void;
9
+ child(options: any): LoggerService;
10
+ }
11
+ //#endregion
3
12
  //#region src/server/gateways/GitGateway.d.ts
4
13
  interface GitRepoInfo {
5
14
  directory: string;
@@ -11,14 +20,20 @@ interface GitRepoInfo {
11
20
  interface GitGatewayOptions {
12
21
  cwd: string;
13
22
  sshKey?: string;
23
+ sshKeyFile?: string;
24
+ sshKeyTmpFileName?: string;
25
+ logger?: LoggerService;
26
+ debug?: boolean;
14
27
  }
15
28
  declare class GitGateway {
16
29
  private readonly cwd;
17
- private readonly env?;
18
- constructor({
19
- cwd,
20
- sshKey
21
- }: GitGatewayOptions);
30
+ private readonly sshKey?;
31
+ private readonly sshKeyFile?;
32
+ private readonly sshKeyTmpFileName?;
33
+ private readonly logger;
34
+ private readonly debug;
35
+ constructor(options: GitGatewayOptions);
36
+ private buildEnv;
22
37
  run(args: string): Promise<string>;
23
38
  tryRun(args: string): Promise<string | null>;
24
39
  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) {
@@ -273,6 +277,17 @@ var PluginRouter = class {
273
277
  }
274
278
  };
275
279
  //#endregion
280
+ //#region src/shared/services/LoggerService.ts
281
+ var LoggerService = class LoggerService {
282
+ info(message, meta) {}
283
+ debug(message, meta) {}
284
+ warn(message, meta) {}
285
+ error(message, meta) {}
286
+ child(options) {
287
+ return new LoggerService();
288
+ }
289
+ };
290
+ //#endregion
276
291
  //#region src/server/gateways/GitGateway.ts
277
292
  const execAsync = promisify(exec);
278
293
  function escapeShellArgument(value) {
@@ -280,20 +295,54 @@ function escapeShellArgument(value) {
280
295
  }
281
296
  var GitGateway = class {
282
297
  cwd;
283
- env;
284
- constructor({ cwd, sshKey }) {
285
- this.cwd = cwd;
286
- this.env = sshKey ? {
287
- ...process.env,
288
- GIT_SSH_COMMAND: `ssh -i ${escapeShellArgument(sshKey)} -o StrictHostKeyChecking=no`
289
- } : void 0;
298
+ sshKey;
299
+ sshKeyFile;
300
+ sshKeyTmpFileName;
301
+ logger = new LoggerService();
302
+ debug;
303
+ constructor(options) {
304
+ Object.assign(this, options);
305
+ }
306
+ async buildEnv() {
307
+ const result = {
308
+ sshKeyFile: void 0,
309
+ env: process.env,
310
+ cleanup: async () => {}
311
+ };
312
+ if (this.sshKeyFile) {
313
+ result.env.GIT_SSH_COMMAND = `ssh -i ${escapeShellArgument(this.sshKeyFile)} -o StrictHostKeyChecking=no`;
314
+ result.sshKeyFile = this.sshKeyFile;
315
+ }
316
+ if (this.sshKey) {
317
+ const tempFile = this.sshKeyTmpFileName ?? join(tmpdir(), `git-ssh-key-${randomUUID()}`);
318
+ await writeFile(tempFile, this.sshKey, { mode: 384 });
319
+ result.env.GIT_SSH_COMMAND = `ssh -i ${escapeShellArgument(tempFile)} -o StrictHostKeyChecking=no`;
320
+ result.sshKeyFile = tempFile;
321
+ result.cleanup = async () => {
322
+ try {
323
+ await unlink(tempFile);
324
+ } catch (err) {
325
+ this.logger.warn(`Failed to delete temporary SSH key file: ${tempFile}`, { error: err });
326
+ }
327
+ };
328
+ }
329
+ return result;
290
330
  }
291
331
  async run(args) {
292
- const { stdout } = await execAsync(`git ${args}`, {
332
+ const { env, sshKeyFile, cleanup } = await this.buildEnv();
333
+ if (this.debug) this.logger.debug("git " + args, {
293
334
  cwd: this.cwd,
294
- env: this.env
335
+ sshKeyFile
295
336
  });
296
- return stdout.trim();
337
+ try {
338
+ const { stdout } = await execAsync(`git ${args}`, {
339
+ cwd: this.cwd,
340
+ env
341
+ });
342
+ return stdout.trim();
343
+ } finally {
344
+ await cleanup();
345
+ }
297
346
  }
298
347
  async tryRun(args) {
299
348
  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.8",
4
4
  "license": "MIT",
5
5
  "description": "A collection of utilities and tools for building language servers and related applications.",
6
6
  "keywords": [],