fix: handle when there is no overrides in the modpack

This commit is contained in:
HerozDotExe 2026-06-29 20:57:55 +02:00
parent 4d7eb93b88
commit 23639e867e
2 changed files with 43 additions and 19 deletions

View file

@ -132,7 +132,7 @@ export async function getOverridesChanges(
overridesList.find(
(a) =>
path.relative(overridesPath, path.join(a.parentPath, a.name)) ===
relativePath,
relativePath,
)
) {
// overwrite as it may be a different file
@ -163,10 +163,10 @@ export async function getOverridesChanges(
!oldOverridesList.find(
(oldFile) =>
relativePath ===
path.relative(
oldOverridesPath,
path.join(oldFile.parentPath, oldFile.name),
),
path.relative(
oldOverridesPath,
path.join(oldFile.parentPath, oldFile.name),
),
)
) {
// new file
@ -187,10 +187,11 @@ export async function getOverridesChanges(
addedDirs.push(
path.relative(overridesPath, path.join(file.parentPath, file.name)),
);
} else
} else {
addedOverrides.push(
path.relative(overridesPath, path.join(file.parentPath, file.name)),
);
}
}
return {
@ -224,10 +225,24 @@ export async function generatePackChanges(
manifest,
oldManifest,
);
const overridesChanges = await getOverridesChanges(
instanceFolder,
tempFolder,
);
let overridesChanges: Awaited<ReturnType<typeof getOverridesChanges>> = {
addedDirs: [],
addedOverrides: [],
removedDirs: [],
removedOverrides: [],
};
if (
await exists(
path.join(tempFolder, "pack", "overrides"),
)
) {
overridesChanges = await getOverridesChanges(
instanceFolder,
tempFolder,
);
}
return { modrinthChanges, overridesChanges };
}
@ -241,7 +256,7 @@ export async function ModrinthDownloader(
concurrency: 5,
},
updateSize: true,
overwrite: true
overwrite: true,
});
modrinthDownloader.on("completed", () => {

View file

@ -1,11 +1,11 @@
import { EventEmitter } from "events";
import {
Config,
FinalConfig,
InstanceEvents,
logger,
Version,
FinalConfig,
ModloaderConfig,
Version,
} from "../utils/types";
import path from "node:path";
import {
@ -53,8 +53,8 @@ export function defineConfig(logger: logger, config: Config) {
instance: config.paths.instance,
versions: config.paths.versions ?? path.join(config.paths.root, "versions"),
assets: config.paths.assets ?? path.join(config.paths.root, "assets"),
libraries:
config.paths.libraries ?? path.join(config.paths.root, "libraries"),
libraries: config.paths.libraries ??
path.join(config.paths.root, "libraries"),
};
config.args = {
@ -267,15 +267,24 @@ export class Instance extends EventEmitter<InstanceEvents> {
// Delete before downloading
await ProjectsDeleter(modrinthChanges.removedProject, (...args) => this.emit(...args));
await ProjectsDeleter(
modrinthChanges.removedProject,
(...args) => this.emit(...args),
);
await ModrinthDownloader(modrinthChanges.addedProjects, (...args) => this.emit(...args));
await ModrinthDownloader(
modrinthChanges.addedProjects,
(...args) => this.emit(...args),
);
await OverridesDeleter(overridesChanges, (...args) => this.emit(...args));
await OverridesDeleter(
overridesChanges,
(...args) => this.emit(...args),
);
await OverridesCopier(
overridesChanges.addedOverrides,
path.join(this.config.modrinth.tempFolder, 'pack', 'overrides'),
path.join(this.config.modrinth.tempFolder, "pack", "overrides"),
this.config.paths.instance,
(...args) => this.emit(...args),
);