fix: fix eslint not actually working and fixed every ts/eslint warnings
This commit is contained in:
parent
f7ba1068ad
commit
143a852281
12 changed files with 107 additions and 86 deletions
|
|
@ -9,7 +9,12 @@ export default defineConfig([
|
|||
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
|
||||
plugins: { js },
|
||||
extends: ["js/recommended"],
|
||||
languageOptions: { globals: globals.node },
|
||||
languageOptions: {
|
||||
globals: globals.node,
|
||||
parserOptions: {
|
||||
projectService: true
|
||||
}
|
||||
},
|
||||
},
|
||||
tseslint.configs.recommended,
|
||||
eslintConfigPrettier,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ function fillArguments(
|
|||
classPaths: string,
|
||||
auth: Auth,
|
||||
) {
|
||||
const argumentsToFill = {
|
||||
const argumentsToFill: { [key: string]: string } = {
|
||||
"${natives_directory}": path.join(instancePath, "natives"),
|
||||
"${launcher_name}": "nlk",
|
||||
"${launcher_version}": packageVersion,
|
||||
|
|
@ -127,12 +127,8 @@ export async function generateLaunchArguments(
|
|||
assetsPath: string,
|
||||
versionRoot: string,
|
||||
auth: Auth,
|
||||
options: {
|
||||
minRam?: string;
|
||||
maxRam?: string;
|
||||
customJvmArgs?: string;
|
||||
customGameArgs?: string;
|
||||
},
|
||||
customArgs: { java: string; game: string },
|
||||
ram: { max: string; min: string },
|
||||
) {
|
||||
const jvm: string[] = [];
|
||||
let game: string[] = [];
|
||||
|
|
@ -186,14 +182,14 @@ export async function generateLaunchArguments(
|
|||
jvm.push(classPaths)
|
||||
}
|
||||
|
||||
if (options.customJvmArgs !== "") {
|
||||
for (const arg of options.customJvmArgs.split(" ")) {
|
||||
if (customArgs.java !== "") {
|
||||
for (const arg of customArgs.java.split(" ")) {
|
||||
jvm.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.customGameArgs !== "") {
|
||||
for (const arg of options.customGameArgs.split(" ")) {
|
||||
if (customArgs.game !== "") {
|
||||
for (const arg of customArgs.game.split(" ")) {
|
||||
game.push(arg);
|
||||
}
|
||||
}
|
||||
|
|
@ -202,8 +198,8 @@ export async function generateLaunchArguments(
|
|||
|
||||
let launchArguments = [
|
||||
...jvm,
|
||||
`-Xms${options.minRam || "2G"}`,
|
||||
`-Xmx${options.maxRam || "2G"}`,
|
||||
`-Xms${ram.min}`,
|
||||
`-Xmx${ram.max}`,
|
||||
"-XX:+UnlockExperimentalVMOptions",
|
||||
"-XX:+UseG1GC",
|
||||
"-XX:G1NewSizePercent=20",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { version as packageVersion } from "../../package.json";
|
||||
import { spawn, spawnSync } from "child_process";
|
||||
import { spawn } from "child_process";
|
||||
import { LaunchArguments } from "../utils/types";
|
||||
|
||||
export function launch(
|
||||
|
|
|
|||
|
|
@ -14,12 +14,18 @@ export function mergeManifests(base: Version, layer: Version) {
|
|||
base.libraries.push(lib);
|
||||
}
|
||||
|
||||
for (const arg of layer.arguments.game) {
|
||||
base.arguments.game.push(arg);
|
||||
}
|
||||
if (layer.arguments && base.arguments) {
|
||||
// modern versions
|
||||
for (const arg of layer.arguments.game) {
|
||||
base.arguments.game.push(arg);
|
||||
}
|
||||
|
||||
for (const arg of layer.arguments.jvm) {
|
||||
base.arguments.jvm.push(arg);
|
||||
for (const arg of layer.arguments.jvm) {
|
||||
base.arguments.jvm.push(arg);
|
||||
}
|
||||
} else {
|
||||
// older versions
|
||||
base.minecraftArguments = layer.minecraftArguments
|
||||
}
|
||||
|
||||
return base;
|
||||
|
|
|
|||
|
|
@ -14,22 +14,25 @@ import { installForge } from "../core/modloaders";
|
|||
import { readJson } from "../utils/fs";
|
||||
import { mergeManifests } from "../core/mergeManifests";
|
||||
import { checkJava } from "./java";
|
||||
import { ChildProcessWithoutNullStreams } from "node:child_process";
|
||||
|
||||
export class Instance extends EventEmitter<InstanceEvents> {
|
||||
version: string;
|
||||
version?: string;
|
||||
modloader?: Modloader;
|
||||
auth: Auth;
|
||||
paths: Paths;
|
||||
auth?: Auth;
|
||||
paths?: Paths;
|
||||
args: { java: string; game: string };
|
||||
versionManifest: Version;
|
||||
versionLocation: string;
|
||||
instanceLocation: string;
|
||||
ram: { max: string; min: string };
|
||||
versionManifest?: Version;
|
||||
versionLocation?: string;
|
||||
instanceLocation?: string;
|
||||
ready: boolean;
|
||||
javaExecutable: string;
|
||||
javaExecutable?: string;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.args = { java: "", game: "" };
|
||||
this.ram = { max: "2G", min: "2G" };
|
||||
this.ready = false;
|
||||
}
|
||||
|
||||
|
|
@ -45,9 +48,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
this.javaExecutable = path;
|
||||
}
|
||||
|
||||
setPaths(paths: string);
|
||||
setPaths(paths: Paths);
|
||||
setPaths(paths: Paths | string) {
|
||||
setPaths(paths: Paths | string): void {
|
||||
if (typeof paths === "string") {
|
||||
this.paths = {
|
||||
root: paths,
|
||||
|
|
@ -76,13 +77,18 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
this.args.game = game || "";
|
||||
}
|
||||
|
||||
setRAM({ min, max }: { min?: string; max?: string }) {
|
||||
this.ram.min = min || "2G";
|
||||
this.ram.max = max || "2G";
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
this.versionLocation = path.join(this.paths.versions, this.version);
|
||||
this.instanceLocation = path.join(this.paths.instances, this.version);
|
||||
this.versionLocation = path.join(this.paths.versions!, this.version);
|
||||
this.instanceLocation = path.join(this.paths.instances!, this.version);
|
||||
|
||||
this.versionManifest = await core.version.getVersionManifest(
|
||||
this.version,
|
||||
|
|
@ -95,8 +101,8 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
await this.initialize();
|
||||
this.ready = true;
|
||||
await core.version.downloadJar(
|
||||
this.versionManifest,
|
||||
this.versionLocation,
|
||||
this.versionManifest!,
|
||||
this.versionLocation!,
|
||||
);
|
||||
} catch (original) {
|
||||
const error = new InstallError("installInit", original);
|
||||
|
|
@ -105,8 +111,8 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
|
||||
try {
|
||||
const librariesDownloader = await core.LibrariesDownloader(
|
||||
this.paths.libraries,
|
||||
this.versionManifest,
|
||||
this.paths!.libraries!,
|
||||
this.versionManifest!,
|
||||
);
|
||||
|
||||
librariesDownloader.on("completed", () => {
|
||||
|
|
@ -127,8 +133,8 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
|
||||
try {
|
||||
const assetsDownloader = await core.AssetsDownloader(
|
||||
this.paths.assets,
|
||||
this.versionManifest,
|
||||
this.paths!.assets!,
|
||||
this.versionManifest!,
|
||||
);
|
||||
assetsDownloader.on("completed", () => {
|
||||
this.emit(
|
||||
|
|
@ -148,8 +154,8 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
|
||||
try {
|
||||
const nativesDownloader = await core.NativesDownloader(
|
||||
path.join(this.instanceLocation, "natives"),
|
||||
this.versionManifest,
|
||||
path.join(this.instanceLocation!, "natives"),
|
||||
this.versionManifest!,
|
||||
);
|
||||
nativesDownloader.on("completed", () => {
|
||||
this.emit(
|
||||
|
|
@ -167,7 +173,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
error.throw();
|
||||
}
|
||||
|
||||
const javaError = await checkJava(this.javaExecutable)
|
||||
const javaError = await checkJava(this.javaExecutable!)
|
||||
if (javaError) {
|
||||
const error = new InstallError("java", javaError)
|
||||
error.throw()
|
||||
|
|
@ -179,12 +185,12 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
case "forge":
|
||||
case "neoforge":
|
||||
await installForge(
|
||||
this.version,
|
||||
this.version!,
|
||||
this.modloader,
|
||||
this.javaExecutable,
|
||||
this.paths.root,
|
||||
this.paths.libraries,
|
||||
this.paths.versions,
|
||||
this.javaExecutable!,
|
||||
this.paths!.root,
|
||||
this.paths!.libraries!,
|
||||
this.paths!.versions!,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -197,7 +203,7 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
}
|
||||
}
|
||||
|
||||
async launch() {
|
||||
async launch(): Promise<ChildProcessWithoutNullStreams> {
|
||||
try {
|
||||
if (!this.ready) {
|
||||
try {
|
||||
|
|
@ -212,14 +218,14 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
case "forge": {
|
||||
const forgeVersionManifest = await readJson<Version>(
|
||||
path.join(
|
||||
this.paths.versions,
|
||||
this.paths!.versions!,
|
||||
`${this.version}-${this.modloader.name}-${this.modloader.version}`,
|
||||
`${this.version}-${this.modloader.name}-${this.modloader.version}.json`,
|
||||
),
|
||||
);
|
||||
|
||||
this.versionManifest = mergeManifests(
|
||||
this.versionManifest,
|
||||
this.versionManifest!,
|
||||
forgeVersionManifest,
|
||||
);
|
||||
break;
|
||||
|
|
@ -228,14 +234,14 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
{
|
||||
const neoForgeVersionManifest = await readJson<Version>(
|
||||
path.join(
|
||||
this.paths.versions,
|
||||
this.paths!.versions!,
|
||||
`${this.modloader.name}-${this.modloader.version}`,
|
||||
`${this.modloader.name}-${this.modloader.version}.json`,
|
||||
),
|
||||
);
|
||||
|
||||
this.versionManifest = mergeManifests(
|
||||
this.versionManifest,
|
||||
this.versionManifest!,
|
||||
neoForgeVersionManifest,
|
||||
);
|
||||
}
|
||||
|
|
@ -244,33 +250,34 @@ export class Instance extends EventEmitter<InstanceEvents> {
|
|||
}
|
||||
|
||||
const args = await core.arguments.generateLaunchArguments(
|
||||
this.versionManifest,
|
||||
this.javaExecutable,
|
||||
this.instanceLocation,
|
||||
this.paths.libraries,
|
||||
this.paths.assets,
|
||||
this.versionLocation,
|
||||
this.auth,
|
||||
{ customGameArgs: this.args.game, customJvmArgs: this.args.java },
|
||||
this.versionManifest!,
|
||||
this.javaExecutable!,
|
||||
this.instanceLocation!,
|
||||
this.paths!.libraries!,
|
||||
this.paths!.assets!,
|
||||
this.versionLocation!,
|
||||
this.auth!,
|
||||
this.args,
|
||||
this.ram
|
||||
);
|
||||
|
||||
const process = core.launch(args, this.instanceLocation);
|
||||
const process = core.launch(args, this.instanceLocation!);
|
||||
|
||||
return process;
|
||||
} catch (original) {
|
||||
const error = new LaunchError(
|
||||
{
|
||||
version: this.version,
|
||||
auth: this.auth,
|
||||
paths: this.paths,
|
||||
customGameArgs: this.args.game,
|
||||
customJvmArgs: this.args.java,
|
||||
versionManifest: this.versionManifest,
|
||||
modloader: this.modloader,
|
||||
version: this.version!,
|
||||
auth: this.auth!,
|
||||
paths: this.paths!,
|
||||
customGameArgs: this.args.game!,
|
||||
customJvmArgs: this.args.java!,
|
||||
versionManifest: this.versionManifest!,
|
||||
modloader: this.modloader!,
|
||||
},
|
||||
original,
|
||||
original as Error,
|
||||
);
|
||||
error.throw();
|
||||
throw error.throw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {
|
|||
RuntimeComponent,
|
||||
RuntimeOS,
|
||||
} from "../utils/types";
|
||||
import { ensureDir, exists } from "../utils/fs";
|
||||
import { ensureDir } from "../utils/fs";
|
||||
import { EventEmitter } from "stream";
|
||||
import { exec } from "child_process";
|
||||
import { arch, os } from "../utils/systemInfo";
|
||||
|
|
@ -91,9 +91,9 @@ async function JavaDownloader(
|
|||
const element = javaRuntimeManifest[key];
|
||||
if (element.type === "file") {
|
||||
files.push({
|
||||
url: element.downloads.raw.url,
|
||||
url: element.downloads!.raw.url,
|
||||
path: path.join(componentDestination, key),
|
||||
size: element.downloads.raw.size,
|
||||
size: element.downloads!.raw.size,
|
||||
});
|
||||
} else if (element.type === "directory") {
|
||||
await ensureDir(path.join(componentDestination, key), true);
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ export class InstallError extends Error {
|
|||
step: string;
|
||||
original: Error;
|
||||
moreInfo?: string;
|
||||
constructor(step: string, original: Error, moreInfo?: string) {
|
||||
constructor(step: string, original: unknown, moreInfo?: string) {
|
||||
super();
|
||||
this.step = step;
|
||||
this.original = original;
|
||||
this.original = original as Error;
|
||||
this.moreInfo = moreInfo;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ export async function downloadFile(file: PoolFile, overwrite = true) {
|
|||
await ensureDir(path.dirname(file.path), true);
|
||||
const res = await fetch(file.url);
|
||||
|
||||
if (!res.ok)
|
||||
if (!res.ok || !res.body)
|
||||
throw new Error(
|
||||
`Failed to download ${file.url}: ${res.status} ${res.statusText}`,
|
||||
);
|
||||
await pipeline(res.body, fs.createWriteStream(file.path));
|
||||
} catch (error) {
|
||||
if (error.name !== "AbortError") throw error;
|
||||
if (error instanceof Error && error.name !== "AbortError") throw error;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -33,29 +33,34 @@ export class DownloadPool extends PQueue {
|
|||
doneSize = 0;
|
||||
totalSize = 0;
|
||||
elements: PoolFile[];
|
||||
cleanup: () => Promise<void>;
|
||||
cleanup?: () => Promise<void>;
|
||||
overwrite: boolean;
|
||||
|
||||
constructor(
|
||||
elements: PoolFile[],
|
||||
options: PoolOptions = { pQueueOptions: {}, overwrite: true },
|
||||
) {
|
||||
//@ts-expect-error can't figure out what to put as arguments of PQueueOptions
|
||||
super(options.pQueueOptions);
|
||||
this.elements = elements;
|
||||
this.total = this.elements.length;
|
||||
this.cleanup = options.cleanup;
|
||||
this.overwrite = options.overwrite;
|
||||
if (options.overwrite) {
|
||||
this.overwrite = true
|
||||
} else {
|
||||
this.overwrite = false
|
||||
}
|
||||
}
|
||||
|
||||
async run() {
|
||||
for (const element of this.elements) {
|
||||
this.totalSize += element.size;
|
||||
this.totalSize += element.size!;
|
||||
|
||||
this.add(async () => {
|
||||
await downloadFile(element, this.overwrite);
|
||||
// update status here to ensure that it is run before "completed" events listeners
|
||||
this.done++;
|
||||
this.doneSize += element.size;
|
||||
this.doneSize += element.size!;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -64,4 +69,4 @@ export class DownloadPool extends PQueue {
|
|||
await this.cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ export function isNeeded(element: Library | Argument): boolean {
|
|||
return true;
|
||||
} else return false;
|
||||
} else {
|
||||
if (rule.os.name === os()) {
|
||||
if (rule.os!.name === os()) {
|
||||
return false;
|
||||
} else return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ export type Native = {
|
|||
url: string;
|
||||
};
|
||||
|
||||
type NativeOS = "natives-linux" | "natives-windows" | "natives-macos";
|
||||
type NativeOS = "natives-linux" | "natives-windows" | "natives-macos" | "natives-osx";
|
||||
|
||||
type Rules = {
|
||||
action: "allow" | "disallow";
|
||||
|
|
@ -217,6 +217,7 @@ export type LauncherProfiles = {
|
|||
};
|
||||
|
||||
export type PoolOptions = {
|
||||
//@ts-expect-error can't figure out what to put as arguments of PQueueOptions
|
||||
pQueueOptions: PQueueOptions<null, null>;
|
||||
cleanup?: () => Promise<void>;
|
||||
overwrite?: boolean;
|
||||
|
|
|
|||
|
|
@ -53,13 +53,13 @@ export class DownloadAndUnzipPool extends DownloadPool {
|
|||
|
||||
async run() {
|
||||
for (const element of this.elements) {
|
||||
this.totalSize += element.size;
|
||||
this.totalSize += element.size!;
|
||||
|
||||
this.add(async () => {
|
||||
await this.downloadAndUnzip(element, this.filters, this.unzipMode);
|
||||
// update status here to ensure that it is run before "completed" events listeners
|
||||
this.done++;
|
||||
this.doneSize += element.size;
|
||||
this.doneSize += element.size!;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@
|
|||
"target": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"noEmit": true,
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue