UNPKG

1.28 kBTypeScriptView Raw
1export type Options = {
2 /**
3 Should be the same as your project name in `package.json`.
4 */
5 readonly name: string;
6
7 /**
8 An array of files that will be searched for a common parent directory. This common parent directory will be used in lieu of the `cwd` option below.
9 */
10 readonly files?: string[];
11
12 /**
13 The directory to start searching for a `package.json` from.
14
15 @default process.cwd()
16 */
17 readonly cwd?: string;
18
19 /**
20 Create the directory synchronously before returning.
21
22 @default false
23 */
24 readonly create?: boolean;
25};
26
27/**
28Finds the cache directory using the given options.
29
30The algorithm checks for the `CACHE_DIR` environmental variable and uses it if it is not set to `true`, `false`, `1` or `0`. If one is not found, it tries to find a `package.json` file, searching every parent directory of the `cwd` specified (or implied from other options). It returns a `string` containing the absolute path to the cache directory, or `undefined` if `package.json` was never found or if the `node_modules` directory is unwritable.
31
32@example
33```
34import findCacheDirectory from 'find-cache-dir';
35
36findCacheDirectory({name: 'unicorns'});
37//=> '/user/path/node-modules/.cache/unicorns'
38```
39*/
40export default function findCacheDirectory(options: Options): string | undefined;