Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 22, 2020
1 parent 71faea2 commit 0bc30bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
22 changes: 11 additions & 11 deletions index.js
Expand Up @@ -5,8 +5,6 @@ const commonDir = require('commondir');
const pkgDir = require('pkg-dir');
const makeDir = require('make-dir');

const {env} = process;

const isWritable = path => {
try {
fs.accessSync(path, fs.constants.W_OK);
Expand Down Expand Up @@ -42,24 +40,26 @@ function getNodeModuleDirectory(directory) {
}

module.exports = (options = {}) => {
if (env.CACHE_DIR) {
return useDirectory(path.join(env.CACHE_DIR, 'find-cache-dir'), options);
if (process.env.CACHE_DIR) {
return useDirectory(path.join(process.env.CACHE_DIR, 'find-cache-dir'), options);
}

let directory = options.cwd || process.cwd();
let {cwd: directory = process.cwd()} = options;

if (options.files) {
directory = commonDir(directory, options.files);
}

directory = pkgDir.sync(directory);

if (directory) {
const nodeModules = getNodeModuleDirectory(directory);
if (!nodeModules) {
return undefined;
}
if (!directory) {
return;
}

return useDirectory(path.join(directory, 'node_modules', '.cache', options.name), options);
const nodeModules = getNodeModuleDirectory(directory);
if (!nodeModules) {
return undefined;
}

return useDirectory(path.join(directory, 'node_modules', '.cache', options.name), options);
};
2 changes: 1 addition & 1 deletion license
@@ -1,6 +1,6 @@
MIT License

Copyright (c) James Talmage <james@talmage.io> (github.com/jamestalmage)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -24,14 +24,14 @@
],
"dependencies": {
"commondir": "^1.0.1",
"make-dir": "^3.0.0",
"make-dir": "^3.0.2",
"pkg-dir": "^4.1.0"
},
"devDependencies": {
"ava": "^2.4.0",
"coveralls": "^3.0.9",
"del": "^4.0.0",
"nyc": "^14.1.1",
"nyc": "^15.0.0",
"tempy": "^0.4.0",
"xo": "^0.25.3"
},
Expand Down
10 changes: 4 additions & 6 deletions readme.md
Expand Up @@ -38,12 +38,6 @@ findCacheDir({name: 'unicorns'});
//=> '/user/path/node-modules/.cache/unicorns'
```


## Tips

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


## API

### findCacheDir(options?)
Expand Down Expand Up @@ -103,6 +97,10 @@ thunk('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

- [`AVA`](https://ava.li)
Expand Down

0 comments on commit 0bc30bd

Please sign in to comment.