Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit 01c4deb

Browse files
authored
Fix error if glob pattern matched nested subdirectory (#96)
1 parent ee22a78 commit 01c4deb

File tree

7 files changed

+50
-12
lines changed

7 files changed

+50
-12
lines changed

src/expander.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn expand_file_to_parcels(
268268
let paths = glob::glob(&expansion_context.to_absolute(pattern))?;
269269
let parcels = paths
270270
.into_iter()
271-
.map(|p| try_convert_one_match_to_parcel(p, expansion_context, member_of))
271+
.filter_map(|p| try_convert_one_match_to_parcel(p, expansion_context, member_of))
272272
.collect::<anyhow::Result<Vec<_>>>()?;
273273
let warned_parcels = if parcels.is_empty() {
274274
Warned::from((parcels, format!("No files matched pattern {}", pattern)))
@@ -282,19 +282,23 @@ fn try_convert_one_match_to_parcel(
282282
path: Result<PathBuf, GlobError>,
283283
expansion_context: &ExpansionContext,
284284
member_of: &str,
285-
) -> anyhow::Result<Parcel> {
285+
) -> Option<anyhow::Result<Parcel>> {
286286
match path {
287-
Err(e) => Err(anyhow::anyhow!("Couldn't expand pattern: {}", e)),
287+
Err(e) => Some(Err(anyhow::anyhow!("Couldn't expand pattern: {}", e))),
288288
Ok(path) => {
289-
let features = vec![("file", "true")];
290-
convert_one_match_to_parcel(
291-
path,
292-
expansion_context,
293-
features,
294-
None,
295-
Some(member_of),
296-
None,
297-
)
289+
if path.is_dir() {
290+
None
291+
} else {
292+
let features = vec![("file", "true")];
293+
Some(convert_one_match_to_parcel(
294+
path,
295+
expansion_context,
296+
features,
297+
None,
298+
Some(member_of),
299+
None,
300+
))
301+
}
298302
}
299303
}
300304
}
@@ -972,6 +976,23 @@ mod test {
972976
assert_eq!(0, count);
973977
}
974978

979+
#[test]
980+
fn test_finds_assets_in_nested_subdirectories() {
981+
let invoice = expand_test_invoice("nesttest").unwrap();
982+
let assets = invoice
983+
.parcel
984+
.unwrap()
985+
.iter()
986+
.filter(|parcel| parcel.member_of("out/fake.wasm-files"))
987+
.map(|parcel| parcel.label.name.clone())
988+
.collect_vec();
989+
assert_eq!(4, assets.len());
990+
assert!(assets.contains(&"assets/scripts/justsome.json".to_owned()));
991+
assert!(assets.contains(&"assets/scripts/real.js".to_owned()));
992+
assert!(assets.contains(&"assets/styles/css/suspicious.css".to_owned()));
993+
assert!(assets.contains(&"assets/styles/sass/iffy.sass".to_owned()));
994+
}
995+
975996
#[test]
976997
fn test_if_file_does_not_exist_then_no_asset_parcels() {
977998
// TODO: I feel like this should be an error

testdata/nesttest/HIPPOFACTS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[bindle]
2+
name = "weather"
3+
version = "1.2.3"
4+
5+
[[handler]]
6+
name = "out/fake.wasm"
7+
route = "/"
8+
files = ["assets/**/*"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"fact": "this shouldn't be included in the bindle"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function foo() {
2+
console.log("This should be included in the bindle")
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* not a css file at all */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* not an actual sass file */

testdata/nesttest/out/fake.wasm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Supposedly Wasm but not really

0 commit comments

Comments
 (0)