use fallow_config::ResolvedConfig;
pub const PRODUCTION_EXCLUDE_PATTERNS: &[&str] = &[
"**/*.test.*",
"**/*.spec.*",
"**/*.e2e.*",
"**/*.e2e-spec.*",
"**/*.bench.*",
"**/*.fixture.*",
"**/*.stories.*",
"**/*.story.*",
"**/__tests__/**",
"**/__mocks__/**",
"**/__snapshots__/**",
"**/__fixtures__/**",
"**/test-d/**",
"**/test/**",
"**/tests/**",
"*.config.*",
"**/.*.js",
"**/.*.ts",
"**/.*.mjs",
"**/.*.cjs",
];
pub(super) fn build_production_excludes(config: &ResolvedConfig) -> Option<globset::GlobSet> {
if !config.production {
return None;
}
production_exclude_globs(config)
}
pub fn production_exclude_globs(config: &ResolvedConfig) -> Option<globset::GlobSet> {
let mut builder = globset::GlobSetBuilder::new();
let user_patterns = config.production_ignore.iter().map(String::as_str);
for pattern in PRODUCTION_EXCLUDE_PATTERNS
.iter()
.copied()
.chain(user_patterns)
{
if let Ok(glob) = globset::GlobBuilder::new(pattern)
.literal_separator(true)
.build()
{
builder.add(glob);
}
}
builder.build().ok()
}
#[cfg(test)]
mod tests {
use super::PRODUCTION_EXCLUDE_PATTERNS;
#[test]
fn production_exclude_patterns_all_compile() {
for pattern in PRODUCTION_EXCLUDE_PATTERNS {
assert!(
globset::GlobBuilder::new(pattern)
.literal_separator(true)
.build()
.is_ok(),
"production exclude pattern does not compile: {pattern}"
);
}
}
}