Special case dependencies are ignored by default

(minecraft, java, fabricloader, forge, etc)
This commit is contained in:
Kir_Antipov 2021-12-10 17:46:10 +03:00
parent ba6a460468
commit 7e5abb93bd
5 changed files with 45 additions and 19 deletions

View file

@ -4,14 +4,16 @@ import Dependency from "../../metadata/dependency";
import DependencyKind from "../../metadata/dependency-kind";
import PublisherTarget from "../../publishing/publisher-target";
const ignoredByDefault = ["minecraft", "java", "fabricloader"];
function getDependenciesByKind(config: any, kind: DependencyKind): Dependency[] {
const kindName = DependencyKind.toString(kind).toLowerCase();
const dependencies = new Array<Dependency>();
for (const [id, value] of Object.entries(config[kindName] || {})) {
const ignore = ignoredByDefault.includes(id);
if (typeof value === "string") {
dependencies.push(Dependency.create({ id, kind, version: value }));
dependencies.push(Dependency.create({ id, kind, version: value, ignore }));
} else {
dependencies.push(new ModConfigDependency({ ...<any>value, id, kind }));
dependencies.push(new ModConfigDependency({ ignore, ...<any>value, id, kind }));
}
}
return dependencies;

View file

@ -3,8 +3,10 @@ import ModConfigDependency from "../../metadata/mod-config-dependency";
import Dependency from "../../metadata/dependency";
import DependencyKind from "../../metadata/dependency-kind";
const ignoredByDefault = ["minecraft", "java", "forge"];
function createDependency(body: any): Dependency {
return new ModConfigDependency({
ignore: ignoredByDefault.includes(body.modId),
...body,
id: body.modId,
version: body.versionRange,

View file

@ -37,7 +37,7 @@
"depends": {
"fabricloader": ">=0.11.3",
"fabric": "*",
"fabric": ">=0.40.0",
"minecraft": "1.17.x",
"java": ">=16"
},

View file

@ -33,6 +33,13 @@ license="MIT"
ordering="NONE"
side="BOTH"
[[dependencies.example-mod]]
modId="java"
mandatory=true
versionRange="[16,)"
ordering="NONE"
side="BOTH"
[[dependencies.example-mod]]
modId="recommended-mod"
mandatory=false
@ -52,7 +59,7 @@ license="MIT"
modId="included-mod"
mandatory=false
embedded=true
versionRange="*"
versionRange="[0.40.0, )"
ordering="NONE"
side="BOTH"

View file

@ -54,14 +54,14 @@ describe("ModMetadataReader.readMetadata", () => {
test("dependency info can be read", async () => {
const metadata = await ModMetadataReader.readMetadata("example-mod.fabric.jar");
const minecraft = metadata.dependencies.find(x => x.id === "minecraft");
expect(minecraft).toBeTruthy();
expect(minecraft.id).toBe("minecraft");
expect(minecraft.kind).toBe(DependencyKind.Depends);
expect(minecraft.version).toBe("1.17.x");
expect(minecraft.ignore).toBe(false);
const fabric = metadata.dependencies.find(x => x.id === "fabric");
expect(fabric).toBeTruthy();
expect(fabric.id).toBe("fabric");
expect(fabric.kind).toBe(DependencyKind.Depends);
expect(fabric.version).toBe(">=0.40.0");
expect(fabric.ignore).toBe(false);
for (const project of PublisherTarget.getValues()) {
expect(minecraft.getProjectSlug(project)).toBe(minecraft.id);
expect(fabric.getProjectSlug(project)).toBe(fabric.id);
}
});
@ -77,6 +77,13 @@ describe("ModMetadataReader.readMetadata", () => {
expect(recommended.getProjectSlug(PublisherTarget.CurseForge)).toBe("42");
expect(recommended.getProjectSlug(PublisherTarget.GitHub)).toBe("v0.2.0");
});
test("special case dependencies (minecraft, java and fabricloader) are ignored by default", async () => {
const metadata = await ModMetadataReader.readMetadata("example-mod.fabric.jar");
expect(metadata.dependencies.find(x => x.id === "minecraft").ignore).toBe(true);
expect(metadata.dependencies.find(x => x.id === "java").ignore).toBe(true);
expect(metadata.dependencies.find(x => x.id === "fabricloader").ignore).toBe(true);
});
});
describe("Forge", () => {
@ -111,10 +118,11 @@ describe("ModMetadataReader.readMetadata", () => {
test("all dependencies are read", async () => {
const metadata = await ModMetadataReader.readMetadata("example-mod.forge.jar");
expect(metadata.dependencies).toHaveLength(5);
expect(metadata.dependencies).toHaveLength(6);
const dependencies = metadata.dependencies.reduce((agg, x) => { agg[x.id] = x; return agg; }, <Record<string, Dependency>>{});
expect(dependencies["forge"]?.kind).toBe(DependencyKind.Depends);
expect(dependencies["minecraft"]?.kind).toBe(DependencyKind.Depends);
expect(dependencies["java"]?.kind).toBe(DependencyKind.Depends);
expect(dependencies["recommended-mod"]?.kind).toBe(DependencyKind.Recommends);
expect(dependencies["included-mod"]?.kind).toBe(DependencyKind.Includes);
expect(dependencies["breaking-mod"]?.kind).toBe(DependencyKind.Breaks);
@ -122,14 +130,14 @@ describe("ModMetadataReader.readMetadata", () => {
test("dependency info can be read", async () => {
const metadata = await ModMetadataReader.readMetadata("example-mod.forge.jar");
const minecraft = metadata.dependencies.find(x => x.id === "minecraft");
expect(minecraft).toBeTruthy();
expect(minecraft.id).toBe("minecraft");
expect(minecraft.kind).toBe(DependencyKind.Depends);
expect(minecraft.version).toBe("[1.17, 1.18)");
expect(minecraft.ignore).toBe(false);
const included = metadata.dependencies.find(x => x.id === "included-mod");
expect(included).toBeTruthy();
expect(included.id).toBe("included-mod");
expect(included.kind).toBe(DependencyKind.Includes);
expect(included.version).toBe("[0.40.0, )");
expect(included.ignore).toBe(false);
for (const project of PublisherTarget.getValues()) {
expect(minecraft.getProjectSlug(project)).toBe(minecraft.id);
expect(included.getProjectSlug(project)).toBe(included.id);
}
});
@ -145,6 +153,13 @@ describe("ModMetadataReader.readMetadata", () => {
expect(recommended.getProjectSlug(PublisherTarget.CurseForge)).toBe("42");
expect(recommended.getProjectSlug(PublisherTarget.GitHub)).toBe("v0.2.0");
});
test("special case dependencies (minecraft, java and forge) are ignored by default", async () => {
const metadata = await ModMetadataReader.readMetadata("example-mod.forge.jar");
expect(metadata.dependencies.find(x => x.id === "minecraft").ignore).toBe(true);
expect(metadata.dependencies.find(x => x.id === "java").ignore).toBe(true);
expect(metadata.dependencies.find(x => x.id === "forge").ignore).toBe(true);
});
});
describe("unsupported mod formats", () => {