Skip to content

Instantly share code, notes, and snippets.

@brettz9
Last active April 23, 2020 12:52
Show Gist options
  • Save brettz9/0551352af37351645e38f7feba7dc4b5 to your computer and use it in GitHub Desktop.
Save brettz9/0551352af37351645e38f7feba7dc4b5 to your computer and use it in GitHub Desktop.
Promise-based `resolve`
/*
import resolve from './resolve.js';
await resolve('tap', { basedir: __dirname });
*/
const _resolve = require('resolve');
const resolve = (path, opts = {}) => {
// eslint-disable-next-line promise/avoid-new
return new Promise((resolve, reject) => {
// eslint-disable-next-line promise/prefer-await-to-callbacks
_resolve(path, opts, (err, res, pkg) => {
if (err) {
reject(err);
return;
}
resolve(res);
});
});
};
export default resolve;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment