read-workspaces
v1.2.2
Published
Read all package.json files in a workspace
Downloads
7,782
Readme
read-workspaces
Resolves all package.json
files of a workspace setup.
Supports both npm / yarn style workspace definitions and pnpm style.
Usage
Simple
import { readWorkspaces } from 'read-workspaces';
for await (const { cwd, pkg, workspace } = readWorkspaces()) {
// ...
}
API
readWorkspaces([options])
options.cwd='.'
: Astring
pointing to the path of the module to look up thepackage.json
and installed modules foroptions.ignorePaths
: An array of strings,string[]
, with paths to ignore during the lookup of workspacesoptions.includeWorkspaceRoot=true
: When set tofalse
the workspace root will not be returned. Equivalent tonpm --include-workspace-root
but with different default.options.skipWorkspaces
: When set totrue
, no workspace lookup will occur. Equivalent tonpm --workspaces
but with different default.options.workspace
: An array of strings,string[]
, that should either match the name of a workspace or its path / path prefix. Narrows returned workspaces to those matching the provided strings. If a requested workspace can't be found, then an error will be thrown when the generator completes. Equivalent to npm'snpm --workspace
/npm -w
.
Returns
AsyncGenerator
that yields the workspace root initially (unless its excluded) and then each matching workspaces
cwd
: thestring
path to the workspace / rootpkg
: thepackage.json
content of the workspace / rootworkspace
: thestring
name of the workspace (not set on the root)
Used by
Similar modules
read-pkg
– similar functionality but reads a single package