mirror of
https://github.com/CompeyDev/bun-lune-loader.git
synced 2024-12-12 12:50:39 +00:00
fmt: luau side loader
This commit is contained in:
parent
783a4b4b22
commit
680724233d
1 changed files with 22 additions and 22 deletions
|
@ -2,40 +2,40 @@ local process = require("@lune/process")
|
||||||
local jsonEncode = require("@lune/net").jsonEncode
|
local jsonEncode = require("@lune/net").jsonEncode
|
||||||
|
|
||||||
local possibleErrors = {
|
local possibleErrors = {
|
||||||
FILE_NOT_FOUND = "No file exist at the path",
|
FILE_NOT_FOUND = "No file exist at the path",
|
||||||
NOT_A_MODULE = "Module must return at least one value"
|
NOT_A_MODULE = "Module must return at least one value",
|
||||||
}
|
}
|
||||||
|
|
||||||
local _, resolvedMod = xpcall(function()
|
local _, resolvedMod = xpcall(function()
|
||||||
-- [1] - Path to import
|
-- [1] - Path to import
|
||||||
-- [2] - Whether module import or not
|
-- [2] - Whether module import or not
|
||||||
|
|
||||||
local mod = require(process.args[1])
|
local mod = require(process.args[1])
|
||||||
|
|
||||||
if process.args[2] == "MODULE" and mod == nil then
|
if process.args[2] == "MODULE" and mod == nil then
|
||||||
error(possibleErrors.NOT_A_MODULE)
|
error(possibleErrors.NOT_A_MODULE)
|
||||||
end
|
end
|
||||||
|
|
||||||
return mod
|
return mod
|
||||||
end, function(err)
|
end, function(err)
|
||||||
-- We only need the msg, not trace
|
-- We only need the msg, not trace
|
||||||
local errMsg = tostring(err):split("stack traceback:")[1]
|
local errMsg = tostring(err):split("stack traceback:")[1]
|
||||||
|
|
||||||
for id, msg in possibleErrors do
|
for id, msg in possibleErrors do
|
||||||
if errMsg:match(msg) then
|
if errMsg:match(msg) then
|
||||||
print(`[bun-loader-lune::ImportError::{id}] ` .. errMsg)
|
print(`[bun-loader-lune::ImportError::{id}] ` .. errMsg)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print("-- [ImportError] --")
|
print("-- [ImportError] --")
|
||||||
print(tostring(err))
|
print(tostring(err))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if process.args[2] == "MODULE" and typeof(resolvedMod) == "table" then
|
if process.args[2] == "MODULE" and typeof(resolvedMod) == "table" then
|
||||||
local modReprJson = jsonEncode(resolvedMod)
|
local modReprJson = jsonEncode(resolvedMod)
|
||||||
|
|
||||||
print("--start @generated JS compatible object--")
|
print("--start @generated JS compatible object--")
|
||||||
print(modReprJson)
|
print(modReprJson)
|
||||||
print("--end @generated JS compatible object--")
|
print("--end @generated JS compatible object--")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue