@umijs/plugins 4.0.5 → 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.
@@ -1,119 +1,140 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const assert_1 = __importDefault(require("assert"));
7
- const fs_1 = require("fs");
8
- const path_1 = require("path");
9
- const plugin_utils_1 = require("umi/plugin-utils");
10
- const withTmpPath_1 = require("../utils/withTmpPath");
11
- const constants_1 = require("./constants");
12
- // BREAK CHANGE: 需要手动配置 slave: {},不能留空
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
- var _a, _b;
15
- const slaveCfg = (_b = (_a = opts.userConfig) === null || _a === void 0 ? void 0 : _a.qiankun) === null || _b === void 0 ? void 0 : _b.slave;
16
- if (slaveCfg) {
17
- return slaveCfg.enable !== false;
18
- }
19
- return !!process.env.INITIAL_QIANKUN_SLAVE_OPTIONS;
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
- exports.default = (api) => {
22
- api.describe({
23
- key: 'qiankun-slave',
24
- enableBy: isSlaveEnable,
25
- });
26
- api.addRuntimePlugin(() => {
27
- return [(0, withTmpPath_1.withTmpPath)({ api, path: 'slaveRuntimePlugin.ts' })];
28
- });
29
- api.register({
30
- key: 'addExtraModels',
31
- fn() {
32
- return [
33
- (0, withTmpPath_1.withTmpPath)({
34
- api,
35
- path: `qiankunModel.ts#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
36
- }),
37
- ];
38
- },
39
- });
40
- api.modifyDefaultConfig((memo) => {
41
- var _a, _b, _c, _d;
42
- const initialSlaveOptions = {
43
- devSourceMap: true,
44
- ...JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}'),
45
- ...(memo.qiankun || {}).slave,
46
- };
47
- const modifiedDefaultConfig = {
48
- ...memo,
49
- // 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
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.addEntryImports(() => {
108
- return [
109
- {
110
- source: '@@/plugin-qiankun-slave/lifecycles',
111
- specifier: '{ genMount as qiankun_genMount, genBootstrap as qiankun_genBootstrap, genUnmount as qiankun_genUnmount, genUpdate as qiankun_genUpdate }',
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
- api.addEntryCode(() => [
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
- function getFileContent(file) {
127
- return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
128
- }
129
- api.onGenerateFiles({
130
- fn() {
131
- // api.writeTmpFile({
132
- // path: 'slaveOptions.ts',
133
- // content: `
134
- // let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
135
- // export const getSlaveOptions = () => options;
136
- // export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
137
- // `,
138
- // });
139
- [
140
- 'qiankunModel.ts',
141
- 'connectMaster.tsx',
142
- 'slaveRuntimePlugin.ts',
143
- 'lifecycles.ts',
144
- ].forEach((file) => {
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
- before: 'model',
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (api) => {
4
- api.describe({
5
- config: {
6
- schema(joi) {
7
- return joi.object().keys({
8
- slave: joi.object(),
9
- master: joi.object(),
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,28 +1,51 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- const plugin_utils_1 = require("umi/plugin-utils");
5
- exports.default = (api) => {
6
- api.describe({
7
- key: 'request',
8
- config: {
9
- schema: (joi) => {
10
- return joi.object({
11
- dataField: joi
12
- .string()
13
- .pattern(/^[a-zA-Z]*$/)
14
- .allow(''),
15
- });
16
- },
17
- },
18
- enableBy: api.EnableBy.config,
19
- });
20
- api.addRuntimePluginKey(() => ['request']);
21
- const requestTpl = `
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,
25
47
  type AxiosResponse,
48
+ type AxiosError,
26
49
  } from '{{{axiosPath}}}';
27
50
  import useUmiRequest, { UseRequestProvider } from '{{{umiRequestPath}}}';
28
51
  import { ApplyPluginsType } from 'umi';
@@ -100,7 +123,7 @@ function useRequest(service: any, options: any = {}) {
100
123
  });
101
124
  }
102
125
 
103
- // request 方法 opts 参数的接口
126
+ // request \u65B9\u6CD5 opts \u53C2\u6570\u7684\u63A5\u53E3
104
127
  interface IRequestOptions extends AxiosRequestConfig {
105
128
  skipErrorHandler?: boolean;
106
129
  requestInterceptors?: IRequestInterceptorTuple[];
@@ -119,10 +142,12 @@ interface IRequestOptionsWithoutResponse extends IRequestOptions{
119
142
  interface IRequest{
120
143
  <T = any>(url: string, opts: IRequestOptionsWithResponse): Promise<AxiosResponse<T>>;
121
144
  <T = any>(url: string, opts: IRequestOptionsWithoutResponse): Promise<T>;
122
- <T = any>(url: string, opts: IRequestOptions): Promise<T>; // getResponse 默认是 false 因此不提供该参数时,只返回 data
123
- <T = any>(url: string): Promise<T>; // 不提供 opts 时,默认使用 'GET' method,并且默认返回 data
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
124
147
  }
125
148
 
149
+ type RequestError = AxiosError | Error
150
+
126
151
  interface IErrorHandler {
127
152
  (error: RequestError, opts: IRequestOptions): void;
128
153
  }
@@ -134,10 +159,10 @@ type IResponseInterceptor = <T = any>(response : AxiosResponse<T>) => AxiosRespo
134
159
  type IRequestInterceptorTuple = [IRequestInterceptor , IErrorInterceptor] | [ IRequestInterceptor ] | IRequestInterceptor
135
160
  type IResponseInterceptorTuple = [IResponseInterceptor, IErrorInterceptor] | [IResponseInterceptor] | IResponseInterceptor
136
161
 
137
- export interface RequestConfig extends AxiosRequestConfig {
162
+ export interface RequestConfig<T = any> extends AxiosRequestConfig {
138
163
  errorConfig?: {
139
164
  errorHandler?: IErrorHandler;
140
- errorThrower?: <T = any>( res: T ) => void
165
+ errorThrower?: ( res: T ) => void
141
166
  };
142
167
  requestInterceptors?: IRequestInterceptorTuple[];
143
168
  responseInterceptors?: IResponseInterceptorTuple[];
@@ -188,7 +213,7 @@ const getRequestInstance = (): AxiosInstance => {
188
213
  requestInstance.interceptors.response.use(interceptor);
189
214
  });
190
215
 
191
- // 当响应的数据 success false 的时候,抛出 error 以供 errorHandler 处理。
216
+ // \u5F53\u54CD\u5E94\u7684\u6570\u636E success \u662F false \u7684\u65F6\u5019\uFF0C\u629B\u51FA error \u4EE5\u4F9B errorHandler \u5904\u7406\u3002
192
217
  requestInstance.interceptors.response.use((response) => {
193
218
  const { data } = response;
194
219
  if(data?.success === false && config?.errorConfig?.errorThrower){
@@ -272,48 +297,54 @@ export type {
272
297
  AxiosInstance,
273
298
  AxiosRequestConfig,
274
299
  AxiosResponse,
300
+ AxiosError,
301
+ RequestError,
275
302
  IResponseInterceptor as ResponseInterceptor,
276
303
  IRequestOptions as RequestOptions,
277
304
  IRequest as Request,
278
305
  };
279
306
 
280
307
  `;
281
- api.onGenerateFiles(() => {
282
- var _a;
283
- const umiRequestPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('@ahooksjs/use-request/package.json')));
284
- const axiosPath = (0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('axios/package.json')));
285
- let dataField = (_a = api.config.request) === null || _a === void 0 ? void 0 : _a.dataField;
286
- if (dataField === undefined)
287
- dataField = 'data';
288
- const formatResult = dataField === '' ? `result => result` : `result => result?.${dataField}`;
289
- api.writeTmpFile({
290
- path: 'request.ts',
291
- content: plugin_utils_1.Mustache.render(requestTpl, {
292
- umiRequestPath,
293
- axiosPath,
294
- formatResult,
295
- }),
296
- });
297
- api.writeTmpFile({
298
- path: 'types.d.ts',
299
- content: `
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: `
300
327
  export type {
301
328
  RequestConfig,
302
329
  AxiosInstance,
303
330
  AxiosRequestConfig,
304
331
  AxiosResponse,
332
+ AxiosError,
333
+ RequestError,
305
334
  ResponseInterceptor } from './request';
306
- `,
307
- });
308
- api.writeTmpFile({
309
- path: 'index.ts',
310
- content: `
335
+ `
336
+ });
337
+ api.writeTmpFile({
338
+ path: "index.ts",
339
+ content: `
311
340
  export {
312
341
  useRequest,
313
342
  UseRequestProvider,
314
343
  request,
315
344
  } from './request';
316
- `,
317
- });
345
+ `
318
346
  });
347
+ });
319
348
  };
349
+ // Annotate the CommonJS export names for ESM import in node:
350
+ 0 && (module.exports = {});