修改持续集成脚本
parent
2b2be5ba17
commit
7fb43d4842
|
@ -1,2 +0,0 @@
|
||||||
# Default ignored files
|
|
||||||
/workspace.xml
|
|
|
@ -1,9 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="JavaScriptSettings">
|
|
||||||
<option name="languageLevel" value="ES6" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,8 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/axios-miniprogram.iml" filepath="$PROJECT_DIR$/.idea/axios-miniprogram.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -6,4 +6,6 @@ cache:
|
||||||
install:
|
install:
|
||||||
- npm install
|
- npm install
|
||||||
script:
|
script:
|
||||||
|
- npm run prettier
|
||||||
|
- npm run lint
|
||||||
- npm run coverage
|
- npm run coverage
|
|
@ -459,9 +459,9 @@ const uri = axios.getUri({
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### `axios.create(config)`
|
### `axios.create(defaults)`
|
||||||
|
|
||||||
创建一个`自定义实例`,传入的自定义配置`config`会和`axios`的默认配置`axios.defaults`合并成`自定义实例`的默认配置。
|
创建一个`自定义实例`,传入的自定义默认配置`defaults`会和`axios`的默认配置`axios.defaults`合并成`自定义实例`的默认配置。
|
||||||
|
|
||||||
`自定义实例`拥有和`axios`相同的调用方式和请求方法的别名。
|
`自定义实例`拥有和`axios`相同的调用方式和请求方法的别名。
|
||||||
|
|
||||||
|
@ -484,9 +484,9 @@ instance.get('/test');
|
||||||
|
|
||||||
### `axios.Axios`
|
### `axios.Axios`
|
||||||
|
|
||||||
`axios.Axios`是一个类,其实`axios`就是`axios.Axios`类的实例改造而来的,`axios.create(config)`创建的也是`axios.Axios`的实例。
|
`axios.Axios`是一个类,其实`axios`就是`axios.Axios`类的实例改造而来的,`axios.create(defaults)`创建的也是`axios.Axios`的实例。
|
||||||
|
|
||||||
直接实例化`axios.Axios`可以得到一个`纯净的实例`,不能当函数调用,传入的自定义配置就是`纯净的实例`的默认配置,而不会像`axios.create(config)`一样去合并`axios`中的默认配置。
|
直接实例化`axios.Axios`可以得到一个`纯净的实例`,不能当函数调用,传入的自定义配置就是`纯净的实例`的默认配置,而不会像`axios.create(defaults)`一样去合并`axios`中的默认配置。
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
axios.defaults.baseURL = 'https://www.xxx.com';
|
axios.defaults.baseURL = 'https://www.xxx.com';
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
"pre-commit": "yarn lint && yarn prettier && yarn test:cov && git add ."
|
"pre-commit": "yarn prettier && yarn lint && yarn test:cov && git add ."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||||
import babel from 'rollup-plugin-babel';
|
import babel from 'rollup-plugin-babel';
|
||||||
import typescript from 'rollup-plugin-typescript2';
|
import typescript2 from 'rollup-plugin-typescript2';
|
||||||
|
|
||||||
function removeDir(name) {
|
function removeDir(name) {
|
||||||
try {
|
try {
|
||||||
|
@ -34,7 +34,7 @@ export default function() {
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
nodeResolve({ extensions: ['.ts'] }),
|
nodeResolve({ extensions: ['.ts'] }),
|
||||||
typescript({ useTsconfigDeclarationDir: true }),
|
typescript2({ useTsconfigDeclarationDir: true }),
|
||||||
babel({ extensions: ['.ts'] }),
|
babel({ extensions: ['.ts'] }),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: early-autumn
|
* @Author: early-autumn
|
||||||
* @Date: 2020-04-13 20:00:08
|
* @Date: 2020-04-13 20:00:08
|
||||||
* @LastEditors: early-autumn
|
* @LastEditors: early-autumn
|
||||||
* @LastEditTime: 2020-05-02 17:43:27
|
* @LastEditTime: 2020-05-05 08:52:21
|
||||||
*/
|
*/
|
||||||
import { CancelToken, CancelAction, CancelExecutor, CancelTokenSource } from '../types';
|
import { CancelToken, CancelAction, CancelExecutor, CancelTokenSource } from '../types';
|
||||||
import Cancel from './Cancel';
|
import Cancel from './Cancel';
|
||||||
|
@ -51,7 +51,7 @@ export default class CancelTokenClass implements CancelToken {
|
||||||
*
|
*
|
||||||
* 取消请求 CancelTokenSource.token
|
* 取消请求 CancelTokenSource.token
|
||||||
*/
|
*/
|
||||||
static source(): CancelTokenSource {
|
public static source(): CancelTokenSource {
|
||||||
let cancel!: CancelAction;
|
let cancel!: CancelAction;
|
||||||
|
|
||||||
const token = new CancelTokenClass(function executor(action) {
|
const token = new CancelTokenClass(function executor(action) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: early-autumn
|
* @Author: early-autumn
|
||||||
* @Date: 2020-04-13 18:00:27
|
* @Date: 2020-04-13 18:00:27
|
||||||
* @LastEditors: early-autumn
|
* @LastEditors: early-autumn
|
||||||
* @LastEditTime: 2020-04-25 09:23:14
|
* @LastEditTime: 2020-05-05 08:58:47
|
||||||
*/
|
*/
|
||||||
import { Method, Params, Data, Interceptors, AxiosRequestConfig, AxiosResponse, Axios } from '../types';
|
import { Method, Params, Data, Interceptors, AxiosRequestConfig, AxiosResponse, Axios } from '../types';
|
||||||
import buildURL from '../helpers/buildURL';
|
import buildURL from '../helpers/buildURL';
|
||||||
|
@ -11,9 +11,6 @@ import InterceptorManager from './InterceptorManager';
|
||||||
import dispatchRequest from './dispatchRequest';
|
import dispatchRequest from './dispatchRequest';
|
||||||
|
|
||||||
export default class AxiosClass implements Axios {
|
export default class AxiosClass implements Axios {
|
||||||
/**
|
|
||||||
* Axios 拦截器
|
|
||||||
*/
|
|
||||||
public interceptors: Interceptors = {
|
public interceptors: Interceptors = {
|
||||||
request: new InterceptorManager<AxiosRequestConfig>(),
|
request: new InterceptorManager<AxiosRequestConfig>(),
|
||||||
response: new InterceptorManager<AxiosResponse>(),
|
response: new InterceptorManager<AxiosResponse>(),
|
||||||
|
@ -24,22 +21,12 @@ export default class AxiosClass implements Axios {
|
||||||
*/
|
*/
|
||||||
public constructor(public defaults: AxiosRequestConfig = {}) {}
|
public constructor(public defaults: AxiosRequestConfig = {}) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据配置中的 url 和 params 生成一个 URI
|
|
||||||
*
|
|
||||||
* @param config Axios 请求配置
|
|
||||||
*/
|
|
||||||
public getUri(config: AxiosRequestConfig): string {
|
public getUri(config: AxiosRequestConfig): string {
|
||||||
const { url = '', params, paramsSerializer } = mergeConfig(this.defaults, config);
|
const { url = '', params, paramsSerializer } = mergeConfig(this.defaults, config);
|
||||||
|
|
||||||
return buildURL(url, params, paramsSerializer).replace(/^\?/, '');
|
return buildURL(url, params, paramsSerializer).replace(/^\?/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 HTTP 请求
|
|
||||||
*
|
|
||||||
* @param config Axios 请求配置
|
|
||||||
*/
|
|
||||||
public request<T extends Data>(config: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public request<T extends Data>(config: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
const requestConfig = mergeConfig(this.defaults, config);
|
const requestConfig = mergeConfig(this.defaults, config);
|
||||||
|
|
||||||
|
@ -51,97 +38,44 @@ export default class AxiosClass implements Axios {
|
||||||
}, 'reverse');
|
}, 'reverse');
|
||||||
|
|
||||||
// 发送请求
|
// 发送请求
|
||||||
let promiseResponse = promiseRequest.then(dispatchRequest) as Promise<AxiosResponse<T>>;
|
let promiseResponse = promiseRequest.then(dispatchRequest);
|
||||||
|
|
||||||
// 执行响应拦截器
|
// 执行响应拦截器
|
||||||
this.interceptors.response.forEach(function executor({ resolved, rejected }) {
|
this.interceptors.response.forEach(function executor({ resolved, rejected }) {
|
||||||
promiseResponse = promiseResponse.then(resolved, rejected);
|
promiseResponse = promiseResponse.then(resolved, rejected);
|
||||||
});
|
});
|
||||||
|
|
||||||
return promiseResponse;
|
return promiseResponse as Promise<AxiosResponse<T>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 HTTP OPTIONS 请求
|
|
||||||
*
|
|
||||||
* @param url 请求地址
|
|
||||||
* @param config 额外配置
|
|
||||||
*/
|
|
||||||
public options<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public options<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutParams<T>('options', url, undefined, config);
|
return this._requestMethodWithoutParams<T>('options', url, undefined, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 HTTP GET 请求
|
|
||||||
*
|
|
||||||
* @param url 请求地址
|
|
||||||
* @param params 请求参数
|
|
||||||
* @param config 额外配置
|
|
||||||
*/
|
|
||||||
public get<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public get<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutParams<T>('get', url, params, config);
|
return this._requestMethodWithoutParams<T>('get', url, params, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 HTTP HEAD 请求
|
|
||||||
*
|
|
||||||
* @param url 请求地址
|
|
||||||
* @param params 请求参数
|
|
||||||
* @param config 额外配置
|
|
||||||
*/
|
|
||||||
public head<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public head<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutParams<T>('head', url, params, config);
|
return this._requestMethodWithoutParams<T>('head', url, params, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 HTTP POST 请求
|
|
||||||
*
|
|
||||||
* @param url 请求地址
|
|
||||||
* @param data 请求数据
|
|
||||||
* @param config 额外配置
|
|
||||||
*/
|
|
||||||
public post<T extends Data>(url: string, data?: Data, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public post<T extends Data>(url: string, data?: Data, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutData<T>('post', url, data, config);
|
return this._requestMethodWithoutData<T>('post', url, data, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 HTTP PUT 请求
|
|
||||||
*
|
|
||||||
* @param url 请求地址
|
|
||||||
* @param data 请求数据
|
|
||||||
* @param config 额外配置
|
|
||||||
*/
|
|
||||||
public put<T extends Data>(url: string, data?: Data, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public put<T extends Data>(url: string, data?: Data, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutData<T>('put', url, data, config);
|
return this._requestMethodWithoutData<T>('put', url, data, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 HTTP DELETE 请求
|
|
||||||
*
|
|
||||||
* @param url 请求地址
|
|
||||||
* @param params 请求参数
|
|
||||||
* @param config 额外配置
|
|
||||||
*/
|
|
||||||
public delete<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public delete<T extends Data>(url: string, params?: Params, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutParams<T>('delete', url, params, config);
|
return this._requestMethodWithoutParams<T>('delete', url, params, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 HTTP TRACE 请求
|
|
||||||
*
|
|
||||||
* @param url 请求地址
|
|
||||||
* @param config 额外配置
|
|
||||||
*/
|
|
||||||
public trace<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public trace<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutParams<T>('trace', url, undefined, config);
|
return this._requestMethodWithoutParams<T>('trace', url, undefined, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 HTTP CONNECT 请求
|
|
||||||
*
|
|
||||||
* @param url 请求地址
|
|
||||||
* @param config 额外配置
|
|
||||||
*/
|
|
||||||
public connect<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
public connect<T extends Data>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {
|
||||||
return this._requestMethodWithoutParams<T>('connect', url, undefined, config);
|
return this._requestMethodWithoutParams<T>('connect', url, undefined, config);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: early-autumn
|
* @Author: early-autumn
|
||||||
* @Date: 2020-04-15 17:50:50
|
* @Date: 2020-04-15 17:50:50
|
||||||
* @LastEditors: early-autumn
|
* @LastEditors: early-autumn
|
||||||
* @LastEditTime: 2020-05-02 14:30:56
|
* @LastEditTime: 2020-05-05 09:01:50
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
InterceptorResolved,
|
InterceptorResolved,
|
||||||
|
@ -26,12 +26,6 @@ export default class InterceptorManagerClass<T> implements InterceptorManager<T>
|
||||||
*/
|
*/
|
||||||
private _interceptors: Record<number, Interceptor<T>> = {};
|
private _interceptors: Record<number, Interceptor<T>> = {};
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加拦截器
|
|
||||||
*
|
|
||||||
* @param resolved 成功的回调函数
|
|
||||||
* @param rejected 失败的回调函数
|
|
||||||
*/
|
|
||||||
public use(resolved: InterceptorResolved<T>, rejected?: InterceptorRejected) {
|
public use(resolved: InterceptorResolved<T>, rejected?: InterceptorRejected) {
|
||||||
this._interceptors[++this._id] = {
|
this._interceptors[++this._id] = {
|
||||||
resolved,
|
resolved,
|
||||||
|
@ -41,21 +35,10 @@ export default class InterceptorManagerClass<T> implements InterceptorManager<T>
|
||||||
return this._id;
|
return this._id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除拦截器
|
|
||||||
*
|
|
||||||
* @param id 拦截器 id
|
|
||||||
*/
|
|
||||||
public eject(id: number): void {
|
public eject(id: number): void {
|
||||||
delete this._interceptors[id];
|
delete this._interceptors[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 遍历所有拦截器
|
|
||||||
*
|
|
||||||
* @param executor 拦截器执行器
|
|
||||||
* @param reverse 是否倒序遍历
|
|
||||||
*/
|
|
||||||
public forEach(executor: InterceptorExecutor<T>, reverse?: 'reverse'): void {
|
public forEach(executor: InterceptorExecutor<T>, reverse?: 'reverse'): void {
|
||||||
let interceptors: Interceptor<T>[] = Object.values(this._interceptors);
|
let interceptors: Interceptor<T>[] = Object.values(this._interceptors);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: early-autumn
|
* @Author: early-autumn
|
||||||
* @Date: 2020-04-14 23:22:52
|
* @Date: 2020-04-14 23:22:52
|
||||||
* @LastEditors: early-autumn
|
* @LastEditors: early-autumn
|
||||||
* @LastEditTime: 2020-04-28 13:06:14
|
* @LastEditTime: 2020-05-02 22:44:34
|
||||||
*/
|
*/
|
||||||
import axios from './axios';
|
import axios from './axios';
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: early-autumn
|
* @Author: early-autumn
|
||||||
* @Date: 2020-04-13 15:23:53
|
* @Date: 2020-04-13 15:23:53
|
||||||
* @LastEditors: early-autumn
|
* @LastEditors: early-autumn
|
||||||
* @LastEditTime: 2020-05-02 14:37:02
|
* @LastEditTime: 2020-05-05 09:02:12
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,7 +181,7 @@ export declare interface AdapterRequestTask {
|
||||||
* 适配器
|
* 适配器
|
||||||
*/
|
*/
|
||||||
export declare interface Adapter {
|
export declare interface Adapter {
|
||||||
(config: AdapterRequestConfig): AdapterRequestTask | undefined;
|
(config: AdapterRequestConfig): AdapterRequestTask | void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -390,6 +390,7 @@ export declare interface InterceptorExecutor<T = any> {
|
||||||
* 拦截器管理器
|
* 拦截器管理器
|
||||||
*/
|
*/
|
||||||
export declare interface InterceptorManager<T = any> {
|
export declare interface InterceptorManager<T = any> {
|
||||||
|
[x: string]: any;
|
||||||
/**
|
/**
|
||||||
* 添加拦截器
|
* 添加拦截器
|
||||||
*
|
*
|
||||||
|
@ -682,7 +683,7 @@ export declare interface AxiosInstance extends AxiosBaseInstance {
|
||||||
/**
|
/**
|
||||||
* 创建 Axios 实例基础拓展
|
* 创建 Axios 实例基础拓展
|
||||||
*
|
*
|
||||||
* @param config 自定义默认配置
|
* @param defaults 自定义默认配置
|
||||||
*/
|
*/
|
||||||
create(defaults?: AxiosRequestConfig): AxiosBaseInstance;
|
create(defaults?: AxiosRequestConfig): AxiosBaseInstance;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue