Contents
Introduction
Lists all packages in a monorepo.
Includes directory, name, and contents of package.json. Order is non-deterministic.
Can be called from any location inside a monorepo.
Supported Package Managers
Package managers that are supported for finding/parsing packages are:
Install
npm i packages-list
Example
Given file structure
/
└─┬ packages
├─┬ my-package-a
│ └── package.json
├─┬ my-package-b
│ └── package.json
└─┬ my-package-c
└── package.json
import { listPackages } from 'packagesList';
const packages = await listPackages();
console.log(packages);
// [
// {
// "directory": "/packages/my-package-a",
// "name": "my-package-a",
// "packageJson": { "name": "my-package-a" }
// },
// {
// "directory": "/packages/my-package-b",
// "name": "my-package-b",
// "packageJson": { "name": "my-package-b" }
// },
// {
// "directory": "/packages/my-package-c",
// "name": "my-package-c",
// "packageJson": { "name": "my-package-c" }
// }
// ]
Usage
packages-list
is an ESM module. That means it must be import
ed. To load from a CJS module, use dynamic import const { listPackages } = await import('packages-list');
.
API
listPackages(options?)
Returns a promise that resolves to an array of packages. Every package contains:
{
"directory": "string",
"name": "string",
"packageJson": { "name": "string", "version": "..." }
}
options
-
cwd
- Type:
string
orURL
- optional, defaults to
process.cwd()
- Directory to use as base directory.
- See
parse-cwd
.
- Type:
-
manager
- Specify package manager to use
-
'lerna'
|'npm'
|'nx'
|'rush'
|'yarn'
- If omitted, will try all and take first found
- e.g. would use
lerna.json
to load packages if found, but can be forced to use npm workspaces ifmanager = 'npm'
- e.g. would use