Closed timofei-iatsenko closed 8 years ago
Test failed. Interesting. Webpack Hash in source maps is diffrent... need another way to check sourcemaps valid. Dirty checking files is not good solution.
@thekip Great job! I need some time to get into it. Thank you for the PR!
Problem not only in hash ( Diffrent between unix/windows line endings. I already fixed that in generated source, but the same mistake exist in maps as well, and it's not so easy to fix.
Last two commits bring next improvments:
sourcemap-checkpoints.js
for each test case, which used as reference for sourcemap.
This is more intelegent way to test maps, because we exactly know work this map or not as if tested in browser.
Also this fix issues with crlf/lf. Any progress on it?
This is ready to merge, wait for @huston007
@hekike You can use my fork, untill it merged to original packet.
@thekip @hekike Oh that cool! Didn't notice that it started passing the build. Merging.
@huston007 thanks ;) When do you plan to release it?
@hekike I have to perform some testing first. You could help me if you try and say it works for you : )
@huston007 I use it about half month in our huge project (codebase about 3mb) and it works. My teammates didn't report any issues related to that.
You can run it on yours project, and test it as well.
@thekip Yep I will. Thank you for the job you've done.
This huge PR brings next improvments:
Tests
First of all i rewrite tests using Tape and change folder structure. It's more convinient way for testing, also such tests more flexible and can be debugged with Node debugger. Bash scripts is not cross-platform solution (Windows does'not support bash scripts without extra tools).
Besides i've added some new test cases. I'll describe this test cases later.
Issues
The main issue i've tried to solve, is duplicating files in sourcemaps (https://github.com/huston007/ng-annotate-loader/issues/24 see last comment, also https://github.com/huston007/ng-annotate-loader/issues/23).
But actually there is a bunch of things cause this issue. Generally, problem is here:
inputSourceMap.sources
should have same path and name asannotateMap.sources
.Otherwise
outputSourceMap
will be have duplicate files in sources.Example:
As you can see in screenshot,
outputSourceMap.sources
has two entries, becuase sources in inputMap and annotateMap have diffrent slahes and path (relative/absoulte)Therefore we see the first problem:
Sourcemap doesn't care about forward slahes
If you are using *nix system you have never got this error. See what mozilla/source-map team think about this https://github.com/mozilla/source-map/issues/91
So solution is simple, we need normalize pathes everewhere.
There is a big problem with accepatance tests, we can't simulate this behaviour, it means somebody on unix system can rewrite something and tests will not report any problems. (i think we need to refactor loader, and write unit test for
mergeMap()
function)Prefixed resource path
Sometimes webpack (or not?), emit map with sources prefixed by loader name:
Actually i don't know when and why it happend. I spend a lot of time to find the reason. But all i found was
awesome-typescript-loader
+tslint
as preloader processed '*.ts' file caused this behaviour.In our project, eslint cuase the same when precessing
*.js
files.I added special test case
typescript
which cover this issue.I was looking for a solution for a long time, i've tried few diffrent approaches, but finally is very simple:
Source map in loader always have just one entry in
sources
and this entry the same to processed file. We override entry, with normalized resource path. Some loaders return sources with relative path and filledsourceRoot
. We clearsourceRoot
, because we override path with absoulte url, and we don't need prefix.Issues with
sourceRoot
SourceMapGenerator
can merge maps even if they have not absolutely the same sources. It can merge relative with absoulte path but only if correct source root is provided.Sourcemaps from
ngAnnotate
always have absolute path, butinputSourceMap.sources
can be diffrent it depend on loader.Sometimes it has relative path + sourceRoot (babel-loader), sometimes only relative path (typescipt-loader), sometimes absolute path.
Solution the same as in previous issue: explicit set absolute path and clear sourceRoot.
I've added test case uglifyjs which cover this issue.
Dependecies
I've updated all dependecies, and update test references (because babel6 generate diffrent output) Also i've added .editorconfig to help writing code in same code style.