From 21d095e8a6db2e717657eb7754b20aad9d07257e Mon Sep 17 00:00:00 2001 From: PrikolMen Date: Tue, 13 Jun 2023 07:23:15 +0400 Subject: [PATCH 1/5] 1.35.0 changes --- lua/gpm/fs.lua | 1 + lua/gpm/init.lua | 2 +- lua/gpm/package.lua | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lua/gpm/fs.lua b/lua/gpm/fs.lua index ecda8341..30793965 100644 --- a/lua/gpm/fs.lua +++ b/lua/gpm/fs.lua @@ -33,6 +33,7 @@ local ipairs = ipairs local assert = assert local type = type +-- TODO: Add drag-n-drop packages feature if efsw ~= nil then hook.Add( "FileWatchEvent", "GPM.AutoReload", function( actionID, _, filePath ) local importPath = string.match( filePath, ".*/lua/(packages/.*)/" ) diff --git a/lua/gpm/init.lua b/lua/gpm/init.lua index f42fcb42..e760bbdf 100644 --- a/lua/gpm/init.lua +++ b/lua/gpm/init.lua @@ -24,7 +24,7 @@ MsgN( [[ module( "gpm", package.seeall ) -_VERSION = 013403 +_VERSION = 013500 if not Colors then Realm = "unknown" diff --git a/lua/gpm/package.lua b/lua/gpm/package.lua index c6f58381..fdf8be22 100644 --- a/lua/gpm/package.lua +++ b/lua/gpm/package.lua @@ -171,7 +171,7 @@ do source.send = nil end - -- Isolation features + -- Libs autonames feature local autonames = source.autonames if type( autonames ) == "table" then autonames.properties = autonames.properties ~= false and source.environment @@ -189,6 +189,21 @@ do } end + local defaults = source.defaults + if type( defaults ) == "table" then + defaults.typeid = autonames.typeid ~= false and source.environment + defaults.http = autonames.http ~= false and source.environment + defaults.type = autonames.type ~= false and source.environment + defaults.file = autonames.file ~= false and source.environment + else + source.defaults = { + ["typeid"] = source.environment, + ["http"] = source.environment, + ["type"] = source.environment, + ["file"] = source.environment + } + end + return source elseif type( source ) == "function" then local metadata = {} @@ -360,14 +375,23 @@ do if type( env ) ~= "table" then env = environment.Create( _G ) self.Environment = env + env._PKG = self env.AddCSLuaFile = addCSLuaFile env.ArgAssert = gpm.ArgAssert - env.TypeID = gpm.TypeID - env.http = gpm.http - env.type = gpm.type - env._PKG = self - env.file = fs + end + + env.TypeID = nil + env.http = nil + env.type = nil + env.file = nil + + local defaults = metadata.defaults + if defaults then + if defaults.typeid then env.TypeID = gpm.TypeID end + if defaults.http then env.http = gpm.http end + if defaults.type then env.type = gpm.type end + if defaults.file then env.file = fs end end env._VERSION = metadata.version From 9bde2bbf3ed9791f0d827b0a5613487b42132cfe Mon Sep 17 00:00:00 2001 From: PrikolMen Date: Tue, 13 Jun 2023 07:27:07 +0400 Subject: [PATCH 2/5] todo --- lua/gpm/fs.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/gpm/fs.lua b/lua/gpm/fs.lua index 30793965..0b7c3999 100644 --- a/lua/gpm/fs.lua +++ b/lua/gpm/fs.lua @@ -34,6 +34,7 @@ local assert = assert local type = type -- TODO: Add drag-n-drop packages feature +-- TODO: Add support for single file packages (rewrite pattern) if efsw ~= nil then hook.Add( "FileWatchEvent", "GPM.AutoReload", function( actionID, _, filePath ) local importPath = string.match( filePath, ".*/lua/(packages/.*)/" ) From e7d0c8197fa3e3953664bb6903f3c3423601ee23 Mon Sep 17 00:00:00 2001 From: PrikolMen Date: Wed, 14 Jun 2023 20:05:20 +0400 Subject: [PATCH 3/5] better logics --- lua/gpm/http.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lua/gpm/http.lua b/lua/gpm/http.lua index afb5e9e8..05c94560 100644 --- a/lua/gpm/http.lua +++ b/lua/gpm/http.lua @@ -1,4 +1,3 @@ -local logger = gpm.Logger local promise = promise local ipairs = ipairs local util = util @@ -7,12 +6,10 @@ local type = type -- https://github.com/WilliamVenner/gmsv_reqwest -- https://github.com/timschumi/gmod-chttp if SERVER then - if util.IsBinaryModuleInstalled( "reqwest" ) then - logger:Info( "A third-party http client 'reqwest' has been initialized." ) - require( "reqwest" ) - elseif util.IsBinaryModuleInstalled( "chttp" ) then - logger:Info( "A third-party http client 'chttp' has been initialized." ) - require( "chttp" ) + if util.IsBinaryModuleInstalled( "reqwest" ) and pcall( require, "reqwest" ) then + gpm.Logger:Info( "A third-party http client 'reqwest' has been initialized." ) + elseif util.IsBinaryModuleInstalled( "chttp" ) and pcall( require, "chttp" ) then + gpm.Logger:Info( "A third-party http client 'chttp' has been initialized." ) end end From e48fac4dd85b80265654a9951f5a70b2a44a72c8 Mon Sep 17 00:00:00 2001 From: PrikolMen Date: Wed, 14 Jun 2023 21:33:31 +0400 Subject: [PATCH 4/5] `GPM.EFSW` --- lua/gpm/fs.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lua/gpm/fs.lua b/lua/gpm/fs.lua index 0b7c3999..14513843 100644 --- a/lua/gpm/fs.lua +++ b/lua/gpm/fs.lua @@ -1,18 +1,17 @@ -local logger = gpm.Logger local SERVER = SERVER local util = util -- https://github.com/Pika-Software/gm_asyncio -- https://github.com/WilliamVenner/gm_async_write if util.IsBinaryModuleInstalled( "asyncio" ) and pcall( require, "asyncio" ) then - logger:Info( "A third-party file system API 'asyncio' has been initialized." ) + gpm.Logger:Info( "A third-party file system API 'asyncio' has been initialized." ) elseif SERVER and util.IsBinaryModuleInstalled( "async_write" ) and pcall( require, "async_write" ) then - logger:Info( "A third-party file system API 'async_write' has been initialized." ) + gpm.Logger:Info( "A third-party file system API 'async_write' has been initialized." ) end -- https://github.com/Pika-Software/gm_efsw if util.IsBinaryModuleInstalled( "efsw" ) and pcall( require, "efsw" ) then - logger:Info( "gm_efsw is initialized, package auto-reload are available." ) + gpm.Logger:Info( "gm_efsw is initialized, package auto-reload are available." ) end -- Libraries @@ -33,11 +32,11 @@ local ipairs = ipairs local assert = assert local type = type --- TODO: Add drag-n-drop packages feature --- TODO: Add support for single file packages (rewrite pattern) if efsw ~= nil then - hook.Add( "FileWatchEvent", "GPM.AutoReload", function( actionID, _, filePath ) - local importPath = string.match( filePath, ".*/lua/(packages/.*)/" ) + hook.Add( "FileWatchEvent", "GPM.EFSW", function( action, _, filePath ) + if action <= 0 then return end + + local importPath = string.match( string.sub( filePath, 5 ), "packages/[^/]+" ) if not importPath then return end local pkg = gpm.Packages[ importPath ] From dd04e551e626e9f33d15d0376ef6df7b5d3d6cec Mon Sep 17 00:00:00 2001 From: PrikolMen Date: Thu, 15 Jun 2023 00:15:45 +0400 Subject: [PATCH 5/5] Few fixes --- lua/gpm/commands.lua | 9 ++++++++- lua/gpm/fs.lua | 8 +++++++- lua/gpm/package.lua | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lua/gpm/commands.lua b/lua/gpm/commands.lua index 22fb704b..3f4cc2ea 100644 --- a/lua/gpm/commands.lua +++ b/lua/gpm/commands.lua @@ -73,6 +73,13 @@ function gpm.Reload( ... ) return end + if SERVER then + net.Start( "GPM.Networking" ) + net.WriteUInt( 2, 3 ) + net.WriteTable( arguments ) + net.Broadcast() + end + local packages, count = {}, 0 for _, searchable in ipairs( arguments ) do if #searchable == 0 then continue end @@ -90,7 +97,7 @@ function gpm.Reload( ... ) logger:Info( "Found %d candidates to reload, reloading...", count ) for pkg in pairs( packages ) do - pkg:Reload() + pkg:Reload( true ) end end diff --git a/lua/gpm/fs.lua b/lua/gpm/fs.lua index 14513843..b9711d8f 100644 --- a/lua/gpm/fs.lua +++ b/lua/gpm/fs.lua @@ -42,7 +42,13 @@ if efsw ~= nil then local pkg = gpm.Packages[ importPath ] if not pkg then return end - pkg:Reload() + local timerName = "GPM.EFSW." .. importPath + timer.Create( timerName, 0.5, 1, function() + timer.Remove( timerName ) + if pkg:IsInstalled() then + pkg:Reload() + end + end ) end ) end diff --git a/lua/gpm/package.lua b/lua/gpm/package.lua index fdf8be22..930b5a8b 100644 --- a/lua/gpm/package.lua +++ b/lua/gpm/package.lua @@ -888,7 +888,9 @@ do self:ClearCallbacks() end - gpm.Packages[ self:GetImportPath() ] = nil + local importPath = self:GetImportPath() + gpm.ImportTasks[ importPath ] = nil + gpm.Packages[ importPath ] = nil self.Installed = nil logger:Info( "Package '%s' was successfully uninstalled, took %.4f seconds.", self:GetIdentifier(), SysTime() - stopwatch )