mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
parent
b34393cfcd
commit
0a3874adee
9 changed files with 299 additions and 177 deletions
|
@ -101,6 +101,7 @@ const IGNORED_DEPENDENCIES: readonly string[] = [
|
|||
"minecraft",
|
||||
"java",
|
||||
"forge",
|
||||
"neoforge",
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,7 @@ import { PlatformType } from "@/platforms";
|
|||
import { PartialRecord } from "@/utils/types";
|
||||
import { deprecate } from "node:util";
|
||||
import { RawForgeMetadata } from "./raw-forge-metadata";
|
||||
import { getForgeDependencies } from "./forge-dependency";
|
||||
import { asString } from "@/utils/string-utils";
|
||||
|
||||
// _ TODO: Remove the deprecated stuff in v4.0.
|
||||
|
@ -81,7 +82,12 @@ const getLegacyForgeMetadataCustomPayload = deprecate(
|
|||
/**
|
||||
* A list of default mod loaders associated with the Forge loader.
|
||||
*/
|
||||
const DEFAULT_LOADERS = [LoaderType.FORGE] as const;
|
||||
const DEFAULT_FORGE_LOADERS = [LoaderType.FORGE] as const;
|
||||
|
||||
/**
|
||||
* A list of default mod loaders associated with the NeoForge loader.
|
||||
*/
|
||||
const DEFAULT_NEOFORGE_LOADERS = [LoaderType.NEOFORGE] as const;
|
||||
|
||||
/**
|
||||
* Gets an array of supported mod loaders from the custom payload attached to the Forge metadata.
|
||||
|
@ -90,8 +96,14 @@ const DEFAULT_LOADERS = [LoaderType.FORGE] as const;
|
|||
*
|
||||
* @returns An array of supported mod loaders.
|
||||
*/
|
||||
export function getLoadersFromForgeMetadataCustomPayload(payload: ForgeMetadataCustomPayload): string[] {
|
||||
return payload?.loaders || [...DEFAULT_LOADERS];
|
||||
export function getLoadersFromForgeMetadataCustomPayload(metadata: RawForgeMetadata): string[] {
|
||||
const payload = getForgeMetadataCustomPayload(metadata);
|
||||
if (payload?.loaders) {
|
||||
return payload.loaders;
|
||||
}
|
||||
|
||||
const isNeoForge = getForgeDependencies(metadata).some(x => x.modId === LoaderType.NEOFORGE);
|
||||
return isNeoForge ? [...DEFAULT_NEOFORGE_LOADERS] : [...DEFAULT_FORGE_LOADERS];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,7 +63,7 @@ export class ForgeMetadata implements LoaderMetadata {
|
|||
* @inheritdoc
|
||||
*/
|
||||
get loaders(): string[] {
|
||||
return getLoadersFromForgeMetadataCustomPayload(this.customPayload);
|
||||
return getLoadersFromForgeMetadataCustomPayload(this._raw);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,6 +59,7 @@ export function createLoaderMetadataReader(loader: LoaderType): LoaderMetadataRe
|
|||
return new FabricMetadataReader();
|
||||
|
||||
case LoaderType.FORGE:
|
||||
case LoaderType.NEOFORGE:
|
||||
return new ForgeMetadataReader();
|
||||
|
||||
case LoaderType.QUILT:
|
||||
|
|
|
@ -20,6 +20,11 @@ enum LoaderTypeValues {
|
|||
* Quilt mod loader.
|
||||
*/
|
||||
QUILT = "quilt",
|
||||
|
||||
/**
|
||||
* NeoForge mod loader.
|
||||
*/
|
||||
NEOFORGE = "neoforge",
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
73
tests/content/neoforge/mods.toml
Normal file
73
tests/content/neoforge/mods.toml
Normal file
|
@ -0,0 +1,73 @@
|
|||
modLoader="javafml"
|
||||
loaderVersion="[34,)"
|
||||
issueTrackerURL="https://github.com/"
|
||||
displayURL="https://github.com/"
|
||||
authors="Author"
|
||||
license="MIT"
|
||||
|
||||
[[mods]]
|
||||
modId="example-mod"
|
||||
version="0.1.0"
|
||||
displayName="Example Mod"
|
||||
description='''
|
||||
Example mod
|
||||
'''
|
||||
|
||||
[[dependencies.example-mod]]
|
||||
modId="minecraft"
|
||||
mandatory=true
|
||||
versionRange="[1.17, 1.18)"
|
||||
side="BOTH"
|
||||
|
||||
[[dependencies.example-mod]]
|
||||
modId="neoforge"
|
||||
mandatory=true
|
||||
versionRange="[34,)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
||||
[[dependencies.example-mod]]
|
||||
modId="java"
|
||||
mandatory=true
|
||||
versionRange="[16,)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
||||
[[dependencies.example-mod]]
|
||||
modId="suggested-mod"
|
||||
mandatory=false
|
||||
versionRange="*"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
[dependencies.example-mod.mc-publish]
|
||||
modrinth="BBBB"
|
||||
curseforge=43
|
||||
github="v0.3.0"
|
||||
ignore=["curseforge"]
|
||||
|
||||
|
||||
[[dependencies.example-mod]]
|
||||
modId="included-mod"
|
||||
mandatory=false
|
||||
embedded=true
|
||||
versionRange="*"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
||||
[[dependencies.example-mod]]
|
||||
modId="breaking-mod"
|
||||
mandatory=false
|
||||
incompatible=true
|
||||
versionRange="*"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
||||
[mc-publish]
|
||||
modrinth="AANobbMI"
|
||||
curseforge=394468
|
||||
github="mc1.18-0.4.0-alpha5"
|
||||
loaders=["forge", "forge2"]
|
||||
dependencies=[
|
||||
"recommended-mod@0.2.0(recommended){modrinth:AAAA}{curseforge:42}{github:v0.2.0}#(ignore)",
|
||||
"conflicting-mod@<0.40.0(conflicting)",
|
||||
]
|
|
@ -6,6 +6,7 @@ import { ForgeMetadataReader } from "@/loaders/forge/forge-metadata-reader";
|
|||
beforeEach(async () => {
|
||||
mockFs({
|
||||
"forge.mod.jar": await zipFile([__dirname, "../../../content/forge/mods.toml"], "META-INF/mods.toml"),
|
||||
"neoforge.mod.jar": await zipFile([__dirname, "../../../content/neoforge/mods.toml"], "META-INF/mods.toml"),
|
||||
"text.txt": "",
|
||||
});
|
||||
});
|
||||
|
@ -15,7 +16,7 @@ afterEach(() => {
|
|||
});
|
||||
|
||||
describe("ForgeMetadataReader", () => {
|
||||
test("successfully reads mods.toml", async () => {
|
||||
test("successfully reads forge/mods.toml", async () => {
|
||||
const reader = new ForgeMetadataReader();
|
||||
|
||||
const metadata = await reader.readMetadataFile("forge.mod.jar");
|
||||
|
@ -23,6 +24,14 @@ describe("ForgeMetadataReader", () => {
|
|||
expect(metadata).toBeInstanceOf(ForgeMetadata);
|
||||
});
|
||||
|
||||
test("successfully reads neoforge/mods.toml", async () => {
|
||||
const reader = new ForgeMetadataReader();
|
||||
|
||||
const metadata = await reader.readMetadataFile("neoforge.mod.jar");
|
||||
|
||||
expect(metadata).toBeInstanceOf(ForgeMetadata);
|
||||
});
|
||||
|
||||
test("returns undefined if file is not a Forge mod", async () => {
|
||||
const reader = new ForgeMetadataReader();
|
||||
|
||||
|
|
|
@ -5,24 +5,35 @@ import { DependencyType } from "@/dependencies/dependency-type";
|
|||
import { PlatformType } from "@/platforms/platform-type";
|
||||
import { RawForgeMetadata } from "@/loaders/forge/raw-forge-metadata";
|
||||
import { ForgeMetadata } from "@/loaders/forge/forge-metadata";
|
||||
import { LoaderType } from "@/loaders/loader-type";
|
||||
|
||||
const RAW_METADATA: RawForgeMetadata = Object.freeze(parseToml(
|
||||
readFileSync(resolvePath(__dirname, "../../../content/forge/mods.toml"), "utf8")
|
||||
function createRawMetadataEntry(loader: LoaderType): { loader: LoaderType, raw: RawForgeMetadata } {
|
||||
const raw = Object.freeze(parseToml(
|
||||
readFileSync(resolvePath(__dirname, `../../../content/${loader}/mods.toml`), "utf8")
|
||||
));
|
||||
|
||||
return Object.freeze({ loader, raw });
|
||||
}
|
||||
|
||||
const RAW_METADATA_ENTRIES = Object.freeze([
|
||||
createRawMetadataEntry(LoaderType.FORGE),
|
||||
createRawMetadataEntry(LoaderType.NEOFORGE),
|
||||
]);
|
||||
|
||||
describe("ForgeMetadata", () => {
|
||||
describe.each(RAW_METADATA_ENTRIES)("$loader", ({ loader, raw }) => {
|
||||
describe("from", () => {
|
||||
test("constructs new ForgeMetadata instance using given raw metadata", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata).toBeInstanceOf(ForgeMetadata);
|
||||
expect(metadata.raw).toBe(RAW_METADATA);
|
||||
expect(metadata.raw).toBe(raw);
|
||||
});
|
||||
});
|
||||
|
||||
describe("id", () => {
|
||||
test("returns id of the mod", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.id).toBe("example-mod");
|
||||
});
|
||||
|
@ -30,7 +41,7 @@ describe("ForgeMetadata", () => {
|
|||
|
||||
describe("name", () => {
|
||||
test("returns name of the mod", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.name).toBe("Example Mod");
|
||||
});
|
||||
|
@ -38,21 +49,29 @@ describe("ForgeMetadata", () => {
|
|||
|
||||
describe("version", () => {
|
||||
test("returns version of the mod", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.version).toBe("0.1.0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("loaders", () => {
|
||||
test("returns 'forge' by default", () => {
|
||||
const metadata = ForgeMetadata.from({} as RawForgeMetadata);
|
||||
test(`returns '${loader}' by default`, () => {
|
||||
const rawWithoutLoadersField = {
|
||||
...raw,
|
||||
"mc-publish": {
|
||||
...raw["mc-publish"],
|
||||
loaders: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
expect(metadata.loaders).toEqual(["forge"]);
|
||||
const metadata = ForgeMetadata.from(rawWithoutLoadersField);
|
||||
|
||||
expect(metadata.loaders).toEqual([loader]);
|
||||
});
|
||||
|
||||
test("returns the same value as the 'loaders' field in the custom payload", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.loaders).toEqual(["forge", "forge2"]);
|
||||
});
|
||||
|
@ -61,7 +80,7 @@ describe("ForgeMetadata", () => {
|
|||
describe("gameName", () => {
|
||||
test("always returns 'minecraft'", () => {
|
||||
expect(ForgeMetadata.from({} as RawForgeMetadata).gameName).toBe("minecraft");
|
||||
expect(ForgeMetadata.from(RAW_METADATA).gameName).toBe("minecraft");
|
||||
expect(ForgeMetadata.from(raw).gameName).toBe("minecraft");
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -79,7 +98,7 @@ describe("ForgeMetadata", () => {
|
|||
});
|
||||
|
||||
test("returns the same values as the 'minecraft' dependency", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.gameVersions).toEqual(["[1.17, 1.18)"]);
|
||||
});
|
||||
|
@ -102,7 +121,7 @@ describe("ForgeMetadata", () => {
|
|||
});
|
||||
|
||||
test("regular dependencies have no aliases", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
const regularDependencies = ["included-mod", "conflicting-mod", "breaking-mod"].map(id => dependencies.find(x => x.id === id));
|
||||
|
@ -114,18 +133,18 @@ describe("ForgeMetadata", () => {
|
|||
}
|
||||
});
|
||||
|
||||
test("special dependencies ('forge', 'minecraft', 'java') are ignored by default", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
test(`special dependencies ('${loader}', 'minecraft', 'java') are ignored by default`, () => {
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(dependencies.find(x => x.id === "forge")?.isIgnored()).toBe(true);
|
||||
expect(dependencies.find(x => x.id === loader)?.isIgnored()).toBe(true);
|
||||
expect(dependencies.find(x => x.id === "minecraft")?.isIgnored()).toBe(true);
|
||||
expect(dependencies.find(x => x.id === "java")?.isIgnored()).toBe(true);
|
||||
});
|
||||
|
||||
test("regular dependencies are not ignored by default", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
|
@ -136,12 +155,12 @@ describe("ForgeMetadata", () => {
|
|||
});
|
||||
|
||||
test("returns dependencies merged with the 'dependencies' declaration from the custom payload", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
const dependencies = metadata.dependencies;
|
||||
|
||||
expect(dependencies).toHaveLength(8);
|
||||
expect(dependencies.find(x => x.id === "forge")).toMatchObject({ versions: ["[34,)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === loader)).toMatchObject({ versions: ["[34,)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === "minecraft")).toMatchObject({ versions: ["[1.17, 1.18)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === "java")).toMatchObject({ versions: ["[16,)"], type: DependencyType.REQUIRED });
|
||||
expect(dependencies.find(x => x.id === "recommended-mod")).toMatchObject({ versions: ["0.2.0"], type: DependencyType.RECOMMENDED });
|
||||
|
@ -167,7 +186,7 @@ describe("ForgeMetadata", () => {
|
|||
|
||||
describe("mod", () => {
|
||||
test("returns the main mod entry in the metadata", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.mod?.modId).toBe("example-mod");
|
||||
});
|
||||
|
@ -181,9 +200,9 @@ describe("ForgeMetadata", () => {
|
|||
|
||||
describe("raw", () => {
|
||||
test("returns the raw metadata oject this instance was created from", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.raw).toBe(RAW_METADATA);
|
||||
expect(metadata.raw).toBe(raw);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -195,7 +214,7 @@ describe("ForgeMetadata", () => {
|
|||
});
|
||||
|
||||
test("return the custom payload if it was specified", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.customPayload?.loaders).toEqual(["forge", "forge2"]);
|
||||
});
|
||||
|
@ -211,7 +230,7 @@ describe("ForgeMetadata", () => {
|
|||
});
|
||||
|
||||
test("returns the same value as one specified in the custom payload", () => {
|
||||
const metadata = ForgeMetadata.from(RAW_METADATA);
|
||||
const metadata = ForgeMetadata.from(raw);
|
||||
|
||||
expect(metadata.getProjectId(PlatformType.MODRINTH)).toBe("AANobbMI");
|
||||
expect(metadata.getProjectId(PlatformType.CURSEFORGE)).toBe("394468");
|
||||
|
@ -219,3 +238,4 @@ describe("ForgeMetadata", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,6 +13,7 @@ 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"),
|
||||
"text.txt": "",
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue