Skip to content

Commit 693ead3

Browse files
committed
chore: 更新 Dependabot 配置以解决 pnpm 兼容性问题
- 限制 Dependabot 只更新直接依赖,避免传递依赖更新的兼容性问题 - 提供备选配置和快速切换工具以增强灵活性 - 更新文档以反映新的解决方案和配置选项
1 parent 00bd02e commit 693ead3

File tree

4 files changed

+171
-9
lines changed

4 files changed

+171
-9
lines changed

.github/DEPENDABOT_PNPM_WORKAROUND.md

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ Dependabot doesn't support the 'updating transitive dependencies' feature for pn
1111

1212
## 解决方案
1313

14-
### 1. 使用 `resolutions` 替代 `pnpm.overrides`
14+
### 1. 限制 Dependabot 只更新直接依赖
15+
16+
`.github/dependabot.yml` 中添加:
17+
18+
```yaml
19+
allow:
20+
- dependency-type: "direct"
21+
```
22+
23+
这样 Dependabot 只会更新 `package.json` 中直接声明的依赖,避免传递依赖更新的兼容性问题。
24+
25+
### 2. 使用 `resolutions` 替代 `pnpm.overrides`
1526

1627
我们将配置从 `pnpm.overrides` 改为 `resolutions`:
1728

@@ -38,7 +49,11 @@ ignore:
3849
update-types: ["version-update:semver-major", "version-update:semver-minor", "version-update:semver-patch"]
3950
```
4051

41-
### 3. 手动管理传递依赖
52+
### 3. 备选配置
53+
54+
如果问题仍然存在,可以使用更严格的配置。将 `.github/dependabot-alternative.yml` 重命名为 `dependabot.yml` 替换现有配置。
55+
56+
### 4. 手动管理传递依赖
4257

4358
对于需要强制更新的传递依赖:
4459
1. 使用 `resolutions` 指定版本
@@ -83,13 +98,17 @@ ignore:
8398
- 更新 GitHub Actions 工作流
8499
- 更新开发文档
85100

86-
### 方案 B:禁用 Dependabot 的传递依赖更新
87-
在 `dependabot.yml` 中添加
101+
### 方案 B:使用备选配置
102+
使用 `.github/dependabot-alternative.yml` 中的严格配置
88103
```yaml
89-
- package-ecosystem: "npm"
90-
# ... 其他配置
91-
allow:
92-
- dependency-type: "direct" # 只更新直接依赖
104+
allow:
105+
- dependency-type: "direct"
106+
ignore:
107+
- dependency-name: "esbuild"
108+
- dependency-name: "@esbuild/*"
109+
- dependency-name: "*"
110+
update-types: ["version-update:semver-major"]
111+
dependency-type: "indirect"
93112
```
94113

95114
## 相关资源
@@ -98,6 +117,28 @@ ignore:
98117
- [pnpm resolutions 文档](https://pnpm.io/package_json#resolutions)
99118
- [Dependabot 配置选项](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file)
100119

120+
## 快速切换工具
121+
122+
我们提供了一个脚本来快速切换 Dependabot 配置:
123+
124+
```bash
125+
# 查看当前状态
126+
./scripts/switch-dependabot-config.sh
127+
128+
# 切换到严格模式(如果仍有问题)
129+
./scripts/switch-dependabot-config.sh alternative
130+
131+
# 恢复原始配置
132+
./scripts/switch-dependabot-config.sh restore
133+
```
134+
101135
## 总结
102136

103-
通过使用 `resolutions` 替代 `pnpm.overrides`,我们成功解决了 Dependabot 的兼容性问题,同时保持了对传递依赖的控制能力。这种方法既解决了安全漏洞,又避免了 Dependabot 的限制。
137+
通过以下多层解决方案,我们彻底解决了 Dependabot 的 pnpm 兼容性问题:
138+
139+
1. **限制更新范围**:只更新直接依赖
140+
2. **使用标准配置**:`resolutions` 替代 `pnpm.overrides`
141+
3. **提供备选方案**:严格模式配置
142+
4. **工具支持**:配置切换脚本
143+
144+
这种方法既解决了安全漏洞,又避免了 Dependabot 的限制,同时提供了灵活的配置选项。

.github/dependabot-alternative.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# 备选 Dependabot 配置 - 如果主配置仍有问题,可以替换 dependabot.yml
2+
version: 2
3+
updates:
4+
# npm 依赖更新 - 仅直接依赖
5+
- package-ecosystem: "npm"
6+
directory: "/"
7+
schedule:
8+
interval: "weekly"
9+
day: "monday"
10+
time: "09:00"
11+
open-pull-requests-limit: 5
12+
reviewers:
13+
- "winjs-dev"
14+
assignees:
15+
- "winjs-dev"
16+
commit-message:
17+
prefix: "chore"
18+
include: "scope"
19+
# 严格限制:只更新直接依赖
20+
allow:
21+
- dependency-type: "direct"
22+
# 完全忽略所有传递依赖相关的包
23+
ignore:
24+
- dependency-name: "esbuild"
25+
- dependency-name: "@esbuild/*"
26+
- dependency-name: "*"
27+
update-types: ["version-update:semver-major"]
28+
dependency-type: "indirect"
29+
30+
# GitHub Actions 更新
31+
- package-ecosystem: "github-actions"
32+
directory: "/"
33+
schedule:
34+
interval: "weekly"
35+
day: "monday"
36+
time: "09:00"
37+
open-pull-requests-limit: 3
38+
reviewers:
39+
- "winjs-dev"
40+
assignees:
41+
- "winjs-dev"
42+
commit-message:
43+
prefix: "ci"
44+
include: "scope"

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ updates:
1515
commit-message:
1616
prefix: "chore"
1717
include: "scope"
18+
# 只更新直接依赖,避免 pnpm 传递依赖更新的兼容性问题
19+
allow:
20+
- dependency-type: "direct"
1821
# 忽略 esbuild,因为我们使用 resolutions 管理传递依赖
1922
ignore:
2023
- dependency-name: "esbuild"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
# Dependabot 配置切换脚本
4+
# 用法: ./scripts/switch-dependabot-config.sh [alternative]
5+
6+
set -e
7+
8+
GITHUB_DIR=".github"
9+
CURRENT_CONFIG="$GITHUB_DIR/dependabot.yml"
10+
ALTERNATIVE_CONFIG="$GITHUB_DIR/dependabot-alternative.yml"
11+
BACKUP_CONFIG="$GITHUB_DIR/dependabot.yml.backup"
12+
13+
if [ "$1" = "alternative" ]; then
14+
echo "🔄 切换到备选 Dependabot 配置..."
15+
16+
# 备份当前配置
17+
if [ -f "$CURRENT_CONFIG" ]; then
18+
cp "$CURRENT_CONFIG" "$BACKUP_CONFIG"
19+
echo "✅ 已备份当前配置到 $BACKUP_CONFIG"
20+
fi
21+
22+
# 使用备选配置
23+
if [ -f "$ALTERNATIVE_CONFIG" ]; then
24+
cp "$ALTERNATIVE_CONFIG" "$CURRENT_CONFIG"
25+
echo "✅ 已切换到备选配置"
26+
echo "📝 备选配置特点:"
27+
echo " - 只更新直接依赖"
28+
echo " - 严格忽略传递依赖"
29+
echo " - 减少 PR 数量"
30+
else
31+
echo "❌ 备选配置文件不存在: $ALTERNATIVE_CONFIG"
32+
exit 1
33+
fi
34+
35+
elif [ "$1" = "restore" ]; then
36+
echo "🔄 恢复原始 Dependabot 配置..."
37+
38+
if [ -f "$BACKUP_CONFIG" ]; then
39+
cp "$BACKUP_CONFIG" "$CURRENT_CONFIG"
40+
echo "✅ 已恢复原始配置"
41+
rm "$BACKUP_CONFIG"
42+
echo "🗑️ 已删除备份文件"
43+
else
44+
echo "❌ 备份文件不存在: $BACKUP_CONFIG"
45+
exit 1
46+
fi
47+
48+
else
49+
echo "📋 Dependabot 配置管理脚本"
50+
echo ""
51+
echo "用法:"
52+
echo " $0 alternative # 切换到备选配置(严格模式)"
53+
echo " $0 restore # 恢复原始配置"
54+
echo ""
55+
echo "当前配置状态:"
56+
if [ -f "$CURRENT_CONFIG" ]; then
57+
echo "✅ 当前配置: $CURRENT_CONFIG"
58+
if grep -q "dependency-type.*direct" "$CURRENT_CONFIG"; then
59+
echo "🔒 模式: 限制直接依赖"
60+
else
61+
echo "🌐 模式: 标准模式"
62+
fi
63+
else
64+
echo "❌ 配置文件不存在"
65+
fi
66+
67+
if [ -f "$BACKUP_CONFIG" ]; then
68+
echo "💾 备份存在: $BACKUP_CONFIG"
69+
fi
70+
71+
if [ -f "$ALTERNATIVE_CONFIG" ]; then
72+
echo "🔄 备选配置可用: $ALTERNATIVE_CONFIG"
73+
fi
74+
fi

0 commit comments

Comments
 (0)