@reddoorla/maintenance 0.1.2 → 0.1.3

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/dist/cli/bin.js CHANGED
@@ -270,59 +270,64 @@ function extractAdvisoriesFromNpm(parsed) {
270
270
  }
271
271
  return [...roots.values()];
272
272
  }
273
- async function tryRun(spawn2, cmd, args, cwd) {
273
+ async function runAuditTool(spawn2, cmd, args, cwd) {
274
+ let raw;
274
275
  try {
275
- return await spawn2(cmd, args, { cwd });
276
+ raw = await spawn2(cmd, args, { cwd });
276
277
  } catch (err) {
277
278
  const e = err;
278
- if (e.code === "ENOENT" || /ENOENT/.test(String(err))) return { missing: true };
279
- throw err;
280
- }
281
- }
282
- async function securityAudit(ctx) {
283
- const spawn2 = ctx.spawn ?? defaultSpawn;
284
- const site = ctx.site;
285
- const label = siteLabel3(site);
286
- let used = "pnpm audit";
287
- let raw = await tryRun(
288
- spawn2,
289
- "pnpm",
290
- ["audit", "--json", "--prod"],
291
- site.path
292
- );
293
- if ("missing" in raw) {
294
- used = "npm audit";
295
- raw = await tryRun(spawn2, "npm", ["audit", "--json", "--omit=dev"], site.path);
296
- }
297
- if ("missing" in raw) {
298
- return {
299
- audit: "security",
300
- site: label,
301
- status: "skip",
302
- summary: "neither pnpm nor npm is available on PATH"
303
- };
279
+ if (e.code === "ENOENT" || /ENOENT/.test(String(err))) return { kind: "missing" };
280
+ return { kind: "error", reason: `spawn failed: ${String(err).slice(0, 200)}` };
304
281
  }
305
282
  if (raw.code !== 0 && raw.code !== 1) {
306
283
  return {
307
- audit: "security",
308
- site: label,
309
- status: "skip",
310
- summary: `${used} exited with code ${raw.code}`,
311
- details: { stderr: raw.stderr }
284
+ kind: "error",
285
+ reason: `exit ${raw.code}${raw.stderr ? `: ${raw.stderr.slice(0, 150)}` : ""}`
312
286
  };
313
287
  }
314
288
  let parsed;
315
289
  try {
316
- parsed = JSON.parse(raw.stdout);
290
+ parsed = JSON.parse(raw.stdout || "{}");
317
291
  } catch (err) {
318
- return {
319
- audit: "security",
320
- site: label,
321
- status: "skip",
322
- summary: `${used} produced unparseable JSON`,
323
- details: { error: String(err), stdout: raw.stdout.slice(0, 500) }
324
- };
292
+ return { kind: "error", reason: `unparseable JSON: ${String(err).slice(0, 100)}` };
293
+ }
294
+ const errEnvelope = parsed.error;
295
+ if (errEnvelope && typeof errEnvelope === "object") {
296
+ return { kind: "error", reason: errEnvelope.code ?? "error envelope returned" };
297
+ }
298
+ if (!parsed.metadata?.vulnerabilities) {
299
+ return { kind: "error", reason: "no metadata.vulnerabilities in output" };
300
+ }
301
+ return { kind: "ok", parsed };
302
+ }
303
+ async function securityAudit(ctx) {
304
+ const spawn2 = ctx.spawn ?? defaultSpawn;
305
+ const site = ctx.site;
306
+ const label = siteLabel3(site);
307
+ let used = "pnpm audit";
308
+ let result = await runAuditTool(spawn2, "pnpm", ["audit", "--json", "--prod"], site.path);
309
+ if (result.kind !== "ok") {
310
+ const pnpmReason = result.kind === "missing" ? "not installed" : result.reason;
311
+ const npmResult = await runAuditTool(
312
+ spawn2,
313
+ "npm",
314
+ ["audit", "--json", "--omit=dev"],
315
+ site.path
316
+ );
317
+ if (npmResult.kind === "ok") {
318
+ result = npmResult;
319
+ used = "npm audit";
320
+ } else {
321
+ const npmReason = npmResult.kind === "missing" ? "not installed" : npmResult.reason;
322
+ return {
323
+ audit: "security",
324
+ site: label,
325
+ status: "skip",
326
+ summary: `cannot run audit \u2014 pnpm: ${pnpmReason}; npm: ${npmReason}`
327
+ };
328
+ }
325
329
  }
330
+ const parsed = result.parsed;
326
331
  const counts = {
327
332
  low: parsed.metadata?.vulnerabilities?.low ?? 0,
328
333
  moderate: parsed.metadata?.vulnerabilities?.moderate ?? 0,