@umijs/plugins 4.0.0-beta.8 → 4.0.0-canary-20240513.3
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/LICENSE +21 -0
- package/README.md +4 -1
- package/dist/access.d.ts +1 -1
- package/dist/access.js +194 -4
- package/dist/{sass.d.ts → analytics.d.ts} +1 -1
- package/dist/analytics.js +118 -0
- package/dist/antd.d.ts +1 -1
- package/dist/antd.js +345 -157
- package/dist/{icons.d.ts → confetti.d.ts} +1 -1
- package/dist/confetti.js +64 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +30 -0
- package/dist/dva.d.ts +4 -1
- package/dist/dva.js +302 -8
- package/dist/initial-state.d.ts +1 -1
- package/dist/initial-state.js +147 -4
- package/dist/layout.d.ts +1 -1
- package/dist/layout.js +754 -4
- package/dist/locale.d.ts +2 -1
- package/dist/locale.js +257 -4
- package/dist/mf.d.ts +2 -0
- package/dist/mf.js +358 -0
- package/dist/model.d.ts +1 -1
- package/dist/model.js +109 -4
- package/dist/moment2dayjs.d.ts +3 -0
- package/dist/moment2dayjs.js +125 -0
- package/dist/qiankun/constants.d.ts +5 -0
- package/dist/qiankun/constants.js +41 -0
- package/dist/qiankun/master.d.ts +6 -0
- package/dist/qiankun/master.js +236 -0
- package/dist/qiankun/slave.d.ts +3 -0
- package/dist/qiankun/slave.js +345 -0
- package/dist/qiankun.d.ts +1 -1
- package/dist/qiankun.js +51 -4
- package/dist/react-query.d.ts +3 -0
- package/dist/react-query.js +193 -0
- package/dist/request.d.ts +1 -1
- package/dist/request.js +384 -4
- package/dist/styled-components.d.ts +3 -0
- package/dist/styled-components.js +150 -0
- package/dist/tailwindcss.d.ts +3 -0
- package/dist/tailwindcss.js +106 -0
- package/dist/unocss.d.ts +3 -0
- package/dist/unocss.js +71 -0
- package/dist/utils/astUtils.d.ts +3 -0
- package/dist/utils/astUtils.js +49 -0
- package/dist/utils/localeUtils.d.ts +33 -0
- package/dist/utils/localeUtils.js +139 -0
- package/dist/utils/mfUtils.d.ts +14 -0
- package/dist/utils/mfUtils.js +56 -0
- package/dist/utils/modelUtils.d.ts +40 -0
- package/dist/utils/modelUtils.js +286 -0
- package/dist/utils/resolveProjectDep.d.ts +5 -0
- package/dist/utils/resolveProjectDep.js +40 -0
- package/dist/utils/withTmpPath.d.ts +6 -0
- package/dist/utils/withTmpPath.js +39 -0
- package/dist/valtio.d.ts +3 -0
- package/dist/valtio.js +81 -0
- package/libs/dva.tsx +45 -0
- package/libs/model.tsx +180 -0
- package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
- package/libs/qiankun/master/AntdLoader.tsx +15 -0
- package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
- package/libs/qiankun/master/MicroApp.tsx +327 -0
- package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
- package/libs/qiankun/master/common.ts +172 -0
- package/libs/qiankun/master/constants.ts +19 -0
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
- package/libs/qiankun/master/masterRuntimePlugin.tsx +161 -0
- package/libs/qiankun/master/routeUtils.ts +26 -0
- package/libs/qiankun/master/types.ts +54 -0
- package/libs/qiankun/slave/MicroAppLink.tsx +122 -0
- package/libs/qiankun/slave/connectMaster.tsx +14 -0
- package/libs/qiankun/slave/constants.ts +5 -0
- package/libs/qiankun/slave/lifecycles.ts +164 -0
- package/libs/qiankun/slave/qiankunModel.ts +18 -0
- package/libs/qiankun/slave/slaveRuntimePlugin.ts +36 -0
- package/package.json +54 -24
- package/templates/antd/runtime.ts.tpl +170 -0
- package/templates/antd/types.d.ts.tpl +17 -0
- package/templates/locale/SelectLang.tpl +502 -0
- package/templates/locale/locale.tpl +82 -0
- package/templates/locale/localeExports.tpl +307 -0
- package/templates/locale/runtime.tpl +34 -0
- package/templates/mf/runtime.ts.tpl +149 -0
- package/dist/access.d.ts.map +0 -1
- package/dist/antd.d.ts.map +0 -1
- package/dist/dva.d.ts.map +0 -1
- package/dist/icons.d.ts.map +0 -1
- package/dist/icons.js +0 -5
- package/dist/initial-state.d.ts.map +0 -1
- package/dist/layout.d.ts.map +0 -1
- package/dist/locale.d.ts.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/qiankun.d.ts.map +0 -1
- package/dist/request.d.ts.map +0 -1
- package/dist/sass.d.ts.map +0 -1
- package/dist/sass.js +0 -5
|
@@ -0,0 +1,345 @@
|
|
|
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(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/qiankun/slave.ts
|
|
30
|
+
var slave_exports = {};
|
|
31
|
+
__export(slave_exports, {
|
|
32
|
+
default: () => slave_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(slave_exports);
|
|
35
|
+
var import_http_proxy_middleware = require("@umijs/bundler-utils/compiled/http-proxy-middleware");
|
|
36
|
+
var import_utils = require("@umijs/utils");
|
|
37
|
+
var import_assert = __toESM(require("assert"));
|
|
38
|
+
var import_fs = require("fs");
|
|
39
|
+
var import_path = require("path");
|
|
40
|
+
var import_umi = require("umi");
|
|
41
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
42
|
+
var import_withTmpPath = require("../utils/withTmpPath");
|
|
43
|
+
var import_constants = require("./constants");
|
|
44
|
+
function getCurrentLocalDevServerEntry(api, req) {
|
|
45
|
+
const port = api.appData.port;
|
|
46
|
+
const hostname = req.hostname;
|
|
47
|
+
const protocol = req.protocol;
|
|
48
|
+
return `${protocol}://${hostname}${port ? ":" : ""}${port}/local-dev-server`;
|
|
49
|
+
}
|
|
50
|
+
function handleOriginalHtml(api, microAppEntry, originalHtml) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
const appName = ((_b = (_a = api.config.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.appName) || api.pkg.name;
|
|
53
|
+
(0, import_assert.default)(
|
|
54
|
+
appName,
|
|
55
|
+
"[@umijs/plugin-qiankun]: You should have name in package.json"
|
|
56
|
+
);
|
|
57
|
+
const $ = import_utils.cheerio.load(originalHtml);
|
|
58
|
+
$("head").prepend(
|
|
59
|
+
`<script>window.__QIANKUN_DEVELOPMENT__=true</script>
|
|
60
|
+
<script type="extra-qiankun-config">${JSON.stringify({
|
|
61
|
+
master: {
|
|
62
|
+
apps: [
|
|
63
|
+
{
|
|
64
|
+
name: appName,
|
|
65
|
+
entry: microAppEntry,
|
|
66
|
+
extraSource: microAppEntry
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
routes: [
|
|
70
|
+
{
|
|
71
|
+
microApp: appName,
|
|
72
|
+
name: appName,
|
|
73
|
+
path: "/" + appName,
|
|
74
|
+
extraSource: microAppEntry
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
prefetch: false
|
|
78
|
+
}
|
|
79
|
+
})}</script>`
|
|
80
|
+
);
|
|
81
|
+
return api.applyPlugins({
|
|
82
|
+
key: "modifyMasterHTML",
|
|
83
|
+
type: api.ApplyPluginsType.modify,
|
|
84
|
+
initialValue: $.html()
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function isSlaveEnable(opts) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
const slaveCfg = (_b = (_a = opts.userConfig) == null ? void 0 : _a.qiankun) == null ? void 0 : _b.slave;
|
|
90
|
+
if (slaveCfg) {
|
|
91
|
+
return slaveCfg.enable !== false;
|
|
92
|
+
}
|
|
93
|
+
return !!process.env.INITIAL_QIANKUN_SLAVE_OPTIONS;
|
|
94
|
+
}
|
|
95
|
+
var slave_default = (api) => {
|
|
96
|
+
api.describe({
|
|
97
|
+
key: "qiankun-slave",
|
|
98
|
+
enableBy: isSlaveEnable
|
|
99
|
+
});
|
|
100
|
+
api.addRuntimePlugin(() => {
|
|
101
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "slaveRuntimePlugin.ts" })];
|
|
102
|
+
});
|
|
103
|
+
api.register({
|
|
104
|
+
key: "addExtraModels",
|
|
105
|
+
fn() {
|
|
106
|
+
return [
|
|
107
|
+
(0, import_withTmpPath.withTmpPath)({
|
|
108
|
+
api,
|
|
109
|
+
path: `qiankunModel.ts#{"namespace":"${import_constants.qiankunStateFromMasterModelNamespace}"}`
|
|
110
|
+
})
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
api.onGenerateFiles(() => {
|
|
115
|
+
api.writeTmpFile({
|
|
116
|
+
path: import_umi.RUNTIME_TYPE_FILE_NAME,
|
|
117
|
+
content: `
|
|
118
|
+
interface LifeCycles {
|
|
119
|
+
bootstrap?: (props?: any) => Promise<any>;
|
|
120
|
+
mount?: (props?: any) => Promise<any>;
|
|
121
|
+
unmount?: (props?: any) => Promise<any>;
|
|
122
|
+
update?: (props?: any) => Promise<any>;
|
|
123
|
+
}
|
|
124
|
+
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
|
125
|
+
type XOR<T, U> = (Without<T, U> & U) | (Without<U, T> & T);
|
|
126
|
+
interface SlaveOption extends LifeCycles {
|
|
127
|
+
enable?: boolean;
|
|
128
|
+
}
|
|
129
|
+
interface Config {
|
|
130
|
+
slave?: SlaveOption;
|
|
131
|
+
}
|
|
132
|
+
export interface IRuntimeConfig {
|
|
133
|
+
qiankun?: XOR<Config, LifeCycles>
|
|
134
|
+
}
|
|
135
|
+
`
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
api.modifyDefaultConfig((memo) => {
|
|
139
|
+
var _a, _b, _c, _d, _e;
|
|
140
|
+
const initialSlaveOptions = {
|
|
141
|
+
devSourceMap: true,
|
|
142
|
+
...JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || "{}"),
|
|
143
|
+
...(memo.qiankun || {}).slave
|
|
144
|
+
};
|
|
145
|
+
const modifiedDefaultConfig = {
|
|
146
|
+
...memo,
|
|
147
|
+
// 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
|
|
148
|
+
runtimePublicPath: true,
|
|
149
|
+
qiankun: {
|
|
150
|
+
...memo.qiankun,
|
|
151
|
+
slave: initialSlaveOptions
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const shouldNotModifyDefaultBase = ((_b = (_a = api.userConfig.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyDefaultBase) ?? initialSlaveOptions.shouldNotModifyDefaultBase;
|
|
155
|
+
const historyType = ((_c = api.userConfig.history) == null ? void 0 : _c.type) || "browser";
|
|
156
|
+
if (!shouldNotModifyDefaultBase && historyType !== "hash") {
|
|
157
|
+
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
158
|
+
}
|
|
159
|
+
if (modifiedDefaultConfig.mfsu !== false) {
|
|
160
|
+
modifiedDefaultConfig.mfsu = {
|
|
161
|
+
...modifiedDefaultConfig.mfsu,
|
|
162
|
+
mfName: ((_d = modifiedDefaultConfig.mfsu) == null ? void 0 : _d.mfName) || `mf_${(_e = api.pkg.name) == null ? void 0 : _e.replace(/^@/, "").replace(/\W/g, "_")}`
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return modifiedDefaultConfig;
|
|
166
|
+
});
|
|
167
|
+
api.addHTMLHeadScripts(() => {
|
|
168
|
+
var _a, _b;
|
|
169
|
+
const dontModify = (_b = (_a = api.config.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyRuntimePublicPath;
|
|
170
|
+
return dontModify ? [] : [
|
|
171
|
+
`window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || "/"}";`
|
|
172
|
+
];
|
|
173
|
+
});
|
|
174
|
+
api.chainWebpack((config, { ssr }) => {
|
|
175
|
+
if (ssr) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
(0, import_assert.default)(api.pkg.name, "You should have name in package.json.");
|
|
179
|
+
const {
|
|
180
|
+
shouldNotAddLibraryChunkName = api.env === "production" || !Boolean(api.config.mfsu)
|
|
181
|
+
} = (api.config.qiankun || {}).slave;
|
|
182
|
+
config.output.libraryTarget("umd").library(
|
|
183
|
+
shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`
|
|
184
|
+
);
|
|
185
|
+
return config;
|
|
186
|
+
});
|
|
187
|
+
api.modifyHTML(($) => {
|
|
188
|
+
$("script").each((_, el) => {
|
|
189
|
+
const scriptEl = $(el);
|
|
190
|
+
const umiEntry = /\/?umi(\.\w+)?\.js$/g;
|
|
191
|
+
if (umiEntry.test(scriptEl.attr("src") ?? "")) {
|
|
192
|
+
scriptEl.attr("entry", "");
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return $;
|
|
196
|
+
});
|
|
197
|
+
api.addEntryImports(() => {
|
|
198
|
+
return [
|
|
199
|
+
{
|
|
200
|
+
source: "@@/plugin-qiankun-slave/lifecycles",
|
|
201
|
+
specifier: "{ genMount as qiankun_genMount, genBootstrap as qiankun_genBootstrap, genUnmount as qiankun_genUnmount, genUpdate as qiankun_genUpdate }"
|
|
202
|
+
}
|
|
203
|
+
];
|
|
204
|
+
});
|
|
205
|
+
api.addEntryCode(() => [
|
|
206
|
+
`
|
|
207
|
+
const qiankun_noop = () => new Error('qiankun lifecycle is not available for server runtime!');
|
|
208
|
+
const isServer = typeof window === 'undefined';
|
|
209
|
+
export const bootstrap = isServer ? qiankun_noop: qiankun_genBootstrap(render);
|
|
210
|
+
export const mount = isServer ? qiankun_noop : qiankun_genMount('${api.config.mountElementId}');
|
|
211
|
+
export const unmount = isServer ? qiankun_noop : qiankun_genUnmount('${api.config.mountElementId}');
|
|
212
|
+
export const update = isServer ? qiankun_noop : qiankun_genUpdate();
|
|
213
|
+
// 增加 ssr 的判断
|
|
214
|
+
if (!isServer && !window.__POWERED_BY_QIANKUN__) {
|
|
215
|
+
bootstrap().then(mount);
|
|
216
|
+
}
|
|
217
|
+
`
|
|
218
|
+
]);
|
|
219
|
+
function getFileContent(file) {
|
|
220
|
+
return (0, import_fs.readFileSync)(
|
|
221
|
+
(0, import_path.join)(__dirname, "../../libs/qiankun/slave", file),
|
|
222
|
+
"utf-8"
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
api.onGenerateFiles({
|
|
226
|
+
fn() {
|
|
227
|
+
[
|
|
228
|
+
"constants.ts",
|
|
229
|
+
"qiankunModel.ts",
|
|
230
|
+
"connectMaster.tsx",
|
|
231
|
+
"MicroAppLink.tsx",
|
|
232
|
+
"slaveRuntimePlugin.ts",
|
|
233
|
+
"lifecycles.ts"
|
|
234
|
+
].forEach((file) => {
|
|
235
|
+
api.writeTmpFile({
|
|
236
|
+
path: file.replace(/\.tpl$/, ""),
|
|
237
|
+
content: getFileContent(file).replace(
|
|
238
|
+
"__USE_MODEL__",
|
|
239
|
+
api.isPluginEnable("model") ? `import { useModel } from '@@/plugin-model'` : `const useModel = null;`
|
|
240
|
+
).replace(
|
|
241
|
+
/from 'qiankun'/g,
|
|
242
|
+
`from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("qiankun/package")))}'`
|
|
243
|
+
).replace(
|
|
244
|
+
/from 'lodash\//g,
|
|
245
|
+
`from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("lodash/package")))}/`
|
|
246
|
+
)
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
api.writeTmpFile({
|
|
250
|
+
path: "index.ts",
|
|
251
|
+
content: `
|
|
252
|
+
export { connectMaster } from './connectMaster';
|
|
253
|
+
export { MicroAppLink } from './MicroAppLink';
|
|
254
|
+
`
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
before: "model"
|
|
258
|
+
});
|
|
259
|
+
api.addMiddlewares(async () => {
|
|
260
|
+
return async (req, res, next) => {
|
|
261
|
+
var _a;
|
|
262
|
+
const qiankunConfig = api.config.qiankun || {};
|
|
263
|
+
const masterEntry = (_a = qiankunConfig.slave) == null ? void 0 : _a.masterEntry;
|
|
264
|
+
const { proxyToMasterEnabled } = await api.applyPlugins({
|
|
265
|
+
key: "shouldProxyToMaster",
|
|
266
|
+
type: api.ApplyPluginsType.modify,
|
|
267
|
+
initialValue: { proxyToMasterEnabled: true, req }
|
|
268
|
+
}) ?? {};
|
|
269
|
+
if (masterEntry && proxyToMasterEnabled) {
|
|
270
|
+
await api.applyPlugins({
|
|
271
|
+
key: "onLocalProxyStart",
|
|
272
|
+
type: api.ApplyPluginsType.event
|
|
273
|
+
});
|
|
274
|
+
const modifyLocalProxyOpts = await api.applyPlugins({
|
|
275
|
+
key: "modifyLocalProxyOpts",
|
|
276
|
+
type: api.ApplyPluginsType.modify,
|
|
277
|
+
initialValue: {}
|
|
278
|
+
}) ?? {};
|
|
279
|
+
const localProxyOpts = {
|
|
280
|
+
target: masterEntry,
|
|
281
|
+
secure: false,
|
|
282
|
+
ignorePath: false,
|
|
283
|
+
followRedirects: false,
|
|
284
|
+
changeOrigin: true,
|
|
285
|
+
selfHandleResponse: true,
|
|
286
|
+
...modifyLocalProxyOpts
|
|
287
|
+
};
|
|
288
|
+
return (0, import_http_proxy_middleware.createProxyMiddleware)(
|
|
289
|
+
(pathname) => pathname !== "/local-dev-server",
|
|
290
|
+
{
|
|
291
|
+
...localProxyOpts,
|
|
292
|
+
onProxyReq(proxyReq) {
|
|
293
|
+
api.applyPlugins({
|
|
294
|
+
key: "onLocalProxyReq",
|
|
295
|
+
type: api.ApplyPluginsType.event,
|
|
296
|
+
sync: true,
|
|
297
|
+
args: proxyReq
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
onProxyRes: (0, import_http_proxy_middleware.responseInterceptor)(
|
|
301
|
+
async (responseBuffer, proxyRes, req2, res2) => {
|
|
302
|
+
var _a2;
|
|
303
|
+
if (proxyRes.statusCode === 302) {
|
|
304
|
+
const { ignorePath = false } = localProxyOpts;
|
|
305
|
+
const { hostname, url, protocol } = req2;
|
|
306
|
+
const port = process.env.PORT || ((_a2 = api.appData) == null ? void 0 : _a2.port);
|
|
307
|
+
const gotoBasePart = `${protocol}://${hostname}:${port}${ignorePath && url ? url : "/"}`;
|
|
308
|
+
const fromBasePart = masterEntry;
|
|
309
|
+
const locationUrl = proxyRes.headers.location || "";
|
|
310
|
+
const [originAndPath, searchParams] = locationUrl.split("?");
|
|
311
|
+
const searchHandled = searchParams ? `?${searchParams.replace(
|
|
312
|
+
encodeURIComponent(fromBasePart),
|
|
313
|
+
encodeURIComponent(gotoBasePart)
|
|
314
|
+
)}` : "";
|
|
315
|
+
const redirectUrl = `${originAndPath}${searchHandled}`;
|
|
316
|
+
const redirectMessage = `[@umijs/plugin-qiankun]: redirect to ${redirectUrl}`;
|
|
317
|
+
api.logger.info(redirectMessage);
|
|
318
|
+
res2.statusCode = 302;
|
|
319
|
+
res2.setHeader("location", redirectUrl);
|
|
320
|
+
return redirectMessage;
|
|
321
|
+
}
|
|
322
|
+
const microAppEntry = getCurrentLocalDevServerEntry(api, req2);
|
|
323
|
+
const originalHtml = responseBuffer.toString("utf8");
|
|
324
|
+
const html = handleOriginalHtml(
|
|
325
|
+
api,
|
|
326
|
+
microAppEntry,
|
|
327
|
+
originalHtml
|
|
328
|
+
);
|
|
329
|
+
return html;
|
|
330
|
+
}
|
|
331
|
+
),
|
|
332
|
+
onError(err, _, res2) {
|
|
333
|
+
api.logger.error(err);
|
|
334
|
+
res2.set("content-type", "text/plain; charset=UTF-8");
|
|
335
|
+
res2.end(
|
|
336
|
+
`[@umijs/plugin-qiankun] 代理到 ${masterEntry} 时出错了,请尝试 ${masterEntry} 是否是可以正常访问的,然后重新启动项目试试。(注意如果出现跨域问题,请修改本地 host ,通过一个和主应用相同的一级域名的域名来访问 127.0.0.1)`
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
)(req, res, next);
|
|
341
|
+
}
|
|
342
|
+
return next();
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
};
|
package/dist/qiankun.d.ts
CHANGED
package/dist/qiankun.js
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
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(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/qiankun.ts
|
|
30
|
+
var qiankun_exports = {};
|
|
31
|
+
__export(qiankun_exports, {
|
|
32
|
+
default: () => qiankun_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(qiankun_exports);
|
|
35
|
+
var qiankun_default = (api) => {
|
|
36
|
+
api.describe({
|
|
37
|
+
config: {
|
|
38
|
+
schema({ zod }) {
|
|
39
|
+
return zod.object({
|
|
40
|
+
slave: zod.record(zod.any()),
|
|
41
|
+
master: zod.record(zod.any()),
|
|
42
|
+
externalQiankun: zod.boolean()
|
|
43
|
+
}).deepPartial();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
api.addRuntimePluginKey(() => ["qiankun"]);
|
|
48
|
+
api.registerPlugins([
|
|
49
|
+
require.resolve("./qiankun/master"),
|
|
50
|
+
require.resolve("./qiankun/slave")
|
|
51
|
+
]);
|
|
5
52
|
};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/react-query.ts
|
|
20
|
+
var react_query_exports = {};
|
|
21
|
+
__export(react_query_exports, {
|
|
22
|
+
default: () => react_query_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(react_query_exports);
|
|
25
|
+
var import_utils = require("@umijs/utils");
|
|
26
|
+
var import_path = require("path");
|
|
27
|
+
var import_resolveProjectDep = require("./utils/resolveProjectDep");
|
|
28
|
+
var import_withTmpPath = require("./utils/withTmpPath");
|
|
29
|
+
var react_query_default = (api) => {
|
|
30
|
+
api.describe({
|
|
31
|
+
key: "reactQuery",
|
|
32
|
+
config: {
|
|
33
|
+
schema({ zod }) {
|
|
34
|
+
return zod.object({
|
|
35
|
+
devtool: zod.union([zod.record(zod.any()), zod.boolean()]),
|
|
36
|
+
queryClient: zod.union([zod.record(zod.any()), zod.boolean()])
|
|
37
|
+
}).deepPartial();
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
enableBy: api.EnableBy.config
|
|
41
|
+
});
|
|
42
|
+
let pkgPath;
|
|
43
|
+
let devtoolsPkgPath;
|
|
44
|
+
const REACT_QUERY_DEP_NAME = "@tanstack/react-query";
|
|
45
|
+
const REACT_QUERY_DEVTOOLS_DEP_NAME = "@tanstack/react-query-devtools";
|
|
46
|
+
const defaultPkgPath = (0, import_utils.winPath)(
|
|
47
|
+
(0, import_path.dirname)(require.resolve(`${REACT_QUERY_DEP_NAME}/package.json`))
|
|
48
|
+
);
|
|
49
|
+
const defaultDevtoolPkgPath = (0, import_utils.winPath)(
|
|
50
|
+
(0, import_path.dirname)(require.resolve(`${REACT_QUERY_DEVTOOLS_DEP_NAME}/package.json`))
|
|
51
|
+
);
|
|
52
|
+
try {
|
|
53
|
+
const localQueryPath = (0, import_resolveProjectDep.resolveProjectDep)({
|
|
54
|
+
pkg: api.pkg,
|
|
55
|
+
cwd: api.cwd,
|
|
56
|
+
dep: REACT_QUERY_DEP_NAME
|
|
57
|
+
});
|
|
58
|
+
pkgPath = localQueryPath ? (0, import_utils.winPath)(localQueryPath) : defaultPkgPath;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`[reactQuery] package '${REACT_QUERY_DEP_NAME}' resolve failed, ${e.message}`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const localDevtoolsPkgPath = (0, import_resolveProjectDep.resolveProjectDep)({
|
|
66
|
+
pkg: api.pkg,
|
|
67
|
+
cwd: api.cwd,
|
|
68
|
+
dep: REACT_QUERY_DEVTOOLS_DEP_NAME
|
|
69
|
+
});
|
|
70
|
+
devtoolsPkgPath = localDevtoolsPkgPath ? (0, import_utils.winPath)(localDevtoolsPkgPath) : defaultDevtoolPkgPath;
|
|
71
|
+
} catch (e) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`[reactQuery] package '${REACT_QUERY_DEVTOOLS_DEP_NAME}' resolve failed, ${e.message}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const pkg = require((0, import_path.join)(pkgPath, "package.json"));
|
|
77
|
+
const devtoolsPkg = require((0, import_path.join)(devtoolsPkgPath, "package.json"));
|
|
78
|
+
const pkgVersion = pkg.version;
|
|
79
|
+
const devtoolsVersion = devtoolsPkg.version;
|
|
80
|
+
const useV4 = pkgVersion.startsWith("4");
|
|
81
|
+
const useV4Devtools = devtoolsVersion.startsWith("4");
|
|
82
|
+
const useV5 = pkgVersion.startsWith("5");
|
|
83
|
+
const useV5Devtools = devtoolsVersion.startsWith("5");
|
|
84
|
+
const canUseDevtools = useV4 && useV4Devtools || useV5 && useV5Devtools;
|
|
85
|
+
api.onStart(() => {
|
|
86
|
+
if (pkgPath !== defaultPkgPath && !process.env.IS_UMI_BUILD_WORKER) {
|
|
87
|
+
api.logger.info(`[reactQuery] use local package, version: ${pkgVersion}`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
api.addRuntimePlugin(() => {
|
|
91
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
|
|
92
|
+
});
|
|
93
|
+
api.addRuntimePluginKey(() => {
|
|
94
|
+
return ["reactQuery"];
|
|
95
|
+
});
|
|
96
|
+
api.modifyConfig((memo) => {
|
|
97
|
+
memo.alias[REACT_QUERY_DEP_NAME] = pkgPath;
|
|
98
|
+
if (canUseDevtools) {
|
|
99
|
+
memo.alias[REACT_QUERY_DEVTOOLS_DEP_NAME] = devtoolsPkgPath;
|
|
100
|
+
}
|
|
101
|
+
return memo;
|
|
102
|
+
});
|
|
103
|
+
api.onGenerateFiles(() => {
|
|
104
|
+
var _a;
|
|
105
|
+
const enableDevTools = api.config.reactQuery.devtool !== false && canUseDevtools;
|
|
106
|
+
const enableQueryClient = api.config.reactQuery.queryClient !== false;
|
|
107
|
+
const reactQueryRuntimeCode = ((_a = api.appData.appJS) == null ? void 0 : _a.exports.includes(
|
|
108
|
+
"reactQuery"
|
|
109
|
+
)) ? `import { reactQuery as reactQueryConfig } from '@/app';` : `const reactQueryConfig = {};`;
|
|
110
|
+
api.writeTmpFile({
|
|
111
|
+
path: "runtime.tsx",
|
|
112
|
+
content: enableQueryClient ? `
|
|
113
|
+
import React from 'react';
|
|
114
|
+
import {
|
|
115
|
+
${useV4 ? "defaultContext," : ""}
|
|
116
|
+
QueryClient,
|
|
117
|
+
QueryClientProvider
|
|
118
|
+
} from '${pkgPath}';
|
|
119
|
+
${enableDevTools ? `import { ReactQueryDevtools } from '${devtoolsPkgPath}';` : ""}
|
|
120
|
+
${reactQueryRuntimeCode}
|
|
121
|
+
const client = new QueryClient(reactQueryConfig.queryClient || {});
|
|
122
|
+
export function rootContainer(container) {
|
|
123
|
+
return (
|
|
124
|
+
<QueryClientProvider
|
|
125
|
+
client={client}
|
|
126
|
+
${useV4 ? "context={defaultContext}" : ""}
|
|
127
|
+
>
|
|
128
|
+
{container}
|
|
129
|
+
${enableDevTools ? `<ReactQueryDevtools
|
|
130
|
+
${useV4 ? "context={defaultContext}" : ""}
|
|
131
|
+
initialIsOpen={false}
|
|
132
|
+
{...(reactQueryConfig.devtool || {})}
|
|
133
|
+
/>` : ""}
|
|
134
|
+
</QueryClientProvider>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
` : ""
|
|
138
|
+
});
|
|
139
|
+
api.writeTmpFile({
|
|
140
|
+
path: "index.tsx",
|
|
141
|
+
content: `
|
|
142
|
+
export {
|
|
143
|
+
// from @tanstack/query-core
|
|
144
|
+
QueryClient,
|
|
145
|
+
MutationObserver,
|
|
146
|
+
MutationCache,
|
|
147
|
+
InfiniteQueryObserver,
|
|
148
|
+
QueriesObserver,
|
|
149
|
+
QueryObserver,
|
|
150
|
+
QueryCache,
|
|
151
|
+
// from @tanstack/react-query
|
|
152
|
+
useIsRestoring,
|
|
153
|
+
IsRestoringProvider,
|
|
154
|
+
useInfiniteQuery,
|
|
155
|
+
useIsMutating,
|
|
156
|
+
useIsFetching,
|
|
157
|
+
useMutation,
|
|
158
|
+
useQueries,
|
|
159
|
+
useQuery,
|
|
160
|
+
QueryClientProvider,
|
|
161
|
+
useQueryClient,
|
|
162
|
+
QueryErrorResetBoundary,
|
|
163
|
+
useQueryErrorResetBoundary,
|
|
164
|
+
${useV5 ? "queryOptions," : ""}
|
|
165
|
+
} from '${pkgPath}';
|
|
166
|
+
`
|
|
167
|
+
});
|
|
168
|
+
api.writeTmpFile({
|
|
169
|
+
path: "types.d.ts",
|
|
170
|
+
content: `
|
|
171
|
+
export type {
|
|
172
|
+
// from @tanstack/query-core
|
|
173
|
+
Query, QueryState, Mutation,
|
|
174
|
+
// from @tanstack/react-query
|
|
175
|
+
QueriesResults,
|
|
176
|
+
QueriesOptions,
|
|
177
|
+
QueryErrorResetBoundaryProps,
|
|
178
|
+
QueryClientProviderProps,
|
|
179
|
+
${useV4 ? "ContextOptions as QueryContextOptions," : ""}
|
|
180
|
+
UseQueryOptions,
|
|
181
|
+
UseBaseQueryOptions,
|
|
182
|
+
UseQueryResult,
|
|
183
|
+
UseBaseQueryResult,
|
|
184
|
+
UseInfiniteQueryOptions,
|
|
185
|
+
UseMutationResult,
|
|
186
|
+
UseMutateFunction,
|
|
187
|
+
UseMutateAsyncFunction,
|
|
188
|
+
UseBaseMutationResult,
|
|
189
|
+
} from '${pkgPath}';
|
|
190
|
+
`
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
package/dist/request.d.ts
CHANGED