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

Adds an option to force relative paths. #215

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iamnoderbx
Copy link

Closes Issue #214

Allows for Darklua to be used for Projects in cross-environment scenarios, as well as plugin development
The only change is this implements a new boolean to the transform require rule: "force_relative_path", which simply forces a path to be relative to the script the transformation is occurring on. See the examples below.

Example

-- Let's assume your project structure has a hierarchy in which results in your relative path length is larger then your ancestor length. 

-- See https://github.com/seaofvoices/darklua/blob/60c886e92051601f3e4b71a1cf641db29110d162/src/rules/convert_require/rojo_sourcemap.rs#L159

-- In this case, your require path would be forced to an ancestor approach, which is problematic in situations where the ancestries may change; such as multiple environments, or for plugin development.

-- This case is especially problematic for plugin design, where the plugin must use relative pathing at all times, otherwise it will attempt to get your work environment rather then the local plugin install.

--------------------------------------

-- "force_relative_path": true
local variable = require(script.Parent.Parent.Parent.Parent:WaitForChild('childA'):WaitForChild('childB'):WaitForChild('childC'))

--------------------------------------

-- "force_relative_path": false
local variable = require(game:GetService('ServerStorage'):WaitForChild('parentA'):WaitForChild('chilA'):WaitForChild('childB'):WaitForChild('childC'))

--------------------------------------

Wasn't entirely sure the best approach for implementing a test for this, however all previous tests work - which at bare minimum allows for compatibility and ease for updating. If you have any advice let me know.

  • Add tests which otherwise would force getting a path from the DataModel.
  • Updating the changelog, there is no mention of whether or not this is done by the maintainer of if we should include it in our pull requests. I can include if this is passed.

@iamnoderbx
Copy link
Author

Please note this is my first contribution to a rust project, I wanted to keep it simple, but I do find that this will have quite a bit of positive impact.

A very simple change in which can allow a handful of more use-cases for darklua.

@nightcycle
Copy link

With the introduction of Roblox supported relative-only string paths, I feel this kind of feature is more helpful than ever. I hope it's merged soon.

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

Successfully merging this pull request may close these issues.

2 participants