@umijs/plugins 4.0.0-canary.20220425.1 → 4.0.0-canary.20220427.1

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/antd.js CHANGED
@@ -49,8 +49,7 @@ exports.default = (api) => {
49
49
  api.modifyConfig((memo) => {
50
50
  checkPkgPath();
51
51
  // antd import
52
- // alias 会导致 antd 不能多实例,故删除
53
- // memo.alias.antd = pkgPath;
52
+ memo.alias.antd = pkgPath;
54
53
  // moment > dayjs
55
54
  if (memo.antd.dayjs) {
56
55
  memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
package/dist/request.js CHANGED
@@ -105,6 +105,7 @@ interface IRequestOptions extends AxiosRequestConfig {
105
105
  skipErrorHandler?: boolean;
106
106
  requestInterceptors?: IRequestInterceptorTuple[];
107
107
  responseInterceptors?: IResponseInterceptorTuple[];
108
+ [key: string]: any;
108
109
  }
109
110
 
110
111
  interface IRequestOptionsWithResponse extends IRequestOptions {
@@ -125,7 +126,9 @@ interface IRequest{
125
126
  interface IErrorHandler {
126
127
  (error: RequestError, opts: IRequestOptions): void;
127
128
  }
128
- type IRequestInterceptor = (config : AxiosRequestConfig) => AxiosRequestConfig;
129
+ type IRequestInterceptorAxios = (config: RequestOptions) => RequestOptions;
130
+ type IRequestInterceptorUmiRequest = (url: string, config : RequestOptions) => { url: string, options: RequestOptions };
131
+ type IRequestInterceptor = IRequestInterceptorAxios;
129
132
  type IErrorInterceptor = (error: Error) => Promise<Error>;
130
133
  type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => AxiosResponse<T> ;
131
134
  type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [ IRequestInterceptor ] | IRequestInterceptor
@@ -158,16 +161,32 @@ const getRequestInstance = (): AxiosInstance => {
158
161
  requestInstance = axios.create(config);
159
162
 
160
163
  config?.requestInterceptors?.forEach((interceptor) => {
161
- return interceptor instanceof Array ?
162
- requestInstance.interceptors.request.use(interceptor[0], interceptor[1]):
163
- requestInstance.interceptors.request.use(interceptor);
164
- });
164
+ if(interceptor instanceof Array){
165
+ requestInstance.interceptors.request.use((config) => {
166
+ const { url } = config;
167
+ if(interceptor[0].length === 2){
168
+ const { url: newUrl, options } = interceptor[0](url, config);
169
+ return { ...options, url: newUrl };
170
+ }
171
+ return interceptor[0](config);
172
+ }, interceptor[1]);
173
+ } else {
174
+ requestInstance.interceptors.request.use((config) => {
175
+ const { url } = config;
176
+ if(interceptor.length === 2){
177
+ const { url: newUrl, options } = interceptor(url, config);
178
+ return { ...options, url: newUrl };
179
+ }
180
+ return interceptor(config);
181
+ })
182
+ }
183
+ });
165
184
 
166
185
  config?.responseInterceptors?.forEach((interceptor) => {
167
- return interceptor instanceof Array ?
186
+ interceptor instanceof Array ?
168
187
  requestInstance.interceptors.response.use(interceptor[0], interceptor[1]):
169
188
  requestInstance.interceptors.response.use(interceptor);
170
- });
189
+ });
171
190
 
172
191
  // 当响应的数据 success 是 false 的时候,抛出 error 以供 errorHandler 处理。
173
192
  requestInstance.interceptors.response.use((response)=>{
@@ -185,9 +204,25 @@ const request: IRequest = (url: string, opts: any = { method: 'GET' }) => {
185
204
  const config = getConfig();
186
205
  const { getResponse = false, requestInterceptors, responseInterceptors } = opts;
187
206
  const requestInterceptorsToEject = requestInterceptors?.map((interceptor) => {
188
- return interceptor instanceof Array ?
189
- requestInstance.interceptors.request.use(interceptor[0], interceptor[1]):
190
- requestInstance.interceptors.request.use(interceptor);
207
+ if(interceptor instanceof Array){
208
+ return requestInstance.interceptors.request.use((config) => {
209
+ const { url } = config;
210
+ if(interceptor[0].length === 2){
211
+ const { url: newUrl, options } = interceptor[0](url, config);
212
+ return { ...options, url: newUrl };
213
+ }
214
+ return interceptor[0](config);
215
+ }, interceptor[1]);
216
+ } else {
217
+ return requestInstance.interceptors.request.use((config) => {
218
+ const { url } = config;
219
+ if(interceptor.length === 2){
220
+ const { url: newUrl, options } = interceptor(url, config);
221
+ return { ...options, url: newUrl };
222
+ }
223
+ return interceptor(config);
224
+ })
225
+ }
191
226
  });
192
227
  const responseInterceptorsToEject = responseInterceptors?.map((interceptor) => {
193
228
  return interceptor instanceof Array ?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-canary.20220425.1",
3
+ "version": "4.0.0-canary.20220427.1",
4
4
  "description": "@umijs/plugins",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -25,8 +25,7 @@
25
25
  "@ahooksjs/use-request": "^2.0.0",
26
26
  "@ant-design/icons": "^4.7.0",
27
27
  "@ant-design/pro-layout": "^6.35.1",
28
- "@umijs/bundler-utils": "4.0.0-canary.20220425.1",
29
- "antd": "^4.20.0",
28
+ "@umijs/bundler-utils": "4.0.0-canary.20220427.1",
30
29
  "antd-dayjs-webpack-plugin": "^1.0.6",
31
30
  "axios": "^0.26.1",
32
31
  "babel-plugin-import": "^1.13.3",
@@ -45,7 +44,7 @@
45
44
  "warning": "^4.0.3"
46
45
  },
47
46
  "devDependencies": {
48
- "umi": "4.0.0-canary.20220425.1"
47
+ "umi": "4.0.0-canary.20220427.1"
49
48
  },
50
49
  "publishConfig": {
51
50
  "access": "public"