Skip to content

alienfast/find-monorepo-root

Repository files navigation

MIT Version CI PRs Welcome

@alienfast/find-monorepo-root

Find the root directory of a monorepo using any of the following strategies:

  • Lerna
  • Yarn
  • Bolt
  • pnpm
  • npm

Install

yarn install @alienfast/find-monorepo-root

Usage

npx

For easy use in a shell script anywhere in your monorepo, execute with the -y

npx -y @alienfast/find-monorepo-root
# output: /Users/rosskevin/projects/archetype

or

#!/usr/bin/env bash

ROOT=`npx -y @alienfast/find-monorepo-root`

echo "My monorepo root is ${ROOT}"

Api

import { findMonorepoRoot } from '@alienfast/find-monorepo-root'
const cwd = process.cwd()

console.log(await findMonorepoRoot(cwd))
// {
//   strategy: 'lerna', // 'bolt' | 'yarn' | 'pnpm' | 'lerna' | 'npm'
//   dir: '/Users/rosskevin/projects/archetype',     // the monorepo root directory
// }

Contributing

PRs are accepted! This project is configured with auto, so feel free to submit a PR and auto will automatically create a canary release for you to try out.

Prior art

This was originally forked from https://github.com/bubkoo/find-monorepo-root/ because it a) did not work for me in it's current form; and b) I wanted to exec it simply with npx. Thanks to the original author and contributors.