Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert_require support for replacing sources / aliases with their relative string pathways #214

Open
nightcycle opened this issue Sep 11, 2024 · 3 comments

Comments

@nightcycle
Copy link

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!

@nightcycle
Copy link
Author

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.

@iamnoderbx
Copy link

iamnoderbx commented Sep 15, 2024

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:

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

if !self.is_datamodel || relative_path_length <= target_ancestors.len() {

@iamnoderbx
Copy link

I created a pull request which can be found here.

It implements a new "force_relative_path" option for your require rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants