Skip to content

Commit

Permalink
Added support for neoforge.mods.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
Kir-Antipov committed Apr 27, 2024
1 parent c0f30ad commit bb3c76b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/loaders/neoforge/neoforge-metadata-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readAllZippedText } from "@/utils/io/file-info";
import { LoaderType } from "../loader-type";
import { LoaderMetadataReader } from "../loader-metadata-reader";
import { NeoForgeMetadata } from "./neoforge-metadata";
import { MODS_TOML } from "./raw-neoforge-metadata";
import { NEOFORGE_MODS_TOML, MODS_TOML } from "./raw-neoforge-metadata";

/**
* A metadata reader that is able to read NeoForge mod metadata from a zipped file.
Expand All @@ -14,7 +14,10 @@ export class NeoForgeMetadataReader implements LoaderMetadataReader<NeoForgeMeta
* @inheritdoc
*/
async readMetadataFile(path: PathLike): Promise<NeoForgeMetadata> {
const metadataText = await readAllZippedText(path, MODS_TOML);
// Prefer `neoforge.mods.toml` over `mods.toml`.
const metadataText = await readAllZippedText(path, NEOFORGE_MODS_TOML)
.catch(() => readAllZippedText(path, MODS_TOML));

const metadata = NeoForgeMetadata.from(parseToml(metadataText));
if (!metadata.dependencies.some(x => x.id === LoaderType.NEOFORGE)) {
throw new Error("A NeoForge metadata file must contain a 'neoforge' dependency");
Expand Down
5 changes: 5 additions & 0 deletions src/loaders/neoforge/raw-neoforge-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ export interface RawNeoForgeMetadata {
* Name of the `mods.toml` file, that contains raw NeoForge metadata.
*/
export const MODS_TOML = "META-INF/mods.toml";

/**
* Name of the `neoforge.mods.toml` file, that contains raw NeoForge metadata.
*/
export const NEOFORGE_MODS_TOML = "META-INF/neoforge.mods.toml";
File renamed without changes.
3 changes: 2 additions & 1 deletion tests/unit/loaders/loader-metadata-reader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ beforeEach(async () => {
"fabric.jar": await zipFile([__dirname, "../../content/fabric/fabric.mod.json"]),
"quilt.jar": await zipFile([__dirname, "../../content/quilt/quilt.mod.json"]),
"forge.jar": await zipFile([__dirname, "../../content/forge/mods.toml"], "META-INF/mods.toml"),
"neoforge.jar": await zipFile([__dirname, "../../content/neoforge/mods.toml"], "META-INF/mods.toml"),
"neoforge.jar": await zipFile([__dirname, "../../content/neoforge/neoforge.mods.toml"], "META-INF/neoforge.mods.toml"),
"neoforge.legacy.jar": await zipFile([__dirname, "../../content/neoforge/neoforge.mods.toml"], "META-INF/mods.toml"),
"text.txt": "",
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/loaders/neoforge/neoforge-metadata-reader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NeoForgeMetadataReader } from "@/loaders/neoforge/neoforge-metadata-rea

beforeEach(async () => {
mockFs({
"neoforge.mod.jar": await zipFile([__dirname, "../../../content/neoforge/mods.toml"], "META-INF/mods.toml"),
"neoforge.mod.jar": await zipFile([__dirname, "../../../content/neoforge/neoforge.mods.toml"], "META-INF/neoforge.mods.toml"),
"text.txt": "",
});
});
Expand All @@ -15,7 +15,7 @@ afterEach(() => {
});

describe("NeoForgeMetadataReader", () => {
test("successfully reads mods.toml", async () => {
test("successfully reads neoforge.mods.toml", async () => {
const reader = new NeoForgeMetadataReader();

const metadata = await reader.readMetadataFile("neoforge.mod.jar");
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/loaders/neoforge/neoforge-metadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RawNeoForgeMetadata } from "@/loaders/neoforge/raw-neoforge-metadata";
import { NeoForgeMetadata } from "@/loaders/neoforge/neoforge-metadata";

const RAW_METADATA: RawNeoForgeMetadata = Object.freeze(parseToml(
readFileSync(resolvePath(__dirname, "../../../content/neoforge/mods.toml"), "utf8")
readFileSync(resolvePath(__dirname, "../../../content/neoforge/neoforge.mods.toml"), "utf8")
));

describe("NeoForgeMetadata", () => {
Expand Down

0 comments on commit bb3c76b

Please sign in to comment.