Add back support for init files in require

This commit is contained in:
Filip Tibell 2023-08-20 15:01:20 -05:00
parent 3cd7a8945c
commit 5905b2d6cf

View file

@ -28,7 +28,7 @@ where
return Ok(res); return Ok(res);
} }
// 2. Try to require the path with an added "lua" extension // 3. Try to require the path with an added "lua" extension
let (lua_abs_path, lua_rel_path) = ( let (lua_abs_path, lua_rel_path) = (
append_extension(&abs_path, "lua"), append_extension(&abs_path, "lua"),
append_extension(&rel_path, "lua"), append_extension(&rel_path, "lua"),
@ -37,6 +37,29 @@ where
return Ok(res); return Ok(res);
} }
// We didn't find any direct file paths, look
// for directories with "init" files in them...
let abs_init = abs_path.join("init");
let rel_init = rel_path.join("init");
// 4. Try to require the init path with an added "luau" extension
let (luau_abs_init, luau_rel_init) = (
append_extension(&abs_init, "luau"),
append_extension(&rel_init, "luau"),
);
if let Ok(res) = require_inner(ctx, &luau_abs_init, &luau_rel_init).await {
return Ok(res);
}
// 5. Try to require the init path with an added "lua" extension
let (lua_abs_init, lua_rel_init) = (
append_extension(&abs_init, "lua"),
append_extension(&rel_init, "lua"),
);
if let Ok(res) = require_inner(ctx, &lua_abs_init, &lua_rel_init).await {
return Ok(res);
}
// Nothing left to try, throw an error // Nothing left to try, throw an error
Err(LuaError::runtime(format!( Err(LuaError::runtime(format!(
"No file exist at the path '{}'", "No file exist at the path '{}'",