From a4bedf960bd37de28ad0cf072fecdf64812ad0ba Mon Sep 17 00:00:00 2001 From: Avan Date: Sun, 18 Aug 2024 11:04:05 +0800 Subject: [PATCH 1/2] Update react-component-ci.yml --- .github/workflows/react-component-ci.yml | 119 +---------------------- 1 file changed, 5 insertions(+), 114 deletions(-) diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 2097f2a..f860ff1 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -1,115 +1,6 @@ -name: CI - -on: ['push', 'pull_request'] - +name: ✅ test +on: [push, pull_request] jobs: - setup: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: cache package-lock.json - uses: actions/cache@v4 - with: - path: package-temp-dir - key: lock-${{ github.sha }} - - - name: create package-lock.json - run: npm i --package-lock-only --ignore-scripts - - - name: hack for singe file - run: | - if [ ! -d "package-temp-dir" ]; then - mkdir package-temp-dir - fi - cp package-lock.json package-temp-dir - - - name: cache node_modules - id: node_modules_cache_id - uses: actions/cache@v4 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - - name: install - if: steps.node_modules_cache_id.outputs.cache-hit != 'true' - run: npm ci - - lint: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v4 - - - name: restore cache from package-lock.json - uses: actions/cache@v4 - with: - path: package-temp-dir - key: lock-${{ github.sha }} - - - name: restore cache from node_modules - uses: actions/cache@v4 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - - name: lint - run: npm run lint - - needs: setup - - compile: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v4 - - - name: restore cache from package-lock.json - uses: actions/cache@v4 - with: - path: package-temp-dir - key: lock-${{ github.sha }} - - - name: restore cache from node_modules - uses: actions/cache@v4 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - - name: compile - run: npm run compile - - needs: setup - - coverage: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v4 - - - name: restore cache from package-lock.json - uses: actions/cache@v4 - with: - path: package-temp-dir - key: lock-${{ github.sha }} - - - name: restore cache from node_modules - uses: actions/cache@v4 - with: - path: node_modules - key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }} - - - name: coverage - run: npm test -- --coverage - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - - needs: setup + test: + uses: react-component/rc-test/.github/workflows/test.yml@main + secrets: inherit From 81a32beda35bb5201f84b80030eab7c9bb12b72c Mon Sep 17 00:00:00 2001 From: Avan Date: Sun, 18 Aug 2024 12:15:21 +0800 Subject: [PATCH 2/2] fix: ts noEmit --- docs/examples/asyncAction.tsx | 2 +- docs/examples/beforeUpload.tsx | 6 +++--- docs/examples/customRequest.tsx | 7 ++++--- src/interface.tsx | 10 ++++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/examples/asyncAction.tsx b/docs/examples/asyncAction.tsx index 5aff04a..c523cf3 100644 --- a/docs/examples/asyncAction.tsx +++ b/docs/examples/asyncAction.tsx @@ -4,7 +4,7 @@ import Upload from 'rc-upload'; const props = { action: () => { - return new Promise(resolve => { + return new Promise(resolve => { setTimeout(() => { resolve('/upload.do'); }, 2000); diff --git a/docs/examples/beforeUpload.tsx b/docs/examples/beforeUpload.tsx index fe78577..cefd775 100644 --- a/docs/examples/beforeUpload.tsx +++ b/docs/examples/beforeUpload.tsx @@ -1,10 +1,10 @@ /* eslint no-console:0 */ -import React from 'react'; +import { Action } from '@/interface'; import Upload from 'rc-upload'; const props = { - action: '/upload.do', + action: '/upload.do' as Action, multiple: true, onStart(file) { console.log('onStart', file, file.name); @@ -17,7 +17,7 @@ const props = { }, beforeUpload(file, fileList) { console.log(file, fileList); - return new Promise(resolve => { + return new Promise(resolve => { console.log('start check'); setTimeout(() => { console.log('check finshed'); diff --git a/docs/examples/customRequest.tsx b/docs/examples/customRequest.tsx index 83c13af..afe58fd 100644 --- a/docs/examples/customRequest.tsx +++ b/docs/examples/customRequest.tsx @@ -2,6 +2,7 @@ import React from 'react'; import axios from 'axios'; import Upload from 'rc-upload'; +import { UploadRequestOption } from '@/interface'; const uploadProps = { action: '/upload.do', @@ -32,13 +33,13 @@ const uploadProps = { onProgress, onSuccess, withCredentials, - }) { + }: UploadRequestOption) { // EXAMPLE: post form-data with 'axios' // eslint-disable-next-line no-undef const formData = new FormData(); if (data) { Object.keys(data).forEach(key => { - formData.append(key, data[key]); + formData.append(key, data[key] as string); }); } formData.append(filename, file); @@ -48,7 +49,7 @@ const uploadProps = { withCredentials, headers, onUploadProgress: ({ total, loaded }) => { - onProgress({ percent: Math.round((loaded / total) * 100).toFixed(2) }, file); + onProgress({ percent: Number(Math.round((loaded / total) * 100).toFixed(2)) }, file); }, }) .then(({ data: response }) => { diff --git a/src/interface.tsx b/src/interface.tsx index 9d02f27..1c6e1d5 100644 --- a/src/interface.tsx +++ b/src/interface.tsx @@ -29,7 +29,7 @@ export interface UploadProps file: RcFile, FileList: RcFile[], ) => BeforeUploadFileType | Promise | void; - customRequest?: (option: UploadRequestOption) => void; + customRequest?: (option: UploadRequestOption) => void | { abort: () => void }; withCredentials?: boolean; openFileDialogOnClick?: boolean; prefixCls?: string; @@ -54,6 +54,8 @@ export type UploadRequestMethod = 'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'p export type UploadRequestHeader = Record; +export type UploadRequestFile = Exclude | RcFile; + export interface UploadRequestError extends Error { status?: number; method?: UploadRequestMethod; @@ -61,12 +63,12 @@ export interface UploadRequestError extends Error { } export interface UploadRequestOption { - onProgress?: (event: UploadProgressEvent) => void; + onProgress?: (event: UploadProgressEvent, file?: UploadRequestFile) => void; onError?: (event: UploadRequestError | ProgressEvent, body?: T) => void; - onSuccess?: (body: T, xhr?: XMLHttpRequest) => void; + onSuccess?: (body: T, fileOrXhr?: UploadRequestFile | XMLHttpRequest) => void; data?: Record; filename?: string; - file: Exclude | RcFile; + file: UploadRequestFile; withCredentials?: boolean; action: string; headers?: UploadRequestHeader;