const require_chunk = require('./chunk-CZg_9w7l.cjs');
let node_path = require("node:path");
node_path = require_chunk.__toESM(node_path);
let fs_extra = require("fs-extra");
fs_extra = require_chunk.__toESM(fs_extra);
let js_runtime = require("js-runtime");
js_runtime = require_chunk.__toESM(js_runtime);

//#region src/fs/write.ts
const writer = (0, js_runtime.switcher)({
	node: async (path, data, { sanity }) => {
		try {
			if ((await fs_extra.default.readFile((0, node_path.resolve)(path), { encoding: "utf-8" }))?.toString() === data?.toString()) return;
		} catch (_err) {}
		await fs_extra.default.outputFile((0, node_path.resolve)(path), data, { encoding: "utf-8" });
		if (sanity) {
			const savedData = await fs_extra.default.readFile((0, node_path.resolve)(path), { encoding: "utf-8" });
			if (savedData?.toString() !== data?.toString()) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
			return savedData;
		}
		return data;
	},
	bun: async (path, data, { sanity }) => {
		try {
			await Bun.write((0, node_path.resolve)(path), data);
			if (sanity) {
				const savedData = await Bun.file((0, node_path.resolve)(path)).text();
				if (savedData?.toString() !== data?.toString()) throw new Error(`Sanity check failed for ${path}\n\nData[${path.length}]:\n${path}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
				return savedData;
			}
			return data;
		} catch (e) {
			console.error(e);
		}
	}
}, "node");
async function write(path, data, options = {}) {
	if (data.trim() === "") return;
	return writer(path, data.trim(), options);
}

//#endregion
Object.defineProperty(exports, 'write', {
  enumerable: true,
  get: function () {
    return write;
  }
});
//# sourceMappingURL=write-BJfM7G1_.cjs.map