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 241b2aa
Show file tree
Hide file tree
Showing 3 changed files with 12 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
6 changes: 3 additions & 3 deletions lib/util/exec/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface DockerOptions {
cwd?: Opt<string>;
}

// TODO: rename
// TODO: rename #16653
export interface RawExecOptions extends ChildProcessSpawnOptions {
/**
* @deprecated renovate uses utf8, encoding property is ignored.
Expand All @@ -36,15 +36,15 @@ export interface RawExecOptions extends ChildProcessSpawnOptions {
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 241b2aa

Please sign in to comment.