@umijs/plugins 4.0.0-canary.20220425.2 → 4.0.0-canary.20220428.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'));
@@ -80,15 +79,6 @@ exports.default = (api) => {
80
79
  },
81
80
  'antd',
82
81
  ],
83
- [
84
- require.resolve('babel-plugin-import'),
85
- {
86
- libraryName: 'antd-4',
87
- libraryDirectory: 'es',
88
- style: style === 'less' ? true : 'css',
89
- },
90
- 'antd-4',
91
- ],
92
82
  ]
93
83
  : [];
94
84
  });
package/dist/layout.js CHANGED
@@ -39,7 +39,7 @@ exports.default = (api) => {
39
39
  schema(joi) {
40
40
  return joi.object();
41
41
  },
42
- onChange: api.ConfigChangeType.regenerateTmpFiles,
42
+ // onChange: api.ConfigChangeType.regenerateTmpFiles,
43
43
  },
44
44
  enableBy: api.EnableBy.config,
45
45
  });
@@ -48,7 +48,6 @@ exports.default = (api) => {
48
48
  cwd: api.cwd,
49
49
  dep: '@ant-design/pro-layout',
50
50
  }) || (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
51
- const antdPkgPath = (0, path_1.dirname)(require.resolve('antd/package.json'));
52
51
  api.modifyAppData((memo) => {
53
52
  const version = require(`${pkgPath}/package.json`).version;
54
53
  memo.pluginLayout = {
@@ -60,7 +59,6 @@ exports.default = (api) => {
60
59
  api.modifyConfig((memo) => {
61
60
  // import from @ant-design/pro-layout
62
61
  memo.alias['@ant-design/pro-layout'] = pkgPath;
63
- memo.alias['antd-4'] = antdPkgPath;
64
62
  return memo;
65
63
  });
66
64
  api.onGenerateFiles(() => {
@@ -247,7 +245,7 @@ export function patchRoutes({ routes }) {
247
245
  });
248
246
  const rightRenderContent = `
249
247
  import React from 'react';
250
- import { Avatar, Dropdown, Menu, Spin } from 'antd-4';
248
+ import { Avatar, Dropdown, Menu, Spin } from 'antd';
251
249
  import { LogoutOutlined } from '@ant-design/icons';
252
250
  {{#Locale}}
253
251
  import { SelectLang } from '@@/plugin-locale';
@@ -489,7 +487,7 @@ export default LogoIcon;
489
487
  content: `
490
488
  import React from 'react';
491
489
  import { history, type IRoute } from 'umi';
492
- import { Result, Button } from 'antd-4';
490
+ import { Result, Button } from 'antd';
493
491
 
494
492
  const Exception: React.FC<{
495
493
  children: React.ReactNode;
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.2",
3
+ "version": "4.0.0-canary.20220428.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.2",
29
- "antd": "^4.20.0",
28
+ "@umijs/bundler-utils": "4.0.0-canary.20220428.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.2"
47
+ "umi": "4.0.0-canary.20220428.1"
49
48
  },
50
49
  "publishConfig": {
51
50
  "access": "public"