Skip to content

Commit

Permalink
Package reload patch
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown-gd committed Jun 23, 2023
1 parent d923fc1 commit 173e2c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lua/gpm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Msg( [[

module( "gpm", package.seeall )

_VERSION = 013600
_VERSION = 013601

if not Colors then
Realm = "unknown"
Expand Down
31 changes: 19 additions & 12 deletions lua/gpm/sources/lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ local error = error
if efsw ~= nil then

local logger = gpm.Logger
local timer = timer

local function catch( message )
logger:Error( message )
end

hook.Add( "FileWatchEvent", "GPM.Sources.Lua.Hot-Reload", function( action, _, filePath )
hook.Add( "FileWatchEvent", "gpm.efsw.sources.lua", function( action, _, filePath )
if action <= 0 then return end

local importPath = string.match( string.sub( filePath, 5 ), "packages/[^/]+" )
Expand All @@ -30,9 +32,13 @@ if efsw ~= nil then
local pkg = gpm.Packages[ importPath ]
if not pkg then return end

if not pkg:IsInstalled() then return end
if pkg:IsReloading() then return end
pkg:Reload():Catch( catch )
local timerName = "gpm.efsw.sources.lua." .. importPath
timer.Create( timerName, 0.25, 1, function()
timer.Remove( timerName )
if not pkg:IsInstalled() then return end
if pkg:IsReloading() then return end
pkg:Reload():Catch( catch )
end )
end )

end
Expand Down Expand Up @@ -67,17 +73,9 @@ GetMetadata = promise.Async( function( importPath )
else
metadata.autorun = true
end

if SERVER or MENU_DLL then
fs.Watch( importPath .. "/", "lsv" )
end
elseif fs.IsFile( importPath, "LUA" ) then
metadata.init = importPath
metadata.autorun = true

if SERVER or MENU_DLL then
fs.Watch( importPath, "lsv" )
end
end

return metadata
Expand Down Expand Up @@ -143,6 +141,15 @@ Import = promise.Async( function( metadata )
return promise.Reject( result )
end

if SERVER or MENU_DLL then
local importPath = metadata.importpath
if fs.IsDir( importPath, "lsv" ) then
fs.Watch( importPath .. "/", "lsv" )
else
fs.Watch( importPath, "lsv" )
end
end

return package.Initialize( metadata, result )
end )

Expand Down

0 comments on commit 173e2c5

Please sign in to comment.