Can I make npm install follow a certain package.json format?

After digging through the npm source, it unfortunately appears the answer to my question is definitely "no". When npm install is executed with one of the "save" options, the following happens:

fs.readFile(saveTarget, function (er, data) {
  try {
    data = JSON.parse(data.toString("utf8"))
  } catch (ex) {
    er = ex
  }
  // ...
  data = JSON.stringify(data, null, 2) + "\n"
  fs.writeFile(saveTarget, data, function (er) {
    cb(er, installed, tree, pretty)
  })
})

The important line is the call to JSON.stringify. When invoking stringify with the third argument, the returned string indentation is formatted with the specified number of spaces.

Since there is no way to customise the value used by npm internally, this behaviour is currently non-configurable.


Fixed in 64b67f0 and npm 5...

https://github.com/npm/npm/issues/4718#issuecomment-307142397

enter image description here

Tags:

Node.Js

Npm