next-anteater 0.2.11 → 0.2.12
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/lib/scaffold.mjs +45 -0
- package/package.json +1 -1
package/lib/scaffold.mjs
CHANGED
|
@@ -166,6 +166,48 @@ async function patchRunsRouteMutationGuardIfMissing(path) {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
async function patchRunsRouteFailedTtlIfMissing(path) {
|
|
170
|
+
try {
|
|
171
|
+
const existing = await readFile(path, "utf-8");
|
|
172
|
+
if (existing.includes("failedCutoffMs")) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const replacement = [
|
|
177
|
+
" // Sort newest first, cap at 5",
|
|
178
|
+
" // Drop stale failed runs (>1h) so old errors don't clutter the bar",
|
|
179
|
+
" const failedCutoffMs = 60 * 60 * 1000;",
|
|
180
|
+
" const freshRuns = runs.filter((r) => {",
|
|
181
|
+
' if (r.step !== "error") return true;',
|
|
182
|
+
" const startedAtMs = new Date(r.startedAt).getTime();",
|
|
183
|
+
" if (Number.isNaN(startedAtMs)) return true;",
|
|
184
|
+
" return Date.now() - startedAtMs <= failedCutoffMs;",
|
|
185
|
+
" });",
|
|
186
|
+
"",
|
|
187
|
+
" freshRuns.sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime());",
|
|
188
|
+
"",
|
|
189
|
+
' return NextResponse.json' + (existing.includes("<AnteaterRunsResponse>") ? "<AnteaterRunsResponse>" : "") + "(",
|
|
190
|
+
" { runs: freshRuns.slice(0, 5), deploymentId: process.env.VERCEL_DEPLOYMENT_ID }",
|
|
191
|
+
" );",
|
|
192
|
+
].join("\n");
|
|
193
|
+
|
|
194
|
+
const sortAndReturnPattern =
|
|
195
|
+
/ \/\/ Sort newest first, cap at 5[\s\S]*? return NextResponse\.json(?:<AnteaterRunsResponse>)?\([\s\S]*?\n \);/;
|
|
196
|
+
if (!sortAndReturnPattern.test(existing)) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const patched = existing.replace(sortAndReturnPattern, replacement);
|
|
201
|
+
if (patched === existing) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
await writeFile(path, patched, "utf-8");
|
|
205
|
+
return true;
|
|
206
|
+
} catch {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
169
211
|
/**
|
|
170
212
|
* Generate anteater.config.ts
|
|
171
213
|
*/
|
|
@@ -1084,6 +1126,9 @@ export async function scaffoldFiles(cwd, options) {
|
|
|
1084
1126
|
if (await patchRunsRouteMutationGuardIfMissing(runsPath)) {
|
|
1085
1127
|
results.push(`${join(runsDir, runsRoute.filename)} (patched same-origin guard)`);
|
|
1086
1128
|
}
|
|
1129
|
+
if (await patchRunsRouteFailedTtlIfMissing(runsPath)) {
|
|
1130
|
+
results.push(`${join(runsDir, runsRoute.filename)} (patched failed-run TTL)`);
|
|
1131
|
+
}
|
|
1087
1132
|
}
|
|
1088
1133
|
|
|
1089
1134
|
// GitHub Action workflow
|