package
Read all package.json files in a workspace — supports npm, Yarn, Bun, pnpm, and Deno
npm install read-workspacesGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Resolves all package.json files of a workspace setup.
import { readWorkspaces } from 'read-workspaces';
for await (const { cwd, pkg, workspace } = readWorkspaces()) {
// ...
}import { readWorkspaces } from 'read-workspaces';
const workspaces = await Array.fromAsync(readWorkspaces());| Package Manager / Runtime | Workspace Configuration | Detection |
|---|---|---|
| npm | package.json "workspaces" | Direct |
| Yarn | package.json "workspaces" | Direct (same format as npm) |
| Bun | package.json "workspaces" | Direct (same format as npm) |
| pnpm | pnpm-workspace.yaml |
All workspace members must have a package.json file. For Deno workspaces, the workspace structure is read from deno.json, but each member's package.json is used for the resolved package data.
Detection priority: npm/Yarn/Bun (package.json workspaces) > pnpm > Deno.
readWorkspaces([options])options.cwd='.': A string pointing to the path of the module to look up the package.json and installed modules foroptions.ignorePaths: An array of strings, string[], with paths to ignore during the lookup of workspacesoptions.includeWorkspaceRoot=true: When set to false the workspace root will not be returned. Equivalent to npm --include-workspace-root but with different default.options.skipWorkspaces: When set to true, no workspace lookup will occur. Equivalent to npm --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's npm --workspace / npm -w.AsyncGenerator that yields the workspace root initially (unless its excluded) and then each matching workspaces
cwd: the string path to the workspace / rootpkg: the package.json content of the workspace / rootworkspace: the string name of the workspace (not set on the root)read-pkg – similar functionality but reads a single packagepackageManager, engines.pnpm, or pnpm field in root package.json |
| Deno | deno.json "workspace" | Presence of deno.json with a workspace array. Only standard JSON is supported — deno.jsonc files with comments are not parsed. |
Estimated unpacked size across 34 packages.
6.4 MB
Includes dependencies.
4 direct dependencies.
^10.1.0
10.1.0
^5.0.0
5.0.0
^6.0.0
6.0.0
^1000.3.0
1000.3.1