Last active
April 23, 2020 12:52
-
-
Save brettz9/0551352af37351645e38f7feba7dc4b5 to your computer and use it in GitHub Desktop.
Promise-based `resolve`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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