diff --git a/src/metadata/fabric/fabric-mod-metadata.ts b/src/metadata/fabric/fabric-mod-metadata.ts index e1c8d73..016d52e 100644 --- a/src/metadata/fabric/fabric-mod-metadata.ts +++ b/src/metadata/fabric/fabric-mod-metadata.ts @@ -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(); 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({ ...value, id, kind })); + dependencies.push(new ModConfigDependency({ ignore, ...value, id, kind })); } } return dependencies; diff --git a/src/metadata/forge/forge-mod-metadata.ts b/src/metadata/forge/forge-mod-metadata.ts index f8cac50..23ed705 100644 --- a/src/metadata/forge/forge-mod-metadata.ts +++ b/src/metadata/forge/forge-mod-metadata.ts @@ -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, diff --git a/test/content/fabric.mod.json b/test/content/fabric.mod.json index f4ed1b2..b6b0d1f 100644 --- a/test/content/fabric.mod.json +++ b/test/content/fabric.mod.json @@ -37,7 +37,7 @@ "depends": { "fabricloader": ">=0.11.3", - "fabric": "*", + "fabric": ">=0.40.0", "minecraft": "1.17.x", "java": ">=16" }, diff --git a/test/content/mods.toml b/test/content/mods.toml index 00141e2..124c7ae 100644 --- a/test/content/mods.toml +++ b/test/content/mods.toml @@ -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" diff --git a/test/mod-metadata-reader.test.ts b/test/mod-metadata-reader.test.ts index fa23b40..34cff9a 100644 --- a/test/mod-metadata-reader.test.ts +++ b/test/mod-metadata-reader.test.ts @@ -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; }, >{}); 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", () => {