Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/turborepo-microfrontends/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub enum Error {
package root (no subdirectories or path traversal)."
)]
InvalidCustomConfigPath(String),
#[error("Invalid microfrontends configuration path: {0}")]
InvalidConfigPath(String),
}

impl Error {
Expand Down
18 changes: 9 additions & 9 deletions crates/turborepo-microfrontends/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! passed through but ignored by Turborepo

#![deny(clippy::all)]
#![allow(clippy::expect_used, clippy::unwrap_used)]
#![allow(clippy::unwrap_used)]
mod configv1;
mod error;
mod port;
Expand Down Expand Up @@ -145,10 +145,10 @@ impl TurborepoMfeConfig {
return Ok(None);
};
let mut config = Self::from_str_with_mfe_dep(&contents, path.as_str(), has_mfe_dependency)?;
config.filename = path
.file_name()
.expect("microfrontends config should not be root")
.to_owned();
let Some(file_name) = path.file_name() else {
return Err(Error::InvalidConfigPath(path.to_string()));
};
config.filename = file_name.to_owned();
config.set_path(package_dir);
Ok(Some(config))
}
Expand Down Expand Up @@ -351,10 +351,10 @@ impl Config {
return Ok(None);
};
let mut config = Config::from_str(&contents, path.as_str())?;
config.filename = path
.file_name()
.expect("microfrontends config should not be root")
.to_owned();
let Some(file_name) = path.file_name() else {
return Err(Error::InvalidConfigPath(path.to_string()));
};
config.filename = file_name.to_owned();
config.set_path(package_dir);
Ok(Some(config))
}
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-microfrontends/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const PORT_RANGE: u16 = MAX_PORT - MIN_PORT;
pub fn generate_port_from_name(name: &str) -> u16 {
let mut hash: i32 = 0;
for c in name.chars() {
let code = i32::try_from(u32::from(c)).expect("char::MAX is less than 2^31");
let code = u32::from(c) as i32;
hash = (hash << 5).overflowing_sub(hash).0.overflowing_add(code).0;
}
let hash = hash.abs_diff(0);
let port = hash % u32::from(PORT_RANGE);
MIN_PORT + u16::try_from(port).expect("u32 modulo a u16 number will be a valid u16")
MIN_PORT + port as u16
}

pub fn parse_port_from_host(host: &str) -> Option<u16> {
Expand Down
Loading