-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically install the probe-rs binaries on request
- Loading branch information
Showing
5 changed files
with
146 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const path = require('path'); | ||
import {promises as fs} from 'fs'; | ||
|
||
/** | ||
* @param {string} exe executable name (without extension if on Windows) | ||
* @return {Promise<string|null>} executable path if found | ||
* */ | ||
async function findExecutable(executableName: string): Promise<string | null> { | ||
const envPath = process.env.PATH || ''; | ||
const envExt = process.env.PATHEXT || ''; | ||
const pathDirs = envPath.replace(/["]+/g, '').split(path.delimiter).filter(Boolean); | ||
const extensions = envExt.split(';'); | ||
const candidates = pathDirs.flatMap((d) => | ||
extensions.map((ext) => path.join(d, executableName + ext)), | ||
); | ||
try { | ||
return await Promise.any(candidates.map(checkFileExists)); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
|
||
async function checkFileExists(filePath): Promise<string | null> { | ||
if ((await fs.stat(filePath)).isFile()) { | ||
return filePath; | ||
} | ||
return null; | ||
} | ||
|
||
export async function probeRsInstalled() { | ||
return await findExecutable('probe-rs'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters