Skip to content
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 getRelativePath behaviour on case-insensitive filesystems #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sammko
Copy link

@sammko sammko commented Apr 26, 2024

See commit message for explanation. A more elegant solution can likely be devised but this should take care of most cases. Let me know if I should provide more details or a reproducer.

Typically when resolving an import in file `A/a.ts` "from" file `B/b.ts` e.g.

  import x from "../B/b"

the function will be called as `getRelativePath("A", "b")`. Note the `"b"` path
has been lowercased by tsc at some point and that `"A"` may not exist on disk
at this point as it's being generated.

The previous logic would fail on `realpathSync.native(from)` because `from =
"A"` does not exist on disk yet and would not fix the casing of `to`. As such
`"../b"` would be returned instead of the correct `"../B"`. The simplest fix is
to swap the realpath calls which is what we do here, as typically `to` will
exist (it's what is being imported) and `from` may not.
@danielpza
Copy link
Member

Hey @sammko, sorry for the late reply.

Can you please add some unit tests to check for this issue. Other than that LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants