@umijs/plugins 4.0.0-canary.20220614.2 → 4.0.0-canary.20220620.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.
@@ -60,8 +60,10 @@ export default function InitialStateProvider(props: any) {
60
60
  import { useState, useEffect, useCallback } from 'react';
61
61
  import { getInitialState } from '@/app';
62
62
 
63
+ export type InitialStateType = Awaited<ReturnType<typeof getInitialState>> | undefined;
64
+
63
65
  const initState = {
64
- initialState: undefined,
66
+ initialState: undefined as InitialStateType,
65
67
  loading: true,
66
68
  error: undefined,
67
69
  };
@@ -76,8 +78,6 @@ export default () => {
76
78
  } catch (e) {
77
79
  setState((s) => ({ ...s, error: e, loading: false }));
78
80
  }
79
- // [?]
80
- // await sleep(10);
81
81
  }, []);
82
82
 
83
83
  const setInitialState = useCallback(async (initialState) => {
@@ -87,8 +87,6 @@ export default () => {
87
87
  }
88
88
  return { ...s, initialState, loading: false };
89
89
  });
90
- // [?]
91
- // await sleep(10)
92
90
  }, []);
93
91
 
94
92
  useEffect(() => {
package/dist/layout.js CHANGED
@@ -52,7 +52,7 @@ exports.default = (api) => {
52
52
  return false;
53
53
  });
54
54
  const getPkgPath = () => {
55
- // 如果 layout 和 techui至少有一个在,找到他们的地址
55
+ // 如果 layout 和 techui 至少有一个在,找到他们的地址
56
56
  if (pkgHasDep &&
57
57
  (0, fs_1.existsSync)((0, path_1.join)(api.cwd, 'node_modules', pkgHasDep, 'package.json'))) {
58
58
  return (0, path_1.join)(api.cwd, 'node_modules', pkgHasDep);
@@ -60,7 +60,7 @@ exports.default = (api) => {
60
60
  // 如果项目中没有去找插件以来的
61
61
  return (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
62
62
  };
63
- const pkgPath = getPkgPath();
63
+ const pkgPath = (0, plugin_utils_1.winPath)(getPkgPath());
64
64
  api.modifyAppData((memo) => {
65
65
  const version = require(`${pkgPath}/package.json`).version;
66
66
  memo.pluginLayout = {
@@ -87,7 +87,7 @@ import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteData, match
87
87
  import { useMemo } from 'react';
88
88
  import {
89
89
  ProLayout,
90
- } from "${pkgHasDep || '@ant-design/pro-layout'}";
90
+ } from "${pkgPath || '@ant-design/pro-layout'}";
91
91
  import './Layout.less';
92
92
  import Logo from './Logo';
93
93
  import Exception from './Exception';
@@ -202,6 +202,26 @@ const { formatMessage } = useIntl();
202
202
  );
203
203
  }
204
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
+ };`,
205
225
  });
206
226
  const iconsMap = Object.keys(api.appData.routes).reduce((memo, id) => {
207
227
  const { icon } = api.appData.routes[id];
package/dist/request.js CHANGED
@@ -272,6 +272,8 @@ export type {
272
272
  AxiosInstance,
273
273
  AxiosRequestConfig,
274
274
  AxiosResponse,
275
+ IRequestOptions as RequestOptions,
276
+ IRequest as Request,
275
277
  };
276
278
 
277
279
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-canary.20220614.2",
3
+ "version": "4.0.0-canary.20220620.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,7 +25,7 @@
25
25
  "@ahooksjs/use-request": "^2.0.0",
26
26
  "@ant-design/icons": "^4.7.0",
27
27
  "@ant-design/pro-layout": "^7.0.1-beta.17",
28
- "@umijs/bundler-utils": "4.0.0-canary.20220614.2",
28
+ "@umijs/bundler-utils": "4.0.0-canary.20220620.1",
29
29
  "antd-dayjs-webpack-plugin": "^1.0.6",
30
30
  "axios": "^0.27.2",
31
31
  "babel-plugin-import": "^1.13.5",
@@ -44,7 +44,7 @@
44
44
  "warning": "^4.0.3"
45
45
  },
46
46
  "devDependencies": {
47
- "umi": "4.0.0-canary.20220614.2"
47
+ "umi": "4.0.0-canary.20220620.1"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"