-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
Improve module resolution #9897
Comments
Thanks for creating an issue. I'm still a bit confused about what the proposed change actually does at a high level (I understand the current behavior generally, but I'm not very familiar with the current implementation details such as Presumably, if this change allows ESLint to resolve the configs from #9746, then this change is making ESLint search for configs in places where it wasn't looking for them previously. Could you clarify where it tries to look for a config with this change applied? My goal in asking these questions is to try to make the high-level behavior change clearer, so that we can ensure it makes sense and works well in general aside from the specific case in #9746. |
Yep, so basically it adds new paths to lookup for module resolution. Current lookup paths:[ '/home/nicolas/Playground/eslint-issue-9746/node_modules/node_modules',
'/home/nicolas/Playground/eslint-issue-9746/node_modules/eslint/lib/util/node_modules',
'/home/nicolas/Playground/eslint-issue-9746/node_modules/eslint/lib/node_modules',
'/home/nicolas/Playground/eslint-issue-9746/node_modules/eslint/node_modules',
'/home/nicolas/Playground/eslint-issue-9746/node_modules',
'/home/nicolas/Playground/node_modules',
'/home/nicolas/node_modules',
'/home/node_modules',
'/node_modules',
'/home/nicolas/.node_modules',
'/home/nicolas/.node_libraries',
'/usr/lib/node' ] With this PR[ '/home/nicolas/Playground/eslint-issue-9746/node_modules/eslint/lib/util/node_modules',
'/home/nicolas/Playground/eslint-issue-9746/node_modules/eslint/lib/node_modules',
'/home/nicolas/Playground/eslint-issue-9746/node_modules/eslint/node_modules',
'/home/nicolas/Playground/eslint-issue-9746/node_modules',
'/home/nicolas/Playground/node_modules',
'/home/nicolas/node_modules',
'/home/node_modules',
'/node_modules',
'/home/nicolas/.node_modules',
'/home/nicolas/.node_libraries',
'/usr/lib/node',
'/home/nicolas/Playground/eslint-issue-9746/packages/eslint-example/node_modules',
'/home/nicolas/Playground/eslint-issue-9746/packages/node_modules' ] So basically it adds two new paths where the module could be found: '/home/nicolas/Playground/eslint-issue-9746/packages/eslint-example/node_modules',
'/home/nicolas/Playground/eslint-issue-9746/packages/node_modules' The module in this case is in |
Thanks, that description is useful. How does ESLint determine that it should search in the |
So the idea is that the Module resolver gets a extraLookup = getLookupPath(relativeTo);
function getLookupPath(configFilePath) {
const basedir = getBaseDir(configFilePath);
return path.join(basedir, "node_modules");
} In my example, Currently, With this PR, The function getBaseDir(configFilePath) {
let projectPath = ...
...
} Currently, the So I guess to sum-up, I guess one can say that it mainly fixes the |
Just as a side note, I didn't quite get how |
Sorry, I should have been more clear: I'm asking about the proposed design of this new feature, not the implementation. We can discuss the implementation in #9896 when/if the design is accepted. For the purposes of the discussion in this issue, though, it's not important to me how the change is implemented (including methods like To clarify the question from #9897 (comment): Why does ESLint search for modules from the |
Sorry for the confusion. Basically, I guess the PR could be divided into 2 parts:
Is that a bit better? |
That does help. However, I am still confused about how this affects user-facing behavior in general, because you're describing it in terms of implementation details such as Again, this issue is intended to discuss the external behavior that users would see, not the implementation. If we were to put an entry in the changelog that says "Updated the return value of I am looking for the second kind of description for this change. You're proposing a change to user-facing behavior, and it might be worthwhile, but I can't tell because I'm not sure what the proposed change actually does. I'm asking for a general description of how the proposed change affects users, without referencing implementation details such as |
Ok yeah I see. So the idea here is that the eslint config and plugins were all in a module linked by npm via symlinks, the two modules being adjacents. |
I think you're thinking about this from the wrong direction. I want us to come up with a workable and coherent design for a change first, and then we can use that to create an implementation. The user-facing impact of the change is much more important than how it's implemented. If we just implement a change and then try to explain how it works afterwards, then there is no guarantee that the user-facing behavior is coherent or useful. (This is why we ask people to create an issue for core modifications -- so that we can discuss the design separately from the implementation.) (Sorry about all the back-and-forth -- I don't mean to sound hostile, and I really appreciate your contributions. There are a lot of people relying on the existing config-resolution behavior, and I just want to make sure that if we make a change, the new behavior is well-reasoned and doesn't violate any existing user expectations.) |
In the example from #9746, lerna sets up a directory structure like this:
ESLint resolves shareable configs from the location of the This means any solution that makes this "just work" with lerna would need to provide some way for ESLint to know where should find |
Yes, I totally see your point, and agree. However, I cannot wrap my head around finding a clear explanation of the issue. Here how it went on my side:
So again, not sure if I can think of a clear explanation... |
You're right, that is a bit strange. It looks like that behavior was introduced as part of a fix for #5164. |
Okay, so here's what I could find:
|
I'm not sure I see the issue with the last directory structure example. How could this setup happen? |
It's unlikely to happen as a result of using |
But wouldn't it rightly make sense to take the |
I agree that it probably makes the most sense to do that. I am clarifying that doing it this way would be a breaking change from the way that ESLint currently resolves that config. |
Ok, right. So should this issue be closed in favour of a more general one? I think you would word it in a better way that I could... |
I just approached this issue. ESLint doesn't follow symlinks as expected. e.g. error can be easily reproduced with following setup: Listing of files in
Listing of files in
Listing of files in
Having above, running
It would be way better if if instead of trying to use internal Node.js functions, eslint would rely on node-resolve or cjs-module/resolve. |
Closing this issue in favor of #10643, since that issue addresses the problem in a more general way and has some more detail on various possible solutions. |
Tell us about your environment
v4.16.0
v9.4.0
v5.6.0
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
This is a follow-up of #9746.
See this repository, which explains the issue: chrisblossom/eslint-issue-9746
What did you expect to happen?
ESLint should be able to work inside Lerna projects.
What actually happened? Please include the actual, raw output from ESLint.
ESLint throws errors regarding module resolutions.
As described here (#9746 (comment)) it seems that this is the expected behaviour, however I'd argue that the changes presented here: #9896 are actually improving the module resolution logic, while fixing #9746.
First, it splits up the
extraLookup
path into multiple paths where modules should be looked for, according to Node module specifications.Secondly, the change to
getBaseDir
seems pretty straightforward: theprojectPath
should not be anode_modules
directory.If those changes are accepted, it would actually resolve issues users have with ESLint and Lerna, while improving the module resolution logic.
The text was updated successfully, but these errors were encountered: