(Luau Require) Resolve Lua file path relative to the current directory

and unrelated to Rust source file location.
When a Lua file is required inside a Rust file (in a chunk), we should resolve the Lua file relative to the current directory,
instead of relative to the Rust chunk path.
The Rust file location is an internal information that does not exist when the compiled binary runs.
Fixes #605
This commit is contained in:
Alex Orlenko
2025-06-23 15:49:37 +01:00
parent 3f0c69b70b
commit 25955893e0
2 changed files with 30 additions and 18 deletions
+4 -2
View File
@@ -200,9 +200,11 @@ impl Require for TextRequirer {
let chunk_path = Self::normalize_path(chunk_name.as_ref());
if chunk_path.extension() == Some("rs".as_ref()) {
// Special case for Rust source files, reset to the current directory
let chunk_filename = chunk_path.file_name().unwrap();
let cwd = env::current_dir().map_err(|_| NavigateError::NotFound)?;
self.abs_path = Self::normalize_path(&cwd.join(&chunk_path));
self.rel_path = chunk_path;
self.abs_path = Self::normalize_path(&cwd.join(chunk_filename));
self.rel_path = ([Component::CurDir, Component::Normal(chunk_filename)].into_iter()).collect();
self.module_path = PathBuf::new();
return Ok(());