import { t as writeFileAtomic } from "./atomic-write-8yjqqLtS.js";
import { t as withFileQueue } from "./write-queue-IbsAjUnh.js";
import fs from "fs";
//#region src/core/file-lock.ts
async function withJsonFile(filePath, updater) {
	return withFileQueue(filePath, async () => {
		let current = null;
		if (fs.existsSync(filePath)) try {
			current = JSON.parse(fs.readFileSync(filePath, "utf-8"));
		} catch {
			current = null;
		}
		const next = await updater(current);
		writeFileAtomic(filePath, JSON.stringify(next, null, 2));
		return next;
	});
}
//#endregion
export { withJsonFile as t };

//# sourceMappingURL=file-lock-CcHotQkZ.js.map