find-cache-dir
Finds the common standard cache directory
Last updated 6 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install find-cache-dir 
SYNC missed versions from official npm registry.

find-cache-dir

Finds the common standard cache directory

The nyc and AVA projects decided to standardize on a common directory structure for storing cache information:

# 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

Install

npm install find-cache-dir

Usage

import findCacheDirectory from 'find-cache-dir';

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

API

findCacheDirectory(options?)

Finds the cache directory using the given 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.

options

Type: object

name

Required
Type: string

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

files

Type: 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

Create the directory synchronously before returning.

Tips

  • To test modules using find-cache-dir, set the CACHE_DIR environment variable to temporarily override the directory that is resolved.

Adopters

Current Tags

  • 5.0.0                                ...           latest (a year ago)

13 Versions

  • 5.0.0                                ...           a year ago
  • 4.0.0                                ...           2 years ago
  • 3.3.2                                ...           3 years ago
  • 3.3.1                                ...           5 years ago
  • 3.3.0                                ...           5 years ago
  • 3.2.0                                ...           5 years ago
  • 3.1.0                                ...           5 years ago
  • 3.0.0                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.0.0                                ...           8 years ago
  • 0.1.1                                ...           9 years ago
  • 0.1.0                                ...           9 years ago

Copyright 2013 - present © cnpmjs.org | Home |