mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-26 02:11:04 -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 {
|
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 {
|
return {
|
||||||
id,
|
id,
|
||||||
version: version ?? "*",
|
version: version ?? "*",
|
||||||
kind: kind ?? DependencyKind.Depends,
|
kind: kind ?? DependencyKind.Depends,
|
||||||
ignore: ignore ?? false,
|
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 ModConfig from "../../metadata/mod-config";
|
||||||
import ModConfigDependency from "../../metadata/mod-config-dependency";
|
import ModConfigDependency from "../../metadata/mod-config-dependency";
|
||||||
import Dependency from "../../metadata/dependency";
|
import Dependency from "../../metadata/dependency";
|
||||||
|
@ -5,15 +6,34 @@ import DependencyKind from "../../metadata/dependency-kind";
|
||||||
import PublisherTarget from "../../publishing/publisher-target";
|
import PublisherTarget from "../../publishing/publisher-target";
|
||||||
|
|
||||||
const ignoredByDefault = ["minecraft", "java", "fabricloader"];
|
const ignoredByDefault = ["minecraft", "java", "fabricloader"];
|
||||||
|
const aliases = new Map([
|
||||||
|
["fabric", "fabric-api"]
|
||||||
|
]);
|
||||||
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);
|
const ignore = ignoredByDefault.includes(id);
|
||||||
if (typeof value === "string") {
|
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 {
|
} 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;
|
return dependencies;
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
"suggested-mod": "*"
|
"suggested-mod": "*"
|
||||||
},
|
},
|
||||||
"conflicts": {
|
"conflicts": {
|
||||||
"conflicting-mod": "*"
|
"conflicting-mod": "<0.40.0"
|
||||||
},
|
},
|
||||||
"breaks": {
|
"breaks": {
|
||||||
"breaking-mod": "*"
|
"breaking-mod": "*"
|
||||||
|
|
|
@ -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 fabric = metadata.dependencies.find(x => x.id === "fabric");
|
const conflicting = metadata.dependencies.find(x => x.id === "conflicting-mod");
|
||||||
expect(fabric).toBeTruthy();
|
expect(conflicting).toBeTruthy();
|
||||||
expect(fabric.id).toBe("fabric");
|
expect(conflicting.id).toBe("conflicting-mod");
|
||||||
expect(fabric.kind).toBe(DependencyKind.Depends);
|
expect(conflicting.kind).toBe(DependencyKind.Conflicts);
|
||||||
expect(fabric.version).toBe(">=0.40.0");
|
expect(conflicting.version).toBe("<0.40.0");
|
||||||
expect(fabric.ignore).toBe(false);
|
expect(conflicting.ignore).toBe(false);
|
||||||
for (const project of PublisherTarget.getValues()) {
|
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 === "java").ignore).toBe(true);
|
||||||
expect(metadata.dependencies.find(x => x.id === "fabricloader").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", () => {
|
describe("Forge", () => {
|
||||||
|
|
Loading…
Reference in a new issue