import { cloudflare } from "@cloudflare/vite-plugin";
import path from "pathe";
import { getDefaultConfigPath, getDefaultPersistPath, validateConfigPath, } from "../miniflare/paths.js";
const alchemy = (config) => {
    const persistState = config?.persistState ?? {
        path: typeof config?.persistState === "object"
            ? config.persistState.path
            : // persist path should default to the /.alchemy/miniflare/v3
                getDefaultPersistPath(),
    };
    if (typeof persistState === "object" && persistState.path.endsWith("v3")) {
        persistState.path = path.dirname(persistState.path);
    }
    return [
        cloudflare({
            ...config,
            configPath: validateConfigPath(
            // config path doesn't need to be in the root, it can be in the app dir
            config?.configPath ?? getDefaultConfigPath()),
            persistState,
        }),
        {
            name: "alchemy:dev",
            config() {
                const allowedHosts = [];
                if (process.env.ALCHEMY_DEV_TUNNEL === "quick") {
                    // leading dot = match all subdomains
                    allowedHosts.push(".trycloudflare.com");
                }
                return {
                    server: {
                        watch: {
                            ignored: ["**/.alchemy/**"],
                        },
                        ...(allowedHosts.length ? { allowedHosts } : {}),
                    },
                };
            },
        },
    ];
};
export default alchemy;
//# sourceMappingURL=plugin.js.map