2 const path = require('path');
3 const locatePath = require('locate-path');
5 module.exports = (filename, opts) => {
8 const startDir = path.resolve(opts.cwd || '');
9 const root = path.parse(startDir).root;
11 const filenames = [].concat(filename);
13 return new Promise(resolve => {
15 locatePath(filenames, {cwd: dir}).then(file => {
17 resolve(path.join(dir, file));
18 } else if (dir === root) {
21 find(path.dirname(dir));
28 module.exports.sync = (filename, opts) => {
31 let dir = path.resolve(opts.cwd || '');
32 const root = path.parse(dir).root;
34 const filenames = [].concat(filename);
36 // eslint-disable-next-line no-constant-condition
38 const file = locatePath.sync(filenames, {cwd: dir});
41 return path.join(dir, file);
42 } else if (dir === root) {
46 dir = path.dirname(dir);