2020-10-02 17:52:19 -04:00
|
|
|
// write the json back, preserving the line breaks and indent
|
2021-04-15 21:53:45 -04:00
|
|
|
const { promisify } = require('util')
|
2020-10-02 17:52:19 -04:00
|
|
|
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,
|
2021-04-15 21:53:45 -04:00
|
|
|
[kNewline]: newline = '\n'
|
2020-10-02 17:52:19 -04:00
|
|
|
} = 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)
|
|
|
|
}
|