UNPKG

dax

Version:

Cross platform shell tools inspired by zx.

81 lines 3.36 kB
export interface Environment { /** Gets an environment variable. */ env(key: string): string | undefined; /** Resolves the file info for the specified path following symlinks. */ stat(filePath: string): Promise<{ isFile: boolean; }>; /** Synchronously resolves the file info for the specified path * following symlinks. */ statSync(filePath: string): { isFile: boolean; }; /** Resolves the file info for the specified path without following symlinks. * * On Windows, the library falls back to this when {@link Environment.stat} * throws with EACCES — needed to resolve Windows Store app execution aliases, * whose reparse points cause stat to fail with EACCES but lstat to succeed. * If the entry is itself a symlink, the library walks the chain via * {@link Environment.readLink} until it reaches a file (handles the case of * a user-created symlink pointing at a Store app alias). */ lstat(filePath: string): Promise<{ isFile: boolean; isSymlink: boolean; }>; /** Synchronous variant of {@link Environment.lstat}. */ lstatSync(filePath: string): { isFile: boolean; isSymlink: boolean; }; /** Reads the literal target of a symlink. Used to walk symlink chains * when stat can't traverse them. */ readLink(filePath: string): Promise<string>; /** Synchronous variant of {@link Environment.readLink}. */ readLinkSync(filePath: string): string; /** Whether the current operating system is Windows. */ isWindows: boolean; /** Optional method for requesting broader permissions for a folder * instead of asking for each file when the operating system requires * probing multiple files for an executable path. * * This is not the default, but is useful on Windows for example. */ requestPermission?(folderPath: string): void; } /** Default implementation that interacts with the file system and process env vars. */ export declare class RealEnvironment implements Environment { env(key: string): string | undefined; stat(path: string): Promise<{ isFile: boolean; }>; statSync(path: string): { isFile: boolean; }; lstat(path: string): Promise<{ isFile: boolean; isSymlink: boolean; }>; lstatSync(path: string): { isFile: boolean; isSymlink: boolean; }; readLink(path: string): Promise<string>; readLinkSync(path: string): string; get isWindows(): boolean; } /** Finds the path to the specified command asynchronously. * * When the command contains a path separator (e.g. `./foo` or `/usr/bin/foo`), * PATH is not searched. The file is resolved relative to the caller's context * and, on Windows, PATHEXT extensions are tried if the literal path doesn't * exist (so `./foo` resolves to `./foo.exe`). */ export declare function which(command: string, environment?: Omit<Environment, "statSync" | "lstatSync" | "readLinkSync">): Promise<string | undefined>; /** Finds the path to the specified command synchronously. * * See {@link which} for the path-separator handling rules. */ export declare function whichSync(command: string, environment?: Omit<Environment, "stat" | "lstat" | "readLink">): string | undefined; //# sourceMappingURL=mod.d.ts.map