Skip to content

Commit

Permalink
meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 19, 2016
1 parent ca53c90 commit 19c1cf9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 33 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ insert_final_newline = true
[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: node_js
node_js:
- 'stable'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var mkdirp = require('mkdirp');
module.exports = function (options) {
var name = options.name;
var dir = options.cwd;

if (options.files) {
dir = commonDir(dir, options.files);
} else {
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.1",
"description": "My well-made module",
"license": "MIT",
"repository": "jamestalmage/find-cache-dir",
"repository": "avajs/find-cache-dir",
"author": {
"name": "James Talmage",
"email": "[email protected]",
Expand All @@ -21,7 +21,10 @@
"keywords": [
"cache",
"directory",
"dir"
"dir",
"caching",
"find",
"search"
],
"dependencies": {
"commondir": "^1.0.1",
Expand All @@ -33,6 +36,6 @@
"coveralls": "^2.11.6",
"nyc": "^6.2.1",
"rimraf": "^2.5.0",
"xo": "^0.13.0"
"xo": "^0.15.1"
}
}
44 changes: 23 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# find-cache-dir [![Build Status](https://travis-ci.org/jamestalmage/find-cache-dir.svg?branch=master)](https://travis-ci.org/jamestalmage/find-cache-dir) [![Coverage Status](https://coveralls.io/repos/jamestalmage/find-cache-dir/badge.svg?branch=master&service=github)](https://coveralls.io/github/jamestalmage/find-cache-dir?branch=master)
# 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)

> Finds the common standard cache directory.
> Finds the common standard cache directory
Recently the [`nyc`](https://www.npmjs.com/package/nyc) and [`AVA`](https://www.npmjs.com/package/ava) projects decided to standardize on a common directory structure for storing cache information:
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:

```sh
# nyc
Expand All @@ -16,12 +16,12 @@ Recently the [`nyc`](https://www.npmjs.com/package/nyc) and [`AVA`](https://www.
```

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:

```
rm -rf ./node_modules/.cache
```

If you decide to adopt this pattern, please file a PR adding your name to the list of adopters below.
If you decide to adopt this pattern, please file a PR adding your name to the list of adopters below.


## Install
Expand All @@ -37,48 +37,48 @@ $ npm install --save find-cache-dir
const findCacheDir = require('find-cache-dir');

findCacheDir({name: 'unicorns'});
//=> /user/path/node-modules/.cache/unicorns
//=> '/user/path/node-modules/.cache/unicorns'
```


## API

### findCacheDir([options])

Finds the cache dir 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.
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.

#### options

##### name

*Required*
Type: `string`
*Required*<br>
Type: `string`

This should be the same as your project name in `package.json`.
Should be the same as your project name in `package.json`.

##### files

Type: `array` of `string`
Type: `Array` `string

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.

##### cwd

Type: `string`
Type: `string`<br>
Default `process.cwd()`

The directory to start searching for a `package.json` from.
Directory to start searching for a `package.json` from.

##### create

Type: `boolean`
Type: `boolean`<br>
Default `false`

If `true`, the directory will be created synchronously before returning.

##### thunk

Type: `boolean`
Type: `boolean`<br>
Default `false`

If `true`, this modifies the return type to be a function that is a thunk for `path.join(theFoundCacheDirectory)`.
Expand All @@ -87,22 +87,24 @@ If `true`, this modifies the return type to be a function that is a thunk for `p
const thunk = findCacheDir({name: 'foo', thunk: true});

thunk();
//=> /some/path/node_modules/.cache/foo
//=> '/some/path/node_modules/.cache/foo'

thunk('bar.js')
//=> /some/path/node_modules/.cache/foo/bar.js
//=> '/some/path/node_modules/.cache/foo/bar.js'

thunk('baz', 'quz.js')
//=> /some/path/node_modules/.cache/foo/baz/quz.js
//=> '/some/path/node_modules/.cache/foo/baz/quz.js'
```

This is helpful for actually putting actual files in the cache!


## Adopters

- [`NYC`](https://www.npmjs.com/package/nyc)
- [`AVA`](https://www.npmjs.com/package/ava)
- [`nyc`](https://github.com/bcoe/nyc)
- [`AVA`](https://ava.li)


## License

MIT © [James Talmage](http://github.com/jamestalmage)
MIT © [James Talmage](https://github.com/jamestalmage)
8 changes: 3 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import _test from 'ava';
import fn from './';
import fs from 'fs';
import path from 'path';
import rimraf from 'rimraf';
import fs from 'fs';

const test = _test.serial;
import {serial as test} from 'ava';
import fn from './';

test('finds from a list of files', t => {
process.chdir(path.join(__dirname, '..'));
Expand Down

0 comments on commit 19c1cf9

Please sign in to comment.