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

Commit

Permalink
Include env from launch config when looking up things on path for mic…
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Dec 22, 2017
1 parent 6a30757 commit fe51af5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/nodeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ export class NodeDebugAdapter extends ChromeDebugAdapter {
runtimeExecutable = runtimeExecutable || NodeDebugAdapter.NODE;
} else if (runtimeExecutable) {
if (!path.isAbsolute(runtimeExecutable)) {
const re = pathUtils.findOnPath(runtimeExecutable);
const re = pathUtils.findOnPath(runtimeExecutable, args.env);
if (!re) {
return this.getRuntimeNotOnPathErrorResponse(runtimeExecutable);
}

runtimeExecutable = re;
} else {
const re = pathUtils.findExecutable(runtimeExecutable);
const re = pathUtils.findExecutable(runtimeExecutable, args.env);
if (!re) {
return this.getNotExistErrorResponse('runtimeExecutable', runtimeExecutable);
}

runtimeExecutable = re;
}
} else {
if (!pathUtils.findOnPath(NodeDebugAdapter.NODE)) {
if (!pathUtils.findOnPath(NodeDebugAdapter.NODE, args.env)) {
return Promise.reject(errors.runtimeNotFound(NodeDebugAdapter.NODE));
}

Expand Down
26 changes: 20 additions & 6 deletions src/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,23 @@ export function makeRelative2(from: string, to: string): string {
/*
* Lookup the given program on the PATH and return its absolute path on success and undefined otherwise.
*/
export function findOnPath(program: string): string | undefined {
export function findOnPath(program: string, args_env: any): string | undefined {
const env = extendObject(extendObject({}, process.env), args_env);

let locator: string;
if (process.platform === 'win32') {
const windir = process.env['WINDIR'] || 'C:\\Windows';
const windir = env['WINDIR'] || 'C:\\Windows';
locator = Path.join(windir, 'System32', 'where.exe');
} else {
locator = '/usr/bin/which';
}

try {
if (FS.existsSync(locator)) {
const lines = CP.execSync(`${locator} ${program}`).toString().split(/\r?\n/);
const lines = CP.execSync(`${locator} ${program}`, { env }).toString().split(/\r?\n/);
if (process.platform === 'win32') {
// return the first path that has a executable extension
const executableExtensions = process.env['PATHEXT'].toUpperCase();
const executableExtensions = env['PATHEXT'].toUpperCase();
for (const path of lines) {
const ext = Path.extname(path).toUpperCase();
if (ext && executableExtensions.indexOf(ext + ';') > 0) {
Expand All @@ -245,9 +247,11 @@ export function findOnPath(program: string): string | undefined {
return undefined;
}

export function findExecutable(program: string): string | undefined {
export function findExecutable(program: string, args_env: any): string | undefined {
const env = extendObject(extendObject({}, process.env), args_env);

if (process.platform === 'win32' && !Path.extname(program)) {
const PATHEXT = process.env['PATHEXT'];
const PATHEXT = env['PATHEXT'];
if (PATHEXT) {
const executableExtensions = PATHEXT.split(';');
for (const extension of executableExtensions) {
Expand All @@ -265,3 +269,13 @@ export function findExecutable(program: string): string | undefined {

return undefined;
}

export function extendObject<T>(toObject: T, fromObject: T): T {

for (let key in fromObject) {
if (fromObject.hasOwnProperty(key)) {
toObject[key] = fromObject[key];
}
}
return toObject;
}

0 comments on commit fe51af5

Please sign in to comment.