The require replacement at the top of basalt.lua has a bug in its fallback path. Here's the line as it currently ships (minified bundle, lib/basalt.lua / basalt.lua):
require = function(path) if(project[path..".lua"])then if(loadedProject[path]==nil)then loadedProject[path] = project[path..".lua"]() end return loadedProject[path] end baseRequire(path) end
Reformatted:
local baseRequire = require
require = function(path)
if project[path..".lua"] then
if loadedProject[path] == nil then
loadedProject[path] = project[path..".lua"]()
end
return loadedProject[path]
end
baseRequire(path) -- missing return
end
If path is one of basalt's bundled modules, everything's fine — the if branch returns properly. But if path is an external module (anything loaded from package.path, i.e. any user code that isn't part of the basalt bundle), the fallback calls baseRequire(path) and discards the result. The module is loaded and cached in package.loaded as usual, but the caller gets nil.
I ran into this trying to structure a project with a few plain Lua modules loaded via require("app"), require("src.comms"), etc., after basalt had been loaded. Every one of them came back nil, which was pretty confusing until I looked at package.loaded and saw they were all there. Basalt itself never hits this branch, since it only ever requires its own bundled files, so it doesn't show up in normal use.
Fix is one word — add return:
I worked around it on my end by wrapping the overridden require right after loading basalt:
local bas = require("lib.basalt")
local basalt_require = require
require = function(path)
local result = basalt_require(path)
if result ~= nil then return result end
return package.loaded[path]
end
That works, but it'd be nicer if the bundle itself did the right thing. Happy to send a PR against the source if the minified bundle isn't the canonical place to patch.
The require replacement at the top of basalt.lua has a bug in its fallback path. Here's the line as it currently ships (minified bundle, lib/basalt.lua / basalt.lua):
Reformatted:
If path is one of basalt's bundled modules, everything's fine — the if branch returns properly. But if path is an external module (anything loaded from package.path, i.e. any user code that isn't part of the basalt bundle), the fallback calls baseRequire(path) and discards the result. The module is loaded and cached in package.loaded as usual, but the caller gets nil.
I ran into this trying to structure a project with a few plain Lua modules loaded via require("app"), require("src.comms"), etc., after basalt had been loaded. Every one of them came back nil, which was pretty confusing until I looked at package.loaded and saw they were all there. Basalt itself never hits this branch, since it only ever requires its own bundled files, so it doesn't show up in normal use.
Fix is one word — add return:
I worked around it on my end by wrapping the overridden require right after loading basalt:
That works, but it'd be nicer if the bundle itself did the right thing. Happy to send a PR against the source if the minified bundle isn't the canonical place to patch.