-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e12a947
commit abd6c9e
Showing
11 changed files
with
845 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
pub mod config_error; | ||
pub mod map; | ||
pub mod parcel_config; | ||
#[cfg(test)] | ||
mod parcel_config_fixtures; | ||
pub mod parcel_config_fixtures; | ||
pub mod parcel_rc; | ||
pub mod parcel_rc_config_loader; | ||
mod partial_parcel_config; | ||
pub mod pipeline; | ||
|
||
pub use parcel_config::ParcelConfig; | ||
pub use parcel_config::PluginNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mod matcher; | ||
use matcher::*; | ||
|
||
mod named_pipelines_map; | ||
pub use named_pipelines_map::*; | ||
|
||
mod pipeline_map; | ||
pub use pipeline_map::*; | ||
|
||
mod pipelines_map; | ||
pub use pipelines_map::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
use std::path::Path; | ||
|
||
use glob_match::glob_match; | ||
|
||
pub fn named_pattern_matcher<'a>(path: &'a Path) -> impl Fn(&str, &str) -> bool + 'a { | ||
let basename = path.file_name().unwrap().to_str().unwrap(); | ||
let path = path.as_os_str().to_str().unwrap(); | ||
|
||
|pattern, pipeline| { | ||
let (named_pipeline, pattern) = pattern.split_once(':').unwrap_or(("", pattern)); | ||
pipeline == named_pipeline && (glob_match(pattern, basename) || glob_match(pattern, path)) | ||
} | ||
} | ||
|
||
pub fn pattern_matcher<'a>(path: &'a Path) -> impl Fn(&str) -> bool + 'a { | ||
let is_match = named_pattern_matcher(path); | ||
|
||
move |pattern| is_match(pattern, "") | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
use super::*; | ||
|
||
fn paths(filename: &str) -> Vec<PathBuf> { | ||
let cwd = env::current_dir().unwrap(); | ||
vec![ | ||
PathBuf::from(filename), | ||
cwd.join(filename), | ||
cwd.join("src").join(filename), | ||
] | ||
} | ||
|
||
mod named_pattern_matcher { | ||
use super::*; | ||
|
||
#[test] | ||
fn returns_false_when_path_does_not_match_pattern_with_empty_pipeline() { | ||
for path in paths("a.ts") { | ||
let is_match = named_pattern_matcher(&path); | ||
|
||
assert_eq!(is_match("*.t", ""), false); | ||
assert_eq!(is_match("*.tsx", ""), false); | ||
assert_eq!(is_match("types:*.{ts,tsx}", ""), false); | ||
assert_eq!(is_match("url:*", ""), false); | ||
} | ||
} | ||
|
||
#[test] | ||
fn returns_false_when_path_does_not_match_pipeline() { | ||
for path in paths("a.ts") { | ||
let is_match = named_pattern_matcher(&path); | ||
|
||
assert_eq!(is_match("types:*.{ts,tsx}", "type"), false); | ||
assert_eq!(is_match("types:*.{ts,tsx}", "typesa"), false); | ||
} | ||
} | ||
|
||
#[test] | ||
fn returns_true_when_path_matches_pattern_with_empty_pipeline() { | ||
for path in paths("a.ts") { | ||
let is_match = named_pattern_matcher(&path); | ||
|
||
assert_eq!(is_match("*.{ts,tsx}", ""), true); | ||
assert_eq!(is_match("*.ts", ""), true); | ||
assert_eq!(is_match("*", ""), true); | ||
} | ||
} | ||
|
||
#[test] | ||
fn returns_true_when_path_matches_pattern_and_pipeline() { | ||
for path in paths("a.ts") { | ||
let is_match = named_pattern_matcher(&path); | ||
|
||
assert_eq!(is_match("types:*.{ts,tsx}", "types"), true); | ||
assert_eq!(is_match("types:*.ts", "types"), true); | ||
assert_eq!(is_match("types:*", "types"), true); | ||
} | ||
} | ||
} | ||
|
||
mod pattern_matcher { | ||
use super::*; | ||
|
||
#[test] | ||
fn returns_false_when_path_does_not_match_pattern() { | ||
for path in paths("a.ts") { | ||
let is_match = pattern_matcher(&path); | ||
|
||
assert_eq!(is_match("*.t"), false); | ||
assert_eq!(is_match("*.tsx"), false); | ||
assert_eq!(is_match("types:*.{ts,tsx}"), false); | ||
assert_eq!(is_match("url:*"), false); | ||
} | ||
} | ||
|
||
#[test] | ||
fn returns_true_when_path_matches_pattern_with_empty_pipeline() { | ||
for path in paths("a.ts") { | ||
let is_match = pattern_matcher(&path); | ||
|
||
assert_eq!(is_match("*.{ts,tsx}"), true); | ||
assert_eq!(is_match("*.ts"), true); | ||
assert_eq!(is_match("*"), true); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.