andrey-skl / ng-annotate-loader

Webpack loader to annotate angular applications
MIT License
120 stars 28 forks source link

If Sourcemap is a String, JSON decode it #47

Closed jaydiablo closed 4 years ago

jaydiablo commented 4 years ago

I was trying to use this loader in a project that uses Webpack 4 and Babel 7, and webpack would fail because the sourcemap wasn't in the expected format:

Syntax Error: Error: .inputSourceMap must be a boolean, object, or undefined

(It appears that this is thrown in Babel, here: https://github.com/babel/babel/blob/master/packages/babel-core/src/config/validation/option-assertions.js#L157)

After some debugging I found that the sourcemap was coming in as a string (JSON encoded string) in this case, which Babel doesn't allow. I've added detection for this, and then JSON decode the string if it's a string.

I had to modify the tests slightly because on my mac the expected was coming back with \r\n line endings in the built code, but just in the typescript test case. I tried modifying typescript to use the LF line ending (via tsconfig.json setting) but that had no effect with awesome-typescript-loader. I tried changing to ts-loader, which does seem to obey the newLine setting, but that opens a whole different can of worms that I didn't want to get into for this (output differed quite a bit with ts-loader, mainly in how it defined the module).

Removed some really old versions of Node from travis.yml as they couldn't even run yarn. Added more up-to-date versions.

jaydiablo commented 4 years ago

Tests passed: https://travis-ci.com/github/diablomedia/ng-annotate-loader/builds/170554990

andrey-skl commented 4 years ago

@jaydiablo thank you!

andrey-skl commented 4 years ago

Published as ng-annotate-loader@0.7.0