mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-25 09:51:01 -05:00
Special case dependencies are ignored by default
(minecraft, java, fabricloader, forge, etc)
This commit is contained in:
parent
ba6a460468
commit
7e5abb93bd
5 changed files with 45 additions and 19 deletions
|
@ -4,14 +4,16 @@ import Dependency from "../../metadata/dependency";
|
||||||
import DependencyKind from "../../metadata/dependency-kind";
|
import DependencyKind from "../../metadata/dependency-kind";
|
||||||
import PublisherTarget from "../../publishing/publisher-target";
|
import PublisherTarget from "../../publishing/publisher-target";
|
||||||
|
|
||||||
|
const ignoredByDefault = ["minecraft", "java", "fabricloader"];
|
||||||
function getDependenciesByKind(config: any, kind: DependencyKind): Dependency[] {
|
function getDependenciesByKind(config: any, kind: DependencyKind): Dependency[] {
|
||||||
const kindName = DependencyKind.toString(kind).toLowerCase();
|
const kindName = DependencyKind.toString(kind).toLowerCase();
|
||||||
const dependencies = new Array<Dependency>();
|
const dependencies = new Array<Dependency>();
|
||||||
for (const [id, value] of Object.entries(config[kindName] || {})) {
|
for (const [id, value] of Object.entries(config[kindName] || {})) {
|
||||||
|
const ignore = ignoredByDefault.includes(id);
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
dependencies.push(Dependency.create({ id, kind, version: value }));
|
dependencies.push(Dependency.create({ id, kind, version: value, ignore }));
|
||||||
} else {
|
} else {
|
||||||
dependencies.push(new ModConfigDependency({ ...<any>value, id, kind }));
|
dependencies.push(new ModConfigDependency({ ignore, ...<any>value, id, kind }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dependencies;
|
return dependencies;
|
||||||
|
|
|
@ -3,8 +3,10 @@ import ModConfigDependency from "../../metadata/mod-config-dependency";
|
||||||
import Dependency from "../../metadata/dependency";
|
import Dependency from "../../metadata/dependency";
|
||||||
import DependencyKind from "../../metadata/dependency-kind";
|
import DependencyKind from "../../metadata/dependency-kind";
|
||||||
|
|
||||||
|
const ignoredByDefault = ["minecraft", "java", "forge"];
|
||||||
function createDependency(body: any): Dependency {
|
function createDependency(body: any): Dependency {
|
||||||
return new ModConfigDependency({
|
return new ModConfigDependency({
|
||||||
|
ignore: ignoredByDefault.includes(body.modId),
|
||||||
...body,
|
...body,
|
||||||
id: body.modId,
|
id: body.modId,
|
||||||
version: body.versionRange,
|
version: body.versionRange,
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.11.3",
|
"fabricloader": ">=0.11.3",
|
||||||
"fabric": "*",
|
"fabric": ">=0.40.0",
|
||||||
"minecraft": "1.17.x",
|
"minecraft": "1.17.x",
|
||||||
"java": ">=16"
|
"java": ">=16"
|
||||||
},
|
},
|
||||||
|
|
|
@ -33,6 +33,13 @@ license="MIT"
|
||||||
ordering="NONE"
|
ordering="NONE"
|
||||||
side="BOTH"
|
side="BOTH"
|
||||||
|
|
||||||
|
[[dependencies.example-mod]]
|
||||||
|
modId="java"
|
||||||
|
mandatory=true
|
||||||
|
versionRange="[16,)"
|
||||||
|
ordering="NONE"
|
||||||
|
side="BOTH"
|
||||||
|
|
||||||
[[dependencies.example-mod]]
|
[[dependencies.example-mod]]
|
||||||
modId="recommended-mod"
|
modId="recommended-mod"
|
||||||
mandatory=false
|
mandatory=false
|
||||||
|
@ -52,7 +59,7 @@ license="MIT"
|
||||||
modId="included-mod"
|
modId="included-mod"
|
||||||
mandatory=false
|
mandatory=false
|
||||||
embedded=true
|
embedded=true
|
||||||
versionRange="*"
|
versionRange="[0.40.0, )"
|
||||||
ordering="NONE"
|
ordering="NONE"
|
||||||
side="BOTH"
|
side="BOTH"
|
||||||
|
|
||||||
|
|
|
@ -54,14 +54,14 @@ describe("ModMetadataReader.readMetadata", () => {
|
||||||
|
|
||||||
test("dependency info can be read", async () => {
|
test("dependency info can be read", async () => {
|
||||||
const metadata = await ModMetadataReader.readMetadata("example-mod.fabric.jar");
|
const metadata = await ModMetadataReader.readMetadata("example-mod.fabric.jar");
|
||||||
const minecraft = metadata.dependencies.find(x => x.id === "minecraft");
|
const fabric = metadata.dependencies.find(x => x.id === "fabric");
|
||||||
expect(minecraft).toBeTruthy();
|
expect(fabric).toBeTruthy();
|
||||||
expect(minecraft.id).toBe("minecraft");
|
expect(fabric.id).toBe("fabric");
|
||||||
expect(minecraft.kind).toBe(DependencyKind.Depends);
|
expect(fabric.kind).toBe(DependencyKind.Depends);
|
||||||
expect(minecraft.version).toBe("1.17.x");
|
expect(fabric.version).toBe(">=0.40.0");
|
||||||
expect(minecraft.ignore).toBe(false);
|
expect(fabric.ignore).toBe(false);
|
||||||
for (const project of PublisherTarget.getValues()) {
|
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.CurseForge)).toBe("42");
|
||||||
expect(recommended.getProjectSlug(PublisherTarget.GitHub)).toBe("v0.2.0");
|
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", () => {
|
describe("Forge", () => {
|
||||||
|
@ -111,10 +118,11 @@ describe("ModMetadataReader.readMetadata", () => {
|
||||||
|
|
||||||
test("all dependencies are read", async () => {
|
test("all dependencies are read", async () => {
|
||||||
const metadata = await ModMetadataReader.readMetadata("example-mod.forge.jar");
|
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>>{});
|
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["forge"]?.kind).toBe(DependencyKind.Depends);
|
||||||
expect(dependencies["minecraft"]?.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["recommended-mod"]?.kind).toBe(DependencyKind.Recommends);
|
||||||
expect(dependencies["included-mod"]?.kind).toBe(DependencyKind.Includes);
|
expect(dependencies["included-mod"]?.kind).toBe(DependencyKind.Includes);
|
||||||
expect(dependencies["breaking-mod"]?.kind).toBe(DependencyKind.Breaks);
|
expect(dependencies["breaking-mod"]?.kind).toBe(DependencyKind.Breaks);
|
||||||
|
@ -122,14 +130,14 @@ describe("ModMetadataReader.readMetadata", () => {
|
||||||
|
|
||||||
test("dependency info can be read", async () => {
|
test("dependency info can be read", async () => {
|
||||||
const metadata = await ModMetadataReader.readMetadata("example-mod.forge.jar");
|
const metadata = await ModMetadataReader.readMetadata("example-mod.forge.jar");
|
||||||
const minecraft = metadata.dependencies.find(x => x.id === "minecraft");
|
const included = metadata.dependencies.find(x => x.id === "included-mod");
|
||||||
expect(minecraft).toBeTruthy();
|
expect(included).toBeTruthy();
|
||||||
expect(minecraft.id).toBe("minecraft");
|
expect(included.id).toBe("included-mod");
|
||||||
expect(minecraft.kind).toBe(DependencyKind.Depends);
|
expect(included.kind).toBe(DependencyKind.Includes);
|
||||||
expect(minecraft.version).toBe("[1.17, 1.18)");
|
expect(included.version).toBe("[0.40.0, )");
|
||||||
expect(minecraft.ignore).toBe(false);
|
expect(included.ignore).toBe(false);
|
||||||
for (const project of PublisherTarget.getValues()) {
|
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.CurseForge)).toBe("42");
|
||||||
expect(recommended.getProjectSlug(PublisherTarget.GitHub)).toBe("v0.2.0");
|
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", () => {
|
describe("unsupported mod formats", () => {
|
||||||
|
|
Loading…
Reference in a new issue