From a5e940b003f396f4839fe5a4386b329920672525 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sat, 27 Dec 2025 14:36:06 -0500 Subject: [PATCH] Fixed exec helper return --- package.json | 2 +- src/cli.ts | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 73eeb63..7d77a35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/node-utils", - "version": "1.0.4", + "version": "1.0.5", "description": "CSS Utility Classes", "author": "ztimson", "license": "MIT", diff --git a/src/cli.ts b/src/cli.ts index 54f025c..34332c0 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,11 +1,18 @@ -import {exec, execSync} from 'child_process'; +import {execSync} from 'child_process'; +import {spawn} from 'node:child_process'; export function $(str: TemplateStringsArray, ...args: string[]): Promise { let cmd = str.reduce((acc, part, i) => acc + part + (args[i] || ''), ''); - return new Promise((res, rej) => exec(cmd, (err, stdout, stderr) => { - if(err) return rej(stderr || err); - return res(stdout); - })) + return new Promise((res, rej) => { + const proc = spawn(cmd, {shell: true}); + let stdout = '', stderr = ''; + proc.stdout.on('data', (data) => stdout += data); + proc.stderr.on('data', (data) => stderr += data); + proc.on('close', (code) => { + if(code !== 0) return rej(new Error(stderr || stdout)); + res(stdout.trim()); + }); + }); } export function $Sync(str: TemplateStringsArray, ...args: string[]): string {