-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix(core): use require.resolve instead of randomly matching from our … #14523
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
8185c36
to
ca8351d
Compare
Require.resolve is notoriously slow. Can we have some benchmarks to check the impact? Running our linter rule on any medium size (50-100 projects) monorepo should tell us. In any case I would move it after npm package check as that's cheaper operation. |
@@ -135,22 +137,17 @@ export class TargetProjectLocator { | |||
return; | |||
} | |||
|
|||
private findProject(importExpr: string): string | undefined { | |||
if (this.projectResolutionCache.has(importExpr)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think its worth keeping the cache? Or I guess require.resolve may have some caching, I know regular require does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require
has its own cache:
https://nodejs.org/api/modules.html#modules_caching
But it should also be rare for it to get down there.
It is already below the npm package check. It's below all of our existing checks actually. The last line isn't part of the actual check. it sets undefined into the cache is to remember that we couldn't resolve the import for later runs. |
I did a benchmark and it took ~4ms for 500 unique imports on my machine.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the benchmark and code reshuffle. Looks good to me!
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
…project graph
Current Behavior
We resolve any imports which match the name of one of the projects in our project graph.
This is kind of arbitrary because this dependency would only exist in Nx and wouldn't stem from any underlying tool.
Expected Behavior
We use
require.resolve
to resolve those dependencies. This is more valid because the dependency would exist natively in JS.Related Issue(s)
Fixes #