find-cache-dir

WebJar for find-cache-dir

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

find-cache-dir
Last Version

Last Version

2.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

find-cache-dir
WebJar for find-cache-dir
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/avajs/find-cache-dir

Download find-cache-dir

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/find-cache-dir/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>find-cache-dir</artifactId>
    <version>2.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/find-cache-dir/
implementation 'org.webjars.npm:find-cache-dir:2.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/find-cache-dir/
implementation ("org.webjars.npm:find-cache-dir:2.1.0")
'org.webjars.npm:find-cache-dir:jar:2.1.0'
<dependency org="org.webjars.npm" name="find-cache-dir" rev="2.1.0">
  <artifact name="find-cache-dir" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='find-cache-dir', version='2.1.0')
)
libraryDependencies += "org.webjars.npm" % "find-cache-dir" % "2.1.0"
[org.webjars.npm/find-cache-dir "2.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.npm : commondir jar [1.0.1,2)
org.webjars.npm : make-dir jar [2.0.0,3)
org.webjars.npm : pkg-dir jar [3.0.0,4)

Project Modules

There are no modules declared in this project.

find-cache-dir Build Status Coverage Status

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

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

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 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[] | 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).

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!

Tips

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

Adopters


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.
org.webjars.npm

AVA

Node.js test runner that lets you develop with confidence 🚀

Versions

Version
2.1.0
1.0.0