Concepts > Workspace Dependencies

Workspaces can depend on other workspaces and import/export code between them. This is a native capability of workspaces in Bun.

For example, this might be some workspace's package.json file, where my-workspace-a depends on my-workspace-b:

{
  "name": "my-workspace-a",
  "dependencies": {
    "my-workspace-b": "workspace:*"
  }
}

Code in my-workspace-a can then import code from my-workspace-b like any other dependency:

import { myFunction } from "my-workspace-b";

myFunction();

Running Scripts in Dependency Order

When running scripts via the CLI or API, workspaces can be run in dependency order.

This means that a workspace's script will wait until any workspaces it depends on have completed. This is similar to how Bun's --filter flag works, though for bun-workspaces, this behavior is opt-in.

This can be useful in situations where one workspace depends on another workspace's output, such as a build script's output.

CLI Example

bw run my-script --dep-order

# Run all scripts even if a dependency fails
bw run my-script --dep-order --ignore-dep-failure

API Example


import { createFileSystemProject } from "bun-workspaces";

const project = createFileSystemProject();

project.runScriptAcrossWorkspaces({
  script: "my-script",
  dependencyOrder: true,
  ignoreDependencyFailure: true,
});