fix: normalize all frame filePath
to posix format
#46
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.
Okay so, I will explain why this modification is required for Windows users :
I wanted to add the feature of having a relative path rather than absolute path in the Japa error printer. But after investigating I noticed that this feature was already in place! Thanks to the
displayShortPath
property ofyouch-terminal
.But it doesn't work for Windows :
So the first thing we need to do is to normalize the Youch filePaths, so that they are all Posix. In our case, the filePaths that come out of StackTracey, are in Posix format, even for me who is under Windows.
The only paths that are not in Posix are the ones coming out of
fileURLToPath
. The separator of the path is platform specific in this case. So that's what's I fixed in this PRThe second thing, which will be sent in a PR for
youch-terminal
, is to modify this line:https://github.com/poppinss/youch-terminal/blob/develop/index.js#L139
We'll just convert the return of
cwd()
, which is platform specific, to posix format. And also don't usesep
anymore but just a/
.Thanks to these modifications, I now have a nice relative path in Japa!
We could have done the opposite, and keep specific platform paths (and thus rather convert the paths of StackTracey). Personally, I prefer that we normalize all this. It makes the code more predictable, I think. If I miss something, let me know
Feel free to ask if it isn't clear ! 👍