From e73fea87764ecd679b78e29a79d5dc7c41d229ec Mon Sep 17 00:00:00 2001 From: TheSparta Date: Sun, 17 Mar 2024 23:19:13 +0000 Subject: [PATCH 1/2] Fixed undefined behaviour - Would break out of the loop at the first dependency removed from `dependenciesToInstall`. --- project/src/loaders/PreAkiModLoader.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/project/src/loaders/PreAkiModLoader.ts b/project/src/loaders/PreAkiModLoader.ts index 784aa6f0..bd890ce1 100644 --- a/project/src/loaders/PreAkiModLoader.ts +++ b/project/src/loaders/PreAkiModLoader.ts @@ -500,22 +500,20 @@ export class PreAkiModLoader implements IModLoader 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 dependenciesToInstall) + for (const [depName, depVersion] of Object.entries(pkg.dependencies)) { // 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 // 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) - // 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 (this.serverDependencies[depName]) + // 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]) { - 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. From d4c04fc71842d0aa2c595d76707cce45221f9a66 Mon Sep 17 00:00:00 2001 From: TheSparta Date: Mon, 18 Mar 2024 00:06:08 +0000 Subject: [PATCH 2/2] Simplified autoInstallDependencies() --- project/src/loaders/PreAkiModLoader.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/project/src/loaders/PreAkiModLoader.ts b/project/src/loaders/PreAkiModLoader.ts index bd890ce1..686880b4 100644 --- a/project/src/loaders/PreAkiModLoader.ts +++ b/project/src/loaders/PreAkiModLoader.ts @@ -500,7 +500,7 @@ export class PreAkiModLoader implements IModLoader protected autoInstallDependencies(modPath: string, pkg: IPackageJsonData): void { - const dependenciesToInstall: [string, string][] = []; + const dependenciesToInstall = new Map(); for (const [depName, depVersion] of Object.entries(pkg.dependencies)) { @@ -512,12 +512,12 @@ export class PreAkiModLoader implements IModLoader // 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]) { - dependenciesToInstall.push([depName, depVersion]); + dependenciesToInstall.set(depName, depVersion); } } // If the mod has no extra dependencies return as there's nothing that needs to be done. - if (dependenciesToInstall.length === 0) + if (dependenciesToInstall.size === 0) { return; } @@ -557,8 +557,13 @@ export class PreAkiModLoader implements IModLoader globalThis.G_RELEASE_CONFIGURATION ? "Aki_Data/Server/@pnpm/exe" : "node_modules/@pnpm/exe", os.platform() === "win32" ? "pnpm.exe" : "pnpm", ); + let command = `${pnpmPath} install `; - command += dependenciesToInstall.map(([depName, depVersion]) => `${depName}@${depVersion}`).join(" "); + for (const [depName, depVersion] of dependenciesToInstall) + { + command += `${depName}@${depVersion} `; + } + execSync(command, { cwd: modPath }); // Delete the new blank package.json then rename the backup back to the original name