From 67ebcd712c79ce179f037b71bf78c0bfab1e2f9c Mon Sep 17 00:00:00 2001 From: Leo Goetz Date: Thu, 21 May 2026 08:33:11 +0200 Subject: refactor: replace promiseExec callback with promise --- src/actions/checkDependencies.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/actions/checkDependencies.ts b/src/actions/checkDependencies.ts index ab0f182..c248903 100644 --- a/src/actions/checkDependencies.ts +++ b/src/actions/checkDependencies.ts @@ -2,7 +2,7 @@ import fs from "fs/promises"; import ora, { type Ora } from "ora"; import type { Config, Project } from "../types.js"; import { getConfig } from "../utils/config.js"; -import { exec } from "child_process"; +import { exec, type ExecException } from "child_process"; export async function checkDependencies() { const spinner = ora("Getting all Project Data").start(); @@ -48,31 +48,31 @@ async function getAuditPromise( await pullLatest(path, spinner); spinner.text = "getting audit"; - promiseExec( - `cd "${path}" && npm audit --json`, - (_: any, stdout: string) => { - let output = JSON.parse(stdout); - let project: Project = { projectName: dirname, ...output }; - if (project.error) { - reject( - `${dirname} could not be audited, maybe package lock is corrupted`, - ); - } - resolve(project); - }, - ); + + let { stdout } = await promiseExec(`cd "${path}" && npm audit --json`); + + let output = JSON.parse(stdout); + let project: Project = { projectName: dirname, ...output }; + if (project.error) { + reject( + `${dirname} could not be audited, maybe package lock is corrupted`, + ); + } + resolve(project); }); } async function pullLatest(path: string, spinner: Ora) { spinner.text = "pulling latest"; - await promiseExec(`cd "${path}" && git pull `, () => {}); + await promiseExec(`cd "${path}" && git pull`); } -function promiseExec(cmd: string, callback: any): Promise { +function promiseExec( + cmd: string, +): Promise<{ error: ExecException | null; stdout: string; stderr: string }> { return new Promise((resolve, _) => { - exec(cmd, (err, stdout, stderr) => { - resolve(callback(err, stdout, stderr)); + exec(cmd, (error, stdout, stderr) => { + resolve({ error, stdout, stderr }); }); }); } -- cgit v1.3.1