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

@@ -236,8 +236,11 @@ export const isPromise = (value: any): value is Promise<any> => {
* When spawning VS Code tries to preserve the environment but since it's in
* the browser, it doesn't work.
*/
export const preserveEnv = (options?: { env?: NodeJS.ProcessEnv } | null): void => {
if (options && options.env) {
options.env = { ...process.env, ...options.env };
}
export const withEnv = <T extends { env?: NodeJS.ProcessEnv }>(options?: T): T | undefined => {
return options && options.env ? {
...options,
env: {
...process.env, ...options.env,
},
} : options;
};