2020-10-02 17:52:19 -04:00
|
|
|
// write the json back, preserving the line breaks and indent
|
2024-05-30 04:21:05 -07:00
|
|
|
const { writeFile } = require('node:fs/promises')
|
2020-10-02 17:52:19 -04:00
|
|
|
const kIndent = Symbol.for('indent')
|
|
|
|
const kNewline = Symbol.for('newline')
|
|
|
|
|
|
|
|
module.exports = async (path, pkg) => {
|
|
|
|
const {
|
|
|
|
[kIndent]: indent = 2,
|
2022-01-14 19:42:48 +02: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)
|
|
|
|
}
|