Closed aleclarson closed 3 years ago
Good idea. One thing though: how about using require.resolve with the paths
options https://nodejs.org/api/modules.html#modules_require_resolve_request_options instead of adding a dependency?
Not worth the effort. The dependency is tiny, popular, and battle-tested: https://github.com/sindresorhus/resolve-from/blob/main/index.js
As a reader it's an order of magnitude easier and quicker to read:
function resolveFrom(source, from) {
try {
return require.resolve(source, {paths: [from]})
} catch(err) {
return null
}
}
Than having to look up what resolve-from
is about. (E.g. I had to do this while reviewing your PR.)
I find code riddled with tiny dependencies non-significantly harder to read.
Objections?
Than having to look up what
resolve-from
is about.
Not a big deal to me, but if you prefer it, you can push a follow-up commit after this is merged. No PR necessary. 👍
follow-up commit
Will do.
I find that these small things add up over time.
Will do.
Done. Feel free to release a new version.
When using a local clone of this plugin, it can fail to resolve
react
and@mdx-js/react
, so this PR usesconfig.root
(from Vite config) when resolving those packages.