2 const path = require('path');
3 const locatePath = require('locate-path');
5 module.exports = (filename, opts = {}) => {
6 const startDir = path.resolve(opts.cwd || '');
7 const {root} = path.parse(startDir);
9 const filenames = [].concat(filename);
11 return new Promise(resolve => {
13 locatePath(filenames, {cwd: dir}).then(file => {
15 resolve(path.join(dir, file));
16 } else if (dir === root) {
19 find(path.dirname(dir));
26 module.exports.sync = (filename, opts = {}) => {
27 let dir = path.resolve(opts.cwd || '');
28 const {root} = path.parse(dir);
30 const filenames = [].concat(filename);
32 // eslint-disable-next-line no-constant-condition
34 const file = locatePath.sync(filenames, {cwd: dir});
37 return path.join(dir, file);
44 dir = path.dirname(dir);