Skip to content

Commit

Permalink
feat: make .setup-cache.bin reproducible
Browse files Browse the repository at this point in the history
The .setup-cache.bin is currently not reproducible because it consists of serialized Hashmaps which have a random order of elements. By switching them out for BTreeMaps, which are always sorted in memory, deno generates the same file every time.
  • Loading branch information
zebreus committed Jul 8, 2024
1 parent b338b54 commit 8b002aa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cli/npm/managed/resolvers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod bin_entries;
use std::borrow::Cow;
use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::fs;
Expand Down Expand Up @@ -504,8 +505,8 @@ async fn sync_resolution_with_fs(

/// Represents a dependency at `node_modules/.deno/<package_id>/`
struct SetupCacheDep<'a> {
previous: Option<&'a HashMap<String, String>>,
current: &'a mut HashMap<String, String>,
previous: Option<&'a BTreeMap<String, String>>,
current: &'a mut BTreeMap<String, String>,
}

impl<'a> SetupCacheDep<'a> {
Expand All @@ -523,9 +524,9 @@ impl<'a> SetupCacheDep<'a> {

#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
struct SetupCacheData {
root_symlinks: HashMap<String, String>,
deno_symlinks: HashMap<String, String>,
dep_symlinks: HashMap<String, HashMap<String, String>>,
root_symlinks: BTreeMap<String, String>,
deno_symlinks: BTreeMap<String, String>,
dep_symlinks: BTreeMap<String, BTreeMap<String, String>>,
}

/// It is very slow to try to re-setup the symlinks each time, so this will
Expand Down

0 comments on commit 8b002aa

Please sign in to comment.