Skip to content

Commit

Permalink
fix(projects): 修复构建后mockjs对xhr的影响问题
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Aug 6, 2022
1 parent 1994262 commit 7757285
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"typecheck": "vue-tsc --noEmit --skipLibCheck",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.json --fix",
"prepare": "husky install",
"postinstall": "patch-package",
"release": "standard-version",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md"
},
Expand Down Expand Up @@ -62,6 +63,7 @@
"@commitlint/config-conventional": "^17.0.3",
"@iconify/json": "^2.1.87",
"@iconify/vue": "^3.2.1",
"@milahu/patch-package": "^6.4.14",
"@types/bmapgl": "^0.0.5",
"@types/crypto-js": "^4.1.1",
"@types/node": "^18.6.3",
Expand Down
26 changes: 26 additions & 0 deletions patches/mockjs+^1.1.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# generated by patch-package 6.4.14
#
# declared package:
# mockjs: ^1.1.0
#
diff --git a/node_modules/mockjs/dist/mock.js b/node_modules/mockjs/dist/mock.js
index 35d5b9a..dcc2fb9 100644
--- a/node_modules/mockjs/dist/mock.js
+++ b/node_modules/mockjs/dist/mock.js
@@ -8310,6 +8310,8 @@ return /******/ (function(modules) { // webpackBootstrap
var xhr = createNativeXMLHttpRequest()
this.custom.xhr = xhr

+ MockXMLHttpRequest.prototype.upload = xhr.upload
+
// 初始化所有事件,用于监听原生 XHR 对象的事件
for (var i = 0; i < XHR_EVENTS.length; i++) {
xhr.addEventListener(XHR_EVENTS[i], handle)
@@ -8360,6 +8362,7 @@ return /******/ (function(modules) { // webpackBootstrap

// 原生 XHR
if (!this.match) {
+ this.custom.xhr.responseType = this.responseType || ''
this.custom.xhr.send(data)
return
}
2 changes: 0 additions & 2 deletions src/typings/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ declare namespace TypeUtil {

type GetFunArgs<F extends Noop> = F extends (...args: infer P) => any ? P : never;

type GetFunReturn<F extends Noop> = F extends (...args: any) => infer R ? R : never;

type Writable<T> = { [K in keyof T]: T[K] };

type FirstOfArray<T extends any[]> = T extends [infer First, ...infer _Rest] ? First : never;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/service/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function handleServiceResult<T = any>(error: Service.RequestError |
export function adapter<T extends Service.ServiceAdapter>(
adapterFun: T,
...args: Service.MultiRequestResult<TypeUtil.GetFunArgs<T>>
): Service.RequestResult<TypeUtil.GetFunReturn<T>> {
): Service.RequestResult<ReturnType<T>> {
let result: Service.RequestResult | undefined;

const hasError = args.some(item => {
Expand Down

0 comments on commit 7757285

Please sign in to comment.