npm.io
1.0.1 • Published 3 years ago

list-workspace

Licence
MIT
Version
1.0.1
Deps
4
Size
9 kB
Vulns
0
Weekly
0
Stars
2

list-workspace

NPM TypeScript

List all packages in a workspace, or all workspaces in a monorepo.

If I should maintain this repo, please ️ GitHub stars

DM me on Twitter if you have questions or suggestions. Twitter


Installation

npm install list-workspace
yarn add list-workspace
pnpm add list-workspace
bun add list-workspace

Usage

import {
  listWorkspaces,
  listWorkspacesPackageJSONs
  listWorkspace,
  listWorkspacePackageJSON
} from "which-pm-lockfile";

/**
 * List all workspace package directories in a monorepo.
 * 
 * Returns the absolute path to each workspace package directory.
 * Returns `undefined` if not in a monorepo.
 * 
 * Example: `["/path/to/packages/foo", "/path/to/packages/bar"]`
 */
const workspaces = await listWorkspaces();

/**
 * List all workspace package package.json files in a monorepo.
 * 
 * Returns the absolute path to each workspace package.json.
 * Returns `undefined` if not in a monorepo.
 * 
 * Example: `["/path/to/packages/foo/package.json", "/path/to/apps/bar/package.json"]`
 */
const workspacesPackageJSONs = await listWorkspacesPackageJSONs();

/**
 * List all package directories in a specific workspace within a monorepo.
 * 
 * Returns the absolute path to each workspace package directory.
 * Returns undefined if not in a monorepo, or if the workspace does not exist.
 * 
 * Example: ["/path/to/packages/foo/package"]
 */
const workspace = await listWorkspace("packages/*");

/**
 * List all package package.jsons in a specific workspace within a monorepo.
 * 
 * Returns the absolute path to each workspace package's package.json.
 * Returns undefined if not in a monorepo, or if the workspace does not exist.
 * 
 * Example: ["/path/to/packages/foo/package/package.json"]
 */
const workspacePackageJSONs= await listWorkspacePackageJSON("packages/*");

Dependenciesdependencies

  • globby: User-friendly glob matching
  • is-monorepo: Check if the working directory is in a monorepo.
  • package-run: Node API for running package.json scripts. Supports yarn, npm, and pnpm.
  • workspace-root: A simple utility to get the workspace root

Dev Dependencies

  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.

License license

MIT

Keywords