-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Yarn PnP resolver out of the box #253
Comments
what do pnp-resolver.js sources look like? |
https://github.com/iambumblehead/esmock/wiki#call-esmock-yarn-pnp - it's enough |
what do these sources look like? |
Oh interesting, so esmock could support yarn pnp without adding any new dependencies... If you make a PR that is good and if you don't I will make one over the next day or two. Imo a single unit test would be sufficient to start and a special ci job could be added for that. |
Yep, I'll start right now. |
Not sure if this would work. Returns user-defined resolver, then tries yarn resolver finally returns resolvewithplus esmockReslover.js import resolvewithplus from 'resolvewithplus'
export default async opts => opts.resolver
|| (await import('./pnp-resolver.js').catch(() => {})).default
|| resolvewithplus |
PnP detection can be done via process.versions.pnp, which is faster and cleaner than trying to import non-existen'pnpapi' module for classic setup. What about order - yeah, we can skip 'getResolver' call if user-defined one already present in ops. Currently it not so important, but we can use dynamic load for resolvewithplus to avoid useless module load (and creating a lot of objects inside) via static import. |
okay its looking good at the PR 👍 |
Due to default resolver (resolvewithplus) doesn't support PnP, users can use custom resolvers to work in PnP environment - https://github.com/iambumblehead/esmock/wiki#call-esmock-yarn-pnp. It's a small effort for one test, but what if existing project contains 1000+ tests?
We can implement PnP detection in esmock, and use our own PnP resolver instead of resolvewithplus (esmockArgs.js):
It's an additional magic inside esmock, but I think we can have such magic for popular tools like Babel or Yarn.
The text was updated successfully, but these errors were encountered: