Skip to content

Commit

Permalink
Merge branch 'alibaba:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hmilin authored Jan 9, 2025
2 parents 80b778f + c7bb04c commit 801fe49
Show file tree
Hide file tree
Showing 41 changed files with 15,262 additions and 19,610 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
gitleaks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: wget
uses: wei/wget@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/issue-reply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- name: help wanted
if: github.event.label.name == 'help wanted'
uses: actions-cool/issues-helper@v1.2
uses: actions-cool/issues-helper@v3
with:
actions: 'create-comment'
issue-number: ${{ github.event.issue.number }}
Expand All @@ -23,7 +23,7 @@ jobs:
- name: 🤔 Need Reproduce
if: github.event.label.name == '🤔 Need Reproduce'
uses: actions-cool/issues-helper@v1.2
uses: actions-cool/issues-helper@v3
with:
actions: 'create-comment'
issue-number: ${{ github.event.issue.number }}
Expand Down
28 changes: 0 additions & 28 deletions .github/workflows/node-ci.yml

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ jobs:
strategy:
matrix:
mode: ['normal', 'strict']
node-version: [14.x, 16.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> "$GITHUB_OUTPUT"
- name: Setup pnpm cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: pnpm run intall, build
- name: pnpm run install, build
run: |
pnpm run init
Expand Down
4 changes: 0 additions & 4 deletions .prettierignore

This file was deleted.

19 changes: 0 additions & 19 deletions .prettierrc

This file was deleted.

48 changes: 48 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
"ignoreUnknown": true
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"linter": {
"rules": {
"style": {
"noNonNullAssertion": "off"
},
"correctness": {
"useHookAtTopLevel": "error"
},
"suspicious": {
"noExplicitAny": "off"
}
}
},
"formatter": {
"lineWidth": 100,
"indentStyle": "space"
},
"javascript": {
"parser": {
"unsafeParameterDecoratorsEnabled": true
},
"formatter": {
"quoteStyle": "single",
"jsxQuoteStyle": "single"
}
},
"css": {
"parser": {
"cssModules": true
},
"formatter": {
"enabled": true
},
"linter": {
"enabled": true
}
}
}
4 changes: 2 additions & 2 deletions config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default {
],
},
{ title: '更新日志', path: 'https://github.com/alibaba/hooks/releases' },
{ title: '国内镜像', path: 'https://ahooks.gitee.io/zh-CN' },
{ title: '国内镜像', path: 'https://ahooks.pages.dev' },
{ title: 'GitHub', path: 'https://github.com/alibaba/hooks' },
],
'en-US': [
Expand All @@ -89,7 +89,7 @@ export default {
],
},
{ title: 'Releases', path: 'https://github.com/alibaba/hooks/releases' },
{ title: '国内镜像', path: 'https://ahooks.gitee.io/zh-CN' },
{ title: '国内镜像', path: 'https://ahooks.pages.dev' },
{ title: 'GitHub', path: 'https://github.com/alibaba/hooks' },
],
},
Expand Down
1 change: 1 addition & 0 deletions config/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const menus = [
'useCounter',
'useTextSelection',
'useWebSocket',
'useTheme',
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
testPathIgnorePatterns: ['/.history/'],
modulePathIgnorePatterns: ['<rootDir>/package.json'],
resetMocks: false,
setupFiles: ['./jest.setup.js', 'jest-localstorage-mock'],
setupFiles: ['./jest.setup.js', 'jest-localstorage-mock', './match-media-mock.js'],
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
transform: {
'^.+\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.json' }],
Expand Down
13 changes: 13 additions & 0 deletions match-media-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "ahooks",
"private": true,
"packageManager": "pnpm@7.33.6",
"packageManager": "pnpm@9.6.0",
"engines": {
"pnpm": ">=7 <8"
"pnpm": ">=7 <10"
},
"repository": {
"type": "git",
Expand All @@ -12,14 +12,14 @@
"scripts": {
"init": "pnpm install && pnpm run build",
"start": "pnpm run dev",
"dev": "dumi dev",
"dev": "set NODE_OPTIONS=--openssl-legacy-provider && dumi dev",
"clean-dist": "rimraf 'packages/*/{lib,es,node_modules,dist}'",
"clean": "pnpm run clean-dist && rimraf node_modules",
"build": "pnpm -r --filter=./packages/* run build",
"test": "jest",
"coveralls": "jest --coverage --coverageReporters=text-lcov | coveralls",
"lint": "eslint --ignore-pattern **/__tests__/* --ignore-pattern **/demo/* \"packages/*/src/**/*.{ts,tsx}\" --cache",
"pretty": "pretty-quick --staged",
"pretty": "biome format --fix --staged",
"build:doc": "dumi build",
"pub:doc-surge": "surge ./dist --domain ahooks.js.org",
"pub:doc-gitee": "cd ./dist && rm -rf .git && touch .spa && touch .nojekyll && git init && git remote add origin [email protected]:ahooks/ahooks.git && git add -A && git commit -m \"publish docs\" && git push origin main -f && echo https://gitee.com/ahooks/ahooks/pages",
Expand All @@ -35,6 +35,7 @@
"@babel/cli": "^7.10.1",
"@babel/core": "^7.10.2",
"@babel/plugin-transform-runtime": "^7.19.6",
"@biomejs/biome": "^1.8.3",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@testing-library/jest-dom": "^5.16.5",
Expand Down Expand Up @@ -62,8 +63,6 @@
"jest-environment-jsdom": "^29.4.1",
"jest-localstorage-mock": "^2.4.18",
"mockjs": "^1.1.0",
"prettier": "^3.2.5",
"pretty-quick": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-drag-listview": "^0.1.6",
Expand All @@ -78,8 +77,6 @@
"webpack-merge": "^4.2.2"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
"extends": ["@commitlint/config-conventional"]
}
}
21 changes: 5 additions & 16 deletions packages/hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
{
"name": "ahooks",
"version": "3.8.0",
"version": "3.8.2",
"description": "react hooks library",
"keywords": [
"ahooks",
"umi hooks",
"react hooks"
],
"keywords": ["ahooks", "umi hooks", "react hooks"],
"main": "./lib/index.js",
"module": "./es/index.js",
"types": "./lib/index.d.ts",
Expand All @@ -24,19 +20,12 @@
"scripts": {
"build": "gulp && webpack-cli"
},
"files": [
"dist",
"lib",
"es",
"metadata.json",
"package.json",
"README.md"
],
"files": ["dist", "lib", "es", "metadata.json", "package.json", "README.md"],
"dependencies": {
"@babel/runtime": "^7.21.0",
"dayjs": "^1.9.1",
"intersection-observer": "^0.12.0",
"js-cookie": "^2.x.x",
"js-cookie": "^3.0.5",
"lodash": "^4.17.21",
"react-fast-compare": "^3.2.2",
"resize-observer-polyfill": "^1.5.1",
Expand All @@ -49,7 +38,7 @@
"devDependencies": {
"@alifd/next": "^1.20.6",
"@ant-design/icons": "^5.0.1",
"@types/js-cookie": "^2.x.x",
"@types/js-cookie": "^3.0.6",
"@types/lodash": "^4.14.202",
"antd": "^5.2.1",
"jest-websocket-mock": "^2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/createDeepCompareEffect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const createDeepCompareEffect: CreateUpdateEffect = (hook) => (effect, de
const signalRef = useRef<number>(0);

if (deps === undefined || !depsEqual(deps, ref.current)) {
ref.current = deps;
signalRef.current += 1;
}
ref.current = deps;

hook(effect, [signalRef.current]);
};
2 changes: 2 additions & 0 deletions packages/hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import useVirtualList from './useVirtualList';
import useWebSocket from './useWebSocket';
import useWhyDidYouUpdate from './useWhyDidYouUpdate';
import useMutationObserver from './useMutationObserver';
import useTheme from './useTheme';

export {
useRequest,
Expand Down Expand Up @@ -156,4 +157,5 @@ export {
useRafTimeout,
useResetState,
useMutationObserver,
useTheme,
};
2 changes: 1 addition & 1 deletion packages/hooks/src/useAntdTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const useAntdTable = <TData extends Data, TParams extends Params>(
run(...params);
return;
}
if (!manual && ready) {
if (ready) {
allFormDataRef.current = defaultParams?.[1] || {};
restoreForm();
_submit(defaultParams?.[0]);
Expand Down
8 changes: 5 additions & 3 deletions packages/hooks/src/useControllableValue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function useControllableValue<T = any>(
props?: Props,
options?: Options<T>,
): [T, (v: SetStateAction<T>, ...args: any[]) => void];
function useControllableValue<T = any>(props: Props = {}, options: Options<T> = {}) {
function useControllableValue<T = any>(defaultProps: Props, options: Options<T> = {}) {
const props = defaultProps ?? {};

const {
defaultValue,
defaultValuePropName = 'defaultValue',
Expand All @@ -35,13 +37,13 @@ function useControllableValue<T = any>(props: Props = {}, options: Options<T> =
} = options;

const value = props[valuePropName] as T;
const isControlled = props.hasOwnProperty(valuePropName);
const isControlled = Object.prototype.hasOwnProperty.call(props, valuePropName);

const initialValue = useMemo(() => {
if (isControlled) {
return value;
}
if (props.hasOwnProperty(defaultValuePropName)) {
if (Object.prototype.hasOwnProperty.call(props, defaultValuePropName)) {
return props[defaultValuePropName];
}
return defaultValue;
Expand Down
Loading

0 comments on commit 801fe49

Please sign in to comment.