@umijs/plugins 4.0.0-canary.20220615.1 → 4.0.0-canary.20220624.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/dva.js +13 -1
- package/dist/initial-state.js +16 -13
- package/dist/layout.js +37 -5
- package/dist/request.js +9 -1
- package/dist/tailwindcss.js +24 -12
- package/package.json +5 -5
package/dist/dva.js
CHANGED
|
@@ -83,6 +83,8 @@ import React, { useRef } from 'react';
|
|
|
83
83
|
import { history, ApplyPluginsType, useAppData } from 'umi';
|
|
84
84
|
import { models } from './models';
|
|
85
85
|
|
|
86
|
+
let dvaApp: any;
|
|
87
|
+
|
|
86
88
|
export function RootContainer(props: any) {
|
|
87
89
|
const { pluginManager } = useAppData();
|
|
88
90
|
const app = useRef<any>();
|
|
@@ -107,10 +109,14 @@ export function RootContainer(props: any) {
|
|
|
107
109
|
},
|
|
108
110
|
},
|
|
109
111
|
);
|
|
112
|
+
dvaApp = app.current;
|
|
110
113
|
app.current.use(createLoading());
|
|
111
114
|
${((_b = api.config.dva) === null || _b === void 0 ? void 0 : _b.immer) ? `app.current.use(dvaImmer());` : ''}
|
|
112
115
|
${((_d = (_c = api.config.dva) === null || _c === void 0 ? void 0 : _c.immer) === null || _d === void 0 ? void 0 : _d.enableES5) ? `enableES5();` : ''}
|
|
113
116
|
${((_f = (_e = api.config.dva) === null || _e === void 0 ? void 0 : _e.immer) === null || _f === void 0 ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ''}
|
|
117
|
+
(runtimeDva.plugins || []).forEach((p) => {
|
|
118
|
+
app.current.use(p);
|
|
119
|
+
});
|
|
114
120
|
for (const id of Object.keys(models)) {
|
|
115
121
|
app.current.model({
|
|
116
122
|
namespace: models[id].namespace,
|
|
@@ -121,6 +127,10 @@ export function RootContainer(props: any) {
|
|
|
121
127
|
}
|
|
122
128
|
return <Provider store={app.current!._store}>{props.children}</Provider>;
|
|
123
129
|
}
|
|
130
|
+
|
|
131
|
+
export function getDvaApp() {
|
|
132
|
+
return dvaApp;
|
|
133
|
+
}
|
|
124
134
|
`,
|
|
125
135
|
context: {},
|
|
126
136
|
});
|
|
@@ -140,7 +150,9 @@ export function dataflowProvider(container, opts) {
|
|
|
140
150
|
api.writeTmpFile({
|
|
141
151
|
path: 'index.ts',
|
|
142
152
|
content: `
|
|
143
|
-
export { connect, useDispatch, useStore, useSelector } from 'dva'
|
|
153
|
+
export { connect, useDispatch, useStore, useSelector } from 'dva';
|
|
154
|
+
export { getDvaApp } from './dva';
|
|
155
|
+
`,
|
|
144
156
|
});
|
|
145
157
|
});
|
|
146
158
|
api.addTmpGenerateWatcherPaths(() => {
|
package/dist/initial-state.js
CHANGED
|
@@ -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,20 +78,21 @@ 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
|
-
const setInitialState = useCallback(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
const setInitialState = useCallback(
|
|
84
|
+
async (
|
|
85
|
+
initialState: InitialStateType | ((initialState: InitialStateType) => InitialStateType),
|
|
86
|
+
) => {
|
|
87
|
+
setState((s) => {
|
|
88
|
+
if (typeof initialState === 'function') {
|
|
89
|
+
return { ...s, initialState: initialState(s.initialState), loading: false };
|
|
90
|
+
}
|
|
91
|
+
return { ...s, initialState, loading: false };
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
[],
|
|
95
|
+
);
|
|
93
96
|
|
|
94
97
|
useEffect(() => {
|
|
95
98
|
refresh();
|
package/dist/layout.js
CHANGED
|
@@ -52,15 +52,22 @@ exports.default = (api) => {
|
|
|
52
52
|
return false;
|
|
53
53
|
});
|
|
54
54
|
const getPkgPath = () => {
|
|
55
|
-
// 如果
|
|
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);
|
|
59
59
|
}
|
|
60
|
+
const cwd = process.cwd();
|
|
61
|
+
// support APP_ROOT
|
|
62
|
+
if (pkgHasDep &&
|
|
63
|
+
api.cwd !== cwd &&
|
|
64
|
+
(0, fs_1.existsSync)((0, path_1.join)(cwd, 'node_modules', pkgHasDep, 'package.json'))) {
|
|
65
|
+
return (0, path_1.join)(cwd, 'node_modules', pkgHasDep);
|
|
66
|
+
}
|
|
60
67
|
// 如果项目中没有去找插件以来的
|
|
61
68
|
return (0, path_1.dirname)(require.resolve('@ant-design/pro-layout/package.json'));
|
|
62
69
|
};
|
|
63
|
-
const pkgPath = getPkgPath();
|
|
70
|
+
const pkgPath = (0, plugin_utils_1.winPath)(getPkgPath());
|
|
64
71
|
api.modifyAppData((memo) => {
|
|
65
72
|
const version = require(`${pkgPath}/package.json`).version;
|
|
66
73
|
memo.pluginLayout = {
|
|
@@ -84,10 +91,10 @@ exports.default = (api) => {
|
|
|
84
91
|
path: 'Layout.tsx',
|
|
85
92
|
content: `
|
|
86
93
|
import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteData, matchRoutes } from 'umi';
|
|
87
|
-
import { useMemo } from 'react';
|
|
88
|
-
import
|
|
94
|
+
import React, { useMemo } from 'react';
|
|
95
|
+
import {
|
|
89
96
|
ProLayout,
|
|
90
|
-
} from "${
|
|
97
|
+
} from "${pkgPath || '@ant-design/pro-layout'}";
|
|
91
98
|
import './Layout.less';
|
|
92
99
|
import Logo from './Logo';
|
|
93
100
|
import Exception from './Exception';
|
|
@@ -202,6 +209,31 @@ const { formatMessage } = useIntl();
|
|
|
202
209
|
);
|
|
203
210
|
}
|
|
204
211
|
`,
|
|
212
|
+
});
|
|
213
|
+
api.writeTmpFile({
|
|
214
|
+
path: 'index.ts',
|
|
215
|
+
content: `export type TempType = string`,
|
|
216
|
+
});
|
|
217
|
+
// 写入类型, RunTimeLayoutConfig 是 app.tsx 中 layout 配置的类型
|
|
218
|
+
// 对于动态 layout 配置很有用
|
|
219
|
+
api.writeTmpFile({
|
|
220
|
+
path: 'types.d.ts',
|
|
221
|
+
content: `
|
|
222
|
+
import type { ProLayoutProps } from "${pkgPath || '@ant-design/pro-layout'}";
|
|
223
|
+
${hasInitialStatePlugin
|
|
224
|
+
? `import type InitialStateType from '@@/plugin-initialState/@@initialState';
|
|
225
|
+
type InitDataType = ReturnType<typeof InitialStateType>;
|
|
226
|
+
`
|
|
227
|
+
: 'type InitDataType = any;'}
|
|
228
|
+
|
|
229
|
+
export type RunTimeLayoutConfig = (
|
|
230
|
+
initData: InitDataType,
|
|
231
|
+
) => ProLayoutProps & {
|
|
232
|
+
childrenRender?: (dom: JSX.Element, props: ProLayoutProps) => React.ReactNode,
|
|
233
|
+
unAccessible?: JSX.Element,
|
|
234
|
+
noFound?: JSX.Element,
|
|
235
|
+
};
|
|
236
|
+
`,
|
|
205
237
|
});
|
|
206
238
|
const iconsMap = Object.keys(api.appData.routes).reduce((memo, id) => {
|
|
207
239
|
const { icon } = api.appData.routes[id];
|
package/dist/request.js
CHANGED
|
@@ -272,6 +272,9 @@ export type {
|
|
|
272
272
|
AxiosInstance,
|
|
273
273
|
AxiosRequestConfig,
|
|
274
274
|
AxiosResponse,
|
|
275
|
+
IResponseInterceptor as ResponseInterceptor,
|
|
276
|
+
IRequestOptions as RequestOptions,
|
|
277
|
+
IRequest as Request,
|
|
275
278
|
};
|
|
276
279
|
|
|
277
280
|
`;
|
|
@@ -294,7 +297,12 @@ export type {
|
|
|
294
297
|
api.writeTmpFile({
|
|
295
298
|
path: 'types.d.ts',
|
|
296
299
|
content: `
|
|
297
|
-
export type {
|
|
300
|
+
export type {
|
|
301
|
+
RequestConfig,
|
|
302
|
+
AxiosInstance,
|
|
303
|
+
AxiosRequestConfig,
|
|
304
|
+
AxiosResponse,
|
|
305
|
+
ResponseInterceptor } from './request';
|
|
298
306
|
`,
|
|
299
307
|
});
|
|
300
308
|
api.writeTmpFile({
|
package/dist/tailwindcss.js
CHANGED
|
@@ -18,18 +18,30 @@ exports.default = (api) => {
|
|
|
18
18
|
const inputPath = (0, path_1.join)(api.cwd, 'tailwind.css');
|
|
19
19
|
const generatedPath = (0, path_1.join)(api.paths.absTmpPath, outputPath);
|
|
20
20
|
const binPath = (0, path_1.join)(api.cwd, 'node_modules/.bin/tailwind');
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
/** 透过子进程建立 tailwindcss 服务,将生成的 css 写入 generatedPath */
|
|
23
|
+
tailwind = (0, plugin_utils_1.crossSpawn)(`${binPath}`, [
|
|
24
|
+
'-i',
|
|
25
|
+
inputPath,
|
|
26
|
+
'-o',
|
|
27
|
+
generatedPath,
|
|
28
|
+
api.env === 'development' ? '--watch' : '',
|
|
29
|
+
], {
|
|
30
|
+
stdio: 'inherit',
|
|
31
|
+
});
|
|
32
|
+
tailwind.on('error', (m) => {
|
|
33
|
+
api.logger.error('tailwindcss service encounter an error: ' + m);
|
|
34
|
+
});
|
|
35
|
+
if (api.env === 'production') {
|
|
36
|
+
tailwind.on('exit', () => {
|
|
37
|
+
api.logger.info('tailwindcss service exited');
|
|
38
|
+
resolve();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
api.logger.info('tailwindcss service started');
|
|
43
|
+
resolve();
|
|
44
|
+
}
|
|
33
45
|
});
|
|
34
46
|
});
|
|
35
47
|
/** 将生成的 css 文件加入到 import 中 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20220624.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",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "pnpm tsc",
|
|
20
20
|
"build:deps": "umi-scripts bundleDeps",
|
|
21
|
-
"dev": "pnpm build --
|
|
21
|
+
"dev": "pnpm build --watch",
|
|
22
22
|
"test": "umi-scripts jest-turbo"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@ahooksjs/use-request": "^2.0.0",
|
|
26
26
|
"@ant-design/icons": "^4.7.0",
|
|
27
|
-
"@ant-design/pro-layout": "^7.0.1-beta.
|
|
28
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
27
|
+
"@ant-design/pro-layout": "^7.0.1-beta.20",
|
|
28
|
+
"@umijs/bundler-utils": "4.0.0-canary.20220624.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.
|
|
47
|
+
"umi": "4.0.0-canary.20220624.1"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|