From d4c04fc71842d0aa2c595d76707cce45221f9a66 Mon Sep 17 00:00:00 2001 From: TheSparta Date: Mon, 18 Mar 2024 00:06:08 +0000 Subject: [PATCH] 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