use super::Plugin;
const ENABLERS: &[&str] = &["rspress", "@rspress/"];
const VIRTUAL_MODULE_PREFIXES: &[&str] = &["@theme/", "@theme-original/"];
define_plugin! {
struct RspressPlugin => "rspress",
enablers: ENABLERS,
virtual_module_prefixes: VIRTUAL_MODULE_PREFIXES,
}
#[cfg(test)]
mod tests {
use std::path::Path;
use super::*;
use crate::analyze::matches_virtual_prefix;
#[test]
fn activates_on_rspress_and_rspress_scope() {
let plugin = RspressPlugin;
assert!(plugin.is_enabled_with_deps(&["rspress".to_string()], Path::new("/p")));
assert!(plugin.is_enabled_with_deps(&["@rspress/core".to_string()], Path::new("/p")));
assert!(
plugin.is_enabled_with_deps(&["@rspress/theme-default".to_string()], Path::new("/p"))
);
}
#[test]
fn inactive_without_rspress() {
let plugin = RspressPlugin;
assert!(!plugin.is_enabled_with_deps(&["react".to_string()], Path::new("/p")));
assert!(!plugin.is_enabled_with_deps(&["rspress-plugin-foo".to_string()], Path::new("/p")));
}
#[test]
fn contributes_theme_virtual_prefixes() {
let prefixes = RspressPlugin.virtual_module_prefixes();
assert!(prefixes.contains(&"@theme/"));
assert!(prefixes.contains(&"@theme-original/"));
}
#[test]
fn theme_prefix_covers_bare_and_subpath_imports() {
let prefixes = RspressPlugin.virtual_module_prefixes();
assert!(
prefixes
.iter()
.any(|prefix| matches_virtual_prefix(prefix, "@theme"))
);
assert!(
prefixes
.iter()
.any(|prefix| matches_virtual_prefix(prefix, "@theme/Layout"))
);
assert!(
prefixes
.iter()
.any(|prefix| matches_virtual_prefix(prefix, "@theme-original/Layout"))
);
assert!(
!prefixes
.iter()
.any(|prefix| matches_virtual_prefix(prefix, "@theme-ui/core"))
);
}
}