Skip to content

Commit 3c91d59

Browse files
authoredJul 9, 2024
fix: make .setup-cache.bin in node_modules more reproducible (#24480)
1 parent ed49f00 commit 3c91d59

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed
 

‎cli/npm/managed/resolvers/local.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod bin_entries;
77
use std::borrow::Cow;
88
use std::cell::RefCell;
99
use std::cmp::Ordering;
10+
use std::collections::BTreeMap;
1011
use std::collections::HashMap;
1112
use std::collections::HashSet;
1213
use std::fs;
@@ -515,10 +516,13 @@ async fn sync_resolution_with_fs(
515516
Ok(())
516517
}
517518

519+
// Uses BTreeMap to preserve the ordering of the elements in memory, to ensure
520+
// the file generated from this datastructure is deterministic.
521+
// See: https://github.com/denoland/deno/issues/24479
518522
/// Represents a dependency at `node_modules/.deno/<package_id>/`
519523
struct SetupCacheDep<'a> {
520-
previous: Option<&'a HashMap<String, String>>,
521-
current: &'a mut HashMap<String, String>,
524+
previous: Option<&'a BTreeMap<String, String>>,
525+
current: &'a mut BTreeMap<String, String>,
522526
}
523527

524528
impl<'a> SetupCacheDep<'a> {
@@ -534,11 +538,14 @@ impl<'a> SetupCacheDep<'a> {
534538
}
535539
}
536540

541+
// Uses BTreeMap to preserve the ordering of the elements in memory, to ensure
542+
// the file generated from this datastructure is deterministic.
543+
// See: https://github.com/denoland/deno/issues/24479
537544
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
538545
struct SetupCacheData {
539-
root_symlinks: HashMap<String, String>,
540-
deno_symlinks: HashMap<String, String>,
541-
dep_symlinks: HashMap<String, HashMap<String, String>>,
546+
root_symlinks: BTreeMap<String, String>,
547+
deno_symlinks: BTreeMap<String, String>,
548+
dep_symlinks: BTreeMap<String, BTreeMap<String, String>>,
542549
}
543550

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

0 commit comments

Comments
 (0)