Concept: Workspace Dependencies
Overview
Workspaces can depend on other workspaces and import/export code between them.
pacwich does not perform source code analysis to determine dependencies. This makes creating
the graph of workspaces computationally fast and cheap, relying instead on explicit
package.json dependencies (using "workspace:*" for bun and pnpm or "*" for npm).
In Bun and pnpm, workspaces must declare each other as dependencies to share code, which is ideal,
but npm does not require this. The verify command can help identify missing dependencies
for npm by attempting to find imports/exports that reference other workspaces.
Setting up Dependencies - Example
Here is the basic structure of workspace dependencies:
package.json{
"name": "my-project-root",
"workspaces": [
"packages/*"
]
}packages/workspace-a/package.json, whereworkspace-a exports some code from its index.ts{
"name": "workspace-a",
"type": "module",
"main": "index.ts"
}packages/workspace-b/package.json: JS/TS files in this workspace can import from "workspace-a".{
"name": "workspace-b",
"dependencies": {
"workspace-a": "workspace:*"
}
}Workspace Dependency Rules
You can set rules to allow or deny other workspaces as dependencies in a workspace's configuration, set by workspace patterns.
Use allowPatterns to define which dependencies are permitted or denyPatterns to forbid specific ones. When both are present,
denyPatterns will further filter the subset already permitted by allowPatterns.
For example, you may disallow dependencies with the tag "backend" for a frontend workspace with denyPatterns: ["tag:backend"].
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 pacwich,
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
pacwich run my-script --dep-order
# Run all scripts even if a dependency fails
pacwich run my-script --dep-order --ignore-dep-failure
API Example
import { createFileSystemProject } from "pacwich";
const project = createFileSystemProject();
project.runScriptAcrossWorkspaces({
script: "my-script",
dependencyOrder: true,
ignoreDependencyFailure: true,
});

