@umijs/plugins 4.0.0-rc.9 → 4.0.0

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 CHANGED
@@ -1,14 +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
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
11
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
12
7
  const path_1 = require("path");
13
8
  const withTmpPath_1 = require("./utils/withTmpPath");
14
9
  exports.default = (api) => {
@@ -20,19 +15,29 @@ exports.default = (api) => {
20
15
  },
21
16
  enableBy: api.EnableBy.config,
22
17
  });
23
- api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
18
+ api.onGenerateFiles(async () => {
19
+ // allow enable access without access file
20
+ const hasAccessFile = ['js', 'jsx', 'ts', 'tsx'].some((ext) => fs_1.default.existsSync((0, path_1.join)(api.paths.absSrcPath, `access.${ext}`)));
24
21
  // runtime.tsx
25
22
  api.writeTmpFile({
26
23
  path: 'runtime.tsx',
27
24
  content: `
28
- import React from 'react';
29
- import accessFactory from '@/access';
25
+ import React from 'react';${hasAccessFile
26
+ ? `
27
+ import accessFactory from '@/access'
30
28
  import { useModel } from '@@/plugin-model';
29
+ `
30
+ : ''}
31
31
  import { AccessContext } from './context';
32
32
 
33
- function Provider(props) {
33
+ function Provider(props) {${hasAccessFile
34
+ ? `
34
35
  const { initialState } = useModel('@@initialState');
35
36
  const access = React.useMemo(() => accessFactory(initialState), [initialState]);
37
+ `
38
+ : `
39
+ const access = {};
40
+ `}
36
41
  return (
37
42
  <AccessContext.Provider value={access}>
38
43
  { props.children }
@@ -45,11 +50,11 @@ export function accessProvider(container) {
45
50
  }
46
51
  `,
47
52
  });
48
- // index.ts
53
+ // index.tsx
49
54
  api.writeTmpFile({
50
- path: 'index.ts',
55
+ path: 'index.tsx',
51
56
  content: `
52
- import React from 'react';
57
+ import React, { PropsWithChildren } from 'react';
53
58
  import { AccessContext } from './context';
54
59
  import type { IRoute } from 'umi';
55
60
 
@@ -61,12 +66,12 @@ export interface AccessProps {
61
66
  accessible: boolean;
62
67
  fallback?: React.ReactNode;
63
68
  }
64
- export const Access: React.FC<AccessProps> = (props) => {
69
+ export const Access: React.FC<PropsWithChildren<AccessProps>> = (props) => {
65
70
  if (process.env.NODE_ENV === 'development' && typeof props.accessible !== 'boolean') {
66
71
  throw new Error('[access] the \`accessible\` property on <Access /> should be a boolean');
67
72
  }
68
73
 
69
- return props.accessible ? props.children : props.fallback;
74
+ return <>{ props.accessible ? props.children : props.fallback }</>;
70
75
  };
71
76
 
72
77
  export const useAccessMarkedRoutes = (routes: IRoute[]) => {
@@ -80,7 +85,7 @@ export const useAccessMarkedRoutes = (routes: IRoute[]) => {
80
85
 
81
86
  // check access code
82
87
  if (typeof accessCode === 'string') {
83
- const detector = access[route.access];
88
+ const detector = access[accessCode];
84
89
 
85
90
  if (typeof detector === 'function') {
86
91
  route.unaccessible = !detector(route);
@@ -92,8 +97,8 @@ export const useAccessMarkedRoutes = (routes: IRoute[]) => {
92
97
  }
93
98
 
94
99
  // check children access code
95
- if (route.routes) {
96
- const isNoAccessibleChild = !route.routes.reduce((hasAccessibleChild, child) => {
100
+ if (route.children?.length) {
101
+ const isNoAccessibleChild = !route.children.reduce((hasAccessibleChild, child) => {
97
102
  process(child, accessCode);
98
103
 
99
104
  return hasAccessibleChild || !child.unaccessible;
@@ -123,7 +128,7 @@ import React from 'react';
123
128
  export const AccessContext = React.createContext<any>(null);
124
129
  `,
125
130
  });
126
- }));
131
+ });
127
132
  api.addRuntimePlugin(() => {
128
133
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
129
134
  });
package/dist/analytics.js CHANGED
@@ -20,7 +20,7 @@ exports.default = (api) => {
20
20
  return `
21
21
  (function() {
22
22
  var hm = document.createElement('script');
23
- hm.src = 'https://hm.baidu.com/hm.js?${code}';
23
+ hm.src = '//hm.baidu.com/hm.js?${code}';
24
24
  var s = document.getElementsByTagName('script')[0];
25
25
  s.parentNode.insertBefore(hm, s);
26
26
  })();
package/dist/antd.js CHANGED
@@ -30,7 +30,12 @@ exports.default = (api) => {
30
30
  });
31
31
  },
32
32
  },
33
- enableBy: api.EnableBy.config,
33
+ enableBy({ userConfig }) {
34
+ // 由于本插件有 api.modifyConfig 的调用,以及 Umi 框架的限制
35
+ // 在其他插件中通过 api.modifyDefaultConfig 设置 antd 并不能让 api.modifyConfig 生效
36
+ // 所以这里通过环境变量来判断是否启用
37
+ return process.env.UMI_PLUGIN_ANTD_ENABLE || userConfig.antd;
38
+ },
34
39
  });
35
40
  function checkPkgPath() {
36
41
  if (!pkgPath) {
@@ -48,21 +53,31 @@ exports.default = (api) => {
48
53
  });
49
54
  api.modifyConfig((memo) => {
50
55
  checkPkgPath();
56
+ const antd = memo.antd || {};
57
+ // defaultConfig 的取值在 config 之后,所以改用环境变量传默认值
58
+ if (process.env.UMI_PLUGIN_ANTD_ENABLE) {
59
+ const { defaultConfig } = JSON.parse(process.env.UMI_PLUGIN_ANTD_ENABLE);
60
+ Object.assign(antd, defaultConfig);
61
+ }
51
62
  // antd import
52
63
  memo.alias.antd = pkgPath;
53
64
  // moment > dayjs
54
- if (memo.antd.dayjs) {
65
+ if (antd.dayjs) {
55
66
  memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
56
67
  }
57
68
  // dark mode & compact mode
58
- if (memo.antd.dark || memo.antd.compact) {
69
+ if (antd.dark || antd.compact) {
59
70
  const { getThemeVariables } = require('antd/dist/theme');
60
- memo.theme = Object.assign(Object.assign({}, getThemeVariables(memo.antd)), memo.theme);
71
+ memo.theme = {
72
+ ...getThemeVariables(antd),
73
+ ...memo.theme,
74
+ };
61
75
  }
62
- return memo;
63
- });
64
- api.modifyConfig((memo) => {
65
- memo.theme = Object.assign({ 'root-entry-name': 'default' }, memo.theme);
76
+ // antd theme
77
+ memo.theme = {
78
+ 'root-entry-name': 'default',
79
+ ...memo.theme,
80
+ };
66
81
  return memo;
67
82
  });
68
83
  // babel-plugin-import
@@ -77,6 +92,7 @@ exports.default = (api) => {
77
92
  libraryDirectory: 'es',
78
93
  style: style === 'less' ? true : 'css',
79
94
  },
95
+ 'antd',
80
96
  ],
81
97
  ]
82
98
  : [];
@@ -88,6 +104,7 @@ exports.default = (api) => {
88
104
  api.writeTmpFile({
89
105
  path: `runtime.tsx`,
90
106
  content: plugin_utils_1.Mustache.render(`
107
+ import React from 'react';
91
108
  import { ConfigProvider, Modal, message, notification } from 'antd';
92
109
 
93
110
  export function rootContainer(container) {
package/dist/dva.js CHANGED
@@ -25,11 +25,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getAllModels = exports.getModelUtil = void 0;
27
27
  const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
28
+ const utils_1 = require("@umijs/utils");
28
29
  const path_1 = require("path");
29
30
  const plugin_utils_1 = require("umi/plugin-utils");
30
31
  const modelUtils_1 = require("./utils/modelUtils");
31
32
  const withTmpPath_1 = require("./utils/withTmpPath");
32
- const utils_1 = require("@umijs/utils");
33
33
  exports.default = (api) => {
34
34
  const pkgPath = (0, path_1.join)(__dirname, '../libs/dva.ts');
35
35
  api.describe({
@@ -80,15 +80,22 @@ import dvaImmer, { enableES5, enableAllPlugins } from '${(0, utils_1.winPath)(re
80
80
  `
81
81
  : ''}
82
82
  import React, { useRef } from 'react';
83
- import { history } from 'umi';
83
+ import { history, ApplyPluginsType, useAppData } from 'umi';
84
84
  import { models } from './models';
85
85
 
86
86
  export function RootContainer(props: any) {
87
+ const { pluginManager } = useAppData();
87
88
  const app = useRef<any>();
89
+ const runtimeDva = pluginManager.applyPlugins({
90
+ key: 'dva',
91
+ type: ApplyPluginsType.modify,
92
+ initialValue: {},
93
+ });
88
94
  if (!app.current) {
89
95
  app.current = create(
90
96
  {
91
97
  history,
98
+ ...(runtimeDva.config || {}),
92
99
  },
93
100
  {
94
101
  initialReducer: {},
@@ -105,7 +112,10 @@ export function RootContainer(props: any) {
105
112
  ${((_d = (_c = api.config.dva) === null || _c === void 0 ? void 0 : _c.immer) === null || _d === void 0 ? void 0 : _d.enableES5) ? `enableES5();` : ''}
106
113
  ${((_f = (_e = api.config.dva) === null || _e === void 0 ? void 0 : _e.immer) === null || _f === void 0 ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ''}
107
114
  for (const id of Object.keys(models)) {
108
- app.current.model(models[id].model);
115
+ app.current.model({
116
+ namespace: models[id].namespace,
117
+ ...models[id].model,
118
+ });
109
119
  }
110
120
  app.current.start();
111
121
  }
@@ -139,6 +149,7 @@ export { connect, useDispatch, useStore, useSelector } from 'dva';`,
139
149
  api.addRuntimePlugin(() => {
140
150
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
141
151
  });
152
+ api.addRuntimePluginKey(() => ['dva']);
142
153
  // dva list model
143
154
  api.registerCommand({
144
155
  name: 'dva',
@@ -14,7 +14,12 @@ exports.default = (api) => {
14
14
  });
15
15
  api.register({
16
16
  key: 'addExtraModels',
17
- fn: () => [(0, withTmpPath_1.withTmpPath)({ api, path: '@@initialState.ts' })],
17
+ fn: () => [
18
+ (0, withTmpPath_1.withTmpPath)({
19
+ api,
20
+ path: '@@initialState.ts#{"namespace":"@@initialState"}',
21
+ }),
22
+ ],
18
23
  });
19
24
  api.addRuntimePluginKey(() => ['getInitialState']);
20
25
  api.addRuntimePlugin(() => {
@@ -30,8 +35,8 @@ exports.default = (api) => {
30
35
  import React from 'react';
31
36
  import { useModel } from '@@/plugin-model';
32
37
  ${loading
33
- ? `import Loading from ${loading}`
34
- : `function Loading() { return <div>loading</div>; }`}
38
+ ? `import Loading from '${loading}'`
39
+ : `function Loading() { return <div />; }`}
35
40
  export default function InitialStateProvider(props: any) {
36
41
  const appLoaded = React.useRef(false);
37
42
  const { loading = false } = useModel("@@initialState") || {};
@@ -55,8 +60,10 @@ export default function InitialStateProvider(props: any) {
55
60
  import { useState, useEffect, useCallback } from 'react';
56
61
  import { getInitialState } from '@/app';
57
62
 
63
+ export type InitialStateType = Awaited<ReturnType<typeof getInitialState>> | undefined;
64
+
58
65
  const initState = {
59
- initialState: undefined,
66
+ initialState: undefined as InitialStateType,
60
67
  loading: true,
61
68
  error: undefined,
62
69
  };
@@ -71,8 +78,6 @@ export default () => {
71
78
  } catch (e) {
72
79
  setState((s) => ({ ...s, error: e, loading: false }));
73
80
  }
74
- // [?]
75
- // await sleep(10);
76
81
  }, []);
77
82
 
78
83
  const setInitialState = useCallback(async (initialState) => {
@@ -82,8 +87,6 @@ export default () => {
82
87
  }
83
88
  return { ...s, initialState, loading: false };
84
89
  });
85
- // [?]
86
- // await sleep(10)
87
90
  }, []);
88
91
 
89
92
  useEffect(() => {
@@ -107,7 +110,7 @@ export default () => ({ loading: false, refresh: () => {} })
107
110
  content: `
108
111
  import React from 'react';
109
112
  import Provider from './Provider';
110
- export function innerProvider(container) {
113
+ export function dataflowProvider(container) {
111
114
  return <Provider>{ container }</Provider>;
112
115
  }
113
116
  `,
package/dist/layout.js CHANGED
@@ -22,15 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  const allIcons = __importStar(require("@ant-design/icons"));
30
- const assert_1 = __importDefault(require("assert"));
27
+ const fs_1 = require("fs");
31
28
  const path_1 = require("path");
32
29
  const plugin_utils_1 = require("umi/plugin-utils");
33
- const resolveProjectDep_1 = require("./utils/resolveProjectDep");
34
30
  const withTmpPath_1 = require("./utils/withTmpPath");
35
31
  exports.default = (api) => {
36
32
  api.describe({
@@ -43,11 +39,28 @@ exports.default = (api) => {
43
39
  },
44
40
  enableBy: api.EnableBy.config,
45
41
  });
46
- const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
47
- pkg: api.pkg,
48
- cwd: api.cwd,
49
- dep: '@ant-design/pro-layout',
50
- }) || (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
42
+ /**
43
+ * 优先去找 '@alipay/tech-ui',保证稳定性
44
+ */
45
+ const depList = ['@alipay/tech-ui', '@ant-design/pro-layout'];
46
+ const pkgHasDep = depList.find((dep) => {
47
+ var _a, _b;
48
+ const { pkg } = api;
49
+ if (((_a = pkg.dependencies) === null || _a === void 0 ? void 0 : _a[dep]) || ((_b = pkg.devDependencies) === null || _b === void 0 ? void 0 : _b[dep])) {
50
+ return true;
51
+ }
52
+ return false;
53
+ });
54
+ const getPkgPath = () => {
55
+ // 如果 layout 和 techui 至少有一个在,找到他们的地址
56
+ if (pkgHasDep &&
57
+ (0, fs_1.existsSync)((0, path_1.join)(api.cwd, 'node_modules', pkgHasDep, 'package.json'))) {
58
+ return (0, path_1.join)(api.cwd, 'node_modules', pkgHasDep);
59
+ }
60
+ // 如果项目中没有去找插件以来的
61
+ return (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
62
+ };
63
+ const pkgPath = (0, plugin_utils_1.winPath)(getPkgPath());
51
64
  api.modifyAppData((memo) => {
52
65
  const version = require(`${pkgPath}/package.json`).version;
53
66
  memo.pluginLayout = {
@@ -57,8 +70,11 @@ exports.default = (api) => {
57
70
  return memo;
58
71
  });
59
72
  api.modifyConfig((memo) => {
60
- // import from @ant-design/pro-layout
61
- memo.alias['@ant-design/pro-layout'] = pkgPath;
73
+ // 只在没有自行依赖 @ant-design/pro-layout 或 @alipay/tech-ui 时
74
+ // 才使用插件中提供的 @ant-design/pro-layout
75
+ if (!pkgHasDep) {
76
+ memo.alias['@ant-design/pro-layout'] = pkgPath;
77
+ }
62
78
  return memo;
63
79
  });
64
80
  api.onGenerateFiles(() => {
@@ -69,9 +85,9 @@ exports.default = (api) => {
69
85
  content: `
70
86
  import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteData, matchRoutes } from 'umi';
71
87
  import { useMemo } from 'react';
72
- import ProLayout, {
73
- PageLoading,
74
- } from '@ant-design/pro-layout';
88
+ import {
89
+ ProLayout,
90
+ } from "${pkgPath || '@ant-design/pro-layout'}";
75
91
  import './Layout.less';
76
92
  import Logo from './Logo';
77
93
  import Exception from './Exception';
@@ -137,7 +153,8 @@ const { formatMessage } = useIntl();
137
153
  }
138
154
  if (menuItemProps.path && location.pathname !== menuItemProps.path) {
139
155
  return (
140
- <Link to={menuItemProps.path} target={menuItemProps.target}>
156
+ // handle wildcard route path, for example /slave/* from qiankun
157
+ <Link to={menuItemProps.path.replace('/*', '')} target={menuItemProps.target}>
141
158
  {defaultDom}
142
159
  </Link>
143
160
  );
@@ -185,14 +202,31 @@ const { formatMessage } = useIntl();
185
202
  );
186
203
  }
187
204
  `,
205
+ });
206
+ // 写入类型, RunTimeLayoutConfig 是 app.tsx 中 layout 配置的类型
207
+ // 对于动态 layout 配置很有用
208
+ api.writeTmpFile({
209
+ path: 'index.ts',
210
+ content: `
211
+ import type { ProLayoutProps } from "${pkgPath || '@ant-design/pro-layout'}";
212
+ ${hasInitialStatePlugin
213
+ ? `import { Models } from '@@/plugin-model/useModel';
214
+ type InitDataType = Models<'@@initialState'>;
215
+ `
216
+ : 'type InitDataType = any;'}
217
+
218
+ export type RunTimeLayoutConfig = (
219
+ initData: InitDataType,
220
+ ) => BasicLayoutProps & {
221
+ childrenRender?: (dom: JSX.Element, props: ProLayoutProps) => React.ReactNode,
222
+ unAccessible?: JSX.Element,
223
+ noFound?: JSX.Element,
224
+ };`,
188
225
  });
189
226
  const iconsMap = Object.keys(api.appData.routes).reduce((memo, id) => {
190
227
  const { icon } = api.appData.routes[id];
191
228
  if (icon) {
192
229
  const upperIcon = plugin_utils_1.lodash.upperFirst(plugin_utils_1.lodash.camelCase(icon));
193
- (0, assert_1.default)(
194
- // @ts-ignore
195
- allIcons[upperIcon] || allIcons[`${upperIcon}Outlined`], `Icon ${upperIcon} is not found`);
196
230
  // @ts-ignore
197
231
  if (allIcons[upperIcon]) {
198
232
  memo[upperIcon] = true;
@@ -237,7 +271,9 @@ export function patchRoutes({ routes }) {
237
271
  const { icon } = routes[key];
238
272
  if (icon && typeof icon === 'string') {
239
273
  const upperIcon = formatIcon(icon);
240
- routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
274
+ if (icons[upperIcon] || icons[upperIcon + 'Outlined']) {
275
+ routes[key].icon = React.createElement(icons[upperIcon] || icons[upperIcon + 'Outlined']);
276
+ }
241
277
  }
242
278
  });
243
279
  }
package/dist/locale.js CHANGED
@@ -1,13 +1,4 @@
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.packageNormalize = void 0;
13
4
  const fs_1 = require("fs");
@@ -58,9 +49,9 @@ exports.default = (api) => {
58
49
  },
59
50
  ]
60
51
  : []);
61
- const addAntdLocales = (args) => __awaiter(void 0, void 0, void 0, function* () {
52
+ const addAntdLocales = async (args) => {
62
53
  var _a;
63
- return yield api.applyPlugins({
54
+ return await api.applyPlugins({
64
55
  key: 'addAntdLocales',
65
56
  type: api.ApplyPluginsType.add,
66
57
  initialValue: [
@@ -68,29 +59,32 @@ exports.default = (api) => {
68
59
  ],
69
60
  args,
70
61
  });
71
- });
72
- const getList = (resolveKey) => __awaiter(void 0, void 0, void 0, function* () {
73
- var _b;
62
+ };
63
+ const getList = async (resolveKey) => {
64
+ var _a;
74
65
  const { paths } = api;
75
66
  return (0, localeUtils_1.getLocaleList)({
76
67
  localeFolder: 'locales',
77
- separator: (_b = api.config.locale) === null || _b === void 0 ? void 0 : _b.baseSeparator,
68
+ separator: (_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.baseSeparator,
78
69
  absSrcPath: paths.absSrcPath,
79
70
  absPagesPath: paths.absPagesPath,
80
71
  addAntdLocales,
81
72
  resolveKey,
82
73
  });
83
- });
84
- api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
85
- var _c, _d, _e, _f;
74
+ };
75
+ api.onGenerateFiles(async () => {
76
+ var _a, _b, _c, _d;
86
77
  const localeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/locale.tpl'), 'utf-8');
87
78
  // moment2dayjs
88
79
  const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
89
80
  const momentPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`)));
90
81
  const EventEmitterPkg = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('event-emitter/package')));
91
- const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = Object.assign(Object.assign({}, defaultConfig), api.config.locale);
92
- const defaultLocale = ((_c = api.config.locale) === null || _c === void 0 ? void 0 : _c.default) || `zh${baseSeparator}CN`;
93
- const localeList = yield getList(resolveKey);
82
+ const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = {
83
+ ...defaultConfig,
84
+ ...api.config.locale,
85
+ };
86
+ const defaultLocale = ((_a = api.config.locale) === null || _a === void 0 ? void 0 : _a.default) || `zh${baseSeparator}CN`;
87
+ const localeList = await getList(resolveKey);
94
88
  const momentLocales = localeList
95
89
  .map(({ momentLocale }) => momentLocale)
96
90
  .filter((locale) => locale);
@@ -100,7 +94,7 @@ exports.default = (api) => {
100
94
  let MomentLocales = momentLocales;
101
95
  let DefaultMomentLocale = '';
102
96
  // set moment default accounding to locale.default
103
- if (!MomentLocales.length && ((_d = api.config.locale) === null || _d === void 0 ? void 0 : _d.default)) {
97
+ if (!MomentLocales.length && ((_b = api.config.locale) === null || _b === void 0 ? void 0 : _b.default)) {
104
98
  const [lang, country = ''] = defaultLocale.split(baseSeparator);
105
99
  const { momentLocale } = (0, localeUtils_1.getMomentLocale)(lang, country, resolveKey);
106
100
  if (momentLocale) {
@@ -110,9 +104,9 @@ exports.default = (api) => {
110
104
  }
111
105
  let DefaultAntdLocales = [];
112
106
  // set antd default locale
113
- if (!antdLocales.length && ((_e = api.config.locale) === null || _e === void 0 ? void 0 : _e.antd)) {
107
+ if (!antdLocales.length && ((_c = api.config.locale) === null || _c === void 0 ? void 0 : _c.antd)) {
114
108
  const [lang, country = ''] = defaultLocale.split(baseSeparator);
115
- DefaultAntdLocales = plugin_utils_1.lodash.uniq(yield addAntdLocales({
109
+ DefaultAntdLocales = plugin_utils_1.lodash.uniq(await addAntdLocales({
116
110
  lang,
117
111
  country,
118
112
  }));
@@ -148,16 +142,20 @@ exports.default = (api) => {
148
142
  UseLocalStorage: !!useLocalStorage,
149
143
  LocaleDir: localeDirName,
150
144
  ExistLocaleDir: (0, fs_1.existsSync)(localeDirPath),
151
- LocaleList: localeList.map((locale) => (Object.assign(Object.assign({}, locale), { antdLocale: locale.antdLocale.map((antdLocale, index) => ({
145
+ LocaleList: localeList.map((locale) => ({
146
+ ...locale,
147
+ antdLocale: locale.antdLocale.map((antdLocale, index) => ({
152
148
  locale: antdLocale,
153
149
  index: index,
154
- })), paths: locale.paths.map((path, index) => ({
150
+ })),
151
+ paths: locale.paths.map((path, index) => ({
155
152
  path,
156
153
  index,
157
- })) }))),
154
+ })),
155
+ })),
158
156
  Antd: !!antd,
159
157
  DefaultLocale: JSON.stringify(defaultLocale),
160
- warningPkgPath: (0, plugin_utils_1.winPath)(require.resolve('warning/package')),
158
+ warningPkgPath: (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('warning/package'))),
161
159
  reactIntlPkgPath,
162
160
  }),
163
161
  });
@@ -177,25 +175,25 @@ exports.default = (api) => {
177
175
  Antd: !!antd,
178
176
  LocaleList: localeList,
179
177
  ShowSelectLang: localeList.length > 1 && !!antd,
180
- antdFiles: ((_f = api.config) === null || _f === void 0 ? void 0 : _f.ssr) ? 'lib' : 'es',
178
+ antdFiles: ((_d = api.config) === null || _d === void 0 ? void 0 : _d.ssr) ? 'lib' : 'es',
181
179
  }),
182
180
  });
183
181
  // index.ts
184
182
  api.writeTmpFile({
185
183
  path: 'index.ts',
186
184
  content: `
187
- export { setLocale, getLocale, useIntl, formatMessage, FormattedMessage } from './localeExports.ts';
185
+ export { setLocale, getLocale, useIntl, injectIntl, formatMessage, FormattedMessage } from './localeExports.ts';
188
186
  export { SelectLang } from './SelectLang.tsx';
189
187
  `,
190
188
  });
191
- }));
189
+ });
192
190
  // Runtime Plugin
193
191
  api.addRuntimePlugin(() => [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]);
194
192
  api.addRuntimePluginKey(() => ['locale']);
195
193
  // watch locale files
196
- api.addTmpGenerateWatcherPaths(() => __awaiter(void 0, void 0, void 0, function* () {
194
+ api.addTmpGenerateWatcherPaths(async () => {
197
195
  const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
198
- const localeList = yield getList(resolveKey);
196
+ const localeList = await getList(resolveKey);
199
197
  return (0, localeUtils_1.exactLocalePaths)(localeList);
200
- }));
198
+ });
201
199
  };
package/dist/model.js CHANGED
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
36
27
  const fs_1 = require("fs");
@@ -49,17 +40,8 @@ exports.default = (api) => {
49
40
  },
50
41
  enableBy: api.EnableBy.config,
51
42
  });
52
- api.modifyAppData((memo) => __awaiter(void 0, void 0, void 0, function* () {
53
- const models = yield getAllModels(api);
54
- memo.pluginModel = {
55
- models,
56
- };
57
- return memo;
58
- }));
59
- api.onGenerateFiles((args) => __awaiter(void 0, void 0, void 0, function* () {
60
- const models = args.isFirstTime
61
- ? api.appData.pluginModel.models
62
- : yield getAllModels(api);
43
+ api.onGenerateFiles(async () => {
44
+ const models = await getAllModels(api);
63
45
  // model.ts
64
46
  api.writeTmpFile({
65
47
  path: 'model.ts',
@@ -94,7 +76,7 @@ export function dataflowProvider(container, opts) {
94
76
  }
95
77
  `,
96
78
  });
97
- }));
79
+ });
98
80
  api.addTmpGenerateWatcherPaths(() => {
99
81
  return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
100
82
  });
@@ -102,19 +84,18 @@ export function dataflowProvider(container, opts) {
102
84
  return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
103
85
  });
104
86
  };
105
- function getAllModels(api) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- const extraModels = yield api.applyPlugins({
108
- key: 'addExtraModels',
109
- type: api.ApplyPluginsType.add,
110
- initialValue: [],
111
- });
112
- return new modelUtils_1.ModelUtils(api, {
113
- astTest({ node }) {
114
- return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
115
- },
116
- }).getAllModels({
117
- extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
118
- });
87
+ async function getAllModels(api) {
88
+ const extraModels = await api.applyPlugins({
89
+ key: 'addExtraModels',
90
+ type: api.ApplyPluginsType.add,
91
+ initialValue: [],
92
+ });
93
+ return new modelUtils_1.ModelUtils(api, {
94
+ astTest({ node }) {
95
+ return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
96
+ },
97
+ }).getAllModels({
98
+ sort: {},
99
+ extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
119
100
  });
120
101
  }