Install dependencies for all workspaces starting with pkg- except for pkg-c
bun install --filter "pkg-*" --filter "!pkg-c"
Paths can also be used. This is equivalent to the command above.
bun install --filter "./packages/pkg-*" --filter "!pkg-c" # or --filter "!./packages/pkg-c"
When publishing, `workspace:` versions are replaced by the package’s `package.json` version,
"workspace:*" -> "1.0.1" "workspace:^" -> "^1.0.1" "workspace:~" -> "~1.0.1"
Setting a specific version takes precedence over the package’s `package.json` version,
"workspace:1.0.2" -> "1.0.2" // Even if current version is 1.0.1
Workspaces have a couple major benefits.
* **Code can be split into logical parts.** If one package relies on another, add it as a dependency in `package.json`. If package `b` depends on `a`, `bun install` will install your local `packages/a` directory into `node_modules` instead of downloading it from the npm registry.
* **Dependencies can be de-duplicated.** If `a` and `b` share a common dependency, it will be _hoisted_ to the root `node_modules` directory. This reduces redundant disk usage and minimizes “dependency hell” issues associated with having multiple versions of a package installed simultaneously.
* **Run scripts in multiple packages.** You can use the [`--filter` flag](../filter/index.md) to run `package.json` scripts in multiple packages in your workspace, or `--workspaces` to run scripts across all workspaces.
When many packages need the same dependency versions, catalogs let you define those versions once in the root `package.json` and reference them from your workspaces using the `catalog:` protocol. Updating the catalog automatically updates every package that references it. See [Catalogs](../catalogs/index.md) for details.