Skip to content

Commit

Permalink
fix: Use where instead of which. Improve Windows support. (#139)
Browse files Browse the repository at this point in the history
* Add try catch.

* Use where instead of which.

* Fix tests.
  • Loading branch information
milesj committed Feb 13, 2021
1 parent aa54fa0 commit a0238c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions packages/debug/src/CrashReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { FilePath, PackageStructure, PortablePath, requireModule, toArray } from
import debug from './debug';

function run(command: string, args: string[]): string {
return String(execa.sync(command, args, { preferLocal: true }).stdout);
let cmd = command;

if (command === 'where' && os.platform() === 'win32') {
cmd += '.exe';
}

return String(execa.sync(cmd, args, { preferLocal: true }).stdout);
}

function resolveHome(filePath: FilePath): string {
Expand Down Expand Up @@ -64,7 +70,7 @@ export default class CrashReporter {
this.add(
bins[bin as keyof typeof bins],
extractVersion(run(bin, ['--version'])),
resolveHome(run('which', [bin])),
resolveHome(run('where', [bin])),
);
} catch {
// Ignore
Expand Down Expand Up @@ -123,13 +129,13 @@ export default class CrashReporter {
if (!version) {
version = extractVersion(run(bin, ['version']));
}

if (version) {
this.add(languages[bin!], version, resolveHome(run('where', [bin])));
}
} catch {
// Ignore
}

if (version) {
this.add(languages[bin!], version, resolveHome(run('which', [bin])));
}
});

return this;
Expand Down
2 changes: 1 addition & 1 deletion packages/debug/tests/CrashReporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('CrashReporter', () => {

return {
stderr: '',
stdout: command === 'which' ? `/${args.join(' ')}` : '0.0.0',
stdout: command.includes('where') ? `/${args.join(' ')}` : '0.0.0',
};
});

Expand Down

0 comments on commit a0238c3

Please sign in to comment.