Projekt

Obecné

Profil

Stáhnout (2.83 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
# 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
5
Recently 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
18
This 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
```
21
rm -rf ./node_modules/.cache
22
```
23
24
If 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
37
const findCacheDir = require('find-cache-dir');
38
39
findCacheDir({name: 'unicorns'});
40
//=> '/user/path/node-modules/.cache/unicorns'
41
```
42
43
44
## API
45
46
### findCacheDir([options])
47
48
Finds 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>
55
Type: `string`
56
57
Should be the same as your project name in `package.json`.
58
59
##### files
60
61
Type: `Array` `string
62
63
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.
64
65
##### cwd
66
67
Type: `string`<br>
68
Default `process.cwd()`
69
70
Directory to start searching for a `package.json` from.
71
72
##### create
73
74
Type: `boolean`<br>
75
Default `false`
76
77
If `true`, the directory will be created synchronously before returning.
78
79
##### thunk
80
81
Type: `boolean`<br>
82
Default `false`
83
84
If `true`, this modifies the return type to be a function that is a thunk for `path.join(theFoundCacheDirectory)`.
85
86
```js
87
const thunk = findCacheDir({name: 'foo', thunk: true});
88
89
thunk();
90
//=> '/some/path/node_modules/.cache/foo'
91
92
thunk('bar.js')
93
//=> '/some/path/node_modules/.cache/foo/bar.js'
94
95
thunk('baz', 'quz.js')
96
//=> '/some/path/node_modules/.cache/foo/baz/quz.js'
97
```
98
99
This 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
113
MIT © [James Talmage](https://github.com/jamestalmage)