Skip to content
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

Implement async dependency resolution #9505

Closed
SimenB opened this issue Feb 3, 2020 · 8 comments · Fixed by #11540
Closed

Implement async dependency resolution #9505

SimenB opened this issue Feb 3, 2020 · 8 comments · Fixed by #11540

Comments

@SimenB
Copy link
Member

SimenB commented Feb 3, 2020

Similar to #9504, but for dependency resolution. Like there, this wouldn't be used by Jest just yet, but could (and would, if support is implemented) be used by the ESM support. This logic is implemented in jest-resolve.

I wonder if it makes sense to reintroduce resolve as a dependency since this already has an async code path. That is callback based, but just promisifying that should work fine. But the increased complexity of mjs, cjs etc makes me want to depend on a dedicated module rather than have that complexity live in Jest itself - Jest should just manipulate resolution based on moduleNameMapper etc and possibly cache some stuff on our side.

resolve was actually removed in #4315, via #2925. Some of #2925 reasoning was that resolve was somewhat unmaintained and that we didn't need the async parts of it - neither of which are true anymore.

Added in #9520

import.meta.resolve has landed on node master (nodejs/node#31032, albeit currently behind a flag), so we'll need to implement this regardless of whether we'd want to use it ourselves or not

@moljac024
Copy link

Any chance of seeing this one in 27? This would unblock vitejs/vite#1955 and allow first-class integration of Jest into Vite.

I am willing to help bring this to life but I would need some guidance as I'm not really familiar with jest and it's internals

@SimenB
Copy link
Member Author

SimenB commented May 1, 2021

PRs are very much welcome! 👍

Similar to how we did async transform (#9889), you can start by adding support to jest-resolve, the module that does the reoslution in Jest. That means adding async APIs to https://github.com/facebook/jest/blob/26cb29a42cc9b967f29d70d8c70169993965cf01/packages/jest-resolve/src/index.ts#L51 and https://github.com/facebook/jest/blob/26cb29a42cc9b967f29d70d8c70169993965cf01/packages/jest-resolve/src/defaultResolver.ts#L34-L37

Note that resolve does not have a promise API which is what we want in jest-resolve, but using its callback API should be fine (there is browserify/resolve#210, but not much movement) as long as teh API exposed by jest-resolve is promise based.


Once jest-resolve supports it we can add support to Jest by modifying jest-runtime. Feel free to look into it of course, but I suspect that will fall to me as the code there is quite complex. But of course if you're up for it I'd love for you to pick that up as well 👍

@rememberlenny
Copy link

I would like to help here, but am not quite sure where to start. @SimenB Is there a reference and just a matter of implementing this to a new context?

@lloydjatkinson
Copy link

Is there any roadmap on implementing this? I believe it’s having quite a significant knock on effect with build tools that wish to use Jest but cannot, Vite being one example.

@IanVS
Copy link
Contributor

IanVS commented Feb 14, 2022

@lloydjatkinson I need to rebase #11540, but it sounds like Simen is ready to give it a review once I do, and then get it into Jest 28.

@SimenB
Copy link
Member Author

SimenB commented Feb 14, 2022

Yep, I'll make sure it's in 28 before releasing it to give a nice major target version for downstream 🙂

@SimenB
Copy link
Member Author

SimenB commented Feb 22, 2022

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants