fmt: luau side loader

This commit is contained in:
Erica Marigold 2023-09-15 17:31:16 +05:30 committed by GitHub
parent 783a4b4b22
commit 680724233d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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--")
print("--start @generated JS compatible object--")
print(modReprJson)
print("--end @generated JS compatible object--")
end