Lua Node Resolver
Allows Lua to import relative paths
as well as modules from node_modules
.
How to install
yarn add star-node # adds to node_modules/
Import lnr.run
in Lua code before using other require
calls.
You can use this if Lua's working directory is the same directory containing node_modules
.
-- node_modules/-- main.luarequire("node_modules.star-node.run")
or, if your Lua working directory is inside a folder, use the code below adjusting the dots as needed.
-- node_modules/-- folder/main.luapackage.path = package.path .. ";../node_modules/?.lua"require("star-node.run")
How the resolution works
-- File Path: C:/project/tools/main.lua require("./foo") --> C:/project/tools/foo.luarequire("../foo") --> C:/project/foo.luarequire("foo") --> C:/project/node_modules/module/internal/dir/foo.lua (this is discovered in a rockspec file)
Examples
yarn init -yyarn add rxi/lurker Olivine-Labs/luassert star-nodeecho "require('node_modules.star-node.run')" > main.luaecho "print(require('lurker'))" >> main.luaecho "print(require('luassert'))" >> main.lualove --console .