@umijs/plugins 4.0.0-rc.2 → 4.0.0-rc.20

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/request.js CHANGED
@@ -7,7 +7,12 @@ exports.default = (api) => {
7
7
  key: 'request',
8
8
  config: {
9
9
  schema: (joi) => {
10
- return joi.object();
10
+ return joi.object({
11
+ dataField: joi
12
+ .string()
13
+ .pattern(/^[a-zA-Z]*$/)
14
+ .allow(''),
15
+ });
11
16
  },
12
17
  },
13
18
  enableBy: api.EnableBy.config,
@@ -20,7 +25,6 @@ import axios, {
20
25
  type AxiosResponse,
21
26
  } from '{{{axiosPath}}}';
22
27
  import useUmiRequest, { UseRequestProvider } from '{{{umiRequestPath}}}';
23
- import { message, notification } from '{{{antdPkg}}}';
24
28
  import { ApplyPluginsType } from 'umi';
25
29
  import { getPluginManager } from '../core/plugin';
26
30
 
@@ -81,7 +85,7 @@ function useRequest<Item = any, U extends Item = any>(
81
85
  ): PaginatedResult<Item>;
82
86
  function useRequest(service: any, options: any = {}) {
83
87
  return useUmiRequest(service, {
84
- formatResult: result => result?.data,
88
+ formatResult: {{{formatResult}}},
85
89
  requestMethod: (requestOptions: any) => {
86
90
  if (typeof requestOptions === 'string') {
87
91
  return request(requestOptions);
@@ -96,114 +100,49 @@ function useRequest(service: any, options: any = {}) {
96
100
  });
97
101
  }
98
102
 
99
- export interface RequestConfig extends AxiosRequestConfig {
100
- errorConfig?: {
101
- errorPage?: string;
102
- adaptor?: IAdaptor; // adaptor 用以用户将不满足接口的后端数据修改成 errorInfo
103
- errorHandler?: IErrorHandler;
104
- defaultNoneResponseErrorMessage?: string;
105
- defaultRequestErrorMessage?: string;
106
- };
107
- formatResultAdaptor?: IFormatResultAdaptor;
108
- }
109
-
110
- export enum ErrorShowType {
111
- SILENT = 0,
112
- WARN_MESSAGE = 1,
113
- ERROR_MESSAGE = 2,
114
- NOTIFICATION = 3,
115
- REDIRECT = 9,
116
- }
117
-
118
- export interface IErrorInfo {
119
- success: boolean;
120
- data?: any;
121
- errorCode?: string;
122
- errorMessage?: string;
123
- showType?: ErrorShowType;
124
- traceId?: string;
125
- host?: string;
103
+ // request 方法 opts 参数的接口
104
+ interface IRequestOptions extends AxiosRequestConfig {
105
+ skipErrorHandler?: boolean;
106
+ requestInterceptors?: IRequestInterceptorTuple[];
107
+ responseInterceptors?: IResponseInterceptorTuple[];
126
108
  [key: string]: any;
127
109
  }
128
- // resData 其实就是 response.data, response 则是 axios 的响应对象
129
- interface IAdaptor {
130
- (resData: any, response: AxiosResponse): IErrorInfo;
110
+
111
+ interface IRequestOptionsWithResponse extends IRequestOptions {
112
+ getResponse: true;
131
113
  }
132
114
 
133
- export interface RequestError extends Error {
134
- data?: any;
135
- info?: IErrorInfo;
115
+ interface IRequestOptionsWithoutResponse extends IRequestOptions{
116
+ getResponse: false;
136
117
  }
137
118
 
138
- interface IRequest {
139
- (
140
- url: string,
141
- opts: AxiosRequestConfig & { skipErrorHandler?: boolean },
142
- ): Promise<AxiosResponse<any, any>>;
119
+ interface IRequest{
120
+ <T = any>(url: string, opts: IRequestOptionsWithResponse): Promise<AxiosResponse<T>>;
121
+ <T = any>(url: string, opts: IRequestOptionsWithoutResponse): Promise<T>;
122
+ <T = any>(url: string, opts: IRequestOptions): Promise<T>; // getResponse 默认是 false, 因此不提供该参数时,只返回 data
123
+ <T = any>(url: string): Promise<T>; // 不提供 opts 时,默认使用 'GET' method,并且默认返回 data
143
124
  }
144
125
 
145
126
  interface IErrorHandler {
146
- (error: RequestError, opts: AxiosRequestConfig & { skipErrorHandler?: boolean }, config: RequestConfig): void;
127
+ (error: RequestError, opts: IRequestOptions): void;
147
128
  }
129
+ type IRequestInterceptorAxios = (config: RequestOptions) => RequestOptions;
130
+ type IRequestInterceptorUmiRequest = (url: string, config : RequestOptions) => { url: string, options: RequestOptions };
131
+ type IRequestInterceptor = IRequestInterceptorAxios;
132
+ type IErrorInterceptor = (error: Error) => Promise<Error>;
133
+ type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => AxiosResponse<T> ;
134
+ type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [ IRequestInterceptor ] | IRequestInterceptor
135
+ type IResponseInterceptorTuple = [IResponseInterceptor, IErrorInterceptor] | [IResponseInterceptor] | IResponseInterceptor
148
136
 
149
- interface IFormatResultAdaptor {
150
- (res: AxiosResponse): any;
137
+ export interface RequestConfig extends AxiosRequestConfig {
138
+ errorConfig?: {
139
+ errorHandler?: IErrorHandler;
140
+ errorThrower?: <T = any>( res: T ) => void
141
+ };
142
+ requestInterceptors?: IRequestInterceptorTuple[];
143
+ responseInterceptors?: IResponseInterceptorTuple[];
151
144
  }
152
145
 
153
- const defaultErrorHandler: IErrorHandler = (error, opts, config) => {
154
- if (opts?.skipErrorHandler) throw error;
155
- const { errorConfig } = config;
156
- if (error.response) {
157
- // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围 或者 成功响应,success字段为false 由我们抛出的错误
158
- let errorInfo: IErrorInfo | undefined;
159
- // 不是我们的错误
160
- if(error.name === 'ResponseError'){
161
- const adaptor: IAdaptor =
162
- errorConfig?.adaptor || ((errorData) => errorData);
163
- errorInfo = adaptor(error.response.data, error.response);
164
- error.info = errorInfo;
165
- error.data = error.response.data;
166
- }
167
- errorInfo = error.info;
168
- if (errorInfo) {
169
- const { errorMessage, errorCode } = errorInfo;
170
- switch (errorInfo.showType) {
171
- case ErrorShowType.SILENT:
172
- // do nothong
173
- break;
174
- case ErrorShowType.WARN_MESSAGE:
175
- message.warn(errorMessage);
176
- break;
177
- case ErrorShowType.ERROR_MESSAGE:
178
- message.error(errorMessage);
179
- break;
180
- case ErrorShowType.NOTIFICATION:
181
- notification.open({ description: errorMessage, message: errorCode });
182
- break;
183
- case ErrorShowType.REDIRECT:
184
- // TODO: redirect
185
- break;
186
- default:
187
- message.error(errorMessage);
188
- }
189
- }
190
- } else if (error.request) {
191
- // 请求已经成功发起,但没有收到响应
192
- // \`error.request\` 在浏览器中是 XMLHttpRequest 的实例,
193
- // 而在node.js中是 http.ClientRequest 的实例
194
- message.error(
195
- errorConfig?.defaultNoneResponseErrorMessage ||
196
- 'None response! Please retry.',
197
- );
198
- } else {
199
- // 发送请求时出了点问题
200
- message.error(
201
- errorConfig?.defaultRequestErrorMessage || 'Request error, please retry.',
202
- );
203
- }
204
- throw error;
205
- };
206
-
207
146
  let requestInstance: AxiosInstance;
208
147
  let config: RequestConfig;
209
148
  const getConfig = (): RequestConfig => {
@@ -215,56 +154,118 @@ const getConfig = (): RequestConfig => {
215
154
  });
216
155
  return config;
217
156
  };
157
+
218
158
  const getRequestInstance = (): AxiosInstance => {
219
159
  if (requestInstance) return requestInstance;
220
160
  const config = getConfig();
221
161
  requestInstance = axios.create(config);
222
162
 
163
+ config?.requestInterceptors?.forEach((interceptor) => {
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
+ });
184
+
185
+ config?.responseInterceptors?.forEach((interceptor) => {
186
+ interceptor instanceof Array ?
187
+ requestInstance.interceptors.response.use(interceptor[0], interceptor[1]):
188
+ requestInstance.interceptors.response.use(interceptor);
189
+ });
190
+
223
191
  // 当响应的数据 success 是 false 的时候,抛出 error 以供 errorHandler 处理。
224
- requestInstance.interceptors.response.use((response)=>{
225
- const {data} = response;
226
- const adaptor = config?.errorConfig?.adaptor || ((resData) => resData);
227
- const errorInfo = adaptor(data,response);
228
- if(errorInfo.success === false){
229
- const error: RequestError = new Error(errorInfo.errorMessage);
230
- error.name = 'BizError';
231
- error.data = data;
232
- error.info = errorInfo;
233
- error.response = response;
234
- throw error;
192
+ requestInstance.interceptors.response.use((response) => {
193
+ const { data } = response;
194
+ if(data?.success === false && config?.errorConfig?.errorThrower){
195
+ config.errorConfig.errorThrower(data);
235
196
  }
236
197
  return response;
237
198
  })
238
199
  return requestInstance;
239
200
  };
240
201
 
241
- const request: IRequest = (url, opts) => {
202
+ const request: IRequest = (url: string, opts: any = { method: 'GET' }) => {
242
203
  const requestInstance = getRequestInstance();
243
204
  const config = getConfig();
244
- return new Promise((resolve, reject) => {
205
+ const { getResponse = false, requestInterceptors, responseInterceptors } = opts;
206
+ const requestInterceptorsToEject = requestInterceptors?.map((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
+ }
226
+ });
227
+ const responseInterceptorsToEject = responseInterceptors?.map((interceptor) => {
228
+ return interceptor instanceof Array ?
229
+ requestInstance.interceptors.response.use(interceptor[0], interceptor[1]):
230
+ requestInstance.interceptors.response.use(interceptor);
231
+ });
232
+ return new Promise((resolve, reject)=>{
245
233
  requestInstance
246
- .request({ ...opts, url })
247
- .then((res) => {
248
- const formatResultAdaptor =
249
- config?.formatResultAdaptor || ((res) => res.data);
250
- resolve(formatResultAdaptor(res));
234
+ .request({...opts, url})
235
+ .then((res)=>{
236
+ requestInterceptorsToEject?.forEach((interceptor) => {
237
+ requestInstance.interceptors.request.eject(interceptor);
238
+ });
239
+ responseInterceptorsToEject?.forEach((interceptor) => {
240
+ requestInstance.interceptors.response.eject(interceptor);
241
+ });
242
+ resolve(getResponse ? res : res.data);
251
243
  })
252
- .catch((error) => {
244
+ .catch((error)=>{
245
+ requestInterceptorsToEject?.forEach((interceptor) => {
246
+ requestInstance.interceptors.request.eject(interceptor);
247
+ });
248
+ responseInterceptorsToEject?.forEach((interceptor) => {
249
+ requestInstance.interceptors.response.eject(interceptor);
250
+ });
253
251
  try {
254
252
  const handler =
255
- config.errorConfig?.errorHandler || defaultErrorHandler;
256
- handler(error, opts, config);
253
+ config.errorConfig?.errorHandler;
254
+ if(handler)
255
+ handler(error, opts, config);
257
256
  } catch (e) {
258
257
  reject(e);
259
258
  }
260
- });
261
- });
262
- };
259
+ reject(error);
260
+ })
261
+ })
262
+ }
263
263
 
264
264
  export {
265
265
  useRequest,
266
266
  UseRequestProvider,
267
267
  request,
268
+ getRequestInstance,
268
269
  };
269
270
 
270
271
  export type {
@@ -278,18 +279,24 @@ export type {
278
279
  var _a;
279
280
  const umiRequestPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('@ahooksjs/use-request/package.json')));
280
281
  const axiosPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('axios/package.json')));
281
- const antdPkg = (0, plugin_utils_1.winPath)(
282
- // use path from antd plugin first
283
- ((_a = api.appData.antd) === null || _a === void 0 ? void 0 : _a.pkgPath) ||
284
- (0, path_1.dirname)(require.resolve('antd/package.json')));
282
+ let dataField = (_a = api.config.request) === null || _a === void 0 ? void 0 : _a.dataField;
283
+ if (dataField === undefined)
284
+ dataField = 'data';
285
+ const formatResult = dataField === '' ? `result => result` : `result => result?.${dataField}`;
285
286
  api.writeTmpFile({
286
287
  path: 'request.ts',
287
288
  content: plugin_utils_1.Mustache.render(requestTpl, {
288
289
  umiRequestPath,
289
290
  axiosPath,
290
- antdPkg,
291
+ formatResult,
291
292
  }),
292
293
  });
294
+ api.writeTmpFile({
295
+ path: 'types.d.ts',
296
+ content: `
297
+ export type { RequestConfig } from './request';
298
+ `,
299
+ });
293
300
  api.writeTmpFile({
294
301
  path: 'index.ts',
295
302
  content: `
@@ -1,38 +1,40 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
- const child_process_1 = require("child_process");
23
- const path = __importStar(require("path"));
3
+ const path_1 = require("path");
4
+ const plugin_utils_1 = require("umi/plugin-utils");
24
5
  exports.default = (api) => {
25
- api.describe({ key: 'tailwindcss' });
26
- api.onStart(() => {
27
- const inputPath = path.resolve(api.cwd, 'tailwind.css');
28
- const generatedPath = path.resolve(api.paths.absTmpPath, 'tailwind.css');
29
- const binPath = path.resolve(api.cwd, 'node_modules/.bin/tailwind');
6
+ api.describe({
7
+ key: 'tailwindcss',
8
+ config: {
9
+ schema(Joi) {
10
+ return Joi.object();
11
+ },
12
+ },
13
+ enableBy: api.EnableBy.config,
14
+ });
15
+ let tailwind = null;
16
+ const outputPath = 'plugin-tailwindcss/tailwind.css';
17
+ api.onBeforeCompiler(() => {
18
+ const inputPath = (0, path_1.join)(api.cwd, 'tailwind.css');
19
+ const generatedPath = (0, path_1.join)(api.paths.absTmpPath, outputPath);
20
+ const binPath = (0, path_1.join)(api.cwd, 'node_modules/.bin/tailwind');
30
21
  /** 透过子进程建立 tailwindcss 服务,将生成的 css 写入 generatedPath */
31
- const tailwind = (0, child_process_1.exec)(`${binPath} -i ${inputPath} -o ${generatedPath} --watch`, { cwd: api.cwd });
22
+ tailwind = (0, plugin_utils_1.crossSpawn)(`${binPath}`, [
23
+ '-i',
24
+ inputPath,
25
+ '-o',
26
+ generatedPath,
27
+ api.env === 'development' ? '--watch' : '',
28
+ ], {
29
+ stdio: 'inherit',
30
+ });
32
31
  tailwind.on('error', (m) => {
33
32
  api.logger.error('tailwindcss service encounter an error: ' + m);
34
33
  });
35
- /** 将生成的 css 文件加入到 import 中 */
36
- api.addEntryImports(() => [{ source: generatedPath }]);
34
+ });
35
+ /** 将生成的 css 文件加入到 import 中 */
36
+ api.addEntryImports(() => {
37
+ const generatedPath = (0, plugin_utils_1.winPath)((0, path_1.join)(api.paths.absTmpPath, outputPath));
38
+ return [{ source: generatedPath }];
37
39
  });
38
40
  };
package/dist/unocss.js CHANGED
@@ -1,31 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
2
  Object.defineProperty(exports, "__esModule", { value: true });
25
- const utils_1 = require("@umijs/utils");
26
3
  const child_process_1 = require("child_process");
27
- const fs = __importStar(require("fs"));
28
- const path_1 = __importDefault(require("path"));
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const plugin_utils_1 = require("umi/plugin-utils");
29
7
  exports.default = (api) => {
30
8
  api.describe({
31
9
  key: 'unocss',
@@ -38,20 +16,24 @@ exports.default = (api) => {
38
16
  },
39
17
  enableBy: api.EnableBy.config,
40
18
  });
41
- api.onStart(() => {
19
+ const outputPath = 'uno.css';
20
+ api.onBeforeCompiler(() => {
42
21
  /** 由于 @unocss/cli 对设置文件进行了检查,因此加入需要 unocss.config.ts 设置的提示
43
22
  * https://github.com/antfu/unocss/blob/main/packages/cli/src/index.ts#L93 */
44
- if (!fs.existsSync(path_1.default.resolve(api.paths.cwd, 'unocss.config.ts')))
45
- utils_1.logger.warn('请在项目目录中添加 unocss.config.ts 文件,并配置需要的 unocss presets,否则插件将没有效果!');
46
- const generatedPath = path_1.default.resolve(api.paths.absTmpPath, 'uno.css');
47
- const binPath = path_1.default.resolve(api.cwd, 'node_modules/.bin/unocss');
23
+ if (!(0, fs_1.existsSync)((0, path_1.join)(api.paths.cwd, 'unocss.config.ts')))
24
+ api.logger.warn('请在项目目录中添加 unocss.config.ts 文件,并配置需要的 unocss presets,否则插件将没有效果!');
25
+ const generatedPath = (0, path_1.join)(api.paths.absTmpPath, outputPath);
26
+ const binPath = (0, path_1.join)(api.cwd, 'node_modules/.bin/unocss');
48
27
  const watchDirs = api.config.unocss.watch;
49
28
  /** 透过子进程建立 unocss 服务,将生成的 css 写入 generatedPath */
50
- const unocss = (0, child_process_1.exec)(`${binPath} ${watchDirs.join(' ')} --out-file ${generatedPath} --watch`, { cwd: api.cwd });
29
+ const unocss = (0, child_process_1.exec)(`${binPath} ${watchDirs.join(' ')} --out-file ${generatedPath} ${api.env === 'development' ? '--watch' : ''}`, { cwd: api.cwd });
51
30
  unocss.on('error', (m) => {
52
31
  api.logger.error('unocss service encounter an error: ' + m);
53
32
  });
54
- /** 将生成的 css 文件加入到 import 中 */
55
- api.addEntryImports(() => [{ source: generatedPath }]);
33
+ });
34
+ /** 将生成的 css 文件加入到 import 中 */
35
+ api.addEntryImports(() => {
36
+ const generatedPath = (0, plugin_utils_1.winPath)((0, path_1.join)(api.paths.absTmpPath, outputPath));
37
+ return [{ source: generatedPath }];
56
38
  });
57
39
  };
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,18 +1,9 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.isNeedPolyfill = exports.exactLocalePaths = exports.getLocaleList = exports.getAntdLocale = exports.getMomentLocale = void 0;
13
- const utils_1 = require("@umijs/utils");
14
4
  const fs_1 = require("fs");
15
5
  const path_1 = require("path");
6
+ const plugin_utils_1 = require("umi/plugin-utils");
16
7
  /**
17
8
  * 获取 moment 包的 locale 名称
18
9
  * @param lang 语言
@@ -55,19 +46,19 @@ const modulesHasLocale = (localePath) => {
55
46
  return false;
56
47
  }
57
48
  };
58
- const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
49
+ const getLocaleList = async (opts) => {
59
50
  const { localeFolder, separator = '-', absSrcPath = '', absPagesPath = '', addAntdLocales, resolveKey = 'moment', } = opts;
60
51
  const localeFileMath = new RegExp(`^([a-z]{2})${separator}?([A-Z]{2})?\.(js|json|ts)$`);
61
- const localeFiles = utils_1.glob
52
+ const localeFiles = plugin_utils_1.glob
62
53
  .sync('*.{ts,js,json}', {
63
- cwd: (0, utils_1.winPath)((0, path_1.join)(absSrcPath, localeFolder)),
54
+ cwd: (0, plugin_utils_1.winPath)((0, path_1.join)(absSrcPath, localeFolder)),
64
55
  })
65
- .map((name) => (0, utils_1.winPath)((0, path_1.join)(absSrcPath, localeFolder, name)))
66
- .concat(utils_1.glob
56
+ .map((name) => (0, plugin_utils_1.winPath)((0, path_1.join)(absSrcPath, localeFolder, name)))
57
+ .concat(plugin_utils_1.glob
67
58
  .sync(`**/${localeFolder}/*.{ts,js,json}`, {
68
59
  cwd: absPagesPath,
69
60
  })
70
- .map((name) => (0, utils_1.winPath)((0, path_1.join)(absPagesPath, name))))
61
+ .map((name) => (0, plugin_utils_1.winPath)((0, path_1.join)(absPagesPath, name))))
71
62
  .filter((p) => localeFileMath.test((0, path_1.basename)(p)) && (0, fs_1.existsSync)(p))
72
63
  .map((fullName) => {
73
64
  var _a, _b;
@@ -79,12 +70,12 @@ const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
79
70
  path: fullName,
80
71
  };
81
72
  });
82
- const groups = utils_1.lodash.groupBy(localeFiles, 'name');
83
- const promises = Object.keys(groups).map((name) => __awaiter(void 0, void 0, void 0, function* () {
73
+ const groups = plugin_utils_1.lodash.groupBy(localeFiles, 'name');
74
+ const promises = Object.keys(groups).map(async (name) => {
84
75
  const [lang, country = ''] = name.split(separator);
85
76
  const { momentLocale } = (0, exports.getMomentLocale)(lang, country, resolveKey);
86
- const antdLocale = utils_1.lodash
87
- .uniq(yield addAntdLocales({ lang, country }))
77
+ const antdLocale = plugin_utils_1.lodash
78
+ .uniq(await addAntdLocales({ lang, country }))
88
79
  .filter((localePath) => modulesHasLocale(localePath));
89
80
  return {
90
81
  lang,
@@ -94,15 +85,15 @@ const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
94
85
  locale: name.split(separator).join('-'),
95
86
  country,
96
87
  antdLocale,
97
- paths: groups[name].map((item) => (0, utils_1.winPath)(item.path)),
88
+ paths: groups[name].map((item) => (0, plugin_utils_1.winPath)(item.path)),
98
89
  momentLocale,
99
90
  };
100
- }));
91
+ });
101
92
  return Promise.all(promises);
102
- });
93
+ };
103
94
  exports.getLocaleList = getLocaleList;
104
95
  const exactLocalePaths = (data) => {
105
- return utils_1.lodash.flatten(data.map((item) => item.paths));
96
+ return plugin_utils_1.lodash.flatten(data.map((item) => item.paths));
106
97
  };
107
98
  exports.exactLocalePaths = exactLocalePaths;
108
99
  function isNeedPolyfill(targets = {}) {
@@ -12,7 +12,9 @@ export declare class Model {
12
12
  namespace: string;
13
13
  id: string;
14
14
  exportName: string;
15
- constructor(file: string, id: number);
15
+ deps: string[];
16
+ constructor(file: string, sort: {} | undefined, id: number);
17
+ findDeps(sort: object): string[];
16
18
  }
17
19
  export declare class ModelUtils {
18
20
  api: IApi;
@@ -20,8 +22,10 @@ export declare class ModelUtils {
20
22
  count: number;
21
23
  constructor(api: IApi | null, opts: IOpts);
22
24
  getAllModels(opts: {
25
+ sort?: object;
23
26
  extraModels: string[];
24
27
  }): Model[];
28
+ getSortedNamespaces(models: Model[]): string[];
25
29
  getModels(opts: {
26
30
  base: string;
27
31
  pattern?: string;