File tree Expand file tree Collapse file tree 4 files changed +117
-12
lines changed
Expand file tree Collapse file tree 4 files changed +117
-12
lines changed Original file line number Diff line number Diff line change 1+ # Dependabot pnpm 限制解决方案
2+
3+ ## 问题描述
4+
5+ Dependabot 报告了以下错误:
6+ ```
7+ Dependabot doesn't support the 'updating transitive dependencies' feature for pnpm package_manager
8+ ```
9+
10+ 这是因为 Dependabot 对 pnpm 包管理器的某些高级功能支持有限,特别是更新传递依赖的功能。
11+
12+ ## 解决方案
13+
14+ ### 1. 使用 ` resolutions ` 替代 ` pnpm.overrides `
15+
16+ 我们将配置从 ` pnpm.overrides ` 改为 ` resolutions ` :
17+
18+ ``` json
19+ {
20+ "resolutions" : {
21+ "esbuild" : " ^0.25.0"
22+ }
23+ }
24+ ```
25+
26+ ** 优势** :
27+ - ` resolutions ` 是更通用的标准
28+ - 被多个包管理器支持(yarn, pnpm)
29+ - Dependabot 兼容性更好
30+
31+ ### 2. 配置 Dependabot 忽略规则
32+
33+ 在 ` .github/dependabot.yml ` 中添加忽略规则:
34+
35+ ``` yaml
36+ ignore :
37+ - dependency-name : " esbuild"
38+ update-types : ["version-update:semver-major", "version-update:semver-minor", "version-update:semver-patch"]
39+ ` ` `
40+
41+ ### 3. 手动管理传递依赖
42+
43+ 对于需要强制更新的传递依赖:
44+ 1. 使用 ` resolutions` 指定版本
45+ 2. 在 Dependabot 中忽略该依赖
46+ 3. 定期手动检查和更新
47+
48+ # # 验证步骤
49+
50+ 1. **检查依赖版本**:
51+ ` ` ` bash
52+ pnpm ls --depth=10 | grep esbuild
53+ ` ` `
54+
55+ 2. **验证构建**:
56+ ` ` ` bash
57+ pnpm run build
58+ ` ` `
59+
60+ 3. **运行测试**:
61+ ` ` ` bash
62+ pnpm test
63+ ` ` `
64+
65+ # # 监控和维护
66+
67+ # ## 定期检查
68+ - 每月检查上游依赖(如 `@rslib/core`)的更新
69+ - 关注安全公告和漏洞报告
70+ - 验证强制版本是否仍然必要
71+
72+ # ## 清理时机
73+ 当上游依赖更新到安全版本时:
74+ 1. 移除 `resolutions` 中的对应条目
75+ 2. 移除 Dependabot 忽略规则
76+ 3. 重新安装依赖验证
77+
78+ # # 替代方案
79+
80+ # ## 方案 A:切换到 npm/yarn
81+ 如果 pnpm 限制影响较大,可以考虑:
82+ - 使用 npm 或 yarn 作为包管理器
83+ - 更新 GitHub Actions 工作流
84+ - 更新开发文档
85+
86+ # ## 方案 B:禁用 Dependabot 的传递依赖更新
87+ 在 `dependabot.yml` 中添加:
88+ ` ` ` yaml
89+ - package-ecosystem: "npm"
90+ # ... 其他配置
91+ allow:
92+ - dependency-type: "direct" # 只更新直接依赖
93+ ` ` `
94+
95+ # # 相关资源
96+
97+ - [Dependabot pnpm 支持状态](https://github.com/dependabot/dependabot-core/issues/1736)
98+ - [pnpm resolutions 文档](https://pnpm.io/package_json#resolutions)
99+ - [Dependabot 配置选项](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file)
100+
101+ # # 总结
102+
103+ 通过使用 `resolutions` 替代 `pnpm.overrides`,我们成功解决了 Dependabot 的兼容性问题,同时保持了对传递依赖的控制能力。这种方法既解决了安全漏洞,又避免了 Dependabot 的限制。
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ updates:
1515 commit-message :
1616 prefix : " chore"
1717 include : " scope"
18- # 忽略 esbuild,因为我们使用 pnpm overrides 管理
18+ # 忽略 esbuild,因为我们使用 resolutions 管理传递依赖
1919 ignore :
2020 - dependency-name : " esbuild"
2121 update-types : ["version-update:semver-major", "version-update:semver-minor", "version-update:semver-patch"]
Original file line number Diff line number Diff line change @@ -10,22 +10,25 @@ Dependabot 报告了 esbuild 的安全漏洞:
1010
1111### 解决方案
1212
13- 由于 ` @rslib/core ` 依赖的 esbuild 版本较旧,我们使用 pnpm overrides 强制更新到安全版本 。
13+ 由于 ` @rslib/core ` 依赖的 esbuild 版本较旧,我们使用 ` resolutions ` 强制更新传递依赖到安全版本 。
1414
1515#### 配置详情
1616
1717在 ` package.json ` 中添加了以下配置:
1818
1919``` json
2020{
21- "pnpm" : {
22- "overrides" : {
23- "esbuild" : " ^0.25.0"
24- }
21+ "resolutions" : {
22+ "esbuild" : " ^0.25.0"
2523 }
2624}
2725```
2826
27+ ** 注意** :我们选择使用 ` resolutions ` 而不是 ` pnpm.overrides ` ,因为:
28+ 1 . ` resolutions ` 是更通用的标准,被多个包管理器支持
29+ 2 . Dependabot 对 pnpm 的 overrides 功能支持有限
30+ 3 . 避免了 "updating transitive dependencies" 的兼容性问题
31+
2932#### Dependabot 配置
3033
3134在 ` .github/dependabot.yml ` 中忽略 esbuild 的自动更新,因为我们手动管理:
@@ -45,7 +48,7 @@ ignore:
4548
4649### 维护
4750
48- 当 ` @rslib/core` 更新其 esbuild 依赖到安全版本时,可以移除 pnpm overrides 配置。
51+ 当 ` @rslib/core` 更新其 esbuild 依赖到安全版本时,可以移除 resolutions 配置。
4952
5053定期检查:
51541. `@rslib/core` 的更新日志
@@ -55,5 +58,6 @@ ignore:
5558# ## 相关链接
5659
5760- [esbuild 安全公告](https://github.com/evanw/esbuild/security/advisories)
58- - [pnpm overrides 文档](https://pnpm.io/package_json#pnpmoverrides)
61+ - [Package.json resolutions 文档](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/)
62+ - [pnpm resolutions 支持](https://pnpm.io/package_json#resolutions)
5963- [Dependabot 配置文档](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file)
Original file line number Diff line number Diff line change 7979 "registry" : " https://registry.npmjs.org" ,
8080 "access" : " public"
8181 },
82- "pnpm" : {
83- "overrides" : {
84- "esbuild" : " ^0.25.0"
85- }
82+ "resolutions" : {
83+ "esbuild" : " ^0.25.0"
8684 },
8785 "license" : " MIT"
8886}
You can’t perform that action at this time.
0 commit comments