https://github.com/hazzard993/star-node
Used to resolve relative Lua paths as well as paths to node_modules.
https://github.com/hazzard993/star-node
lua luajit module-resolver nodejs
Last synced: 7 months ago
JSON representation
Used to resolve relative Lua paths as well as paths to node_modules.
- Host: GitHub
- URL: https://github.com/hazzard993/star-node
- Owner: hazzard993
- Created: 2020-09-24T10:10:24.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-24T12:11:11.000Z (over 5 years ago)
- Last Synced: 2025-02-03T08:13:56.435Z (about 1 year ago)
- Topics: lua, luajit, module-resolver, nodejs
- Language: TypeScript
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lua Node Resolver
Allows Lua to import `relative paths` as well as modules from `node_modules`.
**How to install**
```sh
yarn add lua-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`.
```lua
-- node_modules/
-- main.lua
require("node_modules.lua-star-node.run")
```
or, if your Lua working directory is inside a folder, use the code below adjusting the dots as needed.
```lua
-- node_modules/
-- folder/main.lua
package.path = package.path .. ";../node_modules/?.lua"
require("lua-star-node.run")
```
**How the resolution works**
```lua
-- File Path: C:/project/tools/main.lua
require("./foo") --> C:/project/tools/foo.lua
require("../foo") --> C:/project/foo.lua
require("foo") --> C:/project/node_modules/module/internal/dir/foo.lua (this is discovered in a rockspec file)
```
**Examples**
```sh
yarn init -y
yarn add rxi/lurker rxi/lume lua-star-node
echo "require('node_modules.lua-star-node.run')" > main.lua
echo "print(require('lurker'))" >> main.lua
love --console .
```