Only consider baseUrl for non-relative imports#1111
Merged
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom Aug 31, 2021
wildbook:fix-relative-imports
Merged
Only consider baseUrl for non-relative imports#1111Perryvw merged 1 commit intoTypeScriptToLua:masterfrom wildbook:fix-relative-imports
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom
wildbook:fix-relative-imports
Conversation
sanikoyes
pushed a commit
to sanikoyes/TypeScriptToLua
that referenced
this pull request
Sep 24, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
According to TypeScript's documentation,
baseUrlshould only be used to resolve absolute imports.The way imports are currently resolved requires absolute paths for all imports if
baseUrlis set, which broke our codebase when we updated TSTL.Example
Assume that
baseUrlis set tosource/and that this is how our code is structured:If
baz/index.tscontainsimport { Bar } from './bar', that import will resolve tosource/bar.tsinstead of the correct filesource/baz/bar.ts.If
source/bar.tsdoes not exist, the resolver fallback will successfully assume the correct path, but it will also emit an error that the path could not be resolved. In general we'd much prefer to not ignore errors and resolveDependency on fallbacks, not to mention the errors emitted would make CI builds fail.Fix
I've fixed this by checking whether or not the import is considered relative before considering
options.baseUrlinsrc/transpilation/resolve.ts:resolveDependencybut I don't know if that is the correct way to fix it or not, only that it works in our case and that TSTL's tests pass.Affects
This change only affects relative imports, and only when
baseUrlis set.The definition used for "relative" is "/, ./, or ../" and comes from the same docs page as linked above.