Skip to content

Commit

Permalink
fix: hash also need to split
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinbao1001 committed Aug 27, 2024
1 parent e9aeb86 commit 6959eac
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions crates/mako/src/generate/generate_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,26 @@ impl ChunkFile {
// fixed os error 63 file name too long, reserve 48 bytes for _js-async、extension、.map and others
let reserve_file_name_length = 207;
let file_path = Path::new(&self.file_name);
let mut format_file_name = self.file_name.clone();
if self.file_name.len() > reserve_file_name_length {
let mut hasher: XxHash64 = Default::default();
hasher.write_str(self.file_name.as_str());
let file_extension = file_path.extension().unwrap();
let file_stem = file_path.file_stem().unwrap().to_string_lossy().to_string();
let (_, reserve_file_path) =
file_stem.split_at(file_stem.len() - reserve_file_name_length);
format_file_name = format!(

Check warning on line 54 in crates/mako/src/generate/generate_chunks.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/generate/generate_chunks.rs#L48-L54

Added lines #L48 - L54 were not covered by tests
"{}.{}.{}",
reserve_file_path,
&hasher.finish().to_string()[0..8],
file_extension.to_str().unwrap()

Check warning on line 58 in crates/mako/src/generate/generate_chunks.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/generate/generate_chunks.rs#L57-L58

Added lines #L57 - L58 were not covered by tests
);
}

Check warning on line 60 in crates/mako/src/generate/generate_chunks.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/generate/generate_chunks.rs#L60

Added line #L60 was not covered by tests

if let Some(hash) = &self.hash {
hash_file_name(&self.file_name, hash)
hash_file_name(&format_file_name, hash)

Check warning on line 63 in crates/mako/src/generate/generate_chunks.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/generate/generate_chunks.rs#L63

Added line #L63 was not covered by tests
} else {
if self.file_name.len() > reserve_file_name_length {
let mut hasher: XxHash64 = Default::default();
hasher.write_str(self.file_name.as_str());
let file_extension = file_path.extension().unwrap();
let file_stem = file_path.file_stem().unwrap().to_string_lossy().to_string();
let (_, reserve_file_path) =
file_stem.split_at(file_stem.len() - reserve_file_name_length);
return format!(
"{}.{}.{}",
reserve_file_path,
&hasher.finish().to_string()[0..8],
file_extension.to_str().unwrap()
);
}
self.file_name.clone()
format_file_name
}
}

Expand Down

0 comments on commit 6959eac

Please sign in to comment.