Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@manypkg/get-packages

Thinkmill6.8mMIT2.2.2TypeScript support: included

A simple utility to get the packages from a monorepo, whether they're using Yarn, Bolt, Lerna, pnpm or Rush

readme

@manypkg/get-packages

A simple utility to get the packages from a monorepo, whether they're using Yarn, Bolt, Lerna, pnpm or Rush

This library exports getPackages and getPackagesSync. It is intended mostly for use of developers building tools that want to support different kinds of monorepos as an easy way to write tools without having to write tool-specific code. It supports Yarn, Bolt, Lerna, pnpm, Rush and single-package repos(where the only package is the the same as the root package). This library uses @manypkg/find-root to search up from the directory that's passed to getPackages or getPackagesSync to find the project root.

import { getPackages, getPackagesSync } from "@manypkg/get-packages";

const { tool, packages, rootPackage, rootDir } = await getPackages(process.cwd());
const { tool, packages, rootPackage, rootDir } = getPackagesSync(process.cwd());

// From @manypkg/tools

interface Tool {
    readonly type: string;
    isMonorepoRoot(directory: string): Promise<boolean>;
    isMonorepoRootSync(directory: string): boolean;
    getPackages(directory: string): Promise<Packages>;
    getPackagesSync(directory: string): Packages;
}

interface Package {
    packageJson: PackageJSON;
    dir: string;
    relativeDir: string;
}

interface Packages {
  tool: Tool;
  packages: Package[];
  rootPackage?: Package;
  rootDir: string;
}

changelog

@manypkg/get-packages

2.2.2

Patch Changes

2.2.1

Patch Changes

2.2.0

Minor Changes

Patch Changes

2.1.0

Minor Changes

  • #167 bf586f5 Thanks @elliot-nelson! - The getPackages and getPackagesSync methods now take an optional list of Tool implementations, allowing the caller to restrict the desired types of monorepo discovered, or provide a custom monorepo tool implementation.

Patch Changes

2.0.0

Major Changes

  • #165 7b9c4f6 Thanks @Andarist! - Removed support for Bolt monorepos.

  • #162 f046017 Thanks @Andarist! - Increased the transpilation target of the source files to `node@14.x. At the same time added this aspackage.json#engines` to explicitly declare the minimum node version supported by this package.

  • #151 a01efc9 Thanks @elliot-nelson! - The get-packages package now returns a slightly different structure. The old tool string has been replaced with a tool object, using the new Tool interface provided by @manypkg/tools. Each Package now contains both the absolute directory and relative directory path. Last, the root package has been renamed rootPackage and is optional, to support monorepos that do not contain a root package.

Patch Changes

1.1.3

Patch Changes

  • #122 7bd4f34 Thanks @fz6m! - Fixed getting correct packages in pnpm workspaces with exclude rules.

1.1.2

Patch Changes

1.1.1

Patch Changes

1.1.0

Minor Changes

Patch Changes

1.0.1

Patch Changes

  • 596d821 #55 Thanks @Andarist! - Ignore node_modules when glob searching for packages. This fixes an issue with package cycles.

1.0.0

Major Changes

  • 72a0112 #47 Thanks @tarang9211! - Initial release of @manypkg/get-packages. If you're migrating from get-workspaces, the most important changes are:

    • getPackages is a named export
    • getPackages only accepts a single argument which is the directory to search from
    • getPackages returns an object which has tool, packages and root
    • getPackages will search up from the directory passed in to find a project root rather than requiring the project root to be passed in
    • the package objects no longer have a name field and the config property has been renamed to packageJson

    See the README for more information on the new API

Patch Changes