Skip to content

Commit

Permalink
fix: revert preset-env match & add enforce exclude (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
shulandmimi authored Aug 29, 2024
1 parent b5d2a4c commit b7fb695
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-frogs-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farmfe/core": patch
---

revert preset-env match & add enforce exclude
27 changes: 11 additions & 16 deletions crates/plugin_polyfill/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ pub struct FarmPluginPolyfill {
config: swc_ecma_preset_env::Config,
include: Vec<ConfigRegex>,
exclude: Vec<ConfigRegex>,
enforce_exclude: Vec<ConfigRegex>,
assumptions: Assumptions,
}

impl FarmPluginPolyfill {
pub fn new(config: &Config) -> Self {
let (config, include, mut exclude, assumptions) = match &*config.preset_env {
let (config, include, exclude, assumptions) = match &*config.preset_env {
PresetEnvConfig::Bool(_) => {
let PresetEnvConfigObj {
include,
Expand Down Expand Up @@ -68,13 +69,12 @@ impl FarmPluginPolyfill {
}
};

exclude.push(ConfigRegex::new("node_modules/core-js"));

Self {
config,
include,
exclude,
assumptions,
enforce_exclude: vec![ConfigRegex::new("node_modules/core-js")],
}
}
}
Expand All @@ -100,22 +100,17 @@ impl Plugin for FarmPluginPolyfill {
// ignore node_modules by default
let relative_path = param.module_id.relative_path();

let is_exclude = || {
if self.exclude.is_empty() {
return false;
}

self.exclude.iter().any(|r| r.is_match(relative_path))
};

if is_exclude() {
if !self.include.iter().any(|r| r.is_match(relative_path))
&& self.exclude.iter().any(|r| r.is_match(relative_path))
{
return Ok(None);
}

let is_include =
|| self.include.is_empty() || self.include.iter().any(|r| r.is_match(relative_path));

if !is_include() {
if self
.enforce_exclude
.iter()
.any(|r| r.is_match(relative_path))
{
return Ok(None);
}

Expand Down

0 comments on commit b7fb695

Please sign in to comment.