Skip to content

Build a high-performance version of resolve #2925

Closed
@cpojer

Description

In Jest, we use jest-resolve to resolve modules. However, it shells out to two other dependencies, resolve and browser-resolve. resolve hasn't been maintained as much as I'd like, we have a hacky workaround inside of jest-resolve and we actually have knowledge of the entire filesystem (minus directories) in "HasteFS" (currently not passed to jest-resolve but that can be changed as the places it is created already passes a "ModuleMap" which is also coming from jest-haste-map).

The idea is to take the synchronous part of resolve and put it inside of jest-resolve. Then rewrite it and fine-tune it for performance (cc @trueadm) and use "HasteFS" to optimize the best case scenario (you can use jest-file-exists which is O(1) in the best case and fs.stat in the worst case).

The end state should be for Jest not to depend on resolve any longer. We do not need the asynchronous part of resolve.

Call to resolve: https://github.com/cpojer/jest/blob/master/packages/jest-resolve/src/index.js#L84
See: https://github.com/substack/node-resolve/blob/master/lib/sync.js

Follow-up: We should also aim at replacing browser-resolve and making it configurable so that our resolution algorithm can look at any field in package.json to re-route resolution to a module. This can be done in a follow-up, because this is already a big task :)
browser-resolve: https://github.com/defunctzombie/node-browser-resolve

cc @DmitriiAbramov @wanderley

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions