fix: fix eslint not actually working and fixed every ts/eslint warnings

This commit is contained in:
HerozDotExe 2026-03-06 14:54:23 +01:00
parent f7ba1068ad
commit 143a852281
12 changed files with 107 additions and 86 deletions

View file

@ -9,7 +9,12 @@ export default defineConfig([
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
plugins: { js }, plugins: { js },
extends: ["js/recommended"], extends: ["js/recommended"],
languageOptions: { globals: globals.node }, languageOptions: {
globals: globals.node,
parserOptions: {
projectService: true
}
},
}, },
tseslint.configs.recommended, tseslint.configs.recommended,
eslintConfigPrettier, eslintConfigPrettier,

View file

@ -15,7 +15,7 @@ function fillArguments(
classPaths: string, classPaths: string,
auth: Auth, auth: Auth,
) { ) {
const argumentsToFill = { const argumentsToFill: { [key: string]: string } = {
"${natives_directory}": path.join(instancePath, "natives"), "${natives_directory}": path.join(instancePath, "natives"),
"${launcher_name}": "nlk", "${launcher_name}": "nlk",
"${launcher_version}": packageVersion, "${launcher_version}": packageVersion,
@ -127,12 +127,8 @@ export async function generateLaunchArguments(
assetsPath: string, assetsPath: string,
versionRoot: string, versionRoot: string,
auth: Auth, auth: Auth,
options: { customArgs: { java: string; game: string },
minRam?: string; ram: { max: string; min: string },
maxRam?: string;
customJvmArgs?: string;
customGameArgs?: string;
},
) { ) {
const jvm: string[] = []; const jvm: string[] = [];
let game: string[] = []; let game: string[] = [];
@ -186,14 +182,14 @@ export async function generateLaunchArguments(
jvm.push(classPaths) jvm.push(classPaths)
} }
if (options.customJvmArgs !== "") { if (customArgs.java !== "") {
for (const arg of options.customJvmArgs.split(" ")) { for (const arg of customArgs.java.split(" ")) {
jvm.push(arg); jvm.push(arg);
} }
} }
if (options.customGameArgs !== "") { if (customArgs.game !== "") {
for (const arg of options.customGameArgs.split(" ")) { for (const arg of customArgs.game.split(" ")) {
game.push(arg); game.push(arg);
} }
} }
@ -202,8 +198,8 @@ export async function generateLaunchArguments(
let launchArguments = [ let launchArguments = [
...jvm, ...jvm,
`-Xms${options.minRam || "2G"}`, `-Xms${ram.min}`,
`-Xmx${options.maxRam || "2G"}`, `-Xmx${ram.max}`,
"-XX:+UnlockExperimentalVMOptions", "-XX:+UnlockExperimentalVMOptions",
"-XX:+UseG1GC", "-XX:+UseG1GC",
"-XX:G1NewSizePercent=20", "-XX:G1NewSizePercent=20",

View file

@ -1,5 +1,5 @@
import { version as packageVersion } from "../../package.json"; import { version as packageVersion } from "../../package.json";
import { spawn, spawnSync } from "child_process"; import { spawn } from "child_process";
import { LaunchArguments } from "../utils/types"; import { LaunchArguments } from "../utils/types";
export function launch( export function launch(

View file

@ -14,6 +14,8 @@ export function mergeManifests(base: Version, layer: Version) {
base.libraries.push(lib); base.libraries.push(lib);
} }
if (layer.arguments && base.arguments) {
// modern versions
for (const arg of layer.arguments.game) { for (const arg of layer.arguments.game) {
base.arguments.game.push(arg); base.arguments.game.push(arg);
} }
@ -21,6 +23,10 @@ export function mergeManifests(base: Version, layer: Version) {
for (const arg of layer.arguments.jvm) { for (const arg of layer.arguments.jvm) {
base.arguments.jvm.push(arg); base.arguments.jvm.push(arg);
} }
} else {
// older versions
base.minecraftArguments = layer.minecraftArguments
}
return base; return base;
} }

View file

@ -14,22 +14,25 @@ import { installForge } from "../core/modloaders";
import { readJson } from "../utils/fs"; import { readJson } from "../utils/fs";
import { mergeManifests } from "../core/mergeManifests"; import { mergeManifests } from "../core/mergeManifests";
import { checkJava } from "./java"; import { checkJava } from "./java";
import { ChildProcessWithoutNullStreams } from "node:child_process";
export class Instance extends EventEmitter<InstanceEvents> { export class Instance extends EventEmitter<InstanceEvents> {
version: string; version?: string;
modloader?: Modloader; modloader?: Modloader;
auth: Auth; auth?: Auth;
paths: Paths; paths?: Paths;
args: { java: string; game: string }; args: { java: string; game: string };
versionManifest: Version; ram: { max: string; min: string };
versionLocation: string; versionManifest?: Version;
instanceLocation: string; versionLocation?: string;
instanceLocation?: string;
ready: boolean; ready: boolean;
javaExecutable: string; javaExecutable?: string;
constructor() { constructor() {
super(); super();
this.args = { java: "", game: "" }; this.args = { java: "", game: "" };
this.ram = { max: "2G", min: "2G" };
this.ready = false; this.ready = false;
} }
@ -45,9 +48,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
this.javaExecutable = path; this.javaExecutable = path;
} }
setPaths(paths: string); setPaths(paths: Paths | string): void {
setPaths(paths: Paths);
setPaths(paths: Paths | string) {
if (typeof paths === "string") { if (typeof paths === "string") {
this.paths = { this.paths = {
root: paths, root: paths,
@ -76,13 +77,18 @@ export class Instance extends EventEmitter<InstanceEvents> {
this.args.game = game || ""; this.args.game = game || "";
} }
setRAM({ min, max }: { min?: string; max?: string }) {
this.ram.min = min || "2G";
this.ram.max = max || "2G";
}
private async initialize() { private async initialize() {
if (!this.javaExecutable || !this.paths.root || !this.version) { if (!this.javaExecutable || !this.paths?.root || !this.version || !this.auth) {
throw new Error("Missing options") throw new Error("Missing options")
} }
this.versionLocation = path.join(this.paths.versions, this.version); this.versionLocation = path.join(this.paths.versions!, this.version);
this.instanceLocation = path.join(this.paths.instances, this.version); this.instanceLocation = path.join(this.paths.instances!, this.version);
this.versionManifest = await core.version.getVersionManifest( this.versionManifest = await core.version.getVersionManifest(
this.version, this.version,
@ -95,8 +101,8 @@ export class Instance extends EventEmitter<InstanceEvents> {
await this.initialize(); await this.initialize();
this.ready = true; this.ready = true;
await core.version.downloadJar( await core.version.downloadJar(
this.versionManifest, this.versionManifest!,
this.versionLocation, this.versionLocation!,
); );
} catch (original) { } catch (original) {
const error = new InstallError("installInit", original); const error = new InstallError("installInit", original);
@ -105,8 +111,8 @@ export class Instance extends EventEmitter<InstanceEvents> {
try { try {
const librariesDownloader = await core.LibrariesDownloader( const librariesDownloader = await core.LibrariesDownloader(
this.paths.libraries, this.paths!.libraries!,
this.versionManifest, this.versionManifest!,
); );
librariesDownloader.on("completed", () => { librariesDownloader.on("completed", () => {
@ -127,8 +133,8 @@ export class Instance extends EventEmitter<InstanceEvents> {
try { try {
const assetsDownloader = await core.AssetsDownloader( const assetsDownloader = await core.AssetsDownloader(
this.paths.assets, this.paths!.assets!,
this.versionManifest, this.versionManifest!,
); );
assetsDownloader.on("completed", () => { assetsDownloader.on("completed", () => {
this.emit( this.emit(
@ -148,8 +154,8 @@ export class Instance extends EventEmitter<InstanceEvents> {
try { try {
const nativesDownloader = await core.NativesDownloader( const nativesDownloader = await core.NativesDownloader(
path.join(this.instanceLocation, "natives"), path.join(this.instanceLocation!, "natives"),
this.versionManifest, this.versionManifest!,
); );
nativesDownloader.on("completed", () => { nativesDownloader.on("completed", () => {
this.emit( this.emit(
@ -167,7 +173,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
error.throw(); error.throw();
} }
const javaError = await checkJava(this.javaExecutable) const javaError = await checkJava(this.javaExecutable!)
if (javaError) { if (javaError) {
const error = new InstallError("java", javaError) const error = new InstallError("java", javaError)
error.throw() error.throw()
@ -179,12 +185,12 @@ export class Instance extends EventEmitter<InstanceEvents> {
case "forge": case "forge":
case "neoforge": case "neoforge":
await installForge( await installForge(
this.version, this.version!,
this.modloader, this.modloader,
this.javaExecutable, this.javaExecutable!,
this.paths.root, this.paths!.root,
this.paths.libraries, this.paths!.libraries!,
this.paths.versions, this.paths!.versions!,
); );
break; break;
default: default:
@ -197,7 +203,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
} }
} }
async launch() { async launch(): Promise<ChildProcessWithoutNullStreams> {
try { try {
if (!this.ready) { if (!this.ready) {
try { try {
@ -212,14 +218,14 @@ export class Instance extends EventEmitter<InstanceEvents> {
case "forge": { case "forge": {
const forgeVersionManifest = await readJson<Version>( const forgeVersionManifest = await readJson<Version>(
path.join( path.join(
this.paths.versions, this.paths!.versions!,
`${this.version}-${this.modloader.name}-${this.modloader.version}`, `${this.version}-${this.modloader.name}-${this.modloader.version}`,
`${this.version}-${this.modloader.name}-${this.modloader.version}.json`, `${this.version}-${this.modloader.name}-${this.modloader.version}.json`,
), ),
); );
this.versionManifest = mergeManifests( this.versionManifest = mergeManifests(
this.versionManifest, this.versionManifest!,
forgeVersionManifest, forgeVersionManifest,
); );
break; break;
@ -228,14 +234,14 @@ export class Instance extends EventEmitter<InstanceEvents> {
{ {
const neoForgeVersionManifest = await readJson<Version>( const neoForgeVersionManifest = await readJson<Version>(
path.join( path.join(
this.paths.versions, this.paths!.versions!,
`${this.modloader.name}-${this.modloader.version}`, `${this.modloader.name}-${this.modloader.version}`,
`${this.modloader.name}-${this.modloader.version}.json`, `${this.modloader.name}-${this.modloader.version}.json`,
), ),
); );
this.versionManifest = mergeManifests( this.versionManifest = mergeManifests(
this.versionManifest, this.versionManifest!,
neoForgeVersionManifest, neoForgeVersionManifest,
); );
} }
@ -244,33 +250,34 @@ export class Instance extends EventEmitter<InstanceEvents> {
} }
const args = await core.arguments.generateLaunchArguments( const args = await core.arguments.generateLaunchArguments(
this.versionManifest, this.versionManifest!,
this.javaExecutable, this.javaExecutable!,
this.instanceLocation, this.instanceLocation!,
this.paths.libraries, this.paths!.libraries!,
this.paths.assets, this.paths!.assets!,
this.versionLocation, this.versionLocation!,
this.auth, this.auth!,
{ customGameArgs: this.args.game, customJvmArgs: this.args.java }, this.args,
this.ram
); );
const process = core.launch(args, this.instanceLocation); const process = core.launch(args, this.instanceLocation!);
return process; return process;
} catch (original) { } catch (original) {
const error = new LaunchError( const error = new LaunchError(
{ {
version: this.version, version: this.version!,
auth: this.auth, auth: this.auth!,
paths: this.paths, paths: this.paths!,
customGameArgs: this.args.game, customGameArgs: this.args.game!,
customJvmArgs: this.args.java, customJvmArgs: this.args.java!,
versionManifest: this.versionManifest, versionManifest: this.versionManifest!,
modloader: this.modloader, modloader: this.modloader!,
}, },
original, original as Error,
); );
error.throw(); throw error.throw();
} }
} }
} }

View file

@ -9,7 +9,7 @@ import {
RuntimeComponent, RuntimeComponent,
RuntimeOS, RuntimeOS,
} from "../utils/types"; } from "../utils/types";
import { ensureDir, exists } from "../utils/fs"; import { ensureDir } from "../utils/fs";
import { EventEmitter } from "stream"; import { EventEmitter } from "stream";
import { exec } from "child_process"; import { exec } from "child_process";
import { arch, os } from "../utils/systemInfo"; import { arch, os } from "../utils/systemInfo";
@ -91,9 +91,9 @@ async function JavaDownloader(
const element = javaRuntimeManifest[key]; const element = javaRuntimeManifest[key];
if (element.type === "file") { if (element.type === "file") {
files.push({ files.push({
url: element.downloads.raw.url, url: element.downloads!.raw.url,
path: path.join(componentDestination, key), path: path.join(componentDestination, key),
size: element.downloads.raw.size, size: element.downloads!.raw.size,
}); });
} else if (element.type === "directory") { } else if (element.type === "directory") {
await ensureDir(path.join(componentDestination, key), true); await ensureDir(path.join(componentDestination, key), true);

View file

@ -5,10 +5,10 @@ export class InstallError extends Error {
step: string; step: string;
original: Error; original: Error;
moreInfo?: string; moreInfo?: string;
constructor(step: string, original: Error, moreInfo?: string) { constructor(step: string, original: unknown, moreInfo?: string) {
super(); super();
this.step = step; this.step = step;
this.original = original; this.original = original as Error;
this.moreInfo = moreInfo; this.moreInfo = moreInfo;
} }

View file

@ -15,13 +15,13 @@ export async function downloadFile(file: PoolFile, overwrite = true) {
await ensureDir(path.dirname(file.path), true); await ensureDir(path.dirname(file.path), true);
const res = await fetch(file.url); const res = await fetch(file.url);
if (!res.ok) if (!res.ok || !res.body)
throw new Error( throw new Error(
`Failed to download ${file.url}: ${res.status} ${res.statusText}`, `Failed to download ${file.url}: ${res.status} ${res.statusText}`,
); );
await pipeline(res.body, fs.createWriteStream(file.path)); await pipeline(res.body, fs.createWriteStream(file.path));
} catch (error) { } catch (error) {
if (error.name !== "AbortError") throw error; if (error instanceof Error && error.name !== "AbortError") throw error;
return; return;
} }
} }
@ -33,29 +33,34 @@ export class DownloadPool extends PQueue {
doneSize = 0; doneSize = 0;
totalSize = 0; totalSize = 0;
elements: PoolFile[]; elements: PoolFile[];
cleanup: () => Promise<void>; cleanup?: () => Promise<void>;
overwrite: boolean; overwrite: boolean;
constructor( constructor(
elements: PoolFile[], elements: PoolFile[],
options: PoolOptions = { pQueueOptions: {}, overwrite: true }, options: PoolOptions = { pQueueOptions: {}, overwrite: true },
) { ) {
//@ts-expect-error can't figure out what to put as arguments of PQueueOptions
super(options.pQueueOptions); super(options.pQueueOptions);
this.elements = elements; this.elements = elements;
this.total = this.elements.length; this.total = this.elements.length;
this.cleanup = options.cleanup; this.cleanup = options.cleanup;
this.overwrite = options.overwrite; if (options.overwrite) {
this.overwrite = true
} else {
this.overwrite = false
}
} }
async run() { async run() {
for (const element of this.elements) { for (const element of this.elements) {
this.totalSize += element.size; this.totalSize += element.size!;
this.add(async () => { this.add(async () => {
await downloadFile(element, this.overwrite); await downloadFile(element, this.overwrite);
// update status here to ensure that it is run before "completed" events listeners // update status here to ensure that it is run before "completed" events listeners
this.done++; this.done++;
this.doneSize += element.size; this.doneSize += element.size!;
}); });
} }

View file

@ -33,7 +33,7 @@ export function isNeeded(element: Library | Argument): boolean {
return true; return true;
} else return false; } else return false;
} else { } else {
if (rule.os.name === os()) { if (rule.os!.name === os()) {
return false; return false;
} else return true; } else return true;
} }

View file

@ -83,7 +83,7 @@ export type Native = {
url: string; url: string;
}; };
type NativeOS = "natives-linux" | "natives-windows" | "natives-macos"; type NativeOS = "natives-linux" | "natives-windows" | "natives-macos" | "natives-osx";
type Rules = { type Rules = {
action: "allow" | "disallow"; action: "allow" | "disallow";
@ -217,6 +217,7 @@ export type LauncherProfiles = {
}; };
export type PoolOptions = { export type PoolOptions = {
//@ts-expect-error can't figure out what to put as arguments of PQueueOptions
pQueueOptions: PQueueOptions<null, null>; pQueueOptions: PQueueOptions<null, null>;
cleanup?: () => Promise<void>; cleanup?: () => Promise<void>;
overwrite?: boolean; overwrite?: boolean;

View file

@ -53,13 +53,13 @@ export class DownloadAndUnzipPool extends DownloadPool {
async run() { async run() {
for (const element of this.elements) { for (const element of this.elements) {
this.totalSize += element.size; this.totalSize += element.size!;
this.add(async () => { this.add(async () => {
await this.downloadAndUnzip(element, this.filters, this.unzipMode); await this.downloadAndUnzip(element, this.filters, this.unzipMode);
// update status here to ensure that it is run before "completed" events listeners // update status here to ensure that it is run before "completed" events listeners
this.done++; this.done++;
this.doneSize += element.size; this.doneSize += element.size!;
}); });
} }

View file

@ -5,5 +5,6 @@
"target": "esnext", "target": "esnext",
"moduleResolution": "bundler", "moduleResolution": "bundler",
"noEmit": true, "noEmit": true,
"strict": true
} }
} }