pax_global_header00006660000000000000000000000064131053432400014505gustar00rootroot0000000000000052 comment=39c04031f56206e21590e330b483402235ec91b5 find-cache-dir-1.0.0/000077500000000000000000000000001310534324000142405ustar00rootroot00000000000000find-cache-dir-1.0.0/.editorconfig000066400000000000000000000002571310534324000167210ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 find-cache-dir-1.0.0/.gitattributes000066400000000000000000000000351310534324000171310ustar00rootroot00000000000000* text=auto *.js text eol=lf find-cache-dir-1.0.0/.gitignore000066400000000000000000000000421310534324000162240ustar00rootroot00000000000000node_modules .nyc_output coverage find-cache-dir-1.0.0/.travis.yml000066400000000000000000000001701310534324000163470ustar00rootroot00000000000000language: node_js node_js: - '6' - '4' after_script: - 'cat ./coverage/lcov.info | ./node_modules/.bin/coveralls' find-cache-dir-1.0.0/index.js000066400000000000000000000012261310534324000157060ustar00rootroot00000000000000'use strict'; const path = require('path'); const commonDir = require('commondir'); const pkgDir = require('pkg-dir'); const makeDir = require('make-dir'); module.exports = options => { const name = options.name; let 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) { makeDir.sync(dir); } if (options.thunk) { return function () { return path.join.apply(path, [dir].concat(Array.prototype.slice.call(arguments))); }; } } return dir; }; find-cache-dir-1.0.0/license000066400000000000000000000021401310534324000156020ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) James Talmage (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. find-cache-dir-1.0.0/package.json000066400000000000000000000014421310534324000165270ustar00rootroot00000000000000{ "name": "find-cache-dir", "version": "1.0.0", "description": "My well-made module", "license": "MIT", "repository": "avajs/find-cache-dir", "author": { "name": "James Talmage", "email": "james@talmage.io", "url": "github.com/jamestalmage" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && nyc ava" }, "files": [ "index.js" ], "keywords": [ "cache", "directory", "dir", "caching", "find", "search" ], "dependencies": { "commondir": "^1.0.1", "make-dir": "^1.0.0", "pkg-dir": "^2.0.0" }, "devDependencies": { "ava": "^0.19.1", "coveralls": "^2.11.6", "del": "^2.2.2", "nyc": "^10.3.2", "xo": "^0.18.2" }, "nyc": { "reporter": [ "lcov", "text" ] } } find-cache-dir-1.0.0/readme.md000066400000000000000000000055211310534324000160220ustar00rootroot00000000000000# 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 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 ./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 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` Should be the same as your project name in `package.json`. ##### files 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`
Default `process.cwd()` 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 - [`AVA`](https://ava.li) - [`nyc`](https://github.com/bcoe/nyc) - [`babel-loader`](https://github.com/babel/babel-loader) - [`eslint-loader`](https://github.com/MoOx/eslint-loader) - [`Phenomic`](https://phenomic.io) ## License MIT © [James Talmage](https://github.com/jamestalmage) find-cache-dir-1.0.0/test.js000066400000000000000000000025041310534324000155560ustar00rootroot00000000000000import fs from 'fs'; import path from 'path'; import del from 'del'; import {serial as test} from 'ava'; import fn from '.'; test('finds from a list of files', t => { process.chdir(path.join(__dirname, '..')); const files = ['foo/bar', 'baz/quz'].map(file => path.join(__dirname, file)); t.is(fn({files, name: 'blah'}), path.join(__dirname, 'node_modules', '.cache', 'blah')); }); test('finds from process.cwd', t => { process.chdir(path.join(__dirname)); t.is(fn({name: 'foo'}), path.join(__dirname, 'node_modules', '.cache', 'foo')); }); test('finds from options.cwd', t => { process.chdir(path.join(__dirname, '..')); t.is(fn({cwd: __dirname, name: 'bar'}), path.join(__dirname, 'node_modules', '.cache', 'bar')); }); test('creates dir', t => { const dir = path.join(__dirname, 'node_modules', '.cache', 'created'); del.sync(dir); fn({create: true, name: 'created', cwd: __dirname}); t.true(fs.existsSync(dir)); }); test.only('thunk', t => { const dir = path.join(__dirname, 'node_modules', '.cache', 'thunked'); del.sync(dir); const thunk = fn({thunk: true, name: 'thunked', cwd: __dirname}); t.is(thunk('foo'), path.join(dir, 'foo')); t.is(thunk('bar'), path.join(dir, 'bar')); }); test('returns null if it can\'t find package.json', t => { process.chdir(path.join(__dirname, '..')); t.is(fn({name: 'foo'}), null); });