Updated alias

This commit is contained in:
Menarul Alam 2023-12-11 09:12:03 -08:00
parent 99423a85c7
commit 0643bda137

View file

@ -34,7 +34,7 @@ Or even a sub-module:
local createElement = require("@Roact/createElement")
```
Aliases are overrides. Whenever the first component of a path exactly matches a pre-defined alias, it will be replaced before the path is resolved to a file. Alias names are also restricted to the charset `[A-Za-z0-9.\-_]`. We restrict the charset and make them case insensitive because we envision alias names to be primarily used as package names, which tend to be case insensitive and alphanumeric.
Aliases are overrides. Whenever the first component of a path exactly matches a pre-defined alias, it will be replaced before the path is resolved to a file. Alias names are also restricted to the charset `[A-Za-z0-9.\-_]`. We restrict the charset and make them case insensitive because we envision alias names to be primarily used as package names, which tend to be case insensitive and alphanumeric.They also must be preceded with an `@` symbol.
### Package management
@ -131,7 +131,7 @@ If `.luaurc` contained the following `paths` array:
Then, `module.luau` could simply require `dependency.luau` like this:
```lua
local dependency = require("dependency")
local dependency = require("@dependency")
-- Instead of: require("../dependencies/dependency")
```
@ -230,7 +230,7 @@ This way, each subproject directory can contain its own source code, dependencie
This allows us to refer to other subprojects like this, regardless of the exact location of the requiring file in `large-luau-project`:
```lua
local subproject1 = require("com.roblox.luau/subproject-1")
local subproject1 = require("@com.roblox.luau/subproject-1")
```
### Roblox Specifics
In the Roblox engine, a similar aliasing system could be implemented. Assuming a central package management system were available, a Roblox Script could contain local Roact = require("@Roact"), and everything would "just work".
@ -248,7 +248,7 @@ This alias system introduces a new layer to require that wasn't previously there
Rather than defining paths/alias maps in an external configuration file, we could alternatively define paths/aliases directly in the files that require them. For example, this could manifest itself through an extension of the `--!` comment syntax or introduce new syntax like `--@<ALIAS> = @<PATH>`.
```lua
--@"Roact" = @"C:/LuauModules/Roact-v1.4.2"
local Roact = require("Roact")
local Roact = require("@Roact")
-- Same as this:
local Roact = require("C:/LuauModules/Roact-v1.4.2")