bi-components-library 1.0.18 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,11 +14,19 @@ pnpm add bi-components-library
14
14
 
15
15
  ## ⚠️ 重要提示:React 版本一致性
16
16
 
17
- **如果使用 pnpm,请确保 `react` 和 `react-dom` 版本完全一致**,否则会出现版本不兼容错误。
17
+ **React 要求 `react` 和 `react-dom` 必须完全一致**,这是 React 本身的限制,不是组件库的限制。如果版本不一致,React 会在运行时抛出错误。
18
18
 
19
- ### 解决方案
19
+ ### 自动检测功能
20
20
 
21
- 在您的项目 `package.json` 中添加 `pnpm.overrides` 配置:
21
+ 组件库在安装后会自动检测 React 版本是否一致。如果检测到版本不一致,会在控制台显示警告和修复建议。
22
+
23
+ ### 问题说明
24
+
25
+ 组件库使用 `peerDependencies`,不直接依赖 React,因此不会强制 React 版本。但如果您的项目中 `react` 和 `react-dom` 版本不一致(例如:`react@19.1.0-canary` 和 `react-dom@19.1.1`),React 会检测到并抛出错误。
26
+
27
+ ### 解决方案(使用 pnpm)
28
+
29
+ 在您的项目 `package.json` 中添加 `pnpm.overrides` 配置来强制统一版本:
22
30
 
23
31
  ```json
24
32
  {
@@ -31,8 +39,9 @@ pnpm add bi-components-library
31
39
  }
32
40
  ```
33
41
 
34
- 然后运行:
42
+ 然后重新安装依赖:
35
43
  ```bash
44
+ rm -rf node_modules pnpm-lock.yaml
36
45
  pnpm install
37
46
  ```
38
47
 
@@ -41,6 +50,15 @@ pnpm install
41
50
  pnpm add react@19.1.1 react-dom@19.1.1
42
51
  ```
43
52
 
53
+ ### 解决方案(使用 npm/yarn)
54
+
55
+ 直接安装统一版本:
56
+ ```bash
57
+ npm install react@19.1.1 react-dom@19.1.1
58
+ # 或
59
+ yarn add react@19.1.1 react-dom@19.1.1
60
+ ```
61
+
44
62
  ## 🚀 快速开始
45
63
 
46
64
  ### 1. 安装依赖
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bi-components-library",
3
3
  "private": false,
4
- "version": "1.0.18",
4
+ "version": "1.0.19",
5
5
  "type": "module",
6
6
  "description": "SealSeek BI 组件库 - 基于 Ant Design 的企业级 React 组件",
7
7
  "keywords": [
@@ -18,7 +18,8 @@
18
18
  "types": "./dist/index.d.ts",
19
19
  "files": [
20
20
  "dist",
21
- "README.md"
21
+ "README.md",
22
+ "scripts"
22
23
  ],
23
24
  "exports": {
24
25
  ".": {
@@ -33,6 +34,13 @@
33
34
  "react": ">=18.0.0",
34
35
  "react-dom": ">=18.0.0"
35
36
  },
37
+ "peerDependencyRules": {
38
+ "allowedVersions": {
39
+ "react": "*",
40
+ "react-dom": "*"
41
+ },
42
+ "ignoreMissing": []
43
+ },
36
44
  "scripts": {
37
45
  "dev": "vite",
38
46
  "build": "tsc -p tsconfig.build.json && vite build",
@@ -40,7 +48,8 @@
40
48
  "lint": "eslint .",
41
49
  "preview": "vite preview",
42
50
  "preview:demo": "vite preview --outDir dist-demo",
43
- "prepublishOnly": "npm run build"
51
+ "prepublishOnly": "npm run build",
52
+ "postinstall": "node scripts/check-react-versions.cjs"
44
53
  },
45
54
  "devDependencies": {
46
55
  "@eslint/js": "^9.30.1",
@@ -65,11 +74,5 @@
65
74
  "i": "^0.3.7",
66
75
  "npm": "^11.6.4",
67
76
  "dayjs": "^1.11.13"
68
- },
69
- "pnpm": {
70
- "overrides": {
71
- "react": "19.1.1",
72
- "react-dom": "19.1.1"
73
- }
74
77
  }
75
78
  }
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * 检查 React 和 React-DOM 版本是否一致
5
+ * 如果不一致,提供修复建议
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ function findPackageJson(startPath) {
12
+ let currentPath = startPath;
13
+ while (currentPath !== path.dirname(currentPath)) {
14
+ const packageJsonPath = path.join(currentPath, 'package.json');
15
+ if (fs.existsSync(packageJsonPath)) {
16
+ return packageJsonPath;
17
+ }
18
+ currentPath = path.dirname(currentPath);
19
+ }
20
+ return null;
21
+ }
22
+
23
+ function checkReactVersions() {
24
+ try {
25
+ // 查找项目根目录的 package.json
26
+ const projectRoot = process.cwd();
27
+ const packageJsonPath = findPackageJson(projectRoot);
28
+
29
+ if (!packageJsonPath) {
30
+ return; // 找不到 package.json,静默退出
31
+ }
32
+
33
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
34
+ const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
35
+
36
+ const reactVersion = dependencies.react;
37
+ const reactDomVersion = dependencies['react-dom'];
38
+
39
+ // 如果两个版本都存在但不一致
40
+ if (reactVersion && reactDomVersion && reactVersion !== reactDomVersion) {
41
+ console.warn('\n⚠️ [bi-components-library] 检测到 React 版本不一致:');
42
+ console.warn(` - react: ${reactVersion}`);
43
+ console.warn(` - react-dom: ${reactDomVersion}`);
44
+ console.warn('\n📝 解决方案:');
45
+
46
+ // 检查是否使用 pnpm
47
+ const isPnpm = fs.existsSync(path.join(path.dirname(packageJsonPath), 'pnpm-lock.yaml'));
48
+
49
+ if (isPnpm) {
50
+ console.warn(' 在 package.json 中添加 pnpm.overrides 配置:');
51
+ console.warn(' {');
52
+ console.warn(' "pnpm": {');
53
+ console.warn(' "overrides": {');
54
+ console.warn(` "react": "${reactDomVersion}",`);
55
+ console.warn(` "react-dom": "${reactDomVersion}"`);
56
+ console.warn(' }');
57
+ console.warn(' }');
58
+ console.warn(' }');
59
+ console.warn('\n 然后运行: pnpm install\n');
60
+ } else {
61
+ console.warn(` 运行: npm install react@${reactDomVersion} react-dom@${reactDomVersion}`);
62
+ console.warn(` 或: yarn add react@${reactDomVersion} react-dom@${reactDomVersion}\n`);
63
+ }
64
+ }
65
+ } catch (error) {
66
+ // 静默处理错误,不影响安装过程
67
+ }
68
+ }
69
+
70
+ // 只在安装时运行,不在开发时运行
71
+ if (process.env.npm_lifecycle_event === 'postinstall' || process.env.npm_lifecycle_event === 'install') {
72
+ checkReactVersions();
73
+ }
74
+