Only add basePath to error stacktraces with relative source file paths #1267
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.
Some sourcemap tools can produce absolute paths for source map urls, which will then be reflected in error stacktraces that feature absolute paths for the stack frame source url.
Previously, the basePath (typically
process.cwd()) was prefixed to all error stacktrace urls, which sometimes works for relative paths[1], but will fail with absolute paths.This change checks if the stacktrace url is absolute first - if so, it skips prefixing the url with basePath.
This change is more than cosmetic - the mini reporter uses the stacktrace url to invoke the
codeExcerpthelper, which tries to load the source file from that url. If it's not correct,codeExcerptwill throw.[1] - See #1266. Intermediate build steps between the sourcemap generation and running ava can break relative urls too. This change does not solve that problem - it only fixes the absolute path scenario.