@rainy-updates/cli 0.5.7 → 0.6.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/CHANGELOG.md +81 -0
- package/README.md +90 -31
- package/dist/bin/cli.js +16 -16
- package/dist/bin/dispatch.js +29 -32
- package/dist/bin/help.js +32 -2
- package/dist/cache/cache.js +13 -11
- package/dist/commands/audit/parser.js +2 -2
- package/dist/commands/audit/runner.js +27 -46
- package/dist/commands/audit/targets.js +13 -13
- package/dist/commands/bisect/oracle.js +28 -11
- package/dist/commands/bisect/parser.js +3 -3
- package/dist/commands/bisect/runner.js +15 -8
- package/dist/commands/changelog/fetcher.js +11 -5
- package/dist/commands/dashboard/parser.js +103 -1
- package/dist/commands/dashboard/runner.d.ts +2 -2
- package/dist/commands/dashboard/runner.js +67 -37
- package/dist/commands/doctor/parser.js +9 -4
- package/dist/commands/doctor/runner.js +2 -2
- package/dist/commands/ga/parser.js +4 -4
- package/dist/commands/ga/runner.js +13 -7
- package/dist/commands/health/parser.js +2 -2
- package/dist/commands/licenses/runner.js +4 -4
- package/dist/commands/resolve/runner.js +9 -4
- package/dist/commands/review/parser.js +57 -4
- package/dist/commands/review/runner.js +31 -5
- package/dist/commands/snapshot/runner.js +17 -17
- package/dist/commands/snapshot/store.d.ts +0 -12
- package/dist/commands/snapshot/store.js +26 -38
- package/dist/commands/unused/runner.js +6 -7
- package/dist/commands/unused/scanner.js +17 -20
- package/dist/config/loader.d.ts +2 -2
- package/dist/config/loader.js +2 -5
- package/dist/config/policy.js +20 -11
- package/dist/core/analysis/run-silenced.js +0 -1
- package/dist/core/artifacts.js +6 -5
- package/dist/core/baseline.js +3 -5
- package/dist/core/check.js +2 -2
- package/dist/core/ci.js +52 -1
- package/dist/core/decision-plan.d.ts +14 -0
- package/dist/core/decision-plan.js +107 -0
- package/dist/core/doctor/result.js +8 -5
- package/dist/core/fix-pr-batch.js +38 -28
- package/dist/core/fix-pr.js +27 -24
- package/dist/core/init-ci.js +25 -21
- package/dist/core/options.js +95 -4
- package/dist/core/review-model.js +3 -0
- package/dist/core/summary.js +6 -0
- package/dist/core/upgrade.js +64 -2
- package/dist/core/verification.d.ts +2 -0
- package/dist/core/verification.js +106 -0
- package/dist/core/warm-cache.js +2 -2
- package/dist/output/format.js +15 -0
- package/dist/output/github.js +6 -0
- package/dist/output/sarif.js +12 -12
- package/dist/parsers/package-json.js +2 -4
- package/dist/pm/detect.d.ts +3 -1
- package/dist/pm/detect.js +24 -12
- package/dist/pm/install.d.ts +2 -1
- package/dist/pm/install.js +15 -16
- package/dist/registry/npm.js +34 -76
- package/dist/rup +0 -0
- package/dist/types/index.d.ts +76 -5
- package/dist/ui/tui.d.ts +4 -1
- package/dist/ui/tui.js +5 -4
- package/dist/utils/io.js +5 -6
- package/dist/utils/lockfile.js +24 -19
- package/dist/utils/runtime-paths.d.ts +4 -0
- package/dist/utils/runtime-paths.js +35 -0
- package/dist/utils/runtime.d.ts +7 -0
- package/dist/utils/runtime.js +32 -0
- package/dist/workspace/discover.js +55 -51
- package/package.json +16 -16
- package/dist/ui/dashboard/DashboardTUI.d.ts +0 -6
- package/dist/ui/dashboard/DashboardTUI.js +0 -34
- package/dist/ui/dashboard/components/DetailPanel.d.ts +0 -4
- package/dist/ui/dashboard/components/DetailPanel.js +0 -30
- package/dist/ui/dashboard/components/Footer.d.ts +0 -4
- package/dist/ui/dashboard/components/Footer.js +0 -9
- package/dist/ui/dashboard/components/Header.d.ts +0 -4
- package/dist/ui/dashboard/components/Header.js +0 -12
- package/dist/ui/dashboard/components/Sidebar.d.ts +0 -4
- package/dist/ui/dashboard/components/Sidebar.js +0 -23
- package/dist/ui/dashboard/store.d.ts +0 -34
- package/dist/ui/dashboard/store.js +0 -148
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { promises as fs } from "node:fs";
|
|
3
1
|
import path from "node:path";
|
|
2
|
+
import { writeFileAtomic } from "../../utils/io.js";
|
|
4
3
|
const DEFAULT_STORE_NAME = ".rup-snapshots.json";
|
|
5
|
-
/**
|
|
6
|
-
* Lightweight SQLite-free snapshot store (uses a JSON file in the project root).
|
|
7
|
-
*
|
|
8
|
-
* Design goals:
|
|
9
|
-
* - No extra runtime dependencies (SQLite bindings vary by runtime)
|
|
10
|
-
* - Human-readable store file (git-committable if desired)
|
|
11
|
-
* - Atomic writes via tmp-rename to prevent corruption
|
|
12
|
-
* - Fast: entire store fits in memory for typical use (< 50 snapshots)
|
|
13
|
-
*/
|
|
14
4
|
export class SnapshotStore {
|
|
15
5
|
storePath;
|
|
16
6
|
entries = [];
|
|
@@ -26,8 +16,7 @@ export class SnapshotStore {
|
|
|
26
16
|
if (this.loaded)
|
|
27
17
|
return;
|
|
28
18
|
try {
|
|
29
|
-
const
|
|
30
|
-
const parsed = JSON.parse(raw);
|
|
19
|
+
const parsed = (await Bun.file(this.storePath).json());
|
|
31
20
|
if (Array.isArray(parsed)) {
|
|
32
21
|
this.entries = parsed;
|
|
33
22
|
}
|
|
@@ -38,9 +27,7 @@ export class SnapshotStore {
|
|
|
38
27
|
this.loaded = true;
|
|
39
28
|
}
|
|
40
29
|
async save() {
|
|
41
|
-
|
|
42
|
-
await fs.writeFile(tmp, JSON.stringify(this.entries, null, 2) + "\n", "utf8");
|
|
43
|
-
await fs.rename(tmp, this.storePath);
|
|
30
|
+
await writeFileAtomic(this.storePath, JSON.stringify(this.entries, null, 2) + "\n");
|
|
44
31
|
}
|
|
45
32
|
async saveSnapshot(manifests, lockfileHashes, label) {
|
|
46
33
|
await this.load();
|
|
@@ -76,32 +63,30 @@ export class SnapshotStore {
|
|
|
76
63
|
return false;
|
|
77
64
|
}
|
|
78
65
|
}
|
|
79
|
-
/** Captures current package.json and lockfile state for a set of directories. */
|
|
80
66
|
export async function captureState(packageDirs) {
|
|
81
67
|
const manifests = {};
|
|
82
68
|
const lockfileHashes = {};
|
|
83
|
-
const
|
|
69
|
+
const lockfiles = [
|
|
84
70
|
"package-lock.json",
|
|
85
71
|
"pnpm-lock.yaml",
|
|
86
72
|
"yarn.lock",
|
|
73
|
+
"bun.lock",
|
|
87
74
|
"bun.lockb",
|
|
88
75
|
];
|
|
89
76
|
await Promise.all(packageDirs.map(async (dir) => {
|
|
90
|
-
// Read package.json
|
|
91
77
|
try {
|
|
92
|
-
|
|
93
|
-
manifests[dir] = content;
|
|
78
|
+
manifests[dir] = await Bun.file(path.join(dir, "package.json")).text();
|
|
94
79
|
}
|
|
95
80
|
catch {
|
|
96
81
|
// No package.json — skip
|
|
97
82
|
}
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
for (const lockfileName of lockfiles) {
|
|
84
|
+
const filePath = path.join(dir, lockfileName);
|
|
100
85
|
try {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
86
|
+
const file = Bun.file(filePath);
|
|
87
|
+
if (!(await file.exists()))
|
|
88
|
+
continue;
|
|
89
|
+
lockfileHashes[dir] = await hashFile(filePath);
|
|
105
90
|
break;
|
|
106
91
|
}
|
|
107
92
|
catch {
|
|
@@ -111,16 +96,11 @@ export async function captureState(packageDirs) {
|
|
|
111
96
|
}));
|
|
112
97
|
return { manifests, lockfileHashes };
|
|
113
98
|
}
|
|
114
|
-
/** Restores package.json files from a snapshot's manifest map. */
|
|
115
99
|
export async function restoreState(entry) {
|
|
116
100
|
await Promise.all(Object.entries(entry.manifests).map(async ([dir, content]) => {
|
|
117
|
-
|
|
118
|
-
const tmp = manifestPath + ".tmp";
|
|
119
|
-
await fs.writeFile(tmp, content, "utf8");
|
|
120
|
-
await fs.rename(tmp, manifestPath);
|
|
101
|
+
await writeFileAtomic(path.join(dir, "package.json"), content);
|
|
121
102
|
}));
|
|
122
103
|
}
|
|
123
|
-
/** Computes a diff of dependency versions between two manifest snapshots. */
|
|
124
104
|
export function diffManifests(before, after) {
|
|
125
105
|
const changes = [];
|
|
126
106
|
for (const [dir, afterJson] of Object.entries(after)) {
|
|
@@ -142,12 +122,15 @@ export function diffManifests(before, after) {
|
|
|
142
122
|
"optionalDependencies",
|
|
143
123
|
];
|
|
144
124
|
for (const field of fields) {
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
const allNames = new Set([
|
|
125
|
+
const beforeDeps = beforeManifest[field] ?? {};
|
|
126
|
+
const afterDeps = afterManifest[field] ?? {};
|
|
127
|
+
const allNames = new Set([
|
|
128
|
+
...Object.keys(beforeDeps),
|
|
129
|
+
...Object.keys(afterDeps),
|
|
130
|
+
]);
|
|
148
131
|
for (const name of allNames) {
|
|
149
|
-
const fromVer =
|
|
150
|
-
const toVer =
|
|
132
|
+
const fromVer = beforeDeps[name] ?? "(removed)";
|
|
133
|
+
const toVer = afterDeps[name] ?? "(removed)";
|
|
151
134
|
if (fromVer !== toVer) {
|
|
152
135
|
changes.push({ name, from: fromVer, to: toVer });
|
|
153
136
|
}
|
|
@@ -156,3 +139,8 @@ export function diffManifests(before, after) {
|
|
|
156
139
|
}
|
|
157
140
|
return changes;
|
|
158
141
|
}
|
|
142
|
+
async function hashFile(filePath) {
|
|
143
|
+
const hasher = new Bun.CryptoHasher("sha256");
|
|
144
|
+
hasher.update(await Bun.file(filePath).bytes());
|
|
145
|
+
return hasher.digest("hex");
|
|
146
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import process from "node:process";
|
|
3
2
|
import { readManifest, } from "../../parsers/package-json.js";
|
|
4
3
|
import { discoverPackageDirs } from "../../workspace/discover.js";
|
|
5
4
|
import { writeFileAtomic } from "../../utils/io.js";
|
|
6
5
|
import { stableStringify } from "../../utils/stable-json.js";
|
|
6
|
+
import { writeStderr, writeStdout } from "../../utils/runtime.js";
|
|
7
7
|
import { scanDirectory } from "./scanner.js";
|
|
8
8
|
import { matchDependencies, removeUnusedFromManifest } from "./matcher.js";
|
|
9
9
|
/**
|
|
@@ -60,16 +60,15 @@ export async function runUnused(options) {
|
|
|
60
60
|
// ─ Apply fix ─────────────────────────────────────────────────────────────
|
|
61
61
|
if (options.fix && unused.length > 0) {
|
|
62
62
|
if (options.dryRun) {
|
|
63
|
-
|
|
63
|
+
writeStderr(`[unused] --dry-run: would remove ${unused.length} unused dep(s) from ${packageDir}/package.json\n`);
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
66
|
try {
|
|
67
|
-
const { promises: fs } = await import("node:fs");
|
|
68
67
|
const manifestPath = path.join(packageDir, "package.json");
|
|
69
|
-
const originalJson = await
|
|
68
|
+
const originalJson = await Bun.file(manifestPath).text();
|
|
70
69
|
const updatedJson = removeUnusedFromManifest(originalJson, unused);
|
|
71
70
|
await writeFileAtomic(manifestPath, updatedJson);
|
|
72
|
-
|
|
71
|
+
writeStderr(`[unused] Removed ${unused.length} unused dep(s) from ${packageDir}/package.json\n`);
|
|
73
72
|
}
|
|
74
73
|
catch (error) {
|
|
75
74
|
result.errors.push(`Failed to update package.json in ${packageDir}: ${String(error)}`);
|
|
@@ -80,11 +79,11 @@ export async function runUnused(options) {
|
|
|
80
79
|
result.totalUnused = result.unused.length;
|
|
81
80
|
result.totalMissing = result.missing.length;
|
|
82
81
|
// ─ Render output ─────────────────────────────────────────────────────────
|
|
83
|
-
|
|
82
|
+
writeStdout(renderUnusedTable(result) + "\n");
|
|
84
83
|
// ─ JSON report ───────────────────────────────────────────────────────────
|
|
85
84
|
if (options.jsonFile) {
|
|
86
85
|
await writeFileAtomic(options.jsonFile, stableStringify(result, 2) + "\n");
|
|
87
|
-
|
|
86
|
+
writeStderr(`[unused] JSON report written to ${options.jsonFile}\n`);
|
|
88
87
|
}
|
|
89
88
|
return result;
|
|
90
89
|
}
|
|
@@ -93,34 +93,31 @@ export async function scanDirectory(dir) {
|
|
|
93
93
|
async function walkDirectory(dir, collector) {
|
|
94
94
|
let entries;
|
|
95
95
|
try {
|
|
96
|
-
entries = await fs.readdir(dir);
|
|
96
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
97
97
|
}
|
|
98
98
|
catch {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
101
|
const tasks = [];
|
|
102
|
-
for (const
|
|
102
|
+
for (const entry of entries) {
|
|
103
|
+
const entryName = entry.name;
|
|
103
104
|
if (IGNORED_DIRS.has(entryName))
|
|
104
105
|
continue;
|
|
105
106
|
const fullPath = path.join(dir, entryName);
|
|
106
|
-
|
|
107
|
-
.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
collector.add(name);
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
.catch(() => undefined);
|
|
107
|
+
if (entry.isDirectory()) {
|
|
108
|
+
tasks.push(walkDirectory(fullPath, collector));
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (!entry.isFile())
|
|
112
|
+
continue;
|
|
113
|
+
const ext = path.extname(entryName).toLowerCase();
|
|
114
|
+
if (!SOURCE_EXTENSIONS.has(ext))
|
|
115
|
+
continue;
|
|
116
|
+
tasks.push(Bun.file(fullPath)
|
|
117
|
+
.text()
|
|
118
|
+
.then((source) => {
|
|
119
|
+
for (const name of extractImportsFromSource(source)) {
|
|
120
|
+
collector.add(name);
|
|
124
121
|
}
|
|
125
122
|
})
|
|
126
123
|
.catch(() => undefined));
|
package/dist/config/loader.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CiProfile, DependencyKind, FailOnLevel, GroupBy, LockfileMode, LogLevel, OutputFormat, TargetLevel } from "../types/index.js";
|
|
1
|
+
import type { CiProfile, SelectedPackageManager, DependencyKind, FailOnLevel, GroupBy, LockfileMode, LogLevel, OutputFormat, TargetLevel } from "../types/index.js";
|
|
2
2
|
export interface FileConfig {
|
|
3
3
|
target?: TargetLevel;
|
|
4
4
|
filter?: string;
|
|
@@ -39,7 +39,7 @@ export interface FileConfig {
|
|
|
39
39
|
showImpact?: boolean;
|
|
40
40
|
showHomepage?: boolean;
|
|
41
41
|
install?: boolean;
|
|
42
|
-
packageManager?:
|
|
42
|
+
packageManager?: SelectedPackageManager;
|
|
43
43
|
sync?: boolean;
|
|
44
44
|
}
|
|
45
45
|
export declare function loadConfig(cwd: string): Promise<FileConfig>;
|
package/dist/config/loader.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { promises as fs } from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
export async function loadConfig(cwd) {
|
|
4
3
|
const fromRc = await loadRcFile(cwd);
|
|
@@ -13,8 +12,7 @@ async function loadRcFile(cwd) {
|
|
|
13
12
|
for (const candidate of candidates) {
|
|
14
13
|
const filePath = path.join(cwd, candidate);
|
|
15
14
|
try {
|
|
16
|
-
|
|
17
|
-
return JSON.parse(content);
|
|
15
|
+
return (await Bun.file(filePath).json());
|
|
18
16
|
}
|
|
19
17
|
catch {
|
|
20
18
|
// noop
|
|
@@ -25,8 +23,7 @@ async function loadRcFile(cwd) {
|
|
|
25
23
|
async function loadPackageConfig(cwd) {
|
|
26
24
|
const packagePath = path.join(cwd, "package.json");
|
|
27
25
|
try {
|
|
28
|
-
const
|
|
29
|
-
const parsed = JSON.parse(content);
|
|
26
|
+
const parsed = (await Bun.file(packagePath).json());
|
|
30
27
|
return parsed.rainyUpdates ?? {};
|
|
31
28
|
}
|
|
32
29
|
catch {
|
package/dist/config/policy.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
import { promises as fs } from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
export async function loadPolicy(cwd, policyFile) {
|
|
4
|
-
const candidates = policyFile
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const candidates = policyFile
|
|
4
|
+
? [policyFile]
|
|
5
|
+
: [
|
|
6
|
+
path.join(cwd, ".rainyupdates-policy.json"),
|
|
7
|
+
path.join(cwd, "rainy-updates.policy.json"),
|
|
8
|
+
];
|
|
8
9
|
for (const candidate of candidates) {
|
|
9
|
-
const filePath = path.isAbsolute(candidate)
|
|
10
|
+
const filePath = path.isAbsolute(candidate)
|
|
11
|
+
? candidate
|
|
12
|
+
: path.resolve(cwd, candidate);
|
|
10
13
|
try {
|
|
11
|
-
const
|
|
12
|
-
const parsed = JSON.parse(content);
|
|
14
|
+
const parsed = (await Bun.file(filePath).json());
|
|
13
15
|
return {
|
|
14
16
|
ignorePatterns: parsed.ignore ?? [],
|
|
15
17
|
cooldownDays: asNonNegativeInt(parsed.cooldownDays),
|
|
16
|
-
packageRules: new Map(Object.entries(parsed.packageRules ?? {}).map(([pkg, rule]) => [
|
|
18
|
+
packageRules: new Map(Object.entries(parsed.packageRules ?? {}).map(([pkg, rule]) => [
|
|
19
|
+
pkg,
|
|
20
|
+
normalizeRule(rule),
|
|
21
|
+
])),
|
|
17
22
|
matchRules: Object.values(parsed.packageRules ?? {})
|
|
18
23
|
.map((rule) => normalizeRule(rule))
|
|
19
24
|
.filter((rule) => typeof rule.match === "string" && rule.match.length > 0),
|
|
@@ -44,7 +49,9 @@ function normalizeRule(rule) {
|
|
|
44
49
|
maxUpdatesPerRun: asNonNegativeInt(rule.maxUpdatesPerRun),
|
|
45
50
|
cooldownDays: asNonNegativeInt(rule.cooldownDays),
|
|
46
51
|
allowPrerelease: rule.allowPrerelease === true,
|
|
47
|
-
group: typeof rule.group === "string" && rule.group.trim().length > 0
|
|
52
|
+
group: typeof rule.group === "string" && rule.group.trim().length > 0
|
|
53
|
+
? rule.group.trim()
|
|
54
|
+
: undefined,
|
|
48
55
|
priority: asNonNegativeInt(rule.priority),
|
|
49
56
|
target: rule.target,
|
|
50
57
|
autofix: rule.autofix !== false,
|
|
@@ -60,7 +67,9 @@ function matchesPattern(value, pattern) {
|
|
|
60
67
|
return false;
|
|
61
68
|
if (pattern === "*")
|
|
62
69
|
return true;
|
|
63
|
-
const escaped = pattern
|
|
70
|
+
const escaped = pattern
|
|
71
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
|
72
|
+
.replace(/\*/g, ".*");
|
|
64
73
|
const regex = new RegExp(`^${escaped}$`);
|
|
65
74
|
return regex.test(value);
|
|
66
75
|
}
|
package/dist/core/artifacts.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import { stableStringify } from "../utils/stable-json.js";
|
|
4
3
|
import { writeFileAtomic } from "../utils/io.js";
|
|
5
4
|
export function createRunId(command, options, result) {
|
|
6
|
-
const
|
|
7
|
-
|
|
5
|
+
const hasher = new Bun.CryptoHasher("sha256");
|
|
6
|
+
hasher.update(stableStringify({
|
|
8
7
|
command,
|
|
9
8
|
cwd: path.resolve(options.cwd),
|
|
10
9
|
target: options.target,
|
|
@@ -17,14 +16,15 @@ export function createRunId(command, options, result) {
|
|
|
17
16
|
toRange: update.toRange,
|
|
18
17
|
})),
|
|
19
18
|
}, 0));
|
|
20
|
-
return
|
|
19
|
+
return hasher.digest("hex").slice(0, 16);
|
|
21
20
|
}
|
|
22
21
|
export async function writeArtifactManifest(command, options, result) {
|
|
23
22
|
const shouldWrite = options.ci ||
|
|
24
23
|
Boolean(options.jsonFile) ||
|
|
25
24
|
Boolean(options.githubOutputFile) ||
|
|
26
25
|
Boolean(options.sarifFile) ||
|
|
27
|
-
Boolean(options.prReportFile)
|
|
26
|
+
Boolean(options.prReportFile) ||
|
|
27
|
+
Boolean(options.verificationReportFile);
|
|
28
28
|
if (!shouldWrite)
|
|
29
29
|
return null;
|
|
30
30
|
const runId = result.summary.runId ?? createRunId(command, options, result);
|
|
@@ -41,6 +41,7 @@ export async function writeArtifactManifest(command, options, result) {
|
|
|
41
41
|
githubOutputFile: options.githubOutputFile,
|
|
42
42
|
sarifFile: options.sarifFile,
|
|
43
43
|
prReportFile: options.prReportFile,
|
|
44
|
+
verificationReportFile: options.verificationReportFile,
|
|
44
45
|
},
|
|
45
46
|
};
|
|
46
47
|
await writeFileAtomic(artifactManifestPath, stableStringify(manifest, 2) + "\n");
|
package/dist/core/baseline.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { promises as fs } from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import { collectDependencies, readManifest } from "../parsers/package-json.js";
|
|
3
|
+
import { writeFileAtomic } from "../utils/io.js";
|
|
4
4
|
import { discoverPackageDirs } from "../workspace/discover.js";
|
|
5
5
|
export async function saveBaseline(options) {
|
|
6
6
|
const entries = await collectBaselineEntries(options.cwd, options.workspace, options.includeKinds);
|
|
@@ -9,16 +9,14 @@ export async function saveBaseline(options) {
|
|
|
9
9
|
createdAt: new Date().toISOString(),
|
|
10
10
|
entries,
|
|
11
11
|
};
|
|
12
|
-
await
|
|
13
|
-
await fs.writeFile(options.filePath, JSON.stringify(payload, null, 2) + "\n", "utf8");
|
|
12
|
+
await writeFileAtomic(options.filePath, JSON.stringify(payload, null, 2) + "\n");
|
|
14
13
|
return {
|
|
15
14
|
filePath: options.filePath,
|
|
16
15
|
entries: entries.length,
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
18
|
export async function diffBaseline(options) {
|
|
20
|
-
const
|
|
21
|
-
const baseline = JSON.parse(content);
|
|
19
|
+
const baseline = (await Bun.file(options.filePath).json());
|
|
22
20
|
const currentEntries = await collectBaselineEntries(options.cwd, options.workspace, options.includeKinds);
|
|
23
21
|
const baselineMap = new Map(baseline.entries.map((entry) => [toKey(entry), entry]));
|
|
24
22
|
const currentMap = new Map(currentEntries.map((entry) => [toKey(entry), entry]));
|
package/dist/core/check.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import process from "node:process";
|
|
3
2
|
import { collectDependencies, readManifest } from "../parsers/package-json.js";
|
|
4
3
|
import { matchesPattern } from "../utils/pattern.js";
|
|
5
4
|
import { applyRangeStyle, classifyDiff, clampTarget, pickTargetVersionFromAvailable } from "../utils/semver.js";
|
|
@@ -11,6 +10,7 @@ import { loadPolicy, resolvePolicyRule } from "../config/policy.js";
|
|
|
11
10
|
import { createSummary, finalizeSummary } from "./summary.js";
|
|
12
11
|
import { applyImpactScores } from "./impact.js";
|
|
13
12
|
import { formatClassifiedMessage } from "./errors.js";
|
|
13
|
+
import { writeStdout } from "../utils/runtime.js";
|
|
14
14
|
export async function check(options) {
|
|
15
15
|
const startedAt = Date.now();
|
|
16
16
|
let discoveryMs = 0;
|
|
@@ -48,7 +48,7 @@ export async function check(options) {
|
|
|
48
48
|
if (!options.stream)
|
|
49
49
|
return;
|
|
50
50
|
streamedEvents += 1;
|
|
51
|
-
|
|
51
|
+
writeStdout(`${message}\n`);
|
|
52
52
|
};
|
|
53
53
|
for (const packageDir of packageDirs) {
|
|
54
54
|
let manifest;
|
package/dist/core/ci.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { check } from "./check.js";
|
|
2
2
|
import { warmCache } from "./warm-cache.js";
|
|
3
|
+
import { buildReviewResult, createDoctorResult } from "./review-model.js";
|
|
4
|
+
import { createDecisionPlan, defaultDecisionPlanPath, writeDecisionPlan, } from "./decision-plan.js";
|
|
5
|
+
import { upgrade } from "./upgrade.js";
|
|
3
6
|
export async function runCi(options) {
|
|
4
7
|
const profile = options.ciProfile;
|
|
5
8
|
if (profile !== "minimal") {
|
|
@@ -16,5 +19,53 @@ export async function runCi(options) {
|
|
|
16
19
|
offline: profile === "minimal" ? options.offline : true,
|
|
17
20
|
concurrency: profile === "enterprise" ? Math.max(options.concurrency, 32) : options.concurrency,
|
|
18
21
|
};
|
|
19
|
-
|
|
22
|
+
if (options.ciGate === "check") {
|
|
23
|
+
return await check(checkOptions);
|
|
24
|
+
}
|
|
25
|
+
if (options.ciGate === "doctor") {
|
|
26
|
+
const review = await buildReviewResult(checkOptions);
|
|
27
|
+
createDoctorResult(review);
|
|
28
|
+
return reviewToCheckResult(review);
|
|
29
|
+
}
|
|
30
|
+
if (options.ciGate === "review") {
|
|
31
|
+
const review = await buildReviewResult(checkOptions);
|
|
32
|
+
const selectedItems = review.items.filter((item) => item.update.selectedByDefault !== false &&
|
|
33
|
+
item.update.decisionState !== "blocked");
|
|
34
|
+
const decisionPlanFile = options.decisionPlanFile ?? defaultDecisionPlanPath(options.cwd);
|
|
35
|
+
const plan = createDecisionPlan({
|
|
36
|
+
review,
|
|
37
|
+
selectedItems,
|
|
38
|
+
sourceCommand: "ci",
|
|
39
|
+
mode: "review",
|
|
40
|
+
focus: "all",
|
|
41
|
+
});
|
|
42
|
+
await writeDecisionPlan(decisionPlanFile, plan);
|
|
43
|
+
review.decisionPlan = plan;
|
|
44
|
+
review.summary.decisionPlan = decisionPlanFile;
|
|
45
|
+
review.summary.interactiveSurface = "dashboard";
|
|
46
|
+
review.summary.queueFocus = "all";
|
|
47
|
+
review.summary.suggestedCommand = `rup upgrade --from-plan ${decisionPlanFile}`;
|
|
48
|
+
return reviewToCheckResult(review);
|
|
49
|
+
}
|
|
50
|
+
const decisionPlanFile = options.decisionPlanFile ?? defaultDecisionPlanPath(options.cwd);
|
|
51
|
+
return upgrade({
|
|
52
|
+
...checkOptions,
|
|
53
|
+
install: false,
|
|
54
|
+
packageManager: "auto",
|
|
55
|
+
sync: checkOptions.workspace,
|
|
56
|
+
fromPlanFile: decisionPlanFile,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function reviewToCheckResult(review) {
|
|
60
|
+
return {
|
|
61
|
+
projectPath: review.projectPath,
|
|
62
|
+
packagePaths: review.analysis.check.packagePaths,
|
|
63
|
+
packageManager: review.analysis.check.packageManager,
|
|
64
|
+
target: review.target,
|
|
65
|
+
timestamp: review.analysis.check.timestamp,
|
|
66
|
+
summary: review.summary,
|
|
67
|
+
updates: review.updates,
|
|
68
|
+
errors: review.errors,
|
|
69
|
+
warnings: review.warnings,
|
|
70
|
+
};
|
|
20
71
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DashboardMode, DecisionPlan, PackageUpdate, QueueFocus, ReviewItem, ReviewResult, UpgradeOptions } from "../types/index.js";
|
|
2
|
+
export declare function defaultDecisionPlanPath(cwd: string): string;
|
|
3
|
+
export declare function filterReviewItemsByFocus(items: ReviewItem[], focus: QueueFocus): ReviewItem[];
|
|
4
|
+
export declare function createDecisionPlan(input: {
|
|
5
|
+
review: ReviewResult;
|
|
6
|
+
selectedItems: ReviewItem[];
|
|
7
|
+
sourceCommand: string;
|
|
8
|
+
mode: DashboardMode;
|
|
9
|
+
focus: QueueFocus;
|
|
10
|
+
}): DecisionPlan;
|
|
11
|
+
export declare function writeDecisionPlan(filePath: string, plan: DecisionPlan): Promise<void>;
|
|
12
|
+
export declare function readDecisionPlan(filePath: string): Promise<DecisionPlan>;
|
|
13
|
+
export declare function selectedUpdatesFromPlan(plan: DecisionPlan): PackageUpdate[];
|
|
14
|
+
export declare function resolveDecisionPlanPath(options: Pick<UpgradeOptions, "cwd" | "decisionPlanFile">, explicit?: string): string;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { stableStringify } from "../utils/stable-json.js";
|
|
3
|
+
import { writeFileAtomic } from "../utils/io.js";
|
|
4
|
+
export function defaultDecisionPlanPath(cwd) {
|
|
5
|
+
return path.resolve(cwd, ".artifacts/decision-plan.json");
|
|
6
|
+
}
|
|
7
|
+
export function filterReviewItemsByFocus(items, focus) {
|
|
8
|
+
if (focus === "security") {
|
|
9
|
+
return items.filter((item) => item.advisories.length > 0);
|
|
10
|
+
}
|
|
11
|
+
if (focus === "risk") {
|
|
12
|
+
return items.filter((item) => item.update.riskLevel === "critical" ||
|
|
13
|
+
item.update.riskLevel === "high");
|
|
14
|
+
}
|
|
15
|
+
if (focus === "major") {
|
|
16
|
+
return items.filter((item) => item.update.diffType === "major");
|
|
17
|
+
}
|
|
18
|
+
if (focus === "blocked") {
|
|
19
|
+
return items.filter((item) => item.update.decisionState === "blocked");
|
|
20
|
+
}
|
|
21
|
+
if (focus === "workspace") {
|
|
22
|
+
return items.filter((item) => Boolean(item.update.workspaceGroup));
|
|
23
|
+
}
|
|
24
|
+
return items;
|
|
25
|
+
}
|
|
26
|
+
export function createDecisionPlan(input) {
|
|
27
|
+
const selectedKeys = new Set(input.selectedItems.map((item) => packageUpdateKey(item.update)));
|
|
28
|
+
const items = input.review.items.map((item) => ({
|
|
29
|
+
...toDecisionPlanItem(item.update),
|
|
30
|
+
selected: selectedKeys.has(packageUpdateKey(item.update)),
|
|
31
|
+
}));
|
|
32
|
+
return {
|
|
33
|
+
contractVersion: "1",
|
|
34
|
+
createdAt: new Date().toISOString(),
|
|
35
|
+
sourceCommand: input.sourceCommand,
|
|
36
|
+
mode: input.mode,
|
|
37
|
+
focus: input.focus,
|
|
38
|
+
projectPath: input.review.projectPath,
|
|
39
|
+
target: input.review.target,
|
|
40
|
+
interactiveSurface: "dashboard",
|
|
41
|
+
summary: {
|
|
42
|
+
totalItems: items.length,
|
|
43
|
+
selectedItems: items.filter((item) => item.selected).length,
|
|
44
|
+
},
|
|
45
|
+
items,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export async function writeDecisionPlan(filePath, plan) {
|
|
49
|
+
await writeFileAtomic(filePath, stableStringify(plan, 2) + "\n");
|
|
50
|
+
}
|
|
51
|
+
export async function readDecisionPlan(filePath) {
|
|
52
|
+
const parsed = (await Bun.file(filePath).json());
|
|
53
|
+
if (parsed.contractVersion !== "1" ||
|
|
54
|
+
!Array.isArray(parsed.items) ||
|
|
55
|
+
typeof parsed.projectPath !== "string") {
|
|
56
|
+
throw new Error(`Invalid decision plan: ${filePath}`);
|
|
57
|
+
}
|
|
58
|
+
return parsed;
|
|
59
|
+
}
|
|
60
|
+
export function selectedUpdatesFromPlan(plan) {
|
|
61
|
+
return plan.items.filter((item) => item.selected).map(toPackageUpdate);
|
|
62
|
+
}
|
|
63
|
+
export function resolveDecisionPlanPath(options, explicit) {
|
|
64
|
+
return (explicit ?? options.decisionPlanFile ?? defaultDecisionPlanPath(options.cwd));
|
|
65
|
+
}
|
|
66
|
+
function toDecisionPlanItem(update) {
|
|
67
|
+
return {
|
|
68
|
+
packagePath: update.packagePath,
|
|
69
|
+
name: update.name,
|
|
70
|
+
kind: update.kind,
|
|
71
|
+
fromRange: update.fromRange,
|
|
72
|
+
toRange: update.toRange,
|
|
73
|
+
toVersionResolved: update.toVersionResolved,
|
|
74
|
+
diffType: update.diffType,
|
|
75
|
+
riskLevel: update.riskLevel,
|
|
76
|
+
riskScore: update.riskScore,
|
|
77
|
+
policyAction: update.policyAction,
|
|
78
|
+
decisionState: update.decisionState,
|
|
79
|
+
selected: true,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function toPackageUpdate(item) {
|
|
83
|
+
return {
|
|
84
|
+
packagePath: item.packagePath,
|
|
85
|
+
name: item.name,
|
|
86
|
+
kind: item.kind,
|
|
87
|
+
fromRange: item.fromRange,
|
|
88
|
+
toRange: item.toRange,
|
|
89
|
+
toVersionResolved: item.toVersionResolved,
|
|
90
|
+
diffType: item.diffType,
|
|
91
|
+
filtered: false,
|
|
92
|
+
autofix: true,
|
|
93
|
+
riskLevel: item.riskLevel,
|
|
94
|
+
riskScore: item.riskScore,
|
|
95
|
+
policyAction: item.policyAction,
|
|
96
|
+
decisionState: item.decisionState,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function packageUpdateKey(update) {
|
|
100
|
+
return [
|
|
101
|
+
update.packagePath,
|
|
102
|
+
update.kind,
|
|
103
|
+
update.name,
|
|
104
|
+
update.fromRange,
|
|
105
|
+
update.toRange,
|
|
106
|
+
].join("::");
|
|
107
|
+
}
|
|
@@ -17,6 +17,7 @@ export function createDoctorResult(review) {
|
|
|
17
17
|
review.summary.primaryFindingCode = findings[0]?.code;
|
|
18
18
|
review.summary.primaryFindingCategory = findings[0]?.category;
|
|
19
19
|
review.summary.nextActionReason = nextActionReason;
|
|
20
|
+
review.summary.suggestedCommand = recommendedCommand;
|
|
20
21
|
return {
|
|
21
22
|
verdict,
|
|
22
23
|
score,
|
|
@@ -31,11 +32,13 @@ export function createDoctorResult(review) {
|
|
|
31
32
|
}
|
|
32
33
|
function recommendDoctorCommand(review, verdict) {
|
|
33
34
|
if (verdict === "blocked")
|
|
34
|
-
return "rup review --
|
|
35
|
-
if ((review.summary.securityPackages ?? 0) > 0)
|
|
36
|
-
return "rup review --security
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
return "rup dashboard --mode review --focus blocked";
|
|
36
|
+
if ((review.summary.securityPackages ?? 0) > 0) {
|
|
37
|
+
return "rup dashboard --mode review --focus security";
|
|
38
|
+
}
|
|
39
|
+
if (review.errors.length > 0 || review.items.length > 0) {
|
|
40
|
+
return "rup dashboard --mode review";
|
|
41
|
+
}
|
|
39
42
|
return "rup check";
|
|
40
43
|
}
|
|
41
44
|
function describeNextActionReason(review, verdict) {
|