@lx-frontend/multi-ajax 0.2.4-beta → 0.2.5
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/build/scripts/axios/dist/axios.js +2966 -0
- package/build/scripts/axios/dist/browser/axios.cjs +3193 -0
- package/build/scripts/axios/dist/esm/axios.js +3215 -0
- package/build/scripts/axios/dist/esm/axios.min.js +1160 -0
- package/build/scripts/patch-axios-post-install.js +8 -34
- package/build/utils.js +23 -2
- package/lib/adapters/wx-adapter.d.ts +6 -0
- package/lib/adapters/wx-adapter.js +2 -2
- package/lib/index.js +2 -2
- package/lib/types.d.ts +45 -0
- package/package.json +1 -1
- /package/build/scripts/{patch-content.txt → axios/lib/platform/browser/index.js} +0 -0
|
@@ -1,40 +1,14 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
1
|
const path = require('path')
|
|
3
|
-
const { resolveAxiosPath } = require('../utils')
|
|
4
|
-
|
|
5
|
-
function patchBrowserIndex(axiosPath) {
|
|
6
|
-
const patchPath = path.resolve(axiosPath, 'lib/platform/browser/index.js')
|
|
7
|
-
|
|
8
|
-
// TODO: 验证axios版本
|
|
9
|
-
// TODO:确定在pnpm下,如果存在多个axios版本会怎样?
|
|
10
|
-
|
|
11
|
-
const contentPath = path.resolve(__dirname, './patch-content.txt')
|
|
12
|
-
const patchContent = fs.readFileSync(contentPath)
|
|
13
|
-
|
|
14
|
-
console.log('patched axios file:', patchPath)
|
|
15
|
-
fs.writeFileSync(patchPath, patchContent)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function patchAxiosPackageJson(axiosPath) {
|
|
19
|
-
const packagePath = path.resolve(axiosPath, 'package.json')
|
|
20
|
-
|
|
21
|
-
const contentObj = require(packagePath)
|
|
22
|
-
|
|
23
|
-
const exportDot = contentObj.exports['.']
|
|
24
|
-
|
|
25
|
-
exportDot.browser.require = './index.js'
|
|
26
|
-
exportDot.default.require = './index.js'
|
|
27
|
-
|
|
28
|
-
fs.writeFileSync(packagePath, JSON.stringify(contentObj), {encoding: 'utf8'})
|
|
29
|
-
}
|
|
2
|
+
const { resolveAxiosPath, copyFiles } = require('../utils')
|
|
30
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 从 packages/multi-ajax/build/scripts/axios 复制文件覆盖 node_modules/axios 中文件
|
|
6
|
+
*/
|
|
31
7
|
function patchAxios() {
|
|
8
|
+
const patchSourceAxiosPath = path.resolve(__dirname, './axios')
|
|
9
|
+
const targetAxiosPath = resolveAxiosPath()
|
|
32
10
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
patchBrowserIndex(axiosPath)
|
|
36
|
-
|
|
37
|
-
patchAxiosPackageJson(axiosPath)
|
|
11
|
+
copyFiles(patchSourceAxiosPath, targetAxiosPath);
|
|
38
12
|
}
|
|
39
13
|
|
|
40
|
-
patchAxios()
|
|
14
|
+
patchAxios()
|
package/build/utils.js
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const resolve = require('resolve/sync');
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
|
|
5
6
|
function resolveAxiosPath() {
|
|
6
7
|
var res = resolve('axios', { basedir: __dirname, preserveSymlinks: false });
|
|
7
8
|
return path.dirname(res)
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
function copyFiles(sourceDir, targetDir) {
|
|
12
|
+
if (!fs.existsSync(targetDir)) {
|
|
13
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const files = fs.readdirSync(sourceDir);
|
|
17
|
+
files.forEach(file => {
|
|
18
|
+
const sourceFilePath = path.join(sourceDir, file);
|
|
19
|
+
const targetFilePath = path.join(targetDir, file);
|
|
20
|
+
|
|
21
|
+
if (fs.statSync(sourceFilePath).isDirectory()) {
|
|
22
|
+
copyFiles(sourceFilePath, targetFilePath); // 递归处理子目录
|
|
23
|
+
} else {
|
|
24
|
+
fs.copyFileSync(sourceFilePath, targetFilePath); // 复制文件
|
|
25
|
+
console.info(`覆盖: ${targetFilePath},来源:${sourceFilePath}`)
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
10
30
|
module.exports = {
|
|
11
|
-
resolveAxiosPath
|
|
12
|
-
|
|
31
|
+
resolveAxiosPath,
|
|
32
|
+
copyFiles
|
|
33
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
var axios_1 = require("axios
|
|
4
|
+
var axios_1 = require("axios");
|
|
5
5
|
var utils_1 = require("../utils");
|
|
6
6
|
var canceller_1 = require("../canceller");
|
|
7
7
|
var cancelLastSameRequest_1 = require("../cancelLastSameRequest");
|
|
@@ -79,4 +79,4 @@ function wxAdapter(config) {
|
|
|
79
79
|
}
|
|
80
80
|
exports.default = wxAdapter;
|
|
81
81
|
wxAdapter.type = 'wx';
|
|
82
|
-
//# sourceMappingURL=wx-adapter.js.map
|
|
82
|
+
//# sourceMappingURL=wx-adapter.js.map
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
var axios_1 = tslib_1.__importDefault(require("axios
|
|
4
|
+
var axios_1 = tslib_1.__importDefault(require("axios"));
|
|
5
5
|
var index_1 = require("./adapters/index");
|
|
6
6
|
var compatibleMethods_1 = tslib_1.__importDefault(require("./compatibleMethods"));
|
|
7
7
|
var helpers_1 = require("./helpers");
|
|
@@ -31,4 +31,4 @@ function initAjax(options) {
|
|
|
31
31
|
return ajax;
|
|
32
32
|
}
|
|
33
33
|
exports.default = initAjax;
|
|
34
|
-
//# sourceMappingURL=index.js.map
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { CustomAjaxMethods } from './compatibleMethods';
|
|
3
|
+
import type { RequestCreator } from './methods';
|
|
4
|
+
export type AnyObj = Record<string, any>;
|
|
5
|
+
export interface AjaxOption extends AxiosRequestConfig {
|
|
6
|
+
/** 是否发送FormData数据,仅用于post类请求,为true则使用qs.stringify序列化数据 */
|
|
7
|
+
sendFormData?: boolean;
|
|
8
|
+
/** 当前请求的取消函数名称,使用ajax.canceller[cancelKey]()的方式调用 */
|
|
9
|
+
cancelKey?: string;
|
|
10
|
+
/** 如果有值,则请求直接resolve这个值,阻断请求发送。用于开发mock数据 */
|
|
11
|
+
mock?: any;
|
|
12
|
+
/** 如果请求的URL和method与一个pending状态的请求相同,是否要终止前面的请求 */
|
|
13
|
+
cancelLastSameUrl?: boolean;
|
|
14
|
+
/** 防重设置,在此时间内触发的相同请求会复用上一个处于pending状态的请求,单位为ms。请求返回后,该参数自动失效。 */
|
|
15
|
+
reUseDuration?: number;
|
|
16
|
+
}
|
|
17
|
+
export type RequestMethods = 'get' | 'post' | 'patch' | 'put' | 'delete' | 'head';
|
|
18
|
+
export type ProxyedAttrs = keyof Omit<AxiosInstance, RequestMethods>;
|
|
19
|
+
export type CancellerType = {
|
|
20
|
+
[K: string]: () => void | undefined;
|
|
21
|
+
};
|
|
22
|
+
export interface AjaxInstance<CusOpt extends NonNullable<unknown> = any, DataShape extends object = any> extends Pick<AxiosInstance, ProxyedAttrs> {
|
|
23
|
+
/** @deprecated 即将废弃,请使用ajax.get方法替换 */
|
|
24
|
+
query: CustomAjaxMethods<CusOpt, DataShape>;
|
|
25
|
+
/** @deprecated 即将废弃,请使用ajax.post方法替换 */
|
|
26
|
+
create: CustomAjaxMethods<CusOpt, DataShape>;
|
|
27
|
+
/** @deprecated 即将废弃,请使用ajax.delete方法替换 */
|
|
28
|
+
deletes: CustomAjaxMethods<CusOpt, DataShape>;
|
|
29
|
+
/** @deprecated 即将废弃,请使用ajax.put方法替换 */
|
|
30
|
+
putWay: CustomAjaxMethods<CusOpt, DataShape>;
|
|
31
|
+
/** @deprecated 即将废弃,请使用ajax.patch方法替换 */
|
|
32
|
+
patchWay: CustomAjaxMethods<CusOpt, DataShape>;
|
|
33
|
+
head: RequestCreator<CusOpt, DataShape>;
|
|
34
|
+
get: RequestCreator<CusOpt, DataShape>;
|
|
35
|
+
post: RequestCreator<CusOpt, DataShape>;
|
|
36
|
+
put: RequestCreator<CusOpt, DataShape>;
|
|
37
|
+
delete: RequestCreator<CusOpt, DataShape>;
|
|
38
|
+
patch: RequestCreator<CusOpt, DataShape>;
|
|
39
|
+
extend: (obj: object) => void;
|
|
40
|
+
canceller: CancellerType;
|
|
41
|
+
$baseUrl: string;
|
|
42
|
+
$options: AjaxOption;
|
|
43
|
+
$engine: AxiosInstance;
|
|
44
|
+
}
|
|
45
|
+
export type AxiosMethods = 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' | 'HEAD';
|
package/package.json
CHANGED
|
File without changes
|