index.d.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export type Options = {
  2. /**
  3. Should be the same as your project name in `package.json`.
  4. */
  5. readonly name: string;
  6. /**
  7. 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.
  8. */
  9. readonly files?: string[];
  10. /**
  11. The directory to start searching for a `package.json` from.
  12. @default process.cwd()
  13. */
  14. readonly cwd?: string;
  15. /**
  16. Create the directory synchronously before returning.
  17. @default false
  18. */
  19. readonly create?: boolean;
  20. };
  21. /**
  22. Finds the cache directory using the given options.
  23. The 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.
  24. @example
  25. ```
  26. import findCacheDirectory from 'find-cache-dir';
  27. findCacheDirectory({name: 'unicorns'});
  28. //=> '/user/path/node-modules/.cache/unicorns'
  29. ```
  30. */
  31. export default function findCacheDirectory(options: Options): string | undefined;