new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Bun · Package manager · all subjects

install: workspaces & filtering

24 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

bun --filter for workspace scripts

The --filter flag accepts a glob pattern and runs the command concurrently for every workspace package whose name matches it, respecting dependency order. Example: bun --filter 'lib-*' my-script.

Running bun install in workspace root

Once you add dependencies between workspaces, run bun install from the project root to install dependencies for all workspaces.

Default linker behavior for workspace installs

New workspaces use isolated installs by default. With isolated installs, Bun installs the package into the root node_modules/.bun store and symlinks it from the workspace's own node_modules. With --linker hoisted, Bun hoists the package into the root node_modules instead.

bun install workspaces configuration

Bun supports 'workspaces' in package.json as an array of glob patterns like 'packages/*'. Workspaces enable monorepo structure.

bun install --filter for specific packages in monorepos

Use 'bun install --filter' to install dependencies for a subset of packages. Example: 'bun install --filter !pkg-c' installs for all workspaces except pkg-c. Example: 'bun install --filter ./packages/pkg-a' installs only for pkg-a in ./packages/pkg-a.

bun outdated --filter flag for workspaces

Use the --filter flag to check for outdated dependencies in a specific workspace package. For example, bun outdated --filter='@monorepo/types' checks a specific workspace. The --filter flag accepts glob patterns to match multiple workspaces, such as bun outdated --filter='@monorepo/{types,cli}'.

Workspace handling in isolated installs

In monorepos, workspace packages are symlinked directly to their source directories, not the store. Workspace dependencies can access other workspace packages in the monorepo. External dependencies are installed in the isolated store.

--filter flag syntax and basic usage

The --filter (or -F) flag selects packages in a monorepo by pattern. It works with bun run, bun install, bun add, bun remove, bun update, bun outdated, bun prune, and bun pm licenses. For package-manager commands, put the flag after the subcommand (bun install --filter api), since bun --filter <pattern> <word> runs <word> as a script.

--filter package name pattern matching

Name patterns select packages by the name field in package.json using globs. For example, * matches all packages, pkg* matches pkg-a and pkg-b but not other, and a full name matches a specific package. Name patterns match the full package name (core does not match @acme/core; use @acme/*), and * does not cross /.

--filter path pattern matching

Path patterns start with ./ and select all packages in directories matching the pattern. For example, --filter './packages/**' matches all packages in subdirectories of packages, and --filter ./packages/foo matches the package in packages/foo. Path patterns must match the workspace directory itself: ./packages selects nothing, ./packages/* selects every workspace directly inside it.

--filter directory selector syntax

A directory in braces selects every workspace in that directory or anywhere below it, resolved from the current directory. --filter '{packages}' selects everything under packages/; --filter '{.}' selects the current directory's workspace and everything below it.

--filter dependency relation patterns

Adding ... to a pattern also selects workspaces related through workspace dependencies. foo... selects foo and the workspaces it depends on, directly or transitively. foo^... selects only the workspaces foo depends on, not foo itself. ...foo selects foo and the workspaces that depend on it, directly or transitively. ...^foo selects only the workspaces that depend on foo, not foo itself. To exclude, ! goes first: --filter '!...foo'. foo can be a name glob or a directory selector like ...{./packages/api}.

--filter with bun install and bun outdated behavior

By default, bun install installs dependencies for every package in the monorepo. To install dependencies for specific packages, use --filter. Multiple --filter flags combine: everything matched by a positive pattern, minus everything matched by a ! pattern. A pattern that matches nothing prints a warning. For bun add, bun remove, bun update, bun prune, and bun pm licenses, selecting no workspaces at all is an error. bun outdated displays outdated dependencies for all packages in the monorepo, and --filter restricts the command to a subset of them.

--filter with bun run for script execution

Use bun --filter <pattern> <script> to execute scripts in multiple packages at once. Filters respect workspace configuration. In a workspace, --filter can run scripts in packages located anywhere in the workspace without needing to cd. Only a ./path pattern can select a package.json without a name field. If no selected package has the script, bun run exits with an error (pass --if-present to exit 0 instead).

--parallel and --sequential flags for filtered scripts

Combine --filter or --workspaces with --parallel or --sequential to run scripts across workspace packages with Foreman-style prefixed output. Bun prefixes each line of output with the package and script name (pkg-a:build | ...). Without --filter/--workspaces, the prefix is only the script name (build | ...). When a package's package.json has no name field, Bun uses the relative path from the workspace root instead.

--no-exit-on-error flag for parallel script execution

The --no-exit-on-error flag allows bun run to continue running even if one package's script fails when used with --parallel.

--if-present flag with --workspaces

Use --if-present with --workspaces to skip packages that don't have the requested script instead of erroring.

Bun respects package dependency order when running scripts

Bun respects package dependency order when running scripts with --filter. If package foo depends on package bar in the workspace and both have a build script, when you run bun --filter '*' build, foo only starts once bar is done.

--filter examples for monorepo operations

Example commands: bun install --filter 'web...' installs for web and its dependencies; bun add zod --filter '...^ui' adds a dependency to packages that depend on ui; bun outdated --filter '{./packages/apps}' shows outdated packages in that directory.

--filter examples for running scripts

Example commands: bun --filter '*' dev runs dev in all packages; bun --filter 'web...' build builds web and everything it depends on in dependency order; bun --filter '...^ui' test tests the packages that depend on ui; bun --filter '{./packages/apps}' dev runs dev in every package under packages/apps; bun --filter '*' --filter '!docs' lint runs lint in all packages except docs.

--parallel and --sequential script execution examples

Example commands: bun run --parallel --filter '*' build runs build in all matching packages concurrently; bun run --sequential --workspaces build runs build in all workspace packages sequentially; bun run --parallel --filter '*' 'build:*' runs glob-matched scripts across all packages; bun run --parallel --no-exit-on-error --filter '*' test continues running even if one package's script fails; bun run --parallel --filter '*' build lint runs multiple scripts across all packages.

link-workspace-packages option in .npmrc

The link-workspace-packages option controls how Bun installs workspace packages when they are available locally. Set link-workspace-packages=true in .npmrc to enable linking workspace packages.

bun install with workspaces

bun install installs dependencies for all workspaces in the monorepo, de-duplicating packages if possible. To install dependencies for specific workspaces only, use the --filter flag.

bun install --filter flag syntax

The --filter flag accepts glob patterns and paths to select specific workspaces. Multiple --filter flags can be used together. Patterns starting with ! exclude workspaces. Paths can be relative like ./packages/pkg-* or workspace names like pkg-*.

Give your agent this brain