source: imaps-frontend/node_modules/find-cache-dir/readme.md

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.8 KB
Line 
1# find-cache-dir
2
3> Finds the common standard cache directory
4
5The [`nyc`](https://github.com/istanbuljs/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
24## Install
25
26```sh
27npm install find-cache-dir
28```
29
30## Usage
31
32```js
33import findCacheDirectory from 'find-cache-dir';
34
35findCacheDirectory({name: 'unicorns'});
36//=> '/user/path/node-modules/.cache/unicorns'
37```
38
39## API
40
41### findCacheDirectory(options?)
42
43Finds the cache directory using the supplied options. 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.
44
45#### options
46
47Type: `object`
48
49##### name
50
51*Required*\
52Type: `string`
53
54Should be the same as your project name in `package.json`.
55
56##### files
57
58Type: `string[] | string`
59
60An 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.
61
62##### cwd
63
64Type: `string`\
65Default `process.cwd()`
66
67Directory to start searching for a `package.json` from.
68
69##### create
70
71Type: `boolean`\
72Default `false`
73
74If `true`, the directory will be created synchronously before returning.
75
76##### thunk
77
78Type: `boolean`\
79Default `false`
80
81If `true`, this modifies the return type to be a function that is a thunk for `path.join(theFoundCacheDirectory)`.
82
83```js
84const thunk = findCacheDir({name: 'foo', thunk: true});
85
86thunk();
87//=> '/some/path/node_modules/.cache/foo'
88
89thunk('bar.js')
90//=> '/some/path/node_modules/.cache/foo/bar.js'
91
92thunk('baz', 'quz.js')
93//=> '/some/path/node_modules/.cache/foo/baz/quz.js'
94```
95
96This is helpful for actually putting actual files in the cache!
97
98## Tips
99
100- To test modules using `find-cache-dir`, set the `CACHE_DIR` environment variable to temporarily override the directory that is resolved.
101
102## Adopters
103
104- [`ava`](https://avajs.dev)
105- [`nyc`](https://github.com/istanbuljs/nyc)
106- [`storybook`](https://github.com/storybookjs/storybook)
107- [`babel-loader`](https://github.com/babel/babel-loader)
108- [`eslint-loader`](https://github.com/MoOx/eslint-loader)
109- [More…](https://www.npmjs.com/browse/depended/find-cache-dir)
Note: See TracBrowser for help on using the repository browser.