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

Commit

Permalink
Fix error if glob pattern matched nested subdirectory (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
itowlson authored Jan 5, 2022
1 parent ee22a78 commit 01c4deb
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
45 changes: 33 additions & 12 deletions src/expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn expand_file_to_parcels(
let paths = glob::glob(&expansion_context.to_absolute(pattern))?;
let parcels = paths
.into_iter()
.map(|p| try_convert_one_match_to_parcel(p, expansion_context, member_of))
.filter_map(|p| try_convert_one_match_to_parcel(p, expansion_context, member_of))
.collect::<anyhow::Result<Vec<_>>>()?;
let warned_parcels = if parcels.is_empty() {
Warned::from((parcels, format!("No files matched pattern {}", pattern)))
Expand All @@ -282,19 +282,23 @@ fn try_convert_one_match_to_parcel(
path: Result<PathBuf, GlobError>,
expansion_context: &ExpansionContext,
member_of: &str,
) -> anyhow::Result<Parcel> {
) -> Option<anyhow::Result<Parcel>> {
match path {
Err(e) => Err(anyhow::anyhow!("Couldn't expand pattern: {}", e)),
Err(e) => Some(Err(anyhow::anyhow!("Couldn't expand pattern: {}", e))),
Ok(path) => {
let features = vec![("file", "true")];
convert_one_match_to_parcel(
path,
expansion_context,
features,
None,
Some(member_of),
None,
)
if path.is_dir() {
None
} else {
let features = vec![("file", "true")];
Some(convert_one_match_to_parcel(
path,
expansion_context,
features,
None,
Some(member_of),
None,
))
}
}
}
}
Expand Down Expand Up @@ -972,6 +976,23 @@ mod test {
assert_eq!(0, count);
}

#[test]
fn test_finds_assets_in_nested_subdirectories() {
let invoice = expand_test_invoice("nesttest").unwrap();
let assets = invoice
.parcel
.unwrap()
.iter()
.filter(|parcel| parcel.member_of("out/fake.wasm-files"))
.map(|parcel| parcel.label.name.clone())
.collect_vec();
assert_eq!(4, assets.len());
assert!(assets.contains(&"assets/scripts/justsome.json".to_owned()));
assert!(assets.contains(&"assets/scripts/real.js".to_owned()));
assert!(assets.contains(&"assets/styles/css/suspicious.css".to_owned()));
assert!(assets.contains(&"assets/styles/sass/iffy.sass".to_owned()));
}

#[test]
fn test_if_file_does_not_exist_then_no_asset_parcels() {
// TODO: I feel like this should be an error
Expand Down
8 changes: 8 additions & 0 deletions testdata/nesttest/HIPPOFACTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[bindle]
name = "weather"
version = "1.2.3"

[[handler]]
name = "out/fake.wasm"
route = "/"
files = ["assets/**/*"]
3 changes: 3 additions & 0 deletions testdata/nesttest/assets/scripts/justsome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"fact": "this shouldn't be included in the bindle"
}
3 changes: 3 additions & 0 deletions testdata/nesttest/assets/scripts/real.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function foo() {
console.log("This should be included in the bindle")
}
1 change: 1 addition & 0 deletions testdata/nesttest/assets/styles/css/suspicious.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* not a css file at all */
1 change: 1 addition & 0 deletions testdata/nesttest/assets/styles/sass/iffy.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* not an actual sass file */
1 change: 1 addition & 0 deletions testdata/nesttest/out/fake.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Supposedly Wasm but not really

0 comments on commit 01c4deb

Please sign in to comment.