Skip to content

Commit

Permalink
♻️ - Always use package_dir attribute instead of manually constructin…
Browse files Browse the repository at this point in the history
…g path
  • Loading branch information
jfrolich committed Jan 12, 2024
1 parent dfa27f5 commit 45e7fef
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 49 deletions.
16 changes: 6 additions & 10 deletions src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn remove_compile_assets(
}
}

pub fn clean_mjs_files(build_state: &BuildState, project_root: &str) {
pub fn clean_mjs_files(build_state: &BuildState) {
// get all rescript file locations
let rescript_file_locations = build_state
.modules
Expand All @@ -99,14 +99,10 @@ pub fn clean_mjs_files(build_state: &BuildState, project_root: &str) {
.get(&build_state.root_config_name)
.expect("Could not find root package");
Some((
std::path::PathBuf::from(helpers::get_package_path(
&project_root,
&module.package_name,
package.is_root,
))
.join(source_file.implementation.path.to_string())
.to_string_lossy()
.to_string(),
std::path::PathBuf::from(package.package_dir.to_string())
.join(source_file.implementation.path.to_string())
.to_string_lossy()
.to_string(),
root_package
.bsconfig
.suffix
Expand Down Expand Up @@ -444,7 +440,7 @@ pub fn clean(path: &str) {
std::io::stdout().flush().unwrap();
let mut build_state = BuildState::new(project_root.to_owned(), root_config_name, packages);
packages::parse_packages(&mut build_state);
clean_mjs_files(&build_state, &project_root);
clean_mjs_files(&build_state);
let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed();
println!(
"{}\r{} {}Cleaned mjs files in {:.2}s",
Expand Down
14 changes: 2 additions & 12 deletions src/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,7 @@ fn compile_file(
// editor tools expects the source file in lib/bs for finding the current package
// and in lib/ocaml when referencing modules in other packages
let _ = std::fs::copy(
std::path::Path::new(&helpers::get_package_path(
root_path,
&package.name,
package.is_root,
))
.join(path),
std::path::Path::new(&package.package_dir).join(path),
std::path::Path::new(&helpers::get_bs_build_path(
root_path,
&package.name,
Expand All @@ -625,12 +620,7 @@ fn compile_file(
.expect("copying source file failed");

let _ = std::fs::copy(
std::path::Path::new(&helpers::get_package_path(
root_path,
&package.name,
package.is_root,
))
.join(path),
std::path::Path::new(&package.package_dir).join(path),
std::path::Path::new(&helpers::get_build_path(
root_path,
&package.name,
Expand Down
32 changes: 12 additions & 20 deletions src/build/read_compile_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
let package = build_state.packages.get(&module.package_name).unwrap();

Some(
PathBuf::from(helpers::get_package_path(
&build_state.project_root,
&module.package_name,
package.is_root,
))
.canonicalize()
.expect("Could not canonicalize")
.join(source_file.implementation.path.to_owned())
.to_string_lossy()
.to_string(),
PathBuf::from(&package.package_dir)
.canonicalize()
.expect("Could not canonicalize")
.join(source_file.implementation.path.to_owned())
.to_string_lossy()
.to_string(),
)
}
_ => None,
Expand All @@ -43,16 +39,12 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
.filter_map(|module| {
let package = build_state.packages.get(&module.package_name).unwrap();
module.get_interface().as_ref().map(|interface| {
PathBuf::from(helpers::get_package_path(
&build_state.project_root,
&module.package_name,
package.is_root,
))
.canonicalize()
.expect("Could not canonicalize")
.join(interface.path.to_owned())
.to_string_lossy()
.to_string()
PathBuf::from(&package.package_dir)
.canonicalize()
.expect("Could not canonicalize")
.join(interface.path.to_owned())
.to_string_lossy()
.to_string()
})
})
.collect::<AHashSet<String>>(),
Expand Down
7 changes: 0 additions & 7 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ pub fn get_relative_package_path(package_name: &str, is_root: bool) -> String {
}
}

pub fn get_package_path(root: &str, package_name: &str, is_root: bool) -> String {
match is_root {
true => root.to_string(),
false => format!("{}/node_modules/{}", root, package_name),
}
}

pub fn get_build_path(root: &str, package_name: &str, is_root: bool) -> String {
match is_root {
true => format!("{}/lib/ocaml", root),
Expand Down

0 comments on commit 45e7fef

Please sign in to comment.