All: infra update

This commit is contained in:
Dreamacro 2021-11-03 22:51:55 +08:00
parent 614a20b684
commit 19554b1ab8
18 changed files with 825 additions and 1285 deletions

View File

@ -1,6 +1,7 @@
extends: extends:
- standard-with-typescript - standard-with-typescript
- react-app - airbnb/hooks
- plugin:@typescript-eslint/recommended
parser: '@typescript-eslint/parser' parser: '@typescript-eslint/parser'
parserOptions: parserOptions:
project: './tsconfig.json' project: './tsconfig.json'
@ -26,4 +27,3 @@ rules:
'@typescript-eslint/promise-function-async': off '@typescript-eslint/promise-function-async': off
'@typescript-eslint/no-floating-promises': off '@typescript-eslint/no-floating-promises': off
'@typescript-eslint/no-invalid-void-type': off '@typescript-eslint/no-invalid-void-type': off
'@typescript-eslint/no-misused-promises': off

View File

@ -42,13 +42,13 @@ defaults delete com.west2online.ClashX webviewUrl
This command will start Clash Dashboard at `http://localhost:8080/` This command will start Clash Dashboard at `http://localhost:8080/`
```bash ```bash
yarn start $ pnpm start
``` ```
### Build for production ### Build for production
```bash ```bash
yarn build $ pnpm build
``` ```
## Contributors ## Contributors

View File

@ -19,53 +19,51 @@
"scripts": { "scripts": {
"start": "vite", "start": "vite",
"build": "vite build", "build": "vite build",
"lint": "yarn lint:ts", "lint": "pnpm lint:ts",
"lint:ts": "eslint --ext=jsx,ts,tsx --fix src", "lint:ts": "eslint --ext=jsx,ts,tsx --fix src",
"contributors:add": "all-contributors add", "contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate" "contributors:generate": "all-contributors generate"
}, },
"devDependencies": { "devDependencies": {
"@babel/eslint-parser": "^7.15.7", "@babel/eslint-parser": "^7.16.0",
"@types/lodash-es": "^4.17.5", "@types/lodash-es": "^4.17.5",
"@types/node": "^16.10.2", "@types/node": "^16.11.6",
"@types/react": "^17.0.26", "@types/react": "^17.0.34",
"@types/react-dom": "^17.0.9", "@types/react-dom": "^17.0.11",
"@types/react-router-dom": "^5.3.0", "@types/react-router-dom": "^5.3.2",
"@types/react-table": "^7.7.5", "@types/react-table": "^7.7.7",
"@types/react-virtualized-auto-sizer": "^1.0.1", "@types/react-virtualized-auto-sizer": "^1.0.1",
"@types/react-window": "^1.8.5", "@types/react-window": "^1.8.5",
"@typescript-eslint/eslint-plugin": "^4.32.0", "@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^4.32.0", "@typescript-eslint/parser": "^5.3.0",
"@vitejs/plugin-react": "^1.0.1", "@vitejs/plugin-react": "^1.0.7",
"eslint": "^7.32.0", "eslint": "^8.1.0",
"eslint-config-react-app": "^6.0.0", "eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-typescript": "^14.0.1",
"eslint-config-standard-with-typescript": "^21.0.1", "eslint-config-standard-with-typescript": "^21.0.1",
"eslint-import-resolver-typescript": "^2.5.0", "eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-flowtype": "^6.1.0", "eslint-plugin-import": "^2.25.2",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0", "eslint-plugin-promise": "^5.1.1",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-react-hooks": "^4.2.0", "eslint-plugin-react-hooks": "^4.2.0",
"sass": "^1.42.1", "sass": "^1.43.4",
"type-fest": "^2.3.4", "type-fest": "^2.5.2",
"typescript": "^4.4.3", "typescript": "^4.4.4",
"vite": "^2.6.2", "vite": "^2.6.13",
"vite-plugin-pwa": "^0.11.2", "vite-plugin-pwa": "^0.11.3",
"vite-plugin-windicss": "^1.4.8", "vite-plugin-windicss": "^1.4.12",
"vite-tsconfig-paths": "^3.3.14", "vite-tsconfig-paths": "^3.3.17",
"windicss": "^3.1.8" "windicss": "^3.2.1"
}, },
"dependencies": { "dependencies": {
"axios": "^0.22.0", "axios": "^0.24.0",
"classnames": "^2.3.1", "classnames": "^2.3.1",
"dayjs": "^1.10.7", "dayjs": "^1.10.7",
"eventemitter3": "^4.0.7", "eventemitter3": "^4.0.7",
"immer": "^9.0.6", "immer": "^9.0.6",
"jotai": "^1.3.6", "jotai": "^1.4.2",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"neverthrow": "^4.2.2", "neverthrow": "^4.3.0",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-router-dom": "^5.3.0", "react-router-dom": "^5.3.0",

2004
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +0,0 @@
declare module '*.png'
declare module '*.svg'

View File

@ -79,7 +79,7 @@ export function Select (props: SelectProps) {
}, [value, children]) }, [value, children])
const hookedChildren = useMemo(() => { const hookedChildren = useMemo(() => {
return Children.map(children ?? [], (child: React.ReactElement<any>) => { return Children.map(children ?? [], child => {
if (!child.props || !child.type) { if (!child.props || !child.type) {
return child return child
} }

View File

@ -27,28 +27,28 @@ enum Columns {
Upload = 'upload', Upload = 'upload',
Download = 'download', Download = 'download',
SourceIP = 'sourceIP', SourceIP = 'sourceIP',
Time = 'time' Time = 'time',
} }
const shouldCenter = new Set<string>([Columns.Network, Columns.Type, Columns.Rule, Columns.Speed, Columns.Upload, Columns.Download, Columns.SourceIP, Columns.Time]) const shouldCenter = new Set<string>([Columns.Network, Columns.Type, Columns.Rule, Columns.Speed, Columns.Upload, Columns.Download, Columns.SourceIP, Columns.Time])
interface TableColumn<D extends object = {}> extends interface TableColumn<D extends object> extends
ColumnInstance<D>, ColumnInstance<D>,
UseSortByColumnProps<D>, UseSortByColumnProps<D>,
UseResizeColumnsColumnProps<D> {} UseResizeColumnsColumnProps<D> {}
type TableColumnOption<D extends object = {}> = type TableColumnOption<D extends object> =
Column<D> & Column<D> &
UseResizeColumnsOptions<D> & UseResizeColumnsOptions<D> &
UseFiltersColumnOptions<D> & UseFiltersColumnOptions<D> &
UseSortByColumnOptions<D> UseSortByColumnOptions<D>
interface ITableOptions<D extends object = {}> extends interface ITableOptions<D extends object> extends
TableOptions<D>, TableOptions<D>,
UseSortByOptions<D>, UseSortByOptions<D>,
UseFiltersOptions<D> {} UseFiltersOptions<D> {}
interface ITableInstance<D extends object = {}> extends interface ITableInstance<D extends object> extends
TableInstance<D>, TableInstance<D>,
UseFiltersInstanceProps<D> {} UseFiltersInstanceProps<D> {}

View File

@ -26,6 +26,7 @@ export interface FormatConnection {
class Store { class Store {
protected connections = new Map<string, Connection>() protected connections = new Map<string, Connection>()
protected saveDisconnection = false protected saveDisconnection = false
appendToSet (connections: API.Connections[]) { appendToSet (connections: API.Connections[]) {

View File

@ -12,7 +12,7 @@ import './style.scss'
enum sortType { enum sortType {
None, None,
Asc, Asc,
Desc Desc,
} }
const sortMap = { const sortMap = {

View File

@ -1,7 +1,7 @@
import EventEmitter from 'eventemitter3' import EventEmitter from 'eventemitter3'
export enum Action { export enum Action {
SPEED_NOTIFY = 'speed-notify' SPEED_NOTIFY = 'speed-notify',
} }
class Event { class Event {

View File

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-empty-function
export function noop () {} export function noop () {}
export function partition<T> (arr: T[], fn: (arg: T) => boolean): [T[], T[]] { export function partition<T> (arr: T[], fn: (arg: T) => boolean): [T[], T[]] {

View File

@ -12,7 +12,7 @@ export function useObject<T extends Record<string, unknown>> (initialValue: T) {
function set (data: Partial<T>): void function set (data: Partial<T>): void
function set (f: (draft: Draft<T>) => void | T): void function set (f: (draft: Draft<T>) => void | T): void
function set<K extends keyof Draft<T>> (key: K, value: Draft<T>[K]): void function set<K extends keyof Draft<T>> (key: K, value: Draft<T>[K]): void
function set<K extends keyof Draft<T>> (data: any, value?: Draft<T>[K]): void { function set<K extends keyof Draft<T>> (data: unknown, value?: Draft<T>[K]): void {
if (typeof data === 'string') { if (typeof data === 'string') {
rawSet(draft => { rawSet(draft => {
const key = data as K const key = data as K
@ -20,7 +20,7 @@ export function useObject<T extends Record<string, unknown>> (initialValue: T) {
draft[key] = v! draft[key] = v!
}) })
} else if (typeof data === 'function') { } else if (typeof data === 'function') {
rawSet(data) rawSet(data as (draft: Draft<T>) => void | T)
} else if (typeof data === 'object') { } else if (typeof data === 'object') {
rawSet((draft: Draft<T>) => { rawSet((draft: Draft<T>) => {
const obj = data as Draft<T> const obj = data as Draft<T>

View File

@ -8,7 +8,7 @@ export function useWarpImmerSetter<T> (setter: (f: WritableDraft<T>) => void) {
function set<K extends keyof Draft<T>> (key: K, value: Draft<T>[K]): void function set<K extends keyof Draft<T>> (key: K, value: Draft<T>[K]): void
function set (data: Partial<T>): void function set (data: Partial<T>): void
function set (f: (draft: Draft<T>) => void | T): void function set (f: (draft: Draft<T>) => void | T): void
function set<K extends keyof Draft<T>> (data: any, value?: Draft<T>[K]): void { function set<K extends keyof Draft<T>> (data: unknown, value?: Draft<T>[K]): void {
if (typeof data === 'string') { if (typeof data === 'string') {
setter((draft: Draft<T>) => { setter((draft: Draft<T>) => {
const key = data as K const key = data as K

View File

@ -20,12 +20,12 @@ export interface JsBridgeAPI {
/** /**
* Register a javascript bridge event handle * Register a javascript bridge event handle
*/ */
registerHandler: (eventName: string, callback?: (data: any, responseCallback: (param: any) => void) => void) => void registerHandler: <D, P>(eventName: string, callback?: (data: D, responseCallback: (param: P) => void) => void) => void
/** /**
* Call a native handle * Call a native handle
*/ */
callHandler: <T>(handleName: string, data?: any, responseCallback?: (responseData: T) => void) => void callHandler: <T, D>(handleName: string, data?: D, responseCallback?: (responseData: T) => void) => void
/** /**
* Who knows * Who knows
@ -115,7 +115,7 @@ export class JsBridge {
setTimeout(() => document.documentElement.removeChild(WVJBIframe), 0) setTimeout(() => document.documentElement.removeChild(WVJBIframe), 0)
} }
public async callHandler<T> (handleName: string, data?: any) { public async callHandler<T, D = unknown> (handleName: string, data?: D) {
return await new Promise<T>((resolve) => { return await new Promise<T>((resolve) => {
this.instance?.callHandler( this.instance?.callHandler(
handleName, handleName,

View File

@ -95,6 +95,7 @@ export interface Connections {
export class Client { export class Client {
private readonly axiosClient: AxiosInstance private readonly axiosClient: AxiosInstance
constructor (url: string, secret?: string) { constructor (url: string, secret?: string) {
this.axiosClient = axios.create({ this.axiosClient = axios.create({
baseURL: url, baseURL: url,

View File

@ -12,8 +12,11 @@ export interface Config {
export class StreamReader<T> { export class StreamReader<T> {
protected EE = new EventEmitter() protected EE = new EventEmitter()
protected config: SetRequired<Config, 'bufferLength' | 'retryInterval'> protected config: SetRequired<Config, 'bufferLength' | 'retryInterval'>
protected innerBuffer: T[] = [] protected innerBuffer: T[] = []
protected isClose = false protected isClose = false
constructor (config: Config) { constructor (config: Config) {

View File

@ -8,15 +8,13 @@ export enum RuleType {
SrcPort = 'SrcPort', SrcPort = 'SrcPort',
DstPort = 'DstPort', DstPort = 'DstPort',
MATCH = 'MATCH', MATCH = 'MATCH',
RuleSet = 'RuleSet' RuleSet = 'RuleSet',
} }
export interface Rule { export interface Rule {
type?: RuleType type?: RuleType
payload?: string payload?: string
proxy?: string // proxy or proxy group name proxy?: string // proxy or proxy group name
} }

View File

@ -6,13 +6,11 @@
], ],
"skipLibCheck": true, "skipLibCheck": true,
"esModuleInterop": true, "esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true, "strict": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"module": "esnext", "module": "esnext",
"moduleResolution": "node", "moduleResolution": "node",
"isolatedModules": true, "types": ["vite/client"],
"noEmit": true,
"jsx": "react-jsx", "jsx": "react-jsx",
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {