Skip to content

Commit

Permalink
Merge pull request #113 from tiagonnascimento/feature-avoidingStringA…
Browse files Browse the repository at this point in the history
…llocation

fix: removing stdout and stderr from spawnPromise to avoid memory all…
  • Loading branch information
tiagonnascimento authored Sep 9, 2024
2 parents 3b8c2ec + 80b0e11 commit 3ec0c25
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/modules/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
console.log(' --- auth --- ');
const authCommand = 'sf' as string;
const authCommandArgs: string[] = [];
Expand Down Expand Up @@ -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<void> {
console.log(' --- disabling source tracking on target sandbox --- ');
const configCommand = 'sf' as string;
const configCommandArgs: string[] = [];
Expand All @@ -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<void> {
console.log(` --- build type: ${build.type} --- `);

let buildCommand: string;
Expand Down
18 changes: 3 additions & 15 deletions src/modules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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'}`));
Expand All @@ -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<void> {
const options: SpawnOptions = {};

if (workingFolder) {
Expand Down
3 changes: 1 addition & 2 deletions test/commands/builds/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 3ec0c25

Please sign in to comment.