UNPKG

@storm-software/eslint

Version:

⚡ A package containing the base ESLint configuration used by Storm Software across many projects.

92 lines (89 loc) 2.54 kB
import { correctPaths } from "./chunk-G7QVU75O.js"; import { __name } from "./chunk-SHUYVCID.js"; // src/utils/find-workspace-root.ts import { existsSync } from "node:fs"; import { join } from "node:path"; var MAX_PATH_SEARCH_DEPTH = 30; var depth = 0; function findFolderUp(startPath, endFileNames = [], endDirectoryNames = []) { const _startPath = startPath ?? process.cwd(); if (endDirectoryNames.some((endDirName) => existsSync(join(_startPath, endDirName)))) { return _startPath; } 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, endDirectoryNames); } return void 0; } __name(findFolderUp, "findFolderUp"); var rootFiles = [ "storm-workspace.json", "storm-workspace.json", "storm-workspace.yaml", "storm-workspace.yml", "storm-workspace.js", "storm-workspace.ts", ".storm-workspace.json", ".storm-workspace.yaml", ".storm-workspace.yml", ".storm-workspace.js", ".storm-workspace.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" ]; var rootDirectories = [ ".storm-workspace", ".nx", ".github", ".vscode", ".verdaccio" ]; 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, rootDirectories)); } __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 };