mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
Made aliases for special case dependencies like fabric
This commit is contained in:
parent
7e5abb93bd
commit
7a8b3f6b81
4 changed files with 40 additions and 12 deletions
|
@ -11,13 +11,13 @@ interface Dependency {
|
|||
}
|
||||
|
||||
namespace Dependency {
|
||||
export function create({ id, version = "*", kind = DependencyKind.Depends, ignore = false }: { id: string, version?: string, kind?: DependencyKind, ignore?: boolean }): Dependency {
|
||||
export function create({ id, version = "*", kind = DependencyKind.Depends, ignore = false, aliases = null }: { id: string, version?: string, kind?: DependencyKind, ignore?: boolean, aliases?: Map<PublisherTarget, string> }): Dependency {
|
||||
return {
|
||||
id,
|
||||
version: version ?? "*",
|
||||
kind: kind ?? DependencyKind.Depends,
|
||||
ignore: ignore ?? false,
|
||||
getProjectSlug: _ => id
|
||||
getProjectSlug: target => aliases?.has(target) ? aliases.get(target) : id
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import action from "../../../package.json";
|
||||
import ModConfig from "../../metadata/mod-config";
|
||||
import ModConfigDependency from "../../metadata/mod-config-dependency";
|
||||
import Dependency from "../../metadata/dependency";
|
||||
|
@ -5,15 +6,34 @@ import DependencyKind from "../../metadata/dependency-kind";
|
|||
import PublisherTarget from "../../publishing/publisher-target";
|
||||
|
||||
const ignoredByDefault = ["minecraft", "java", "fabricloader"];
|
||||
const aliases = new Map([
|
||||
["fabric", "fabric-api"]
|
||||
]);
|
||||
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, ignore }));
|
||||
const dependencyAliases = aliases.has(id) ? new Map(PublisherTarget.getValues().map(x => [x, aliases.get(id)])) : null;
|
||||
dependencies.push(Dependency.create({ id, kind, version: value, ignore, aliases: dependencyAliases }));
|
||||
} else {
|
||||
dependencies.push(new ModConfigDependency({ ignore, ...<any>value, id, kind }));
|
||||
const dependencyMetadata = { ignore, ...<any>value, id, kind };
|
||||
if (aliases.has(id)) {
|
||||
if (!dependencyMetadata.custom) {
|
||||
dependencyMetadata.custom = {};
|
||||
}
|
||||
if (!dependencyMetadata.custom[action.name]) {
|
||||
dependencyMetadata.custom[action.name] = {};
|
||||
}
|
||||
for (const target of PublisherTarget.getValues()) {
|
||||
const targetName = PublisherTarget.toString(target).toLowerCase();
|
||||
if (typeof dependencyMetadata.custom[action.name][targetName] !== "string") {
|
||||
dependencyMetadata.custom[action.name][targetName] = aliases.get(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
dependencies.push(new ModConfigDependency(dependencyMetadata));
|
||||
}
|
||||
}
|
||||
return dependencies;
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
"suggested-mod": "*"
|
||||
},
|
||||
"conflicts": {
|
||||
"conflicting-mod": "*"
|
||||
"conflicting-mod": "<0.40.0"
|
||||
},
|
||||
"breaks": {
|
||||
"breaking-mod": "*"
|
||||
|
|
|
@ -54,14 +54,14 @@ describe("ModMetadataReader.readMetadata", () => {
|
|||
|
||||
test("dependency info can be read", async () => {
|
||||
const metadata = await ModMetadataReader.readMetadata("example-mod.fabric.jar");
|
||||
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);
|
||||
const conflicting = metadata.dependencies.find(x => x.id === "conflicting-mod");
|
||||
expect(conflicting).toBeTruthy();
|
||||
expect(conflicting.id).toBe("conflicting-mod");
|
||||
expect(conflicting.kind).toBe(DependencyKind.Conflicts);
|
||||
expect(conflicting.version).toBe("<0.40.0");
|
||||
expect(conflicting.ignore).toBe(false);
|
||||
for (const project of PublisherTarget.getValues()) {
|
||||
expect(fabric.getProjectSlug(project)).toBe(fabric.id);
|
||||
expect(conflicting.getProjectSlug(project)).toBe(conflicting.id);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -84,6 +84,14 @@ describe("ModMetadataReader.readMetadata", () => {
|
|||
expect(metadata.dependencies.find(x => x.id === "java").ignore).toBe(true);
|
||||
expect(metadata.dependencies.find(x => x.id === "fabricloader").ignore).toBe(true);
|
||||
});
|
||||
|
||||
test("special case dependencies (fabric) are replaced with their aliases", async() => {
|
||||
const metadata = await ModMetadataReader.readMetadata("example-mod.fabric.jar");
|
||||
const fabric = metadata.dependencies.find(x => x.id === "fabric");
|
||||
for (const target of PublisherTarget.getValues()) {
|
||||
expect(fabric.getProjectSlug(target) === "fabric-api");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Forge", () => {
|
||||
|
|
Loading…
Reference in a new issue