Fixed undefined behaviour

- Would break out of the loop at the first dependency removed from `dependenciesToInstall`.
This commit is contained in:
TheSparta 2024-03-17 23:19:13 +00:00
parent ecc6638a20
commit e73fea8776

View File

@ -500,22 +500,20 @@ export class PreAkiModLoader implements IModLoader
protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void
{ {
const dependenciesToInstall: [string, string][] = Object.entries(pkg.dependencies); const dependenciesToInstall: [string, string][] = [];
let depIdx = 0; for (const [depName, depVersion] of Object.entries(pkg.dependencies))
for (const [depName, depVersion] of dependenciesToInstall)
{ {
// currently not checking for version mismatches, but we could check it, just don't know what we would do afterwards, some options would be: // currently not checking for version mismatches, but we could check it, just don't know what we would do afterwards, some options would be:
// 1 - throw an error // 1 - throw an error
// 2 - use the server's version (which is what's currently happening by not checking the version) // 2 - use the server's version (which is what's currently happening by not checking the version)
// 3 - use the mod's version (don't know the reprecursions this would have, or if it would even work) // 3 - use the mod's version (don't know the reprecursions this would have, or if it would even work)
// if a dependency from the mod exists in the server dependencies we can safely remove it from the list of dependencies to install since it already comes bundled in the server. // if a mod's dependency does not exist in the server's dependencies we can add it to the list of dependencies to install.
if (this.serverDependencies[depName]) if (!this.serverDependencies[depName])
{ {
dependenciesToInstall.splice(depIdx, 1); dependenciesToInstall.push([depName, depVersion]);
} }
depIdx++;
} }
// If the mod has no extra dependencies return as there's nothing that needs to be done. // If the mod has no extra dependencies return as there's nothing that needs to be done.