@umijs/plugins 4.0.0-rc.1 → 4.0.0-rc.10
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 +58 -1
- package/dist/antd.js +24 -8
- package/dist/dva.js +18 -1
- package/dist/initial-state.js +1 -1
- package/dist/layout.js +64 -9
- package/dist/locale.js +33 -35
- package/dist/model.js +5 -1
- package/dist/moment2dayjs.js +4 -4
- package/dist/qiankun/master.js +3 -3
- package/dist/qiankun/slave.js +16 -18
- package/dist/request.js +7 -6
- package/dist/tailwindcss.js +31 -29
- package/dist/unocss.js +15 -33
- package/dist/utils/astUtils.js +5 -1
- package/dist/utils/localeUtils.js +10 -10
- package/dist/utils/modelUtils.js +8 -4
- package/dist/utils/withTmpPath.js +2 -2
- package/libs/locale/localeExports.tpl +6 -6
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +0 -9
- package/package.json +10 -8
package/dist/access.js
CHANGED
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
const path_1 = require("path");
|
|
13
13
|
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
14
14
|
exports.default = (api) => {
|
|
15
|
-
// TODO: route access
|
|
16
15
|
api.describe({
|
|
17
16
|
config: {
|
|
18
17
|
schema(joi) {
|
|
@@ -52,10 +51,68 @@ export function accessProvider(container) {
|
|
|
52
51
|
content: `
|
|
53
52
|
import React from 'react';
|
|
54
53
|
import { AccessContext } from './context';
|
|
54
|
+
import type { IRoute } from 'umi';
|
|
55
55
|
|
|
56
56
|
export const useAccess = () => {
|
|
57
57
|
return React.useContext(AccessContext);
|
|
58
58
|
};
|
|
59
|
+
|
|
60
|
+
export interface AccessProps {
|
|
61
|
+
accessible: boolean;
|
|
62
|
+
fallback?: React.ReactNode;
|
|
63
|
+
}
|
|
64
|
+
export const Access: React.FC<AccessProps> = (props) => {
|
|
65
|
+
if (process.env.NODE_ENV === 'development' && typeof props.accessible !== 'boolean') {
|
|
66
|
+
throw new Error('[access] the \`accessible\` property on <Access /> should be a boolean');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return props.accessible ? props.children : props.fallback;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const useAccessMarkedRoutes = (routes: IRoute[]) => {
|
|
73
|
+
const access = useAccess();
|
|
74
|
+
const markdedRoutes: IRoute[] = React.useMemo(() => {
|
|
75
|
+
const process = (route, parentAccessCode) => {
|
|
76
|
+
const accessCode = route.access || parentAccessCode;
|
|
77
|
+
|
|
78
|
+
// set default status
|
|
79
|
+
route.unaccessible = ${api.config.access.strictMode ? 'true' : 'false'};
|
|
80
|
+
|
|
81
|
+
// check access code
|
|
82
|
+
if (typeof accessCode === 'string') {
|
|
83
|
+
const detector = access[route.access];
|
|
84
|
+
|
|
85
|
+
if (typeof detector === 'function') {
|
|
86
|
+
route.unaccessible = !detector(route);
|
|
87
|
+
} else if (typeof detector === 'boolean') {
|
|
88
|
+
route.unaccessible = !detector;
|
|
89
|
+
} else if (typeof detector === 'undefined') {
|
|
90
|
+
route.unaccessible = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// check children access code
|
|
95
|
+
if (route.routes) {
|
|
96
|
+
const isNoAccessibleChild = !route.routes.reduce((hasAccessibleChild, child) => {
|
|
97
|
+
process(child, accessCode);
|
|
98
|
+
|
|
99
|
+
return hasAccessibleChild || !child.unaccessible;
|
|
100
|
+
}, false);
|
|
101
|
+
|
|
102
|
+
// make sure parent route is unaccessible if all children are unaccessible
|
|
103
|
+
if (isNoAccessibleChild) {
|
|
104
|
+
route.unaccessible = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return route;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return routes.map(route => process(route));
|
|
112
|
+
}, [routes.length]);
|
|
113
|
+
|
|
114
|
+
return markdedRoutes;
|
|
115
|
+
}
|
|
59
116
|
`,
|
|
60
117
|
});
|
|
61
118
|
// context.ts
|
package/dist/antd.js
CHANGED
|
@@ -5,11 +5,16 @@ const plugin_utils_1 = require("umi/plugin-utils");
|
|
|
5
5
|
const resolveProjectDep_1 = require("./utils/resolveProjectDep");
|
|
6
6
|
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
7
7
|
exports.default = (api) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
let pkgPath;
|
|
9
|
+
try {
|
|
10
|
+
pkgPath =
|
|
11
|
+
(0, resolveProjectDep_1.resolveProjectDep)({
|
|
12
|
+
pkg: api.pkg,
|
|
13
|
+
cwd: api.cwd,
|
|
14
|
+
dep: 'antd',
|
|
15
|
+
}) || (0, path_1.dirname)(require.resolve('antd/package.json'));
|
|
16
|
+
}
|
|
17
|
+
catch (e) { }
|
|
13
18
|
api.describe({
|
|
14
19
|
config: {
|
|
15
20
|
schema(Joi) {
|
|
@@ -27,7 +32,13 @@ exports.default = (api) => {
|
|
|
27
32
|
},
|
|
28
33
|
enableBy: api.EnableBy.config,
|
|
29
34
|
});
|
|
35
|
+
function checkPkgPath() {
|
|
36
|
+
if (!pkgPath) {
|
|
37
|
+
throw new Error(`Can't find antd package. Please install antd first.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
30
40
|
api.modifyAppData((memo) => {
|
|
41
|
+
checkPkgPath();
|
|
31
42
|
const version = require(`${pkgPath}/package.json`).version;
|
|
32
43
|
memo.antd = {
|
|
33
44
|
pkgPath,
|
|
@@ -36,6 +47,7 @@ exports.default = (api) => {
|
|
|
36
47
|
return memo;
|
|
37
48
|
});
|
|
38
49
|
api.modifyConfig((memo) => {
|
|
50
|
+
checkPkgPath();
|
|
39
51
|
// antd import
|
|
40
52
|
memo.alias.antd = pkgPath;
|
|
41
53
|
// moment > dayjs
|
|
@@ -49,6 +61,10 @@ exports.default = (api) => {
|
|
|
49
61
|
}
|
|
50
62
|
return memo;
|
|
51
63
|
});
|
|
64
|
+
api.modifyConfig((memo) => {
|
|
65
|
+
memo.theme = Object.assign({ 'root-entry-name': 'default' }, memo.theme);
|
|
66
|
+
return memo;
|
|
67
|
+
});
|
|
52
68
|
// babel-plugin-import
|
|
53
69
|
api.addExtraBabelPlugins(() => {
|
|
54
70
|
const style = api.config.antd.style || 'less';
|
|
@@ -67,7 +83,7 @@ exports.default = (api) => {
|
|
|
67
83
|
});
|
|
68
84
|
// antd config provider
|
|
69
85
|
api.onGenerateFiles(() => {
|
|
70
|
-
if (!api.config.antd.
|
|
86
|
+
if (!api.config.antd.configProvider)
|
|
71
87
|
return;
|
|
72
88
|
api.writeTmpFile({
|
|
73
89
|
path: `runtime.tsx`,
|
|
@@ -90,12 +106,12 @@ export function rootContainer(container) {
|
|
|
90
106
|
return <ConfigProvider {...finalConfig}>{container}</ConfigProvider>;
|
|
91
107
|
}
|
|
92
108
|
`.trim(), {
|
|
93
|
-
config: JSON.stringify(api.config.antd.
|
|
109
|
+
config: JSON.stringify(api.config.antd.configProvider),
|
|
94
110
|
}),
|
|
95
111
|
});
|
|
96
112
|
});
|
|
97
113
|
api.addRuntimePlugin(() => {
|
|
98
|
-
return api.config.antd.
|
|
114
|
+
return api.config.antd.configProvider
|
|
99
115
|
? [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]
|
|
100
116
|
: [];
|
|
101
117
|
});
|
package/dist/dva.js
CHANGED
|
@@ -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.
|
|
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];
|
|
@@ -25,6 +29,7 @@ const path_1 = require("path");
|
|
|
25
29
|
const plugin_utils_1 = require("umi/plugin-utils");
|
|
26
30
|
const modelUtils_1 = require("./utils/modelUtils");
|
|
27
31
|
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
32
|
+
const utils_1 = require("@umijs/utils");
|
|
28
33
|
exports.default = (api) => {
|
|
29
34
|
const pkgPath = (0, path_1.join)(__dirname, '../libs/dva.ts');
|
|
30
35
|
api.describe({
|
|
@@ -32,6 +37,7 @@ exports.default = (api) => {
|
|
|
32
37
|
schema(Joi) {
|
|
33
38
|
return Joi.object({
|
|
34
39
|
extraModels: Joi.array().items(Joi.string()),
|
|
40
|
+
immer: Joi.object(),
|
|
35
41
|
});
|
|
36
42
|
},
|
|
37
43
|
},
|
|
@@ -51,6 +57,7 @@ exports.default = (api) => {
|
|
|
51
57
|
return memo;
|
|
52
58
|
});
|
|
53
59
|
api.onGenerateFiles((args) => {
|
|
60
|
+
var _a, _b, _c, _d, _e, _f;
|
|
54
61
|
const models = args.isFirstTime
|
|
55
62
|
? api.appData.pluginDva.models
|
|
56
63
|
: getAllModels(api);
|
|
@@ -66,6 +73,12 @@ exports.default = (api) => {
|
|
|
66
73
|
// It's faked dva
|
|
67
74
|
// aliased to @umijs/plugins/templates/dva
|
|
68
75
|
import { create, Provider } from 'dva';
|
|
76
|
+
import createLoading from '${(0, utils_1.winPath)(require.resolve('dva-loading'))}';
|
|
77
|
+
${((_a = api.config.dva) === null || _a === void 0 ? void 0 : _a.immer)
|
|
78
|
+
? `
|
|
79
|
+
import dvaImmer, { enableES5, enableAllPlugins } from '${(0, utils_1.winPath)(require.resolve('dva-immer'))}';
|
|
80
|
+
`
|
|
81
|
+
: ''}
|
|
69
82
|
import React, { useRef } from 'react';
|
|
70
83
|
import { history } from 'umi';
|
|
71
84
|
import { models } from './models';
|
|
@@ -87,6 +100,10 @@ export function RootContainer(props: any) {
|
|
|
87
100
|
},
|
|
88
101
|
},
|
|
89
102
|
);
|
|
103
|
+
app.current.use(createLoading());
|
|
104
|
+
${((_b = api.config.dva) === null || _b === void 0 ? void 0 : _b.immer) ? `app.current.use(dvaImmer());` : ''}
|
|
105
|
+
${((_d = (_c = api.config.dva) === null || _c === void 0 ? void 0 : _c.immer) === null || _d === void 0 ? void 0 : _d.enableES5) ? `enableES5();` : ''}
|
|
106
|
+
${((_f = (_e = api.config.dva) === null || _e === void 0 ? void 0 : _e.immer) === null || _f === void 0 ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ''}
|
|
90
107
|
for (const id of Object.keys(models)) {
|
|
91
108
|
app.current.model(models[id].model);
|
|
92
109
|
}
|
package/dist/initial-state.js
CHANGED
|
@@ -30,7 +30,7 @@ exports.default = (api) => {
|
|
|
30
30
|
import React from 'react';
|
|
31
31
|
import { useModel } from '@@/plugin-model';
|
|
32
32
|
${loading
|
|
33
|
-
? `import Loading from ${loading}`
|
|
33
|
+
? `import Loading from '${loading}'`
|
|
34
34
|
: `function Loading() { return <div>loading</div>; }`}
|
|
35
35
|
export default function InitialStateProvider(props: any) {
|
|
36
36
|
const appLoaded = React.useRef(false);
|
package/dist/layout.js
CHANGED
|
@@ -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.
|
|
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];
|
|
@@ -63,17 +67,23 @@ exports.default = (api) => {
|
|
|
63
67
|
api.writeTmpFile({
|
|
64
68
|
path: 'Layout.tsx',
|
|
65
69
|
content: `
|
|
66
|
-
import { Link, useLocation, useNavigate, Outlet, useAppData,
|
|
70
|
+
import { Link, useLocation, useNavigate, Outlet, useAppData, useRouteData, matchRoutes } from 'umi';
|
|
71
|
+
import { useMemo } from 'react';
|
|
67
72
|
import ProLayout, {
|
|
68
73
|
PageLoading,
|
|
69
74
|
} from '@ant-design/pro-layout';
|
|
70
75
|
import './Layout.less';
|
|
71
76
|
import Logo from './Logo';
|
|
77
|
+
import Exception from './Exception';
|
|
72
78
|
import { getRightRenderContent } from './rightRender';
|
|
73
79
|
${hasInitialStatePlugin
|
|
74
80
|
? `import { useModel } from '@@/plugin-model';`
|
|
75
81
|
: 'const useModel = null;'}
|
|
76
|
-
|
|
82
|
+
${api.config.access
|
|
83
|
+
? `
|
|
84
|
+
import { useAccessMarkedRoutes } from '@@/plugin-access';
|
|
85
|
+
`.trim()
|
|
86
|
+
: 'const useAccessMarkedRoutes = (r) => r;'}
|
|
77
87
|
${api.config.locale
|
|
78
88
|
? `
|
|
79
89
|
import { useIntl } from '@@/plugin-locale';
|
|
@@ -81,7 +91,7 @@ import { useIntl } from '@@/plugin-locale';
|
|
|
81
91
|
: ''}
|
|
82
92
|
|
|
83
93
|
|
|
84
|
-
export default () => {
|
|
94
|
+
export default (props: any) => {
|
|
85
95
|
const location = useLocation();
|
|
86
96
|
const navigate = useNavigate();
|
|
87
97
|
const { clientRoutes, pluginManager } = useAppData();
|
|
@@ -104,9 +114,8 @@ const { formatMessage } = useIntl();
|
|
|
104
114
|
...initialInfo
|
|
105
115
|
},
|
|
106
116
|
});
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
})[0];
|
|
117
|
+
const matchedRoute = useMemo(() => matchRoutes(clientRoutes, location.pathname).pop()?.route, [location.pathname]);
|
|
118
|
+
const [route] = useAccessMarkedRoutes(clientRoutes.filter(({ id }) => id === 'ant-design-pro-layout'));
|
|
110
119
|
return (
|
|
111
120
|
<ProLayout
|
|
112
121
|
route={route}
|
|
@@ -162,7 +171,16 @@ const { formatMessage } = useIntl();
|
|
|
162
171
|
})
|
|
163
172
|
}
|
|
164
173
|
>
|
|
165
|
-
<
|
|
174
|
+
<Exception
|
|
175
|
+
route={matchedRoute}
|
|
176
|
+
notFound={runtimeConfig.notFound}
|
|
177
|
+
noAccessible={runtimeConfig.noAccessible}
|
|
178
|
+
>
|
|
179
|
+
{runtimeConfig.childrenRender
|
|
180
|
+
? runtimeConfig.childrenRender(<Outlet />, props)
|
|
181
|
+
: <Outlet />
|
|
182
|
+
}
|
|
183
|
+
</Exception>
|
|
166
184
|
</ProLayout>
|
|
167
185
|
);
|
|
168
186
|
}
|
|
@@ -187,7 +205,7 @@ const { formatMessage } = useIntl();
|
|
|
187
205
|
return memo;
|
|
188
206
|
}, {});
|
|
189
207
|
const icons = Object.keys(iconsMap);
|
|
190
|
-
const antIconsPath = (0, path_1.dirname)(require.resolve('@ant-design/icons/package'));
|
|
208
|
+
const antIconsPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('@ant-design/icons/package')));
|
|
191
209
|
api.writeTmpFile({
|
|
192
210
|
path: 'icons.tsx',
|
|
193
211
|
content: `
|
|
@@ -464,6 +482,43 @@ const LogoIcon: React.FC = () => {
|
|
|
464
482
|
export default LogoIcon;
|
|
465
483
|
`,
|
|
466
484
|
});
|
|
485
|
+
api.writeTmpFile({
|
|
486
|
+
path: 'Exception.tsx',
|
|
487
|
+
content: `
|
|
488
|
+
import React from 'react';
|
|
489
|
+
import { history, type IRoute } from 'umi';
|
|
490
|
+
import { Result, Button } from 'antd';
|
|
491
|
+
|
|
492
|
+
const Exception: React.FC<{
|
|
493
|
+
children: React.ReactNode;
|
|
494
|
+
route?: IRoute;
|
|
495
|
+
notFound?: React.ReactNode;
|
|
496
|
+
noAccessible?: React.ReactNode;
|
|
497
|
+
}> = (props) => (
|
|
498
|
+
// render custom 404
|
|
499
|
+
(!props.route && props.notFound) ||
|
|
500
|
+
// render custom 403
|
|
501
|
+
(props.route.unaccessible && props.noAccessible) ||
|
|
502
|
+
// render default exception
|
|
503
|
+
((!props.route || props.route.unaccessible) && (
|
|
504
|
+
<Result
|
|
505
|
+
status={props.route ? '403' : '404'}
|
|
506
|
+
title={props.route ? '403' : '404'}
|
|
507
|
+
subTitle={props.route ? '抱歉,你无权访问该页面' : '抱歉,你访问的页面不存在'}
|
|
508
|
+
extra={
|
|
509
|
+
<Button type="primary" onClick={() => history.push('/')}>
|
|
510
|
+
返回首页
|
|
511
|
+
</Button>
|
|
512
|
+
}
|
|
513
|
+
/>
|
|
514
|
+
)) ||
|
|
515
|
+
// normal render
|
|
516
|
+
props.children
|
|
517
|
+
);
|
|
518
|
+
|
|
519
|
+
export default Exception;
|
|
520
|
+
`,
|
|
521
|
+
});
|
|
467
522
|
});
|
|
468
523
|
api.addLayouts(() => {
|
|
469
524
|
return [
|
package/dist/locale.js
CHANGED
|
@@ -10,16 +10,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.packageNormalize = void 0;
|
|
13
|
-
const utils_1 = require("@umijs/utils");
|
|
14
13
|
const fs_1 = require("fs");
|
|
15
14
|
const path_1 = require("path");
|
|
15
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
16
16
|
const localeUtils_1 = require("./utils/localeUtils");
|
|
17
17
|
const withTmpPath_1 = require("./utils/withTmpPath");
|
|
18
18
|
const packageNormalize = (packageName) => packageName.replace(/[@\/\-.]/g, '_');
|
|
19
19
|
exports.packageNormalize = packageNormalize;
|
|
20
20
|
// TODO: runtime plugin
|
|
21
21
|
exports.default = (api) => {
|
|
22
|
-
var _a;
|
|
23
22
|
// TODO: antd 的校验考虑 antd 插件
|
|
24
23
|
let hasAntd = false;
|
|
25
24
|
try {
|
|
@@ -28,15 +27,15 @@ exports.default = (api) => {
|
|
|
28
27
|
catch (e) {
|
|
29
28
|
api.logger.warn('antd is not installed. <SelecLang /> unavailable');
|
|
30
29
|
}
|
|
30
|
+
const defaultConfig = {
|
|
31
|
+
baseNavigator: true,
|
|
32
|
+
useLocalStorage: true,
|
|
33
|
+
baseSeparator: '-',
|
|
34
|
+
antd: hasAntd,
|
|
35
|
+
};
|
|
31
36
|
api.describe({
|
|
32
37
|
key: 'locale',
|
|
33
38
|
config: {
|
|
34
|
-
default: {
|
|
35
|
-
baseNavigator: true,
|
|
36
|
-
useLocalStorage: true,
|
|
37
|
-
baseSeparator: '-',
|
|
38
|
-
antd: hasAntd,
|
|
39
|
-
},
|
|
40
39
|
schema(joi) {
|
|
41
40
|
return joi.object({
|
|
42
41
|
default: joi.string(),
|
|
@@ -50,32 +49,32 @@ exports.default = (api) => {
|
|
|
50
49
|
},
|
|
51
50
|
enableBy: api.EnableBy.config,
|
|
52
51
|
});
|
|
53
|
-
const reactIntlPkgPath = (0, path_1.dirname)(require.resolve('react-intl/package'));
|
|
52
|
+
const reactIntlPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('react-intl/package')));
|
|
54
53
|
// polyfill
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
api.addEntryImportsAhead(() => (0, localeUtils_1.isNeedPolyfill)(api.config.targets || {})
|
|
55
|
+
? [
|
|
57
56
|
{
|
|
58
57
|
source: require.resolve('intl'),
|
|
59
58
|
},
|
|
60
|
-
]
|
|
61
|
-
|
|
59
|
+
]
|
|
60
|
+
: []);
|
|
62
61
|
const addAntdLocales = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
-
var
|
|
62
|
+
var _a;
|
|
64
63
|
return yield api.applyPlugins({
|
|
65
64
|
key: 'addAntdLocales',
|
|
66
65
|
type: api.ApplyPluginsType.add,
|
|
67
66
|
initialValue: [
|
|
68
|
-
`antd/${((
|
|
67
|
+
`antd/${((_a = api.config) === null || _a === void 0 ? void 0 : _a.ssr) ? 'lib' : 'es'}/locale/${(0, localeUtils_1.getAntdLocale)(args.lang, args.country)}`,
|
|
69
68
|
],
|
|
70
69
|
args,
|
|
71
70
|
});
|
|
72
71
|
});
|
|
73
72
|
const getList = (resolveKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
-
var
|
|
73
|
+
var _b;
|
|
75
74
|
const { paths } = api;
|
|
76
75
|
return (0, localeUtils_1.getLocaleList)({
|
|
77
|
-
localeFolder:
|
|
78
|
-
separator: (
|
|
76
|
+
localeFolder: 'locales',
|
|
77
|
+
separator: (_b = api.config.locale) === null || _b === void 0 ? void 0 : _b.baseSeparator,
|
|
79
78
|
absSrcPath: paths.absSrcPath,
|
|
80
79
|
absPagesPath: paths.absPagesPath,
|
|
81
80
|
addAntdLocales,
|
|
@@ -83,15 +82,14 @@ exports.default = (api) => {
|
|
|
83
82
|
});
|
|
84
83
|
});
|
|
85
84
|
api.onGenerateFiles(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
-
var
|
|
85
|
+
var _c, _d, _e, _f;
|
|
87
86
|
const localeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/locale.tpl'), 'utf-8');
|
|
88
87
|
// moment2dayjs
|
|
89
88
|
const resolveKey = api.config.moment2dayjs ? 'dayjs' : 'moment';
|
|
90
|
-
const momentPkgPath = (0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`));
|
|
91
|
-
const EventEmitterPkg = (0, path_1.dirname)(require.resolve('event-emitter/package'));
|
|
92
|
-
const { baseSeparator, baseNavigator, antd, title, useLocalStorage } = api
|
|
93
|
-
|
|
94
|
-
const defaultLocale = ((_e = api.config.locale) === null || _e === void 0 ? void 0 : _e.default) || `zh${baseSeparator}CN`;
|
|
89
|
+
const momentPkgPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve(`${resolveKey}/package.json`)));
|
|
90
|
+
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`;
|
|
95
93
|
const localeList = yield getList(resolveKey);
|
|
96
94
|
const momentLocales = localeList
|
|
97
95
|
.map(({ momentLocale }) => momentLocale)
|
|
@@ -102,7 +100,7 @@ exports.default = (api) => {
|
|
|
102
100
|
let MomentLocales = momentLocales;
|
|
103
101
|
let DefaultMomentLocale = '';
|
|
104
102
|
// set moment default accounding to locale.default
|
|
105
|
-
if (!MomentLocales.length && ((
|
|
103
|
+
if (!MomentLocales.length && ((_d = api.config.locale) === null || _d === void 0 ? void 0 : _d.default)) {
|
|
106
104
|
const [lang, country = ''] = defaultLocale.split(baseSeparator);
|
|
107
105
|
const { momentLocale } = (0, localeUtils_1.getMomentLocale)(lang, country, resolveKey);
|
|
108
106
|
if (momentLocale) {
|
|
@@ -112,9 +110,9 @@ exports.default = (api) => {
|
|
|
112
110
|
}
|
|
113
111
|
let DefaultAntdLocales = [];
|
|
114
112
|
// set antd default locale
|
|
115
|
-
if (!antdLocales.length && ((
|
|
113
|
+
if (!antdLocales.length && ((_e = api.config.locale) === null || _e === void 0 ? void 0 : _e.antd)) {
|
|
116
114
|
const [lang, country = ''] = defaultLocale.split(baseSeparator);
|
|
117
|
-
DefaultAntdLocales =
|
|
115
|
+
DefaultAntdLocales = plugin_utils_1.lodash.uniq(yield addAntdLocales({
|
|
118
116
|
lang,
|
|
119
117
|
country,
|
|
120
118
|
}));
|
|
@@ -124,7 +122,7 @@ exports.default = (api) => {
|
|
|
124
122
|
return (0, exports.packageNormalize)(this);
|
|
125
123
|
};
|
|
126
124
|
api.writeTmpFile({
|
|
127
|
-
content:
|
|
125
|
+
content: plugin_utils_1.Mustache.render(localeTpl, {
|
|
128
126
|
MomentLocales,
|
|
129
127
|
DefaultMomentLocale,
|
|
130
128
|
NormalizeAntdLocalesName,
|
|
@@ -139,11 +137,11 @@ exports.default = (api) => {
|
|
|
139
137
|
path: 'locale.tsx',
|
|
140
138
|
});
|
|
141
139
|
const localeExportsTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/localeExports.tpl'), 'utf-8');
|
|
142
|
-
const localeDirName =
|
|
140
|
+
const localeDirName = 'locales';
|
|
143
141
|
const localeDirPath = (0, path_1.join)(api.paths.absSrcPath, localeDirName);
|
|
144
142
|
api.writeTmpFile({
|
|
145
143
|
path: 'localeExports.ts',
|
|
146
|
-
content:
|
|
144
|
+
content: plugin_utils_1.Mustache.render(localeExportsTpl, {
|
|
147
145
|
EventEmitterPkg,
|
|
148
146
|
BaseSeparator: baseSeparator,
|
|
149
147
|
BaseNavigator: baseNavigator,
|
|
@@ -159,7 +157,7 @@ exports.default = (api) => {
|
|
|
159
157
|
})) }))),
|
|
160
158
|
Antd: !!antd,
|
|
161
159
|
DefaultLocale: JSON.stringify(defaultLocale),
|
|
162
|
-
warningPkgPath: require.resolve('warning/package'),
|
|
160
|
+
warningPkgPath: (0, plugin_utils_1.winPath)(require.resolve('warning/package')),
|
|
163
161
|
reactIntlPkgPath,
|
|
164
162
|
}),
|
|
165
163
|
});
|
|
@@ -167,7 +165,7 @@ exports.default = (api) => {
|
|
|
167
165
|
const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/runtime.tpl'), 'utf-8');
|
|
168
166
|
api.writeTmpFile({
|
|
169
167
|
path: 'runtime.tsx',
|
|
170
|
-
content:
|
|
168
|
+
content: plugin_utils_1.Mustache.render(runtimeTpl, {
|
|
171
169
|
Title: !!title,
|
|
172
170
|
}),
|
|
173
171
|
});
|
|
@@ -175,18 +173,18 @@ exports.default = (api) => {
|
|
|
175
173
|
const selectLang = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../libs/locale/SelectLang.tpl'), 'utf-8');
|
|
176
174
|
api.writeTmpFile({
|
|
177
175
|
path: 'SelectLang.tsx',
|
|
178
|
-
content:
|
|
176
|
+
content: plugin_utils_1.Mustache.render(selectLang, {
|
|
179
177
|
Antd: !!antd,
|
|
180
178
|
LocaleList: localeList,
|
|
181
179
|
ShowSelectLang: localeList.length > 1 && !!antd,
|
|
182
|
-
antdFiles: ((
|
|
180
|
+
antdFiles: ((_f = api.config) === null || _f === void 0 ? void 0 : _f.ssr) ? 'lib' : 'es',
|
|
183
181
|
}),
|
|
184
182
|
});
|
|
185
183
|
// index.ts
|
|
186
184
|
api.writeTmpFile({
|
|
187
185
|
path: 'index.ts',
|
|
188
186
|
content: `
|
|
189
|
-
export { useIntl, formatMessage, FormattedMessage } from './localeExports.ts';
|
|
187
|
+
export { setLocale, getLocale, useIntl, formatMessage, FormattedMessage } from './localeExports.ts';
|
|
190
188
|
export { SelectLang } from './SelectLang.tsx';
|
|
191
189
|
`,
|
|
192
190
|
});
|
package/dist/model.js
CHANGED
|
@@ -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.
|
|
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];
|
package/dist/moment2dayjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("@umijs/utils");
|
|
4
3
|
const path_1 = require("path");
|
|
4
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
5
5
|
/*
|
|
6
6
|
As long as moment2dayjs is registered, moment will be replaced by dayjs.
|
|
7
7
|
The presets that can adapt to antd is registered by default.
|
|
@@ -81,11 +81,11 @@ dayjs.extend({{.}});
|
|
|
81
81
|
|
|
82
82
|
dayjs.extend(antdPlugin);
|
|
83
83
|
`;
|
|
84
|
-
const dayjsAntdPluginPath = require.resolve('antd-dayjs-webpack-plugin/src/antd-plugin');
|
|
85
|
-
const dayjsPath = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
|
|
84
|
+
const dayjsAntdPluginPath = (0, plugin_utils_1.winPath)(require.resolve('antd-dayjs-webpack-plugin/src/antd-plugin'));
|
|
85
|
+
const dayjsPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('dayjs/package.json')));
|
|
86
86
|
api.writeTmpFile({
|
|
87
87
|
path: 'runtime.tsx',
|
|
88
|
-
content:
|
|
88
|
+
content: plugin_utils_1.Mustache.render(runtimeTpl, {
|
|
89
89
|
plugins,
|
|
90
90
|
dayjsPath,
|
|
91
91
|
dayjsAntdPluginPath,
|
package/dist/qiankun/master.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isMasterEnable = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
6
7
|
const withTmpPath_1 = require("../utils/withTmpPath");
|
|
7
8
|
const constants_1 = require("./constants");
|
|
8
9
|
function isMasterEnable(opts) {
|
|
@@ -90,7 +91,6 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
|
|
|
90
91
|
path: file.replace(/\.tpl$/, ''),
|
|
91
92
|
tpl: getFileContent(file),
|
|
92
93
|
context: {
|
|
93
|
-
runtimeHistory: api.config.runtimeHistory,
|
|
94
94
|
dynamicRoot: false,
|
|
95
95
|
hasModelPlugin: api.isPluginEnable('model'),
|
|
96
96
|
// dynamicRoot:
|
|
@@ -105,8 +105,8 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
|
|
|
105
105
|
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
106
106
|
? `import { useModel } from '@@/plugin-model'`
|
|
107
107
|
: `const useModel = null;`)
|
|
108
|
-
.replace(/from 'qiankun'/g, `from '${(0, path_1.dirname)(require.resolve('qiankun/package'))}'`)
|
|
109
|
-
.replace(/from 'lodash\//g, `from '${(0, path_1.dirname)(require.resolve('lodash/package'))}/`),
|
|
108
|
+
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
109
|
+
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
});
|
package/dist/qiankun/slave.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const assert_1 = __importDefault(require("assert"));
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
9
10
|
const withTmpPath_1 = require("../utils/withTmpPath");
|
|
10
11
|
const constants_1 = require("./constants");
|
|
11
12
|
// BREAK CHANGE: 需要手动配置 slave: {},不能留空
|
|
@@ -34,15 +35,14 @@ exports.default = (api) => {
|
|
|
34
35
|
},
|
|
35
36
|
});
|
|
36
37
|
api.modifyDefaultConfig((memo) => {
|
|
37
|
-
var _a, _b, _c;
|
|
38
|
+
var _a, _b, _c, _d;
|
|
38
39
|
const initialSlaveOptions = Object.assign(Object.assign({ devSourceMap: true }, JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}')), (memo.qiankun || {}).slave);
|
|
39
40
|
const modifiedDefaultConfig = Object.assign(Object.assign({}, memo), {
|
|
40
41
|
// 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
|
|
41
|
-
runtimePublicPath: true,
|
|
42
|
-
// TODO: runtimeHistory
|
|
43
|
-
runtimeHistory: {}, qiankun: Object.assign(Object.assign({}, memo.qiankun), { slave: initialSlaveOptions }) });
|
|
42
|
+
runtimePublicPath: true, qiankun: Object.assign(Object.assign({}, memo.qiankun), { slave: initialSlaveOptions }) });
|
|
44
43
|
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
|
-
|
|
44
|
+
const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
|
|
45
|
+
if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
|
|
46
46
|
// @ts-ignore
|
|
47
47
|
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
48
48
|
}
|
|
@@ -57,17 +57,15 @@ exports.default = (api) => {
|
|
|
57
57
|
}
|
|
58
58
|
return config;
|
|
59
59
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// return publicPathStr;
|
|
70
|
-
// });
|
|
60
|
+
api.addHTMLHeadScripts(() => {
|
|
61
|
+
var _a;
|
|
62
|
+
const dontModify = (_a = api.config.qiankun) === null || _a === void 0 ? void 0 : _a.shouldNotModifyRuntimePublicPath;
|
|
63
|
+
return dontModify
|
|
64
|
+
? []
|
|
65
|
+
: [
|
|
66
|
+
`window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || '/'}";`,
|
|
67
|
+
];
|
|
68
|
+
});
|
|
71
69
|
api.chainWebpack((config) => {
|
|
72
70
|
(0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
|
|
73
71
|
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
@@ -133,8 +131,8 @@ if (!window.__POWERED_BY_QIANKUN__) {
|
|
|
133
131
|
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
134
132
|
? `import { useModel } from '@@/plugin/model'`
|
|
135
133
|
: `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'))}/`),
|
|
134
|
+
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
135
|
+
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
138
136
|
});
|
|
139
137
|
});
|
|
140
138
|
});
|
package/dist/request.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("@umijs/utils");
|
|
4
3
|
const path_1 = require("path");
|
|
4
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
5
5
|
exports.default = (api) => {
|
|
6
6
|
api.describe({
|
|
7
7
|
key: 'request',
|
|
@@ -265,6 +265,7 @@ export {
|
|
|
265
265
|
useRequest,
|
|
266
266
|
UseRequestProvider,
|
|
267
267
|
request,
|
|
268
|
+
getRequestInstance,
|
|
268
269
|
};
|
|
269
270
|
|
|
270
271
|
export type {
|
|
@@ -276,15 +277,15 @@ export type {
|
|
|
276
277
|
`;
|
|
277
278
|
api.onGenerateFiles(() => {
|
|
278
279
|
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 =
|
|
280
|
+
const umiRequestPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('@ahooksjs/use-request/package.json')));
|
|
281
|
+
const axiosPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('axios/package.json')));
|
|
282
|
+
const antdPkg = (0, plugin_utils_1.winPath)(
|
|
282
283
|
// use path from antd plugin first
|
|
283
284
|
((_a = api.appData.antd) === null || _a === void 0 ? void 0 : _a.pkgPath) ||
|
|
284
|
-
(0, path_1.dirname)(require.resolve('antd/package.json'));
|
|
285
|
+
(0, path_1.dirname)(require.resolve('antd/package.json')));
|
|
285
286
|
api.writeTmpFile({
|
|
286
287
|
path: 'request.ts',
|
|
287
|
-
content:
|
|
288
|
+
content: plugin_utils_1.Mustache.render(requestTpl, {
|
|
288
289
|
umiRequestPath,
|
|
289
290
|
axiosPath,
|
|
290
291
|
antdPkg,
|
package/dist/tailwindcss.js
CHANGED
|
@@ -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
|
|
23
|
-
const
|
|
3
|
+
const path_1 = require("path");
|
|
4
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
24
5
|
exports.default = (api) => {
|
|
25
|
-
api.describe({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
|
28
|
-
const path_1 =
|
|
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
|
-
|
|
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 (!
|
|
45
|
-
|
|
46
|
-
const generatedPath = path_1.
|
|
47
|
-
const binPath = path_1.
|
|
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
|
-
|
|
55
|
-
|
|
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
|
};
|
package/dist/utils/astUtils.js
CHANGED
|
@@ -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.
|
|
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];
|
|
@@ -10,9 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.isNeedPolyfill = exports.exactLocalePaths = exports.getLocaleList = exports.getAntdLocale = exports.getMomentLocale = void 0;
|
|
13
|
-
const utils_1 = require("@umijs/utils");
|
|
14
13
|
const fs_1 = require("fs");
|
|
15
14
|
const path_1 = require("path");
|
|
15
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
16
16
|
/**
|
|
17
17
|
* 获取 moment 包的 locale 名称
|
|
18
18
|
* @param lang 语言
|
|
@@ -58,16 +58,16 @@ const modulesHasLocale = (localePath) => {
|
|
|
58
58
|
const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
59
|
const { localeFolder, separator = '-', absSrcPath = '', absPagesPath = '', addAntdLocales, resolveKey = 'moment', } = opts;
|
|
60
60
|
const localeFileMath = new RegExp(`^([a-z]{2})${separator}?([A-Z]{2})?\.(js|json|ts)$`);
|
|
61
|
-
const localeFiles =
|
|
61
|
+
const localeFiles = plugin_utils_1.glob
|
|
62
62
|
.sync('*.{ts,js,json}', {
|
|
63
|
-
cwd: (0,
|
|
63
|
+
cwd: (0, plugin_utils_1.winPath)((0, path_1.join)(absSrcPath, localeFolder)),
|
|
64
64
|
})
|
|
65
|
-
.map((name) => (0,
|
|
66
|
-
.concat(
|
|
65
|
+
.map((name) => (0, plugin_utils_1.winPath)((0, path_1.join)(absSrcPath, localeFolder, name)))
|
|
66
|
+
.concat(plugin_utils_1.glob
|
|
67
67
|
.sync(`**/${localeFolder}/*.{ts,js,json}`, {
|
|
68
68
|
cwd: absPagesPath,
|
|
69
69
|
})
|
|
70
|
-
.map((name) => (0,
|
|
70
|
+
.map((name) => (0, plugin_utils_1.winPath)((0, path_1.join)(absPagesPath, name))))
|
|
71
71
|
.filter((p) => localeFileMath.test((0, path_1.basename)(p)) && (0, fs_1.existsSync)(p))
|
|
72
72
|
.map((fullName) => {
|
|
73
73
|
var _a, _b;
|
|
@@ -79,11 +79,11 @@ const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
79
79
|
path: fullName,
|
|
80
80
|
};
|
|
81
81
|
});
|
|
82
|
-
const groups =
|
|
82
|
+
const groups = plugin_utils_1.lodash.groupBy(localeFiles, 'name');
|
|
83
83
|
const promises = Object.keys(groups).map((name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
84
|
const [lang, country = ''] = name.split(separator);
|
|
85
85
|
const { momentLocale } = (0, exports.getMomentLocale)(lang, country, resolveKey);
|
|
86
|
-
const antdLocale =
|
|
86
|
+
const antdLocale = plugin_utils_1.lodash
|
|
87
87
|
.uniq(yield addAntdLocales({ lang, country }))
|
|
88
88
|
.filter((localePath) => modulesHasLocale(localePath));
|
|
89
89
|
return {
|
|
@@ -94,7 +94,7 @@ const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
94
94
|
locale: name.split(separator).join('-'),
|
|
95
95
|
country,
|
|
96
96
|
antdLocale,
|
|
97
|
-
paths: groups[name].map((item) => (0,
|
|
97
|
+
paths: groups[name].map((item) => (0, plugin_utils_1.winPath)(item.path)),
|
|
98
98
|
momentLocale,
|
|
99
99
|
};
|
|
100
100
|
}));
|
|
@@ -102,7 +102,7 @@ const getLocaleList = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
102
102
|
});
|
|
103
103
|
exports.getLocaleList = getLocaleList;
|
|
104
104
|
const exactLocalePaths = (data) => {
|
|
105
|
-
return
|
|
105
|
+
return plugin_utils_1.lodash.flatten(data.map((item) => item.paths));
|
|
106
106
|
};
|
|
107
107
|
exports.exactLocalePaths = exactLocalePaths;
|
|
108
108
|
function isNeedPolyfill(targets = {}) {
|
package/dist/utils/modelUtils.js
CHANGED
|
@@ -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.
|
|
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];
|
|
@@ -26,9 +30,9 @@ exports.ModelUtils = exports.Model = void 0;
|
|
|
26
30
|
const parser = __importStar(require("@umijs/bundler-utils/compiled/babel/parser"));
|
|
27
31
|
const traverse_1 = __importDefault(require("@umijs/bundler-utils/compiled/babel/traverse"));
|
|
28
32
|
const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
|
|
29
|
-
const utils_1 = require("@umijs/utils");
|
|
30
33
|
const fs_1 = require("fs");
|
|
31
34
|
const path_1 = require("path");
|
|
35
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
32
36
|
const astUtils_1 = require("./astUtils");
|
|
33
37
|
class Model {
|
|
34
38
|
constructor(file, id) {
|
|
@@ -76,12 +80,12 @@ class ModelUtils {
|
|
|
76
80
|
});
|
|
77
81
|
}
|
|
78
82
|
getModels(opts) {
|
|
79
|
-
return
|
|
83
|
+
return plugin_utils_1.glob
|
|
80
84
|
.sync(opts.pattern || '**/*.{ts,js}', {
|
|
81
85
|
cwd: opts.base,
|
|
82
86
|
absolute: true,
|
|
83
87
|
})
|
|
84
|
-
.map(
|
|
88
|
+
.map(plugin_utils_1.winPath)
|
|
85
89
|
.filter((file) => {
|
|
86
90
|
if (/\.d.ts$/.test(file))
|
|
87
91
|
return false;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withTmpPath = void 0;
|
|
4
|
-
const utils_1 = require("@umijs/utils");
|
|
5
4
|
const path_1 = require("path");
|
|
5
|
+
const plugin_utils_1 = require("umi/plugin-utils");
|
|
6
6
|
function withTmpPath(opts) {
|
|
7
|
-
return (0,
|
|
7
|
+
return (0, plugin_utils_1.winPath)((0, path_1.join)(opts.api.paths.absTmpPath, opts.api.plugin.key && !opts.noPluginDir
|
|
8
8
|
? `plugin-${opts.api.plugin.key}`
|
|
9
9
|
: '', opts.path));
|
|
10
10
|
}
|
|
@@ -163,9 +163,9 @@ export const getLocale = () => {
|
|
|
163
163
|
// please clear localStorage if you change the baseSeparator config
|
|
164
164
|
// because changing will break the app
|
|
165
165
|
const lang =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
navigator.cookieEnabled && typeof localStorage !== 'undefined' && useLocalStorage
|
|
167
|
+
? window.localStorage.getItem('umi_locale')
|
|
168
|
+
: '';
|
|
169
169
|
// support baseNavigator, default true
|
|
170
170
|
let browserLang;
|
|
171
171
|
{{#BaseNavigator}}
|
|
@@ -207,9 +207,9 @@ export const setLocale = (lang: string, realReload: boolean = true) => {
|
|
|
207
207
|
|
|
208
208
|
const updater = () => {
|
|
209
209
|
if (getLocale() !== lang) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
if (navigator.cookieEnabled && typeof window.localStorage !== 'undefined' && useLocalStorage) {
|
|
211
|
+
window.localStorage.setItem('umi_locale', lang || '');
|
|
212
|
+
}
|
|
213
213
|
setIntl(lang);
|
|
214
214
|
if (realReload) {
|
|
215
215
|
window.location.reload();
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { MicroApp } from './MicroApp';
|
|
3
|
-
{{#runtimeHistory}}
|
|
4
|
-
import { getCreateHistoryOptions } from 'umi';
|
|
5
|
-
{{/runtimeHistory}}
|
|
6
3
|
import { useLocation } from 'umi';
|
|
7
4
|
|
|
8
5
|
export function getMicroAppRouteComponent(opts: {
|
|
@@ -18,12 +15,6 @@ export function getMicroAppRouteComponent(opts: {
|
|
|
18
15
|
// 默认取静态配置的 base
|
|
19
16
|
let umiConfigBase = base === '/' ? '' : base;
|
|
20
17
|
|
|
21
|
-
{{#runtimeHistory}}
|
|
22
|
-
// 存在 getCreateHistoryOptions 说明当前应用开启了 runtimeHistory,此时取运行时的 history 配置的 basename
|
|
23
|
-
const { basename = '/' } = getCreateHistoryOptions();
|
|
24
|
-
umiConfigBase = basename === '/' ? '' : basename;
|
|
25
|
-
{{/runtimeHistory}}
|
|
26
|
-
|
|
27
18
|
let runtimeMatchedBase =
|
|
28
19
|
umiConfigBase + (url.endsWith('/') ? url.substr(0, url.length - 1) : url);
|
|
29
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.10",
|
|
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,19 +18,21 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "pnpm tsc",
|
|
20
20
|
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
21
|
-
"dev": "pnpm build -- --watch"
|
|
21
|
+
"dev": "pnpm build -- --watch",
|
|
22
|
+
"test": "jest -c ../../jest.turbo.config.ts"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"@ahooksjs/use-request": "^2.0.0",
|
|
25
26
|
"@ant-design/icons": "^4.7.0",
|
|
26
|
-
"@ant-design/pro-layout": "^6.
|
|
27
|
-
"@umijs/bundler-utils": "4.0.0-rc.
|
|
28
|
-
"antd": "^4.17.3",
|
|
27
|
+
"@ant-design/pro-layout": "^6.34.6",
|
|
28
|
+
"@umijs/bundler-utils": "4.0.0-rc.10",
|
|
29
29
|
"antd-dayjs-webpack-plugin": "^1.0.6",
|
|
30
|
-
"axios": "^0.
|
|
30
|
+
"axios": "^0.26.1",
|
|
31
31
|
"babel-plugin-import": "^1.13.3",
|
|
32
|
-
"dayjs": "^1.
|
|
32
|
+
"dayjs": "^1.11.0",
|
|
33
33
|
"dva-core": "^2.0.4",
|
|
34
|
+
"dva-immer": "^1.0.0",
|
|
35
|
+
"dva-loading": "^3.0.22",
|
|
34
36
|
"event-emitter": "~0.3.5",
|
|
35
37
|
"fast-deep-equal": "3.1.3",
|
|
36
38
|
"lodash": "^4.17.21",
|
|
@@ -42,7 +44,7 @@
|
|
|
42
44
|
"warning": "^4.0.3"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
|
-
"umi": "4.0.0-rc.
|
|
47
|
+
"umi": "4.0.0-rc.10"
|
|
46
48
|
},
|
|
47
49
|
"publishConfig": {
|
|
48
50
|
"access": "public"
|