-
Notifications
You must be signed in to change notification settings - Fork 645
move env consolidation after loading envFile #935
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
out | ||
node_modules | ||
.vscode-test | ||
*.vsix | ||
*.vsix | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,7 +181,7 @@ class Delve { | |
this.program = program; | ||
this.remotePath = remotePath; | ||
let mode = launchArgs.mode; | ||
let env = launchArgs.env || {}; | ||
let env = Object.assign({}, launchArgs.env, process.env); | ||
let dlvCwd = dirname(program); | ||
let isProgramDirectory = false; | ||
this.connection = new Promise((resolve, reject) => { | ||
|
@@ -207,20 +207,27 @@ class Delve { | |
return reject('The program attribute must point to valid directory, .go file or executable.'); | ||
} | ||
|
||
// Consolidate env vars | ||
let finalEnv: Object = null; | ||
if (Object.keys(env).length > 0) { | ||
finalEnv = {}; | ||
for (let k in process.env) { | ||
finalEnv[k] = process.env[k]; | ||
} | ||
for (let k in env) { | ||
finalEnv[k] = env[k]; | ||
// read env from disk and merge into envVars | ||
if (launchArgs.envFile) { | ||
try { | ||
const buffer = stripBOM(FS.readFileSync(launchArgs.envFile, 'utf8')); | ||
buffer.split('\n').forEach( line => { | ||
const r = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/); | ||
if (r !== null) { | ||
let value = r[2] || ''; | ||
if (value.length > 0 && value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') { | ||
value = value.replace(/\\n/gm, '\n'); | ||
} | ||
env[r[1]] = value.replace(/(^['"]|['"]$)/g, ''); | ||
} | ||
}); | ||
} catch (e) { | ||
return reject('Cannot load environment variables from file'); | ||
} | ||
} | ||
|
||
if (!!launchArgs.noDebug && mode === 'debug' && !isProgramDirectory) { | ||
this.debugProcess = spawn(getGoRuntimePath(), ['run', program], {env: finalEnv}); | ||
this.debugProcess = spawn(getGoRuntimePath(), ['run', program], { env }); | ||
this.debugProcess.stderr.on('data', chunk => { | ||
let str = chunk.toString(); | ||
if (this.onstderr) { this.onstderr(str); } | ||
|
@@ -250,25 +257,6 @@ class Delve { | |
return; | ||
} | ||
|
||
// read env from disk and merge into envVars | ||
if (launchArgs.envFile) { | ||
try { | ||
const buffer = stripBOM(FS.readFileSync(launchArgs.envFile, 'utf8')); | ||
buffer.split('\n').forEach( line => { | ||
const r = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/); | ||
if (r !== null) { | ||
let value = r[2] || ''; | ||
if (value.length > 0 && value.charAt(0) === '"' && value.charAt(value.length - 1) === '"') { | ||
value = value.replace(/\\n/gm, '\n'); | ||
} | ||
env[r[1]] = value.replace(/(^['"]|['"]$)/g, ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, just changing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or we can get rid of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea! I was focusing only on getting it done 😄 Can you see how it looks now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, I'm suggesting that we use the following precedence order What do you think? Check the last commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed on the order. |
||
} | ||
}); | ||
} catch (e) { | ||
return reject('Cannot load environment variables from file'); | ||
} | ||
} | ||
|
||
let dlv = getBinPathWithPreferredGopath('dlv', resolvePath(env['GOPATH'])); | ||
|
||
if (!existsSync(dlv)) { | ||
|
@@ -301,7 +289,7 @@ class Delve { | |
|
||
this.debugProcess = spawn(dlv, dlvArgs, { | ||
cwd: dlvCwd, | ||
env: finalEnv, | ||
env, | ||
}); | ||
|
||
function connectClient(port: number, host: string) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this way the
process.env
overrideslaunchArgs.env
It should be the other way around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check last commit, I changed it.