lune-org/lune

Support custom aliases in require paths

Closed this issue · 3 comments

Lune currently has the @ prefix reserved for aliases, along with a lune alias, and it is currently being used for built-in libraries with require statements such as:

  • require("@lune/fs")
  • require("@lune/net")
  • require("@lune/...")

These aliased requires are special, and are not relative to the current file. We can extend this to allow for user-defined aliases.

Users would have to specify these aliases in a configuration file, something which Lune does not currently have. We have a couple of options here:

  • We could wait for and use .luaurc when require-by-string support and native aliases land (RFC)
  • Maybe it's time for Lune to get its own configuration file. This would let us provide user configuration in several areas, but require aliases specifically could look something like this:
[require.aliases]
# The current working directory
# Files are require-able using `require("@cwd/...")`
cwd = "."
# A directory called 'modules' in the current working directory
# Files are require-able using `require("@modules/...")`
modules = "./modules"

This is now (mostly) supported in our require implementation, with a few details missing as of #88 , we just need to settle on what we want our config to look like

This looks very nice.

Implemented in b07202a using .luaurc files which is a shared configuration file with a formal spec by the Luau team, in the future we may still have our own config file for other things, but this is what's used for aliases