-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Relative path manipulation handles Windows paths and different extensions #23
base: master
Are you sure you want to change the base?
Conversation
pathIsAbsolute(relativeRootedPath) || // absolute path, nor | ||
protocolRx.test(relativeRootedPath)) { // absolute protocol need rebasing | ||
return relativeRootedPath; | ||
} | ||
|
||
// make relative to source file | ||
return path.join(path.dirname(sourceFile), relativeRootedPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required to make existing tests pass on Windows, but probably wise anyway.
This is really a big problem since global detection is on by default in browserify and code built on Windows with browserify (which relies on combine-source-map) will also fail for all other users for source files that contains references to Is this library still being maintained? If not, I think we ought to ask browserify to require the fork in this PR. |
if (sourceFile === relativeRootedPath || // same path, | ||
path.dirname(sourceFile) === path.dirname(relativeRootedPath) || // same dir, different file (e.g. foo.ts > foo.js) | ||
pathIsAbsolute(relativeRootedPath) || // absolute path, nor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix the alignment of ||
here, they were all in the same column for improved readability.
Also cut the comment a bit shorter, (remove the e.g.
part).
Sure, I'll be happy to adjust the PR. Re: the alignment, would you like me to break after the However, while the backslashes issue is clear to me (and the main reason for my asking for the merge), and while I understand the rationale for the Sorry if I'm muddling things based on an incomplete understanding but it actually seems like, except for the backslashes issue, that it ought to be possible to supply more information to |
IIRC, I went through much the same thinking and chose a simple dirname comparison for two reasons. Firstly, as you say, there may be cases of Apologies for ruining the layout. Looking back, adding a function |
Although I think this is sound, I would like to take another look when I get a chance at how But the backslash issue at least ought to be fixed here and the other items in the PR should still be valid, particularly if all path info needed for a good comparison is being and can be supplied. |
@thlorenz : I'm not sure if or when I may have time to debug things on the browserify side or to better contemplate the soundness of directory comparisons here. It does seem clear that If you don't have time to consider it either, Thorsten, I suggest at least merging #21 which is a no-brainer for Windows. |
In giving this a little further thought, it seems to me that @chrissewart's changes are not only generally safe but that we ought to go further in avoiding the assumption that existing map sources should be rebased relative to newly added files (unless some config is passed in to indicate such a desire). Is there some compelling reason why this assumption is being made? (If such cases are required, I'd be interested to know whether browser-pack and browserify ought to be making use of them by default.) |
But if there is a need for rebasing by default, it seems to me that making exceptions for source file conversions like CoffeeScript/TypeScript ought to be specified via explicit config in some manner. In looking at coffeeify, I see a I hate to be feeling around in the dark here, but I am hoping this may provide some food for thought by someone more comfortable with the code base, source map specs, and the consumings apps. |
Do we still need this @brettz9 given we applied the two other changes? |
There is still an aspect of the PR not incorporated which ought to be addressed somewhere (namely ensuring that pre-compiled sources like However, unless @chrissewart might provide further rationales, my previous two comments attempted to address why I am not convinced that the still-unincorporated aspect of this PR, namely, this line: path.dirname(sourceFile) === path.dirname(relativeRootedPath) || // same dir, different file (e.g. foo.ts > foo.js) ...while understandable and solving the problem, doesn't strike me as a fully satisfying solution. |
OK, thanks for the feedback @brettz9. If we don't hear from him in a month or so we'll just close the PR. |
My rationale for the contentious change referenced by @brettz9 above is where some upstream module has already done a mapping and given the result a relative path. Specifically, modules containing node globals go through So, anything that wasn't originally JS that uses node globals breaks. My reasoning that ignoring the filename is OK is that if the conditional isn't true the resulting code also ignores the filename - it plucks it off sourceFile and uses the one from relativePath !! Given the debate it has caused, I can see that my proposed solution isn't fully satisfying, but figured it was better than some other person spending the hours I did figuring out why some of their project's TS files couldn't be debugged with sourcemaps. :-) If I was to try for something better, I'd note that
So, in my head, it should work like this:
But right now I can't even run the tests. |
Fixes two problems when combining source maps that already have a relative path.
The first problem is when the extensions differ. e.g. A Typescript or Coffeescript compiler has converted
foo.ts
intofoo.js
and something upstream has given them relative paths.bar/foo.ts
does not matchbar/foo.js
so the sources comes out asbar/bar/foo.ts
The second problem is doing the above on Windows.
bar\\foo.ts
does not matchbar/foo.js
.Both occur when running Browserify on Windows on files generated by the Typescript compiler. Most files work ok, but ones that contain node.js globals go through the
insert-module-globals
module which generates a relative path. The path.join() in combine-source-maps is hit generating a Windows path which then causes the path comparison to fail when this code is hit again duringbrowser-pack
The simplest fix seemed to be to ensure URL path separators everywhere and compare only on dirname.
Tests added for both problems.