From 3c91d597ce6436d6b602f15af6b3e22379e0ed00 Mon Sep 17 00:00:00 2001 From: Zebreus Date: Tue, 9 Jul 2024 20:04:21 +0200 Subject: fix: make .setup-cache.bin in node_modules more reproducible (#24480) --- cli/npm/managed/resolvers/local.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'cli') diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs index ed36162c0..1f8e82d54 100644 --- a/cli/npm/managed/resolvers/local.rs +++ b/cli/npm/managed/resolvers/local.rs @@ -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; @@ -515,10 +516,13 @@ async fn sync_resolution_with_fs( Ok(()) } +// Uses BTreeMap to preserve the ordering of the elements in memory, to ensure +// the file generated from this datastructure is deterministic. +// See: https://github.com/denoland/deno/issues/24479 /// Represents a dependency at `node_modules/.deno//` struct SetupCacheDep<'a> { - previous: Option<&'a HashMap>, - current: &'a mut HashMap, + previous: Option<&'a BTreeMap>, + current: &'a mut BTreeMap, } impl<'a> SetupCacheDep<'a> { @@ -534,11 +538,14 @@ impl<'a> SetupCacheDep<'a> { } } +// Uses BTreeMap to preserve the ordering of the elements in memory, to ensure +// the file generated from this datastructure is deterministic. +// See: https://github.com/denoland/deno/issues/24479 #[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)] struct SetupCacheData { - root_symlinks: HashMap, - deno_symlinks: HashMap, - dep_symlinks: HashMap>, + root_symlinks: BTreeMap, + deno_symlinks: BTreeMap, + dep_symlinks: BTreeMap>, } /// It is very slow to try to re-setup the symlinks each time, so this will -- cgit v1.2.3