find-cache-dir

中文文档
6.0.0发布于 2025/04/08MITTypeScriptES Module近 30 天下载 1.7亿

Finds the common standard cache directory

此软件包已被标记为弃用

Renamed to `find-cache-directory`.

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. API
  4. findCacheDirectory(options?)
  5. Tips
  6. Adopters

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

版本与发布记录

find-cache-dir 共发布 14 个版本,首次发布于 2015/12/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.0latest2025/04/081.6 年前
5.0.02023/08/193 年前
4.0.02022/11/044 年前
3.3.22021/08/305 年前
3.3.12020/03/096 年前
3.3.02020/02/226 年前

关于 find-cache-dir 的常见问题

find-cache-dir 是什么?

Finds the common standard cache directory注意:该包已被作者标记为弃用——Renamed to `find-cache-directory`.

如何安装 find-cache-dir?

在项目目录运行 npm install find-cache-dir,或使用 pnpm add / yarn add / bun add。

find-cache-dir 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

find-cache-dir 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

find-cache-dir 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

find-cache-dir 可以商用吗?

find-cache-dir 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

find-cache-dir 的下载量有多少?

根据 npm 官方下载统计,find-cache-dir 在 2026/10/05 – 2026/11/03 这 30 天内被下载 167,306,115 次,日均约 5,576,871 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

find-cache-dir 还在维护吗?

最新版本 6.0.0 发布于 2025/04/08(1.6 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2015/12/30。作者已将其标记为弃用,新项目建议寻找替代方案。