What is @manypkg/find-root?
@manypkg/find-root is an npm package designed to help you find the root directory of a monorepo or a project. This can be particularly useful in monorepo setups where you need to determine the root directory from a nested package.
What are @manypkg/find-root's main functionalities?
Find the root directory of a monorepo
This feature allows you to find the root directory of a monorepo starting from the current working directory. The `findRoot` function will traverse up the directory tree until it finds the root directory.
const findRoot = require('@manypkg/find-root');
const rootDir = findRoot(process.cwd());
console.log(rootDir);
Find the root directory with a custom start path
This feature allows you to specify a custom start path from which to begin the search for the root directory. This can be useful if you want to find the root directory from a specific location in your project.
const findRoot = require('@manypkg/find-root');
const rootDir = findRoot('/path/to/start');
console.log(rootDir);
Other packages similar to @manypkg/find-root
find-root
The `find-root` package is a similar utility that helps you find the root directory of a project by looking for a specific file (like `package.json`). It is simpler and more focused on finding the root directory based on the presence of a file, whereas @manypkg/find-root is more tailored for monorepo setups.
pkg-dir
The `pkg-dir` package finds the root directory of a Node.js project by looking for the nearest `package.json` file. It is similar to @manypkg/find-root but is more general-purpose and not specifically designed for monorepos.
@manypkg/find-root
Find the root of a monorepo with Yarn workspaces, Bolt, Lerna, pnpm or Rush
Install
yarn add @manypkg/find-root
Usage
import { findRoot, findRootSync } from "@manypkg/find-root";
let dir = await findRoot(process.cwd());
let dir = findRootSync(process.cwd());