import { P as useTmpDirectory, z as Logger } from "./util-CsmUMRtR.js";
import upath from "upath";
import { dim } from "yoctocolors";
import { createLogger, mergeConfig, resolveConfig } from "vite";
//#region src/config/vite.ts
const defaultConfigEnv = {
	preview: {
		command: "serve",
		mode: "development",
		isPreview: false
	},
	build: {
		command: "serve",
		mode: "production",
		isPreview: true
	}
};
async function resolveViteConfig({ serverRootDir, server, viteConfig, viteConfigFile, logLevel, workspaceDir, mode }) {
	const viteLogger = createLogger({
		silent: "silent",
		info: "info",
		verbose: "info",
		debug: "info"
	}[logLevel], { allowClearScreen: false });
	const warnedMessages = /* @__PURE__ */ new Set();
	viteLogger.info = (msg) => {
		Logger.logInfo(`${dim("[vite]")} ${msg}`);
	};
	viteLogger.warn = (msg) => {
		viteLogger.hasWarned = true;
		Logger.logWarn(`${dim("[vite]")} ${msg}`);
	};
	viteLogger.warnOnce = (msg) => {
		if (warnedMessages.has(msg)) return;
		viteLogger.hasWarned = true;
		Logger.logWarn(`${dim("[vite]")} ${msg}`);
		warnedMessages.add(msg);
	};
	viteLogger.error = (msg) => {
		viteLogger.hasWarned = true;
		Logger.logError(`${dim("[vite]")} ${msg}`);
	};
	const root = typeof serverRootDir === "string" ? serverRootDir : (await useTmpDirectory())[0];
	const cacheDir = typeof serverRootDir === "string" ? upath.join(workspaceDir, ".vite") : upath.join(root, ".vite");
	return resolveConfig(mergeConfig(viteConfig ?? {}, {
		server,
		preview: server,
		configFile: viteConfigFile === true ? void 0 : viteConfigFile,
		root,
		customLogger: viteLogger,
		cacheDir
	}), defaultConfigEnv[mode].command, defaultConfigEnv[mode].mode, "development", defaultConfigEnv[mode].isPreview);
}
//#endregion
export { resolveViteConfig as t };

//# sourceMappingURL=vite-C-mM5_eo.js.map