From d8cd78e7e213c0422faef453db0b10dac5d979d5 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Fri, 26 Jul 2024 19:16:47 +0200 Subject: [PATCH] fix: correctly generate require paths --- src/linking/generator.rs | 24 ++++++++++++------------ src/linking/mod.rs | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/linking/generator.rs b/src/linking/generator.rs index 65db82e..78d751b 100644 --- a/src/linking/generator.rs +++ b/src/linking/generator.rs @@ -65,19 +65,19 @@ pub fn generate_lib_linking_module, S: AsRef>( } fn luau_style_path(path: &Path) -> String { - path.components() - .enumerate() - .filter_map(|(i, ct)| match ct { - Component::ParentDir => Some(if i == 0 { - ".".to_string() - } else { - "..".to_string() - }), + let path = path + .components() + .filter_map(|ct| match ct { + Component::CurDir => Some(".".to_string()), + Component::ParentDir => Some("..".to_string()), Component::Normal(part) => Some(format!("{}", part.to_string_lossy())), _ => None, }) .collect::>() - .join("/") + .join("/"); + + let require = format!("./{path}"); + format!("{require:?}") } pub fn get_lib_require_path( @@ -115,10 +115,10 @@ pub fn get_lib_require_path( .collect::>() .join(""); - return format!("script{path}"); + return format!("script.Parent{path}"); }; - format!("{:?}", luau_style_path(&path)) + luau_style_path(&path) } pub fn generate_bin_linking_module(path: &str) -> String { @@ -133,5 +133,5 @@ pub fn get_bin_require_path( let path = pathdiff::diff_paths(destination_dir, base_dir).unwrap(); let path = bin_file.to_path(path); - format!("{:?}", luau_style_path(&path)) + luau_style_path(&path) } diff --git a/src/linking/mod.rs b/src/linking/mod.rs index 7fdcf65..6b888d4 100644 --- a/src/linking/mod.rs +++ b/src/linking/mod.rs @@ -122,7 +122,7 @@ impl Project { let module = generator::generate_lib_linking_module( &generator::get_lib_require_path( &node.target.kind(), - &linker_file, + &base_folder, lib_file, &container_folder, node.node.pkg_ref.use_new_structure(), @@ -138,7 +138,7 @@ impl Project { let module = generator::generate_bin_linking_module( &generator::get_bin_require_path( - &linker_file, + &base_folder, bin_file, &container_folder, ), @@ -165,16 +165,16 @@ impl Project { continue; }; - let linker_file = create_and_canonicalize( + let linker_folder = create_and_canonicalize( container_folder .join(dependency_node.node.base_folder(node.target.kind(), false)), - )? - .join(format!("{dependency_alias}.luau")); + )?; + let linker_file = linker_folder.join(format!("{dependency_alias}.luau")); let module = generator::generate_lib_linking_module( &generator::get_lib_require_path( &dependency_node.target.kind(), - &linker_file, + &linker_folder, lib_file, &dependency_node.node.container_folder( &packages_container_folder,