{"action":"created","issue":{"url":"https://api.github.com/repos/huston007/ng-annotate-loader/issues/26","repository_url":"https://api.github.com/repos/huston007/ng-annotate-loader","labels_url":"https://api.github.com/repos/huston007/ng-annotate-loader/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/huston007/ng-annotate-loader/issues/26/comments","events_url":"https://api.github.com/repos/huston007/ng-annotate-loader/issues/26/events","html_url":"https://github.com/huston007/ng-annotate-loader/pull/26","id":174061011,"number":26,"title":"Fix sourcemaps errors and update test","user":{"login":"thekip","id":1586852,"avatar_url":"https://avatars.githubusercontent.com/u/1586852?v=3","gravatar_id":"","url":"https://api.github.com/users/thekip","html_url":"https://github.com/thekip","followers_url":"https://api.github.com/users/thekip/followers","following_url":"https://api.github.com/users/thekip/following{/other_user}","gists_url":"https://api.github.com/users/thekip/gists{/gist_id}","starred_url":"https://api.github.com/users/thekip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thekip/subscriptions","organizations_url":"https://api.github.com/users/thekip/orgs","repos_url":"https://api.github.com/users/thekip/repos","events_url":"https://api.github.com/users/thekip/events{/privacy}","received_events_url":"https://api.github.com/users/thekip/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-30T16:10:05Z","updated_at":"2016-08-30T16:16:15Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/huston007/ng-annotate-loader/pulls/26","html_url":"https://github.com/huston007/ng-annotate-loader/pull/26","diff_url":"https://github.com/huston007/ng-annotate-loader/pull/26.diff","patch_url":"https://github.com/huston007/ng-annotate-loader/pull/26.patch"},"body":"This huge PR brings next improvments: \r\n\r\n## Tests\r\n\r\nFirst of all i rewrite tests using [Tape](https://github.com/substack/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). \r\n\r\nBesides i've added some new test cases. I'll describe this test cases later.\r\n\r\n## Issues\r\nThe 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).\r\n\r\nBut actually there is a bunch of things cause this issue. \r\nGenerally, problem is here: \r\n\r\n```js\r\nvar generator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(annotateMap));\r\ngenerator.applySourceMap(new SourceMapConsumer(inputSourceMap), filename);\r\n\r\noutputSourceMap = generator.toJSON();\r\n```\r\n\r\n`inputSourceMap.sources` should have same path and name as `annotateMap.sources`.\r\n\r\nOtherwise `outputSourceMap` will be have duplicate files in sources. \r\n\r\nExample: \r\n\r\n![image](https://cloud.githubusercontent.com/assets/1586852/18095287/2e772662-6edf-11e6-9b7c-6214580c415f.png)\r\n\r\nAs you can see in screenshot, `outputSourceMap.sources` has two entries, becuase sources in inputMap and annotateMap have diffrent slahes and path (relative/absoulte) \r\n\r\nTherefore we see the first problem: \r\n\r\n## Sourcemap doesn't care about forward slahes\r\n\r\nIf 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\r\n\r\nSo solution is simple, we need normalize pathes everewhere. \r\n\r\nThere 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)\r\n\r\n## Prefixed resource path\r\n\r\nSometimes webpack (or not?), emit map with sources prefixed by loader name: \r\n\r\n>node_modules\\tslint-loader\\index.js!c:\\opensource\\ng-annotate-loader\\cases\\typescript\\file-to-annotate.ts\r\n\r\nActually 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.\r\n\r\nIn our project, eslint cuase the same when precessing `*.js` files.\r\n\r\nI added special test case `typescript` which cover this issue.\r\n\r\nI was looking for a solution for a long time, i've tried few diffrent approaches, but finally is very simple: \r\n```js\r\n var filename = normalizePath(this.resourcePath);\r\ninputSourceMap.sourceRoot = '';\r\ninputSourceMap.sources[0] = filename;\r\n```\r\nSource 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. \r\nSome loaders return sources with relative path and filled `sourceRoot`. We clear `sourceRoot`, because we override path with absoulte url, and we don't need prefix.\r\n\r\n## Issues with `sourceRoot`\r\n\r\n`SourceMapGenerator` can merge maps even if they have not absolutely the same sources. \r\nIt can merge relative with absoulte path but only if correct source root is provided. \r\n\r\nSourcemaps from `ngAnnotate` always have absolute path, but `inputSourceMap.sources` can be diffrent it depend on loader.\r\n\r\nSometimes it has relative path + sourceRoot (babel-loader), sometimes only relative path (typescipt-loader), sometimes absolute path. \r\n\r\nSolution the same as in previous issue: explicit set absolute path and clear sourceRoot.\r\n\r\nI've added test case uglifyjs which cover this issue.\r\n\r\n## Dependecies\r\nI've updated all dependecies, and update test references (because babel6 generate diffrent output)\r\nAlso i've added .editorconfig to help writing code in same code style. \r\n"},"comment":{"url":"https://api.github.com/repos/huston007/ng-annotate-loader/issues/comments/243494231","html_url":"https://github.com/huston007/ng-annotate-loader/pull/26#issuecomment-243494231","issue_url":"https://api.github.com/repos/huston007/ng-annotate-loader/issues/26","id":243494231,"user":{"login":"thekip","id":1586852,"avatar_url":"https://avatars.githubusercontent.com/u/1586852?v=3","gravatar_id":"","url":"https://api.github.com/users/thekip","html_url":"https://github.com/thekip","followers_url":"https://api.github.com/users/thekip/followers","following_url":"https://api.github.com/users/thekip/following{/other_user}","gists_url":"https://api.github.com/users/thekip/gists{/gist_id}","starred_url":"https://api.github.com/users/thekip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thekip/subscriptions","organizations_url":"https://api.github.com/users/thekip/orgs","repos_url":"https://api.github.com/users/thekip/repos","events_url":"https://api.github.com/users/thekip/events{/privacy}","received_events_url":"https://api.github.com/users/thekip/received_events","type":"User","site_admin":false},"created_at":"2016-08-30T16:16:14Z","updated_at":"2016-08-30T16:16:14Z","body":"Test failed. Interesting. Webpack Hash in source maps is diffrent... need another way to check sourcemaps valid. Dirty checking files is not good solution."}}
{"actor":{"display_login":"thekip"}}