find-cache-dir
Advanced tools
Comparing version 3.3.2 to 4.0.0
29
index.js
@@ -1,7 +0,6 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const commonDir = require('commondir'); | ||
const pkgDir = require('pkg-dir'); | ||
const makeDir = require('make-dir'); | ||
import process from 'node:process'; | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import commonPathPrefix from 'common-path-prefix'; | ||
import {packageDirectorySync} from 'pkg-dir'; | ||
@@ -14,3 +13,3 @@ const {env, cwd} = process; | ||
return true; | ||
} catch (_) { | ||
} catch { | ||
return false; | ||
@@ -22,3 +21,3 @@ } | ||
if (options.create) { | ||
makeDir.sync(directory); | ||
fs.mkdirSync(directory, {recursive: true}); | ||
} | ||
@@ -37,4 +36,4 @@ | ||
if ( | ||
!isWritable(nodeModules) && | ||
(fs.existsSync(nodeModules) || !isWritable(path.join(directory))) | ||
!isWritable(nodeModules) | ||
&& (fs.existsSync(nodeModules) || !isWritable(path.join(directory))) | ||
) { | ||
@@ -47,3 +46,3 @@ return; | ||
module.exports = (options = {}) => { | ||
export default function findCacheDirectory(options = {}) { | ||
if (env.CACHE_DIR && !['true', 'false', '1', '0'].includes(env.CACHE_DIR)) { | ||
@@ -56,6 +55,6 @@ return useDirectory(path.join(env.CACHE_DIR, options.name), options); | ||
if (options.files) { | ||
directory = commonDir(directory, options.files); | ||
directory = commonPathPrefix(options.files.map(file => path.resolve(directory, file))); | ||
} | ||
directory = pkgDir.sync(directory); | ||
directory = packageDirectorySync({cwd: directory}); | ||
@@ -68,6 +67,6 @@ if (!directory) { | ||
if (!nodeModules) { | ||
return undefined; | ||
return; | ||
} | ||
return useDirectory(path.join(directory, 'node_modules', '.cache', options.name), options); | ||
}; | ||
} |
{ | ||
"name": "find-cache-dir", | ||
"version": "3.3.2", | ||
"version": "4.0.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", | ||
"repository": "sindresorhus/find-cache-dir", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=14.16" | ||
}, | ||
"scripts": { | ||
"test": "xo && nyc ava" | ||
"test": "xo && ava" | ||
}, | ||
@@ -26,20 +33,14 @@ "files": [ | ||
"dependencies": { | ||
"commondir": "^1.0.1", | ||
"make-dir": "^3.0.2", | ||
"pkg-dir": "^4.1.0" | ||
"common-path-prefix": "^3.0.0", | ||
"pkg-dir": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"coveralls": "^3.0.9", | ||
"del": "^4.0.0", | ||
"nyc": "^15.0.0", | ||
"tempy": "^0.4.0", | ||
"xo": "^0.25.3" | ||
"ava": "^5.0.1", | ||
"del": "^7.0.0", | ||
"tempy": "^3.0.0", | ||
"xo": "^0.52.4" | ||
}, | ||
"nyc": { | ||
"reporter": [ | ||
"lcov", | ||
"text" | ||
] | ||
"ava": { | ||
"workerThreads": false | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# find-cache-dir [![Coverage Status](https://codecov.io/gh/avajs/find-cache-dir/branch/master/graph/badge.svg)](https://codecov.io/gh/avajs/find-cache-dir/branch/master) | ||
# find-cache-dir | ||
@@ -24,9 +24,7 @@ > Finds the common standard cache directory | ||
If you decide to adopt this pattern, please file a PR adding your name to the list of adopters below. | ||
## Install | ||
```sh | ||
npm install find-cache-dir | ||
``` | ||
$ npm install find-cache-dir | ||
``` | ||
@@ -36,5 +34,5 @@ ## Usage | ||
```js | ||
const findCacheDir = require('find-cache-dir'); | ||
import findCacheDirectory from 'find-cache-dir'; | ||
findCacheDir({name: 'unicorns'}); | ||
findCacheDirectory({name: 'unicorns'}); | ||
//=> '/user/path/node-modules/.cache/unicorns' | ||
@@ -45,3 +43,3 @@ ``` | ||
### findCacheDir(options?) | ||
### findCacheDirectory(options?) | ||
@@ -115,13 +113,1 @@ 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. | ||
- [More…](https://www.npmjs.com/browse/depended/find-cache-dir) | ||
--- | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-find_cache-dir?utm_source=npm-find-cache-dir&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
2
4
1
1
Yes
6358
51
110
+ Addedcommon-path-prefix@^3.0.0
+ Addedcommon-path-prefix@3.0.0(transitive)
+ Addedfind-up@6.3.0(transitive)
+ Addedlocate-path@7.2.0(transitive)
+ Addedp-limit@4.0.0(transitive)
+ Addedp-locate@6.0.0(transitive)
+ Addedpath-exists@5.0.0(transitive)
+ Addedpkg-dir@7.0.0(transitive)
+ Addedyocto-queue@1.1.1(transitive)
- Removedcommondir@^1.0.1
- Removedmake-dir@^3.0.2
- Removedcommondir@1.0.1(transitive)
- Removedfind-up@4.1.0(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpkg-dir@4.2.0(transitive)
- Removedsemver@6.3.1(transitive)
Updatedpkg-dir@^7.0.0