-
Notifications
You must be signed in to change notification settings - Fork 108
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
feat: add source maps to libraries bundle #144
Comments
Hey @wawyed, awesome idea! This shouldn't be too hard to implement, all the pieces are already there. |
There's basic support for source maps for the bundled packages now: karmaTypescriptConfig: {
bundlerOptions: {
sourceMap: true
}
} To try it out you can install from the dev branch, |
You sir are on fire. I'll give it a try ^^ |
I just tried it, it works but it doesn't seem to keep the sourcemap comment for the original js. So if it had a map to typescript it doesn't show the original typescript code. |
Source maps for the original code are now loaded (only first level) and it works for packages like |
@wawyed, have you tested the last commit, can I close this? |
I'm trying to test it but Im getting this when trying to npm install the branch npm ERR! code 128 |
Oh great, I broke the git repo... I've cleaned up now and the build passes on the ci servers and I'm able to |
Yes, I got it working, unfortunately even though is mapping from the bundle to the original TS the line that it goes to when I'm setting a breaking point doesn't match the correct one. |
Which package isn't working when you debug, a specific one or all? I banged my head on my desk for days before realizing that some packages simply have incorrect source maps, I verified by loading a few packages directly in Chrome: <!DOCTYPE html>
<html>
<body>
<script src="node_modules/@angular/core/bundles/core.umd.js"></script>
<script src="node_modules/diff/dist/diff.js"></script>
<script src="node_modules/es6-promise/dist/es6-promise.js"></script>
<script>
console.log("try setting a break point");
</script>
</body>
</html> Put this html file in the root of, for instance, the angular2 example project and open the html file in Chrome. The angular file will crash and you might have to hit reload before the source maps load but it's still possible to set break points. Now add This is the result I get with Chrome on OSX:
The pattern I see is if it works when loading a source map directly in Chrome, it will work in karma-typescript as well. It seems some vendors have a broken build chain where they transpile with source maps first and then they add umd wrappers without updating the source map, which throws the line numbers off. |
The package I used as a test is one of our private npm package and I can validate that the sourcemaps are correctly generated as they work fine when I run the app. |
New approach: I've modified one of the typescript example projects to add the package Debugging this project works as expected, I can set a breakpoint in src/hello.component.ts and step through the code with correct line mappings. Does it work if you install from the sourcemap branch, In your project, are the line numbers off by one or by a lot, or does the discrepancy grow as the line numbers grow? |
@trwolfe13 @Salasar @patrickarlt, I would love some testing outside my environment for this, could you guys help me out please? |
Hi, sorry about the delay in the reply. I have tried the branch and I'm getting mixed results. Some ts files are getting remapped but others just show an empty file while trying to load the ts file. |
Ok, you should get the same results for your project with the Does the typescript-latest example project on the |
Yes, that seems to work correctly. One difference that I didn't mention, my compiled code uses inlineSources in the sourceMap so it doesn't point to a different file, contains the original code inside the sourcemap file. |
Great, so it's not an os/environment issue then... Which leaves us with what? If you look at source-map.ts, there's nothing special going on in my code; file content is fed to I have yet to find a correct source map that doesn't work in karma-typescript, apart from your source maps, which I can't test since it's a private package. I'm out of ideas here 😕 |
I'm going to try to reproduce it in your example. |
Okay so I have created an example that you can reproduce :) You can find it here: https://github.com/wawyed/karma-typescript/tree/sourcemaps Hope it helps! If you look at MhrWindowService you will see that the original ts file is shown as an empty file. |
Awesome!! Your source maps have sources that look like this: [
'webpack:///webpack/bootstrap a5a1de700b3a78264108',
'webpack:///./src/services/index.ts',
'webpack:///external "@angular/core"',
'webpack:///./index.ts',
'webpack:///./src/index.ts',
'webpack:///./src/services/MhrWindow/MhrWindow.service.ts',
'webpack:///./src/mhrCommon.module.ts',
'webpack:///external "@angular/common"'
] The |
Hello, good news is that the files are not blank anymore :D. Bad news... the lines seem offset by a few lines. |
I found this tool to check sourcemaps visually. Maybe it can help you find out what's wrong: http://sokra.github.io/source-map-visualization/ Seems to have a limitation on the number of lines it can show sokra/source-map-visualization#21 so might not be that useful. |
Darn. I loaded @ mhrwebux/common/index.js and its source map from your tar ball into the visualization tool you linked and inspected row 127-129 of index.js: function _window() {
return window;
} Row 128 ( I then launched the typescript-latest project from your fork, with the fix for empty files, and located the Row 162 of index.js, This seems pretty accurate and consistent to me, could you give me an example of a file and a row in your fork where the source mapping is off please? I suspect there is more webpack magic hidden in your source maps 😕 |
Aah, windows line breaks, the gift from the dot-matrix printers era that keeps on giving If I hardcode |
I was going to say it might be something related to line endings since you didn't seem to have issues. Could you do something like?
|
This is exactly what |
hmm, from what I can see the sourcemap gets converted into a base64 string that gets read by chrome, so maybe chrome wants linux endings regardless? |
I'm using the fix the hardcoded unix line breaks, it doesn't seem to affect anything else but the source maps, the fix is on the next branch, |
So, that fixes the issue :)... unfortunately, it seems that there is some issue with the sourcemaps of the src or test files. I don't seem to be able to set a breakpoint in some statements, specially if I have new lines in between. The crossed lines are the ones I'm not able to add a breakpoint. But if i remove the line lines.. Works fine. Don't know if it's a chrome thing or what. |
This must be a Chrome issue, I get the same behavior on windows with and without the latest line break fix. Also, the new source maps logic only affects the main bundle, the project ts files still use the inline source maps generated by Typescript. Anyway, I managed to set breakpoints in Chrome on windows by setting them in the compiled file and the breakpoints end on the correct lines, so it's a Chrome issue I guess: |
Ok, case closed then |
Releasing the new version soon? :) |
3.0.6 is on npm now 🚀 |
It would be nice if the karma-typescript-bundle was mapped back to the original files. so when debugging in unit tests is easier to know where the errors come from.
The text was updated successfully, but these errors were encountered: