@umijs/plugins 4.0.7 → 4.0.8
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 +69 -53
- package/dist/analytics.js +62 -41
- package/dist/antd.js +139 -123
- package/dist/dva.js +133 -142
- package/dist/icons.js +28 -4
- package/dist/initial-state.js +71 -54
- package/dist/layout.js +179 -207
- package/dist/locale.js +213 -191
- package/dist/model.js +79 -78
- package/dist/moment2dayjs.js +102 -81
- package/dist/qiankun/constants.js +41 -8
- package/dist/qiankun/master.js +147 -121
- package/dist/qiankun/slave.js +160 -150
- package/dist/qiankun.js +46 -19
- package/dist/request.js +77 -51
- package/dist/tailwindcss.js +70 -49
- package/dist/unocss.js +56 -36
- package/dist/utils/astUtils.js +38 -34
- package/dist/utils/localeUtils.js +125 -120
- package/dist/utils/modelUtils.js +216 -237
- package/dist/utils/resolveProjectDep.js +36 -13
- package/dist/utils/withTmpPath.js +31 -9
- package/libs/qiankun/master/MicroApp.tsx +9 -10
- package/libs/qiankun/slave/lifecycles.ts +1 -1
- package/package.json +5 -5
package/dist/qiankun/slave.js
CHANGED
|
@@ -1,119 +1,140 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
4
35
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
36
|
+
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));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
|
|
39
|
+
// slave.ts
|
|
40
|
+
var slave_exports = {};
|
|
41
|
+
__export(slave_exports, {
|
|
42
|
+
default: () => slave_default
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(slave_exports);
|
|
45
|
+
var import_assert = __toESM(require("assert"));
|
|
46
|
+
var import_fs = require("fs");
|
|
47
|
+
var import_path = require("path");
|
|
48
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
49
|
+
var import_withTmpPath = require("../utils/withTmpPath");
|
|
50
|
+
var import_constants = require("./constants");
|
|
13
51
|
function isSlaveEnable(opts) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
52
|
+
var _a, _b;
|
|
53
|
+
const slaveCfg = (_b = (_a = opts.userConfig) == null ? void 0 : _a.qiankun) == null ? void 0 : _b.slave;
|
|
54
|
+
if (slaveCfg) {
|
|
55
|
+
return slaveCfg.enable !== false;
|
|
56
|
+
}
|
|
57
|
+
return !!process.env.INITIAL_QIANKUN_SLAVE_OPTIONS;
|
|
20
58
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
runtimePublicPath: true,
|
|
51
|
-
qiankun: {
|
|
52
|
-
...memo.qiankun,
|
|
53
|
-
slave: initialSlaveOptions,
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
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;
|
|
57
|
-
const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
|
|
58
|
-
if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
61
|
-
}
|
|
62
|
-
return modifiedDefaultConfig;
|
|
63
|
-
});
|
|
64
|
-
api.modifyConfig((config) => {
|
|
65
|
-
var _a, _b;
|
|
66
|
-
// mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
|
|
67
|
-
if (config.mfsu !== false) {
|
|
68
|
-
config.mfsu = {
|
|
69
|
-
...config.mfsu,
|
|
70
|
-
mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
|
|
71
|
-
`mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}`,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
return config;
|
|
75
|
-
});
|
|
76
|
-
api.addHTMLHeadScripts(() => {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
const dontModify = (_b = (_a = api.config.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyRuntimePublicPath;
|
|
79
|
-
return dontModify
|
|
80
|
-
? []
|
|
81
|
-
: [
|
|
82
|
-
`window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || '/'}";`,
|
|
83
|
-
];
|
|
84
|
-
});
|
|
85
|
-
api.chainWebpack((config) => {
|
|
86
|
-
(0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
|
|
87
|
-
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
88
|
-
config.output
|
|
89
|
-
.libraryTarget('umd')
|
|
90
|
-
.library(shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`);
|
|
91
|
-
// TODO: SOCKET_SERVER
|
|
92
|
-
// TODO: devSourceMap
|
|
93
|
-
return config;
|
|
94
|
-
});
|
|
95
|
-
// umi bundle 添加 entry 标记
|
|
96
|
-
api.modifyHTML(($) => {
|
|
97
|
-
$('script').each((_, el) => {
|
|
98
|
-
var _a;
|
|
99
|
-
const scriptEl = $(el);
|
|
100
|
-
const umiEntry = /\/?umi(\.\w+)?\.js$/g;
|
|
101
|
-
if (umiEntry.test((_a = scriptEl.attr('src')) !== null && _a !== void 0 ? _a : '')) {
|
|
102
|
-
scriptEl.attr('entry', '');
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return $;
|
|
59
|
+
var slave_default = (api) => {
|
|
60
|
+
api.describe({
|
|
61
|
+
key: "qiankun-slave",
|
|
62
|
+
enableBy: isSlaveEnable
|
|
63
|
+
});
|
|
64
|
+
api.addRuntimePlugin(() => {
|
|
65
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "slaveRuntimePlugin.ts" })];
|
|
66
|
+
});
|
|
67
|
+
api.register({
|
|
68
|
+
key: "addExtraModels",
|
|
69
|
+
fn() {
|
|
70
|
+
return [
|
|
71
|
+
(0, import_withTmpPath.withTmpPath)({
|
|
72
|
+
api,
|
|
73
|
+
path: `qiankunModel.ts#{"namespace":"${import_constants.qiankunStateFromMasterModelNamespace}"}`
|
|
74
|
+
})
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
api.modifyDefaultConfig((memo) => {
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
const initialSlaveOptions = __spreadValues(__spreadValues({
|
|
81
|
+
devSourceMap: true
|
|
82
|
+
}, JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || "{}")), (memo.qiankun || {}).slave);
|
|
83
|
+
const modifiedDefaultConfig = __spreadProps(__spreadValues({}, memo), {
|
|
84
|
+
runtimePublicPath: true,
|
|
85
|
+
qiankun: __spreadProps(__spreadValues({}, memo.qiankun), {
|
|
86
|
+
slave: initialSlaveOptions
|
|
87
|
+
})
|
|
106
88
|
});
|
|
107
|
-
api.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
89
|
+
const shouldNotModifyDefaultBase = ((_b = (_a = api.userConfig.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyDefaultBase) ?? initialSlaveOptions.shouldNotModifyDefaultBase;
|
|
90
|
+
const historyType = ((_c = api.userConfig.history) == null ? void 0 : _c.type) || "browser";
|
|
91
|
+
if (!shouldNotModifyDefaultBase && historyType !== "hash") {
|
|
92
|
+
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
93
|
+
}
|
|
94
|
+
return modifiedDefaultConfig;
|
|
95
|
+
});
|
|
96
|
+
api.modifyConfig((config) => {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
if (config.mfsu !== false) {
|
|
99
|
+
config.mfsu = __spreadProps(__spreadValues({}, config.mfsu), {
|
|
100
|
+
mfName: ((_a = config.mfsu) == null ? void 0 : _a.mfName) || `mf_${(_b = api.pkg.name) == null ? void 0 : _b.replace(/^@/, "").replace(/\W/g, "_")}`
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return config;
|
|
104
|
+
});
|
|
105
|
+
api.addHTMLHeadScripts(() => {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
const dontModify = (_b = (_a = api.config.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyRuntimePublicPath;
|
|
108
|
+
return dontModify ? [] : [
|
|
109
|
+
`window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || "/"}";`
|
|
110
|
+
];
|
|
111
|
+
});
|
|
112
|
+
api.chainWebpack((config) => {
|
|
113
|
+
(0, import_assert.default)(api.pkg.name, "You should have name in package.json.");
|
|
114
|
+
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
115
|
+
config.output.libraryTarget("umd").library(shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`);
|
|
116
|
+
return config;
|
|
117
|
+
});
|
|
118
|
+
api.modifyHTML(($) => {
|
|
119
|
+
$("script").each((_, el) => {
|
|
120
|
+
const scriptEl = $(el);
|
|
121
|
+
const umiEntry = /\/?umi(\.\w+)?\.js$/g;
|
|
122
|
+
if (umiEntry.test(scriptEl.attr("src") ?? "")) {
|
|
123
|
+
scriptEl.attr("entry", "");
|
|
124
|
+
}
|
|
114
125
|
});
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
return $;
|
|
127
|
+
});
|
|
128
|
+
api.addEntryImports(() => {
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
source: "@@/plugin-qiankun-slave/lifecycles",
|
|
132
|
+
specifier: "{ genMount as qiankun_genMount, genBootstrap as qiankun_genBootstrap, genUnmount as qiankun_genUnmount, genUpdate as qiankun_genUpdate }"
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
});
|
|
136
|
+
api.addEntryCode(() => [
|
|
137
|
+
`
|
|
117
138
|
export const bootstrap = qiankun_genBootstrap(render);
|
|
118
139
|
export const mount = qiankun_genMount('${api.config.mountElementId}');
|
|
119
140
|
export const unmount = qiankun_genUnmount('${api.config.mountElementId}');
|
|
@@ -121,44 +142,33 @@ export const update = qiankun_genUpdate();
|
|
|
121
142
|
if (!window.__POWERED_BY_QIANKUN__) {
|
|
122
143
|
bootstrap().then(mount);
|
|
123
144
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
api.writeTmpFile({
|
|
146
|
-
path: file.replace(/\.tpl$/, ''),
|
|
147
|
-
content: getFileContent(file)
|
|
148
|
-
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
149
|
-
? `import { useModel } from '@@/plugin-model'`
|
|
150
|
-
: `const useModel = null;`)
|
|
151
|
-
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
152
|
-
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
api.writeTmpFile({
|
|
156
|
-
path: 'index.ts',
|
|
157
|
-
content: `
|
|
145
|
+
`
|
|
146
|
+
]);
|
|
147
|
+
function getFileContent(file) {
|
|
148
|
+
return (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../../libs/qiankun/slave", file), "utf-8");
|
|
149
|
+
}
|
|
150
|
+
api.onGenerateFiles({
|
|
151
|
+
fn() {
|
|
152
|
+
[
|
|
153
|
+
"qiankunModel.ts",
|
|
154
|
+
"connectMaster.tsx",
|
|
155
|
+
"slaveRuntimePlugin.ts",
|
|
156
|
+
"lifecycles.ts"
|
|
157
|
+
].forEach((file) => {
|
|
158
|
+
api.writeTmpFile({
|
|
159
|
+
path: file.replace(/\.tpl$/, ""),
|
|
160
|
+
content: getFileContent(file).replace("__USE_MODEL__", api.isPluginEnable("model") ? `import { useModel } from '@@/plugin-model'` : `const useModel = null;`).replace(/from 'qiankun'/g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("qiankun/package")))}'`).replace(/from 'lodash\//g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("lodash/package")))}/`)
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
api.writeTmpFile({
|
|
164
|
+
path: "index.ts",
|
|
165
|
+
content: `
|
|
158
166
|
export { connectMaster } from './connectMaster';
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
167
|
+
`
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
before: "model"
|
|
171
|
+
});
|
|
164
172
|
};
|
|
173
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
174
|
+
0 && (module.exports = {});
|
package/dist/qiankun.js
CHANGED
|
@@ -1,20 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
externalQiankun: joi.boolean(),
|
|
11
|
-
});
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
api.addRuntimePluginKey(() => ['qiankun']);
|
|
16
|
-
api.registerPlugins([
|
|
17
|
-
require.resolve('./qiankun/master'),
|
|
18
|
-
require.resolve('./qiankun/slave'),
|
|
19
|
-
]);
|
|
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 });
|
|
20
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
|
+
// qiankun.ts
|
|
23
|
+
var qiankun_exports = {};
|
|
24
|
+
__export(qiankun_exports, {
|
|
25
|
+
default: () => qiankun_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(qiankun_exports);
|
|
28
|
+
var qiankun_default = (api) => {
|
|
29
|
+
api.describe({
|
|
30
|
+
config: {
|
|
31
|
+
schema(joi) {
|
|
32
|
+
return joi.object().keys({
|
|
33
|
+
slave: joi.object(),
|
|
34
|
+
master: joi.object(),
|
|
35
|
+
externalQiankun: joi.boolean()
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
api.addRuntimePluginKey(() => ["qiankun"]);
|
|
41
|
+
api.registerPlugins([
|
|
42
|
+
require.resolve("./qiankun/master"),
|
|
43
|
+
require.resolve("./qiankun/slave")
|
|
44
|
+
]);
|
|
45
|
+
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {});
|
package/dist/request.js
CHANGED
|
@@ -1,24 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
// request.ts
|
|
23
|
+
var request_exports = {};
|
|
24
|
+
__export(request_exports, {
|
|
25
|
+
default: () => request_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(request_exports);
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
30
|
+
var request_default = (api) => {
|
|
31
|
+
api.describe({
|
|
32
|
+
key: "request",
|
|
33
|
+
config: {
|
|
34
|
+
schema: (joi) => {
|
|
35
|
+
return joi.object({
|
|
36
|
+
dataField: joi.string().pattern(/^[a-zA-Z]*$/).allow("")
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
enableBy: api.EnableBy.config
|
|
41
|
+
});
|
|
42
|
+
api.addRuntimePluginKey(() => ["request"]);
|
|
43
|
+
const requestTpl = `
|
|
22
44
|
import axios, {
|
|
23
45
|
type AxiosInstance,
|
|
24
46
|
type AxiosRequestConfig,
|
|
@@ -101,7 +123,7 @@ function useRequest(service: any, options: any = {}) {
|
|
|
101
123
|
});
|
|
102
124
|
}
|
|
103
125
|
|
|
104
|
-
// request
|
|
126
|
+
// request \u65B9\u6CD5 opts \u53C2\u6570\u7684\u63A5\u53E3
|
|
105
127
|
interface IRequestOptions extends AxiosRequestConfig {
|
|
106
128
|
skipErrorHandler?: boolean;
|
|
107
129
|
requestInterceptors?: IRequestInterceptorTuple[];
|
|
@@ -120,8 +142,8 @@ interface IRequestOptionsWithoutResponse extends IRequestOptions{
|
|
|
120
142
|
interface IRequest{
|
|
121
143
|
<T = any>(url: string, opts: IRequestOptionsWithResponse): Promise<AxiosResponse<T>>;
|
|
122
144
|
<T = any>(url: string, opts: IRequestOptionsWithoutResponse): Promise<T>;
|
|
123
|
-
<T = any>(url: string, opts: IRequestOptions): Promise<T>; // getResponse
|
|
124
|
-
<T = any>(url: string): Promise<T>; //
|
|
145
|
+
<T = any>(url: string, opts: IRequestOptions): Promise<T>; // getResponse \u9ED8\u8BA4\u662F false\uFF0C \u56E0\u6B64\u4E0D\u63D0\u4F9B\u8BE5\u53C2\u6570\u65F6\uFF0C\u53EA\u8FD4\u56DE data
|
|
146
|
+
<T = any>(url: string): Promise<T>; // \u4E0D\u63D0\u4F9B opts \u65F6\uFF0C\u9ED8\u8BA4\u4F7F\u7528 'GET' method\uFF0C\u5E76\u4E14\u9ED8\u8BA4\u8FD4\u56DE data
|
|
125
147
|
}
|
|
126
148
|
|
|
127
149
|
type RequestError = AxiosError | Error
|
|
@@ -191,7 +213,7 @@ const getRequestInstance = (): AxiosInstance => {
|
|
|
191
213
|
requestInstance.interceptors.response.use(interceptor);
|
|
192
214
|
});
|
|
193
215
|
|
|
194
|
-
//
|
|
216
|
+
// \u5F53\u54CD\u5E94\u7684\u6570\u636E success \u662F false \u7684\u65F6\u5019\uFF0C\u629B\u51FA error \u4EE5\u4F9B errorHandler \u5904\u7406\u3002
|
|
195
217
|
requestInstance.interceptors.response.use((response) => {
|
|
196
218
|
const { data } = response;
|
|
197
219
|
if(data?.success === false && config?.errorConfig?.errorThrower){
|
|
@@ -275,31 +297,33 @@ export type {
|
|
|
275
297
|
AxiosInstance,
|
|
276
298
|
AxiosRequestConfig,
|
|
277
299
|
AxiosResponse,
|
|
300
|
+
AxiosError,
|
|
301
|
+
RequestError,
|
|
278
302
|
IResponseInterceptor as ResponseInterceptor,
|
|
279
303
|
IRequestOptions as RequestOptions,
|
|
280
304
|
IRequest as Request,
|
|
281
305
|
};
|
|
282
306
|
|
|
283
307
|
`;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
308
|
+
api.onGenerateFiles(() => {
|
|
309
|
+
var _a;
|
|
310
|
+
const umiRequestPath = (0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("@ahooksjs/use-request/package.json")));
|
|
311
|
+
const axiosPath = (0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("axios/package.json")));
|
|
312
|
+
let dataField = (_a = api.config.request) == null ? void 0 : _a.dataField;
|
|
313
|
+
if (dataField === void 0)
|
|
314
|
+
dataField = "data";
|
|
315
|
+
const formatResult = dataField === "" ? `result => result` : `result => result?.${dataField}`;
|
|
316
|
+
api.writeTmpFile({
|
|
317
|
+
path: "request.ts",
|
|
318
|
+
content: import_plugin_utils.Mustache.render(requestTpl, {
|
|
319
|
+
umiRequestPath,
|
|
320
|
+
axiosPath,
|
|
321
|
+
formatResult
|
|
322
|
+
})
|
|
323
|
+
});
|
|
324
|
+
api.writeTmpFile({
|
|
325
|
+
path: "types.d.ts",
|
|
326
|
+
content: `
|
|
303
327
|
export type {
|
|
304
328
|
RequestConfig,
|
|
305
329
|
AxiosInstance,
|
|
@@ -308,17 +332,19 @@ export type {
|
|
|
308
332
|
AxiosError,
|
|
309
333
|
RequestError,
|
|
310
334
|
ResponseInterceptor } from './request';
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
335
|
+
`
|
|
336
|
+
});
|
|
337
|
+
api.writeTmpFile({
|
|
338
|
+
path: "index.ts",
|
|
339
|
+
content: `
|
|
316
340
|
export {
|
|
317
341
|
useRequest,
|
|
318
342
|
UseRequestProvider,
|
|
319
343
|
request,
|
|
320
344
|
} from './request';
|
|
321
|
-
|
|
322
|
-
});
|
|
345
|
+
`
|
|
323
346
|
});
|
|
347
|
+
});
|
|
324
348
|
};
|
|
349
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
350
|
+
0 && (module.exports = {});
|