Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Simplify environment merging
Browse files Browse the repository at this point in the history
  • Loading branch information
SteelPhase committed Mar 22, 2019
1 parent 9921e09 commit 47211bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,23 @@ class Delve {
}

// read env from disk and merge into env variables
let fileEnv = {};
let envs = [process.env];

try {
if (typeof launchArgs.envFile === 'string') {
fileEnv = parseEnvFiles([launchArgs.envFile]);
envs.push(...parseEnvFiles([launchArgs.envFile]));
}

if (launchArgs.envFile instanceof Array) {
fileEnv = parseEnvFiles(launchArgs.envFile);
envs.push(...parseEnvFiles(launchArgs.envFile));
}
} catch (e) {
return reject(e);
}

let env = Object.assign({}, process.env, fileEnv, launchArgsEnv);
envs.push(launchArgsEnv);

let env = Object.assign({}, ...envs);

let dirname = isProgramDirectory ? program : path.dirname(program);
if (!env['GOPATH'] && (mode === 'debug' || mode === 'test')) {
Expand Down
8 changes: 4 additions & 4 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,17 @@ export function parseEnvFile(path: string): { [key: string]: string } {
}
}

export function parseEnvFiles(paths: string[]): { [key: string]: string } {
let mergedEnv: { [key: string]: any } = {};
export function parseEnvFiles(paths: string[]): { [key: string]: string }[] {
let envs: { [key: string]: any }[] = [];

for (let i = 0; i < paths.length; i++) {
const path = paths[i];
let env = parseEnvFile(path);

mergedEnv = Object.assign(mergedEnv, env);
envs.push(env)
}

return mergedEnv;
return envs;
}

// Walks up given folder path to return the closest ancestor that has `src` as a child
Expand Down

0 comments on commit 47211bc

Please sign in to comment.