Skip to content

Commit c8a0e51

Browse files
authored
Fix config loading precedence for v3 transformers (#884)
1 parent 8eb84ee commit c8a0e51

File tree

11 files changed

+1275
-112
lines changed

11 files changed

+1275
-112
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@atlaspack/rust': patch
3+
---
4+
5+
Fix config loading precedence for v3 transformer patterns

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/atlaspack_config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ serde_json5 = { workspace = true }
2424

2525
[dev-dependencies]
2626
anyhow = { workspace = true }
27+
atlaspack_test_fixtures = { path = "../atlaspack_test_fixtures" }
2728
mockall = { workspace = true }

crates/atlaspack_config/src/atlaspack_config.rs

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::sync::Arc;
33

44
use atlaspack_core::diagnostic_error;
55
use atlaspack_core::types::DiagnosticError;
6-
use indexmap::IndexMap;
76
use serde::Deserialize;
87
use serde::Serialize;
98

@@ -38,36 +37,17 @@ impl TryFrom<PartialAtlaspackConfig> for AtlaspackConfig {
3837
type Error = DiagnosticError;
3938

4039
fn try_from(config: PartialAtlaspackConfig) -> Result<Self, Self::Error> {
41-
// The final stage of merging filters out any ... extensions as they are a noop
42-
fn filter_out_extends(pipelines: Vec<PluginNode>) -> Vec<PluginNode> {
43-
pipelines
44-
.into_iter()
45-
.filter(|p| p.package_name != "...")
46-
.collect()
47-
}
48-
49-
fn filter_out_extends_from_map(
50-
map: IndexMap<String, Vec<PluginNode>>,
51-
) -> IndexMap<String, Vec<PluginNode>> {
52-
map
53-
.into_iter()
54-
.map(|(pattern, plugins)| (pattern, filter_out_extends(plugins)))
55-
.collect()
56-
}
57-
5840
let mut missing_phases = Vec::new();
5941

6042
if config.bundler.is_none() {
6143
missing_phases.push(String::from("bundler"));
6244
}
6345

64-
let namers = filter_out_extends(config.namers);
65-
if namers.is_empty() {
46+
if config.namers.is_empty() {
6647
missing_phases.push(String::from("namers"));
6748
}
6849

69-
let resolvers = filter_out_extends(config.resolvers);
70-
if resolvers.is_empty() {
50+
if config.resolvers.is_empty() {
7151
missing_phases.push(String::from("resolvers"));
7252
}
7353

@@ -80,15 +60,15 @@ impl TryFrom<PartialAtlaspackConfig> for AtlaspackConfig {
8060

8161
Ok(AtlaspackConfig {
8262
bundler: config.bundler.unwrap(),
83-
compressors: PipelinesMap::new(filter_out_extends_from_map(config.compressors)),
84-
namers,
85-
optimizers: NamedPipelinesMap::new(filter_out_extends_from_map(config.optimizers)),
63+
compressors: PipelinesMap::new(config.compressors),
64+
namers: config.namers,
65+
optimizers: NamedPipelinesMap::new(config.optimizers),
8666
packagers: PipelineMap::new(config.packagers),
87-
reporters: filter_out_extends(config.reporters),
88-
resolvers,
89-
runtimes: filter_out_extends(config.runtimes),
90-
transformers: NamedPipelinesMap::new(filter_out_extends_from_map(config.transformers)),
91-
validators: PipelinesMap::new(filter_out_extends_from_map(config.validators)),
67+
reporters: config.reporters,
68+
resolvers: config.resolvers,
69+
runtimes: config.runtimes,
70+
transformers: NamedPipelinesMap::new(config.transformers),
71+
validators: PipelinesMap::new(config.validators),
9272
})
9373
}
9474
}
@@ -113,33 +93,5 @@ mod tests {
11393
)
11494
);
11595
}
116-
117-
#[test]
118-
fn returns_the_config() {
119-
fn plugin() -> PluginNode {
120-
PluginNode {
121-
package_name: String::from("package"),
122-
resolve_from: Arc::new(PathBuf::from("/")),
123-
}
124-
}
125-
126-
fn extension() -> PluginNode {
127-
PluginNode {
128-
package_name: String::from("..."),
129-
resolve_from: Arc::new(PathBuf::from("/")),
130-
}
131-
}
132-
133-
let partial_config = PartialAtlaspackConfigBuilder::default()
134-
.bundler(Some(plugin()))
135-
.namers(vec![plugin()])
136-
.resolvers(vec![extension(), plugin()])
137-
.build()
138-
.unwrap();
139-
140-
let config = AtlaspackConfig::try_from(partial_config);
141-
142-
assert!(config.is_ok_and(|c| !c.resolvers.contains(&extension())));
143-
}
14496
}
14597
}

0 commit comments

Comments
 (0)