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 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