Skip to content

Commit d1833fa

Browse files
authored
fix: Use BTreeMap for bundled_deps in bun PackageIndex (#12266)
## Summary - Switches `bundled_deps` in `PackageIndex` from `HashMap` to `BTreeMap` for deterministic iteration order in `find_package()` ## Context Follow-up to #12254. `find_package()` iterates `bundled_deps` and returns the first match when a package isn't found via workspace-scoped or top-level lookups. With `HashMap`, the per-process random seed produces different iteration orders across `turbo` invocations, making the result non-deterministic when multiple parents bundle the same dependency name. This is unlikely to trigger in practice (bundled deps are rare, and having the same dep bundled by multiple parents is rarer), but it closes the last remaining `HashMap` iteration on a hash-affecting code path across all five lockfile implementations. No performance impact — `bundled_deps` is almost always empty. Closes #12252
1 parent 29bf4a5 commit d1833fa

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

crates/turborepo-lockfiles/src/bun/index.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! Package indexing for efficient lockfile lookups.
22
3-
use std::{collections::HashMap, sync::Arc};
3+
use std::{
4+
collections::{BTreeMap, HashMap},
5+
sync::Arc,
6+
};
47

58
use super::{PackageEntry, types::PackageKey};
69

@@ -22,7 +25,8 @@ pub struct PackageIndex {
2225

2326
/// Bundled dependency lookup
2427
/// Maps (parent_key, dep_name) -> lockfile key
25-
bundled_deps: HashMap<(StringRef, StringRef), StringRef>,
28+
/// BTreeMap for deterministic iteration in find_package().
29+
bundled_deps: BTreeMap<(StringRef, StringRef), StringRef>,
2630
}
2731

2832
impl PackageIndex {
@@ -31,7 +35,7 @@ impl PackageIndex {
3135
let mut by_key = HashMap::with_capacity(packages.len());
3236
let mut by_ident: HashMap<StringRef, Vec<StringRef>> = HashMap::new();
3337
let mut workspace_scoped = HashMap::new();
34-
let mut bundled_deps = HashMap::new();
38+
let mut bundled_deps = BTreeMap::new();
3539

3640
// First pass: populate by_key and by_ident
3741
for (key, entry) in packages {

turbo.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"dist/**/*",
6666
".next/**/*",
6767
"!.next/cache/**/*",
68-
"!.next/dev/**/*"
68+
"!.next/dev/**/*",
69+
"!README.md"
6970
],
7071
"dependsOn": ["^build"]
7172
},

0 commit comments

Comments
 (0)