Skip to content

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.

@danielpza
Copy link
Member

superseded by #187

@danielpza danielpza closed this Jul 3, 2025
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