@umijs/plugins 4.0.66 → 4.0.67
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/antd.js +17 -4
- package/dist/layout.js +10 -5
- package/libs/qiankun/master/MicroApp.tsx +27 -23
- package/package.json +4 -3
package/dist/antd.js
CHANGED
|
@@ -32,6 +32,7 @@ __export(antd_exports, {
|
|
|
32
32
|
default: () => antd_default
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(antd_exports);
|
|
35
|
+
var import_moment_webpack_plugin = __toESM(require("@ant-design/moment-webpack-plugin"));
|
|
35
36
|
var import_assert = __toESM(require("assert"));
|
|
36
37
|
var import_path = require("path");
|
|
37
38
|
var import_umi = require("umi");
|
|
@@ -54,6 +55,7 @@ var antd_default = (api) => {
|
|
|
54
55
|
}
|
|
55
56
|
const appComponentAvailable = import_plugin_utils.semver.gte(antdVersion, "5.1.0");
|
|
56
57
|
const appConfigAvailable = import_plugin_utils.semver.gte(antdVersion, "5.3.0");
|
|
58
|
+
const day2MomentAvailable = import_plugin_utils.semver.gte(antdVersion, "5.0.0");
|
|
57
59
|
api.describe({
|
|
58
60
|
config: {
|
|
59
61
|
schema({ zod }) {
|
|
@@ -68,7 +70,9 @@ var antd_default = (api) => {
|
|
|
68
70
|
style: zod.enum(["less", "css"]).describe("less or css, default less"),
|
|
69
71
|
theme: zod.record(zod.any()),
|
|
70
72
|
// Only antd@5.1.0 is supported
|
|
71
|
-
appConfig: zod.record(zod.any()).describe("Only antd@5.1.0 is supported")
|
|
73
|
+
appConfig: zod.record(zod.any()).describe("Only antd@5.1.0 is supported"),
|
|
74
|
+
// DatePicker & Calendar use moment version
|
|
75
|
+
momentPicker: zod.boolean().describe("Only antd@5.x is supported")
|
|
72
76
|
}).deepPartial();
|
|
73
77
|
}
|
|
74
78
|
},
|
|
@@ -100,9 +104,6 @@ var antd_default = (api) => {
|
|
|
100
104
|
memo.antd = antd = Object.assign(defaultConfig, antd);
|
|
101
105
|
}
|
|
102
106
|
memo.alias.antd = pkgPath;
|
|
103
|
-
if (antd.dayjs) {
|
|
104
|
-
memo.alias.moment = (0, import_path.dirname)(require.resolve("dayjs/package.json"));
|
|
105
|
-
}
|
|
106
107
|
if (antdVersion.startsWith("5")) {
|
|
107
108
|
const theme = require("@ant-design/antd-theme-variable");
|
|
108
109
|
memo.theme = {
|
|
@@ -153,6 +154,18 @@ var antd_default = (api) => {
|
|
|
153
154
|
}
|
|
154
155
|
return memo;
|
|
155
156
|
});
|
|
157
|
+
api.chainWebpack((memo) => {
|
|
158
|
+
if (api.config.antd.momentPicker) {
|
|
159
|
+
if (day2MomentAvailable) {
|
|
160
|
+
memo.plugin("antd-moment-webpack-plugin").use(import_moment_webpack_plugin.default);
|
|
161
|
+
} else {
|
|
162
|
+
api.logger.warn(
|
|
163
|
+
`MomentPicker is only available in version 5.0.0 and above, but you are using version ${antdVersion}`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return memo;
|
|
168
|
+
});
|
|
156
169
|
api.addExtraBabelPlugins(() => {
|
|
157
170
|
const style = antdVersion.startsWith("5") ? false : api.config.antd.style || "less";
|
|
158
171
|
return api.config.antd.import && !api.appData.vite ? [
|
package/dist/layout.js
CHANGED
|
@@ -52,6 +52,7 @@ var getAllIcons = () => {
|
|
|
52
52
|
{}
|
|
53
53
|
);
|
|
54
54
|
};
|
|
55
|
+
var ANT_PRO_COMPONENT = "@ant-design/pro-components";
|
|
55
56
|
var layout_default = (api) => {
|
|
56
57
|
let antdVersion = "4.0.0";
|
|
57
58
|
try {
|
|
@@ -75,7 +76,7 @@ var layout_default = (api) => {
|
|
|
75
76
|
});
|
|
76
77
|
const depList = [
|
|
77
78
|
"@alipay/tech-ui",
|
|
78
|
-
|
|
79
|
+
ANT_PRO_COMPONENT,
|
|
79
80
|
"@ant-design/pro-layout"
|
|
80
81
|
];
|
|
81
82
|
const pkgHasDep = depList.find((dep) => {
|
|
@@ -94,9 +95,10 @@ var layout_default = (api) => {
|
|
|
94
95
|
if (pkgHasDep && api.cwd !== cwd && (0, import_fs.existsSync)((0, import_path.join)(cwd, "node_modules", pkgHasDep, "package.json"))) {
|
|
95
96
|
return (0, import_path.join)(cwd, "node_modules", pkgHasDep);
|
|
96
97
|
}
|
|
97
|
-
return (0, import_path.dirname)(require.resolve(
|
|
98
|
+
return (0, import_path.dirname)(require.resolve(`${ANT_PRO_COMPONENT}/package.json`));
|
|
98
99
|
};
|
|
99
100
|
const pkgPath = (0, import_plugin_utils.winPath)(getPkgPath());
|
|
101
|
+
const resolvedPkgPath = pkgPath || ANT_PRO_COMPONENT;
|
|
100
102
|
api.modifyAppData((memo) => {
|
|
101
103
|
const version = require(`${pkgPath}/package.json`).version;
|
|
102
104
|
memo.pluginLayout = {
|
|
@@ -112,8 +114,11 @@ var layout_default = (api) => {
|
|
|
112
114
|
}
|
|
113
115
|
return memo;
|
|
114
116
|
});
|
|
117
|
+
const isFlattedDepsDir = [import_plugin_utils.NpmClientEnum.npm, import_plugin_utils.NpmClientEnum.yarn].includes(
|
|
118
|
+
api.appData.npmClient
|
|
119
|
+
);
|
|
115
120
|
api.onGenerateFiles(() => {
|
|
116
|
-
const PKG_TYPE_REFERENCE = `/// <reference types="${
|
|
121
|
+
const PKG_TYPE_REFERENCE = `/// <reference types="${isFlattedDepsDir ? ANT_PRO_COMPONENT : resolvedPkgPath}" />`;
|
|
117
122
|
const hasInitialStatePlugin = api.config.initialState;
|
|
118
123
|
api.writeTmpFile({
|
|
119
124
|
path: "Layout.tsx",
|
|
@@ -124,7 +129,7 @@ import type { IRoute } from 'umi';
|
|
|
124
129
|
import React, { useMemo } from 'react';
|
|
125
130
|
import {
|
|
126
131
|
ProLayout,
|
|
127
|
-
} from "${
|
|
132
|
+
} from "${resolvedPkgPath}";
|
|
128
133
|
import './Layout.less';
|
|
129
134
|
import Logo from './Logo';
|
|
130
135
|
import Exception from './Exception';
|
|
@@ -299,7 +304,7 @@ const { formatMessage } = useIntl();
|
|
|
299
304
|
path: "types.d.ts",
|
|
300
305
|
content: `
|
|
301
306
|
${PKG_TYPE_REFERENCE}
|
|
302
|
-
import type { ProLayoutProps, HeaderProps } from "${
|
|
307
|
+
import type { ProLayoutProps, HeaderProps } from "${resolvedPkgPath}";
|
|
303
308
|
${hasInitialStatePlugin ? `import type InitialStateType from '@@/plugin-initialState/@@initialState';
|
|
304
309
|
type InitDataType = ReturnType<typeof InitialStateType>;
|
|
305
310
|
` : "type InitDataType = any;"}
|
|
@@ -8,7 +8,7 @@ import noop from 'lodash/noop';
|
|
|
8
8
|
import {
|
|
9
9
|
FrameworkConfiguration,
|
|
10
10
|
loadMicroApp,
|
|
11
|
-
MicroApp as
|
|
11
|
+
MicroApp as MicroAppTypeDefinition,
|
|
12
12
|
prefetchApps,
|
|
13
13
|
} from 'qiankun';
|
|
14
14
|
import React, {
|
|
@@ -37,6 +37,12 @@ type MemoryHistory = {
|
|
|
37
37
|
type?: 'memory';
|
|
38
38
|
} & any;
|
|
39
39
|
|
|
40
|
+
type MicroAppType = MicroAppTypeDefinition & {
|
|
41
|
+
_unmounting?: boolean;
|
|
42
|
+
_updatingPromise?: Promise<void>;
|
|
43
|
+
_updatingTimestamp?: number;
|
|
44
|
+
};
|
|
45
|
+
|
|
40
46
|
export type Props = {
|
|
41
47
|
name: string;
|
|
42
48
|
settings?: FrameworkConfiguration;
|
|
@@ -59,10 +65,8 @@ export type Props = {
|
|
|
59
65
|
className?: string;
|
|
60
66
|
} & Record<string, any>;
|
|
61
67
|
|
|
62
|
-
function unmountMicroApp(microApp
|
|
63
|
-
|
|
64
|
-
microApp.mountPromise.then(() => microApp.unmount());
|
|
65
|
-
}
|
|
68
|
+
function unmountMicroApp(microApp: MicroAppType) {
|
|
69
|
+
microApp.mountPromise.then(() => microApp.unmount());
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
function useDeepCompare<T>(value: T): T {
|
|
@@ -98,7 +102,6 @@ export const MicroApp = forwardRef(
|
|
|
98
102
|
...propsFromParams
|
|
99
103
|
} = componentProps;
|
|
100
104
|
|
|
101
|
-
// ref: https://github.com/umijs/plugins/pull/866
|
|
102
105
|
// name 跟 appNameKeyAlias 这两个 key 同时存在时,优先使用 name,避免对存量应用造成 breaking change。
|
|
103
106
|
// 比如 appNameKeyAlias 配置是 id,但之前 id 正好作为普通的 props 使用过,如 <MicroApp name="app" id="123" />
|
|
104
107
|
// 正常场景会优先匹配 appNameKeyAlias 对应的字段,fallback 到 name,避免对已经使用 <MicroApp name="app" /> 的应用造成影响
|
|
@@ -133,8 +136,6 @@ export const MicroApp = forwardRef(
|
|
|
133
136
|
|
|
134
137
|
const containerRef = useRef<HTMLDivElement>();
|
|
135
138
|
const microAppRef = useRef<MicroAppType>();
|
|
136
|
-
const updatingPromise = useRef<Promise<any>>();
|
|
137
|
-
const updatingTimestamp = useRef(Date.now());
|
|
138
139
|
|
|
139
140
|
useImperativeHandle(componentRef, () => microAppRef.current);
|
|
140
141
|
|
|
@@ -143,8 +144,8 @@ export const MicroApp = forwardRef(
|
|
|
143
144
|
if (!appConfig) {
|
|
144
145
|
setComponentError(
|
|
145
146
|
new Error(
|
|
146
|
-
`[@umijs/plugin-qiankun]: Can not find the configuration of ${name} app
|
|
147
|
-
)
|
|
147
|
+
`[@umijs/plugin-qiankun]: Can not find the configuration of ${name} app! Currently, only the following apps are configured:\n${JSON.stringify(apps, null, 2)}`
|
|
148
|
+
)
|
|
148
149
|
);
|
|
149
150
|
}
|
|
150
151
|
return noop;
|
|
@@ -223,36 +224,39 @@ export const MicroApp = forwardRef(
|
|
|
223
224
|
},
|
|
224
225
|
);
|
|
225
226
|
|
|
226
|
-
return () =>
|
|
227
|
+
return () => {
|
|
228
|
+
const microApp = microAppRef.current;
|
|
229
|
+
if (microApp) {
|
|
230
|
+
// 微应用 unmount 是异步的,中间的流转状态不能确定,所有需要一个标志位来确保 unmount 开始之后不会再触发 update
|
|
231
|
+
microApp._unmounting = true;
|
|
232
|
+
unmountMicroApp(microApp);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
227
235
|
}, [name]);
|
|
228
236
|
|
|
229
237
|
useEffect(() => {
|
|
230
238
|
const microApp = microAppRef.current;
|
|
231
239
|
if (microApp) {
|
|
232
|
-
if (!
|
|
240
|
+
if (!microApp._updatingPromise) {
|
|
233
241
|
// 初始化 updatingPromise 为 microApp.mountPromise,从而确保后续更新是在应用 mount 完成之后
|
|
234
|
-
|
|
242
|
+
microApp._updatingPromise = microApp.mountPromise;
|
|
243
|
+
microApp._updatingTimestamp = Date.now();
|
|
235
244
|
} else {
|
|
236
245
|
// 确保 microApp.update 调用是跟组件状态变更顺序一致的,且后一个微应用更新必须等待前一个更新完成
|
|
237
|
-
|
|
246
|
+
microApp._updatingPromise = microApp._updatingPromise.then(() => {
|
|
238
247
|
const canUpdate = (microApp?: MicroAppType) =>
|
|
239
|
-
microApp?.update && microApp.getStatus() === 'MOUNTED';
|
|
248
|
+
microApp?.update && microApp.getStatus() === 'MOUNTED' && !microApp._unmounting;
|
|
240
249
|
if (canUpdate(microApp)) {
|
|
241
250
|
const props = {
|
|
242
251
|
...propsFromConfig,
|
|
243
252
|
...stateForSlave,
|
|
244
253
|
...propsFromParams,
|
|
245
|
-
__globalRoutesInfo: {
|
|
246
|
-
appNameKeyAlias,
|
|
247
|
-
masterHistoryType,
|
|
248
|
-
base: globalSettings.base,
|
|
249
|
-
microAppRoutes: globalSettings.microAppRoutes,
|
|
250
|
-
},
|
|
251
254
|
setLoading,
|
|
252
255
|
};
|
|
253
256
|
|
|
254
257
|
if (process.env.NODE_ENV === 'development') {
|
|
255
|
-
|
|
258
|
+
const updatingTimestamp = microApp._updatingTimestamp!;
|
|
259
|
+
if (Date.now() - updatingTimestamp < 200) {
|
|
256
260
|
console.warn(
|
|
257
261
|
`[@umijs/plugin-qiankun] It seems like microApp ${name} is updating too many times in a short time(200ms), you may need to do some optimization to avoid the unnecessary re-rendering.`,
|
|
258
262
|
);
|
|
@@ -262,7 +266,7 @@ export const MicroApp = forwardRef(
|
|
|
262
266
|
`[@umijs/plugin-qiankun] MicroApp ${name} is updating with props: `,
|
|
263
267
|
props,
|
|
264
268
|
);
|
|
265
|
-
|
|
269
|
+
microApp._updatingTimestamp = Date.now();
|
|
266
270
|
}
|
|
267
271
|
|
|
268
272
|
// 返回 microApp.update 形成链式调用
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.67",
|
|
4
4
|
"description": "@umijs/plugins",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"@ahooksjs/use-request": "^2.0.0",
|
|
21
21
|
"@ant-design/antd-theme-variable": "^1.0.0",
|
|
22
22
|
"@ant-design/icons": "^4.7.0",
|
|
23
|
+
"@ant-design/moment-webpack-plugin": "^0.0.3",
|
|
23
24
|
"@ant-design/pro-components": "^2.0.1",
|
|
24
25
|
"@tanstack/react-query": "^4.24.10",
|
|
25
26
|
"@tanstack/react-query-devtools": "^4.24.10",
|
|
@@ -42,12 +43,12 @@
|
|
|
42
43
|
"styled-components": "6.0.0-beta.9",
|
|
43
44
|
"tslib": "^2",
|
|
44
45
|
"warning": "^4.0.3",
|
|
45
|
-
"@umijs/bundler-utils": "4.0.
|
|
46
|
+
"@umijs/bundler-utils": "4.0.67",
|
|
46
47
|
"@umijs/valtio": "1.0.3"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"antd": "^4.24.1",
|
|
50
|
-
"umi": "4.0.
|
|
51
|
+
"umi": "4.0.67"
|
|
51
52
|
},
|
|
52
53
|
"publishConfig": {
|
|
53
54
|
"access": "public"
|