Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

find-cache-dir

Package Overview
Dependencies
2
Maintainers
1
Versions
12
Issues
File Explorer

Advanced tools

find-cache-dir

Finds the common standard cache directory

    4.0.0latest

Version published
Maintainers
1
Weekly downloads
36,017,027
increased by4.39%

Weekly downloads

Changelog

Source

Breaking

  • Require Node.js 14 c5e8e5c
  • This package is now pure ESM. Please read this.

Improvements

  • Upgrade dependencies
  • Reduce amount of dependencies

https://github.com/sindresorhus/find-cache-dir/compare/v3.3.2...v4.0.0

Readme

Source

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

Keywords

FAQs

What is find-cache-dir?

Finds the common standard cache directory

Is find-cache-dir popular?

The npm package find-cache-dir receives a total of 30,219,313 weekly downloads. As such, find-cache-dir popularity was classified as popular.

Is find-cache-dir well maintained?

We found that find-cache-dir demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 04 Nov 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc