Compare commits
No commits in common. "c76087fe173ec270e09a7edb6525bcd6de12d7cf" and "ac1afd3997024ce74eedef43508860bb3f819e2e" have entirely different histories.
c76087fe17
...
ac1afd3997
4 changed files with 41 additions and 95 deletions
14
bun.lock
14
bun.lock
|
@ -4,8 +4,6 @@
|
||||||
"": {
|
"": {
|
||||||
"name": "packwizjs",
|
"name": "packwizjs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/semver": "^7.5.8",
|
|
||||||
"semver": "^7.7.1",
|
|
||||||
"toml": "^3.0.0",
|
"toml": "^3.0.0",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -55,8 +53,6 @@
|
||||||
|
|
||||||
"@types/node": ["@types/node@22.13.1", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew=="],
|
"@types/node": ["@types/node@22.13.1", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew=="],
|
||||||
|
|
||||||
"@types/semver": ["@types/semver@7.5.8", "", {}, "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ=="],
|
|
||||||
|
|
||||||
"@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
|
"@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
|
||||||
|
|
||||||
"acorn": ["acorn@8.14.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="],
|
"acorn": ["acorn@8.14.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="],
|
||||||
|
@ -369,7 +365,7 @@
|
||||||
|
|
||||||
"safe-regex-test": ["safe-regex-test@1.1.0", "", { "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "is-regex": "^1.2.1" } }, "sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw=="],
|
"safe-regex-test": ["safe-regex-test@1.1.0", "", { "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "is-regex": "^1.2.1" } }, "sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw=="],
|
||||||
|
|
||||||
"semver": ["semver@7.7.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA=="],
|
"semver": ["semver@6.3.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
|
||||||
|
|
||||||
"set-function-length": ["set-function-length@1.2.2", "", { "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", "function-bind": "^1.1.2", "get-intrinsic": "^1.2.4", "gopd": "^1.0.1", "has-property-descriptors": "^1.0.2" } }, "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg=="],
|
"set-function-length": ["set-function-length@1.2.2", "", { "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", "function-bind": "^1.1.2", "get-intrinsic": "^1.2.4", "gopd": "^1.0.1", "has-property-descriptors": "^1.0.2" } }, "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg=="],
|
||||||
|
|
||||||
|
@ -447,14 +443,18 @@
|
||||||
|
|
||||||
"@humanfs/node/@humanwhocodes/retry": ["@humanwhocodes/retry@0.3.1", "", {}, "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA=="],
|
"@humanfs/node/@humanwhocodes/retry": ["@humanwhocodes/retry@0.3.1", "", {}, "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA=="],
|
||||||
|
|
||||||
|
"builtins/semver": ["semver@7.7.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA=="],
|
||||||
|
|
||||||
|
"eslint-compat-utils/semver": ["semver@7.7.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA=="],
|
||||||
|
|
||||||
"eslint-import-resolver-node/debug": ["debug@3.2.7", "", { "dependencies": { "ms": "^2.1.1" } }, "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ=="],
|
"eslint-import-resolver-node/debug": ["debug@3.2.7", "", { "dependencies": { "ms": "^2.1.1" } }, "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ=="],
|
||||||
|
|
||||||
"eslint-module-utils/debug": ["debug@3.2.7", "", { "dependencies": { "ms": "^2.1.1" } }, "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ=="],
|
"eslint-module-utils/debug": ["debug@3.2.7", "", { "dependencies": { "ms": "^2.1.1" } }, "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ=="],
|
||||||
|
|
||||||
"eslint-plugin-import/debug": ["debug@3.2.7", "", { "dependencies": { "ms": "^2.1.1" } }, "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ=="],
|
"eslint-plugin-import/debug": ["debug@3.2.7", "", { "dependencies": { "ms": "^2.1.1" } }, "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ=="],
|
||||||
|
|
||||||
"eslint-plugin-import/semver": ["semver@6.3.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
|
|
||||||
|
|
||||||
"eslint-plugin-n/globals": ["globals@13.24.0", "", { "dependencies": { "type-fest": "^0.20.2" } }, "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ=="],
|
"eslint-plugin-n/globals": ["globals@13.24.0", "", { "dependencies": { "type-fest": "^0.20.2" } }, "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ=="],
|
||||||
|
|
||||||
|
"eslint-plugin-n/semver": ["semver@7.7.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA=="],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/semver": "^7.5.8",
|
|
||||||
"semver": "^7.7.1",
|
|
||||||
"toml": "^3.0.0"
|
"toml": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@ export function isValidHashFormat(hashFormat: string): HashFormat {
|
||||||
if (hashFormat in HashFormat) {
|
if (hashFormat in HashFormat) {
|
||||||
return HashFormat[hashFormat as keyof typeof HashFormat];
|
return HashFormat[hashFormat as keyof typeof HashFormat];
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Invalid index file hash format: ${hashFormat}`);
|
throw new Error("Invalid index file hash format!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
118
src/parser.ts
118
src/parser.ts
|
@ -8,7 +8,6 @@ import {
|
||||||
} from "./provider";
|
} from "./provider";
|
||||||
import { HashFormat, isValidHashFormat } from "./enums/hash-format";
|
import { HashFormat, isValidHashFormat } from "./enums/hash-format";
|
||||||
import { isValidSide, type Side } from "./enums/side";
|
import { isValidSide, type Side } from "./enums/side";
|
||||||
import * as semver from "semver";
|
|
||||||
|
|
||||||
export interface Metafile {
|
export interface Metafile {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -113,97 +112,46 @@ export class IndexFileEntry {
|
||||||
*/
|
*/
|
||||||
export interface PackwizIndex {
|
export interface PackwizIndex {
|
||||||
location: Resource;
|
location: Resource;
|
||||||
hash: string;
|
|
||||||
hashFormat: HashFormat;
|
hashFormat: HashFormat;
|
||||||
files: IndexFileEntry[];
|
files: IndexFileEntry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PackwizVersions {
|
// TODO: parse pack.toml too instead of just the index file
|
||||||
minecraft: string;
|
// This is because pack.toml contains important information like modloader versions
|
||||||
fabric?: string;
|
|
||||||
forge?: string;
|
|
||||||
neoforge?: string;
|
|
||||||
quilt?: string;
|
|
||||||
liteloader?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Packwiz {
|
|
||||||
constructor(
|
|
||||||
readonly location: Resource,
|
|
||||||
readonly index: PackwizIndex,
|
|
||||||
readonly name: string,
|
|
||||||
readonly packFormat: string = "packwiz:1.0.0",
|
|
||||||
readonly authors: Array<string>,
|
|
||||||
readonly description: string,
|
|
||||||
readonly version: string,
|
|
||||||
readonly versions: PackwizVersions,
|
|
||||||
) {
|
|
||||||
const packwizJsMaxSupportedVersion = "1.1.0";
|
|
||||||
const packFormatSemver = semver.clean(packFormat.split(":")[1]);
|
|
||||||
if (!packFormat.startsWith("packwiz:")) {
|
|
||||||
throw new Error("Invalid packwiz pack format!");
|
|
||||||
} else if (!packFormatSemver) {
|
|
||||||
throw new Error("Unable to parse pack format!");
|
|
||||||
} else if (semver.gt(packFormatSemver, packwizJsMaxSupportedVersion)) {
|
|
||||||
throw new Error(
|
|
||||||
`Pack format of ${packFormat} is higher than what PackwizJS supports! Please report this upstream at https://www.coastalcommits.com/GalacticFactory/PackwizJS/issues`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a packwiz.toml file and returns its contents.
|
* Parses a Packwiz index file and returns its contents.
|
||||||
*
|
*
|
||||||
* @param indexFilePath - The path of the TOML file.
|
* @param indexFilePath - The path of the TOML file.
|
||||||
* @returns The parsed file as a structured class.
|
* @returns The parsed index as a structured object.
|
||||||
*/
|
*/
|
||||||
export async function parsePackwiz(filePath: string): Promise<Packwiz> {
|
export async function parsePackwizIndex(
|
||||||
const packwizFile = new Resource(filePath);
|
indexFilePath: string,
|
||||||
const parsedPackwizFile = toml.parse(await packwizFile.fetchContents());
|
): Promise<PackwizIndex> {
|
||||||
|
const indexFile = new Resource(indexFilePath);
|
||||||
const indexFile = packwizFile.parent.join(parsedPackwizFile.index.file);
|
const parsed = toml.parse(await indexFile.fetchContents());
|
||||||
const parsedIndexFile = toml.parse(await indexFile.fetchContents());
|
const hashFormat = isValidHashFormat(parsed["hash-format"]);
|
||||||
const indexHashFormat = isValidHashFormat(parsedIndexFile["hash-format"]);
|
return {
|
||||||
|
location: indexFile,
|
||||||
return new Packwiz(
|
hashFormat: hashFormat,
|
||||||
packwizFile,
|
files: parsed.files.map(
|
||||||
{
|
(file: {
|
||||||
location: indexFile,
|
file: string;
|
||||||
hash: parsedPackwizFile.index.hash,
|
hash: string;
|
||||||
hashFormat: indexHashFormat,
|
hashFormat: HashFormat;
|
||||||
files: parsedIndexFile.files.map(
|
alias?: string;
|
||||||
(file: {
|
metafile?: boolean;
|
||||||
file: string;
|
preserve?: boolean;
|
||||||
hash: string;
|
}) => {
|
||||||
hashFormat: HashFormat;
|
return new IndexFileEntry(
|
||||||
alias?: string;
|
indexFile.parent.join(file.file),
|
||||||
metafile?: boolean;
|
file.hash,
|
||||||
preserve?: boolean;
|
file.hashFormat || hashFormat,
|
||||||
}) => {
|
file.alias,
|
||||||
return new IndexFileEntry(
|
file.metafile ?? false,
|
||||||
packwizFile.parent.join(file.file),
|
file.preserve ?? false,
|
||||||
file.hash,
|
);
|
||||||
file.hashFormat ?? indexHashFormat,
|
},
|
||||||
file.alias,
|
),
|
||||||
file.metafile ?? false,
|
};
|
||||||
file.preserve ?? false,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
|
||||||
parsedPackwizFile.name,
|
|
||||||
parsedPackwizFile["pack-format"],
|
|
||||||
parsedPackwizFile.author?.split(",").map((s: string) => s.trim()),
|
|
||||||
parsedPackwizFile.description,
|
|
||||||
parsedPackwizFile.version,
|
|
||||||
{
|
|
||||||
minecraft: parsedPackwizFile.versions.minecraft,
|
|
||||||
fabric: parsedPackwizFile.versions.fabric,
|
|
||||||
forge: parsedPackwizFile.versions.forge,
|
|
||||||
neoforge: parsedPackwizFile.versions.neoforge,
|
|
||||||
quilt: parsedPackwizFile.versions.quilt,
|
|
||||||
liteloader: parsedPackwizFile.versions.liteloader,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue