Skip to content

bunx: allow multiple packages in a single temporary execution environment - #39449

Open
loicnaoussi wants to merge 6 commits into
oven-sh:mainfrom
loicnaoussi:claude/bunx-multi-package
Open

loicnaoussi wants to merge 6 commits into
oven-sh:mainfrom
loicnaoussi:claude/bunx-multi-package

Conversation

@loicnaoussi

Copy link
Copy Markdown

Summary

Fixes #39444 — --package/-p can now be repeated to install several packages into the same temporary bunx execution environment, matching npx --package a --package b cmd.

  • Parsing: specified_package: Option<&[u8]> becomes specified_packages: Vec<&[u8]>; --package/-p/--package=/-p= all accumulate instead of overwriting.
  • Install: every --package value is parsed into its own UpdateRequest and passed to bun add as its own target (raw specifiers, unmodified — bun add already parses name@version, github:, URL forms itself, so no reconstruction needed). The install argv is a Vec now instead of a fixed-size BoundedArray<_, 8>, since the size is no longer bounded by a small constant.
  • Cache key: the bunx cache directory name (bunx-<uid>-<key>) is derived from the sorted, hashed set of raw --package specifiers when more than one is given, so --package a --package b and --package b --package a share one cache directory. For 0 or 1 --package the key is byte-identical to before (existing caches aren't invalidated). The cache-clearing code in package_manager_command.rs only matches the bunx-<uid>- prefix, so it needed no changes.
  • Cache freshness (do_cache_bust/look_for_existing_bin): aggregated across every requested package (any floating dist-tag busts the cache for the whole set) instead of reading only the first request.
  • As with a single --package (existing behavior, unchanged), the binary to run must always be given explicitly — no bin-guessing is needed across multiple packages, since whichever package provides the named bin is found via the shared cache's node_modules/.bin.

Split into 6 commits by concern: CLI parsing → N-request parsing + cache-freshness aggregation → cache-key/install-target aggregation → generalizing the actual install argv → the missing-binary error message → docs/tests.

Test plan

  • test/cli/install/bunx.test.ts:
    • CLI validation: multiple --package without a trailing binary name still errors, same message as a single --package.
    • Functional: two distinct packages (each with its own bin) installed together via --package a --package b, binary from the first one runs; then re-run with the --package order reversed asking for the other binary — asserts zero registry requests, which only holds if the cache key is genuinely order-independent.
  • docs/pm/bunx.mdx: added a repeated---package example next to the existing single-package one.

I could not compile or run any of this locally — same constraint as on a recent PR in this repo: no bun, cargo, or C++ toolchain available in this environment. I reviewed the Rust changes carefully by hand (borrow-checker implications of computing do_cache_bust/look_for_existing_bin before update_requests[0] is borrowed mutably, the install_param → install_params move and its downstream display-string uses, Vec<&[u8]> lifetime consistency), and independently re-derived the final diff twice (once as a single pass, once reconstructed commit-by-commit) to confirm both produce byte-identical output — but none of it has been checked by actually building. buildkite/bun passing is load-bearing here.

specified_package: Option<&[u8]> becomes specified_packages: Vec<&[u8]>
so --package/-p can be given more than once. Every call site is updated
to check emptiness instead of Option::is_some/is_none; behavior for zero
or one --package is unchanged (opts.package_name still resolves to the
first requested package).

This is groundwork only: downstream install/cache-key logic still only
consumes the first entry until the following commits.
UpdateRequest::parse now runs over the full specified_packages list
(when non-empty) instead of always parsing just opts.package_name, so
each --package gets its own parsed request.

do_cache_bust/look_for_existing_bin move earlier and become aggregates
over every request (any floating dist-tag busts the cache; all requests
must want the cache path for it to be tried) instead of reading only the
first request. They're computed before update_requests[0] is borrowed
mutably, since that borrow is held for the rest of the function. For 0
or 1 --package this is behaviorally identical to the check it replaces.
…lues

package_fmt (the cache directory key) and install_param (the bun add
target) become package_fmt/install_params for 0 or 1 --package they are
unchanged; for N > 1 the cache key is derived from the raw --package
specifiers, sorted (so order doesn't create a second cache directory for
the same package set) and hashed (so it stays short and filesystem-safe
regardless of package name length or count), and install_params holds
one raw specifier per package — bun add already parses each one itself,
including github:/URL forms that don't reduce to a clean name.

install_param is moved into install_params here, so log/error messages
that displayed it now use install_param_display, a comma-joined string
covering every requested package.

The actual install argv still only installs the first entry — generalizing
it to every install_params entry is the next commit.
The install argv now pushes every install_params entry (previously only
index 0), so bun add actually receives all N packages from N --package
flags in one invocation, into the same temporary node_modules. Swapped
the fixed-size BoundedArray<_, 8> for a Vec<&[u8]> since the argv length
is no longer bounded by a small constant, and dropped the now-unused
BoundedArray import.
The "does not provide a binary named" message displayed only
update_request.name (the first requested package), which is misleading
once more than one --package can be given. Uses install_param_display
(all requested packages, comma-joined) instead.
docs/pm/bunx.mdx: add a repeated --package example alongside the
existing single-package one, and note that the binary must still be
given explicitly and nothing is added to the project's dependencies.

test/cli/install/bunx.test.ts:
- CLI validation: multiple --package still requires an explicit binary
  name, same as a single --package.
- Functional: two distinct packages, each with its own bin, installed
  together via `--package a --package b` and run from the shared
  environment; then re-run with the package order reversed asking for
  the *other* binary, asserting zero registry requests — the cache key
  must be order-independent for this to hold.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

gberlian pushed a commit to gberlian/bun that referenced this pull request Oct 14, 2026
### What does this PR do?

Picked up from oven-sh#27452 by @ctjlewis (requested by @alii in
oven-sh#27452 (comment)) so CI
runs automatically and the autofixer works.

All commits preserve original authorship (Lewis <lewis@spellcraft.org>).

---

Adds `--path-ignore-patterns` argument and Bunfig option similar to
`--coverage-path-ignore-patterns`.

https://bun.com/docs/test/configuration#coverage-path-ignore-patterns

- Closes oven-sh#27388
- Closes oven-sh#21395
- Closes oven-sh#13963

### How did you verify your code works?

Tests in `test/cli/test/path-ignore-patterns.test.ts` (328 lines).

### Docs

Simple docs added for Bunfig and Configuration docs.

### Verification

Buildkite oven-sh#39573 on `1a1af82`: only CI failure is a snapshot mismatch in
`test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts` (111
passed, 1 failed snapshot) — completely unrelated to this PR. Main
branch also failing on all recent commits (builds oven-sh#39449, oven-sh#39406,
oven-sh#39511, oven-sh#39396). All 3 bot review threads resolved. Diff clean — no
TODOs, changes scoped to bunfig parsing, CLI args, test scanner, docs,
and tests. Ready for human review.

---
**Verification (robobun):** CI green (13/13 on `525b4dd`). Diff clean —
no TODOs, changes well-scoped to bunfig parsing, CLI args, test scanner,
docs, and tests. All 3 bot review threads resolved (coderabbit
precedence fix applied, trailing-slash pruning restricted to `**`
patterns). Feature PR — tests confirm baked binary lacks the feature (9
fail) while CI passes all platform suites.

---------

Co-authored-by: Lewis <lewis@spellcraft.org>
Co-authored-by: Alistair Smith <alistair@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bunx: allow multiple packages in a single temporary execution environment

1 participant