find_cwd.js 454 B

123456789101112131415161718
  1. const path = require('path');
  2. module.exports = function (opts) {
  3. if (!opts) {
  4. opts = {};
  5. }
  6. var cwd = opts.cwd;
  7. var configPath = opts.configPath;
  8. // if a path to the desired config was specified
  9. // but no cwd was provided, use configPath dir
  10. if (typeof configPath === 'string' && !cwd) {
  11. cwd = path.dirname(path.resolve(configPath));
  12. }
  13. if (typeof cwd === 'string') {
  14. return path.resolve(cwd);
  15. }
  16. return process.cwd();
  17. };