@tacuchi/updater 2.1.1 → 2.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.
Files changed (2) hide show
  1. package/dist/cli.js +127 -23
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -589,17 +589,42 @@ function logCommand(rec) {
589
589
  }
590
590
  addToMemory("debug", `$ ${rec.cmd} (${status})`);
591
591
  }
592
+ function formatResultLines(r) {
593
+ const id = r.managerId ?? "?";
594
+ const reason = r.reason ? ` reason=${r.reason}` : "";
595
+ const reboot = r.reboot ? ` reboot=${r.reboot}` : "";
596
+ const lines = [`${id}: status=${r.status} upgraded=${r.upgraded} failed=${r.failed}${reason}${reboot}`];
597
+ if (r.startedAt !== void 0 && r.finishedAt !== void 0) {
598
+ lines.push(` ${id}: duration=${r.finishedAt - r.startedAt}ms`);
599
+ }
600
+ for (const p of r.packages ?? []) {
601
+ const ver = p.fromVersion || p.toVersion ? ` ${p.fromVersion ?? "?"}->${p.toVersion ?? "?"}` : "";
602
+ lines.push(` ${id}: ${p.name}${ver} [${p.outcome}]`);
603
+ }
604
+ return lines;
605
+ }
592
606
  function logResult(r) {
593
607
  const id = r.managerId ?? "?";
594
608
  const ok = r.status === "success" || r.status === "noop";
595
609
  const level = ok ? "INFO" : r.status === "partial" ? "WARN" : "ERROR";
596
- const reason = r.reason ? ` reason=${r.reason}` : "";
597
- const reboot = r.reboot ? ` reboot=${r.reboot}` : "";
598
- writeRaw(level, `${id}: status=${r.status} upgraded=${r.upgraded} failed=${r.failed}${reason}${reboot}`);
610
+ for (const line of formatResultLines(r)) writeRaw(level, line);
599
611
  for (const e of r.errors) writeRaw(level, ` ${id}: ${e}`);
600
612
  const memLevel = ok ? "info" : r.status === "partial" ? "warn" : "error";
601
613
  addToMemory(memLevel, `${id}: ${r.status} (${r.upgraded} ok, ${r.failed} fail)`);
602
614
  }
615
+ function formatRunSummary(s) {
616
+ const lines = ["\u2500\u2500\u2500\u2500 Resumen del run \u2500\u2500\u2500\u2500"];
617
+ for (const m of s.managers) {
618
+ const dur = m.durationMs !== void 0 ? ` ${m.durationMs}ms` : "";
619
+ lines.push(` ${m.id}: ${m.status} (${m.upgraded} ok, ${m.failed} fail)${dur}`);
620
+ }
621
+ lines.push(`Total: ${s.upgraded} upgraded \xB7 ${s.failed} failed \xB7 ${s.skipped} skipped`);
622
+ return lines;
623
+ }
624
+ function logRunSummary(s) {
625
+ for (const line of formatRunSummary(s)) writeRaw("INFO", line);
626
+ addToMemory("info", `Resumen: ${s.upgraded} ok \xB7 ${s.failed} fail \xB7 ${s.skipped} skip`);
627
+ }
603
628
  function getLogFilePath() {
604
629
  return logFilePath;
605
630
  }
@@ -736,7 +761,23 @@ async function verifySnapshot(d, c, deps, manager, _requested) {
736
761
  return { stillOutdated: still.map((p) => ({ name: p.name, currentVersion: p.currentVersion, newVersion: p.newVersion })) };
737
762
  }
738
763
 
764
+ // src/lib/exec/percent.ts
765
+ function clamp(n) {
766
+ return Math.max(0, Math.min(100, n));
767
+ }
768
+ function makeFractionParser(re) {
769
+ return (line) => {
770
+ const m = line.match(re);
771
+ if (!m) return void 0;
772
+ const num = Number(m[1]);
773
+ const den = Number(m[2]);
774
+ if (!den || Number.isNaN(num) || Number.isNaN(den)) return void 0;
775
+ return clamp(Math.round(num / den * 100));
776
+ };
777
+ }
778
+
739
779
  // src/managers/descriptors/brew.ts
780
+ var brewUpgradePercent = makeFractionParser(/Upgrading (\d+)\/(\d+)/);
740
781
  function parseBrewOutdated(stdout) {
741
782
  try {
742
783
  const data = JSON.parse(stdout);
@@ -764,7 +805,8 @@ var brew = {
764
805
  parseOutdated: (stdout) => parseBrewOutdated(stdout),
765
806
  preUpgradeCmds: () => [{ cmd: "brew", args: ["update"] }],
766
807
  upgradeCmd: (pkgs) => ({ cmd: "brew", args: pkgs && pkgs.length ? ["upgrade", ...pkgs] : ["upgrade"] }),
767
- postUpgradeCmds: () => [{ cmd: "brew", args: ["cleanup"] }]
808
+ postUpgradeCmds: () => [{ cmd: "brew", args: ["cleanup"] }],
809
+ percentParser: (line) => brewUpgradePercent(line)
768
810
  };
769
811
 
770
812
  // src/lib/exec/capabilities.ts
@@ -1087,7 +1129,12 @@ var winget = {
1087
1129
  if (!targets.length) {
1088
1130
  yield* run(["upgrade", "--all", "--include-unknown", "--include-pinned", ...UPGRADE_FLAGS]);
1089
1131
  } else {
1090
- for (const id of targets) yield* run(["upgrade", "--exact", "--id", id, "--include-unknown", ...UPGRADE_FLAGS]);
1132
+ const n = targets.length;
1133
+ for (let i = 0; i < n; i++) {
1134
+ const id = targets[i];
1135
+ yield* run(["upgrade", "--exact", "--id", id, "--include-unknown", ...UPGRADE_FLAGS]);
1136
+ yield { type: "progress", message: `(${i + 1}/${n}) ${id}`, percent: Math.round((i + 1) / n * 100) };
1137
+ }
1091
1138
  }
1092
1139
  yield { type: "phase", phase: "verifying", message: "Verificando resultado..." };
1093
1140
  const after = await listWinget();
@@ -1124,6 +1171,7 @@ var apt = {
1124
1171
  };
1125
1172
 
1126
1173
  // src/managers/descriptors/dnf.ts
1174
+ var dnfVerifyPercent = makeFractionParser(/Verifying\s*:\s*(\d+)\/(\d+)/);
1127
1175
  function parseDnfOutdated(stdout) {
1128
1176
  return stdout.split("\n").filter((l) => l.trim() && !l.startsWith("Last") && !l.startsWith("Obsoleting")).map((line) => {
1129
1177
  const cols = line.trim().split(/\s+/);
@@ -1150,7 +1198,8 @@ var dnf = {
1150
1198
  // Single bulk upgrade; the engine runs it under sudo when sudoMode is on and
1151
1199
  // shows manualCommand otherwise.
1152
1200
  upgradeCmd: () => ({ cmd: "dnf", args: ["upgrade", "-y"] }),
1153
- manualCommand: () => "sudo dnf upgrade"
1201
+ manualCommand: () => "sudo dnf upgrade",
1202
+ percentParser: (line) => dnfVerifyPercent(line)
1154
1203
  };
1155
1204
 
1156
1205
  // src/managers/descriptors/pacman.ts
@@ -2785,7 +2834,16 @@ function toManagerResult(r, logRef) {
2785
2834
  skipped: r.skipped ?? 0,
2786
2835
  failures,
2787
2836
  manualCommand: r.manualCommand,
2788
- reboot: r.reboot
2837
+ reboot: r.reboot,
2838
+ // Keep the per-package detail + engine timings the Summary needs (previously discarded).
2839
+ packages: r.packages?.map((p) => ({
2840
+ name: p.name,
2841
+ outcome: p.outcome,
2842
+ fromVersion: p.fromVersion,
2843
+ toVersion: p.toVersion
2844
+ })),
2845
+ startedAt: r.startedAt,
2846
+ finishedAt: r.finishedAt
2789
2847
  };
2790
2848
  }
2791
2849
  function summarizeRun(state) {
@@ -2801,11 +2859,13 @@ function summarizeRun(state) {
2801
2859
  managers.push({ id, status: "skipped", upgraded: 0, failed: 0 });
2802
2860
  continue;
2803
2861
  }
2804
- const u = e.result?.upgraded ?? 0;
2805
- const f = e.result?.failed ?? 0;
2862
+ const r = e.result;
2863
+ const u = r?.upgraded ?? 0;
2864
+ const f = r?.failed ?? 0;
2806
2865
  upgraded += u;
2807
2866
  failed += f;
2808
- managers.push({ id, status: e.status, upgraded: u, failed: f });
2867
+ const durationMs = r?.startedAt !== void 0 && r?.finishedAt !== void 0 ? r.finishedAt - r.startedAt : void 0;
2868
+ managers.push({ id, status: e.status, upgraded: u, failed: f, durationMs, packages: r?.packages });
2809
2869
  }
2810
2870
  return { upgraded, failed, skipped, managers };
2811
2871
  }
@@ -2984,6 +3044,10 @@ function useAppMachine(sudoMode2, nonInteractive2 = false) {
2984
3044
  } catch {
2985
3045
  }
2986
3046
  }, [state.phase]);
3047
+ useEffect(() => {
3048
+ if (state.phase !== "summary") return;
3049
+ logRunSummary(summarizeRun(state));
3050
+ }, [state.phase]);
2987
3051
  const relaunch = useCallback(() => {
2988
3052
  void (async () => {
2989
3053
  const ok = await relaunchElevated();
@@ -3152,6 +3216,10 @@ var ASCII_GLYPHS = {
3152
3216
  };
3153
3217
  var ASCII = shouldUseAscii(process.env, process.platform);
3154
3218
  var g = ASCII ? ASCII_GLYPHS : UNICODE;
3219
+ var NO_ANIM = ASCII || !process.stdout.isTTY;
3220
+ var SPINNER_UNICODE = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
3221
+ var SPINNER_ASCII = ["|", "/", "-", "\\"];
3222
+ var spinnerFrames = ASCII ? SPINNER_ASCII : SPINNER_UNICODE;
3155
3223
 
3156
3224
  // src/components/step-header.tsx
3157
3225
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
@@ -3197,6 +3265,7 @@ function StepHeader({ phase }) {
3197
3265
  }
3198
3266
 
3199
3267
  // src/components/status-glyph.tsx
3268
+ import { useEffect as useEffect2, useState } from "react";
3200
3269
  import { Text as Text2 } from "ink";
3201
3270
  import { jsx as jsx3 } from "react/jsx-runtime";
3202
3271
  var SPECS = {
@@ -3217,6 +3286,16 @@ function StatusGlyph({ status }) {
3217
3286
  const spec = SPECS[status];
3218
3287
  return /* @__PURE__ */ jsx3(Text2, { color: spec.color, children: spec.glyph });
3219
3288
  }
3289
+ function RunningGlyph() {
3290
+ const [i, setI] = useState(0);
3291
+ useEffect2(() => {
3292
+ if (NO_ANIM) return;
3293
+ const t3 = setInterval(() => setI((n) => (n + 1) % spinnerFrames.length), 90);
3294
+ return () => clearInterval(t3);
3295
+ }, []);
3296
+ const frame = NO_ANIM ? g.running : spinnerFrames[i] ?? g.running;
3297
+ return /* @__PURE__ */ jsx3(Text2, { color: SPECS.running.color, children: frame });
3298
+ }
3220
3299
 
3221
3300
  // src/screens/detect.tsx
3222
3301
  import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
@@ -3257,7 +3336,7 @@ function DetectScreen() {
3257
3336
  }
3258
3337
 
3259
3338
  // src/screens/select.tsx
3260
- import { useState } from "react";
3339
+ import { useState as useState2 } from "react";
3261
3340
  import { Box as Box3, Text as Text4 } from "ink";
3262
3341
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
3263
3342
  function clip(s, n) {
@@ -3265,7 +3344,7 @@ function clip(s, n) {
3265
3344
  }
3266
3345
  function SelectScreen() {
3267
3346
  const { state, toggleItem, selectAll, selectNone, goConfirm, openSettings } = useMachine();
3268
- const [cursor, setCursor] = useState(0);
3347
+ const [cursor, setCursor] = useState2(0);
3269
3348
  const rows = [];
3270
3349
  for (const id of state.order) {
3271
3350
  const m = state.managers[id];
@@ -3403,7 +3482,7 @@ function Row({ e, width }) {
3403
3482
  else if (e.status === "skipped") detail = e.manualCommand ?? "manual";
3404
3483
  else if (e.status === "failed") detail = e.result?.failures[0]?.message ?? "";
3405
3484
  return /* @__PURE__ */ jsxs5(Box5, { children: [
3406
- /* @__PURE__ */ jsx7(Box5, { width: 2, children: /* @__PURE__ */ jsx7(StatusGlyph, { status: e.status }) }),
3485
+ /* @__PURE__ */ jsx7(Box5, { width: 2, children: e.status === "running" ? /* @__PURE__ */ jsx7(RunningGlyph, {}) : /* @__PURE__ */ jsx7(StatusGlyph, { status: e.status }) }),
3407
3486
  /* @__PURE__ */ jsx7(Box5, { width: 16, children: /* @__PURE__ */ jsx7(Text6, { color: semantic.text, bold: e.status === "running", children: clip2(managerName(e.id), 15) }) }),
3408
3487
  /* @__PURE__ */ jsx7(Box5, { width: 13, children: /* @__PURE__ */ jsx7(Text6, { color: statusColor(e.status), children: t("status", e.status) }) }),
3409
3488
  /* @__PURE__ */ jsx7(Text6, { color: semantic.muted, children: clip2(detail, Math.max(0, width - 33)) })
@@ -3458,14 +3537,42 @@ function UpdateScreen() {
3458
3537
  // src/screens/summary.tsx
3459
3538
  import { Box as Box6, Text as Text7 } from "ink";
3460
3539
  import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
3540
+ function versionDelta(m) {
3541
+ const ups = (m.packages ?? []).filter((p2) => p2.outcome === "upgraded" && p2.toVersion);
3542
+ if (ups.length !== 1) return "";
3543
+ const p = ups[0];
3544
+ return p.fromVersion ? `${p.name} ${p.fromVersion} ${g.arrow} ${p.toVersion}` : `${p.name} ${g.arrow} ${p.toVersion}`;
3545
+ }
3546
+ function ManagerRow({ m }) {
3547
+ const dur = m.durationMs !== void 0 ? `${(m.durationMs / 1e3).toFixed(1)}s` : "";
3548
+ return /* @__PURE__ */ jsxs6(Box6, { children: [
3549
+ /* @__PURE__ */ jsx8(Box6, { width: 2, children: /* @__PURE__ */ jsx8(StatusGlyph, { status: m.status }) }),
3550
+ /* @__PURE__ */ jsx8(Box6, { width: 14, children: /* @__PURE__ */ jsx8(Text7, { color: semantic.text, wrap: "truncate-end", children: managerName(m.id) }) }),
3551
+ /* @__PURE__ */ jsxs6(Box6, { width: 9, children: [
3552
+ m.upgraded > 0 ? /* @__PURE__ */ jsxs6(Text7, { color: semantic.success, children: [
3553
+ g.done,
3554
+ " ",
3555
+ m.upgraded
3556
+ ] }) : null,
3557
+ m.failed > 0 ? /* @__PURE__ */ jsxs6(Text7, { color: semantic.error, children: [
3558
+ " ",
3559
+ g.failed,
3560
+ " ",
3561
+ m.failed
3562
+ ] }) : null
3563
+ ] }),
3564
+ /* @__PURE__ */ jsx8(Box6, { flexGrow: 1, children: /* @__PURE__ */ jsx8(Text7, { color: semantic.muted, wrap: "truncate-end", children: versionDelta(m) }) }),
3565
+ /* @__PURE__ */ jsx8(Box6, { width: 7, justifyContent: "flex-end", children: /* @__PURE__ */ jsx8(Text7, { color: semantic.muted, children: dur }) })
3566
+ ] });
3567
+ }
3461
3568
  function SummaryScreen() {
3462
3569
  const { state, rescan } = useMachine();
3463
3570
  useSafeInput((input) => {
3464
3571
  if (input === "r" || input === "R") rescan();
3465
3572
  });
3466
- let upgraded = 0;
3467
- let failed = 0;
3468
- let skipped = 0;
3573
+ const summary = summarizeRun(state);
3574
+ const { upgraded, failed, skipped } = summary;
3575
+ const hasErrors = failed > 0;
3469
3576
  const failures = [];
3470
3577
  const manuals = [];
3471
3578
  const reboots = [];
@@ -3473,19 +3580,15 @@ function SummaryScreen() {
3473
3580
  const e = state.managers[id];
3474
3581
  if (!e) continue;
3475
3582
  if (e.status === "skipped") {
3476
- skipped++;
3477
3583
  if (e.manualCommand) manuals.push({ manager: id, command: e.manualCommand });
3478
3584
  continue;
3479
3585
  }
3480
3586
  const r = e.result;
3481
3587
  if (r) {
3482
- upgraded += r.upgraded;
3483
- failed += r.failed;
3484
3588
  for (const f of r.failures) failures.push({ manager: id, package: f.package, message: f.message, kind: f.kind });
3485
3589
  if (r.reboot) reboots.push({ manager: id, state: r.reboot });
3486
3590
  }
3487
3591
  }
3488
- const hasErrors = failed > 0;
3489
3592
  return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
3490
3593
  /* @__PURE__ */ jsx8(StepHeader, { phase: state.phase }),
3491
3594
  /* @__PURE__ */ jsx8(Box6, { marginBottom: 1, children: /* @__PURE__ */ jsx8(Text7, { color: hasErrors ? semantic.error : semantic.success, bold: true, children: hasErrors ? `${g.failed} ${t("ui", "withErrors")}` : `${g.done} ${t("ui", "allDone")}` }) }),
@@ -3508,6 +3611,7 @@ function SummaryScreen() {
3508
3611
  t("ui", "skipped")
3509
3612
  ] })
3510
3613
  ] }),
3614
+ summary.managers.length > 0 && /* @__PURE__ */ jsx8(Box6, { flexDirection: "column", marginBottom: 1, children: summary.managers.map((m) => /* @__PURE__ */ jsx8(ManagerRow, { m }, m.id)) }),
3511
3615
  failures.length > 0 && /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", marginBottom: 1, children: [
3512
3616
  failures.slice(0, 8).map((f, i) => /* @__PURE__ */ jsxs6(Text7, { color: semantic.error, wrap: "truncate-end", children: [
3513
3617
  g.failed,
@@ -3541,7 +3645,7 @@ function SummaryScreen() {
3541
3645
  " Reinicio pendiente: ",
3542
3646
  reboots.map((r) => `${managerName(r.manager)} (${r.state})`).join(", ")
3543
3647
  ] }) }),
3544
- hasErrors && /* @__PURE__ */ jsxs6(Text7, { color: semantic.muted, children: [
3648
+ /* @__PURE__ */ jsxs6(Text7, { color: semantic.muted, children: [
3545
3649
  t("ui", "logAt"),
3546
3650
  " ",
3547
3651
  getLogFilePath() ?? "~/.tacuchi-updater/logs/"
@@ -3551,13 +3655,13 @@ function SummaryScreen() {
3551
3655
  }
3552
3656
 
3553
3657
  // src/screens/settings-screen.tsx
3554
- import { useState as useState2 } from "react";
3658
+ import { useState as useState3 } from "react";
3555
3659
  import { Box as Box7, Text as Text8 } from "ink";
3556
3660
  import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
3557
3661
  function SettingsScreen() {
3558
3662
  const { state, toggleEnabled, setLang, closeSettings } = useMachine();
3559
3663
  const ids = state.order;
3560
- const [cursor, setCursor] = useState2(0);
3664
+ const [cursor, setCursor] = useState3(0);
3561
3665
  const clamped = Math.min(cursor, Math.max(0, ids.length - 1));
3562
3666
  useSafeInput((input, key) => {
3563
3667
  if (key.escape) closeSettings();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tacuchi/updater",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "CLI multiplataforma para actualizar gestores de paquetes del sistema",
5
5
  "type": "module",
6
6
  "bin": {