Skip to content
This repository was archived by the owner on Dec 6, 2022. It is now read-only.

Commit 0a503aa

Browse files
committed
Fix #706 - allow setting env vars to "null" like node-debug
1 parent 83decfc commit 0a503aa

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/chromeDebugAdapter.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
8787
// Start with remote debugging enabled
8888
const port = args.port || 9222;
8989
const chromeArgs: string[] = [];
90-
const chromeEnv: {[key: string]: string} = args.env || null;
90+
const chromeEnv: coreUtils.IStringDictionary<string> = args.env || null;
9191
const chromeWorkingDir: string = args.cwd || null;
9292

9393
if (!args.noDebug) {
@@ -379,7 +379,7 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
379379
Promise.resolve();
380380
}
381381

382-
private async spawnChrome(chromePath: string, chromeArgs: string[], env: {[key: string]: string},
382+
private async spawnChrome(chromePath: string, chromeArgs: string[], env: coreUtils.IStringDictionary<string>,
383383
cwd: string, usingRuntimeExecutable: boolean, shouldLaunchUnelevated: boolean): Promise<ChildProcess> {
384384
/* __GDPR__FRAGMENT__
385385
"StepNames" : {
@@ -406,10 +406,7 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
406406
silent: true
407407
};
408408
if (env) {
409-
options['env'] = {
410-
...process.env,
411-
...env
412-
};
409+
options['env'] = this.getFullEnv(env);
413410
}
414411
if (cwd) {
415412
options['cwd'] = cwd;
@@ -444,10 +441,7 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
444441
stdio: ['ignore'],
445442
};
446443
if (env) {
447-
options['env'] = {
448-
...process.env,
449-
...env
450-
};
444+
options['env'] = this.getFullEnv(env);
451445
}
452446
if (cwd) {
453447
options['cwd'] = cwd;
@@ -485,6 +479,16 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
485479
return null;
486480
}
487481

482+
private getFullEnv(customEnv: coreUtils.IStringDictionary<string>): coreUtils.IStringDictionary<string> {
483+
const env = {
484+
...process.env,
485+
...customEnv
486+
};
487+
488+
Object.keys(env).filter(k => env[k] === null).forEach(key => delete env[key]);
489+
return env;
490+
}
491+
488492
private async spawnChromeUnelevatedWithClient(chromePath: string, chromeArgs: string[]): Promise<number> {
489493
return new Promise<number>((resolve, reject) => {
490494
this._session.sendRequest('launchUnelevated', {

0 commit comments

Comments
 (0)