Skip to content

Commit

Permalink
fix: Search using PATH.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Oct 8, 2024
1 parent d03a78c commit 2d58873
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"version": "0.13.1",
"version": "0.13.2",
"name": "moon-console",
"publisher": "moonrepo",
"displayName": "moon console",
Expand Down
19 changes: 8 additions & 11 deletions packages/vscode-extension/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ export class Workspace {
return null;
}

const isWindows = process.platform === 'win32';
let binPath = vscode.workspace.getConfiguration('moon').get('binPath', 'moon');

if (process.platform === 'win32' && !binPath.endsWith('.exe')) {
if (isWindows && !binPath.endsWith('.exe')) {
binPath += '.exe';
}

Expand All @@ -175,19 +176,15 @@ export class Workspace {
return binPath;
}

try {
let globalBin = '';
if (process.platform === 'win32') {
globalBin = execa.sync('cmd', ['/c', 'where', 'moon']).stdout;
} else {
globalBin = execa.sync('which', ['moon']).stdout;
}
const paths = process.env.PATH?.split(isWindows ? ';' : ':') ?? [];
const binName = isWindows ? 'moon.exe' : 'moon';

if (globalBin && fs.existsSync(globalBin)) {
for (const dir of paths) {
const globalBin = path.join(dir, binName);

if (fs.existsSync(globalBin)) {
return globalBin;
}
} catch {
// Ignore
}

return null;
Expand Down

0 comments on commit 2d58873

Please sign in to comment.