pax_global_header00006660000000000000000000000064135744276340014531gustar00rootroot0000000000000052 comment=c432cb44d605a22f01c9768d5ca97c5d49ae2156 find-cache-dir-3.2.0/000077500000000000000000000000001357442763400142705ustar00rootroot00000000000000find-cache-dir-3.2.0/.editorconfig000066400000000000000000000002571357442763400167510ustar00rootroot00000000000000root = 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-3.2.0/.gitattributes000066400000000000000000000000231357442763400171560ustar00rootroot00000000000000* text=auto eol=lf find-cache-dir-3.2.0/.github/000077500000000000000000000000001357442763400156305ustar00rootroot00000000000000find-cache-dir-3.2.0/.github/funding.yml000066400000000000000000000000621357442763400200030ustar00rootroot00000000000000github: sindresorhus tidelift: npm/find-cache-dir find-cache-dir-3.2.0/.github/security.md000066400000000000000000000002631357442763400200220ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. find-cache-dir-3.2.0/.gitignore000066400000000000000000000000541357442763400162570ustar00rootroot00000000000000node_modules yarn.lock .nyc_output coverage find-cache-dir-3.2.0/.npmrc000066400000000000000000000000231357442763400154030ustar00rootroot00000000000000package-lock=false find-cache-dir-3.2.0/.travis.yml000066400000000000000000000002021357442763400163730ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' after_script: - 'cat ./coverage/lcov.info | ./node_modules/.bin/coveralls' find-cache-dir-3.2.0/index.js000066400000000000000000000020311357442763400157310ustar00rootroot00000000000000'use strict'; const path = require('path'); const fs = require('fs'); const commonDir = require('commondir'); const pkgDir = require('pkg-dir'); const makeDir = require('make-dir'); const isWritable = path => { try { fs.accessSync(path, fs.constants.W_OK); return true; } catch (_) { return false; } }; module.exports = (options = {}) => { const {name} = options; let directory = options.cwd; if (options.files) { directory = commonDir(directory, options.files); } else { directory = directory || process.cwd(); } directory = pkgDir.sync(directory); if (directory) { const nodeModules = path.join(directory, 'node_modules'); if ( !isWritable(nodeModules) && (fs.existsSync(nodeModules) || !isWritable(path.join(directory))) ) { return undefined; } directory = path.join(directory, 'node_modules', '.cache', name); if (directory && options.create) { makeDir.sync(directory); } if (options.thunk) { return (...arguments_) => path.join(directory, ...arguments_); } } return directory; }; find-cache-dir-3.2.0/license000066400000000000000000000021261357442763400156360ustar00rootroot00000000000000MIT License 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-3.2.0/package.json000066400000000000000000000013021357442763400165520ustar00rootroot00000000000000{ "name": "find-cache-dir", "version": "3.2.0", "description": "Finds the common standard cache directory", "license": "MIT", "repository": "avajs/find-cache-dir", "funding": "https://github.com/avajs/find-cache-dir?sponsor=1", "engines": { "node": ">=8" }, "scripts": { "test": "xo && nyc ava" }, "files": [ "index.js" ], "keywords": [ "cache", "directory", "dir", "caching", "find", "search" ], "dependencies": { "commondir": "^1.0.1", "make-dir": "^3.0.0", "pkg-dir": "^4.1.0" }, "devDependencies": { "ava": "^2.4.0", "coveralls": "^3.0.9", "del": "^4.0.0", "nyc": "^14.1.1", "xo": "^0.25.3" }, "nyc": { "reporter": [ "lcov", "text" ] } } find-cache-dir-3.2.0/readme.md000066400000000000000000000065631357442763400160610ustar00rootroot00000000000000# 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 The [`nyc`](https://github.com/istanbuljs/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 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 `undefined` if `package.json` was never found or if the `node_modules` directory is unwritable. #### options Type: `object` ##### name *Required*\ Type: `string` Should be the same as your project name in `package.json`. ##### files Type: `string[] | 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/istanbuljs/nyc) - [`Storybook`](https://storybook.js.org) - [`babel-loader`](https://github.com/babel/babel-loader) - [`eslint-loader`](https://github.com/MoOx/eslint-loader) - [`Phenomic`](https://phenomic.io) - [`javascripthon-loader`](https://github.com/Beg-in/javascripthon-loader) ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
find-cache-dir-3.2.0/test.js000066400000000000000000000026711357442763400156130ustar00rootroot00000000000000import fs from 'fs'; import path from 'path'; import {serial as test} from 'ava'; import del from 'del'; import findCacheDir 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(findCacheDir({files, name: 'blah'}), path.join(__dirname, 'node_modules', '.cache', 'blah')); }); test('finds from process.cwd', t => { process.chdir(path.join(__dirname)); t.is(findCacheDir({name: 'foo'}), path.join(__dirname, 'node_modules', '.cache', 'foo')); }); test('finds from options.cwd', t => { process.chdir(path.join(__dirname, '..')); t.is(findCacheDir({cwd: __dirname, name: 'bar'}), path.join(__dirname, 'node_modules', '.cache', 'bar')); }); test('creates dir', t => { const directory = path.join(__dirname, 'node_modules', '.cache', 'created'); del.sync(directory); findCacheDir({create: true, name: 'created', cwd: __dirname}); t.true(fs.existsSync(directory)); }); test('thunk', t => { const directory = path.join(__dirname, 'node_modules', '.cache', 'thunked'); del.sync(directory); const thunk = findCacheDir({thunk: true, name: 'thunked', cwd: __dirname}); t.is(thunk('foo'), path.join(directory, 'foo')); t.is(thunk('bar'), path.join(directory, 'bar')); }); test('returns undefined if it can\'t find package.json', t => { process.chdir(path.join(__dirname, '..')); t.is(findCacheDir({name: 'foo'}), undefined); });