-
-
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 file resolution for paths higher than CWD #1259
Comments
All commands should always be ran from the project root; why is the cwd not A? |
One example is monorepo, which aggregates multiple projects under one root. |
In a monorepo, you'd still want to run every command from the root. |
@ljharb I think the issue is wider than just current working directory. Since most of build tools are case-sensitive, a module with an equal name when case is ignored can lead to unexpected behavior and cause real bugs because different module instances are returned. I suppose performance optimization makes sense here, but I'd rather to have an option ( |
If there's a reproducible test case, I'm open to fixing it, but I'm still not clear on the use case. |
@ljharb, here're a few examples reproducible with NodeJS resolver (used by default): // Absolute paths
import Foo from `/Users/fOo/bar/file.js`
import Foo from `d:/fOo/bar/file.js`
// Relative paths, cwd is Users/foo/
import Foo from `./../fOo/bar/file.js` |
@sergei-startsev with each of those, what is the current vs expected error? |
It's expected that the code above (each of imports) is identified as invalid by |
Env:
Windows 7 x64, NodeJs v10.15.0, eslint 5.11.1, eslint-plugin-import: 2.14.0
Repro steps:
Rule no-unresolved is turned on with case sensitive option
Project root is "B/"
CWD is "C/"
Project Structure (tree)
Expected result:
Actual result:
Description:
Eslint task is launched by grunt, where grunt config file is located in "C/" folder (CWD). While actual project folder is one ore more levels higher than cwd ("B/" ). So imports with such path don't cause error.
It is caused by "fileExistsWithCaseSync" function
https://github.com/benmosher/eslint-plugin-import/blob/1cd82eb27df85768fbd076e4ff6b7f36d6f652ce/utils/resolve.js#L38
So it basically doesn't go any higher than cwd to cache path.
Suggestion:
It either should not be limited at all (because it is relatively cheap operation as it caches previous paths),
or at least it should be limited to project dir (something like getBaseDir() is doing - line 153)
The text was updated successfully, but these errors were encountered: