diff --git a/Cargo.lock b/Cargo.lock index 6c61e61dba977..e186925b866ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4944,11 +4944,11 @@ checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] name = "patricia_tree" -version = "0.5.5" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "062a6297f2cd3969a780156ccb288eafb34bb5ed0f3c9a2b4500dbde869d4b86" +checksum = "4df0e43512f12f23a6b08c7b893192b7d6ec937b95ee03af040847907fe5cef7" dependencies = [ - "bitflags 1.3.2", + "serde", ] [[package]] diff --git a/turbopack/crates/turbopack-core/Cargo.toml b/turbopack/crates/turbopack-core/Cargo.toml index f9b0f227b778a..51f16c5af379f 100644 --- a/turbopack/crates/turbopack-core/Cargo.toml +++ b/turbopack/crates/turbopack-core/Cargo.toml @@ -23,7 +23,7 @@ data-encoding = { workspace = true } either = { workspace = true } indexmap = { workspace = true } once_cell = { workspace = true } -patricia_tree = "0.5.5" +patricia_tree = { version = "0.10.1", features = ["serde"] } petgraph = { workspace = true, features = ["serde-1"] } roaring = { workspace = true, features = ["serde"] } ref-cast = "1.0.20" diff --git a/turbopack/crates/turbopack-core/src/resolve/alias_map.rs b/turbopack/crates/turbopack-core/src/resolve/alias_map.rs index 4c73f9d13190d..a6c85fdd18fe9 100644 --- a/turbopack/crates/turbopack-core/src/resolve/alias_map.rs +++ b/turbopack/crates/turbopack-core/src/resolve/alias_map.rs @@ -6,12 +6,7 @@ use std::{ use anyhow::Result; use patricia_tree::PatriciaMap; -use serde::{ - Deserialize, Deserializer, Serialize, Serializer, - de::{MapAccess, Visitor}, - ser::SerializeMap, -}; -use serde_bytes::{ByteBuf, Bytes}; +use serde::{Deserialize, Serialize}; use turbo_rcstr::RcStr; use turbo_tasks::{ NonLocalValue, @@ -29,7 +24,8 @@ use super::pattern::Pattern; /// /// If the pattern does not have a wildcard character, it will only match the /// exact string, and return the template as-is. -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] +#[serde(transparent)] pub struct AliasMap { map: PatriciaMap>, } @@ -55,63 +51,6 @@ where impl Eq for AliasMap where T: Eq {} -impl Serialize for AliasMap -where - T: Serialize, -{ - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut map = serializer.serialize_map(Some(self.map.len()))?; - for (prefix, value) in self.map.iter() { - let key = ByteBuf::from(prefix); - map.serialize_entry(&key, value)?; - } - map.end() - } -} - -struct AliasMapVisitor { - marker: std::marker::PhantomData, -} - -impl<'de, T> Visitor<'de> for AliasMapVisitor -where - T: Deserialize<'de>, -{ - type Value = AliasMap; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("a map of alias patterns to templates") - } - - fn visit_map(self, mut access: M) -> Result - where - M: MapAccess<'de>, - { - let mut map = AliasMap::new(); - while let Some((key, value)) = access.next_entry::<&Bytes, _>()? { - map.map.insert(key, value); - } - Ok(map) - } -} - -impl<'a, T> Deserialize<'a> for AliasMap -where - T: Deserialize<'a>, -{ - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'a>, - { - deserializer.deserialize_map(AliasMapVisitor { - marker: std::marker::PhantomData, - }) - } -} - impl TraceRawVcs for AliasMap where T: TraceRawVcs, @@ -392,7 +331,7 @@ impl<'a, T> IntoIterator for &'a AliasMap { /// /// [PATTERN_KEY_COMPARE]: https://nodejs.org/api/esm.html#resolver-algorithm-specification pub struct AliasMapIntoIter { - iter: patricia_tree::map::IntoIter>, + iter: patricia_tree::map::IntoIter, BTreeMap>, current_prefix_iterator: Option>, } @@ -457,7 +396,7 @@ impl Iterator for AliasMapIntoIter { /// /// [PATTERN_KEY_COMPARE]: https://nodejs.org/api/esm.html#resolver-algorithm-specification pub struct AliasMapIter<'a, T> { - iter: patricia_tree::map::Iter<'a, BTreeMap>, + iter: patricia_tree::map::Iter<'a, Vec, BTreeMap>, current_prefix_iterator: Option>, }