Skip to content

Commit

Permalink
improved 'require'
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown-gd committed May 21, 2023
1 parent a71af0c commit efd59aa
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lua/gpm/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,31 @@ Initialize = promise.Async( function( metadata, func, files )

-- require
environment.SetValue( env, "require", function( name, alternative )
if util.IsBinaryModuleInstalled( name ) then return require( name ) end
gpm.ArgAssert( name, 1, "string" )

local hasAlternative = type( alternative ) == "string"
if util.IsBinaryModuleInstalled( name ) then
return require( name )
elseif hasAlternative and util.IsBinaryModuleInstalled( alternative ) then
return require( alternative )
end

if string.IsURL( name ) then
return gpm.Import( name, false, pkg )
end

local importPath = "includes/modules/" .. name .. ".lua"
if fs.IsFile( importPath, luaRealm ) then
return gpm.Import( importPath, false, pkg )
elseif hasAlternative then
if string.IsURL( alternative ) then
return gpm.Import( alternative, false, pkg )
end

importPath = "includes/modules/" .. alternative .. ".lua"
if fs.IsFile( importPath, luaRealm ) then
return gpm.Import( importPath, false, pkg )
end
end

return gpm.Import( gpm.LocatePackage( name, alternative ), false, pkg )
Expand Down

0 comments on commit efd59aa

Please sign in to comment.