Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/rules/convert_require/roblox_require_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct RobloxRequireMode {
indexing_style: RobloxIndexStyle,
#[serde(skip)]
cached_sourcemap: Option<RojoSourcemap>,
#[serde(default)]
force_relative_path: bool,
}

impl RobloxRequireMode {
Expand Down Expand Up @@ -91,7 +93,7 @@ impl RobloxRequireMode {
);

if let Some(instance_path) =
sourcemap.get_instance_path(&source_path, &require_relative_to_sourcemap)
sourcemap.get_instance_path(&source_path, &require_relative_to_sourcemap, self.force_relative_path)
{
Ok(Some(Arguments::default().with_argument(
instance_path.convert(&self.indexing_style),
Expand Down
13 changes: 7 additions & 6 deletions src/rules/convert_require/rojo_sourcemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl RojoSourcemap {
&self,
from_file: impl AsRef<Path>,
target_file: impl AsRef<Path>,
force_relative_path: bool,
) -> Option<InstancePath> {
let from_file = from_file.as_ref();
let target_file = target_file.as_ref();
Expand Down Expand Up @@ -156,7 +157,7 @@ impl RojoSourcemap {

let relative_path_length = parents.len().saturating_add(descendants.len());

if !self.is_datamodel || relative_path_length <= target_ancestors.len() {
if !self.is_datamodel || force_relative_path || relative_path_length <= target_ancestors.len() {
log::trace!(" ⨽ use Roblox path from script instance");

let mut instance_path = InstancePath::from_script();
Expand Down Expand Up @@ -267,7 +268,7 @@ mod test {
);
pretty_assertions::assert_eq!(
sourcemap
.get_instance_path("src/init.lua", "src/value.lua")
.get_instance_path("src/init.lua", "src/value.lua", false)
.unwrap(),
script_path(&["value"])
);
Expand Down Expand Up @@ -296,7 +297,7 @@ mod test {
);
pretty_assertions::assert_eq!(
sourcemap
.get_instance_path("src/main.lua", "src/value.lua")
.get_instance_path("src/main.lua", "src/value.lua", false)
.unwrap(),
script_path(&["parent", "value"])
);
Expand Down Expand Up @@ -331,7 +332,7 @@ mod test {
);
pretty_assertions::assert_eq!(
sourcemap
.get_instance_path("src/main.lua", "src/Lib/format.lua")
.get_instance_path("src/main.lua", "src/Lib/format.lua", false)
.unwrap(),
script_path(&["parent", "Lib", "format"])
);
Expand All @@ -355,7 +356,7 @@ mod test {
);
pretty_assertions::assert_eq!(
sourcemap
.get_instance_path("src/main.lua", "src/init.lua")
.get_instance_path("src/main.lua", "src/init.lua", false)
.unwrap(),
script_path(&["parent"])
);
Expand Down Expand Up @@ -386,7 +387,7 @@ mod test {
);
pretty_assertions::assert_eq!(
sourcemap
.get_instance_path("src/Sub/test.lua", "src/Sub/init.lua")
.get_instance_path("src/Sub/test.lua", "src/Sub/init.lua", false)
.unwrap(),
script_path(&["parent"])
);
Expand Down