convert_require support for replacing sources / aliases with their relative string pathways
Hello! I've been using darklua for a few weeks now and I'm really liking it! While using it I came across a relatively new painpoint when using it to deploy code across lune and roblox.
Use Case
I have a few projects that have modules which deploy to both a lune env and a roblox env. I don't tend to use the same aliases in the lune environment.
Example Output
source:
local Enums = require("@shared/Enums")
typical roblox conversion:
local Enums = require(script.Parent.Parent.Parent:FindFirstChild("Enums"))
requested feature that would run in lune without much fuss:
local Enums = require("./../../../Enums")
Conclusion
This isn't a blocker for me anymore - I wrote up a slow bash script that I run afterwards to convert a property-path to the requested format, however it has flaws, and I think that as lune grows in popularity there are only going to be more people who use darklua to deploy across multiple env with separate alias configs.
Thank you for your time!
Also, not sure if this would be worth a new issue - but being able to convert local Enums = require(script.Parent.Parent.Parent:FindFirstChild("Enums")) to local Enums = require("./../../../Enums") would be super helpful as well. There've been more than a few instances where I found a wally package that was perfectly sound to run in lune, but used the native Roblox require structure.
Can second this.
Currently working with darklua to manage a plugin, in which case whenever it decides to transpile to a hierarchy descending from the DataModel, you would need to manually force a relative path approach.
@nightcycle I'm wondering if in your case - I know in mine it'd work - if there was just a rule to force all paths to be relative.
Alternative approach could be to add a padding around the rojo_sourcemap which determines whether or not we want to use relative paths or paths from the DataModel.
The issue as whole arises here: https://github.com/seaofvoices/darklua/blob/60c886e92051601f3e4b71a1cf641db29110d162/src/rules/convert_require/rojo_sourcemap.rs#L157
https://github.com/seaofvoices/darklua/blob/60c886e92051601f3e4b71a1cf641db29110d162/src/rules/convert_require/rojo_sourcemap.rs#L159
I created a pull request which can be found here.
It implements a new "force_relative_path" option for your require rules.