index.js 693 B

123456789101112131415161718192021222324252627282930313233
  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. };