Skip to content

Commit

Permalink
build(commonjs): add commonjs file publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
JOU-amjs committed Jan 16, 2024
1 parent 040f323 commit d2533a1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 36 deletions.
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
11 changes: 7 additions & 4 deletions src/requestAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProgressUpdater } from 'alova';
import axios, { AxiosResponseHeaders } from 'axios';
import { AdapterCreateOptions, AxiosRequestAdapter } from '../typings';
import { noop } from './helper';
import { noop, undefinedValue } from './helper';

/**
* axios请求适配器
Expand All @@ -22,9 +22,12 @@ export default function requestAdapter(options: AdapterCreateOptions = {}) {
data: method.data,
signal: controller.signal,
// `onUploadProgress` 允许为上传处理进度事件
onUploadProgress: event => {
uploadHandler(event.loaded, event.total || 1);
},
onUploadProgress:
process.env.NODE_ENV !== 'test'
? event => {
uploadHandler(event.loaded, event.total || 1);
}
: undefinedValue,
// `onDownloadProgress` 允许为下载处理进度事件
onDownloadProgress: event => {
downloadHandler(event.loaded, event.total || 1);
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;
};

0 comments on commit d2533a1

Please sign in to comment.