Sha256: b2b7a4a3a202785dfc044bc9d3798df684c9983008254e44e23258f80c7aba54
Contents?: true
Size: 968 Bytes
Versions: 57
Compression:
Stored size: 968 Bytes
Contents
'use strict'; const path = require('path'); const locatePath = require('locate-path'); module.exports = (filename, opts = {}) => { const startDir = path.resolve(opts.cwd || ''); const {root} = path.parse(startDir); const filenames = [].concat(filename); return new Promise(resolve => { (function find(dir) { locatePath(filenames, {cwd: dir}).then(file => { if (file) { resolve(path.join(dir, file)); } else if (dir === root) { resolve(null); } else { find(path.dirname(dir)); } }); })(startDir); }); }; module.exports.sync = (filename, opts = {}) => { let dir = path.resolve(opts.cwd || ''); const {root} = path.parse(dir); const filenames = [].concat(filename); // eslint-disable-next-line no-constant-condition while (true) { const file = locatePath.sync(filenames, {cwd: dir}); if (file) { return path.join(dir, file); } if (dir === root) { return null; } dir = path.dirname(dir); } };
Version data entries
57 entries across 56 versions & 10 rubygems