From 80b0e11e93fe84f930903760f0bf5b4a7d48f665 Mon Sep 17 00:00:00 2001 From: tnascimento Date: Sun, 8 Sep 2024 21:22:47 -0300 Subject: [PATCH] fix: removing stdout and stderr from spawnPromise to avoid memory allocation increasing --- src/modules/commands.ts | 6 +++--- src/modules/utils.ts | 18 +++--------------- test/commands/builds/deploy.test.ts | 3 +-- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/modules/commands.ts b/src/modules/commands.ts index ccfc1b0..575e04f 100644 --- a/src/modules/commands.ts +++ b/src/modules/commands.ts @@ -4,7 +4,7 @@ import { AuthParameters, Build } from './types.js'; import BuildsUtils from './utils.js'; export default class Commands { - public static async auth(authParms: AuthParameters): Promise<{ stdout: string; stderr: string }> { + public static async auth(authParms: AuthParameters): Promise { console.log(' --- auth --- '); const authCommand = 'sf' as string; const authCommandArgs: string[] = []; @@ -38,7 +38,7 @@ export default class Commands { return BuildsUtils.execCommand(authCommand, authCommandArgs); } - public static async disableTracking(username: string): Promise<{ stdout: string; stderr: string }> { + public static async disableTracking(username: string): Promise { console.log(' --- disabling source tracking on target sandbox --- '); const configCommand = 'sf' as string; const configCommandArgs: string[] = []; @@ -51,7 +51,7 @@ export default class Commands { return BuildsUtils.execCommand(configCommand, configCommandArgs); } - public static async deploy(build: Build, username: string): Promise<{ stdout: string; stderr: string }> { + public static async deploy(build: Build, username: string): Promise { console.log(` --- build type: ${build.type} --- `); let buildCommand: string; diff --git a/src/modules/utils.ts b/src/modules/utils.ts index fbaf5a0..dbbbfda 100644 --- a/src/modules/utils.ts +++ b/src/modules/utils.ts @@ -13,30 +13,22 @@ export default class BuildsUtils { * @param options SpawnOptions for this request * @returns */ - public static async spawnPromise( - command: string, - args: string[], - options: SpawnOptions - ): Promise<{ stdout: string; stderr: string }> { + public static async spawnPromise(command: string, args: string[], options: SpawnOptions): Promise { return new Promise((resolve, reject) => { const process = spawn(command, args, options); - let stdout = ''; - let stderr = ''; process.stdout?.on('data', (data: Buffer) => { console.log(data.toString()); - stdout += data.toString(); }); process.stderr?.on('data', (data: Buffer) => { console.error(data.toString()); - stderr += data.toString(); }); process.on('close', (code) => { if (code === 0) { console.log('Command executed successfully'); - resolve({ stdout, stderr }); + resolve(); } else { console.error(`Process exited with code ${code ?? 'null or undefined'}`); reject(new Error(`Process exited with code ${code ?? 'null or undefined'}`)); @@ -57,11 +49,7 @@ export default class BuildsUtils { * @param {*} args array with args * @param {*} workingFolder opcional */ - public static async execCommand( - command: string, - args: string[], - workingFolder: string | null = null - ): Promise<{ stdout: string; stderr: string }> { + public static async execCommand(command: string, args: string[], workingFolder: string | null = null): Promise { const options: SpawnOptions = {}; if (workingFolder) { diff --git a/test/commands/builds/deploy.test.ts b/test/commands/builds/deploy.test.ts index 330d0ee..cb8e318 100644 --- a/test/commands/builds/deploy.test.ts +++ b/test/commands/builds/deploy.test.ts @@ -73,8 +73,7 @@ describe('BuildsDeploy', () => { const execSpawnSync = stub(BuildsUtils, 'spawnPromise').returns( new Promise((resolve, reject) => { - const cmdReturn: { stdout: string; stderr: string } = { stdout: 'stdout', stderr: 'stderr' }; - resolve(cmdReturn); + resolve(); }) ); const execReadFileSync = stub(BuildsUtils, 'execReadFileSync');