Skip to content

docs - Add "workspace:*" to workspace docs. #5379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions docs/install/workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,34 @@ To try it, specify a list of sub-packages in the `workspaces` field of your `pac
{
"name": "my-project",
"version": "1.0.0",
"workspaces": ["packages/*"]
"workspaces": ["packages/*"],
"devDependencies": {
"example-package-in-monorepo": "workspace:*"
}
}
```

{% callout %}
**Glob support** — Bun supports simple `<directory>/*` globs in `"workspaces"`. Full glob syntax (e.g. `**` and `?`) is not yet supported.
{% /callout %}

This has a couple major benefits.
When referencing other packages in the monorepo, use `"workspace:*"` as the version field in your `package.json`.

```json
{
"name": "pkg-a",
"version": "1.0.0",
"dependencies": {
"pkg-b": "workspace:*"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid this workspace:* ?

Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, you can put "pkg-b": "*" too

}
}
```

{% callout %}
**Version support** — Bun supports simple `workspace:*` versions in `"dependencies"`. Full version syntax (e.g. `workspace:^*`) is not yet supported.
{% /callout %}

Workspaces have a couple major benefits.

- **Code can be split into logical parts.** If one package relies on another, you can simply add it as a dependency with `bun add`. If package `b` depends on `a`, `bun install` will symlink your local `packages/a` directory into the `node_modules` folder of `b`, instead of trying to download 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.
Expand Down