@umijs/plugins 4.0.33 → 4.0.35
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/qiankun/slave.js +2 -1
- package/dist/styled-components.d.ts +3 -0
- package/dist/styled-components.js +61 -0
- package/dist/utils/modelUtils.d.ts +1 -1
- package/dist/utils/modelUtils.js +51 -35
- package/dist/valtio.js +9 -2
- package/libs/qiankun/master/masterRuntimePlugin.tsx +5 -1
- package/libs/qiankun/slave/lifecycles.ts +27 -32
- package/libs/qiankun/slave/slaveRuntimePlugin.ts +9 -1
- package/package.json +5 -4
package/dist/qiankun/slave.js
CHANGED
|
@@ -247,9 +247,10 @@ export { connectMaster } from './connectMaster';
|
|
|
247
247
|
});
|
|
248
248
|
},
|
|
249
249
|
onProxyRes: (0, import_http_proxy_middleware.responseInterceptor)(async (responseBuffer, proxyRes, req2, res2) => {
|
|
250
|
+
var _a2;
|
|
250
251
|
if (proxyRes.statusCode === 302) {
|
|
251
252
|
const hostname = req2.hostname;
|
|
252
|
-
const port = process.env.PORT;
|
|
253
|
+
const port = process.env.PORT || ((_a2 = api.appData) == null ? void 0 : _a2.port);
|
|
253
254
|
const goto = `${hostname}:${port}`;
|
|
254
255
|
const redirectUrl = proxyRes.headers.location.replace(encodeURIComponent(new URL(masterEntry).hostname), encodeURIComponent(goto)) || masterEntry;
|
|
255
256
|
const redirectMessage = `[@umijs/plugin-qiankun]: redirect to ${redirectUrl}`;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/styled-components.ts
|
|
23
|
+
var styled_components_exports = {};
|
|
24
|
+
__export(styled_components_exports, {
|
|
25
|
+
default: () => styled_components_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(styled_components_exports);
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
var styled_components_default = (api) => {
|
|
30
|
+
api.describe({
|
|
31
|
+
key: "styledComponents",
|
|
32
|
+
config: {
|
|
33
|
+
schema(Joi) {
|
|
34
|
+
return Joi.object({
|
|
35
|
+
babelPlugin: Joi.object()
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
enableBy: api.EnableBy.config
|
|
40
|
+
});
|
|
41
|
+
api.modifyBabelPresetOpts((memo) => {
|
|
42
|
+
if (api.env === "development") {
|
|
43
|
+
memo.pluginStyledComponents = {
|
|
44
|
+
...api.config.styledComponents.babelPlugin
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return memo;
|
|
48
|
+
});
|
|
49
|
+
const libPath = (0, import_path.dirname)(require.resolve("styled-components/package"));
|
|
50
|
+
api.onGenerateFiles(() => {
|
|
51
|
+
api.writeTmpFile({
|
|
52
|
+
path: "index.tsx",
|
|
53
|
+
content: `
|
|
54
|
+
import styled, { ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme } from '${libPath}';
|
|
55
|
+
export { styled, ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetManager, useTheme };
|
|
56
|
+
`
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {});
|
|
@@ -26,7 +26,6 @@ export declare class ModelUtils {
|
|
|
26
26
|
sort?: object;
|
|
27
27
|
extraModels: string[];
|
|
28
28
|
}): Model[];
|
|
29
|
-
getSortedNamespaces(models: Model[]): string[];
|
|
30
29
|
getModels(opts: {
|
|
31
30
|
base: string;
|
|
32
31
|
pattern?: string;
|
|
@@ -35,6 +34,7 @@ export declare class ModelUtils {
|
|
|
35
34
|
content: string;
|
|
36
35
|
file: string;
|
|
37
36
|
}): boolean;
|
|
37
|
+
static topologicalSort: (models: Model[]) => string[];
|
|
38
38
|
static getModelsContent(models: Model[]): string;
|
|
39
39
|
}
|
|
40
40
|
export {};
|
package/dist/utils/modelUtils.js
CHANGED
|
@@ -89,7 +89,7 @@ var Model = class {
|
|
|
89
89
|
return [...deps];
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
var
|
|
92
|
+
var _ModelUtils = class {
|
|
93
93
|
constructor(api, opts) {
|
|
94
94
|
this.opts = {};
|
|
95
95
|
this.count = 1;
|
|
@@ -120,44 +120,11 @@ var ModelUtils = class {
|
|
|
120
120
|
throw new Error(`Duplicate namespace in models: ${namespaces.sort().join(", ")}`);
|
|
121
121
|
}
|
|
122
122
|
if (opts.sort) {
|
|
123
|
-
const namespaces2 =
|
|
123
|
+
const namespaces2 = _ModelUtils.topologicalSort(models);
|
|
124
124
|
models.sort((a, b) => namespaces2.indexOf(a.namespace) - namespaces2.indexOf(b.namespace));
|
|
125
125
|
}
|
|
126
126
|
return models;
|
|
127
127
|
}
|
|
128
|
-
getSortedNamespaces(models) {
|
|
129
|
-
let final = [];
|
|
130
|
-
models.forEach((model, index) => {
|
|
131
|
-
const { deps, namespace } = model;
|
|
132
|
-
if (deps && deps.length) {
|
|
133
|
-
const itemGroup = [...deps, namespace];
|
|
134
|
-
const cannotUse = [namespace];
|
|
135
|
-
for (let i = 0; i <= index; i += 1) {
|
|
136
|
-
if (models[i].deps.filter((v) => cannotUse.includes(v)).length) {
|
|
137
|
-
if (!cannotUse.includes(models[i].namespace)) {
|
|
138
|
-
cannotUse.push(models[i].namespace);
|
|
139
|
-
i = -1;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const errorList = deps.filter((v) => cannotUse.includes(v));
|
|
144
|
-
if (errorList.length) {
|
|
145
|
-
throw Error(`Circular dependencies: ${namespace} can't use ${errorList.join(", ")}`);
|
|
146
|
-
}
|
|
147
|
-
const intersection = final.filter((v) => itemGroup.includes(v));
|
|
148
|
-
if (intersection.length) {
|
|
149
|
-
const finalIndex = final.indexOf(intersection[0]);
|
|
150
|
-
final = final.slice(0, finalIndex).concat(itemGroup).concat(final.slice(finalIndex + 1));
|
|
151
|
-
} else {
|
|
152
|
-
final.push(...itemGroup);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (!final.includes(namespace)) {
|
|
156
|
-
final.push(namespace);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return [...new Set(final)];
|
|
160
|
-
}
|
|
161
128
|
getModels(opts) {
|
|
162
129
|
return import_plugin_utils.glob.sync(opts.pattern || "**/*.{ts,js}", {
|
|
163
130
|
cwd: opts.base,
|
|
@@ -222,6 +189,55 @@ ${modelProps.join("\n")}
|
|
|
222
189
|
} as const`;
|
|
223
190
|
}
|
|
224
191
|
};
|
|
192
|
+
var ModelUtils = _ModelUtils;
|
|
193
|
+
ModelUtils.topologicalSort = (models) => {
|
|
194
|
+
const graph = [];
|
|
195
|
+
const namespaceToNode = {};
|
|
196
|
+
models.forEach((model, index) => {
|
|
197
|
+
const node = {
|
|
198
|
+
namespace: model.namespace,
|
|
199
|
+
deps: model.deps,
|
|
200
|
+
index,
|
|
201
|
+
in: 0,
|
|
202
|
+
childs: []
|
|
203
|
+
};
|
|
204
|
+
if (namespaceToNode[model.namespace]) {
|
|
205
|
+
throw new Error(`Duplicate namespace in models: ${model.namespace}`);
|
|
206
|
+
}
|
|
207
|
+
namespaceToNode[model.namespace] = node;
|
|
208
|
+
graph.push(node);
|
|
209
|
+
});
|
|
210
|
+
graph.forEach((node) => {
|
|
211
|
+
node.deps.forEach((dep) => {
|
|
212
|
+
const depNode = namespaceToNode[dep];
|
|
213
|
+
if (!depNode) {
|
|
214
|
+
throw new Error(`Model namespace not found: ${dep}`);
|
|
215
|
+
}
|
|
216
|
+
depNode.childs.push(node);
|
|
217
|
+
node.in++;
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
const queue = [];
|
|
221
|
+
while (true) {
|
|
222
|
+
const zeronode = graph.find((n) => {
|
|
223
|
+
return n && n.in === 0;
|
|
224
|
+
});
|
|
225
|
+
if (!zeronode) {
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
queue.push(zeronode.namespace);
|
|
229
|
+
zeronode.childs.forEach((child) => {
|
|
230
|
+
child.in--;
|
|
231
|
+
});
|
|
232
|
+
zeronode.childs = [];
|
|
233
|
+
delete graph[zeronode.index];
|
|
234
|
+
}
|
|
235
|
+
const leftNodes = graph.filter(Boolean);
|
|
236
|
+
if (leftNodes.length > 0) {
|
|
237
|
+
throw new Error(`Circle dependency detected in models: ${leftNodes.map((m) => import_plugin_utils.chalk.red(m.namespace)).join(", ")}`);
|
|
238
|
+
}
|
|
239
|
+
return queue;
|
|
240
|
+
};
|
|
225
241
|
// Annotate the CommonJS export names for ESM import in node:
|
|
226
242
|
0 && (module.exports = {
|
|
227
243
|
Model,
|
package/dist/valtio.js
CHANGED
|
@@ -34,7 +34,8 @@ var valtio_default = (api) => {
|
|
|
34
34
|
schema(joi) {
|
|
35
35
|
return joi.object();
|
|
36
36
|
}
|
|
37
|
-
}
|
|
37
|
+
},
|
|
38
|
+
enableBy: api.EnableBy.config
|
|
38
39
|
});
|
|
39
40
|
const libPath = (0, import_utils.winPath)((0, import_path.dirname)(require.resolve("@umijs/valtio/package.json")));
|
|
40
41
|
api.onGenerateFiles(() => {
|
|
@@ -42,12 +43,18 @@ var valtio_default = (api) => {
|
|
|
42
43
|
path: "index.ts",
|
|
43
44
|
content: `
|
|
44
45
|
export {
|
|
45
|
-
proxy,
|
|
46
|
+
proxy,
|
|
47
|
+
useSnapshot,
|
|
48
|
+
snapshot,
|
|
49
|
+
subscribe,
|
|
50
|
+
subscribeKey,
|
|
46
51
|
proxyWithComputed,
|
|
47
52
|
proxyWithHistory,
|
|
48
53
|
proxyWithDevtools,
|
|
49
54
|
proxyMap,
|
|
50
55
|
proxySet,
|
|
56
|
+
derive,
|
|
57
|
+
underive,
|
|
51
58
|
} from '${libPath}';
|
|
52
59
|
`
|
|
53
60
|
});
|
|
@@ -33,7 +33,11 @@ function patchMicroAppRouteComponent(routes: any[]) {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
const getRootRoutes = (routes: any[]) => {
|
|
36
|
-
|
|
36
|
+
// 重定向根路由不能用作 microAppRuntimeRoutes 的父节点
|
|
37
|
+
const rootRoute = routes.find(
|
|
38
|
+
// 基于是否有 .to props 判断是否为 redirect
|
|
39
|
+
(route) => route.path === '/' && !route.element?.props?.to,
|
|
40
|
+
);
|
|
37
41
|
if (rootRoute) {
|
|
38
42
|
// 如果根路由是叶子节点,则直接返回其父节点
|
|
39
43
|
if (!rootRoute.children?.length) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import { getPluginManager } from '@@/core/plugin';
|
|
3
3
|
import ReactDOM from 'react-dom';
|
|
4
|
-
import { ApplyPluginsType, __getRoot } from 'umi';
|
|
4
|
+
import { ApplyPluginsType, __getRoot, history } from 'umi';
|
|
5
5
|
import { setModelState } from './qiankunModel';
|
|
6
6
|
|
|
7
7
|
const noop = () => {};
|
|
@@ -23,22 +23,22 @@ let hasMountedAtLeastOnce = false;
|
|
|
23
23
|
export default () => defer.promise;
|
|
24
24
|
export const contextOptsStack: any[] = [];
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
function normalizeHistory(
|
|
27
|
+
history?: 'string' | Record<string, any>,
|
|
28
|
+
base?: string,
|
|
29
|
+
) {
|
|
30
|
+
let normalizedHistory: Record<string, any> = {};
|
|
31
|
+
if (base) normalizedHistory.basename = base;
|
|
32
|
+
if (history) {
|
|
33
|
+
if (typeof history === 'string') {
|
|
34
|
+
normalizedHistory.type = history;
|
|
35
|
+
} else {
|
|
36
|
+
normalizedHistory = history;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return normalizedHistory;
|
|
41
|
+
}
|
|
42
42
|
|
|
43
43
|
async function getSlaveRuntime() {
|
|
44
44
|
const config = await getPluginManager().applyPlugins({
|
|
@@ -73,21 +73,24 @@ export function genMount(mountElementId: string) {
|
|
|
73
73
|
await slaveRuntime.mount(props);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
const { type, ...historyOpts } =
|
|
76
|
+
const { type, ...historyOpts } = normalizeHistory(
|
|
77
|
+
props?.history || {},
|
|
78
|
+
props?.base,
|
|
79
|
+
);
|
|
77
80
|
|
|
78
81
|
// 更新 clientRender 配置
|
|
79
82
|
const clientRenderOpts = {
|
|
80
|
-
// 默认开启
|
|
81
|
-
// 如果需要手动控制 loading,通过主应用配置 props.autoSetLoading false 可以关闭
|
|
82
83
|
callback: () => {
|
|
84
|
+
// 默认开启
|
|
85
|
+
// 如果需要手动控制 loading,通过主应用配置 props.autoSetLoading false 可以关闭
|
|
83
86
|
if (props.autoSetLoading && typeof props.setLoading === 'function') {
|
|
84
87
|
props.setLoading(false);
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
// 支持将子应用的 history 回传给父应用
|
|
91
|
+
if (typeof props?.onHistoryInit === 'function') {
|
|
92
|
+
props.onHistoryInit(history);
|
|
93
|
+
}
|
|
91
94
|
},
|
|
92
95
|
// 支持通过 props 注入 container 来限定子应用 mountElementId 的查找范围
|
|
93
96
|
// 避免多个子应用出现在同一主应用时出现 mount 冲突
|
|
@@ -125,14 +128,6 @@ export function genMount(mountElementId: string) {
|
|
|
125
128
|
defer.resolve();
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
// 如果需要手动控制 loading,通过主应用配置 props.autoSetLoading false 可以关闭
|
|
129
|
-
// 考虑到 react 18 之后 callback 不再准
|
|
130
|
-
// 所以在这里直接返回,而不使用 ReactDOM.render 的第三个参数
|
|
131
|
-
if (typeof props !== 'undefined') {
|
|
132
|
-
if (props.autoSetLoading && typeof props.setLoading === 'function') {
|
|
133
|
-
props.setLoading(false);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
131
|
hasMountedAtLeastOnce = true;
|
|
137
132
|
};
|
|
138
133
|
}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import qiankunRender, { contextOptsStack } from './lifecycles';
|
|
3
|
+
import { createHistory } from '@@/core/history';
|
|
3
4
|
|
|
4
5
|
export function render(oldRender: any) {
|
|
5
6
|
return qiankunRender().then(oldRender);
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
export function
|
|
9
|
+
export function modifyClientRenderOpts(memo: any) {
|
|
9
10
|
// 每次应用 render 的时候会调 modifyClientRenderOpts,这时尝试从队列中取 render 的配置
|
|
10
11
|
const clientRenderOpts = contextOptsStack.shift();
|
|
12
|
+
if (clientRenderOpts) {
|
|
13
|
+
clientRenderOpts.history = createHistory({
|
|
14
|
+
type: clientRenderOpts.historyType,
|
|
15
|
+
basename: clientRenderOpts.basename,
|
|
16
|
+
...clientRenderOpts.historyOpts,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
11
19
|
return {
|
|
12
20
|
...memo,
|
|
13
21
|
...clientRenderOpts,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.35",
|
|
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",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@ant-design/antd-theme-variable": "^1.0.0",
|
|
28
28
|
"@ant-design/icons": "^4.7.0",
|
|
29
29
|
"@ant-design/pro-components": "^2.0.1",
|
|
30
|
-
"@umijs/bundler-utils": "4.0.
|
|
31
|
-
"@umijs/valtio": "^1.0.
|
|
30
|
+
"@umijs/bundler-utils": "4.0.35",
|
|
31
|
+
"@umijs/valtio": "^1.0.2",
|
|
32
32
|
"antd-dayjs-webpack-plugin": "^1.0.6",
|
|
33
33
|
"axios": "^0.27.2",
|
|
34
34
|
"babel-plugin-import": "^1.13.5",
|
|
@@ -45,11 +45,12 @@
|
|
|
45
45
|
"react-intl": "3.12.1",
|
|
46
46
|
"react-redux": "^8.0.2",
|
|
47
47
|
"redux": "^4.2.0",
|
|
48
|
+
"styled-components": "6.0.0-beta.6",
|
|
48
49
|
"warning": "^4.0.3"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"antd": "^4.24.1",
|
|
52
|
-
"umi": "4.0.
|
|
53
|
+
"umi": "4.0.35"
|
|
53
54
|
},
|
|
54
55
|
"publishConfig": {
|
|
55
56
|
"access": "public"
|