@umijs/plugins 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access.js +1 -1
- package/dist/dva.js +1 -1
- package/dist/layout.js +5 -3
- package/dist/request.js +21 -12
- package/package.json +4 -4
package/dist/access.js
CHANGED
|
@@ -80,7 +80,7 @@ export function accessProvider(container) {
|
|
|
80
80
|
content: `
|
|
81
81
|
import React, { PropsWithChildren } from 'react';
|
|
82
82
|
import { AccessContext } from './context';
|
|
83
|
-
import type { IRoute } from 'umi';
|
|
83
|
+
import type { IRoute } from '${api.appData.umi.importSource}';
|
|
84
84
|
|
|
85
85
|
export const useAccess = () => {
|
|
86
86
|
return React.useContext(AccessContext);
|
package/dist/dva.js
CHANGED
|
@@ -186,7 +186,7 @@ export { getDvaApp } from './dva';
|
|
|
186
186
|
api.writeTmpFile({
|
|
187
187
|
path: "types.d.ts",
|
|
188
188
|
tpl: `
|
|
189
|
-
import type { History } from 'umi';
|
|
189
|
+
import type { History } from '${api.appData.umi.importSource}';
|
|
190
190
|
|
|
191
191
|
export interface ConnectProps {
|
|
192
192
|
dispatch?: Dispatch;
|
package/dist/layout.js
CHANGED
|
@@ -130,8 +130,10 @@ ${isFlattedDepsDir ? '/// <reference types="antd" />' : ""}
|
|
|
130
130
|
path: "Layout.tsx",
|
|
131
131
|
content: `
|
|
132
132
|
${PKG_TYPE_REFERENCE}
|
|
133
|
-
import {
|
|
134
|
-
|
|
133
|
+
import {
|
|
134
|
+
Link, useLocation, useNavigate, Outlet, useAppData, matchRoutes,
|
|
135
|
+
type IRoute
|
|
136
|
+
} from '${api.appData.umi.importSource}';
|
|
135
137
|
import React, { useMemo } from 'react';
|
|
136
138
|
import {
|
|
137
139
|
ProLayout,
|
|
@@ -694,7 +696,7 @@ export default LogoIcon;
|
|
|
694
696
|
path: "Exception.tsx",
|
|
695
697
|
content: `
|
|
696
698
|
import React from 'react';
|
|
697
|
-
import { history, type IRoute } from 'umi';
|
|
699
|
+
import { history, type IRoute } from '${api.appData.umi.importSource}';
|
|
698
700
|
import { Result, Button } from 'antd';
|
|
699
701
|
|
|
700
702
|
const Exception: React.FC<{
|
package/dist/request.js
CHANGED
|
@@ -160,12 +160,13 @@ type RequestError = AxiosError | Error
|
|
|
160
160
|
interface IErrorHandler {
|
|
161
161
|
(error: RequestError, opts: IRequestOptions): void;
|
|
162
162
|
}
|
|
163
|
-
type
|
|
164
|
-
type
|
|
163
|
+
type WithPromise<T> = T | Promise<T>;
|
|
164
|
+
type IRequestInterceptorAxios = (config: IRequestOptions) => WithPromise<IRequestOptions>;
|
|
165
|
+
type IRequestInterceptorUmiRequest = (url: string, config : IRequestOptions) => WithPromise<{ url: string, options: IRequestOptions }>;
|
|
165
166
|
type IRequestInterceptor = IRequestInterceptorAxios | IRequestInterceptorUmiRequest;
|
|
166
167
|
type IErrorInterceptor = (error: Error) => Promise<Error>;
|
|
167
|
-
type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => AxiosResponse<T
|
|
168
|
-
type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [
|
|
168
|
+
type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => WithPromise<AxiosResponse<T>> ;
|
|
169
|
+
type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [IRequestInterceptor] | IRequestInterceptor
|
|
169
170
|
type IResponseInterceptorTuple = [IResponseInterceptor, IErrorInterceptor] | [IResponseInterceptor] | IResponseInterceptor
|
|
170
171
|
|
|
171
172
|
export interface RequestConfig<T = any> extends AxiosRequestConfig {
|
|
@@ -196,19 +197,19 @@ const getRequestInstance = (): AxiosInstance => {
|
|
|
196
197
|
|
|
197
198
|
config?.requestInterceptors?.forEach((interceptor) => {
|
|
198
199
|
if(interceptor instanceof Array){
|
|
199
|
-
requestInstance.interceptors.request.use((config) => {
|
|
200
|
+
requestInstance.interceptors.request.use(async (config) => {
|
|
200
201
|
const { url } = config;
|
|
201
202
|
if(interceptor[0].length === 2){
|
|
202
|
-
const { url: newUrl, options } = interceptor[0](url, config);
|
|
203
|
+
const { url: newUrl, options } = await interceptor[0](url, config);
|
|
203
204
|
return { ...options, url: newUrl };
|
|
204
205
|
}
|
|
205
206
|
return interceptor[0](config);
|
|
206
207
|
}, interceptor[1]);
|
|
207
208
|
} else {
|
|
208
|
-
requestInstance.interceptors.request.use((config) => {
|
|
209
|
+
requestInstance.interceptors.request.use(async (config) => {
|
|
209
210
|
const { url } = config;
|
|
210
211
|
if(interceptor.length === 2){
|
|
211
|
-
const { url: newUrl, options } = interceptor(url, config);
|
|
212
|
+
const { url: newUrl, options } = await interceptor(url, config);
|
|
212
213
|
return { ...options, url: newUrl };
|
|
213
214
|
}
|
|
214
215
|
return interceptor(config);
|
|
@@ -239,19 +240,19 @@ const request: IRequest = (url: string, opts: any = { method: 'GET' }) => {
|
|
|
239
240
|
const { getResponse = false, requestInterceptors, responseInterceptors } = opts;
|
|
240
241
|
const requestInterceptorsToEject = requestInterceptors?.map((interceptor) => {
|
|
241
242
|
if(interceptor instanceof Array){
|
|
242
|
-
return requestInstance.interceptors.request.use((config) => {
|
|
243
|
+
return requestInstance.interceptors.request.use(async (config) => {
|
|
243
244
|
const { url } = config;
|
|
244
245
|
if(interceptor[0].length === 2){
|
|
245
|
-
const { url: newUrl, options } = interceptor[0](url, config);
|
|
246
|
+
const { url: newUrl, options } = await interceptor[0](url, config);
|
|
246
247
|
return { ...options, url: newUrl };
|
|
247
248
|
}
|
|
248
249
|
return interceptor[0](config);
|
|
249
250
|
}, interceptor[1]);
|
|
250
251
|
} else {
|
|
251
|
-
return requestInstance.interceptors.request.use((config) => {
|
|
252
|
+
return requestInstance.interceptors.request.use(async (config) => {
|
|
252
253
|
const { url } = config;
|
|
253
254
|
if(interceptor.length === 2){
|
|
254
|
-
const { url: newUrl, options } = interceptor(url, config);
|
|
255
|
+
const { url: newUrl, options } = await interceptor(url, config);
|
|
255
256
|
return { ...options, url: newUrl };
|
|
256
257
|
}
|
|
257
258
|
return interceptor(config);
|
|
@@ -308,6 +309,10 @@ export type {
|
|
|
308
309
|
AxiosResponse,
|
|
309
310
|
AxiosError,
|
|
310
311
|
RequestError,
|
|
312
|
+
IRequestInterceptorAxios as RequestInterceptorAxios,
|
|
313
|
+
IRequestInterceptorUmiRequest as RequestInterceptorUmiRequest,
|
|
314
|
+
IRequestInterceptor as RequestInterceptor,
|
|
315
|
+
IErrorInterceptor as ErrorInterceptor,
|
|
311
316
|
IResponseInterceptor as ResponseInterceptor,
|
|
312
317
|
IRequestOptions as RequestOptions,
|
|
313
318
|
IRequest as Request,
|
|
@@ -347,6 +352,10 @@ export type {
|
|
|
347
352
|
AxiosResponse,
|
|
348
353
|
AxiosError,
|
|
349
354
|
RequestError,
|
|
355
|
+
RequestInterceptorAxios,
|
|
356
|
+
RequestInterceptorUmiRequest,
|
|
357
|
+
RequestInterceptor,
|
|
358
|
+
ErrorInterceptor,
|
|
350
359
|
ResponseInterceptor,
|
|
351
360
|
RequestOptions,
|
|
352
361
|
Request } from './request';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "@umijs/plugins",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"styled-components": "6.1.1",
|
|
46
46
|
"tslib": "^2",
|
|
47
47
|
"warning": "^4.0.3",
|
|
48
|
-
"@umijs/
|
|
49
|
-
"@umijs/
|
|
48
|
+
"@umijs/valtio": "1.0.4",
|
|
49
|
+
"@umijs/bundler-utils": "4.1.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"antd": "^4.24.1",
|
|
53
|
-
"umi": "4.1.
|
|
53
|
+
"umi": "4.1.2"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|