dependfix 0.1.0 → 0.2.0
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 +1 -1
- package/dist/bin.d.mts +1 -1
- package/dist/bin.mjs +2 -3
- package/dist/bin.mjs.map +1 -1
- package/dist/index.d.mts +818 -27
- package/dist/index.mjs +3 -4
- package/dist/index.mjs.map +1 -1
- package/dist/runner.mjs +7402 -0
- package/dist/runner.mjs.map +1 -0
- package/package.json +17 -15
- package/dist/bin.cjs +0 -14
- package/dist/bin.cjs.map +0 -1
- package/dist/bin.d.cts +0 -1
- package/dist/cli.cjs +0 -2812
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.mjs +0 -2530
- package/dist/cli.mjs.map +0 -1
- package/dist/index.cjs +0 -76
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -672
package/dist/index.d.cts
DELETED
|
@@ -1,672 +0,0 @@
|
|
|
1
|
-
import * as citty from "citty";
|
|
2
|
-
import { AppError, FixAction, NormalizedSecurityAlert, RunResult, SeverityThreshold } from "@dependfix/core";
|
|
3
|
-
import { Octokit } from "@octokit/rest";
|
|
4
|
-
export * from "@dependfix/core";
|
|
5
|
-
|
|
6
|
-
//#region src/config/index.d.ts
|
|
7
|
-
declare const RUNTIME_MODES: readonly ["report-only", "fix", "fix-and-pr", "cleanup-branches"];
|
|
8
|
-
declare const SEVERITY_THRESHOLDS: readonly ["critical", "high", "medium", "all"];
|
|
9
|
-
type RuntimeMode = typeof RUNTIME_MODES[number];
|
|
10
|
-
interface RuntimeConfig {
|
|
11
|
-
mode: RuntimeMode;
|
|
12
|
-
severityThreshold: SeverityThreshold;
|
|
13
|
-
repositories: string[];
|
|
14
|
-
dryRun: boolean;
|
|
15
|
-
createPullRequest: boolean;
|
|
16
|
-
/** 修复完成后是否在本地当前分支直接提交(不推送、不创建 PR) */
|
|
17
|
-
commit: boolean;
|
|
18
|
-
/** fix-and-pr 模式下结束后是否列出已合并的 dependfix 分支到报告(不自动删除) */
|
|
19
|
-
cleanupBranches: boolean;
|
|
20
|
-
githubToken: string;
|
|
21
|
-
maxAlertsPerRepository: number;
|
|
22
|
-
}
|
|
23
|
-
interface CliConfigOverrides {
|
|
24
|
-
mode?: RuntimeMode;
|
|
25
|
-
severityThreshold?: SeverityThreshold;
|
|
26
|
-
repositories?: string[];
|
|
27
|
-
reposFilePath?: string;
|
|
28
|
-
dryRun?: boolean;
|
|
29
|
-
createPullRequest?: boolean;
|
|
30
|
-
/** 修复完成后是否在本地当前分支直接提交 */
|
|
31
|
-
commit?: boolean;
|
|
32
|
-
/** fix-and-pr 模式下结束后是否列出已合并的 dependfix 分支到报告 */
|
|
33
|
-
cleanupBranches?: boolean;
|
|
34
|
-
githubToken?: string;
|
|
35
|
-
maxAlertsPerRepository?: number;
|
|
36
|
-
/** 是否输出详细日志 */
|
|
37
|
-
verbose?: boolean;
|
|
38
|
-
/** 自定义验证命令(覆盖默认的 `pnpm install --frozen-lockfile` / `pnpm lint` / `pnpm build`) */
|
|
39
|
-
commands?: string[];
|
|
40
|
-
}
|
|
41
|
-
interface ResolveRuntimeConfigOptions {
|
|
42
|
-
env?: NodeJS.ProcessEnv;
|
|
43
|
-
cliOverrides?: CliConfigOverrides;
|
|
44
|
-
/** 工作目录,用于从 git remote 推断仓库名(默认 `process.cwd()`) */
|
|
45
|
-
workDir?: string;
|
|
46
|
-
}
|
|
47
|
-
declare const DEFAULT_RUNTIME_CONFIG: Omit<RuntimeConfig, 'githubToken' | 'repositories' | 'dryRun' | 'createPullRequest' | 'commit' | 'cleanupBranches'>;
|
|
48
|
-
declare function readEnvConfig(env?: NodeJS.ProcessEnv): CliConfigOverrides;
|
|
49
|
-
declare function resolveRuntimeConfig(options?: ResolveRuntimeConfigOptions): RuntimeConfig;
|
|
50
|
-
/**
|
|
51
|
-
* 从 git remote origin 推断 owner/repo。
|
|
52
|
-
*
|
|
53
|
-
* 支持格式:
|
|
54
|
-
* - `https://github.com/owner/repo.git`
|
|
55
|
-
* - `git@github.com:owner/repo.git`
|
|
56
|
-
* - `ssh://git@github.com/owner/repo.git`
|
|
57
|
-
*
|
|
58
|
-
* @returns `owner/repo` 或 `null`(非 GitHub / 无 origin)
|
|
59
|
-
*/
|
|
60
|
-
declare function inferRepoFromGitRemote(workDir: string): string | null;
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/cli/index.d.ts
|
|
63
|
-
interface CliInvocation {
|
|
64
|
-
mode?: RuntimeMode;
|
|
65
|
-
configOverrides: CliConfigOverrides;
|
|
66
|
-
rawArgs: string[];
|
|
67
|
-
}
|
|
68
|
-
interface CliRunResult {
|
|
69
|
-
ok: true;
|
|
70
|
-
invocation: CliInvocation;
|
|
71
|
-
config: ReturnType<typeof resolveRuntimeConfig>;
|
|
72
|
-
}
|
|
73
|
-
declare function parseCliArgs(rawArgs: string[]): CliInvocation;
|
|
74
|
-
declare function runCli(rawArgs: string[]): CliRunResult;
|
|
75
|
-
declare const dependfixCommand: citty.CommandDef<{
|
|
76
|
-
mode: {
|
|
77
|
-
type: "positional";
|
|
78
|
-
description: string;
|
|
79
|
-
required: false;
|
|
80
|
-
default: "report-only";
|
|
81
|
-
};
|
|
82
|
-
repo: {
|
|
83
|
-
type: "string";
|
|
84
|
-
description: string;
|
|
85
|
-
alias: string[];
|
|
86
|
-
};
|
|
87
|
-
'repos-file': {
|
|
88
|
-
type: "string";
|
|
89
|
-
description: string;
|
|
90
|
-
};
|
|
91
|
-
'severity-threshold': {
|
|
92
|
-
type: "string";
|
|
93
|
-
description: string;
|
|
94
|
-
default: "high";
|
|
95
|
-
};
|
|
96
|
-
'dry-run': {
|
|
97
|
-
type: "boolean";
|
|
98
|
-
description: string;
|
|
99
|
-
negativeDescription: string;
|
|
100
|
-
};
|
|
101
|
-
'create-pr': {
|
|
102
|
-
type: "boolean";
|
|
103
|
-
description: string;
|
|
104
|
-
negativeDescription: string;
|
|
105
|
-
};
|
|
106
|
-
commit: {
|
|
107
|
-
type: "boolean";
|
|
108
|
-
description: string;
|
|
109
|
-
negativeDescription: string;
|
|
110
|
-
};
|
|
111
|
-
'cleanup-branches': {
|
|
112
|
-
type: "boolean";
|
|
113
|
-
description: string;
|
|
114
|
-
negativeDescription: string;
|
|
115
|
-
};
|
|
116
|
-
'github-token': {
|
|
117
|
-
type: "string";
|
|
118
|
-
description: string;
|
|
119
|
-
};
|
|
120
|
-
'max-alerts-per-repository': {
|
|
121
|
-
type: "string";
|
|
122
|
-
description: string;
|
|
123
|
-
default: "10";
|
|
124
|
-
};
|
|
125
|
-
commands: {
|
|
126
|
-
type: "string";
|
|
127
|
-
description: string;
|
|
128
|
-
};
|
|
129
|
-
verbose: {
|
|
130
|
-
type: "boolean";
|
|
131
|
-
description: string;
|
|
132
|
-
};
|
|
133
|
-
}>;
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/app.d.ts
|
|
136
|
-
interface DependfixAppOptions {
|
|
137
|
-
/** 已解析的运行时配置 */
|
|
138
|
-
config: RuntimeConfig;
|
|
139
|
-
/** 工作目录(默认 `process.cwd()`) */
|
|
140
|
-
workDir?: string;
|
|
141
|
-
/** 是否输出详细日志 */
|
|
142
|
-
verbose?: boolean;
|
|
143
|
-
/** 自定义验证命令(覆盖默认命令链) */
|
|
144
|
-
commands?: string[];
|
|
145
|
-
}
|
|
146
|
-
interface DependfixRunResult {
|
|
147
|
-
/** 结构化运行结果(用于报告生成) */
|
|
148
|
-
result: RunResult;
|
|
149
|
-
/** 进程退出码:0=全部成功, 1=部分失败, 2=全部失败 */
|
|
150
|
-
exitCode: number;
|
|
151
|
-
}
|
|
152
|
-
declare class DependfixApp {
|
|
153
|
-
private readonly config;
|
|
154
|
-
private readonly workDir;
|
|
155
|
-
private readonly logger;
|
|
156
|
-
private readonly verbose;
|
|
157
|
-
private readonly customCommands?;
|
|
158
|
-
private readonly runId;
|
|
159
|
-
private readonly allAlerts;
|
|
160
|
-
private readonly allActions;
|
|
161
|
-
private readonly allErrors;
|
|
162
|
-
private readonly repoResults;
|
|
163
|
-
private readonly summary;
|
|
164
|
-
private startedAt;
|
|
165
|
-
private finishedAt;
|
|
166
|
-
constructor(options: DependfixAppOptions);
|
|
167
|
-
/** 供辅助方法使用的状态切片。 */
|
|
168
|
-
private get ctx();
|
|
169
|
-
/** 执行完整的编排流程,返回结构化结果和退出码。 */
|
|
170
|
-
run(): Promise<DependfixRunResult>;
|
|
171
|
-
private executeMode;
|
|
172
|
-
private executeReportMode;
|
|
173
|
-
private processRepoForReport;
|
|
174
|
-
private executeFixMode;
|
|
175
|
-
private processRepoForFix;
|
|
176
|
-
/**
|
|
177
|
-
* 修复 → 计算内容指纹 → 查重 →(同指纹跳过 / 异指纹关旧开新)。
|
|
178
|
-
*
|
|
179
|
-
* 去重语义(T210):
|
|
180
|
-
* - 同告警集 → 同修复结果 → 同指纹 → 跳过,不重复提交相同 PR
|
|
181
|
-
* - 内容变化 → 先创建新 PR(body 注明 Supersedes),成功后关闭旧 PR;
|
|
182
|
-
* 新 PR 创建失败时保留旧 PR,避免出现"无 PR 窗口"
|
|
183
|
-
*/
|
|
184
|
-
private executeFixAndPrMode;
|
|
185
|
-
/**
|
|
186
|
-
* 清理已合并(或已关闭)的 dependfix 分支。
|
|
187
|
-
*
|
|
188
|
-
* - 分类:已合并(安全清理)/ 已关闭未合并(supersede 孤儿)/ open(跳过)
|
|
189
|
-
* - 删除前必须交互式确认(y/N);非 TTY 环境(CI)默认拒绝
|
|
190
|
-
* - 只删 `dependfix/` 前缀分支,绝不触碰 open PR 对应分支
|
|
191
|
-
* - dry-run 模式仅列清单并打印 "would delete",不执行删除
|
|
192
|
-
*/
|
|
193
|
-
private executeCleanupBranchesMode;
|
|
194
|
-
private createClient;
|
|
195
|
-
/**
|
|
196
|
-
* 获取仓库的默认分支。
|
|
197
|
-
* 失败时返回 `'unknown'`(不阻塞主流程)。
|
|
198
|
-
*/
|
|
199
|
-
private fetchDefaultBranch;
|
|
200
|
-
}
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region src/fixers/dependency/index.d.ts
|
|
203
|
-
interface UpgradeDependencyParams {
|
|
204
|
-
/** 包名(如 `'lodash'`, `'@babel/traverse'`) */
|
|
205
|
-
packageName: string;
|
|
206
|
-
/** 目标精确版本(如 `'4.17.21'`) */
|
|
207
|
-
targetVersion: string;
|
|
208
|
-
/** 工作目录(包含 `package.json` 和 `pnpm-lock.yaml`) */
|
|
209
|
-
workDir: string;
|
|
210
|
-
}
|
|
211
|
-
interface DependencyFixResult {
|
|
212
|
-
packageName: string;
|
|
213
|
-
/** 升级前版本声明(保留原始 range 格式,如 `^4.17.20`) */
|
|
214
|
-
fromVersion: string;
|
|
215
|
-
/** 升级后版本声明(保留原始前缀,如 `^4.17.21`) */
|
|
216
|
-
toVersion: string;
|
|
217
|
-
/** 是否为 major 版本升级 */
|
|
218
|
-
isMajor: boolean;
|
|
219
|
-
/** 升级是否成功 */
|
|
220
|
-
success: boolean;
|
|
221
|
-
/** 失败原因(仅 `success=false` 时有值) */
|
|
222
|
-
error?: string;
|
|
223
|
-
}
|
|
224
|
-
interface PackageJson {
|
|
225
|
-
name?: string;
|
|
226
|
-
dependencies?: Record<string, string>;
|
|
227
|
-
devDependencies?: Record<string, string>;
|
|
228
|
-
optionalDependencies?: Record<string, string>;
|
|
229
|
-
peerDependencies?: Record<string, string>;
|
|
230
|
-
pnpm?: {
|
|
231
|
-
overrides?: Record<string, string>;
|
|
232
|
-
[key: string]: unknown;
|
|
233
|
-
};
|
|
234
|
-
[key: string]: unknown;
|
|
235
|
-
}
|
|
236
|
-
interface DependencyInfo {
|
|
237
|
-
group: 'dependencies' | 'devDependencies' | 'optionalDependencies';
|
|
238
|
-
version: string;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* 升级单个依赖到指定版本。
|
|
242
|
-
*
|
|
243
|
-
* - 在 `workDir` 中查找 `package.json` 并修改目标包的版本声明(保留原始前缀)
|
|
244
|
-
* - 执行 `pnpm install --no-frozen-lockfile` 更新 lockfile
|
|
245
|
-
* - 失败时自动回滚 `package.json` 和 `pnpm-lock.yaml`
|
|
246
|
-
* - 不执行验证(由 T107 负责)
|
|
247
|
-
*
|
|
248
|
-
* @param params - 包名、目标版本、工作目录
|
|
249
|
-
* @returns 修复结果
|
|
250
|
-
*/
|
|
251
|
-
declare function upgradeDependency(params: UpgradeDependencyParams): Promise<DependencyFixResult>;
|
|
252
|
-
/**
|
|
253
|
-
* 通过 pnpm `overrides` 升级间接(transitive)依赖。
|
|
254
|
-
*
|
|
255
|
-
* 间接依赖不在 `package.json` 的 `dependencies` / `devDependencies` 中列出,
|
|
256
|
-
* 因此无法通过常规 `upgradeDependency` 处理。本函数根据项目类型选择覆盖写入位置:
|
|
257
|
-
*
|
|
258
|
-
* - **有 `pnpm-workspace.yaml`**(monorepo / workspace)→ 写入其中的 `overrides` 字段(pnpm v10+ 推荐)
|
|
259
|
-
* - **无 `pnpm-workspace.yaml`**(单包项目)→ 写入 `package.json` 的 `pnpm.overrides`
|
|
260
|
-
*
|
|
261
|
-
* 失败时自动回滚被修改的文件和 `pnpm-lock.yaml`。不执行验证(由 T107 负责)。
|
|
262
|
-
*
|
|
263
|
-
* @param params - 包名、目标版本、工作目录
|
|
264
|
-
* @returns 修复结果
|
|
265
|
-
*/
|
|
266
|
-
declare function overrideTransitiveDependency(params: UpgradeDependencyParams): Promise<DependencyFixResult>;
|
|
267
|
-
/**
|
|
268
|
-
* 从版本声明中提取前缀(^ / ~ / 空)。
|
|
269
|
-
*
|
|
270
|
-
* @example
|
|
271
|
-
* extractPrefix('^4.17.20') // '^'
|
|
272
|
-
* extractPrefix('~4.17.0') // '~'
|
|
273
|
-
* extractPrefix('4.17.20') // ''
|
|
274
|
-
* extractPrefix('*') // '^' (默认)
|
|
275
|
-
*/
|
|
276
|
-
declare function extractPrefix(version: string): string;
|
|
277
|
-
/**
|
|
278
|
-
* 从版本声明中提取主版本号(major)。
|
|
279
|
-
* 去除前缀后匹配第一个 semver 段。
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* parseMajorVersion('^4.17.20') // 4
|
|
283
|
-
* parseMajorVersion('~2.0.0') // 2
|
|
284
|
-
* parseMajorVersion('1.2.3') // 1
|
|
285
|
-
* parseMajorVersion('*') // -1
|
|
286
|
-
*/
|
|
287
|
-
declare function parseMajorVersion(version: string): number;
|
|
288
|
-
/**
|
|
289
|
-
* 在 `package.json` 的 `dependencies` / `devDependencies` / `optionalDependencies` 中按顺序查找包。
|
|
290
|
-
*/
|
|
291
|
-
declare function findDependencyVersion(pkg: PackageJson, packageName: string): DependencyInfo | null;
|
|
292
|
-
/**
|
|
293
|
-
* 确保 `package.json` 中存在 `pnpm.overrides` 对象,若不存在则创建。
|
|
294
|
-
* 返回 `overrides` 对象的引用,调用方可直接写入。
|
|
295
|
-
*/
|
|
296
|
-
declare function ensurePnpmOverrides(pkg: PackageJson): Record<string, string>;
|
|
297
|
-
/**
|
|
298
|
-
* 从 `pnpm-lock.yaml` 中读取指定包的当前锁定版本。
|
|
299
|
-
* 通过简单的正则匹配查找,不解析完整 YAML(性能优先)。
|
|
300
|
-
*
|
|
301
|
-
* pnpm v9+ lockfile 格式(v9.0 起):
|
|
302
|
-
* /package-name/version:
|
|
303
|
-
* /@scope/package-name/version:
|
|
304
|
-
*
|
|
305
|
-
* @returns 锁定版本字符串(如 `'5.0.0'`),未找到返回 `null`
|
|
306
|
-
*/
|
|
307
|
-
declare function readLockfileVersion(lockfilePath: string, packageName: string): string | null;
|
|
308
|
-
//#endregion
|
|
309
|
-
//#region src/fixers/pnpm/index.d.ts
|
|
310
|
-
type LockfileFailureCategory = 'LOCKFILE_NOT_FOUND' | 'MANIFEST_MISMATCH' | 'LOCKFILE_VERSION_MISMATCH' | 'CORRUPTED_LOCKFILE' | 'CREDENTIAL_ERROR' | 'RESOLVE_ERROR' | 'UNKNOWN';
|
|
311
|
-
type RepairStrategy = 'REGENERATE' | 'FIX_ENTRIES' | 'PIN_TOOLCHAIN' | 'REINSTALL' | 'SKIP';
|
|
312
|
-
interface RepairLockfileParams {
|
|
313
|
-
/** 工作目录(必须包含 package.json 和 pnpm-lock.yaml) */
|
|
314
|
-
workDir: string;
|
|
315
|
-
/** 可选:期望的 pnpm 版本(优先于 packageManager 字段) */
|
|
316
|
-
toolchain?: {
|
|
317
|
-
pnpmVersion?: string;
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
interface LockfileDiff {
|
|
321
|
-
/** lockfile 行数变化(正=增加) */
|
|
322
|
-
linesChanged: number;
|
|
323
|
-
/** packages 条数变化(正=增加) */
|
|
324
|
-
packagesChanged: number;
|
|
325
|
-
/** 简要文字摘要 */
|
|
326
|
-
summary: string;
|
|
327
|
-
}
|
|
328
|
-
interface RepairAttempt {
|
|
329
|
-
strategy: RepairStrategy;
|
|
330
|
-
command: string;
|
|
331
|
-
success: boolean;
|
|
332
|
-
error?: string;
|
|
333
|
-
durationMs: number;
|
|
334
|
-
}
|
|
335
|
-
interface LockfileRepairResult {
|
|
336
|
-
success: boolean;
|
|
337
|
-
failureCategory?: LockfileFailureCategory;
|
|
338
|
-
failureDetail?: string;
|
|
339
|
-
strategy?: RepairStrategy;
|
|
340
|
-
diff?: LockfileDiff | null;
|
|
341
|
-
attemptHistory: RepairAttempt[];
|
|
342
|
-
}
|
|
343
|
-
interface ClassificationResult {
|
|
344
|
-
ok: boolean;
|
|
345
|
-
category?: LockfileFailureCategory;
|
|
346
|
-
stderr?: string;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* 执行 `pnpm i --frozen-lockfile` 并解析失败分类。
|
|
350
|
-
* 成功时返回 { ok: true }。
|
|
351
|
-
*/
|
|
352
|
-
declare function classifyLockfileFailure(workDir: string): ClassificationResult;
|
|
353
|
-
/**
|
|
354
|
-
* 比较修复前后 lockfile,返回行数与包数量变化摘要。
|
|
355
|
-
*/
|
|
356
|
-
declare function computeLockfileDiff(beforePath: string, afterPath: string): LockfileDiff;
|
|
357
|
-
/**
|
|
358
|
-
* 从 package.json 的 `packageManager` 字段解析 pnpm 版本。
|
|
359
|
-
* 优先级: toolchain.pnpmVersion > packageManager > null
|
|
360
|
-
*/
|
|
361
|
-
declare function resolvePnpmVersion(workDir: string, toolchain?: {
|
|
362
|
-
pnpmVersion?: string;
|
|
363
|
-
}): string | null;
|
|
364
|
-
/**
|
|
365
|
-
* 检测并修复 pnpm frozen-lockfile 漂移。
|
|
366
|
-
*
|
|
367
|
-
* 流程:
|
|
368
|
-
* 1. 先跑 `pnpm i --frozen-lockfile` 诊断
|
|
369
|
-
* 2. 若已合规 → 直接返回 success
|
|
370
|
-
* 3. 若为 CREDENTIAL_ERROR → SKIP
|
|
371
|
-
* 4. 按分类选取策略链,逐级尝试修复:
|
|
372
|
-
* - 每个策略执行后立即用 `pnpm i --frozen-lockfile` 验证
|
|
373
|
-
* - 验证通过 → 记录 diff、返回 success
|
|
374
|
-
* - 验证失败 → 继续下一个策略
|
|
375
|
-
* 5. 所有策略失败 → 回滚 lockfile、返回失败结果
|
|
376
|
-
*/
|
|
377
|
-
declare function repairLockfile(params: RepairLockfileParams): LockfileRepairResult;
|
|
378
|
-
//#endregion
|
|
379
|
-
//#region src/github/client.d.ts
|
|
380
|
-
interface OctokitClientOptions {
|
|
381
|
-
/** GitHub Personal Access Token */
|
|
382
|
-
token: string;
|
|
383
|
-
/**
|
|
384
|
-
* API 基地址。
|
|
385
|
-
* 默认 `https://api.github.com`。
|
|
386
|
-
* 测试时指向 nock 拦截的同一地址。
|
|
387
|
-
*/
|
|
388
|
-
baseUrl?: string;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* 创建已认证的 Octokit 实例。
|
|
392
|
-
*
|
|
393
|
-
* 调用方直接使用 `octokit.rest.*` 访问所有已类型化的 GitHub REST API。
|
|
394
|
-
* 分页使用 `octokit.paginate()` 自动合并多页结果。
|
|
395
|
-
*
|
|
396
|
-
* @example
|
|
397
|
-
* ```typescript
|
|
398
|
-
* const octokit = createGitHubClient({ token: 'ghp_xxxx' })
|
|
399
|
-
*
|
|
400
|
-
* // 仓库信息
|
|
401
|
-
* const { data: repo } = await octokit.rest.repos.get({ owner: 'foo', repo: 'bar' })
|
|
402
|
-
*
|
|
403
|
-
* // Dependabot 告警(自动分页)
|
|
404
|
-
* const alerts = await octokit.paginate(
|
|
405
|
-
* octokit.rest.dependabot.listAlertsForRepo,
|
|
406
|
-
* { owner: 'foo', repo: 'bar', state: 'open', per_page: 100 },
|
|
407
|
-
* )
|
|
408
|
-
* ```
|
|
409
|
-
*/
|
|
410
|
-
declare function createGitHubClient(options: OctokitClientOptions): Octokit;
|
|
411
|
-
//#endregion
|
|
412
|
-
//#region src/github/dependabot-fetcher.d.ts
|
|
413
|
-
interface FetchDependabotAlertsParams {
|
|
414
|
-
/** 仓库所属组织或用户 */
|
|
415
|
-
owner: string;
|
|
416
|
-
/** 仓库名称 */
|
|
417
|
-
repo: string;
|
|
418
|
-
/**
|
|
419
|
-
* 告警状态过滤。
|
|
420
|
-
* M1 只拉 `open`(默认)。
|
|
421
|
-
*/
|
|
422
|
-
state?: 'open' | 'fixed' | 'dismissed' | 'auto_dismissed';
|
|
423
|
-
/** 每页数量,默认 100(GitHub API 最大值) */
|
|
424
|
-
perPage?: number;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* 拉取指定仓库的 Dependabot 告警并映射为标准化模型。
|
|
428
|
-
*
|
|
429
|
-
* - 自动分页(`octokit.paginate()`),返回所有匹配的告警
|
|
430
|
-
* - 仅处理 `state=open` 的告警(可通过 `params.state` 覆盖)
|
|
431
|
-
* - 异常通过 `mapGitHubError` 转为 `AppError`
|
|
432
|
-
* - 空仓库返回 `[]`,不抛异常
|
|
433
|
-
*
|
|
434
|
-
* @param client - 已认证的 Octokit 实例(来自 `createGitHubClient`)
|
|
435
|
-
* @param params - 仓库标识与过滤参数
|
|
436
|
-
* @returns 标准化告警列表
|
|
437
|
-
*
|
|
438
|
-
* @example
|
|
439
|
-
* ```typescript
|
|
440
|
-
* const octokit = createGitHubClient({ token: 'ghp_xxxx' })
|
|
441
|
-
* const alerts = await fetchDependabotAlerts(octokit, { owner: 'foo', repo: 'bar' })
|
|
442
|
-
* ```
|
|
443
|
-
*/
|
|
444
|
-
declare function fetchDependabotAlerts(client: Octokit, params: FetchDependabotAlertsParams): Promise<NormalizedSecurityAlert[]>;
|
|
445
|
-
//#endregion
|
|
446
|
-
//#region src/github/errors.d.ts
|
|
447
|
-
/**
|
|
448
|
-
* 将 Octokit 请求错误映射为 `AppError`。
|
|
449
|
-
*
|
|
450
|
-
* @param error - 原始错误(`RequestError` 或网络异常)
|
|
451
|
-
* @param context - 调用上下文描述(如 `'fetch repo info for foo/bar'`),会附加到错误消息中
|
|
452
|
-
*/
|
|
453
|
-
declare function mapGitHubError(error: unknown, context: string): AppError;
|
|
454
|
-
//#endregion
|
|
455
|
-
//#region src/github/pr-creator.d.ts
|
|
456
|
-
interface CreatePullRequestParams {
|
|
457
|
-
/** 已认证的 Octokit 实例 */
|
|
458
|
-
octokit: Octokit;
|
|
459
|
-
/** 仓库 owner */
|
|
460
|
-
owner: string;
|
|
461
|
-
/** 仓库名 */
|
|
462
|
-
repo: string;
|
|
463
|
-
/** 修复分支名 */
|
|
464
|
-
headBranch: string;
|
|
465
|
-
/** 目标分支(默认 master/main,从 API 获取) */
|
|
466
|
-
baseBranch: string;
|
|
467
|
-
/** PR 标题 */
|
|
468
|
-
title: string;
|
|
469
|
-
/** PR 内容(Markdown) */
|
|
470
|
-
body: string;
|
|
471
|
-
}
|
|
472
|
-
interface PullRequestResult {
|
|
473
|
-
/** PR 编号 */
|
|
474
|
-
number: number;
|
|
475
|
-
/** PR HTML URL */
|
|
476
|
-
htmlUrl: string;
|
|
477
|
-
}
|
|
478
|
-
interface FixBranchResult {
|
|
479
|
-
/** 分支名 */
|
|
480
|
-
branchName: string;
|
|
481
|
-
/** 是否为新创建 */
|
|
482
|
-
created: boolean;
|
|
483
|
-
}
|
|
484
|
-
/** dependfix 自动修复 PR 的公开信息(用于查重/取代判定) */
|
|
485
|
-
interface DependfixOpenPR {
|
|
486
|
-
/** PR 编号 */
|
|
487
|
-
number: number;
|
|
488
|
-
/** PR HTML URL */
|
|
489
|
-
htmlUrl: string;
|
|
490
|
-
/** PR head 分支名 */
|
|
491
|
-
headRef: string;
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* 计算修复内容指纹(sha256 前 8 位)。
|
|
495
|
-
*
|
|
496
|
-
* 指纹基于**结构化修复结果**而非 git diff:
|
|
497
|
-
* - 成功升级集:`pkg@toVersion`(排序拼接)
|
|
498
|
-
* - 修复失败集:失败包名(排序拼接)
|
|
499
|
-
* - lockfile 修复状态(成功/失败)
|
|
500
|
-
*
|
|
501
|
-
* 同告警集 → 同修复结果 → 同指纹 → 幂等跳过;
|
|
502
|
-
* 内容变化(升级集/失败集/锁文件修复变化)→ 指纹变化 → 关旧开新。
|
|
503
|
-
* 不用 diff hash 是因为 pnpm 版本等非确定性因素会使锁文件内容漂移,
|
|
504
|
-
* 导致"告警没变但指纹变"。
|
|
505
|
-
*/
|
|
506
|
-
declare function computeFixFingerprint(actions: FixAction[]): string;
|
|
507
|
-
/**
|
|
508
|
-
* 从分支名提取内容指纹(`dependfix/auto-fix-{fp8}` → `{fp8}`)。
|
|
509
|
-
* 指纹格式为 8 位 hex;分支名不含 `-` 后的内容、前缀不匹配或格式不合法时返回 null
|
|
510
|
-
* (如旧版 runId 分支,会被 supersede)。
|
|
511
|
-
*/
|
|
512
|
-
declare function extractFingerprintFromBranch(branchName: string): string | null;
|
|
513
|
-
/** fix-and-pr 去重决策结果 */
|
|
514
|
-
interface FixAndPrPlan {
|
|
515
|
-
/** skip = 已有同内容 PR,不重复提交;create = 需要新建 PR */
|
|
516
|
-
action: 'skip' | 'create';
|
|
517
|
-
/** action=skip 时命中的同内容 PR */
|
|
518
|
-
sameContentPR?: DependfixOpenPR;
|
|
519
|
-
/** 内容不同、需要关闭(supersede)的旧 PR 列表 */
|
|
520
|
-
supersedePRs: DependfixOpenPR[];
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* 计算 fix-and-pr 去重决策:
|
|
524
|
-
* - 存在同指纹 open PR → skip(仅需关闭其余异指纹 PR)
|
|
525
|
-
* - 否则 → create(关闭全部旧 PR,先建新后关旧由调用方保证)
|
|
526
|
-
*/
|
|
527
|
-
declare function computeFixAndPrPlan(existingPRs: DependfixOpenPR[], fingerprint: string): FixAndPrPlan;
|
|
528
|
-
/**
|
|
529
|
-
* 在工作目录创建修复分支。
|
|
530
|
-
*
|
|
531
|
-
* - 分支名由调用方传入(T210 起为 `dependfix/auto-fix-{内容指纹}`,不再依赖 runId)
|
|
532
|
-
* - 如果分支已存在(如重跑),切换到该分支
|
|
533
|
-
*
|
|
534
|
-
* @returns 分支名和是否为新创建
|
|
535
|
-
*/
|
|
536
|
-
declare function createFixBranch(branchName: string, workDir: string): FixBranchResult;
|
|
537
|
-
/**
|
|
538
|
-
* 暂存所有变更并提交。
|
|
539
|
-
* 自动设置 git user.name / user.email(如未设置)。
|
|
540
|
-
*/
|
|
541
|
-
declare function stageAndCommit(message: string, workDir: string): void;
|
|
542
|
-
/**
|
|
543
|
-
* 推送分支到远程 origin。
|
|
544
|
-
*/
|
|
545
|
-
declare function pushBranch(branchName: string, workDir: string): void;
|
|
546
|
-
/**
|
|
547
|
-
* 查找目标仓库中所有 open 状态的 dependfix 自动修复 PR。
|
|
548
|
-
*
|
|
549
|
-
* GitHub 的 `pulls.list` 的 `head` 参数不支持通配符,因此拉取 open PR 列表后
|
|
550
|
-
* 按 head 分支前缀 `dependfix/auto-fix-` 过滤。假设 PR 数量不多(单页 100 足够),
|
|
551
|
-
* 未来 PR 数量增大时可引入 label 索引(见 backlog B1)。
|
|
552
|
-
*/
|
|
553
|
-
declare function findDependfixOpenPR(octokit: Octokit, owner: string, repo: string): Promise<DependfixOpenPR[]>;
|
|
554
|
-
/**
|
|
555
|
-
* 关闭 Pull Request(用于 supersede 旧 PR)。
|
|
556
|
-
*/
|
|
557
|
-
declare function closePullRequest(octokit: Octokit, owner: string, repo: string, pullNumber: number): Promise<void>;
|
|
558
|
-
/**
|
|
559
|
-
* 通过 GitHub API 创建 Pull Request。
|
|
560
|
-
*/
|
|
561
|
-
declare function createPullRequest(params: CreatePullRequestParams): Promise<PullRequestResult>;
|
|
562
|
-
/** 分支清理状态(用于 cleanup-branches 清单分类) */
|
|
563
|
-
interface DependfixBranchStatus {
|
|
564
|
-
/** 分支名 */
|
|
565
|
-
branch: string;
|
|
566
|
-
/** 关联 PR 编号(无 PR 记录时为 null) */
|
|
567
|
-
prNumber: number | null;
|
|
568
|
-
/** PR 是否已合并 */
|
|
569
|
-
merged: boolean;
|
|
570
|
-
/** PR 是否已关闭(含合并) */
|
|
571
|
-
closed: boolean;
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* 列出远端所有 `dependfix/` 前缀分支(git.listMatchingRefs 精确前缀匹配)。
|
|
575
|
-
*/
|
|
576
|
-
declare function listDependfixBranches(octokit: Octokit, owner: string, repo: string): Promise<string[]>;
|
|
577
|
-
/**
|
|
578
|
-
* 查询分支对应的最近 PR 状态(pulls.list head 精确匹配,按最近更新取 1 条)。
|
|
579
|
-
*/
|
|
580
|
-
declare function getBranchPrStatus(octokit: Octokit, owner: string, repo: string, branch: string): Promise<DependfixBranchStatus>;
|
|
581
|
-
/**
|
|
582
|
-
* 删除远端分支(git ref delete)。失败(分支保护、不存在)由调用方捕获处理。
|
|
583
|
-
*/
|
|
584
|
-
declare function deleteRemoteBranch(octokit: Octokit, owner: string, repo: string, branch: string): Promise<void>;
|
|
585
|
-
/**
|
|
586
|
-
* 判定交互确认回答是否为"是"(y/yes,大小写不敏感;空输入默认拒绝)。
|
|
587
|
-
*/
|
|
588
|
-
declare function isConfirmAnswer(answer: string): boolean;
|
|
589
|
-
/**
|
|
590
|
-
* 从 RunResult 生成 PR body(Markdown)。
|
|
591
|
-
*
|
|
592
|
-
* @param supersededNumbers 被本 PR 取代并已关闭的旧 PR 编号列表(用于 Supersedes 声明)
|
|
593
|
-
*/
|
|
594
|
-
declare function generatePRBody(result: RunResult, supersededNumbers?: number[]): string;
|
|
595
|
-
//#endregion
|
|
596
|
-
//#region src/github/repo-selector.d.ts
|
|
597
|
-
/**
|
|
598
|
-
* 从文件读取仓库列表(每行一个 `owner/repo`)。
|
|
599
|
-
* 空行和 `#` 开头的注释行会被跳过。
|
|
600
|
-
*/
|
|
601
|
-
declare function readReposFile(filePath: string): string[];
|
|
602
|
-
/**
|
|
603
|
-
* 合并 CLI 传入仓库列表与文件中的仓库列表,去重并校验。
|
|
604
|
-
*/
|
|
605
|
-
declare function resolveRepoList(cliRepos: string[], reposFilePath?: string): string[];
|
|
606
|
-
//#endregion
|
|
607
|
-
//#region src/runners/verification-runner.d.ts
|
|
608
|
-
/**
|
|
609
|
-
* 单条命令的执行结果
|
|
610
|
-
*/
|
|
611
|
-
interface CommandResult {
|
|
612
|
-
/** 执行的命令文本 */
|
|
613
|
-
command: string;
|
|
614
|
-
/** 退出码(0 = 成功) */
|
|
615
|
-
exitCode: number;
|
|
616
|
-
/** 执行耗时(毫秒) */
|
|
617
|
-
durationMs: number;
|
|
618
|
-
/** stdout 摘要(截断到 200 行,已脱敏) */
|
|
619
|
-
stdout: string;
|
|
620
|
-
/** stderr 摘要(截断到 200 行,已脱敏) */
|
|
621
|
-
stderr: string;
|
|
622
|
-
}
|
|
623
|
-
/**
|
|
624
|
-
* 验证执行参数
|
|
625
|
-
*/
|
|
626
|
-
interface VerificationParams {
|
|
627
|
-
/** 工作目录 */
|
|
628
|
-
workDir: string;
|
|
629
|
-
/**
|
|
630
|
-
* 要执行的命令序列。
|
|
631
|
-
* 默认: `pnpm install --frozen-lockfile` → `pnpm lint` → `pnpm build`
|
|
632
|
-
*/
|
|
633
|
-
commands?: string[];
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* 验证执行结果
|
|
637
|
-
*/
|
|
638
|
-
interface VerificationResult {
|
|
639
|
-
/** 所有命令是否全部成功 */
|
|
640
|
-
success: boolean;
|
|
641
|
-
/** 每条命令的详细结果 */
|
|
642
|
-
commandResults: CommandResult[];
|
|
643
|
-
/** 失败的命令(仅 success=false 时填充) */
|
|
644
|
-
failedCommand?: string;
|
|
645
|
-
/** 失败详情(仅 success=false 时填充) */
|
|
646
|
-
failure?: string;
|
|
647
|
-
}
|
|
648
|
-
/**
|
|
649
|
-
* 按顺序在工作目录执行命令序列,任一命令失败则停止。
|
|
650
|
-
*
|
|
651
|
-
* @example
|
|
652
|
-
* ```ts
|
|
653
|
-
* const result = await runVerification({ workDir: '/repo' })
|
|
654
|
-
* if (!result.success) {
|
|
655
|
-
* console.error(result.failure)
|
|
656
|
-
* }
|
|
657
|
-
* ```
|
|
658
|
-
*/
|
|
659
|
-
declare function runVerification(params: VerificationParams): Promise<VerificationResult>;
|
|
660
|
-
/**
|
|
661
|
-
* 对外暴露以支持单独测试
|
|
662
|
-
*/
|
|
663
|
-
declare function sanitizeOutput(output: string): string;
|
|
664
|
-
//#endregion
|
|
665
|
-
//#region src/index.d.ts
|
|
666
|
-
/**
|
|
667
|
-
* 简化调用的入口(内部数据处理,非 CLI 使用)。
|
|
668
|
-
*/
|
|
669
|
-
declare function main(args?: string[]): CliRunResult;
|
|
670
|
-
//#endregion
|
|
671
|
-
export { CliConfigOverrides, CliInvocation, CliRunResult, CommandResult, CreatePullRequestParams, DEFAULT_RUNTIME_CONFIG, DependencyFixResult, DependfixApp, DependfixAppOptions, DependfixBranchStatus, DependfixOpenPR, DependfixRunResult, FetchDependabotAlertsParams, FixAndPrPlan, FixBranchResult, LockfileDiff, LockfileFailureCategory, LockfileRepairResult, OctokitClientOptions, PullRequestResult, RUNTIME_MODES, RepairAttempt, RepairLockfileParams, RepairStrategy, ResolveRuntimeConfigOptions, RuntimeConfig, RuntimeMode, SEVERITY_THRESHOLDS, type SeverityThreshold, UpgradeDependencyParams, VerificationParams, VerificationResult, classifyLockfileFailure, closePullRequest, computeFixAndPrPlan, computeFixFingerprint, computeLockfileDiff, createFixBranch, createGitHubClient, createPullRequest, deleteRemoteBranch, dependfixCommand, ensurePnpmOverrides, extractFingerprintFromBranch, extractPrefix, fetchDependabotAlerts, findDependencyVersion, findDependfixOpenPR, generatePRBody, getBranchPrStatus, inferRepoFromGitRemote, isConfirmAnswer, listDependfixBranches, main, mapGitHubError, overrideTransitiveDependency, parseCliArgs, parseMajorVersion, pushBranch, readEnvConfig, readLockfileVersion, readReposFile, repairLockfile, resolvePnpmVersion, resolveRepoList, resolveRuntimeConfig, runCli, runVerification, sanitizeOutput, stageAndCommit, upgradeDependency };
|
|
672
|
-
//# sourceMappingURL=index.d.cts.map
|