Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import path from 'path';

export default defineConfig({
alias: {
'rc-rate$': path.resolve('src'),
'rc-rate/es': path.resolve('src'),
'@rc-component/rate$': path.resolve('src'),
'@rc-component/rate/es': path.resolve('src'),
},
favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'],
themeConfig: {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ npm start
```js
import React from 'react';
import ReactDOM from 'react-dom';
import Rate from 'rc-rate';
import Rate from '@rc-component/rate';

ReactDOM.render(
<Rate />,
Expand All @@ -68,7 +68,7 @@ ReactDOM.render(
```js
import React from 'react';
import ReactDOM from 'react-dom';
import Rate from 'rc-rate';
import Rate from '@rc-component/rate';
import styled from 'styled-components';

const StyledRate = styled(Rate)`
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/characterRender.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint no-console: 0 */
import Rate from '@rc-component/rate';
import Tooltip from '@rc-component/tooltip';
import '@rc-component/tooltip/assets/bootstrap_white.css';
import React from 'react';
import Tooltip from 'rc-tooltip';
import 'rc-tooltip/assets/bootstrap_white.css';
import Rate from 'rc-rate';
import '../../assets/index.less';

export default () => (
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/simple.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-console: 0 */
import React from 'react';
import Rate from 'rc-rate';
import Rate from '@rc-component/rate';
import '../../assets/index.less';

function onChange(v: number) {
Expand Down
14 changes: 0 additions & 14 deletions now.json

This file was deleted.

48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
{
"name": "rc-rate",
"version": "2.13.1",
"name": "@rc-component/rate",
"version": "1.0.0",
"description": "React Star Rate Component",
"engines": {
"node": ">=8.x"
},
"keywords": [
"react",
"react-component",
"react-rate",
"rate"
],
"homepage": "https://github.com/react-component/rate",
"bugs": {
"url": "https://github.com/react-component/rate/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/react-component/rate.git"
},
"bugs": {
"url": "https://github.com/react-component/rate/issues"
},
"license": "MIT",
"main": "./lib/index",
"module": "./es/index",
Comment on lines +20 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

缺少 types 字段,TypeScript 消费者可能无法获得类型入口

既然通过 father 输出 es/lib/,通常会同时生成 .d.ts。建议显式声明:

   "main": "./lib/index",
   "module": "./es/index",
+  "types": "./es/index.d.ts",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"main": "./lib/index",
"module": "./es/index",
"main": "./lib/index",
"module": "./es/index",
"types": "./es/index.d.ts",
🤖 Prompt for AI Agents
In package.json around lines 20-21, the package lacks a "types" field so
TypeScript consumers won't know the declaration entry; add a "types" field that
points to the generated .d.ts entry (for example the lib build output like
"./lib/index.d.ts" or wherever father emits declarations) and, if you publish
both ESM and CJS with different .d.ts locations, ensure the field points to the
canonical declaration file (and optionally add a "typesVersions" map if you need
to support alternate paths for different TS versions).

"files": [
"lib",
"es",
"assets/*.css"
],
"license": "MIT",
"main": "./lib/index",
"module": "./es/index",
"scripts": {
"start": "dumi dev",
"compile": "father build && lessc assets/index.less assets/index.css",
"coverage": "rc-test --coverage",
"docs:build": "dumi build",
"docs:deploy": "gh-pages -d .doc",
"compile": "father build && lessc assets/index.less assets/index.css",
"prepare": "dumi setup",
"prepublishOnly": "npm run compile && np --yolo --no-publish",
"postpublish": "npm run docs:build && npm run docs:deploy",
"lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md",
"now-build": "npm run docs:build",
"prepare": "dumi setup",
"prepublishOnly": "npm run compile && rc-np",
"prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"",
"postpublish": "npm run docs:build && npm run docs:deploy",
"start": "dumi dev",
"test": "rc-test",
"coverage": "rc-test --coverage",
"now-build": "npm run docs:build"
"tsc": "bunx tsc --noEmit"
},
Comment on lines +28 to 41
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

构建/发布脚本存在两点风险:bunx 依赖外部环境;now-build 与 now.json 不匹配

  • tsc 使用 bunx 会在未安装 Bun 的环境(多数 CI、开发机)失败。应改为使用本地 devDependency 的 tsc
  • now-build 仅执行 docs:build,与 now.json 的 dist 指向不一致,可能部署空目录(详见 now.json 评论)。

建议修改:

-    "now-build": "npm run docs:build",
+    "now-build": "npm run docs:build", // 若采用 now.json 方案 A;否则参考 now.json 方案 B
@@
-    "tsc": "bunx tsc --noEmit"
+    "tsc": "tsc --noEmit"

如果仓库目前未安装 TypeScript 的可执行文件,请确保 typescript 已在 devDependencies(此处已存在 ^5.0.4,可直接使用)。

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In package.json lines 28-41, the tsc script uses bunx which will fail when Bun
is not installed and now-build only runs docs:build which doesn't produce the
dist folder referenced by now.json; change "tsc" to invoke the local TypeScript
compiler (use the package's devDependency binary, e.g., replace bunx tsc
--noEmit with just tsc --noEmit or use npm/yarn exec to call the local tsc) and
update "now-build" to run the script that actually emits the deployment output
(e.g., run the compile script or whichever build produces the dist directory
referenced in now.json) and ensure typescript is present in devDependencies so
the local tsc binary is available.

"dependencies": {
"@babel/runtime": "^7.10.1",
"classnames": "^2.2.5",
"rc-util": "^5.0.1"
"@rc-component/util": "^1.3.0",
"classnames": "^2.2.5"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.0",
"@rc-component/father-plugin": "^2.1.3",
"@rc-component/np": "^1.0.0",
"@rc-component/tooltip": "^1.2.1",
"@types/classnames": "^2.2.9",
"@types/jest": "^29.5.1",
"@types/react": "^17.0.15",
Expand All @@ -63,15 +62,16 @@
"father": "^4.0.0",
"gh-pages": "^3.1.0",
"less": "^3.0.0",
"np": "^7.0.0",
"rc-test": "^7.0.15",
"rc-tooltip": "^5.0.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"typescript": "^5.0.4"
},
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
},
Comment on lines 66 to +73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

peerDependencies 与本地 dev React 版本不匹配

peer 要求 react/react-dom >=16.9.0,但 devDependencies 中是 ^16.0.0。这会导致本地开发/测试未覆盖到真实的 peer 下限并可能出现类型/行为差异。

建议至少对齐到 16.14(React 16 的最后一个小版本):

-    "react": "^16.0.0",
-    "react-dom": "^16.0.0",
+    "react": "^16.14.0",
+    "react-dom": "^16.14.0",

或直接提升到更高的 LTS 支持版本(若项目策略允许)。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"react": "^16.0.0",
"react-dom": "^16.0.0",
"typescript": "^5.0.4"
},
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
},
"react": "^16.14.0",
"react-dom": "^16.14.0",
"typescript": "^5.0.4"
},
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
},
🤖 Prompt for AI Agents
In package.json around lines 66 to 73, the devDependencies list react/react-dom
as ^16.0.0 which conflicts with peerDependencies requiring >=16.9.0; update the
devDependencies to match the peer lower bound (recommend at least 16.14.0 for
React 16 final patch) or bump both devDependencies and peerDependencies to a
supported LTS version per project policy so local dev/test runs use a React
version compatible with the declared peer range.

"engines": {
"node": ">=8.x"
}
Comment on lines +74 to 76
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

engines 声明过低(>=8.x),与现有工具链不兼容并且已 EOL

Node 8 早已 EOL,且与 typescript@^5father@^4dumi@^2 等工具不兼容。建议将最低版本提升到维护中的 LTS(建议 ≥14.18 或 ≥16.14,视工具链支持而定)。

推荐:

-  "engines": {
-    "node": ">=8.x"
-  }
+  "engines": {
+    "node": ">=16.14"
+  }

并在 CI 中同步调整 Node 版本矩阵。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"engines": {
"node": ">=8.x"
}
"engines": {
"node": ">=16.14"
}
🤖 Prompt for AI Agents
In package.json around lines 74–76, the "engines" field currently pins Node to
">=8.x" which is EOL and incompatible with our toolchain; update it to a
maintained LTS baseline (recommend ">=16.14.0" or at minimum ">=14.18.0"
depending on downstream support) and ensure the string uses full semver (e.g.
">=16.14.0"); after updating package.json, mirror the same Node versions in CI
(update the Node matrix in workflow files) so tests/builds run against the new
minimum and any additional supported versions.

}
12 changes: 5 additions & 7 deletions src/Rate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
import KeyCode from '@rc-component/util/lib/KeyCode';
import pickAttrs from '@rc-component/util/lib/pickAttrs';
import classNames from 'classnames';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import KeyCode from 'rc-util/lib/KeyCode';
import pickAttrs from 'rc-util/lib/pickAttrs';
import React from 'react';
import type { StarProps } from './Star';
import Star from './Star';
Expand Down Expand Up @@ -94,10 +94,8 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
}));

// =========================== Value ============================
const [value, setValue] = useMergedState(defaultValue || 0, {
value: propValue,
});
const [cleanedValue, setCleanedValue] = useMergedState<number | null>(null);
const [value, setValue] = useControlledState(defaultValue || 0, propValue);
const [cleanedValue, setCleanedValue] = useControlledState<number | null>(null);

const getStarValue = (index: number, x: number) => {
const reverse = direction === 'rtl';
Expand Down
2 changes: 1 addition & 1 deletion src/Star.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import KeyCode from 'rc-util/lib/KeyCode';
import KeyCode from '@rc-component/util/lib/KeyCode';
import classNames from 'classnames';

export interface StarProps {
Expand Down
2 changes: 1 addition & 1 deletion tests/simple.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render, mount } from 'enzyme';
import KeyCode from 'rc-util/lib/KeyCode';
import KeyCode from '@rc-component/util/lib/KeyCode';
import Rate from '../src';

describe('rate', () => {
Expand Down
21 changes: 5 additions & 16 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,10 @@
"skipLibCheck": true,
"esModuleInterop": true,
"paths": {
"@/*": [
"src/*"
],
"@@/*": [
".dumi/tmp/*"
],
"rc-rate": [
"src/index.tsx"
]
"@/*": ["src/*"],
"@@/*": [".dumi/tmp/*"],
"@rc-component/rate": ["src/index.tsx"]
}
},
"include": [
".dumirc.ts",
"./src/**/*.ts",
"./src/**/*.tsx",
"./docs/**/*.tsx"
]
}
"include": [".dumirc.ts", "./src/**/*.ts", "./src/**/*.tsx", "./docs/**/*.tsx"]
}