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

Commit

Permalink
Merge pull request #520 from jpap/env-cwd-options
Browse files Browse the repository at this point in the history
Support for env and cwd options.
  • Loading branch information
roblourens committed Oct 5, 2017
2 parents a89d57e + 8e32916 commit 8565cad
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ See our wiki page for some configured example apps: [Examples](https://github.co
* `trace`: When true, the adapter logs its own diagnostic info to this file: `~/.vscode/extensions/msjsdiag.debugger-for-chrome/vscode-chrome-debug.txt`. This is often useful info to include when filing an issue on GitHub. If you set it to "verbose", it will also log to the console.
* `runtimeExecutable`: Workspace relative or absolute path to the runtime executable to be used. If not specified, Chrome will be used from the default install location
* `runtimeArgs`: Optional arguments passed to the runtime executable
* `env`: Optional dictionary of environment key/value pairs
* `cwd`: Optional working directory for the runtime executable
* `userDataDir`: Normally, if Chrome is already running when you start debugging with a launch config, then the new instance won't start in remote debugging mode. So by default, the extension launches Chrome with a separate user profile in a temp folder. Use this option to set a different path to use, or set to false to launch with your default user profile.
* `url`: On a 'launch' config, it will launch Chrome at this URL.
* `urlFilter`: On an 'attach' config, or a 'launch' config with no 'url' set, search for a page with this url and attach to it. It can also contain wildcards, for example, `"localhost:*/app"` will match either `"http://localhost:123/app"` or `"http://localhost:456/app"`, but not `"http://stackoverflow.com"`.
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@
},
"default": []
},
"env": {
"type": "object",
"description": "Optional dictionary of environment key/value pairs.",
"default": null
},
"cwd": {
"type": "string",
"description": "Optional working directory for the runtime executable.",
"default": null
},
"sourceMaps": {
"type": "boolean",
"description": "Use JavaScript source maps (if they exist).",
Expand Down
35 changes: 30 additions & 5 deletions src/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
// Start with remote debugging enabled
const port = args.port || 9222;
const chromeArgs: string[] = [];
const chromeEnv: {[key: string]: string} = args.env || null;
const chromeWorkingDir: string = args.cwd || null;

if (!args.noDebug) {
chromeArgs.push('--remote-debugging-port=' + port);
Expand Down Expand Up @@ -89,7 +91,7 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
chromeArgs.push(launchUrl);
}

this._chromeProc = this.spawnChrome(runtimeExecutable, chromeArgs, !!args.runtimeExecutable);
this._chromeProc = this.spawnChrome(runtimeExecutable, chromeArgs, chromeEnv, chromeWorkingDir, !!args.runtimeExecutable);
this._chromeProc.on('error', (err) => {
const errMsg = 'Chrome error: ' + err;
logger.error(errMsg);
Expand Down Expand Up @@ -204,9 +206,22 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
Promise.resolve();
}

private spawnChrome(chromePath: string, chromeArgs: string[], usingRuntimeExecutable: boolean): ChildProcess {
private spawnChrome(chromePath: string, chromeArgs: string[], env: {[key: string]: string}, cwd: string, usingRuntimeExecutable: boolean): ChildProcess {
if (coreUtils.getPlatform() === coreUtils.Platform.Windows && !usingRuntimeExecutable) {
const chromeProc = fork(getChromeSpawnHelperPath(), [chromePath, ...chromeArgs], { execArgv: [], silent: true });
const options = {
execArgv: [],
silent: true
};
if (env) {
options['env'] = {
...process.env,
...env
};
}
if (cwd) {
options['cwd'] = cwd;
}
const chromeProc = fork(getChromeSpawnHelperPath(), [chromePath, ...chromeArgs], options);
chromeProc.unref();

chromeProc.on('message', data => {
Expand All @@ -231,10 +246,20 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
return chromeProc;
} else {
logger.log(`spawn('${chromePath}', ${JSON.stringify(chromeArgs) })`);
const chromeProc = spawn(chromePath, chromeArgs, {
const options = {
detached: true,
stdio: ['ignore'],
});
};
if (env) {
options['env'] = {
...process.env,
...env
};
}
if (cwd) {
options['cwd'] = cwd;
}
const chromeProc = spawn(chromePath, chromeArgs, options);
chromeProc.unref();
return chromeProc;
}
Expand Down
2 changes: 2 additions & 0 deletions src/chromeDebugInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface ICommonRequestArgs extends Core.ICommonRequestArgs {
export interface ILaunchRequestArgs extends Core.ILaunchRequestArgs, ICommonRequestArgs {
runtimeArgs?: string[];
runtimeExecutable?: string;
env?: { [key: string]: string; };
cwd?: string;
file?: string;
url?: string;
stopOnEntry?: boolean;
Expand Down

0 comments on commit 8565cad

Please sign in to comment.