Because commas cannot be added to the last element of an object or an array in package.json, the line blame in not preserved; that is, if I have the following in package.json in commit A:
{
"version": "0.0.1"
}
And then in commit B I add another field:
{
"version": "0.0.1",
"main": "index.js"
}
git blame package.json
shows both lines being blamed by commit B. The blame would be preserved if I instead added a comma to the end of the first field definition in commit A:
{
"version": "0.0.1",
}
But this isn't valid JSON, or at least it isn't allowed by npm. Doing this and then running npm install
will raise this error:
npm ERR! install Couldn't read dependencies
npm ERR! Failed to parse json
npm ERR! Unexpected token } ...
Is there a way to get around the npm error? Or is there a clever way of using git blame to see that commit A should really be to blame for the first field?