-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Incorrect behavior of import/order in a monorepo setup #1597
Comments
How to fixThis is pretty complicated actually. The first problem here is that But even fixing this won't make the plugin support the case described here since Webpack resolver returns the fully resolved path to the module's main file which, in the case of a monorepo, might not contain the scope part or even the package name. So, I see two options. The first one is to make
The risk I see here is that the stuff with checking the import name in The second, safer, way is to add another configuration option, e.g. I'm working on a PR implementing the first option but need your input about whether it's safe to do. |
I think that in general, if it doesn't fail tests, it's safe to do, and I definitely prefer the first option to the second. |
Thanks, I'll proceed with the first option then, making sure it breaks no existing tests. |
Minimal reproduction of the bug and a detailed analysis of the cause: https://github.com/skozin/eslint-plugin-import-bug-repro.
The bug
The
import/order
rule gives a false positive in a setup with the following conditions met:A quick example
Consider this code:
and this config:
The expected result is no errors being reported. However, this comes up instead:
I've prepared a repo with a minimal reproduction and a detailed analysis of the cause: https://github.com/skozin/eslint-plugin-import-bug-repro.
What happens
See the repo with a reproduction for a detailed explanation.
In short, the problem is that paths to scoped packages get considered as internal ones by the
isExternalPath
function even though the directory where these packages reside is added to theimport/external-module-folders
list in the config. Before #1294, this was not a problem since scoped packages were always considered as external ones, but after merging that PR the behavior changed and now scoped packages are considered external only if their resolved path is determined as external.In turn, seemingly incorrect behavior of
isExternalPath
is caused by the logic inside it that doesn't only check that the resolved path to a package contains one of theimport/external-module-folders
as a subpath, but also that it includes the package name as a subpath. This is not true in the case of a monorepo with scoped packages since a path to a Yarn workspace containing the package contents doesn't need to include the package scope or even the package name as a subpath.For example, in the described case the resolved path to
@my-scope/package-a
is/path/to/the/project/packages/package-a/index.js
and it doesn't contain@my-scope
part at all.The text was updated successfully, but these errors were encountered: