@blzsky/variant 0.2.1 → 0.3.0-canary.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 +110 -56
- package/dist/{build-3DSBMMI3.js → build-GKWNLU4Q.js} +9 -8
- package/dist/{check-SIQJU6Z2.js → check-KO5VY67Z.js} +6 -6
- package/dist/{chunk-FA64KWJ2.js → chunk-7NC7AO75.js} +15 -28
- package/dist/{chunk-VYWPQKMS.js → chunk-ACTY42RE.js} +20 -0
- package/dist/{chunk-ZH2PQUNL.js → chunk-CN25SRKD.js} +6 -6
- package/dist/{chunk-43VLELTL.js → chunk-CWF6QXEW.js} +1 -1
- package/dist/{chunk-7OPTWU6E.js → chunk-DMDAJPFJ.js} +1 -1
- package/dist/{chunk-RC23JQKI.js → chunk-DSQDMFQ6.js} +9 -1
- package/dist/chunk-H5C4SE73.js +184 -0
- package/dist/chunk-IFFZ46YS.js +575 -0
- package/dist/chunk-IHXJ72XA.js +31 -0
- package/dist/chunk-KCEGA56S.js +670 -0
- package/dist/{chunk-FZEXZBXB.js → chunk-MAK3HG46.js} +41 -9
- package/dist/chunk-MT4BOAAV.js +167 -0
- package/dist/{chunk-TCISS2AS.js → chunk-NFFXYYM6.js} +120 -25
- package/dist/{chunk-26DHEXGS.js → chunk-RJBFCURK.js} +1 -1
- package/dist/{chunk-6BXSZPHC.js → chunk-RSIOYQOQ.js} +67 -8
- package/dist/chunk-SGP5JX6I.js +377 -0
- package/dist/chunk-X3VVGTEV.js +268 -0
- package/dist/{chunk-Q7RLUZSN.js → chunk-YII4TAKS.js} +10 -3
- package/dist/cli.js +62 -27
- package/dist/{diff-HSJBZFMC.js → diff-A3TQWWUJ.js} +5 -5
- package/dist/{doctor-B7MHFIYJ.js → doctor-6ONS6LKY.js} +4 -4
- package/dist/{env-I7JZRWDN.js → env-XF2US3CB.js} +6 -6
- package/dist/git-W6N3WMYQ.js +24 -0
- package/dist/impact-DPZIAJR4.js +263 -0
- package/dist/index.js +2 -2
- package/dist/init-VNK5E4H3.js +777 -0
- package/dist/{insight-JQLTGFYB.js → insight-LNYVMCAE.js} +7 -7
- package/dist/pr-6CYMM2XU.js +707 -0
- package/dist/{run-C6VAQOVM.js → run-44PKMOV5.js} +9 -8
- package/dist/{symbol-graph-E5GXKDFZ.js → symbol-graph-OB4AJCLW.js} +3 -3
- package/dist/{tsconfig-paths-E3UEDGXZ.js → tsconfig-paths-SV3PULCW.js} +3 -1
- package/dist/vitest.cjs +629 -0
- package/dist/vitest.d.cts +181 -0
- package/dist/vitest.d.ts +181 -0
- package/dist/vitest.js +356 -0
- package/dist/workspace-PIQXG4ZD.js +65 -0
- package/package.json +13 -2
- package/dist/chunk-DRMASVYN.js +0 -25
- package/dist/chunk-KSHWC2XN.js +0 -78
- package/dist/chunk-XTYVVUWW.js +0 -279
- package/dist/impact-PRZ6HEP5.js +0 -735
- package/dist/init-O2BY3FOY.js +0 -158
- package/dist/pr-Y724QAHE.js +0 -165
- package/dist/workspace-HRTFGWKN.js +0 -186
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultBranchRef,
|
|
3
|
+
mergeBase,
|
|
4
|
+
resolveCommit
|
|
5
|
+
} from "./chunk-RSIOYQOQ.js";
|
|
6
|
+
import {
|
|
7
|
+
GitRefError,
|
|
8
|
+
NoBaseCommitError
|
|
9
|
+
} from "./chunk-ACTY42RE.js";
|
|
10
|
+
|
|
11
|
+
// src/core/vcs/change-base.ts
|
|
12
|
+
import { readFile } from "fs/promises";
|
|
13
|
+
function changeBaseDeps(cwd) {
|
|
14
|
+
return {
|
|
15
|
+
env: process.env,
|
|
16
|
+
readEvent: async (path2) => {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(await readFile(path2, "utf8"));
|
|
19
|
+
} catch {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
resolveCommit: (ref) => resolveCommit(cwd, ref),
|
|
24
|
+
mergeBase: (a, b) => mergeBase(cwd, a, b),
|
|
25
|
+
defaultBranch: () => defaultBranchRef(cwd)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var ZERO_SHA = /^0+$/;
|
|
29
|
+
function field(value, ...keys) {
|
|
30
|
+
let current = value;
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
if (typeof current !== "object" || current === null) return void 0;
|
|
33
|
+
current = current[key];
|
|
34
|
+
}
|
|
35
|
+
return current;
|
|
36
|
+
}
|
|
37
|
+
function isPullRequest(env) {
|
|
38
|
+
const event = env["GITHUB_EVENT_NAME"];
|
|
39
|
+
return env["GITHUB_ACTIONS"] === "true" && (event === "pull_request" || event === "pull_request_target") && (env["GITHUB_BASE_REF"] ?? "") !== "";
|
|
40
|
+
}
|
|
41
|
+
async function readEvent(deps) {
|
|
42
|
+
const path2 = deps.env["GITHUB_EVENT_PATH"];
|
|
43
|
+
return path2 === void 0 || path2 === "" ? void 0 : deps.readEvent(path2);
|
|
44
|
+
}
|
|
45
|
+
async function resolveChangeBase(explicit, deps) {
|
|
46
|
+
if (explicit !== void 0) {
|
|
47
|
+
return { ref: explicit, source: "flag", label: explicit };
|
|
48
|
+
}
|
|
49
|
+
const fromEnvironment = deps.env["VARIANT_BASE"];
|
|
50
|
+
if (fromEnvironment !== void 0 && fromEnvironment !== "") {
|
|
51
|
+
return {
|
|
52
|
+
ref: fromEnvironment,
|
|
53
|
+
source: "environment",
|
|
54
|
+
label: `${fromEnvironment} (VARIANT_BASE)`
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (isPullRequest(deps.env)) {
|
|
58
|
+
const target = `origin/${deps.env["GITHUB_BASE_REF"]}`;
|
|
59
|
+
if (await deps.resolveCommit(target) === null) {
|
|
60
|
+
throw new GitRefError(
|
|
61
|
+
`The pull request's target branch, "${target}", is not in this clone`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
const fork = await deps.mergeBase("HEAD", target);
|
|
65
|
+
if (fork === null) {
|
|
66
|
+
throw new GitRefError(
|
|
67
|
+
`"${target}" shares no history with HEAD in this clone`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
const pushed = field(await readEvent(deps), "pull_request", "head", "sha");
|
|
71
|
+
return {
|
|
72
|
+
ref: fork,
|
|
73
|
+
source: "pull-request",
|
|
74
|
+
label: `merge base with ${target}`,
|
|
75
|
+
...typeof pushed === "string" && pushed !== "" && { headSha: pushed }
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (deps.env["GITHUB_ACTIONS"] === "true" && deps.env["GITHUB_EVENT_NAME"] === "push") {
|
|
79
|
+
const before = field(await readEvent(deps), "before");
|
|
80
|
+
if (typeof before !== "string" || before === "" || ZERO_SHA.test(before) || await deps.resolveCommit(before) === null) {
|
|
81
|
+
throw new NoBaseCommitError();
|
|
82
|
+
}
|
|
83
|
+
const pushed = deps.env["GITHUB_SHA"];
|
|
84
|
+
return {
|
|
85
|
+
ref: before,
|
|
86
|
+
source: "push",
|
|
87
|
+
label: "the commit this push replaced",
|
|
88
|
+
...pushed !== void 0 && pushed !== "" && { headSha: pushed }
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const branch = await deps.defaultBranch();
|
|
92
|
+
if (branch !== null) {
|
|
93
|
+
const [fork, head] = await Promise.all([
|
|
94
|
+
deps.mergeBase("HEAD", branch),
|
|
95
|
+
deps.resolveCommit("HEAD")
|
|
96
|
+
]);
|
|
97
|
+
if (fork !== null && fork !== head) {
|
|
98
|
+
return {
|
|
99
|
+
ref: fork,
|
|
100
|
+
source: "default-branch",
|
|
101
|
+
label: `merge base with ${branch}`
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { ref: "HEAD~1", source: "previous-commit", label: "previous commit" };
|
|
106
|
+
}
|
|
107
|
+
async function resolvePullRequestBase(explicit, deps) {
|
|
108
|
+
if (explicit !== void 0) return explicit;
|
|
109
|
+
if (isPullRequest(deps.env)) return `origin/${deps.env["GITHUB_BASE_REF"]}`;
|
|
110
|
+
return await deps.defaultBranch() ?? "main";
|
|
111
|
+
}
|
|
112
|
+
async function detectHeadSha(deps) {
|
|
113
|
+
if (deps.env["GITHUB_ACTIONS"] !== "true") return void 0;
|
|
114
|
+
if (isPullRequest(deps.env)) {
|
|
115
|
+
const pushed = field(await readEvent(deps), "pull_request", "head", "sha");
|
|
116
|
+
return typeof pushed === "string" && pushed !== "" ? pushed : void 0;
|
|
117
|
+
}
|
|
118
|
+
const sha = deps.env["GITHUB_SHA"];
|
|
119
|
+
return deps.env["GITHUB_EVENT_NAME"] === "push" && sha !== void 0 && sha !== "" ? sha : void 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/core/history/impact-log.ts
|
|
123
|
+
import { appendFile, mkdir, readFile as readFile2, writeFile } from "fs/promises";
|
|
124
|
+
import path from "path";
|
|
125
|
+
var MAX_IMPACT_RECORDS = 1e3;
|
|
126
|
+
var LOG_FILENAME = "impact.jsonl";
|
|
127
|
+
var RECONCILIATION_FILENAME = "reconciliation.jsonl";
|
|
128
|
+
function defaultHistoryDir(cwd) {
|
|
129
|
+
return path.join(cwd, ".variant", "history");
|
|
130
|
+
}
|
|
131
|
+
async function appendImpactPrediction(historyDir, prediction) {
|
|
132
|
+
return appendRecord(historyDir, LOG_FILENAME, prediction);
|
|
133
|
+
}
|
|
134
|
+
async function appendReconciliation(historyDir, reconciliation) {
|
|
135
|
+
return appendRecord(historyDir, RECONCILIATION_FILENAME, reconciliation);
|
|
136
|
+
}
|
|
137
|
+
async function appendRecord(historyDir, filename, record) {
|
|
138
|
+
try {
|
|
139
|
+
await mkdir(historyDir, { recursive: true });
|
|
140
|
+
const file = path.join(historyDir, filename);
|
|
141
|
+
await appendFile(file, `${JSON.stringify(record)}
|
|
142
|
+
`);
|
|
143
|
+
const lines = (await readFile2(file, "utf8")).split("\n").filter((l) => l.trim() !== "");
|
|
144
|
+
if (lines.length > MAX_IMPACT_RECORDS) {
|
|
145
|
+
await writeFile(file, `${lines.slice(-MAX_IMPACT_RECORDS).join("\n")}
|
|
146
|
+
`);
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
} catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function readImpactPredictions(historyDir) {
|
|
154
|
+
return readRecords(historyDir, LOG_FILENAME);
|
|
155
|
+
}
|
|
156
|
+
async function readRecords(historyDir, filename) {
|
|
157
|
+
let raw;
|
|
158
|
+
try {
|
|
159
|
+
raw = await readFile2(path.join(historyDir, filename), "utf8");
|
|
160
|
+
} catch {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
const out = [];
|
|
164
|
+
for (const line of raw.split("\n")) {
|
|
165
|
+
const trimmed = line.trim();
|
|
166
|
+
if (trimmed === "") continue;
|
|
167
|
+
try {
|
|
168
|
+
out.push(JSON.parse(trimmed));
|
|
169
|
+
} catch {
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export {
|
|
176
|
+
defaultHistoryDir,
|
|
177
|
+
appendImpactPrediction,
|
|
178
|
+
appendReconciliation,
|
|
179
|
+
readImpactPredictions,
|
|
180
|
+
changeBaseDeps,
|
|
181
|
+
resolveChangeBase,
|
|
182
|
+
resolvePullRequestBase,
|
|
183
|
+
detectHeadSha
|
|
184
|
+
};
|