import {
  findFolderUp
} from "./chunk-HBVGMJMF.js";
import {
  correctPaths
} from "./chunk-NLLVE3DA.js";
import {
  __name,
  init_esm_shims
} from "./chunk-BFNZYC5O.js";

// src/utilities/find-workspace-root.ts
init_esm_shims();
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));
}
__name(findWorkspaceRootSafe, "findWorkspaceRootSafe");
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;
}
__name(findWorkspaceRoot, "findWorkspaceRoot");

export {
  findWorkspaceRootSafe,
  findWorkspaceRoot
};
