Skip to content

Commit 0a532b5

Browse files
authored
Merge pull request #89 from InhiblabCore/dev
chore: run type & use-request type optimized
2 parents 4536358 + 0998a5d commit 0a532b5

26 files changed

+1096
-1077
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v3
1111
- uses: pnpm/action-setup@v2
1212
with:
1313
version: 7.9.5

DEV_DOCUMENT.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,16 @@ pnpm docs:dev
3333

3434
```
3535

36+
or
37+
38+
at `root` dir run
39+
40+
```bash
41+
42+
pnpm docs:dev
43+
44+
```
45+
46+
will implement script to finished `scripts/docs.ts`
47+
3648
If the page startup is blank, you need to refresh the page.

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
"version": "1.0.0",
44
"private": true,
55
"scripts": {
6-
"docs:dev":"cd packages/hooks && npm run initial && npm run docs:dev",
7-
"docs:build":"cd packages/hooks && npm run initial && npm run docs:build",
8-
"docs:build-github":"cd packages/hooks && npm run initial && npm run docs:build-github",
9-
"docs:build-gitee":"cd packages/hooks && npm run initial && npm run docs:build-gitee",
6+
"bootstrap": "tsx scripts/bootstrap.ts",
7+
"docs:dev":"tsx scripts/docs.ts dev",
8+
"docs:build":"tsx scripts/docs.ts build",
9+
"docs:build-github":"tsx scripts/gitPage.ts github",
10+
"docs:build-gitee":"tsx scripts/gitPage.ts gitee",
1011
"clean": " rimraf dist lib es",
11-
"build": "cd packages/hooks && npm run clean && vue-tsc --noEmit && vite build",
12-
"build:types": "cd packages/hooks && vue-tsc --noEmit && vite build --mode fullTypes",
12+
"build": "tsx scripts/build.ts",
1313
"test": "vitest",
1414
"test:ui": "vitest --ui",
1515
"coverage": "vitest run --coverage",
16-
"prepare": "husky install"
16+
"prepare": "husky install",
17+
"build:types": "cd packages/hooks && vue-tsc --noEmit && vite build --mode fullTypes"
1718
},
1819
"devDependencies": {
1920
"@commitlint/cli": "^17.1.2",
@@ -43,6 +44,7 @@
4344
"eslint-config-prettier": "^8.5.0",
4445
"eslint-plugin-prettier": "^4.2.1",
4546
"eslint-plugin-vue": "^9.6.0",
47+
"execa":"^6.1.0",
4648
"husky": "^8.0.1",
4749
"lint-staged": "^13.0.3",
4850
"vue-eslint-parser": "^9.0.3",

packages/hooks/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-hooks-plus",
3-
"version": "1.5.2",
3+
"version": "1.5.3",
44
"description": "Vue hooks library",
55
"files": [
66
"dist",
@@ -21,7 +21,6 @@
2121
"typeScript"
2222
],
2323
"scripts": {
24-
"bootstrap": "tsx scripts/bootstrap.ts",
2524
"initial": "initial-scan .docs",
2625
"docs:dev": "vhp-vitepress dev .docs --host",
2726
"docs:build": "vhp-vitepress build .docs",

packages/hooks/scripts/plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { cyan } from 'kolorist'
12
import { Logger, Plugin } from 'vite'
2-
import { cyan, move } from './utils'
3+
import { move } from './utils'
34

45
export function movePlugin({ from, to }: { from: string; to: string }): Plugin {
56
let logger: Logger

packages/hooks/scripts/utils.ts

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,12 @@
1-
import fs, { existsSync, readdirSync, statSync } from 'fs-extra'
2-
import { resolve } from 'node:path'
3-
import { bgYellow, bgCyan, bgGreen, bgRed, yellow, cyan, green, red } from 'kolorist'
1+
import fs from 'fs-extra'
2+
import { cyan } from 'kolorist'
43
import { Logger } from 'vite'
5-
import { Config } from 'prettier'
64

75
const logPrefix = '[vite-plugin-move]'
86

9-
export const prettierConfig: Config = {
10-
printWidth: 100,
11-
arrowParens: 'avoid',
12-
bracketSpacing: true,
13-
endOfLine: 'lf',
14-
bracketSameLine: false,
15-
quoteProps: 'as-needed',
16-
semi: false,
17-
singleQuote: true,
18-
tabWidth: 2,
19-
trailingComma: 'none',
20-
useTabs: false,
21-
vueIndentScriptAndStyle: false,
22-
overrides: [
23-
{
24-
files: '*.md',
25-
options: {
26-
embeddedLanguageFormatting: 'off',
27-
},
28-
},
29-
],
30-
}
31-
327
export function move(originalUrl: string, targetUrl: string, log: Logger) {
338
fs.move(originalUrl, targetUrl, err => {
349
if (err) return log.error(JSON.stringify(err))
3510
log.info(`\n${cyan(logPrefix)} File successfully moved!!`)
3611
})
3712
}
38-
39-
export const rootDir = resolve(__dirname, '..')
40-
41-
export const hooksDir = resolve(rootDir, 'src')
42-
43-
export const hooks = readdirSync(hooksDir).filter(f => {
44-
const path = resolve(hooksDir, f)
45-
if (!statSync(path).isDirectory()) {
46-
return false
47-
}
48-
49-
return existsSync(`${path}/index.ts`)
50-
})
51-
52-
type LogFn = () => void
53-
54-
export const logger = {
55-
ln: () => console.log(),
56-
withStartLn: (log: LogFn) => {
57-
logger.ln()
58-
log()
59-
},
60-
withEndLn: (log: LogFn) => {
61-
log()
62-
logger.ln()
63-
},
64-
withBothLn: (log: LogFn) => {
65-
logger.ln()
66-
log()
67-
logger.ln()
68-
},
69-
warning: (msg: string) => {
70-
console.warn(`${bgYellow(' WARNING ')} ${yellow(msg)}`)
71-
},
72-
info: (msg: string) => {
73-
console.log(`${bgCyan(' INFO ')} ${cyan(msg)}`)
74-
},
75-
success: (msg: string) => {
76-
console.log(`${bgGreen(' SUCCESS ')} ${green(msg)}`)
77-
},
78-
error: (msg: string) => {
79-
console.error(`${bgRed(' ERROR ')} ${red(msg)}`)
80-
},
81-
warningText: (msg: string) => {
82-
console.warn(`${yellow(msg)}`)
83-
},
84-
infoText: (msg: string) => {
85-
console.log(`${cyan(msg)}`)
86-
},
87-
successText: (msg: string) => {
88-
console.log(`${green(msg)}`)
89-
},
90-
errorText: (msg: string) => {
91-
console.error(`${red(msg)}`)
92-
},
93-
}

packages/hooks/src/useRequest/Fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Ref } from 'vue'
22
import { FetchState, Options, PluginReturn, Service } from './types'
33

4-
export default class Fetch<TData, TParams extends any[] = any> {
4+
export default class Fetch<TData, TParams extends unknown[] = any> {
55
pluginImpls: PluginReturn<TData, TParams>[] | undefined
66

77
count = 0

packages/hooks/src/useRequest/docs/basic/index.en-US.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const {
156156
loading: Ref<boolean>,
157157
data?: Ref<TData>,
158158
error?: Ref<Error>,
159-
params: Ref<TParams || []>,
159+
params: Ref<TParams | []>,
160160
run: (...params: TParams) => void,
161161
runAsync: (...params: TParams) => Promise<TData>,
162162
refresh: () => void,
@@ -168,7 +168,7 @@ const {
168168
{
169169
manual?: boolean,
170170
defaultParams?: TParams,
171-
formatResult?:(response:TData)=>any,
171+
formatResult?:(response:TData)=>unknown,
172172
onBefore?: (params: TParams) => void,
173173
onSuccess?: (data: TData, params: TParams) => void,
174174
onError?: (e: Error, params: TParams) => void,
@@ -184,7 +184,7 @@ const {
184184
| data | Data returned by service | `Ref<TData>` \| `undefined` |
185185
| error | Exception thrown by service | `Ref<Error>` \| `undefined` |
186186
| loading | Is the service being executed | `Ref<boolean>` |
187-
| params | An array of parameters for the service being executed. For example, you triggered `run(1, 2, 3)`, then params is equal to `[1, 2, 3]` | `Ref<TParams>` \| `[]` |
187+
| params | An array of parameters for the service being executed. For example, you triggered `run(1, 2, 3)`, then params is equal to `[1, 2, 3]` | `Ref<TParams | []>` |
188188
| formatResult | Format the request results, which recommend to use `useFormatResult` | `(response: TData) => any` | |
189189
| run | <ul><li> Manually trigger the execution of the service, and the parameters will be passed to the service</li><li>Automatic handling of exceptions, feedback through `onError`</li></ul> | `(...params: TParams) => void` |
190190
| runAsync | The usage is the same as `run`, but it returns a Promise, so you need to handle the exception yourself. | `(...params: TParams) => Promise<TData>` |

packages/hooks/src/useRequest/docs/basic/index.zh-CN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const {
153153
loading: Ref<boolean>,
154154
data?: Ref<TData>,
155155
error?: Ref<Error>,
156-
params: Ref<TParams || []>,
156+
params: Ref<TParams | []>,
157157
run: (...params: TParams) => void,
158158
runAsync: (...params: TParams) => Promise<TData>,
159159
refresh: () => void,
@@ -165,7 +165,7 @@ const {
165165
{
166166
manual?: boolean,
167167
defaultParams?: TParams,
168-
formatResult?:(response:TData)=>any,
168+
formatResult?:(response:TData)=>unknown,
169169
onBefore?: (params: TParams) => void,
170170
onSuccess?: (data: TData, params: TParams) => void,
171171
onError?: (e: Error, params: TParams) => void,
@@ -181,7 +181,7 @@ const {
181181
| data | service 返回的数据 | `Ref<TData>` \| `undefined` |
182182
| error | service 抛出的异常 | `Ref<Error>` \| `undefined` |
183183
| loading | service 是否正在执行 | `Ref<boolean>` |
184-
| params | 当次执行的 service 的参数数组。比如你触发了 `run(1, 2, 3)`,则 params 等于 `[1, 2, 3]` | `Ref<TParams>` \| `[]` |
184+
| params | 当次执行的 service 的参数数组。比如你触发了 `run(1, 2, 3)`,则 params 等于 `[1, 2, 3]` | `Ref<TParams | []>` |
185185
| formatResult | 格式化请求结果,建议使用 `useFormatResult` | `(response: TData) => any` | |
186186
| run | <ul><li> 手动触发 service 执行,参数会传递给 service</li><li>异常自动处理,通过 `onError` 反馈</li></ul> | `(...params: TParams) => void` |
187187
| runAsync |`run` 用法一致,但返回的是 Promise,需要自行处理异常。 | `(...params: TParams) => Promise<TData>` |

packages/hooks/src/useRequest/plugins/useAutoRunPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { isRef, unref, ref, watch } from 'vue'
22
import { FetchState, Plugin } from '../types'
33

44
// support refreshDeps & ready
5-
const useAutoRunPlugin: Plugin<any, any[]> = (
5+
const useAutoRunPlugin: Plugin<unknown, unknown[]> = (
66
fetchInstance,
77
{ manual, ready = true, defaultParams = [], refreshDeps = [], refreshDepsAction },
88
) => {

0 commit comments

Comments
 (0)