@dsherret/which
v0.7.4
Published
Finds the path to the specified command.
Readme
deno-which
Finds the path to the specified command. Works in Deno and Node.js.
# Deno
> deno add @david/which
# Node.js
> npm install @dsherret/whichimport { which, whichSync } from "@dsherret/which";
const pathToCurl = await which("curl");Custom Environment
If you want to use this with an fake or in memory environment, then you can provide a custom environment as the second parameter.
For example:
const pathToCurl = await which("curl", {
isWindows: true,
async stat(filePath: string): Promise<{ isFile: boolean }> {
// implement this
},
statSync(filePath: string): { isFile: boolean } {
// implement this
},
// lstat/readLink are used as a fallback on Windows when stat throws
// with EACCES, to resolve Windows Store app execution aliases (and
// user-created symlinks pointing at them)
async lstat(
filePath: string,
): Promise<{ isFile: boolean; isSymlink: boolean }> {
// implement this
},
lstatSync(filePath: string): { isFile: boolean; isSymlink: boolean } {
// implement this
},
async readLink(filePath: string): Promise<string> {
// implement this
},
readLinkSync(filePath: string): string {
// implement this
},
env(key: string): string | undefined {
// implement getting an environment variable
},
// optional method for requesting broader permissions for a folder
requestPermission(folderPath: string): void {
Deno.permissions.requestSync({
name: "read",
path: folderPath,
});
},
});