UNPKG

@skarab/detect-package-manager

Version:

Detects which package manager (bun, pnpm, yarn, npm) is used based on the current working directory.

25 lines (24 loc) 1.32 kB
export declare type OnDirectory<ReturnType> = (directory: string) => ReturnType; /** * Executes a callback function with the current directory path as first argument. If the callback function returns a value other than `undefined` then the search is stopped and the value is returned. Otherwise it starts again with the parent directory. * * @example * ``` * // Find the nearest package.json from current working directory. * const packageJSON = walkDirectoryUp(directory => { * const path = resolve(directory, 'package.json'); * return existsSync(path) ? path : undefined; * }); * ``` * * @param callback a callback function to be executed on each directory. * @param directory the directory where the search begins, default to current working directory. */ export declare function walkDirectoryUp<ReturnType>(callback: OnDirectory<Promise<ReturnType | undefined>>, directory?: string): Promise<ReturnType | undefined>; /** * Returns the absolute path to the first file found in the directory provided or `undefined`. * * @param fileName file name or array of file name to search. * @param directory the directory where the search begins, default to current working directory. */ export declare function findFile(fileName: string | readonly string[], directory?: string): Promise<string | undefined>;