Skip to content

Commit fa4bb34

Browse files
Add serde to config types (#9718)
1 parent 43d5d19 commit fa4bb34

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

crates/parcel_config/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ indexmap = { version = "2.2.6", features = ["serde", "std"] }
1111
parcel_filesystem = { path = "../parcel_filesystem" }
1212
parcel_package_manager = { path = "../parcel_package_manager" }
1313
pathdiff = "0.2.1"
14-
serde = { version = "1.0.123", features = ["derive"] }
14+
serde = { version = "1.0.123", features = ["derive", "rc"] }
1515
serde_json5 = "0.1.0"
1616
thiserror = "1.0.59"
1717

crates/parcel_config/src/parcel_config.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ use std::path::PathBuf;
33
use std::rc::Rc;
44

55
use indexmap::IndexMap;
6+
use serde::Deserialize;
7+
use serde::Serialize;
68

79
use super::config_error::ConfigError;
810
use super::partial_parcel_config::PartialParcelConfig;
911
use super::pipeline::is_match;
1012
use super::pipeline::PipelineMap;
1113

12-
#[derive(Clone, Debug, PartialEq)]
14+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
15+
#[serde(rename_all = "camelCase")]
1316
pub struct PluginNode {
1417
pub package_name: String,
1518
pub resolve_from: Rc<PathBuf>,
1619
}
1720

1821
/// Represents a fully merged and validated .parcel_rc config
19-
#[derive(Debug, PartialEq)]
22+
#[derive(Debug, Deserialize, PartialEq, Serialize)]
2023
pub struct ParcelConfig {
2124
pub(crate) bundler: PluginNode,
2225
pub(crate) compressors: PipelineMap,

crates/parcel_config/src/pipeline.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::path::Path;
22

33
use glob_match::glob_match;
44
use indexmap::IndexMap;
5+
use serde::Deserialize;
6+
use serde::Serialize;
57

68
use super::parcel_config::PluginNode;
79

@@ -25,15 +27,15 @@ use super::parcel_config::PluginNode;
2527
/// });
2628
/// ```
2729
///
28-
#[derive(Debug, Default, PartialEq)]
29-
pub struct PipelineMap {
30+
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
31+
pub struct PipelineMap(
3032
/// Maps patterns to a series of plugins, called pipelines
31-
map: IndexMap<String, Vec<PluginNode>>,
32-
}
33+
IndexMap<String, Vec<PluginNode>>,
34+
);
3335

3436
impl PipelineMap {
3537
pub fn new(map: IndexMap<String, Vec<PluginNode>>) -> Self {
36-
Self { map }
38+
Self(map)
3739
}
3840

3941
/// Finds pipelines contained by a pattern that match the given file path and named pipeline
@@ -74,7 +76,7 @@ impl PipelineMap {
7476
// If a pipeline is requested, a the glob needs to match exactly
7577
if let Some(pipeline) = named_pipeline {
7678
let exact_match = self
77-
.map
79+
.0
7880
.iter()
7981
.find(|(pattern, _)| is_match(pattern, path, basename, pipeline.as_ref()));
8082

@@ -85,7 +87,7 @@ impl PipelineMap {
8587
}
8688
}
8789

88-
for (pattern, pipelines) in self.map.iter() {
90+
for (pattern, pipelines) in self.0.iter() {
8991
if is_match(&pattern, path, basename, "") {
9092
matches.extend(pipelines.iter().cloned());
9193
}
@@ -97,15 +99,12 @@ impl PipelineMap {
9799
pub fn contains_named_pipeline(&self, pipeline: impl AsRef<str>) -> bool {
98100
let named_pipeline = format!("{}:", pipeline.as_ref());
99101

100-
self
101-
.map
102-
.keys()
103-
.any(|glob| glob.starts_with(&named_pipeline))
102+
self.0.keys().any(|glob| glob.starts_with(&named_pipeline))
104103
}
105104

106105
pub fn named_pipelines(&self) -> Vec<&str> {
107106
self
108-
.map
107+
.0
109108
.keys()
110109
.filter_map(|glob| glob.split_once(':').map(|g| g.0))
111110
.collect()

0 commit comments

Comments
 (0)