diff --git a/crates/binding/src/lib.rs b/crates/binding/src/lib.rs index 013838b7e..6b50c41c2 100644 --- a/crates/binding/src/lib.rs +++ b/crates/binding/src/lib.rs @@ -1,6 +1,5 @@ #![deny(clippy::all)] -use std::cmp::Ordering; use std::sync::{Arc, Once}; use js_hook::{JsHooks, TsFnHooks}; @@ -194,39 +193,10 @@ pub fn build(env: Env, build_params: BuildParams) -> napi::Result { } // sort with enforce: pre / post - plugins.sort_by(|a, b| { - let a_enforce = a.enforce(); - let b_enforce = b.enforce(); - match (a_enforce, b_enforce) { - (Some(a_enforce), Some(b_enforce)) => { - if a_enforce == "pre" || b_enforce == "post" { - Ordering::Less - } else if a_enforce == "post" || b_enforce == "pre" { - Ordering::Greater - } else { - Ordering::Equal - } - } - (Some(a_enforce), None) => { - if a_enforce == "pre" { - Ordering::Less - } else if a_enforce == "post" { - Ordering::Greater - } else { - Ordering::Equal - } - } - (None, Some(b_enforce)) => { - if b_enforce == "post" { - Ordering::Greater - } else if b_enforce == "pre" { - Ordering::Less - } else { - Ordering::Equal - } - } - (None, None) => Ordering::Equal, - } + plugins.sort_by_key(|plugin| match plugin.enforce().as_deref() { + Some("pre") => 0, + Some("post") => 2, + _ => 1, }); let root = std::path::PathBuf::from(&build_params.root);