Skip to content

Commit

Permalink
perf(*): drop typia
Browse files Browse the repository at this point in the history
- Remove unnecessary type checks.
- Replace some checks with faster alternative.
  • Loading branch information
skjsjhb committed Jan 17, 2025
1 parent ef2555a commit 4985560
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 613 deletions.
2 changes: 0 additions & 2 deletions build-tools.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Runs the development build and starts frontend hot-reloading server
import { TsconfigPathsPlugin } from "@esbuild-plugins/tsconfig-paths";
import typiaPlugin from "@ryoppippi/unplugin-typia/esbuild";
import consola from "consola";
import esbuild, { type BuildOptions } from "esbuild";
import fs from "fs-extra";
Expand Down Expand Up @@ -57,7 +56,6 @@ export async function build(variant: BuildVariant) {
"hash-worker": "src/main/security/hash-worker.ts"
},
plugins: [
typiaPlugin({ cache: true, log: false }),
TsconfigPathsPlugin({ tsconfig: "./tsconfig.json" })
],
chunkNames: "[hash]",
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
"dist": "tsx pack.ts",
"test": "vitest --run",
"type-check": "tsc",
"prepare": "pnpm install-typia",
"install-typia": "ts-patch install && typia patch",
"update-compat-table": "tsx scripts/gen-compat-table.ts"
},
"devDependencies": {
"@electron/packager": "^18.3.6",
"@esbuild-plugins/tsconfig-paths": "^0.1.2",
"@ryoppippi/unplugin-typia": "^1.1.0",
"@types/chai-as-promised": "^8.0.1",
"@types/fs-extra": "^11.0.4",
"@types/lzma": "^2.3.0",
Expand Down Expand Up @@ -74,7 +71,6 @@
"react-i18next": "^15.4.0",
"react-use": "^17.6.0",
"superserial": "^0.3.5",
"typia": "^7.5.1",
"uuid": "^11.0.3",
"wouter": "^3.3.5",
"ws": "^8.18.0",
Expand Down
600 changes: 3 additions & 597 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/main/jrt/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import fs from "fs-extra";
import * as child_process from "node:child_process";
import os from "node:os";
import path from "path";
import { is } from "typia";

const JRT_MANIFEST = "https://piston-meta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json";

Expand Down Expand Up @@ -50,12 +49,12 @@ async function getProfile(componentName: string): Promise<JavaRuntimeProfile> {
const d = await (await netx.get(JRT_MANIFEST)).json();
const availableProfiles = d[osPair()][componentName];

if (!is<JavaRuntimeProfile[]>(availableProfiles) || availableProfiles.length < 1) {
if (!Array.isArray(availableProfiles) || availableProfiles.length < 1) {
throw `Could not find available JRT profiles for ${componentName}`;
}

// Gets the latest release
return availableProfiles.reduce((prev, it) => {
return availableProfiles.reduce((prev: JavaRuntimeProfile, it) => {
if (prev.version?.released && it.version?.released) {
const d1 = new Date(prev.version.released);
const d2 = new Date(it.version.released);
Expand Down Expand Up @@ -99,7 +98,6 @@ async function installRuntime(component: string): Promise<void> {

const dat = await (await net.fetch(profile.manifest.url)).json();
let files = Object.entries(dat.files)
.filter(([, file]) => is<FileHint>(file))
.map(([name, file]) => ({ name, ...(file as FileHint) } satisfies NamedFileHint));

if (conf().jrt.filterDocs) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/profile/linker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { patchProfile } from "@/main/profile/profile-adaptor";
import type { VersionProfile } from "@/main/profile/version-profile";
import { mergician } from "mergician";
import { is } from "typia";

/**
* Links the given profiles.
Expand Down Expand Up @@ -37,7 +36,9 @@ export async function linkProfile(id: string, provider: (id: string) => unknown

await patchProfile(obj);

if (is<VersionProfile>(obj)) return obj;
if (obj.inheritsFrom || !("id" in obj)) {
throw `Link unsatisfied: ${id} has no complete inheritance`;
}

throw `Link unsatisfied: ${id} has no complete inheritance`;
return obj as VersionProfile;
}
2 changes: 2 additions & 0 deletions src/main/profile/version-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface VersionProfile {

complianceLevel: number;

inheritsFrom?: string;

downloads: {
/**
* Defines the client download source.
Expand Down
4 changes: 1 addition & 3 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import TypiaPlugin from "@ryoppippi/unplugin-typia/vite";
import tsConfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";

Expand All @@ -10,7 +9,6 @@ export default defineConfig({
]
},
plugins: [
tsConfigPaths(),
TypiaPlugin({ cache: true, log: false })
tsConfigPaths()
]
});

0 comments on commit 4985560

Please sign in to comment.