summaryrefslogtreecommitdiff
path: root/cli/npm/managed/resolvers/local.rs
diff options
context:
space:
mode:
authorZebreus <zebreus@zebre.us>2024-07-09 20:04:21 +0200
committerGitHub <noreply@github.com>2024-07-09 18:04:21 +0000
commit3c91d597ce6436d6b602f15af6b3e22379e0ed00 (patch)
tree7adfe6a56c1a124c07ef2f6d3ab70b38c86027dd /cli/npm/managed/resolvers/local.rs
parented49f00e04959bc7ea6e169fd7a7bdc341f06062 (diff)
fix: make .setup-cache.bin in node_modules more reproducible (#24480)
Diffstat (limited to 'cli/npm/managed/resolvers/local.rs')
-rw-r--r--cli/npm/managed/resolvers/local.rs17
1 files changed, 12 insertions, 5 deletions
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/<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> {
@@ -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<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