31839db08dece3737cd06ac3a999130cbf54c79642973904ad53fbb993d4823313e5672dc8c21fa505819fc441c87962ddfe19f252dd3fbe53f007d8c04391 512 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. const path = require('path');
  3. const pathExists = require('path-exists');
  4. const pLocate = require('p-locate');
  5. module.exports = (iterable, opts) => {
  6. opts = Object.assign({
  7. cwd: process.cwd()
  8. }, opts);
  9. return pLocate(iterable, el => pathExists(path.resolve(opts.cwd, el)), opts);
  10. };
  11. module.exports.sync = (iterable, opts) => {
  12. opts = Object.assign({
  13. cwd: process.cwd()
  14. }, opts);
  15. for (const el of iterable) {
  16. if (pathExists.sync(path.resolve(opts.cwd, el))) {
  17. return el;
  18. }
  19. }
  20. };