@umijs/plugins 4.0.0-beta.9 → 4.0.0-rc.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.
Files changed (58) hide show
  1. package/README.md +4 -1
  2. package/dist/access.js +73 -1
  3. package/dist/{sass.d.ts → analytics.d.ts} +0 -0
  4. package/dist/analytics.js +67 -0
  5. package/dist/antd.js +89 -145
  6. package/dist/dva.d.ts +3 -0
  7. package/dist/dva.js +168 -4
  8. package/dist/initial-state.js +112 -1
  9. package/dist/layout.js +479 -1
  10. package/dist/locale.d.ts +1 -0
  11. package/dist/locale.js +199 -1
  12. package/dist/model.js +112 -1
  13. package/dist/moment2dayjs.d.ts +3 -0
  14. package/dist/moment2dayjs.js +96 -0
  15. package/dist/qiankun/constants.d.ts +5 -0
  16. package/dist/qiankun/constants.js +8 -0
  17. package/dist/qiankun/master.d.ts +6 -0
  18. package/dist/qiankun/master.js +114 -0
  19. package/dist/qiankun/slave.d.ts +3 -0
  20. package/dist/qiankun/slave.js +141 -0
  21. package/dist/qiankun.js +15 -1
  22. package/dist/request.js +300 -1
  23. package/dist/tailwindcss.d.ts +3 -0
  24. package/dist/tailwindcss.js +38 -0
  25. package/dist/unocss.d.ts +3 -0
  26. package/dist/unocss.js +57 -0
  27. package/dist/utils/astUtils.d.ts +3 -0
  28. package/dist/utils/astUtils.js +34 -0
  29. package/dist/utils/localeUtils.d.ts +33 -0
  30. package/dist/utils/localeUtils.js +135 -0
  31. package/dist/utils/modelUtils.d.ts +35 -0
  32. package/dist/utils/modelUtils.js +145 -0
  33. package/dist/utils/resolveProjectDep.d.ts +5 -0
  34. package/dist/utils/resolveProjectDep.js +15 -0
  35. package/dist/utils/withTmpPath.d.ts +6 -0
  36. package/dist/utils/withTmpPath.js +11 -0
  37. package/libs/dva.ts +10 -0
  38. package/libs/locale/SelectLang.tpl +478 -0
  39. package/libs/locale/locale.tpl +82 -0
  40. package/libs/locale/localeExports.tpl +271 -0
  41. package/libs/locale/runtime.tpl +33 -0
  42. package/libs/model.tsx +140 -0
  43. package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
  44. package/libs/qiankun/master/AntdLoader.tsx +15 -0
  45. package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
  46. package/libs/qiankun/master/MicroApp.tsx +262 -0
  47. package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
  48. package/libs/qiankun/master/common.ts +133 -0
  49. package/libs/qiankun/master/constants.ts +7 -0
  50. package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
  51. package/libs/qiankun/master/masterRuntimePlugin.tsx +130 -0
  52. package/libs/qiankun/master/types.ts +44 -0
  53. package/libs/qiankun/slave/connectMaster.tsx +15 -0
  54. package/libs/qiankun/slave/lifecycles.ts +149 -0
  55. package/libs/qiankun/slave/qiankunModel.ts +19 -0
  56. package/libs/qiankun/slave/slaveRuntimePlugin.ts +21 -0
  57. package/package.json +21 -5
  58. package/dist/sass.js +0 -5
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const assert_1 = __importDefault(require("assert"));
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ const withTmpPath_1 = require("../utils/withTmpPath");
10
+ const constants_1 = require("./constants");
11
+ // BREAK CHANGE: 需要手动配置 slave: {},不能留空
12
+ function isSlaveEnable(opts) {
13
+ var _a, _b;
14
+ const slaveCfg = (_b = (_a = opts.userConfig) === null || _a === void 0 ? void 0 : _a.qiankun) === null || _b === void 0 ? void 0 : _b.slave;
15
+ if (slaveCfg) {
16
+ return slaveCfg.enable !== false;
17
+ }
18
+ return !!process.env.INITIAL_QIANKUN_SLAVE_OPTIONS;
19
+ }
20
+ exports.default = (api) => {
21
+ api.describe({
22
+ key: 'qiankun-slave',
23
+ enableBy: isSlaveEnable,
24
+ });
25
+ api.addRuntimePlugin(() => {
26
+ return [(0, withTmpPath_1.withTmpPath)({ api, path: 'slaveRuntimePlugin.ts' })];
27
+ });
28
+ api.register({
29
+ key: 'addExtraModels',
30
+ fn() {
31
+ return [
32
+ `@@/plugin-qiankun-slave/qiankunModel#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
33
+ ];
34
+ },
35
+ });
36
+ api.modifyDefaultConfig((memo) => {
37
+ var _a, _b, _c;
38
+ const initialSlaveOptions = Object.assign(Object.assign({ devSourceMap: true }, JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}')), (memo.qiankun || {}).slave);
39
+ const modifiedDefaultConfig = Object.assign(Object.assign({}, memo), {
40
+ // 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
41
+ runtimePublicPath: true,
42
+ // TODO: runtimeHistory
43
+ runtimeHistory: {}, qiankun: Object.assign(Object.assign({}, memo.qiankun), { slave: initialSlaveOptions }) });
44
+ const shouldNotModifyDefaultBase = (_c = (_b = (_a = api.userConfig.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyDefaultBase) !== null && _c !== void 0 ? _c : initialSlaveOptions.shouldNotModifyDefaultBase;
45
+ if (!shouldNotModifyDefaultBase) {
46
+ // @ts-ignore
47
+ modifiedDefaultConfig.base = `/${api.pkg.name}`;
48
+ }
49
+ return modifiedDefaultConfig;
50
+ });
51
+ api.modifyConfig((config) => {
52
+ var _a, _b;
53
+ // mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
54
+ if (config.mfsu !== false) {
55
+ config.mfsu = Object.assign(Object.assign({}, config.mfsu), { mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
56
+ `mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}` });
57
+ }
58
+ return config;
59
+ });
60
+ // api.modifyPublicPathStr((publicPathStr) => {
61
+ // const { runtimePublicPath } = api.config;
62
+ // const { shouldNotModifyRuntimePublicPath } = (api.config.qiankun || {})
63
+ // .slave!;
64
+ // if (runtimePublicPath === true && !shouldNotModifyRuntimePublicPath) {
65
+ // return `window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${
66
+ // api.config.publicPath || '/'
67
+ // }"`;
68
+ // }
69
+ // return publicPathStr;
70
+ // });
71
+ api.chainWebpack((config) => {
72
+ (0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
73
+ const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
74
+ config.output
75
+ .libraryTarget('umd')
76
+ .library(shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`);
77
+ // TODO: SOCKET_SERVER
78
+ // TODO: devSourceMap
79
+ return config;
80
+ });
81
+ // umi bundle 添加 entry 标记
82
+ api.modifyHTML(($) => {
83
+ $('script').each((_, el) => {
84
+ var _a;
85
+ const scriptEl = $(el);
86
+ const umiEntry = /\/?umi(\.\w+)?\.js$/g;
87
+ if (umiEntry.test((_a = scriptEl.attr('src')) !== null && _a !== void 0 ? _a : '')) {
88
+ scriptEl.attr('entry', '');
89
+ }
90
+ });
91
+ return $;
92
+ });
93
+ api.addEntryImports(() => {
94
+ return [
95
+ {
96
+ source: '@@/plugin-qiankun-slave/lifecycles',
97
+ specifier: '{ genMount as qiankun_genMount, genBootstrap as qiankun_genBootstrap, genUnmount as qiankun_genUnmount, genUpdate as qiankun_genUpdate }',
98
+ },
99
+ ];
100
+ });
101
+ api.addEntryCode(() => [
102
+ `
103
+ export const bootstrap = qiankun_genBootstrap(render);
104
+ export const mount = qiankun_genMount('${api.config.mountElementId}');
105
+ export const unmount = qiankun_genUnmount('${api.config.mountElementId}');
106
+ export const update = qiankun_genUpdate();
107
+ if (!window.__POWERED_BY_QIANKUN__) {
108
+ bootstrap().then(mount);
109
+ }
110
+ `,
111
+ ]);
112
+ function getFileContent(file) {
113
+ return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
114
+ }
115
+ api.onGenerateFiles(() => {
116
+ // api.writeTmpFile({
117
+ // path: 'slaveOptions.ts',
118
+ // content: `
119
+ // let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
120
+ // export const getSlaveOptions = () => options;
121
+ // export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
122
+ // `,
123
+ // });
124
+ [
125
+ 'qiankunModel.ts',
126
+ 'connectMaster.tsx',
127
+ 'slaveRuntimePlugin.ts',
128
+ 'lifecycles.ts',
129
+ ].forEach((file) => {
130
+ api.writeTmpFile({
131
+ path: file.replace(/\.tpl$/, ''),
132
+ content: getFileContent(file)
133
+ .replace('__USE_MODEL__', api.isPluginEnable('model')
134
+ ? `import { useModel } from '@@/plugin/model'`
135
+ : `const useModel = null;`)
136
+ .replace(/from 'qiankun'/g, `from '${(0, path_1.dirname)(require.resolve('qiankun/package'))}'`)
137
+ .replace(/from 'lodash\//g, `from '${(0, path_1.dirname)(require.resolve('lodash/package'))}/`),
138
+ });
139
+ });
140
+ });
141
+ };
package/dist/qiankun.js CHANGED
@@ -1,5 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = (api) => {
4
- api;
4
+ api.describe({
5
+ config: {
6
+ schema(joi) {
7
+ return joi.object().keys({
8
+ slave: joi.object(),
9
+ master: joi.object(),
10
+ });
11
+ },
12
+ },
13
+ });
14
+ api.addRuntimePluginKey(() => ['qiankun']);
15
+ api.registerPlugins([
16
+ require.resolve('./qiankun/master'),
17
+ require.resolve('./qiankun/slave'),
18
+ ]);
5
19
  };
package/dist/request.js CHANGED
@@ -1,5 +1,304 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@umijs/utils");
4
+ const path_1 = require("path");
3
5
  exports.default = (api) => {
4
- api;
6
+ api.describe({
7
+ key: 'request',
8
+ config: {
9
+ schema: (joi) => {
10
+ return joi.object();
11
+ },
12
+ },
13
+ enableBy: api.EnableBy.config,
14
+ });
15
+ api.addRuntimePluginKey(() => ['request']);
16
+ const requestTpl = `
17
+ import axios, {
18
+ type AxiosInstance,
19
+ type AxiosRequestConfig,
20
+ type AxiosResponse,
21
+ } from '{{{axiosPath}}}';
22
+ import useUmiRequest, { UseRequestProvider } from '{{{umiRequestPath}}}';
23
+ import { message, notification } from '{{{antdPkg}}}';
24
+ import { ApplyPluginsType } from 'umi';
25
+ import { getPluginManager } from '../core/plugin';
26
+
27
+ import {
28
+ BaseOptions,
29
+ BasePaginatedOptions,
30
+ BaseResult,
31
+ CombineService,
32
+ LoadMoreFormatReturn,
33
+ LoadMoreOptions,
34
+ LoadMoreOptionsWithFormat,
35
+ LoadMoreParams,
36
+ LoadMoreResult,
37
+ OptionsWithFormat,
38
+ PaginatedFormatReturn,
39
+ PaginatedOptionsWithFormat,
40
+ PaginatedParams,
41
+ PaginatedResult,
42
+ } from '{{{umiRequestPath}}}/es/types';
43
+
44
+ type ResultWithData< T = any > = { data?: T; [key: string]: any };
45
+
46
+ function useRequest<
47
+ R = any,
48
+ P extends any[] = any,
49
+ U = any,
50
+ UU extends U = any,
51
+ >(
52
+ service: CombineService<R, P>,
53
+ options: OptionsWithFormat<R, P, U, UU>,
54
+ ): BaseResult<U, P>;
55
+ function useRequest<R extends ResultWithData = any, P extends any[] = any>(
56
+ service: CombineService<R, P>,
57
+ options?: BaseOptions<R['data'], P>,
58
+ ): BaseResult<R['data'], P>;
59
+ function useRequest<R extends LoadMoreFormatReturn = any, RR = any>(
60
+ service: CombineService<RR, LoadMoreParams<R>>,
61
+ options: LoadMoreOptionsWithFormat<R, RR>,
62
+ ): LoadMoreResult<R>;
63
+ function useRequest<
64
+ R extends ResultWithData<LoadMoreFormatReturn | any> = any,
65
+ RR extends R = any,
66
+ >(
67
+ service: CombineService<R, LoadMoreParams<R['data']>>,
68
+ options: LoadMoreOptions<RR['data']>,
69
+ ): LoadMoreResult<R['data']>;
70
+
71
+ function useRequest<R = any, Item = any, U extends Item = any>(
72
+ service: CombineService<R, PaginatedParams>,
73
+ options: PaginatedOptionsWithFormat<R, Item, U>,
74
+ ): PaginatedResult<Item>;
75
+ function useRequest<Item = any, U extends Item = any>(
76
+ service: CombineService<
77
+ ResultWithData<PaginatedFormatReturn<Item>>,
78
+ PaginatedParams
79
+ >,
80
+ options: BasePaginatedOptions<U>,
81
+ ): PaginatedResult<Item>;
82
+ function useRequest(service: any, options: any = {}) {
83
+ return useUmiRequest(service, {
84
+ formatResult: result => result?.data,
85
+ requestMethod: (requestOptions: any) => {
86
+ if (typeof requestOptions === 'string') {
87
+ return request(requestOptions);
88
+ }
89
+ if (typeof requestOptions === 'object') {
90
+ const { url, ...rest } = requestOptions;
91
+ return request(url, rest);
92
+ }
93
+ throw new Error('request options error');
94
+ },
95
+ ...options,
96
+ });
97
+ }
98
+
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;
126
+ [key: string]: any;
127
+ }
128
+ // resData 其实就是 response.data, response 则是 axios 的响应对象
129
+ interface IAdaptor {
130
+ (resData: any, response: AxiosResponse): IErrorInfo;
131
+ }
132
+
133
+ export interface RequestError extends Error {
134
+ data?: any;
135
+ info?: IErrorInfo;
136
+ }
137
+
138
+ interface IRequest {
139
+ (
140
+ url: string,
141
+ opts: AxiosRequestConfig & { skipErrorHandler?: boolean },
142
+ ): Promise<AxiosResponse<any, any>>;
143
+ }
144
+
145
+ interface IErrorHandler {
146
+ (error: RequestError, opts: AxiosRequestConfig & { skipErrorHandler?: boolean }, config: RequestConfig): void;
147
+ }
148
+
149
+ interface IFormatResultAdaptor {
150
+ (res: AxiosResponse): any;
151
+ }
152
+
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
+ let requestInstance: AxiosInstance;
208
+ let config: RequestConfig;
209
+ const getConfig = (): RequestConfig => {
210
+ if (config) return config;
211
+ config = getPluginManager().applyPlugins({
212
+ key: 'request',
213
+ type: ApplyPluginsType.modify,
214
+ initialValue: {},
215
+ });
216
+ return config;
217
+ };
218
+ const getRequestInstance = (): AxiosInstance => {
219
+ if (requestInstance) return requestInstance;
220
+ const config = getConfig();
221
+ requestInstance = axios.create(config);
222
+
223
+ // 当响应的数据 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;
235
+ }
236
+ return response;
237
+ })
238
+ return requestInstance;
239
+ };
240
+
241
+ const request: IRequest = (url, opts) => {
242
+ const requestInstance = getRequestInstance();
243
+ const config = getConfig();
244
+ return new Promise((resolve, reject) => {
245
+ requestInstance
246
+ .request({ ...opts, url })
247
+ .then((res) => {
248
+ const formatResultAdaptor =
249
+ config?.formatResultAdaptor || ((res) => res.data);
250
+ resolve(formatResultAdaptor(res));
251
+ })
252
+ .catch((error) => {
253
+ try {
254
+ const handler =
255
+ config.errorConfig?.errorHandler || defaultErrorHandler;
256
+ handler(error, opts, config);
257
+ } catch (e) {
258
+ reject(e);
259
+ }
260
+ });
261
+ });
262
+ };
263
+
264
+ export {
265
+ useRequest,
266
+ UseRequestProvider,
267
+ request,
268
+ };
269
+
270
+ export type {
271
+ AxiosInstance,
272
+ AxiosRequestConfig,
273
+ AxiosResponse,
274
+ };
275
+
276
+ `;
277
+ api.onGenerateFiles(() => {
278
+ var _a;
279
+ const umiRequestPath = (0, path_1.dirname)(require.resolve('@ahooksjs/use-request/package.json'));
280
+ const axiosPath = (0, path_1.dirname)(require.resolve('axios/package.json'));
281
+ const antdPkg =
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'));
285
+ api.writeTmpFile({
286
+ path: 'request.ts',
287
+ content: utils_1.Mustache.render(requestTpl, {
288
+ umiRequestPath,
289
+ axiosPath,
290
+ antdPkg,
291
+ }),
292
+ });
293
+ api.writeTmpFile({
294
+ path: 'index.ts',
295
+ content: `
296
+ export {
297
+ useRequest,
298
+ UseRequestProvider,
299
+ request,
300
+ } from './request';
301
+ `,
302
+ });
303
+ });
5
304
  };
@@ -0,0 +1,3 @@
1
+ import { IApi } from 'umi';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,38 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const child_process_1 = require("child_process");
23
+ const path = __importStar(require("path"));
24
+ 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');
30
+ /** 透过子进程建立 tailwindcss 服务,将生成的 css 写入 generatedPath */
31
+ const tailwind = (0, child_process_1.exec)(`${binPath} -i ${inputPath} -o ${generatedPath} --watch`, { cwd: api.cwd });
32
+ tailwind.on('error', (m) => {
33
+ api.logger.error('tailwindcss service encounter an error: ' + m);
34
+ });
35
+ /** 将生成的 css 文件加入到 import 中 */
36
+ api.addEntryImports(() => [{ source: generatedPath }]);
37
+ });
38
+ };
@@ -0,0 +1,3 @@
1
+ import { IApi } from 'umi';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
package/dist/unocss.js ADDED
@@ -0,0 +1,57 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const utils_1 = require("@umijs/utils");
26
+ const child_process_1 = require("child_process");
27
+ const fs = __importStar(require("fs"));
28
+ const path_1 = __importDefault(require("path"));
29
+ exports.default = (api) => {
30
+ api.describe({
31
+ key: 'unocss',
32
+ config: {
33
+ schema(Joi) {
34
+ return Joi.object({
35
+ watch: Joi.array(),
36
+ });
37
+ },
38
+ },
39
+ enableBy: api.EnableBy.config,
40
+ });
41
+ api.onStart(() => {
42
+ /** 由于 @unocss/cli 对设置文件进行了检查,因此加入需要 unocss.config.ts 设置的提示
43
+ * 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');
48
+ const watchDirs = api.config.unocss.watch;
49
+ /** 透过子进程建立 unocss 服务,将生成的 css 写入 generatedPath */
50
+ const unocss = (0, child_process_1.exec)(`${binPath} ${watchDirs.join(' ')} --out-file ${generatedPath} --watch`, { cwd: api.cwd });
51
+ unocss.on('error', (m) => {
52
+ api.logger.error('unocss service encounter an error: ' + m);
53
+ });
54
+ /** 将生成的 css 文件加入到 import 中 */
55
+ api.addEntryImports(() => [{ source: generatedPath }]);
56
+ });
57
+ };
@@ -0,0 +1,3 @@
1
+ import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
2
+ import * as t from '@umijs/bundler-utils/compiled/babel/types';
3
+ export declare function getIdentifierDeclaration(node: t.Node, path: Babel.NodePath): Babel.types.Node;
@@ -0,0 +1,34 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getIdentifierDeclaration = void 0;
23
+ const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
24
+ function getIdentifierDeclaration(node, path) {
25
+ if (t.isIdentifier(node) && path.scope.hasBinding(node.name)) {
26
+ let bindingNode = path.scope.getBinding(node.name).path.node;
27
+ if (t.isVariableDeclarator(bindingNode)) {
28
+ bindingNode = bindingNode.init;
29
+ }
30
+ return bindingNode;
31
+ }
32
+ return node;
33
+ }
34
+ exports.getIdentifierDeclaration = getIdentifierDeclaration;
@@ -0,0 +1,33 @@
1
+ export declare type IAddAntdLocales = (args: {
2
+ lang: string;
3
+ country: string;
4
+ }) => Promise<string[]>;
5
+ export interface IGetLocaleFileListOpts {
6
+ localeFolder: string;
7
+ separator?: string;
8
+ absSrcPath?: string;
9
+ absPagesPath?: string;
10
+ addAntdLocales: IAddAntdLocales;
11
+ resolveKey: string;
12
+ }
13
+ /**
14
+ * 获取 moment 包的 locale 名称
15
+ * @param lang 语言
16
+ * @param country 国家
17
+ * @param resolveKey 用来resolve的key,moment 或者 dayjs,为了使 dayjs 可以替换 moment
18
+ */
19
+ export declare const getMomentLocale: (lang: string, country: string, resolveKey: string) => {
20
+ momentLocale: string;
21
+ };
22
+ export declare const getAntdLocale: (lang: string, country: string) => string;
23
+ export interface IGetLocaleFileListResult {
24
+ lang: string;
25
+ country: string;
26
+ name: string;
27
+ paths: string[];
28
+ antdLocale: string[];
29
+ momentLocale: string;
30
+ }
31
+ export declare const getLocaleList: (opts: IGetLocaleFileListOpts) => Promise<IGetLocaleFileListResult[]>;
32
+ export declare const exactLocalePaths: (data: IGetLocaleFileListResult[]) => string[];
33
+ export declare function isNeedPolyfill(targets?: {}): boolean;