Skip to content

Commit 05551f6

Browse files
authored
Merge pull request #138 from itowlson/fix-inferred-wasm-path
Fix inferred dep path losing patch version
2 parents 021aae5 + 039d37c commit 05551f6

File tree

1 file changed

+28
-1
lines changed
  • crates/wac-resolver/src

1 file changed

+28
-1
lines changed

crates/wac-resolver/src/fs.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl FileSystemPackageResolver {
6161

6262
// If the path is not a directory, use a `.wasm` or `.wat` extension
6363
if !path.is_dir() {
64-
path.set_extension("wasm");
64+
append_extension(&mut path, "wasm");
6565

6666
#[cfg(feature = "wat")]
6767
{
@@ -176,3 +176,30 @@ impl Default for FileSystemPackageResolver {
176176
Self::new("deps", Default::default(), true)
177177
}
178178
}
179+
180+
/// Similar to Path::set_extension except it always appends.
181+
/// For example "0.0.1" -> "0.0.1.wasm" (instead of to "0.0.wasm").
182+
fn append_extension(path: &mut PathBuf, extension: &str) {
183+
let os_str = path.as_mut_os_string();
184+
os_str.push(".");
185+
os_str.push(extension)
186+
}
187+
188+
#[cfg(test)]
189+
mod tests {
190+
use super::*;
191+
192+
#[test]
193+
fn append_extension_if_no_existing_extension() {
194+
let mut path = PathBuf::from("a/b/c");
195+
append_extension(&mut path, "txt");
196+
assert_eq!("a/b/c.txt", path.display().to_string());
197+
}
198+
199+
#[test]
200+
fn append_extension_if_existing_extension() {
201+
let mut path = PathBuf::from("a/b/0.0.1");
202+
append_extension(&mut path, "wasm");
203+
assert_eq!("a/b/0.0.1.wasm", path.display().to_string());
204+
}
205+
}

0 commit comments

Comments
 (0)