Repository navigation
Add --trusted flag to bun list - #32478
Conversation
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.
|
Updated 7:05 PM PT - Jun 17th, 2026
❌ @robobun, your commit 8b4e618 has 1 failures in 🧪 To try this PR locally: bunx bun-pr 32478That installs a local version of the PR into your bun-32478 --bun |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdds a Changesbun pm ls --trusted filtering
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (6)
docs/pm/cli/pm.mdxsrc/install/PackageManager.rssrc/install/PackageManager/CommandLineArguments.rssrc/runtime/cli/package_manager_command.rstest/cli/install/bun-install-lifecycle-scripts.test.tstest/cli/install/bun-pm.test.ts
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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), emptytrustedDependencies, and default-trusted-list fallback. - Not in CODEOWNERS-covered paths.
- The one CI failure (
test-docker-build-debian.tson macOS aarch64) is unrelated to this change. - All CodeRabbit threads were resolved/withdrawn.
|
CI status: the diff is green. The remaining red on build #63264 is unrelated to this change:
Prior build #63257 failed on Ready for review. |
What
Adds a
--trustedflag tobun pm ls/bun listthat filters the output to only show dependencies that are trusted (i.e. allowed to run lifecycle scripts).The flag filters using
Lockfile::has_trusted_dependency(), so it honors both:"trustedDependencies"array inpackage.json(only packages listed there are shown)trustedDependenciesis not setWorks on its own and combined with
--all.Changes
src/runtime/cli/package_manager_command.rs: parse--trustedand filter the sorted dependency list in both the top-level and recursive (--all) printers before renderingsrc/install/PackageManager.rs,src/install/PackageManager/CommandLineArguments.rs: register the flag and add it tobun pm --helpdocs/pm/cli/pm.mdx: document the flagVerification
test/cli/install/bun-pm.test.tscover--trusted,--all --trusted, and an emptytrustedDependencieslist; all fail on the released bun and pass with this change.test/cli/install/bun-install-lifecycle-scripts.test.tscovers the default trusted list fallback (notrustedDependenciesinpackage.json,electronis on the default list,no-depsis not) and the switchover whentrustedDependenciesis added.bun bd test test/cli/install/bun-pm.test.ts: 17 pass, 0 fail.trustedDependencies):bun list --trustedprints onlyesbuild, the one top-level dep on the default list.