blob: 30ca1af0f19edcf7035c83dfcfe8642ed89dd472 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
// write the json back, preserving the line breaks and indent
const {promisify} = require('util')
const writeFile = promisify(require('fs').writeFile)
const kIndent = Symbol.for('indent')
const kNewline = Symbol.for('newline')
module.exports = async (path, pkg) => {
const {
[kIndent]: indent = 2,
[kNewline]: newline = '\n',
} = pkg
delete pkg._id
const raw = JSON.stringify(pkg, null, indent) + '\n'
const data = newline === '\n' ? raw : raw.split('\n').join(newline)
return writeFile(path, data)
}
|