Skip to content

Commit

Permalink
Merge branch 'main' into don/test/dequeue
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac authored Jan 8, 2025
2 parents a8a8051 + 04b388e commit 000be1d
Show file tree
Hide file tree
Showing 44 changed files with 1,791 additions and 1,765 deletions.
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# To learn more about git's mailmap: https://ntietz.com/blog/git-mailmap-for-name-changes
chloe caruso <git@paperclover.net> <me@paperdave.net>
28 changes: 0 additions & 28 deletions .vscode/launch.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions docs/api/s3.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const writer = s3file.writer({
queueSize: 10,

// Upload in 5 MB chunks
partSize: 5,
partSize: 5 * 1024 * 1024,
});
for (let i = 0; i < 10; i++) {
await writer.write(bigFile);
Expand Down Expand Up @@ -614,9 +614,10 @@ const credentials = {

const stat = await S3Client.stat("my-file.txt", credentials);
// {
// etag: "\"7a30b741503c0b461cc14157e2df4ad8\"",
// lastModified: 2025-01-07T00:19:10.000Z,
// size: 1024,
// etag: "1234567890",
// lastModified: new Date(),
// type: "text/plain;charset=utf-8",
// }
```

Expand Down Expand Up @@ -661,7 +662,7 @@ const response = await fetch("s3://my-bucket/my-file.txt", {
endpoint: "https://s3.us-east-1.amazonaws.com",
},
headers: {
"x-amz-meta-foo": "bar",
"range": "bytes=0-1023",
},
});
```
Expand Down
67 changes: 50 additions & 17 deletions docs/cli/filter.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
Use the `--filter` flag to execute lifecycle scripts in multiple packages at once:
The `--filter` (or `-F`) flag is used for selecting packages by pattern in a monorepo. Patterns can be used to match package names or package paths, with full glob syntax support.

Currently `--filter` is supported by `bun install` and `bun outdated`, and can also be used to run scripts for multiple packages at once.

## Matching

### Package Name `--filter <pattern>`

Name patterns select packages based on the package name, as specified in `package.json`. For example, if you have packages `pkg-a`, `pkg-b` and `other`, you can match all packages with `*`, only `pkg-a` and `pkg-b` with `pkg*`, and a specific package by providing the full name of the package.

### Package Path `--filter ./<glob>`

Path patterns are specified by starting the pattern with `./`, and will select all packages in directories that match the pattern. For example, to match all packages in subdirectories of `packages`, you can use `--filter './packages/**'`. To match a package located in `packages/foo`, use `--filter ./packages/foo`.

## `bun install` and `bun outdated`

Both `bun install` and `bun outdated` support the `--filter` flag.

`bun install` by default will install dependencies for all packages in the monorepo. To install dependencies for specific packages, use `--filter`.

Given a monorepo with workspaces `pkg-a`, `pkg-b`, and `pkg-c` under `./packages`:

```bash
# Install dependencies for all workspaces except `pkg-c`
$ bun install --filter '!pkg-c'

# Install dependencies for packages in `./packages` (`pkg-a`, `pkg-b`, `pkg-c`)
$ bun install --filter './packages/*'

# Save as above, but exclude the root package.json
$ bun install --filter --filter '!./' --filter './packages/*'
```

Similarly, `bun outdated` will display outdated dependencies for all packages in the monorepo, and `--filter` can be used to restrict the command to a subset of the packages:

```bash
# Display outdated dependencies for workspaces starting with `pkg-`
$ bun outdated --filter 'pkg-*'

# Display outdated dependencies for only the root package.json
$ bun outdated --filter './'
```

For more infomation on both these commands, see [`bun install`](https://bun.sh/docs/cli/install) and [`bun outdated`](https://bun.sh/docs/cli/outdated).

## Running scripts with `--filter`

Use the `--filter` flag to execute scripts in multiple packages at once:

```bash
bun --filter <pattern> <script>
Expand All @@ -24,19 +71,7 @@ bun --filter '*' dev
Both commands will be run in parallel, and you will see a nice terminal UI showing their respective outputs:
![Terminal Output](https://github.com/oven-sh/bun/assets/48869301/2a103e42-9921-4c33-948f-a1ad6e6bac71)

## Matching

`--filter` accepts a pattern to match specific packages, either by name or by path. Patterns have full support for glob syntax.

### Package Name `--filter <pattern>`

Name patterns select packages based on the package name, as specified in `package.json`. For example, if you have packages `pkga`, `pkgb` and `other`, you can match all packages with `*`, only `pkga` and `pkgb` with `pkg*`, and a specific package by providing the full name of the package.

### Package Path `--filter ./<glob>`

Path patterns are specified by starting the pattern with `./`, and will select all packages in directories that match the pattern. For example, to match all packages in subdirectories of `packages`, you can use `--filter './packages/**'`. To match a package located in `pkgs/foo`, use `--filter ./pkgs/foo`.

## Workspaces
### Running scripts in workspaces

Filters respect your [workspace configuration](https://bun.sh/docs/install/workspaces): If you have a `package.json` file that specifies which packages are part of the workspace,
`--filter` will be restricted to only these packages. Also, in a workspace you can use `--filter` to run scripts in packages that are located anywhere in the workspace:
Expand All @@ -50,8 +85,6 @@ Filters respect your [workspace configuration](https://bun.sh/docs/install/works
bun run --filter foo myscript
```

## Dependency Order
### Dependency Order

Bun will respect package dependency order when running scripts. Say you have a package `foo` that depends on another package `bar` in your workspace, and both packages have a `build` script. When you run `bun --filter '*' build`, you will notice that `foo` will only start running once `bar` is done.

### Cyclic Dependencies
14 changes: 14 additions & 0 deletions docs/cli/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ Bun supports `"workspaces"` in package.json. For complete documentation refer to
}
```

## Installing dependencies for specific packages

In a monorepo, you can install the dependencies for a subset of packages using the `--filter` flag.

```bash
# Install dependencies for all workspaces except `pkg-c`
$ bun install --filter '!pkg-c'

# Install dependencies for only `pkg-a` in `./packages/pkg-a`
$ bun install --filter './packages/pkg-a'
```

For more information on filtering with `bun install`, refer to [Package Manager > Filtering](https://bun.sh/docs/cli/install#bun-install-and-bun-outdated)

## Overrides and resolutions

Bun supports npm's `"overrides"` and Yarn's `"resolutions"` in `package.json`. These are mechanisms for specifying a version range for _metadependencies_—the dependencies of your dependencies. Refer to [Package manager > Overrides and resolutions](https://bun.sh/docs/install/overrides) for complete documentation.
Expand Down
2 changes: 2 additions & 0 deletions docs/cli/outdated.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ If you want to do the same, but exclude the `./apps/api` workspace:
```sh
$ bun outdated --filter './apps/*' --filter '!./apps/api'
```

Refer to [Package Manager > Filtering](https://bun.sh/docs/cli/filter#bun-install-and-bun-outdated) for more information on `--filter`.
4 changes: 2 additions & 2 deletions docs/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ $ bun run --bun vite

### Filtering

in monorepos containing multiple packages, you can use the `--filter` argument to execute scripts in many packages at once.
In monorepos containing multiple packages, you can use the `--filter` argument to execute scripts in many packages at once.

Use `bun run --filter <name_pattern> <script>` to execute `<script>` in all packages whose name matches `<name_pattern>`.
For example, if you have subdirectories containing packages named `foo`, `bar` and `baz`, running
Expand All @@ -164,7 +164,7 @@ bun run --filter 'ba*' <script>

will execute `<script>` in both `bar` and `baz`, but not in `foo`.

Find more details in the docs page for [filter](https://bun.sh/docs/cli/filter).
Find more details in the docs page for [filter](https://bun.sh/docs/cli/filter#running-scripts-with-filter).

## `bun run -` to pipe code from stdin

Expand Down
Loading

0 comments on commit 000be1d

Please sign in to comment.