// packages/config-tools/src/utilities/correct-paths.ts
var correctPaths = (path) => {
  if (!path) {
    return "";
  }
  if (!path.toUpperCase().startsWith("C:") && path.includes("\\")) {
    path = `C:${path}`;
  }
  return path.replaceAll("\\", "/");
};

// packages/config-tools/src/utilities/find-up.ts
import { existsSync } from "node:fs";
import { join } from "node:path";
var MAX_PATH_SEARCH_DEPTH = 30;
var depth = 0;
function findFolderUp(startPath, endFileNames) {
  const _startPath = startPath ?? process.cwd();
  if (endFileNames.some((endFileName) => existsSync(join(_startPath, endFileName)))) {
    return _startPath;
  }
  if (_startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
    const parent = join(_startPath, "..");
    return findFolderUp(parent, endFileNames);
  }
  return void 0;
}

// packages/config-tools/src/utilities/find-workspace-root.ts
var rootFiles = [
  "storm.json",
  "storm.json",
  "storm.yaml",
  "storm.yml",
  "storm.js",
  "storm.ts",
  ".storm.json",
  ".storm.yaml",
  ".storm.yml",
  ".storm.js",
  ".storm.ts",
  "lerna.json",
  "nx.json",
  "turbo.json",
  "npm-workspace.json",
  "yarn-workspace.json",
  "pnpm-workspace.json",
  "npm-workspace.yaml",
  "yarn-workspace.yaml",
  "pnpm-workspace.yaml",
  "npm-workspace.yml",
  "yarn-workspace.yml",
  "pnpm-workspace.yml",
  "npm-lock.json",
  "yarn-lock.json",
  "pnpm-lock.json",
  "npm-lock.yaml",
  "yarn-lock.yaml",
  "pnpm-lock.yaml",
  "npm-lock.yml",
  "yarn-lock.yml",
  "pnpm-lock.yml",
  "bun.lockb"
];
function findWorkspaceRootSafe(pathInsideMonorepo) {
  if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
    return correctPaths(
      process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH
    );
  }
  return correctPaths(
    findFolderUp(pathInsideMonorepo ?? process.cwd(), rootFiles)
  );
}
function findWorkspaceRoot(pathInsideMonorepo) {
  const result = findWorkspaceRootSafe(pathInsideMonorepo);
  if (!result) {
    throw new Error(
      `Cannot find workspace root upwards from known path. Files search list includes: 
${rootFiles.join(
        "\n"
      )}
Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
    );
  }
  return result;
}
export {
  findWorkspaceRoot,
  findWorkspaceRootSafe
};
