import { AsyncLocalStorage } from "node:async_hooks";
// biome-ignore lint/style/noRestrictedImports: I/O is acceptable here
import { existsSync } from "node:fs";
import path from "pathe";
import { findWorkspaceRootSync } from "../../util/find-workspace-root.js";
import { ALCHEMY_ROOT } from "../../util/root-dir.js";
const dynamicImportContext = new AsyncLocalStorage();
/**
 * Used to disable path validation during dynamic imports.
 */
export const withSkipPathValidation = (callback) => {
    return dynamicImportContext.run(true, callback);
};
export const getDefaultConfigPath = (rootDir = process.cwd()) => {
    return path.join(rootDir, ".alchemy", "local", "wrangler.jsonc");
};
export const getDefaultPersistPath = (rootDir = ALCHEMY_ROOT) => {
    const workspaceRoot = findWorkspaceRootSync(rootDir);
    return path.join(workspaceRoot, ".alchemy", "miniflare", "v3");
};
export const validateConfigPath = (path, throws = true) => {
    if (!existsSync(path)) {
        warnOrThrow(`The Wrangler config path, "${path}", could not be found. Please run \`alchemy dev\` or \`alchemy deploy\` to create it.`, throws);
    }
    return path;
};
const warned = new Set();
const warnOrThrow = (message, throws) => {
    if (dynamicImportContext.getStore()) {
        return;
    }
    if (throws) {
        throw new Error(message);
    }
    if (!warned.has(message)) {
        console.warn(message);
        warned.add(message);
    }
};
//# sourceMappingURL=paths.js.map