@@ -745,15 +745,20 @@ function scm:updateConfig (name, value)
745745end
746746
747747--- @param name string
748- function scm :checkRequirements (name )
748+ --- @param localPath string
749+ function scm :checkRequirements (name , localPath )
749750 scm :log (" Checking requirements of " .. name .. " ..." )
750751 local file
751- if fs .exists (" ./" .. self .config [" libraryDirectory" ] .. name .. self .config [" librarySuffix" ] .. " /" .. name .. " .lua" ) then
752- file = fs .open (" ./" .. self .config [" libraryDirectory" ] .. name .. self .config [" librarySuffix" ] .. " /" .. name .. " .lua" , " r" )
752+ if localPath then
753+ file = fs .open (localPath )
754+ elseif fs .exists (" ./" ..
755+ self .config [" libraryDirectory" ] .. name .. self .config [" librarySuffix" ] .. " /" .. name .. " .lua" ) then
756+ file = fs .open (" ./" ..
757+ self .config [" libraryDirectory" ] .. name .. self .config [" librarySuffix" ] .. " /" .. name .. " .lua" , " r" )
753758 else
754759 file = fs .open (" ./" .. self .config [" libraryDirectory" ] .. name .. " .lua" , " r" )
755760 end
756-
761+ if not file then scm : log ( ' File ' .. name .. ' not found ' ) end
757762 -- Find requirements by searching for comment --@requires name
758763 local requires = {}
759764 while true do
@@ -799,13 +804,46 @@ function scm:checkRequirements(name)
799804 self :download (n , " library" )
800805 end
801806 else
802- scm :log (n .. " already exists." )
807+ scm :log (n .. " already exists." )
803808 end
804809
805810 self :checkRequirements (n )
806811 end
807812end
808813
814+ --- used when no script with the name was found online
815+ --- searches locally for the script
816+ --- @param name string
817+ --- @return any | nil
818+ local function fallbackRequire (name )
819+ scm :log (name .. " not found online, try to find locally" )
820+ --- if script does not exist
821+ local possiblePath = {
822+ name ,
823+ self .config [" libraryDirectory" ] .. name ,
824+ self .config [" libraryDirectory" ] .. name .. " /" .. name ,
825+ self .config [" libraryDirectory" ] .. name .. " /" .. " init.lua"
826+ }
827+ local script
828+ local success
829+ --- TryFunction for Require
830+ --- @param path string
831+ --- @return any
832+ local function tryRequire (path )
833+ return require (path )
834+ end
835+
836+ for _ , path in pairs (possiblePath ) do
837+ success , script = pcall (tryRequire , path )
838+ if success then
839+ checkRequirements (name , path )
840+ return script
841+ end
842+ end
843+ scm :log (" Could not load " .. name )
844+ return nil
845+ end
846+
809847--- @param name string
810848--- @return any
811849function scm :load (name )
@@ -835,9 +873,8 @@ function scm:load(name)
835873 scm :log (" Done" )
836874 return script
837875 end
838-
839- scm :log (" Done" )
840- return nil
876+
877+ return fallbackRequire (name )
841878end
842879
843880function scm :init ()
0 commit comments