@sidekick-coder/zenith-kit 0.0.6 → 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;
@@ -13,18 +22,17 @@ interface GitGatewayOptions {
13
22
  sshKey?: string;
14
23
  sshKeyFile?: string;
15
24
  sshKeyTmpFileName?: string;
25
+ logger?: LoggerService;
26
+ debug?: boolean;
16
27
  }
17
28
  declare class GitGateway {
18
29
  private readonly cwd;
19
30
  private readonly sshKey?;
20
31
  private readonly sshKeyFile?;
21
32
  private readonly sshKeyTmpFileName?;
22
- constructor({
23
- cwd,
24
- sshKey,
25
- sshKeyFile,
26
- sshKeyTmpFileName
27
- }: GitGatewayOptions);
33
+ private readonly logger;
34
+ private readonly debug;
35
+ constructor(options: GitGatewayOptions);
28
36
  private buildEnv;
29
37
  run(args: string): Promise<string>;
30
38
  tryRun(args: string): Promise<string | null>;
@@ -277,6 +277,17 @@ var PluginRouter = class {
277
277
  }
278
278
  };
279
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
280
291
  //#region src/server/gateways/GitGateway.ts
281
292
  const execAsync = promisify(exec);
282
293
  function escapeShellArgument(value) {
@@ -287,40 +298,42 @@ var GitGateway = class {
287
298
  sshKey;
288
299
  sshKeyFile;
289
300
  sshKeyTmpFileName;
290
- constructor({ cwd, sshKey, sshKeyFile, sshKeyTmpFileName }) {
291
- this.cwd = cwd;
292
- this.sshKey = sshKey;
293
- this.sshKeyFile = sshKeyFile;
294
- this.sshKeyTmpFileName = sshKeyTmpFileName;
301
+ logger = new LoggerService();
302
+ debug;
303
+ constructor(options) {
304
+ Object.assign(this, options);
295
305
  }
296
306
  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
- },
307
+ const result = {
308
+ sshKeyFile: void 0,
309
+ env: process.env,
302
310
  cleanup: async () => {}
303
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
+ }
304
316
  if (this.sshKey) {
305
317
  const tempFile = this.sshKeyTmpFileName ?? join(tmpdir(), `git-ssh-key-${randomUUID()}`);
306
318
  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(() => {});
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 });
314
326
  }
315
327
  };
316
328
  }
317
- return {
318
- env: process.env,
319
- cleanup: async () => {}
320
- };
329
+ return result;
321
330
  }
322
331
  async run(args) {
323
- const { env, cleanup } = await this.buildEnv();
332
+ const { env, sshKeyFile, cleanup } = await this.buildEnv();
333
+ if (this.debug) this.logger.debug("git " + args, {
334
+ cwd: this.cwd,
335
+ sshKeyFile
336
+ });
324
337
  try {
325
338
  const { stdout } = await execAsync(`git ${args}`, {
326
339
  cwd: this.cwd,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sidekick-coder/zenith-kit",
3
- "version": "0.0.6",
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": [],