Skip to content

Commit b66176f

Browse files
committed
feat: 支持 es2015
1 parent 73ac18d commit b66176f

19 files changed

+438
-58
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
- name: Install
2727
run: pnpm i
2828

29+
- name: Create releaselog
30+
run: pnpm releaselog
31+
2932
- name: Check prerelease
3033
id: prerelease
3134
uses: actions/github-script@v6
@@ -40,7 +43,7 @@ jobs:
4043
with:
4144
tag_name: ${{ github.ref }}
4245
release_name: Release ${{ github.ref }}
43-
body_path: 'CHANGELOG.md'
46+
body_path: 'RELEASELOG.md'
4447
prerelease: ${{ steps.prerelease.outputs.result }}
4548

4649
- name: Build Release Asset

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ coverage
2323

2424
# eslint
2525
.eslintcache
26+
27+
# release
28+
RELEASELOG.md

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CHANGELOG.md

CHANGELOG.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
# 2.0.0-beta.0 (2023-04-04)
22

3-
43
### Bug Fixes
54

65
* 清理 url 前面多余的斜线 ([666a942](https://github.com/zjx0905/axios-miniprogram/commit/666a9427d3c9bfbd96def9e112d5183acdf08d84))
76

8-
97
### Features
108

119
* 增强默认参数系列化器 ([0cfb3e1](https://github.com/zjx0905/axios-miniprogram/commit/0cfb3e1ff04b69896ba43ffcb6abba5fb61ad48a))
1210
* 支持合并自定义配置 ([4409a57](https://github.com/zjx0905/axios-miniprogram/commit/4409a5720ba1e58a4c218ee67f71d5f05beee6a8)), closes [#38](https://github.com/zjx0905/axios-miniprogram/issues/38)
1311
* 支持京东小程序 ([0d1d21f](https://github.com/zjx0905/axios-miniprogram/commit/0d1d21fc66eb202463ef2baaa174b0f60276035e))
1412
* 支持自定义配置 ([b15b31e](https://github.com/zjx0905/axios-miniprogram/commit/b15b31ee55217f11e08713ce02dd7ab21732fba1))
1513

16-
1714
### BREAKING CHANGES
1815

1916
* axios.get('url',{obj:{v1:1,v2:2}}) -> fetch: 'url?obj={"val":1,"v2":2}'
20-
变为
21-
axios.get('url',{obj:{v1:1,v2:2}}) -> fetch: 'url?obj[v1]=1&obj[v2]=2'
22-
23-
24-
17+
变为
18+
axios.get('url',{obj:{v1:1,v2:2}}) -> fetch: 'url?obj[v1]=1&obj[v2]=2'

package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "axios-miniprogram",
33
"version": "2.0.0-beta.0",
44
"description": "基于 Promise 的 HTTP 请求库,适用于各大小程序平台。",
5-
"main": "dist/axios-miniprogram.esm.js",
6-
"module": "dist/axios-miniprogram.cjs.js",
5+
"main": "dist/axios-miniprogram.cjs.js",
6+
"module": "dist/axios-miniprogram.esm.js",
77
"types": "dist/axios-miniprogram.d.ts",
88
"type": "module",
99
"files": [
@@ -25,17 +25,14 @@
2525
},
2626
"homepage": "https://github.com/zjx0905/axios-miniprogram#readme",
2727
"license": "MIT",
28-
"engines": {
29-
"node": ">=16",
30-
"pnpm": ">=7"
31-
},
3228
"scripts": {
3329
"cz": "czg",
3430
"build": "esno scripts/build.ts",
3531
"build:asset": "esno scripts/build-asset.ts",
3632
"release": "esno scripts/release.ts",
3733
"publish:ci": "esno scripts/publish.ts",
3834
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
35+
"releaselog": "esno scripts/releaselog.ts",
3936
"upload:asset": "esno scripts/upload-asset.ts",
4037
"test": "vitest run",
4138
"test:watch": "vitest",
@@ -94,4 +91,4 @@
9491
]
9592
}
9693
}
97-
}
94+
}

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function buildConfig(format) {
4545
: esbuildPlugin({
4646
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
4747
sourceMap: output.sourcemap,
48+
target: 'es2015',
4849
minify: true,
4950
}),
5051
],

scripts/publish.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
1+
import fs from 'node:fs';
12
import consola from 'consola';
2-
import { exec, getPkgJSON } from './utils';
3+
import { exec, pkgPath, getPkgJSON } from './utils';
34

4-
const { version } = getPkgJSON();
5+
const pkg = getPkgJSON();
56

67
main();
78

89
function main() {
10+
consola.info('Generate publish pkg');
11+
generatePublishPkg();
12+
913
let command = 'npm publish --access public';
1014

11-
const preid = version.match(/\d-(.+)\.\d$/)?.[1];
15+
const preid = pkg.version.match(/\d-(.+)\.\d$/)?.[1];
1216
if (preid) {
1317
command += ` --tag ${preid}`;
1418
}
1519

1620
consola.info('Publish NPM');
1721
exec(command);
1822
}
23+
24+
function generatePublishPkg() {
25+
const publishPkg = {};
26+
27+
[
28+
'name',
29+
'version',
30+
'description',
31+
'main',
32+
'module',
33+
'types',
34+
'files',
35+
'repository',
36+
'keywords',
37+
'author',
38+
'bugs',
39+
'homepage',
40+
'license',
41+
].forEach((key) => {
42+
publishPkg[key] = pkg[key];
43+
});
44+
45+
fs.writeFileSync(pkgPath, JSON.stringify(publishPkg, null, 2) + '\n');
46+
}

scripts/releaselog.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import readline from 'node:readline';
4+
import { __dirname, getPkgJSON } from './utils';
5+
6+
const changelogPath = path.resolve(__dirname, 'CHANGELOG.md');
7+
const releaselogPath = path.resolve(__dirname, 'RELEASELOG.md');
8+
const { version } = getPkgJSON();
9+
const versionRE = new RegExp(`^# \\[?${version}\\]?`);
10+
11+
main();
12+
13+
async function main() {
14+
const changelog = readline.createInterface({
15+
input: fs.createReadStream(changelogPath),
16+
crlfDelay: Infinity,
17+
});
18+
19+
let releaselog = '';
20+
for await (const line of changelog) {
21+
if (line.startsWith('# ') && !versionRE.test(line)) {
22+
break;
23+
}
24+
releaselog += `${line}\n`;
25+
}
26+
27+
fs.writeFileSync(releaselogPath, releaselog);
28+
}

src/adapter.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
isEmptyArray,
33
isFunction,
44
isPlainObject,
5-
isString,
65
isUndefined,
76
} from './helpers/isTypes';
87
import { assert, throwError } from './helpers/error';
@@ -152,7 +151,7 @@ export function getAdapterDefault(): AxiosAdapter | undefined {
152151
try {
153152
const tryGetPlatform = tryGetPlatforms.shift();
154153

155-
if (isPlainObject((platform = tryGetPlatform?.()))) {
154+
if (isPlainObject((platform = tryGetPlatform!()))) {
156155
platform = revisePlatformApiNames(platform);
157156
}
158157
} catch (err) {
@@ -169,13 +168,11 @@ export function getAdapterDefault(): AxiosAdapter | undefined {
169168

170169
export function createAdapter(platform: AxiosPlatform): AxiosAdapter {
171170
assert(isPlainObject(platform), 'platform 不是一个 object');
172-
assert(isFunction(platform.request), 'platform.request 不是一个 function');
173-
assert(isFunction(platform.upload), 'platform.upload 不是一个 function');
174-
assert(isFunction(platform.download), 'platform.download 不是一个 function');
171+
assert(isFunction(platform.request), 'request 不是一个 function');
172+
assert(isFunction(platform.upload), 'upload 不是一个 function');
173+
assert(isFunction(platform.download), 'download 不是一个 function');
175174

176-
function adapterDefault(
177-
config: AxiosAdapterRequestConfig,
178-
): AxiosAdapterTask | void {
175+
function adapter(config: AxiosAdapterRequestConfig): AxiosAdapterTask | void {
179176
const baseOptions = transformOptions(config);
180177

181178
switch (config.type) {
@@ -201,16 +198,6 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter {
201198
upload: AxiosAdapterUpload,
202199
baseOptions: AxiosAdapterBaseOptions,
203200
): AxiosAdapterTask | void {
204-
assert(isPlainObject(baseOptions.data), 'data 不是一个 object');
205-
assert(
206-
isString(baseOptions.data?.fileName),
207-
'data.fileName 不是一个 string',
208-
);
209-
assert(
210-
isString(baseOptions.data?.filePath),
211-
'data.filePath 不是一个 string',
212-
);
213-
214201
const { fileName, filePath, fileType, ...formData } =
215202
baseOptions.data as AxiosRequestFormData;
216203
const options = {
@@ -306,7 +293,7 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter {
306293
}
307294
}
308295

309-
return adapterDefault;
296+
return adapter;
310297
}
311298

312299
export function isPlatform(value: unknown): value is AxiosPlatform {

src/axios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface AxiosInstance extends Axios {
2020
export interface AxiosStatic extends AxiosInstance {
2121
Axios: AxiosConstructor;
2222
defaults: AxiosRequestConfig & {
23-
headers: Required<AxiosRequestHeaders> & { common?: AnyObject };
23+
headers?: AxiosRequestHeaders & { common?: AnyObject };
2424
};
2525
CancelToken: CancelTokenConstructor;
2626
create(defaults?: AxiosRequestConfig): AxiosInstance;

0 commit comments

Comments
 (0)