1# find-cache-dir [![Build Status](https://travis-ci.org/avajs/find-cache-dir.svg?branch=master)](https://travis-ci.org/avajs/find-cache-dir) [![Coverage Status](https://coveralls.io/repos/github/avajs/find-cache-dir/badge.svg?branch=master)](https://coveralls.io/github/avajs/find-cache-dir?branch=master) 2 3> Finds the common standard cache directory 4 5Recently the [`nyc`](https://github.com/bcoe/nyc) and [`AVA`](https://ava.li) projects decided to standardize on a common directory structure for storing cache information: 6 7```sh 8# nyc 9./node_modules/.cache/nyc 10 11# ava 12./node_modules/.cache/ava 13 14# your-module 15./node_modules/.cache/your-module 16``` 17 18This module makes it easy to correctly locate the cache directory according to this shared spec. If this pattern becomes ubiquitous, clearing the cache for multiple dependencies becomes easy and consistent: 19 20``` 21rm -rf ./node_modules/.cache 22``` 23 24If you decide to adopt this pattern, please file a PR adding your name to the list of adopters below. 25 26 27## Install 28 29``` 30$ npm install --save find-cache-dir 31``` 32 33 34## Usage 35 36```js 37const findCacheDir = require('find-cache-dir'); 38 39findCacheDir({name: 'unicorns'}); 40//=> '/user/path/node-modules/.cache/unicorns' 41``` 42 43 44## API 45 46### findCacheDir([options]) 47 48Finds the cache directory using the supplied options. The algorithm 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 `null` if `package.json` was never found. 49 50#### options 51 52##### name 53 54*Required*<br> 55Type: `string` 56 57Should be the same as your project name in `package.json`. 58 59##### files 60 61Type: `Array` `string 62 63An 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. 64 65##### cwd 66 67Type: `string`<br> 68Default `process.cwd()` 69 70Directory to start searching for a `package.json` from. 71 72##### create 73 74Type: `boolean`<br> 75Default `false` 76 77If `true`, the directory will be created synchronously before returning. 78 79##### thunk 80 81Type: `boolean`<br> 82Default `false` 83 84If `true`, this modifies the return type to be a function that is a thunk for `path.join(theFoundCacheDirectory)`. 85 86```js 87const thunk = findCacheDir({name: 'foo', thunk: true}); 88 89thunk(); 90//=> '/some/path/node_modules/.cache/foo' 91 92thunk('bar.js') 93//=> '/some/path/node_modules/.cache/foo/bar.js' 94 95thunk('baz', 'quz.js') 96//=> '/some/path/node_modules/.cache/foo/baz/quz.js' 97``` 98 99This is helpful for actually putting actual files in the cache! 100 101 102## Adopters 103 104- [`AVA`](https://ava.li) 105- [`nyc`](https://github.com/bcoe/nyc) 106- [`babel-loader`](https://github.com/babel/babel-loader) 107- [`eslint-loader`](https://github.com/MoOx/eslint-loader) 108- [`Phenomic`](https://phenomic.io) 109 110 111## License 112 113MIT © [James Talmage](https://github.com/jamestalmage) 114