mirror of
https://github.com/CompeyDev/bun-lune-loader.git
synced 2024-12-12 04:40: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 possibleErrors = {
|
||||
FILE_NOT_FOUND = "No file exist at the path",
|
||||
NOT_A_MODULE = "Module must return at least one value"
|
||||
FILE_NOT_FOUND = "No file exist at the path",
|
||||
NOT_A_MODULE = "Module must return at least one value",
|
||||
}
|
||||
|
||||
local _, resolvedMod = xpcall(function()
|
||||
-- [1] - Path to import
|
||||
-- [2] - Whether module import or not
|
||||
-- [2] - Whether module import or not
|
||||
|
||||
local mod = require(process.args[1])
|
||||
|
||||
if process.args[2] == "MODULE" and mod == nil then
|
||||
error(possibleErrors.NOT_A_MODULE)
|
||||
end
|
||||
if process.args[2] == "MODULE" and mod == nil then
|
||||
error(possibleErrors.NOT_A_MODULE)
|
||||
end
|
||||
|
||||
return mod
|
||||
return mod
|
||||
end, function(err)
|
||||
-- We only need the msg, not trace
|
||||
local errMsg = tostring(err):split("stack traceback:")[1]
|
||||
-- We only need the msg, not trace
|
||||
local errMsg = tostring(err):split("stack traceback:")[1]
|
||||
|
||||
for id, msg in possibleErrors do
|
||||
if errMsg:match(msg) then
|
||||
print(`[bun-loader-lune::ImportError::{id}] ` .. errMsg)
|
||||
return
|
||||
end
|
||||
end
|
||||
for id, msg in possibleErrors do
|
||||
if errMsg:match(msg) then
|
||||
print(`[bun-loader-lune::ImportError::{id}] ` .. errMsg)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
print("-- [ImportError] --")
|
||||
print(tostring(err))
|
||||
print("-- [ImportError] --")
|
||||
print(tostring(err))
|
||||
end)
|
||||
|
||||
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(modReprJson)
|
||||
print("--end @generated JS compatible object--")
|
||||
end
|
||||
print("--start @generated JS compatible object--")
|
||||
print(modReprJson)
|
||||
print("--end @generated JS compatible object--")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue