You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 693B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const path = require('path');
  3. const commonDir = require('commondir');
  4. const pkgDir = require('pkg-dir');
  5. const makeDir = require('make-dir');
  6. module.exports = (options = {}) => {
  7. const {name} = options;
  8. let directory = options.cwd;
  9. if (options.files) {
  10. directory = commonDir(directory, options.files);
  11. } else {
  12. directory = directory || process.cwd();
  13. }
  14. directory = pkgDir.sync(directory);
  15. if (directory) {
  16. directory = path.join(directory, 'node_modules', '.cache', name);
  17. if (directory && options.create) {
  18. makeDir.sync(directory);
  19. }
  20. if (options.thunk) {
  21. return (...arguments_) => path.join(directory, ...arguments_);
  22. }
  23. }
  24. return directory;
  25. };