Repository navigation
fix: don't add comments in json files - #922
alan-agius4 wants to merge 1 commit into
Conversation
evmar
left a comment
There was a problem hiding this comment.
Nice, thanks for the patch!
eb9cc36 to
a66b24f
Compare
a66b24f to
05bb063
Compare
05bb063 to
0a1c079
Compare
0a1c079 to
c14de3c
Compare
|
Can someone please review and merge this? It's breaking Angular library compilation, too, if it imports JSON files: The comment on top of the file breaks rollup-plugin-json. Comments in JSON files aren't allowed to begin with, this tool actually adds comments to JSON, instantly invalidating the format. Please prioritize this. Thank you! |
|
@vikerman is taking a look at why these dependencies keep cropping up. |
|
Any progress on this? The behavior seems to have remained the same. |
|
I'm afraid nobody is currently working on this. Solving this problem also
doesn't make sense - there's no way to import `.json` files like this in
Closure Compiler, and the sole purpose of `tsickle` is to annotate files
for Closure Compiler.
So I think the Real Bug (tm) is that you somehow depend on tsickle, which
you should not. That's either an Angular problem (@alexeagle?) or a problem
in your local setup though.
|
|
@mprobst, TypeScript allows to import json as modules; the problem is most likely due that users are using this TSC feature with tsickle in ngpackagr, since in ng-packagr tsickle is used to solve the TDZ of Angular’s forwardRef. |
|
ngpackagr should not use tsickle unless the code it emits is intended to go
through Closure Compiler. There are many, many limitations in tsickle that
are purely there to deal with Closure Compiler. You really, really don't
want to use this tool unless you're specifically targeting Closure.
|
|
I am getting more keen into adding the transformer in ngpackagr similar to what was done in the CLI |
|
@mprobst Thanks for your reply. My setup is simply what Angular offers for library compilation and packaging via ngpackagr, as @alan-agius4 also mentioned. Regardless of the use case, couldn't tsickle simply be prevented to annotate JSON files at all, in no circumstance, since that is against the JSON standard anyway? |
|
You could do that, but it won't fix your problem. Your problem is that
you're using tsickle in a place where you really, really should not. It
brings a host of other issues as well that you might just not have noticed
yet.
|
|
Thing is, I'm not explicitly using tsickle, it is apparently used by Angular to compile and package libraries. However, not allowing tsickle to add comments to JSON (and breaking the JSON spec) would actually solve my problem, since the process fails when invalid JSON comes down the pipe (namely in the Rollup JSON plugin). I have manually edited said plugin to cleanup that tsickle comment, and the compilation passes like a charm. I am certain you are right and there may be other, hidden, implications of this, but for now I strongly believe that simply not allowing tsickle to corrupt valid JSON with comments, under any circumstances, would go a long way. |
|
The PR from @alan-agius4 is addressing just that (avoid adding comments to any JSON file) in a straightforward way, as far as I can tell, it simply needs someone to review and merge. |
|
What does Closure compiler do when you tell it to import a json file? I think it will fail, won't it? |
|
No news on this? Basically one cannot build an Angular library if it happens to import JSON files because of this issue, as simple as that. Would not allowing tsickle corruption of JSON files with comments under any circumstance be too far fetched? |
|
Rereading the above comments: I think the conclusion is that if you get into this state, something has gone wrong with your app configuration. Another way of saying this is that the correct fix for your problem is to not use tsickle. |
|
re-read what @alan-agius4 said above - ng-packagr is stuck using tsickle because it has a needed feature (decorator downleveling that doesn't introduce a temporal dead zone) but it should not - we ought to have implemented decorator downleveling in a different place (a typescript CustomTransformer as well as something to fix up JS files in node_modules) - @clydin did a hack to port the feature into the Angular webpack loader so that the tsickle dependency was removed from Angular apps, but @alan-agius4 proposes that we also pull it into ng-packagr in order to remove the tsickle dependency from Angular libraries. |
|
@evmar My configuration is the default, generated with the ng CLI, I did not do any customization, I did not chose to use tsickle. As I said before, at no point did I explicitly involve tsickle. There's nothing I can do there, as far as I can tell. @alexeagle Thanks for your reply. Does this mean said "hack" will at some point fix ng-packagr in this respect, by making it not use tsickle anymore? |
|
I referenced ng-packagr/ng-packagr#1400 - that's the actual bug I'll leave it up to Martin and Evan if they want to close this PR |
|
@alexeagle Thanks for that, hopefully it will sort out this issue. Until then I'm stuck with manually editing the Rollup JSON plugin to remove the JSON comment every time yarn overwrites it with the original. |
|
The fix doesn't seem to bad so if doing the wrong thing here is the best place to fix all the other pieces, we may as well do it I guess. But now that I think about it: if we do fix this in tsickle, it would only show up in a newer Angular release, right? And in that case you might as well be using ivy which doesn't involve this(?). Also I vaguely recall @alexeagle making the tsickle dep toggleable at runtime or something. Is it possible for @tgv1975 to hand-edit a config file somewhere to turn it off? (Sorry in advance for my really vague comments here, I don't know much about Angular.) |
|
Nope, in this case it's not user controlled, the ng-packagr tool always does this. |
|
Actually it is under the user controller.
Tsickle can be disable by setting the `annotateForClosureCompiler` compiler
option to false
…On Fri, 13 Sep 2019 at 18:49, Alex Eagle ***@***.***> wrote:
Nope, in this case it's not user controlled, the ng-packagr tool always
does this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#922?email_source=notifications&email_token=AEF74WVB7L6J7YSCWCSDQ33QJPADLA5CNFSM4F6JQC32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6VSVHQ#issuecomment-531311262>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEF74WSNDW35ZRYMUBLHBQTQJPADLANCNFSM4F6JQC3Q>
.
|
|
… On Fri, 13 Sep 2019 at 18:49, Alex Eagle ***@***.***> wrote:
Nope, in this case it's not user controlled, the ng-packagr tool always
does this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#922?email_source=notifications&email_token=AEF74WVB7L6J7YSCWCSDQ33QJPADLA5CNFSM4F6JQC32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6VSVHQ#issuecomment-531311262>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEF74WSNDW35ZRYMUBLHBQTQJPADLANCNFSM4F6JQC3Q>
.
|
|
Great stuff, guys, thank you! @alan-agius4 I found the @evmar I suppose no tool, ever, should corrupt JSON with comments, regardless of the context, so maybe having this fix (not parsing JSON files at all) is not ill-advised after all, and may prevent unforeseen such incidents down the road. |
|
In all fairness I don’t think it’s a good idea to use json modules in web this is because they are not supported natively by the browsers and you’ll always be dependent on a bundler for your code to run. I believe that resolveJsonModules was more intended for node applications. In most cases you should use an Object Literal instead of a JSON module. |

TypeScript 2.9 introduced the
resolveJsonModulefeature, howevertsicklewill parse json files add the overview comment will will make them invalid json files.Example:
This change will make sure that
.jsonfiles are not parsed.