From 5ad054631cacf1e45af8e936192edd820b937fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Tue, 9 May 2023 01:22:00 +0100 Subject: [PATCH] refactor: use `~` as import alias --- package.json | 1 + pnpm-lock.yaml | 14 +++++++++++--- src/decrypt-worker/client.ts | 4 ++-- src/decrypt-worker/worker.ts | 2 +- src/features/file-listing/fileListingSlice.ts | 4 ++-- tsconfig.json | 7 ++++++- vite.config.ts | 12 +++++++++--- 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 0851e76..6659ecf 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "react-redux": "^8.0.5" }, "devDependencies": { + "@types/node": "^20.1.1", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", "@typescript-eslint/eslint-plugin": "^5.57.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d553209..a7283e5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,6 +33,9 @@ dependencies: version: 8.0.5(@types/react-dom@18.0.11)(@types/react@18.0.28)(react-dom@18.2.0)(react@18.2.0)(redux@4.2.1) devDependencies: + '@types/node': + specifier: ^20.1.1 + version: 20.1.1 '@types/react': specifier: ^18.0.28 version: 18.0.28 @@ -65,7 +68,7 @@ devDependencies: version: 5.0.2 vite: specifier: ^4.3.2 - version: 4.3.2 + version: 4.3.2(@types/node@20.1.1) packages: @@ -1867,6 +1870,10 @@ packages: resolution: {integrity: sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==} dev: false + /@types/node@20.1.1: + resolution: {integrity: sha512-uKBEevTNb+l6/aCQaKVnUModfEMjAl98lw2Si9P5y4hLu9tm6AlX2ZIoXZX6Wh9lJueYPrGPKk5WMCNHg/u6/A==} + dev: true + /@types/parse-json@4.0.0: resolution: {integrity: sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==} dev: false @@ -2037,7 +2044,7 @@ packages: '@babel/plugin-transform-react-jsx-self': 7.21.0(@babel/core@7.21.8) '@babel/plugin-transform-react-jsx-source': 7.19.6(@babel/core@7.21.8) react-refresh: 0.14.0 - vite: 4.3.2 + vite: 4.3.2(@types/node@20.1.1) transitivePeerDependencies: - supports-color dev: true @@ -3388,7 +3395,7 @@ packages: react: 18.2.0 dev: false - /vite@4.3.2: + /vite@4.3.2(@types/node@20.1.1): resolution: {integrity: sha512-9R53Mf+TBoXCYejcL+qFbZde+eZveQLDYd9XgULILLC1a5ZwPaqgmdVpL8/uvw2BM/1TzetWjglwm+3RO+xTyw==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -3413,6 +3420,7 @@ packages: terser: optional: true dependencies: + '@types/node': 20.1.1 esbuild: 0.17.18 postcss: 8.4.23 rollup: 3.21.5 diff --git a/src/decrypt-worker/client.ts b/src/decrypt-worker/client.ts index a81f2b2..514412a 100644 --- a/src/decrypt-worker/client.ts +++ b/src/decrypt-worker/client.ts @@ -1,5 +1,5 @@ -import { ConcurrentQueue } from '../util/ConcurrentQueue'; -import { WorkerClientBus } from '../util/WorkerEventBus'; +import { ConcurrentQueue } from '~/util/ConcurrentQueue'; +import { WorkerClientBus } from '~/util/WorkerEventBus'; import { DECRYPTION_WORKER_ACTION_NAME } from './constants'; // TODO: Worker pool? diff --git a/src/decrypt-worker/worker.ts b/src/decrypt-worker/worker.ts index 629973e..932e38a 100644 --- a/src/decrypt-worker/worker.ts +++ b/src/decrypt-worker/worker.ts @@ -1,4 +1,4 @@ -import { WorkerServerBus } from '../util/WorkerEventBus'; +import { WorkerServerBus } from '~/util/WorkerEventBus'; import { DECRYPTION_WORKER_ACTION_NAME } from './constants'; const bus = new WorkerServerBus(); diff --git a/src/features/file-listing/fileListingSlice.ts b/src/features/file-listing/fileListingSlice.ts index 1118182..88b6a16 100644 --- a/src/features/file-listing/fileListingSlice.ts +++ b/src/features/file-listing/fileListingSlice.ts @@ -1,7 +1,7 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; import type { PayloadAction } from '@reduxjs/toolkit'; -import type { RootState } from '../../store'; -import { decryptionQueue } from '../../decrypt-worker/client'; +import type { RootState } from '~/store'; +import { decryptionQueue } from '~/decrypt-worker/client'; export enum ProcessState { UNTOUCHED = 'UNTOUCHED', diff --git a/tsconfig.json b/tsconfig.json index c81ef9f..30ecbe6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,12 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + + "baseUrl": ".", + "paths": { + "~/*": ["src/*"] + } }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] diff --git a/vite.config.ts b/vite.config.ts index 5a33944..a4d8ef7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,13 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' +import path from 'path'; +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], -}) + resolve: { + alias: { + '~': path.resolve(__dirname, 'src'), + }, + }, +});