Skip to content

Commit 1647b2a

Browse files
committed
♻️ - Always use package_dir attribute instead of manually constructing path
1 parent c36e207 commit 1647b2a

File tree

4 files changed

+20
-49
lines changed

4 files changed

+20
-49
lines changed

src/build/clean.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn remove_compile_assets(
8686
}
8787
}
8888

89-
pub fn clean_mjs_files(build_state: &BuildState, project_root: &str) {
89+
pub fn clean_mjs_files(build_state: &BuildState) {
9090
// get all rescript file locations
9191
let rescript_file_locations = build_state
9292
.modules
@@ -99,14 +99,10 @@ pub fn clean_mjs_files(build_state: &BuildState, project_root: &str) {
9999
.get(&build_state.root_config_name)
100100
.expect("Could not find root package");
101101
Some((
102-
std::path::PathBuf::from(helpers::get_package_path(
103-
&project_root,
104-
&module.package_name,
105-
package.is_root,
106-
))
107-
.join(source_file.implementation.path.to_string())
108-
.to_string_lossy()
109-
.to_string(),
102+
std::path::PathBuf::from(package.package_dir.to_string())
103+
.join(source_file.implementation.path.to_string())
104+
.to_string_lossy()
105+
.to_string(),
110106
root_package
111107
.bsconfig
112108
.suffix
@@ -444,7 +440,7 @@ pub fn clean(path: &str) {
444440
std::io::stdout().flush().unwrap();
445441
let mut build_state = BuildState::new(project_root.to_owned(), root_config_name, packages);
446442
packages::parse_packages(&mut build_state);
447-
clean_mjs_files(&build_state, &project_root);
443+
clean_mjs_files(&build_state);
448444
let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed();
449445
println!(
450446
"{}\r{} {}Cleaned mjs files in {:.2}s",

src/build/compile.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,7 @@ fn compile_file(
609609
// editor tools expects the source file in lib/bs for finding the current package
610610
// and in lib/ocaml when referencing modules in other packages
611611
let _ = std::fs::copy(
612-
std::path::Path::new(&helpers::get_package_path(
613-
root_path,
614-
&package.name,
615-
package.is_root,
616-
))
617-
.join(path),
612+
std::path::Path::new(&package.package_dir).join(path),
618613
std::path::Path::new(&helpers::get_bs_build_path(
619614
root_path,
620615
&package.name,
@@ -625,12 +620,7 @@ fn compile_file(
625620
.expect("copying source file failed");
626621

627622
let _ = std::fs::copy(
628-
std::path::Path::new(&helpers::get_package_path(
629-
root_path,
630-
&package.name,
631-
package.is_root,
632-
))
633-
.join(path),
623+
std::path::Path::new(&package.package_dir).join(path),
634624
std::path::Path::new(&helpers::get_build_path(
635625
root_path,
636626
&package.name,

src/build/read_compile_state.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
2020
let package = build_state.packages.get(&module.package_name).unwrap();
2121

2222
Some(
23-
PathBuf::from(helpers::get_package_path(
24-
&build_state.project_root,
25-
&module.package_name,
26-
package.is_root,
27-
))
28-
.canonicalize()
29-
.expect("Could not canonicalize")
30-
.join(source_file.implementation.path.to_owned())
31-
.to_string_lossy()
32-
.to_string(),
23+
PathBuf::from(&package.package_dir)
24+
.canonicalize()
25+
.expect("Could not canonicalize")
26+
.join(source_file.implementation.path.to_owned())
27+
.to_string_lossy()
28+
.to_string(),
3329
)
3430
}
3531
_ => None,
@@ -43,16 +39,12 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
4339
.filter_map(|module| {
4440
let package = build_state.packages.get(&module.package_name).unwrap();
4541
module.get_interface().as_ref().map(|interface| {
46-
PathBuf::from(helpers::get_package_path(
47-
&build_state.project_root,
48-
&module.package_name,
49-
package.is_root,
50-
))
51-
.canonicalize()
52-
.expect("Could not canonicalize")
53-
.join(interface.path.to_owned())
54-
.to_string_lossy()
55-
.to_string()
42+
PathBuf::from(&package.package_dir)
43+
.canonicalize()
44+
.expect("Could not canonicalize")
45+
.join(interface.path.to_owned())
46+
.to_string_lossy()
47+
.to_string()
5648
})
5749
})
5850
.collect::<AHashSet<String>>(),

src/helpers.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ pub fn get_relative_package_path(package_name: &str, is_root: bool) -> String {
5050
}
5151
}
5252

53-
pub fn get_package_path(root: &str, package_name: &str, is_root: bool) -> String {
54-
match is_root {
55-
true => root.to_string(),
56-
false => format!("{}/node_modules/{}", root, package_name),
57-
}
58-
}
59-
6053
pub fn get_build_path(root: &str, package_name: &str, is_root: bool) -> String {
6154
match is_root {
6255
true => format!("{}/lib/ocaml", root),

0 commit comments

Comments
 (0)