question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement async dependency resolution

See original GitHub issue

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 (https://github.com/nodejs/node/pull/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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

39reactions
lloydjatkinsoncommented, Nov 22, 2021

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.

7reactions
SimenBcommented, 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 https://github.com/browserify/resolve/issues/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 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to implement dependency between asynchronous ...
Typically you will establish, in some suitable outer scope, a js plain object as a promise cache, and always look there first before...
Read more >
Dependency Injection, Async and HangFire for Simple ...
This post is set to resolve this shortcoming by discussing how you can create your own tasks, trigger them with HangFire, either recurring...
Read more >
Asynchronous Injection - ploeh blog
How to combine asynchronous programming with Dependency Injection without leaky abstractions.
Read more >
Parallelizing Async Tasks with Dependencies
This frees up all its dependencies to be executed. You can find the complete code implementation here . To run an example we...
Read more >
async-resolve - npm
An asynchronous and configurable implementation of require.resolve(), like node-resolve or enhanced-resolve.. Latest version: 0.3.5, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found