import { normalize, relative } from "node:path";
import fs from "fs-extra";
import { switcher } from "js-runtime";

//#region src/fs/clean.ts
async function clean(path$1) {
	return fs.remove(path$1);
}

//#endregion
//#region src/fs/exists.ts
const reader$1 = switcher({
	node: async (path$1) => {
		return fs.pathExists(path$1);
	},
	bun: async (path$1) => {
		return Bun.file(path$1).exists();
	}
}, "node");
const syncReader$1 = switcher({
	node: (path$1) => {
		return fs.pathExistsSync(path$1);
	},
	bun: () => {
		throw new Error("Bun cannot read sync");
	}
}, "node");
async function exists(path$1) {
	return reader$1(path$1);
}

//#endregion
//#region src/fs/read.ts
const reader = switcher({
	node: async (path$1) => {
		return fs.readFile(path$1, { encoding: "utf8" });
	},
	bun: async (path$1) => {
		return Bun.file(path$1).text();
	}
}, "node");
const syncReader = switcher({
	node: (path$1) => {
		return fs.readFileSync(path$1, { encoding: "utf8" });
	},
	bun: () => {
		throw new Error("Bun cannot read sync");
	}
}, "node");
async function read(path$1) {
	return reader(path$1);
}
function readSync(path$1) {
	return syncReader(path$1);
}

//#endregion
//#region src/fs/unlink.ts
async function unlink(path$1) {
	return fs.unlink(path$1);
}

//#endregion
//#region src/fs/utils.ts
function slash(path$1, platform = "linux") {
	const isWindowsPath = /^\\\\\?\\/.test(path$1);
	const normalizedPath = normalize(path$1);
	if (["linux", "mac"].includes(platform) && !isWindowsPath) return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
	return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
}
function getRelativePath(rootDir, filePath, platform = "linux") {
	if (!rootDir || !filePath) throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
	const relativePath = relative(rootDir, filePath);
	const slashedPath = slash(relativePath, platform);
	if (slashedPath.startsWith("../")) return slashedPath;
	return `./${slashedPath}`;
}

//#endregion
//#region src/fs/types.ts
var types_exports = {};

//#endregion
//#region src/fs/index.ts
function trimExtName(text) {
	return text.replace(/\.[^/.]+$/, "");
}

//#endregion
export { clean, exists, getRelativePath, read, readSync, trimExtName, types_exports, unlink };
//# sourceMappingURL=fs-BNC5Fj6t.js.map