Skip to content

Conversation

jeparlefrancais
Copy link
Contributor

@jeparlefrancais jeparlefrancais commented Aug 6, 2025

Closes #268 Closes #214

This PR adds a completely new require mode called luau 🚀 This means that you will be able to use the latest require system update that uses the @self special alias.

This has been a fair amount of work to fully support (and test) the new luau require syntax, while still preserving support for the regular paths. If you appreciate the work, please consider giving a tip to my ko-fi or through github sponsors ❤️

Why a new require mode?

For those who prefer regular file paths for their simplicity (they do not need an extra mental model as they map 1:1 to the concrete files) and to avoid breaking existing code, darklua will continue to support the existing file paths in the existing path require mode.

There is a hidden feature in luau-lsp that lets you use regular path requires. If you use VSCode, you can put an entry in your settings file at .vscode/settings.json:

  "luau-lsp.require.useOriginalRequireByStringSemantics": true

darklua now has 3 require mode:

name description usable as source usable as target support bundling
path for using relative file paths and configurable aliases
luau for using relative file paths and configurable aliases
roblox for Roblox specific requires using Instances

Bonus feature: Inline aliases

This PR also closes #214 because the path or luau require mode can now be used as target modes with the convert_require rule. This means that you can use these require modes as source and target and tweak the aliases/sources. Let's say the target mode does not have an alias named @pkg that the source require mode uses, then darklua will produce a new path that does not use the @pkg 🤯. Example of a config that does that:

{
  rules: [
    {
      rule: 'convert_require',
      current: {
        name: 'path',
        sources: { '@pkg': './node_modules/.luau-aliases' }
      },
      target: 'path'
    }
  ]
}

Checklist

  • add entry to the changelog
  • update documentation

Support the latest breaking change to the module require system in Luau.
Luau no longers support simple file paths, instead it introduces a new
way to require modules using something that could be called 'module
paths'.

These changes add a new require mode called 'luau' to use this new luau
require behavior.

For those who prefer regular file paths for their simplicity (they do
not need an extra mental model as they map 1:1 to the concrete files)
and to avoid breaking existing code, darklua will continue to support
the existing file paths in the existing `path` require mode.
Copy link

github-actions bot commented Aug 8, 2025

Coverage after merging luau-require-mode into main will be

88.13%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
src/nodes/expressions
   interpolated_string.rs81.30%100%86.05%80.21%18–23, 240–242, 25–30, 32, 34, 346–349, 35, 350–351, 36, 39–40, 82–84, 93–95
   mod.rs96.84%100%97.30%96.73%166–168, 292, 346
   string.rs90.06%100%90.63%89.93%147–149, 16–21, 23–24, 241–243, 25–28, 30, 32–34, 37–38
src/nodes/types
   string_type.rs84.81%100%83.33%85.25%61–63, 67–69, 85–87
src/process/evaluator
   lua_value.rs90.34%100%88.89%90.68%122–124, 150–152, 162–164, 53, 67
src/rules
   append_text_comment.rs53.22%100%70.37%52.12%118–125, 141–154, 160–171, 177–186, 192–201, 207–223, 229–240, 246–253, 259–267, 282–300, 321–328, 331–333, 335–337, 347–348, 350–351, 360–362, 366–368, 37, 370–371, 379, 38, 380, 385–389, 39, 390–393, 40, 406–407, 41–43, 450–455, 482–498, 505–507, 54, 56–59
   convert_square_root_call.rs92.78%100%92.31%92.86%30, 50–51, 60–62
   remove_comments.rs94.02%100%90.67%95.13%293, 333, 414, 491–493
   rule_property.rs90.91%100%96.15%89.84%100, 110–111, 116, 160–165, 167–170, 172–175, 179–180, 41, 49, 60, 76, 94
src/rules/bundle
   require_mode.rs91.67%100%66.67%95.24%
src/rules/bundle/path_require_mode
   mod.rs85.16%100%94.12%84.52%116–118, 122–124, 126, 176, 202–204, 219–221, 231–233, 255, 295, 297–298, 328–329, 335–338, 340–341, 351–352, 361–363, 97–99
src/rules/convert_require
   mod.rs91.98%100%90.48%92.20%115–117, 140, 150–151, 47, 70–71
   roblox_require_mode.rs53.33%100%75%52.11%106–109, 111, 114–116, 118, 124–125, 158–165, 168–176, 180, 185–189, 192, 196–201, 204–211, 46–47, 61–68, 78–80, 92, 94–96
src/rules/require
   luau_path_locator.rs59.26%100%33.33%61.33%38–40, 52–53, 55–57, 59, 68–70, 72, 75, 89–93, 95–97
   luau_require_mode.rs81.31%100%91.18%80%109–111, 115–118, 122–123, 126–131, 133–140, 142, 144, 149–152, 166, 168, 189–190, 205, 210, 215, 239–241, 43–46, 49–52, 56–57, 97
   path_locator.rs85.53%100%83.33%85.71%35–37, 52–54, 56, 70
   path_require_mode.rs90.27%100%95.83%89.44%116, 134–136, 140, 144–147, 162, 164, 184–185, 191, 73–74
   path_utils.rs79.78%100%88.89%78.75%17–19, 22–24, 35–38, 55, 86–90

@jeparlefrancais jeparlefrancais merged commit 4126c9a into main Aug 8, 2025
6 checks passed
@jeparlefrancais jeparlefrancais deleted the luau-require-mode branch August 8, 2025 19:37
This was referenced Aug 8, 2025
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.

@self support for require-by-string convert_require support for replacing sources / aliases with their relative string pathways
1 participant