Skip to content

Add --trusted flag to bun list - #32478

Merged
Jarred-Sumner merged 7 commits into
mainfrom
farm/f789453a/bun-list-trusted-flag
Jun 18, 2026
Merged

Jarred-Sumner merged 7 commits into
mainfrom
farm/f789453a/bun-list-trusted-flag

Conversation

@robobun

@robobun robobun commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

What

Adds a --trusted flag to bun pm ls / bun list that filters the output to only show dependencies that are trusted (i.e. allowed to run lifecycle scripts).

$ bun pm ls --trusted
/path/to/project node_modules (135)
└── esbuild@0.21.5

The flag filters using Lockfile::has_trusted_dependency(), so it honors both:

  • an explicit "trustedDependencies" array in package.json (only packages listed there are shown)
  • Bun's default trusted list when trustedDependencies is not set

Works on its own and combined with --all.

Changes

  • src/runtime/cli/package_manager_command.rs: parse --trusted and filter the sorted dependency list in both the top-level and recursive (--all) printers before rendering
  • src/install/PackageManager.rs, src/install/PackageManager/CommandLineArguments.rs: register the flag and add it to bun pm --help
  • docs/pm/cli/pm.mdx: document the flag

Verification

  • New tests in test/cli/install/bun-pm.test.ts cover --trusted, --all --trusted, and an empty trustedDependencies list; all fail on the released bun and pass with this change.
  • New test in test/cli/install/bun-install-lifecycle-scripts.test.ts covers the default trusted list fallback (no trustedDependencies in package.json, electron is on the default list, no-deps is not) and the switchover when trustedDependencies is added.
  • bun bd test test/cli/install/bun-pm.test.ts: 17 pass, 0 fail.
  • Manual check against this repo (which has no trustedDependencies): bun list --trusted prints only esbuild, the one top-level dep on the default list.

Adds a --trusted flag to `bun pm ls` / `bun list` that filters output to
only show dependencies that are trusted (allowed to run lifecycle
scripts). Uses Lockfile::has_trusted_dependency() so it honors both an
explicit "trustedDependencies" array in package.json and Bun's default
trusted list when that array is not set. Works with --all as well.
@robobun

robobun commented Jun 18, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 7:05 PM PT - Jun 17th, 2026

❌ @robobun, your commit 8b4e618 has 1 failures in Build #63264 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 32478

That installs a local version of the PR into your bun-32478 executable, so you can run:

bun-32478 --bun

@mintlify

mintlify Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
bun 🟢 Ready View Preview Jun 18, 2026, 12:13 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c534bace-0147-464a-83e6-4d3318370a95

📥 Commits

Reviewing files that changed from the base of the PR and between 805991e and 8b4e618.

📒 Files selected for processing (1)
  • completions/bun.zsh

Walkthrough

Adds a --trusted flag to bun pm ls/bun pm list that filters the dependency tree output to only trusted dependencies. The flag is registered in PM_PARAMS, help text is updated in multiple places, filtering logic is added to the ls command using lockfile.has_trusted_dependency, and comprehensive tests and documentation are included.

Changes

bun pm ls --trusted filtering

Layer / File(s) Summary
CLI flag registration, help, and completions
src/install/PackageManager/CommandLineArguments.rs, src/install/PackageManager.rs, src/runtime/cli/package_manager_command.rs, completions/bun.zsh
Adds --trusted to PM_PARAMS, updates bun pm list help text in PackageManagerCommand::print_help, adds --all/--trusted option entries to the pm CLI help section, and includes --trusted in shell completion arguments for pm ls.
ls --trusted filtering implementation
src/runtime/cli/package_manager_command.rs
Parses --trusted into trusted_only, filters sorted_dependencies at the top level via lockfile.has_trusted_dependency, derives pkg_names for resolved package name checks, routes --all --trusted through a new flat printer helper (print_trusted_dependencies_flat) that de-duplicates and prints trusted dependencies without tree structure.
Tests and documentation
test/cli/install/bun-install-lifecycle-scripts.test.ts, test/cli/install/bun-pm.test.ts, docs/pm/cli/pm.mdx
Adds lifecycle-scripts test verifying default trusted list fallback vs explicit trustedDependencies, adds four bun-pm tests covering direct trusted deps, --all --trusted tree filtering with standard and isolated linkers, and empty trustedDependencies. Documents the --trusted flag with usage examples.

Possibly related PRs

  • oven-sh/bun#31218: Changes lockfile.has_trusted_dependency to compare stored trusted name bytes rather than truncated hashes, which is the exact trust-check codepath this PR filters through.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and accurately summarizes the main change: adding a --trusted flag to the bun list command for filtering trusted dependencies.
Description check ✅ Passed The description fully addresses both required template sections with clear explanations of what the PR does, how it was verified, and includes comprehensive implementation details and test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/install/PackageManager/CommandLineArguments.rs`:
- Line 172: The new --trusted flag parameter has been added to PM_PARAMS but the
parse() method is not reading it correctly. Locate where parse() extracts the
flag value (likely reading --trust instead of --trusted) and update it to
properly read the --trusted flag so that the value is correctly assigned to the
cli.trusted field. Ensure the flag name matches exactly between the parameter
definition and where it is read in the parsing logic.

In `@src/runtime/cli/package_manager_command.rs`:
- Around line 802-815: The issue is that the trusted_only filter at the
beginning of this block (using sorted_dependencies.retain with the
lockfile.has_trusted_dependency check) removes untrusted parents before any
recursive traversal can occur, preventing trusted transitive dependencies under
untrusted parents from being visited. To fix this, remove the retain filter that
runs at the start of the trusted_only block, allow the recursion (which occurs
after line 815) to traverse all dependencies regardless of trust status, and
instead apply the trusted filtering either after the full traversal is complete
or at a different stage in the code where both the parent and all ancestors have
been evaluated for trust. This ensures that trusted descendants of untrusted
parents are still discovered and displayed when using the --all --trusted flags
together.

In `@test/cli/install/bun-install-lifecycle-scripts.test.ts`:
- Around line 1719-1721: Replace all instances of `env` with `testEnv` when
passing environment variables to spawned commands within the for loop that
iterates over forceWaiterThread variants. The current code uses `env` which does
not include the waiter-thread configuration changes, causing both loop
iterations to run identically. Update the destructured assignment from ctx to
include `testEnv`, and replace `env` with `testEnv` in all spawned command calls
throughout the test, including the ranges mentioned in the comment at lines
1735-1742, 1752-1759, 1783-1790, and 1797-1804, to ensure each waiter-thread
variant is properly tested.

In `@test/cli/install/bun-pm.test.ts`:
- Around line 288-300: The spawn function calls in this test file are reading
stderr sequentially and then awaiting exited, which can cause pipe buffer
deadlocks when buffers fill up. Replace the sequential pipe reads with
concurrent draining by using Promise.all to await all pipe text operations
(stdout.text(), stderr.text()) and exited simultaneously. This pattern needs to
be fixed at the spawn call around line 288-300 and also at the two other
locations mentioned (lines 369-381 and 419-431) where similar spawn patterns
exist.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a8b682e2-fd54-4e4e-a9fa-d3b2dfe6122f

📥 Commits

Reviewing files that changed from the base of the PR and between 797d565 and 59b402c.

📒 Files selected for processing (6)
  • docs/pm/cli/pm.mdx
  • src/install/PackageManager.rs
  • src/install/PackageManager/CommandLineArguments.rs
  • src/runtime/cli/package_manager_command.rs
  • test/cli/install/bun-install-lifecycle-scripts.test.ts
  • test/cli/install/bun-pm.test.ts

Comment thread test/cli/install/bun-pm.test.ts Resolved
robobun and others added 2 commits June 18, 2026 00:33
The previous implementation filtered each folder's dependency list
before recursion, so a trusted package installed in a nested
node_modules under an untrusted parent was never visited. Under the
isolated linker every package gets its own nested folder, so this was
the common case there, and hoisted installs hit it on version
conflicts.

Trust is by package name, not tree position, so --all --trusted now
scans every node_modules folder the lockfile tree iterator produces,
collects trusted packages deduped by package id, and prints a flat
sorted list. Added an isolated-linker test that covers a trusted
transitive dep under an untrusted parent.

@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.

My earlier feedback (the --all --trusted nested-folder miss and the zsh completion) has been addressed; deferring to a human for sign-off on the new CLI surface and the flat-output choice for --all --trusted.

Extended reasoning...

Overview

Adds a --trusted filter flag to bun pm ls / bun list. Touches src/runtime/cli/package_manager_command.rs (~110 net new lines including a new print_trusted_dependencies_flat helper that walks every NodeModulesFolder and prints a deduped flat list), registers the flag in PM_PARAMS, updates help text in two places, docs, zsh completion, and adds five new tests across two test files.

Security risks

None apparent. The flag is read-only and reuses the existing Lockfile::has_trusted_dependency() check; it does not change which packages are trusted or which scripts run. The output is intended for users auditing lifecycle-script permissions, so completeness matters — the earlier gap where trusted packages nested under untrusted parents were dropped has been fixed by switching --all --trusted to a flat scan over all collected node_modules folders.

Level of scrutiny

Moderate. This is a new user-facing CLI feature in the package manager, not a mechanical fix. The implementation reaches into lockfile buffers (resolutions, dependencies, packages.slice()) and the tree iterator, and a UX/design decision was made mid-review (flat list rather than a pruned tree for --all --trusted, with a header that omits the (N) count). A maintainer should confirm that output shape is what they want before it ships.

Other factors

All four CodeRabbit comments and both of my prior inline comments are resolved (commits e6bd5f0, 8733b3a, 29ba960). Test coverage is solid: explicit trustedDependencies, empty list, default-trusted fallback, --all --trusted under both hoisted and isolated linkers. The Buildkite failures in the robobun comment look like infra (Windows aarch64 agent-creation failures) and cross-target build-rust shards rather than anything specific to this change, but worth a glance. No CODEOWNERS cover the touched paths.

@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.

Both of my earlier concerns are addressed (the --all --trusted traversal now walks every node_modules folder flat, and zsh completions include the flag) and I didn't find anything else — deferring only because this adds a new user-facing CLI flag and a new output format for --all --trusted, which is worth a quick human sign-off.

Extended reasoning...

Overview

Adds a --trusted flag to bun pm ls / bun list that filters output to only dependencies allowed to run lifecycle scripts, via Lockfile::has_trusted_dependency(). Touches src/runtime/cli/package_manager_command.rs (flag parsing, top-level filter, and a new ~75-line print_trusted_dependencies_flat helper for --all --trusted), CommandLineArguments.rs (registers the flag in PM_PARAMS), two help-text strings, docs/pm/cli/pm.mdx, completions/bun.zsh, and adds five tests across two test files.

Security risks

None identified. This is a read-only display command that reuses the existing has_trusted_dependency() check; it does not change which packages are trusted or which scripts run. The flag is read from raw argv the same way --all is, and the PM_PARAMS entry only exists so clap accepts the flag.

Level of scrutiny

Medium. The implementation is straightforward and follows existing patterns in the file (same ByName sort, same prettyln! tree glyphs, same lockfile slice accessors as the non-trusted path). However, it introduces a new user-facing CLI surface and a deliberate UX decision: --all --trusted prints a flat, deduped-by-package_id list rather than a pruned tree. That decision was made in response to my earlier review (so trusted packages nested under untrusted parents — common with the isolated linker — aren't silently dropped), and I think it's the right call, but it's the kind of product/UX choice a maintainer should ratify.

Other factors

  • My two prior inline comments (traversal bug under untrusted parents; missing zsh completion entry) were both addressed in 8733b3a and 29ba960, and the new isolated-linker test covers the case I raised.
  • Test coverage is solid: top-level --trusted, --all --trusted (hoisted and isolated), empty trustedDependencies, and default-trusted-list fallback.
  • Not in CODEOWNERS-covered paths.
  • The one CI failure (test-docker-build-debian.ts on macOS aarch64) is unrelated to this change.
  • All CodeRabbit threads were resolved/withdrawn.

@robobun

robobun commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

CI status: the diff is green. The remaining red on build #63264 is unrelated to this change:

  • test/integration/next-pages/test/dev-server.test.ts on darwin aarch64: puppeteer chrome-headless-shell download failed ("browser folder exists but the executable is missing")
  • flaky-retry warnings: update_interactive_install.test.ts (Windows x64), hot.test.ts ENOENT (aarch64), test/package.json puppeteer download (darwin aarch64)

Prior build #63257 failed on test-docker-build-debian.ts hitting Docker Hub 429 rate limit. Neither bun-pm.test.ts nor bun-install-lifecycle-scripts.test.ts failed on any lane in either build. 285/287 jobs passed on each run.

Ready for review.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants