@@ -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对于需要强制更新的传递依赖:
44591. 使用 `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 的限制,同时提供了灵活的配置选项。
0 commit comments