Skip to content

Commit ce0d458

Browse files
committed
chore: Address review comments by @Angelmmiguel and @ereslibre
1 parent 6e1c192 commit ce0d458

File tree

5 files changed

+29
-63
lines changed

5 files changed

+29
-63
lines changed

Cargo.lock

Lines changed: 1 addition & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/router/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ wws-runtimes-manager = { workspace = true }
1616
wws-worker = { workspace = true }
1717
lazy_static = "1.4.0"
1818
regex = "1"
19-
wax = "0.5.0"
19+
20+
# This commit fixes an issue with Walk::not, and is not yet released
21+
wax = { git = "https://github.com/olson-sean-k/wax.git", ref = "6d66a10" }
2022

2123
[dev-dependencies]
2224
path-slash = "0.2.1"

crates/router/src/files.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,64 @@ const IGNORE_PATH_PREFIX: &str = "_";
1212
/// It uses glob patterns to detect the workers and
1313
/// provide utilities to work with public folders and
1414
/// other related resources.
15-
pub struct Files {
15+
pub struct Files<'t> {
1616
/// Root path
1717
root: PathBuf,
1818
/// Defines pattern for files considered as workers
19-
include_pattern: String,
19+
include_pattern: Glob<'t>,
2020
/// Defines patterns to exclude when traversing for workers
21-
ignore_patterns: Vec<String>,
21+
ignore_patterns: Vec<Glob<'t>>,
2222
}
2323

24-
impl Files {
24+
impl<'t> Files<'t> {
25+
const PUBLIC_ASSETS_FOLDER: &str = "public";
2526
const DEFAULT_EXTENSIONS: [&str; 2] = ["js", "wasm"];
2627

2728
/// Initializes a new files instance. It will detect
2829
/// relevant resources for WWS like the public folder.
2930
pub fn new(root: &Path, file_extensions: Vec<String>, ignore_patterns: Vec<String>) -> Self {
3031
Self {
3132
root: root.to_path_buf(),
32-
include_pattern: Self::construct_include_pattern(file_extensions),
33-
ignore_patterns: Self::construct_ignore_patterns(ignore_patterns),
33+
include_pattern: Self::build_include_pattern(file_extensions),
34+
ignore_patterns: Self::build_ignore_patterns(ignore_patterns),
3435
}
3536
}
3637

3738
/// Walk through all the different files associated to this
3839
/// project using a Glob pattern
3940
pub fn walk(&self) -> Vec<WalkEntry> {
40-
let include_pattern = Glob::from_str(self.include_pattern.as_str()).expect(
41-
"Failed to parse include pattern when processing files in the current directory",
42-
);
43-
44-
return include_pattern
41+
return self
42+
.include_pattern
4543
.walk(&self.root)
46-
.not(self.ignore_patterns.iter().map(|s| s.as_str()))
47-
.expect(
48-
"Failed to parse ignore patterns when processing files in the current directory",
49-
)
44+
.not(self.ignore_patterns.clone())
45+
.expect("Failed to walk the tree when processing files in the current directory")
5046
.map(|e| e.unwrap())
5147
.collect();
5248
}
5349

54-
fn construct_include_pattern(file_extensions: Vec<String>) -> String {
50+
fn build_include_pattern(file_extensions: Vec<String>) -> Glob<'t> {
5551
let mut file_extensions = file_extensions;
5652
for default_extension in Self::DEFAULT_EXTENSIONS {
5753
file_extensions.push(default_extension.to_string());
5854
}
5955

60-
format!("**/*.{{{}}}", file_extensions.join(","))
56+
let include_pattern = format!("**/*.{{{}}}", file_extensions.join(","));
57+
Glob::from_str(include_pattern.as_str()).expect("Failed to parse include pattern!")
6158
}
6259

63-
fn construct_ignore_patterns(ignore_patterns: Vec<String>) -> Vec<String> {
64-
let mut result = vec![
65-
"**/public/**".to_string(),
60+
fn build_ignore_patterns(ignore_patterns: Vec<String>) -> Vec<Glob<'t>> {
61+
let default_ignore_patterns = vec![
62+
format!("**/{}/**", Self::PUBLIC_ASSETS_FOLDER),
6663
format!("**/{}/**", STORE_FOLDER),
6764
format!("**/{}*/**", IGNORE_PATH_PREFIX),
6865
];
66+
67+
let mut result = default_ignore_patterns;
6968
result.extend(ignore_patterns);
7069
result
70+
.iter()
71+
.map(|s| Glob::from_str(s.as_str()).expect("Failed to parse ignore pattern"))
72+
.collect()
7173
}
7274
}
7375

@@ -177,7 +179,7 @@ mod tests {
177179
}
178180

179181
#[test]
180-
fn walk_ignore2() {
182+
fn walk_ignore_multiple_patterns() {
181183
let files = Files::new(
182184
Path::new("tests/data/files"),
183185
vec!["ext".to_string(), "none".to_string()],

crates/router/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod route;
1212
use files::Files;
1313
use route::{Route, RouteAffinity};
1414
use std::path::{Path, PathBuf};
15-
use std::time::{Instant};
15+
use std::time::Instant;
1616
use wws_config::Config;
1717

1818
/// Contains all registered routes

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Args {
3333
prefix: String,
3434

3535
/// Patterns to ignore when looking for worker files
36-
#[arg(long, default_value = "", value_delimiter=';', num_args= 0..)]
36+
#[arg(long, default_value = "")]
3737
ignore: Vec<String>,
3838

3939
/// Manage language runtimes in your project

0 commit comments

Comments
 (0)