Made plugin load order deterministic.

This commit is contained in:
Adam Harrison 2021-11-07 13:14:48 -05:00
parent c1a5e6e16d
commit 05dcddaeec
1 changed files with 5 additions and 3 deletions

View File

@ -675,16 +675,18 @@ function core.load_plugins()
userdir = {dir = USERDIR, plugins = {}}, userdir = {dir = USERDIR, plugins = {}},
datadir = {dir = DATADIR, plugins = {}}, datadir = {dir = DATADIR, plugins = {}},
} }
local files = {} local files, ordered = {}, {}
for _, root_dir in ipairs {DATADIR, USERDIR} do for _, root_dir in ipairs {DATADIR, USERDIR} do
local plugin_dir = root_dir .. "/plugins" local plugin_dir = root_dir .. "/plugins"
for _, filename in ipairs(system.list_dir(plugin_dir) or {}) do for _, filename in ipairs(system.list_dir(plugin_dir) or {}) do
if not files[filename] then table.insert(ordered, filename) end
files[filename] = plugin_dir -- user plugins will always replace system plugins files[filename] = plugin_dir -- user plugins will always replace system plugins
end end
end end
table.sort(ordered)
for filename, plugin_dir in pairs(files) do for i, filename in ipairs(ordered) do
local basename = filename:match("(.-)%.lua$") or filename local plugin_dir, basename = files[filename], filename:match("(.-)%.lua$") or filename
local is_lua_file, version_match = check_plugin_version(plugin_dir .. '/' .. filename) local is_lua_file, version_match = check_plugin_version(plugin_dir .. '/' .. filename)
if is_lua_file then if is_lua_file then
if not version_match then if not version_match then