write to component.json only on success #169

I got a little annoyed by this issue (it's easy to make the mistake of writing "component install dom" instead of "component install component/dom") so I wrote a fix that seems to work.

However I didn't really research it much, so it's very possible you'd like another solution.