Make preserveEnv return a new object

Modifying the object didn't feel quite right, plus this makes the code a
bit more compact.
This commit is contained in:
Asher
2019-04-29 11:49:59 -05:00
parent 1622fd4152
commit cdb900aca8
5 changed files with 20 additions and 39 deletions

View File

@@ -1,6 +1,6 @@
import * as cp from "child_process";
import { ServerProxy } from "../../common/proxy";
import { preserveEnv } from "../../common/util";
import { withEnv } from "../../common/util";
import { WritableProxy, ReadableProxy } from "./stream";
// tslint:disable completed-docs
@@ -71,21 +71,15 @@ export class ChildProcessModuleProxy {
options?: { encoding?: string | null } & cp.ExecOptions | null,
callback?: ((error: cp.ExecException | null, stdin: string | Buffer, stdout: string | Buffer) => void),
): Promise<ChildProcessProxies> {
preserveEnv(options);
return this.returnProxies(cp.exec(command, options, callback));
return this.returnProxies(cp.exec(command, options && withEnv(options), callback));
}
public async fork(modulePath: string, args?: string[], options?: cp.ForkOptions): Promise<ChildProcessProxies> {
preserveEnv(options);
return this.returnProxies((this.forkProvider || cp.fork)(modulePath, args, options));
return this.returnProxies((this.forkProvider || cp.fork)(modulePath, args, withEnv(options)));
}
public async spawn(command: string, args?: string[], options?: cp.SpawnOptions): Promise<ChildProcessProxies> {
preserveEnv(options);
return this.returnProxies(cp.spawn(command, args, options));
return this.returnProxies(cp.spawn(command, args, withEnv(options)));
}
private returnProxies(process: cp.ChildProcess): ChildProcessProxies {