2022-11-11 00:44:39 +09:00
|
|
|
import { debugFactory } from './debug'
|
|
|
|
import { writeFileAsync, fileExists } from './utils'
|
|
|
|
|
|
|
|
const debug = debugFactory('update-package')
|
2020-09-04 17:22:15 +09:00
|
|
|
|
|
|
|
export async function updatePackageJson(
|
|
|
|
path: string,
|
|
|
|
partial: Record<string, any>,
|
|
|
|
) {
|
2022-11-11 00:44:39 +09:00
|
|
|
const exists = await fileExists(path)
|
|
|
|
if (!exists) {
|
|
|
|
debug(`File not exists ${path}`)
|
|
|
|
return
|
|
|
|
}
|
2020-09-04 17:22:15 +09:00
|
|
|
const old = require(path)
|
|
|
|
await writeFileAsync(path, JSON.stringify({ ...old, ...partial }, null, 2))
|
|
|
|
}
|