From f83fc24d131a2377235323225d1b8e850ae26e99 Mon Sep 17 00:00:00 2001 From: Ryan Walters Date: Thu, 21 Aug 2025 22:00:24 -0500 Subject: [PATCH] refactor: simplify tsconfig with @tsconfig/bases for vite react, move 'features' into 'components' --- package.json | 1 + pnpm-lock.yaml | 8 ++++++ src/App.tsx | 8 +++--- .../drop => components}/drop-overlay.tsx | 6 ++--- src/{features/graph => components}/graph.tsx | 4 +-- tsconfig.json | 27 +++++-------------- vite.config.ts | 6 +++++ 7 files changed, 30 insertions(+), 30 deletions(-) rename src/{features/drop => components}/drop-overlay.tsx (98%) rename src/{features/graph => components}/graph.tsx (93%) diff --git a/package.json b/package.json index b96b0a9..a7f31e1 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ }, "devDependencies": { "@tauri-apps/cli": "^2", + "@tsconfig/vite-react": "^7.0.0", "@types/react": "^18.3.1", "@types/react-dom": "^18.3.1", "@vitejs/plugin-react": "^4.3.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cb0a528..1094ee7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,6 +42,9 @@ importers: '@tauri-apps/cli': specifier: ^2 version: 2.6.2 + '@tsconfig/vite-react': + specifier: ^7.0.0 + version: 7.0.0 '@types/react': specifier: ^18.3.1 version: 18.3.23 @@ -679,6 +682,9 @@ packages: '@tauri-apps/plugin-opener@2.4.0': resolution: {integrity: sha512-43VyN8JJtvKWJY72WI/KNZszTpDpzHULFxQs0CJBIYUdCRowQ6Q1feWTDb979N7nldqSuDOaBupZ6wz2nvuWwQ==} + '@tsconfig/vite-react@7.0.0': + resolution: {integrity: sha512-fiuTviENxttMlo8BHuVWgPe/DRwcuU722oVvQ/HLfI3pxXfX4uBjvj9tHm1fbj5+iYbcPmdGENXOUks6yKF2Ug==} + '@types/babel__core@7.20.5': resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} @@ -1863,6 +1869,8 @@ snapshots: dependencies: '@tauri-apps/api': 2.6.0 + '@tsconfig/vite-react@7.0.0': {} + '@types/babel__core@7.20.5': dependencies: '@babel/parser': 7.28.0 diff --git a/src/App.tsx b/src/App.tsx index 3600b36..8af324e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,7 @@ -import { useDragDropPaths } from "./hooks/useDragDropPaths.js"; -import Graph from "./features/graph/graph.js"; -import DropOverlay from "./features/drop/drop-overlay.js"; -import type { Frame } from "./types/graph.js"; +import { useDragDropPaths } from "./hooks/useDragDropPaths"; +import Graph from "./components/graph"; +import DropOverlay from "./components/drop-overlay"; +import type { Frame } from "./types/graph"; function App() { const data: Frame[] = []; diff --git a/src/features/drop/drop-overlay.tsx b/src/components/drop-overlay.tsx similarity index 98% rename from src/features/drop/drop-overlay.tsx rename to src/components/drop-overlay.tsx index 648a6eb..a0b36d6 100644 --- a/src/features/drop/drop-overlay.tsx +++ b/src/components/drop-overlay.tsx @@ -1,4 +1,4 @@ -import { ReactNode, useEffect, useRef, useState } from "react"; +import { type ReactNode, useEffect, useRef, useState } from "react"; import { match, P } from "ts-pattern"; import { CheckCircle, @@ -10,8 +10,8 @@ import { Music, XCircle, } from "lucide-react"; -import { commands } from "../../bindings"; -import type { MediaType, StreamDetail } from "../../bindings"; +import { commands } from "../bindings"; +import type { MediaType, StreamDetail } from "../bindings"; type DropOverlayProps = { paths: string[]; diff --git a/src/features/graph/graph.tsx b/src/components/graph.tsx similarity index 93% rename from src/features/graph/graph.tsx rename to src/components/graph.tsx index 1fe4edd..619dfa5 100644 --- a/src/features/graph/graph.tsx +++ b/src/components/graph.tsx @@ -1,6 +1,6 @@ import { ResponsiveLine } from "@nivo/line"; -import { formatBytes } from "../../lib/format.js"; -import type { Frame } from "../../types/graph.js"; +import { formatBytes } from "@/lib/format"; +import type { Frame } from "@/types/graph"; type GraphProps = { data: Frame[]; diff --git a/tsconfig.json b/tsconfig.json index aca4895..6b982af 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,25 +1,10 @@ { + "extends": "@tsconfig/vite-react/tsconfig.json", "compilerOptions": { - "target": "ES2020", - "useDefineForClassFields": true, - "lib": ["ES2020", "DOM", "DOM.Iterable"], - "module": "ESNext", - "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx", - - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + /* Paths */ + "paths": { + "@/*": ["./src/*"] + } }, - "include": ["src"], - "references": [{ "path": "./tsconfig.node.json" }] + "include": ["src"] } diff --git a/vite.config.ts b/vite.config.ts index c7bfc9b..ec61a78 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,7 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import tailwindcss from "@tailwindcss/vite"; +import path from "path"; // @ts-expect-error process is a nodejs global const host = process.env.TAURI_DEV_HOST; @@ -8,6 +9,11 @@ const host = process.env.TAURI_DEV_HOST; // https://vite.dev/config/ export default defineConfig(async () => ({ plugins: [react(), tailwindcss()], + resolve: { + alias: { + "@": path.resolve(__dirname, "src"), + }, + }, // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` //