This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+33
View File
@@ -0,0 +1,33 @@
'use strict';
var path = require('path');
var commonDir = require('commondir');
var pkgDir = require('pkg-dir');
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 {
dir = dir || process.cwd();
}
dir = pkgDir.sync(dir);
if (dir) {
dir = path.join(dir, 'node_modules', '.cache', name);
if (dir && options.create) {
mkdirp.sync(dir);
}
if (options.thunk) {
return function () {
return path.join.apply(path, [dir].concat(Array.prototype.slice.call(arguments)));
};
}
}
return dir;
};
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) James Talmage <james@talmage.io> (github.com/jamestalmage)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+101
View File
@@ -0,0 +1,101 @@
{
"_args": [
[
{
"raw": "find-cache-dir@^0.1.1",
"scope": null,
"escapedName": "find-cache-dir",
"name": "find-cache-dir",
"rawSpec": "^0.1.1",
"spec": ">=0.1.1 <0.2.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\babel-loader"
]
],
"_from": "find-cache-dir@>=0.1.1 <0.2.0",
"_id": "find-cache-dir@0.1.1",
"_inCache": true,
"_location": "/find-cache-dir",
"_nodeVersion": "5.2.0",
"_npmUser": {
"name": "jamestalmage",
"email": "james@talmage.io"
},
"_npmVersion": "3.5.2",
"_phantomChildren": {},
"_requested": {
"raw": "find-cache-dir@^0.1.1",
"scope": null,
"escapedName": "find-cache-dir",
"name": "find-cache-dir",
"rawSpec": "^0.1.1",
"spec": ">=0.1.1 <0.2.0",
"type": "range"
},
"_requiredBy": [
"/babel-loader"
],
"_resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-0.1.1.tgz",
"_shasum": "c8defae57c8a52a8a784f9e31c57c742e993a0b9",
"_shrinkwrap": null,
"_spec": "find-cache-dir@^0.1.1",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\babel-loader",
"author": {
"name": "James Talmage",
"email": "james@talmage.io",
"url": "github.com/jamestalmage"
},
"bugs": {
"url": "https://github.com/jamestalmage/find-cache-dir/issues"
},
"dependencies": {
"commondir": "^1.0.1",
"mkdirp": "^0.5.1",
"pkg-dir": "^1.0.0"
},
"description": "My well-made module",
"devDependencies": {
"ava": "^0.8.0",
"coveralls": "^2.11.6",
"nyc": "^5.0.1",
"rimraf": "^2.5.0",
"xo": "^0.12.1"
},
"directories": {},
"dist": {
"shasum": "c8defae57c8a52a8a784f9e31c57c742e993a0b9",
"tarball": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-0.1.1.tgz"
},
"engines": {
"node": ">=0.10.0"
},
"files": [
"index.js"
],
"gitHead": "722fff2aa8fbf666d37192917d2e1fb0e1287489",
"homepage": "https://github.com/jamestalmage/find-cache-dir#readme",
"keywords": [
"cache",
"directory",
"dir"
],
"license": "MIT",
"maintainers": [
{
"name": "jamestalmage",
"email": "james@talmage.io"
}
],
"name": "find-cache-dir",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/jamestalmage/find-cache-dir.git"
},
"scripts": {
"test": "xo && nyc --reporter=lcov --reporter=text ava"
},
"version": "0.1.1"
}
+108
View File
@@ -0,0 +1,108 @@
# 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)
> 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:
```sh
# nyc
./node_modules/.cache/nyc
# ava
./node_modules/.cache/ava
# your-module
./node_modules/.cache/your-module
```
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.
## Install
```
$ npm install --save find-cache-dir
```
## Usage
```js
const findCacheDir = require('find-cache-dir');
findCacheDir({name: '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.
#### options
##### name
*Required*
Type: `string`
This should be the same as your project name in `package.json`.
##### files
Type: `array` of `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`
Default `process.cwd()`
The directory to start searching for a `package.json` from.
##### create
Type: `boolean`
Default `false`
If `true`, the directory will be created synchronously before returning.
##### thunk
Type: `boolean`
Default `false`
If `true`, this modifies the return type to be a function that is a thunk for `path.join(theFoundCacheDirectory)`.
```js
const thunk = findCacheDir({name: 'foo', thunk: true});
thunk();
//=> /some/path/node_modules/.cache/foo
thunk('bar.js')
//=> /some/path/node_modules/.cache/foo/bar.js
thunk('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)
## License
MIT © [James Talmage](http://github.com/jamestalmage)