Skip to content

Commit

Permalink
refactor(util): use spawn instead of exec
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Ladzaretti committed Jul 21, 2022
1 parent d9c4629 commit 3fa4f25
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions lib/util/exec/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function exec(cmd: string, opts: RawExecOptions): Promise<ExecResult> {

function kill(cp: ChildProcess, signal: NodeJS.Signals): boolean {
try {
// TODO: will be enabled in #16654
/**
* If `pid` is negative, but not `-1`, signal shall be sent to all processes
* (excluding an unspecified set of system processes),
Expand All @@ -136,8 +137,8 @@ function kill(cp: ChildProcess, signal: NodeJS.Signals): boolean {
}
}

// TODO: rename
// TODO: rename #16653
export const rawExec: (
cmd: string,
opts: RawExecOptions
) => Promise<ExecResult> = exec; // TODO: rename
) => Promise<ExecResult> = exec; // TODO: rename #16653
7 changes: 4 additions & 3 deletions lib/util/exec/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,25 @@ export interface DockerOptions {
cwd?: Opt<string>;
}

// TODO: rename
// TODO: rename #16653
export interface RawExecOptions extends ChildProcessSpawnOptions {
// TODO: to be removed in #16655
/**
* @deprecated renovate uses utf8, encoding property is ignored.
*/
encoding: string;
maxBuffer?: number | undefined;
}

// TODO: rename
// TODO: rename #16653
export interface ExecResult {
stdout: string;
stderr: string;
}

export type ExtraEnv<T = unknown> = Record<string, T>;

// TODO: rename
// TODO: rename #16653
export interface ExecOptions {
cwd?: string;
cwdFile?: string;
Expand Down
12 changes: 6 additions & 6 deletions test/exec-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { regEx } from '../lib/util/regex';

type CallOptions = ExecOptions | null | undefined;

// TODO: rename
// TODO: rename #16653
export type ExecResult = { stdout: string; stderr: string } | Error;

// TODO: fix type #7154
Expand All @@ -18,16 +18,16 @@ export const exec: ExecMock = _exec as any;
export type SpawnMock = jest.MockedFunction<typeof _spawn>;
export const spawn = _spawn as SpawnMock;

// TODO: rename
// TODO: rename #16653
interface ExecSnapshot {
cmd: string;
options?: ExecOptions | null | undefined;
}

// TODO: rename
// TODO: rename #16653
export type ExecSnapshots = ExecSnapshot[];

// TODO: rename
// TODO: rename #16653
export function execSnapshot(cmd: string, options?: CallOptions): ExecSnapshot {
const snapshot = {
cmd,
Expand All @@ -48,7 +48,7 @@ export function execSnapshot(cmd: string, options?: CallOptions): ExecSnapshot {

const defaultExecResult = { stdout: '', stderr: '' };

// TODO: rename
// TODO: rename #16653
export function mockExecAll(
execFn: ExecMock,
execResult: ExecResult = defaultExecResult
Expand All @@ -64,7 +64,7 @@ export function mockExecAll(
return snapshots;
}

// TODO: rename
// TODO: rename #16653
export function mockExecSequence(
execFn: ExecMock,
execResults: ExecResult[]
Expand Down

0 comments on commit 3fa4f25

Please sign in to comment.