Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/install/PackageManager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ pub struct PackageManager {
// (catalog name, dependency name) -> original version literal
pub updating_catalogs: Vec<CatalogUpdateInfo>,

// When `bun update` is run with `--recursive` or `--filter`, this holds the
// name hashes of the workspaces whose dependencies should be updated. `None`
// means the default behavior: only the current (root/cwd) workspace updates.
Comment thread
robobun marked this conversation as resolved.
Resolved
pub(crate) update_workspace_name_hashes: Option<Box<[PackageNameHash]>>,

pub(crate) patched_dependencies_to_remove:
ArrayHashMap<PackageNameAndVersionHash, () /* , ArrayIdentityContext::U64, false */>,

Expand Down Expand Up @@ -1954,6 +1959,7 @@ pub fn init(
wr!(any_failed_to_install, false);
wr!(updating_packages, StringArrayHashMap::default());
wr!(updating_catalogs, Vec::new());
wr!(update_workspace_name_hashes, None);
wr!(patched_dependencies_to_remove, ArrayHashMap::default());
wr!(last_reported_slow_lifecycle_script_at, 0);
wr!(cached_tick_for_slow_lifecycle_script_logging, 0);
Expand Down Expand Up @@ -2392,6 +2398,7 @@ fn init_with_runtime_once(
);
wr!(updating_packages, StringArrayHashMap::default());
wr!(updating_catalogs, Vec::new());
wr!(update_workspace_name_hashes, None);
wr!(patched_dependencies_to_remove, ArrayHashMap::default());
wr!(last_reported_slow_lifecycle_script_at, 0);
wr!(cached_tick_for_slow_lifecycle_script_logging, 0);
Expand Down
23 changes: 13 additions & 10 deletions src/install/PackageManager/PackageJSONEditor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bun_collections::VecExt;
use bun_collections::{StringArrayHashMap, VecExt};
use std::io::Write as _;

use bun_ast as js_ast;
Expand All @@ -9,7 +9,7 @@ use bun_semver as semver;
use bun_install::dependency::{self, TagExt as _};
use bun_install::lockfile::package::PackageColumns as _;
use bun_install::{Dependency, INVALID_PACKAGE_ID, resolution};
use bun_install_types::DependencyGroup;
use bun_install_types::{DependencyGroup, PackageNameHash};

use super::package_manager_options::{Do, Enable};
use super::{CatalogUpdateInfo, PackageManager, PackageUpdateInfo, Subcommand, UpdateRequest};
Expand Down Expand Up @@ -242,6 +242,13 @@ pub fn edit_trusted_dependencies(
/// versions.
pub(crate) fn edit_update_no_args(
manager: &mut PackageManager,
// Per-workspace scratch so two workspaces can pin the same dep differently.
// The root/cwd passes `manager.updating_packages`; fanned-out members each
// pass a fresh map.
Comment thread
robobun marked this conversation as resolved.
Resolved
updating_packages: &mut StringArrayHashMap<PackageUpdateInfo>,
// Which workspace's resolved versions to read back in the post-install pass.
// `None` means the root workspace.
Comment thread
robobun marked this conversation as resolved.
Resolved
workspace_name_hash: Option<PackageNameHash>,
current_package_json: &mut Expr,
options: EditOptions,
) -> Result<(), bun_alloc::AllocError> {
Expand All @@ -252,8 +259,6 @@ pub(crate) fn edit_update_no_args(

// Process-lifetime arena for AST
// nodes that must outlive `Expr.Data.Store.reset()`. See `PackageManager.ast_arena`.
// `arena` is a disjoint-field borrow held across
// the `&mut manager.updating_packages` accesses below.
let arena = &manager.ast_arena;

for group in DEPENDENCY_GROUPS {
Expand Down Expand Up @@ -315,9 +320,9 @@ pub(crate) fn edit_update_no_args(

let key_str = key.as_utf8_string_literal().expect("unreachable");
// Capture the literal as an owned
// copy before borrowing `manager.updating_packages` mutably.
// copy before borrowing `updating_packages` mutably.
let version_literal_owned = Box::<[u8]>::from(version_literal);
let entry = manager.updating_packages.get_or_put(key_str)?;
let entry = updating_packages.get_or_put(key_str)?;

// If a dependency is present in more than one dependency group, only one of it's versions
// will be updated. The group is determined by the order of `dependency_groups`, the same
Expand Down Expand Up @@ -359,7 +364,7 @@ pub(crate) fn edit_update_no_args(
let lockfile = &*manager.lockfile;
let string_buf = lockfile.buffers.string_bytes.as_slice();
let workspace_package_id =
lockfile.get_workspace_package_id(manager.workspace_name_hash);
lockfile.get_workspace_package_id(workspace_name_hash);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
let packages = lockfile.packages.slice();
let resolutions = packages.items_resolution();
let deps = packages.items_dependencies()[workspace_package_id as usize];
Expand Down Expand Up @@ -402,9 +407,7 @@ pub(crate) fn edit_update_no_args(
'updated: {
// fetchSwapRemove because we want to update the first dependency with a matching
// name, or none at all
if let Some(entry) =
manager.updating_packages.fetch_swap_remove(key_str)
{
if let Some(entry) = updating_packages.fetch_swap_remove(key_str) {
let is_alias = entry.value.is_alias;
let dep_name = &*entry.key;
debug_assert_eq!(
Expand Down
12 changes: 7 additions & 5 deletions src/install/PackageManager/PackageManagerEnqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1964,18 +1964,20 @@ fn get_or_put_resolved_package_with_find_result(
install_peer: bool,
success_fn: SuccessFn,
) -> crate::Result<Option<ResolvedPackageResult>> {
// reshaped for borrowck — `is_root_dependency(&self, &mut PackageManager, …)`
// reshaped for borrowck — `is_update_target_dependency(&self, &mut PackageManager, …)`
// borrows `this.lockfile` and `this` at once. Split via raw root.
let should_update = {
let this_ptr: *mut PackageManager = this;
// SAFETY: `is_root_dependency` reads `manager.root_dependency_list` /
// `manager.workspace_package_json_cache` only — disjoint from
// SAFETY: `is_update_target_dependency` reads `manager.root_package_id` /
// `manager.update_workspace_name_hashes` only — disjoint from
// `manager.lockfile`.
this.to_update
// Update direct deps of the current workspace; catalogs are root-scoped.
// Update direct deps of the targeted workspace(s): the cwd by
// default, or the `--recursive`/`--filter` set when one was
// selected. Catalogs are root-scoped.
Comment thread
robobun marked this conversation as resolved.
Resolved
&& (dependency.version.tag == dependency::version::Tag::Catalog
|| unsafe { &*(*this_ptr).lockfile }
.is_root_dependency(unsafe { &mut *this_ptr }, dependency_id))
.is_update_target_dependency(unsafe { &mut *this_ptr }, dependency_id))
// no need to do a look up if update requests are empty (`bun update` with no args)
&& (this.update_requests.is_empty()
|| this.updating_packages.contains(
Expand Down
Loading
Loading