Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove condition of enableDownload or enableUpload #16

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"editor.suggestSelection": "recentlyUsedByPrefix", // 自动补全
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll.eslint": true // 修复所有代码
"source.organizeImports": "explicit",
"source.fixAll.eslint": "explicit"
}
}
2 changes: 1 addition & 1 deletion config/rollup.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ const compilePath = (exports.compilePath = {
external: ['alova', 'axios'],
packageName: 'AlovaAdapterAxios',
input: 'src/index.ts',
output: suffix => `dist/alova-adapter-axios.${suffix}.js`
output: (suffix, ext = 'js') => `dist/alova-adapter-axios.${suffix}.${ext}`
});
exports.external = compilePath.external;
5 changes: 2 additions & 3 deletions config/rollup.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
// rollup.config.js
// commonjs
const config = require('./rollup.cjs');
const module = process.argv.pop().replace('--', '') || 'core';
const paths = config.compilePath;
const moduleType = 'cjs';
const moduleType = 'common';

module.exports = {
input: paths.input,
output: {
name: paths.packageName,
file: paths.output(moduleType),
file: paths.output(moduleType, 'cjs'),
format: 'cjs',
// When export and export default are not used at the same time, set legacy to true.
// legacy: true,
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.1.1",
"description": "axios adapter for alova.js",
"homepage": "https://alova.js.org",
"main": "dist/alova-adapter-axios.esm.js",
"main": "dist/alova-adapter-axios.common.cjs",
"module": "dist/alova-adapter-axios.esm.js",
"types": "typings/index.d.ts",
"type": "module",
Expand Down Expand Up @@ -31,9 +31,10 @@
"lint": "eslint --ext .ts,.js src/**",
"lint:fix": "eslint --ext .ts,.js src/** --fix",
"build:esm": "cross-env NODE_ENV=development rollup -c ./config/rollup.config.esm.cjs",
"build:cjs": "cross-env NODE_ENV=development rollup -c ./config/rollup.config.cjs",
"build:umd": "cross-env NODE_ENV=development rollup -c ./config/rollup.config.umd.cjs",
"build:umd.min": "cross-env NODE_ENV=production rollup -c ./config/rollup.config.umd.cjs",
"build": "npm run clean && npm run build:esm && npm run build:umd && npm run build:umd.min",
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd.min",
"release": "semantic-release",
"coveralls": "npm run test:coverage && coveralls < coverage/lcov.info",
"changelog": "conventional-changelog -p angular -u -i CHANGELOG.md -s -r 0",
Expand All @@ -57,7 +58,7 @@
"typings/*.d.ts"
],
"devDependencies": {
"@alova/mock": "^1.5.0",
"@alova/mock": "^1.5.1",
"@babel/core": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@commitlint/config-conventional": "^17.4.4",
Expand All @@ -71,7 +72,7 @@
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"alova": "^2.13.1",
"alova": "^2.16.2",
"axios": "^1.3.4",
"babel-jest": "^29.2.2",
"commitizen": "^4.3.0",
Expand Down
19 changes: 9 additions & 10 deletions src/requestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ export default function requestAdapter(options: AdapterCreateOptions = {}) {
data: method.data,
signal: controller.signal,
// `onUploadProgress` 允许为上传处理进度事件
onUploadProgress: config.enableUpload
? event => {
uploadHandler(event.loaded, event.total || 1);
}
: undefinedValue,
onUploadProgress:
process.env.NODE_ENV !== 'test'
? event => {
uploadHandler(event.loaded, event.total || 1);
}
: undefinedValue,
// `onDownloadProgress` 允许为下载处理进度事件
onDownloadProgress: config.enableDownload
? event => {
downloadHandler(event.loaded, event.total || 1);
}
: undefinedValue,
onDownloadProgress: event => {
downloadHandler(event.loaded, event.total || 1);
},
...config
});

Expand Down
14 changes: 4 additions & 10 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders
/**
* axios请求配置参数
*/
export type AlovaAxiosRequestConfig = Omit<
type AlovaAxiosRequestConfig = Omit<
AxiosRequestConfig,
| 'url'
| 'method'
Expand All @@ -22,13 +22,7 @@ export type AlovaAxiosRequestConfig = Omit<
/**
* axios请求适配器
*/
export type AxiosRequestAdapter = AlovaRequestAdapter<
any,
any,
AlovaAxiosRequestConfig,
AxiosResponse,
AxiosResponseHeaders
>;
type AxiosRequestAdapter = AlovaRequestAdapter<any, any, AlovaAxiosRequestConfig, AxiosResponse, AxiosResponseHeaders>;

interface AdapterCreateOptions {
axios?: AxiosInstance;
Expand All @@ -37,7 +31,7 @@ interface AdapterCreateOptions {
* axios请求适配器
* @param options 选项参数
*/
export declare function axiosRequestAdapter(options?: AdapterCreateOptions): AxiosRequestAdapter;
declare function axiosRequestAdapter(options?: AdapterCreateOptions): AxiosRequestAdapter;

/**
* 模拟响应适配器,它用于@alova/mock中,让模拟请求时也能返回axios响应数据兼容的格式
Expand All @@ -58,7 +52,7 @@ export declare function axiosRequestAdapter(options?: AdapterCreateOptions): Axi
* });
* ```
*/
export declare const axiosMockResponse: {
declare const axiosMockResponse: {
onMockResponse: MockResponse<AlovaAxiosRequestConfig, AxiosResponse, AxiosResponse['headers']>;
onMockError: MockError;
};