Skip to content

Adds luau.requires to @std#889

Open
tyulpan wants to merge 2 commits intoluau-lang:primaryfrom
tyulpan:add-requires-to-std
Open

Adds luau.requires to @std#889
tyulpan wants to merge 2 commits intoluau-lang:primaryfrom
tyulpan:add-requires-to-std

Conversation

@tyulpan
Copy link
Copy Markdown
Contributor

@tyulpan tyulpan commented Mar 20, 2026

Adds luau.requires(filePath: path.pathlike): { RequireNode } to @std, which parses Luau source code and returns all of its required modules in the following format:

{
  resolvedPath: string?, -- the path to the resolved require
  requireContent: string?,  -- an argument passed to the require as a string literal
  requireAst: luteLuau.AstExprCall, -- the ast expression passed to require
}

Resolves #776.
Related to PR #878.

Now we can run this code for hash.luau:

local pp = require("@batteries/pp")
local luau = require("@std/luau")

local requires = luau.requires("./examples/hash.luau")

print(pp(requires))

and get:

{
  {
    requireContent = "@lute/crypto",
    resolvedPath = "/path/to/lute/definitions/crypto.luau",
    requireAst = {...}
  },
  {
    requireContent = "@batteries/base64",
    resolvedPath = "/path/to/lute/batteries/base64.luau",
    requireAst = {...}
  },
}

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.

There should be a standard library method for 'get all the required modules for a given module'

1 participant