DRY up code

This commit is contained in:
Anthony Bullard 2024-12-26 10:03:46 -06:00
parent 2a8765c1e9
commit 8a726d23ed
No known key found for this signature in database

View file

@ -1317,8 +1317,13 @@ fn handle_root_type<'a>(
use HeaderType::*;
let use_main = match header_type {
Package { .. } | App { .. } | Platform { .. } => true,
Module { .. } | Builtin { .. } | Hosted { .. } => false,
};
match header_type {
Module { .. } | Builtin { .. } | Hosted { .. } => {
Module { .. } | Builtin { .. } | Hosted { .. } | Package { .. } => {
let main_path = opt_main_path.or_else(|| find_main_roc_recursively(src_dir));
let cache_dir = roc_cache_dir.as_persistent_path();
@ -1340,31 +1345,13 @@ fn handle_root_type<'a>(
header_output.msg = Msg::Many(messages);
}
Ok((header_output, RootType::Module { main_path }))
}
Package { .. } => {
let main_path = opt_main_path.or_else(|| find_main_roc_recursively(src_dir));
let root_type = if use_main {
RootType::Main
} else {
RootType::Module { main_path }
};
let cache_dir = roc_cache_dir.as_persistent_path();
if let (Some(main_path), Some(cache_dir)) = (main_path.clone(), cache_dir) {
let mut messages = Vec::with_capacity(4);
messages.push(header_output.msg);
load_packages_from_main(
arena,
src_dir.clone(),
main_path,
&mut messages,
Arc::clone(&arc_modules),
Arc::clone(&ident_ids_by_module),
Arc::clone(&arc_shorthands),
cache_dir,
)?;
header_output.msg = Msg::Many(messages);
}
Ok((header_output, RootType::Main))
Ok((header_output, root_type))
}
App { .. } | Platform { .. } => Ok((header_output, RootType::Main)),
}