Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove template custom filters feature #1822

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions crates/templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,3 @@ tokio = { version = "1.23", features = ["fs", "process", "rt", "macros"] }
toml = "0.5"
url = "2.2.2"
walkdir = "2"
wasmtime = { workspace = true }
wasmtime-wasi = { workspace = true }

[dependencies.wit-bindgen-wasmtime]
git = "https://github.com/fermyon/wit-bindgen-backport"
rev = "598cd229bb43baceff9616d16930b8a5a3e79d79"
features = ["async"]
166 changes: 0 additions & 166 deletions crates/templates/src/custom_filters.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
mod app_info;
mod cancellable;
mod constraints;
mod custom_filters;
mod directory;
mod environment;
mod filters;
Expand Down
36 changes: 10 additions & 26 deletions crates/templates/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum ExistsBehaviour {
Update,
}

#[allow(clippy::large_enum_variant)] // it's not worth it
enum InstallationResult {
Installed(Template),
Skipped(String, SkippedReason),
Expand Down Expand Up @@ -828,43 +829,26 @@ mod tests {
}

#[tokio::test]
async fn can_use_custom_filter_in_template() {
async fn cannot_use_custom_filter_in_template() {
let temp_dir = tempdir().unwrap();
let store = TemplateStore::new(temp_dir.path());
let manager = TemplateManager { store };
let source = TemplateSource::File(test_data_root());

manager
let install_results = manager
.install(&source, &InstallOptions::default(), &DiscardingReporter)
.await
.unwrap();

let template = manager.get("testing-custom-filter").unwrap().unwrap();
assert_eq!(1, install_results.skipped.len());

let dest_temp_dir = tempdir().unwrap();
let output_dir = dest_temp_dir.path().join("myproj");
let values = [
("p1".to_owned(), "biscuits".to_owned()),
("p2".to_owned(), "nomnomnom".to_owned()),
]
.into_iter()
.collect();
let options = RunOptions {
variant: crate::template::TemplateVariantInfo::NewApplication,
output_path: output_dir.clone(),
name: "custom-filter-test".to_owned(),
values,
accept_defaults: false,
let (id, reason) = &install_results.skipped[0];
assert_eq!("testing-custom-filter", id);
let SkippedReason::InvalidManifest(message) = reason else {
panic!("skip reason should be InvalidManifest"); // clippy dislikes assert!(false...)
};

template.run(options).silent().await.unwrap();

let message = tokio::fs::read_to_string(output_dir.join("test.txt"))
.await
.unwrap();
assert!(message.contains("p1/studly = bIsCuItS"));
assert!(message.contains("p2/studly = nOmNoMnOm"));
assert!(message.contains("p1/clappy = b👏i👏s👏c👏u👏i👏t👏s"));
assert_contains(message, "filters");
assert_contains(message, "not supported");
}

#[tokio::test]
Expand Down
9 changes: 1 addition & 8 deletions crates/templates/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) struct RawTemplateManifestV1 {
pub new_application: Option<RawTemplateVariant>,
pub add_component: Option<RawTemplateVariant>,
pub parameters: Option<IndexMap<String, RawParameter>>,
pub custom_filters: Option<Vec<RawCustomFilter>>,
pub custom_filters: Option<serde::de::IgnoredAny>, // kept for error messaging
}

#[derive(Debug, Deserialize)]
Expand All @@ -45,13 +45,6 @@ pub(crate) struct RawParameter {
pub pattern: Option<String>,
}

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub(crate) struct RawCustomFilter {
pub name: String,
pub wasm: String,
}

pub(crate) fn parse_manifest_toml(text: impl AsRef<str>) -> anyhow::Result<RawTemplateManifest> {
toml::from_str(text.as_ref()).context("Failed to parse template manifest TOML")
}
Expand Down
5 changes: 1 addition & 4 deletions crates/templates/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,11 @@ impl Run {
}

fn template_parser(&self) -> liquid::Parser {
let mut builder = liquid::ParserBuilder::with_stdlib()
let builder = liquid::ParserBuilder::with_stdlib()
.filter(crate::filters::KebabCaseFilterParser)
.filter(crate::filters::PascalCaseFilterParser)
.filter(crate::filters::SnakeCaseFilterParser)
.filter(crate::filters::HttpWildcardFilterParser);
for filter in self.template.custom_filters() {
builder = builder.filter(filter);
}
builder
.build()
.expect("can't fail due to no partials support")
Expand Down
Loading