3 Commits

Author SHA1 Message Date
742a562109 feat: 添加queryclient 2024-09-28 22:22:17 +08:00
61a68fbd41 feat: add publish workflow 2024-09-28 19:37:35 +08:00
9ba7fb2f10 fix: types fix 2024-09-28 19:22:00 +08:00
4 changed files with 40 additions and 51 deletions

35
.github/workflow/publish.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: Publish to npm
on:
push:
tags:
- 'v*.*.*' # 当推送带有版本号的 tag 时触发,例如 v1.0.0
jobs:
publish:
runs-on: ubuntu-latest
steps:
# Step 1: Clone current Git repository
- name: Checkout this repository
uses: actions/checkout@v3
# Setop 2: list files in current directory
- name: List files in current directory
run: ls -al
# Step 3: Setup Node.js and install dependencies
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20.6'
registry-url: 'https://registry.npmjs.org/'
- name: npm whoami
run: |
npm whoami
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
# Step 4: Install dependencies
- name: Install dependencies
run: npm install
# Step 5: Publish to npm
- name: Publish package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # 使用 GitHub Secrets 来安全存储 npm token
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # 使用 GitHub Secrets 来安全存储 npm token

View File

@@ -1,38 +0,0 @@
name: Publish to npm
on:
push:
tags:
- 'v*.*.*' # 当推送带有版本号的 tag 时触发,例如 v1.0.0
workflow_dispatch: # 添加手动触发器
jobs:
publish:
runs-on: ubuntu-latest
steps:
# Step 1: Clone current Git repository
- name: Checkout this repository
uses: actions/checkout@v3
# Step 3: Setup Node.js and install dependencies
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20.6'
registry-url: 'https://registry.npmjs.org/'
cache: 'npm' # 启用 npm 缓存,提高安装速度
- name: Configure npm authentication
run: npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: npm install
- name: Build project
run: npm run build
# Step 6: 发布到 npm
- name: Publish package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Step 7: 发布成功后,更新版本标签
# - name: Create Git tag
# run: |
# TAG="v$(node -p -e "require('./package.json').version")"
# git tag $TAG
# git push origin $TAG

View File

@@ -1,6 +1,6 @@
{
"name": "@kevisual/query",
"version": "0.0.6",
"version": "0.0.5",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
@@ -14,11 +14,8 @@
"files": [
"dist"
],
"keywords": [
"kevisual",
"query"
],
"author": "abearxiong",
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
@@ -34,10 +31,6 @@
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/abearxiong/kevisual-query.git"
},
"exports": {
".": {
"import": "./dist/index.js",

View File

@@ -64,7 +64,6 @@ export class Query<U = any, V = any> {
const headers = { ...this.headers, ...options?.headers };
const adapter = options?.adapter || this.adapter;
const beforeRequest = options?.beforeRequest || this.beforeRequest;
const afterResponse = options?.afterResponse || this.afterResponse;
const timeout = options?.timeout || this.timeout;
const req = {
url: url,
@@ -77,8 +76,8 @@ export class Query<U = any, V = any> {
}
return adapter(req).then(async (res) => {
res.success = res.code === 200;
if (afterResponse) {
return await afterResponse(res);
if (options?.afterResponse) {
return await options.afterResponse(res);
}
return res;
});