Concepts > Workspace Patterns

Workspace Patterns

Workspace patterns are used to match workspaces when running commands such as run-script or list-workspaces.

Default Matching

By default, workspace patterns match the workspace name or alias, but if a wildcard is provided, it will only match the name.

bw run lint my-name-or-alias "my-name-pattern-*"

However, you can use the following matching specifiers to match workspaces by different criteria:

Matching Specifiers

Name

Match by the workspace name (from package.json). Accepts wildcards.

bw ls name:my-workspace "name:my-workspace-*"
bw run lint "name:my-workspace-*"

Alias

Match by the workspace alias. Accepts wildcards.

bw ls "alias:my-alias-*"
bw run lint "alias:my-alias-b"

Path

Match by the relative workspace path, with glob syntax supported.

bw ls "path:packages/**/*"
bw run lint "path:packages/**/*"

In the API

These same matching patterns can be used in the API.

import { createFileSystemProject } from "bun-workspaces";

const project = createFileSystemProject();

project.findWorkspacesByPattern(
  "name:my-workspace-*", 
  "alias:my-alias-*", 
  "path:packages/**/*"
);

project.runScriptAcrossWorkspaces({
  workspacePatterns: [
    "name:my-workspace-*",
    "alias:my-alias-*",
    "path:packages/**/*",
  ],
  script: "bun lint",
});