@tacuchi/updater 2.1.0 → 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 +142 -25
  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
@@ -781,6 +823,19 @@ function once(key, fn) {
781
823
  function pipCmd() {
782
824
  return process.platform === "win32" ? "pip" : "pip3";
783
825
  }
826
+ function pipInvocation(python) {
827
+ return python ? { cmd: python, baseArgs: ["-m", "pip"] } : { cmd: pipCmd(), baseArgs: [] };
828
+ }
829
+ async function pythonModuleCmd() {
830
+ return once("pip:python", async () => {
831
+ const candidates = process.platform === "win32" ? ["python", "py", "python3"] : ["python3", "python"];
832
+ for (const c of candidates) {
833
+ const probe = await execCommand(c, ["-m", "pip", "--version"], 5e3);
834
+ if (probe.exitCode === 0) return c;
835
+ }
836
+ return null;
837
+ });
838
+ }
784
839
  function parsePipOutdated(stdout) {
785
840
  try {
786
841
  const data = JSON.parse(stdout);
@@ -817,15 +872,15 @@ var pip = {
817
872
  escapeHatch: {
818
873
  listOutdated,
819
874
  async *upgrade(packages, ctx) {
820
- const cmd = pipCmd();
821
875
  yield { type: "phase", phase: "upgrading", message: "Actualizando pip..." };
822
876
  const flags = await pep668Flags();
823
877
  if (flags.length) yield { type: "log", message: "Entorno PEP 668: usando --break-system-packages" };
878
+ const { cmd, baseArgs } = pipInvocation(await pythonModuleCmd());
824
879
  const before = await listOutdated();
825
880
  const target = packages && packages.length ? packages : before.map((p) => p.name);
826
881
  const commands = [];
827
882
  if (target.length) {
828
- const args2 = ["install", "--user", "--upgrade", ...flags, ...target];
883
+ const args2 = [...baseArgs, "install", "--user", "--upgrade", ...flags, ...target];
829
884
  yield { type: "log", message: `${cmd} ${args2.join(" ")}` };
830
885
  const rec = yield* runStream(cmd, args2, { timeoutMs: 3e5, sudo: false, signal: ctx.signal });
831
886
  commands.push(rec);
@@ -1074,7 +1129,12 @@ var winget = {
1074
1129
  if (!targets.length) {
1075
1130
  yield* run(["upgrade", "--all", "--include-unknown", "--include-pinned", ...UPGRADE_FLAGS]);
1076
1131
  } else {
1077
- 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
+ }
1078
1138
  }
1079
1139
  yield { type: "phase", phase: "verifying", message: "Verificando resultado..." };
1080
1140
  const after = await listWinget();
@@ -1111,6 +1171,7 @@ var apt = {
1111
1171
  };
1112
1172
 
1113
1173
  // src/managers/descriptors/dnf.ts
1174
+ var dnfVerifyPercent = makeFractionParser(/Verifying\s*:\s*(\d+)\/(\d+)/);
1114
1175
  function parseDnfOutdated(stdout) {
1115
1176
  return stdout.split("\n").filter((l) => l.trim() && !l.startsWith("Last") && !l.startsWith("Obsoleting")).map((line) => {
1116
1177
  const cols = line.trim().split(/\s+/);
@@ -1137,7 +1198,8 @@ var dnf = {
1137
1198
  // Single bulk upgrade; the engine runs it under sudo when sudoMode is on and
1138
1199
  // shows manualCommand otherwise.
1139
1200
  upgradeCmd: () => ({ cmd: "dnf", args: ["upgrade", "-y"] }),
1140
- manualCommand: () => "sudo dnf upgrade"
1201
+ manualCommand: () => "sudo dnf upgrade",
1202
+ percentParser: (line) => dnfVerifyPercent(line)
1141
1203
  };
1142
1204
 
1143
1205
  // src/managers/descriptors/pacman.ts
@@ -2772,7 +2834,16 @@ function toManagerResult(r, logRef) {
2772
2834
  skipped: r.skipped ?? 0,
2773
2835
  failures,
2774
2836
  manualCommand: r.manualCommand,
2775
- 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
2776
2847
  };
2777
2848
  }
2778
2849
  function summarizeRun(state) {
@@ -2788,11 +2859,13 @@ function summarizeRun(state) {
2788
2859
  managers.push({ id, status: "skipped", upgraded: 0, failed: 0 });
2789
2860
  continue;
2790
2861
  }
2791
- const u = e.result?.upgraded ?? 0;
2792
- const f = e.result?.failed ?? 0;
2862
+ const r = e.result;
2863
+ const u = r?.upgraded ?? 0;
2864
+ const f = r?.failed ?? 0;
2793
2865
  upgraded += u;
2794
2866
  failed += f;
2795
- 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 });
2796
2869
  }
2797
2870
  return { upgraded, failed, skipped, managers };
2798
2871
  }
@@ -2971,6 +3044,10 @@ function useAppMachine(sudoMode2, nonInteractive2 = false) {
2971
3044
  } catch {
2972
3045
  }
2973
3046
  }, [state.phase]);
3047
+ useEffect(() => {
3048
+ if (state.phase !== "summary") return;
3049
+ logRunSummary(summarizeRun(state));
3050
+ }, [state.phase]);
2974
3051
  const relaunch = useCallback(() => {
2975
3052
  void (async () => {
2976
3053
  const ok = await relaunchElevated();
@@ -3139,6 +3216,10 @@ var ASCII_GLYPHS = {
3139
3216
  };
3140
3217
  var ASCII = shouldUseAscii(process.env, process.platform);
3141
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;
3142
3223
 
3143
3224
  // src/components/step-header.tsx
3144
3225
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
@@ -3184,6 +3265,7 @@ function StepHeader({ phase }) {
3184
3265
  }
3185
3266
 
3186
3267
  // src/components/status-glyph.tsx
3268
+ import { useEffect as useEffect2, useState } from "react";
3187
3269
  import { Text as Text2 } from "ink";
3188
3270
  import { jsx as jsx3 } from "react/jsx-runtime";
3189
3271
  var SPECS = {
@@ -3204,6 +3286,16 @@ function StatusGlyph({ status }) {
3204
3286
  const spec = SPECS[status];
3205
3287
  return /* @__PURE__ */ jsx3(Text2, { color: spec.color, children: spec.glyph });
3206
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
+ }
3207
3299
 
3208
3300
  // src/screens/detect.tsx
3209
3301
  import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
@@ -3244,7 +3336,7 @@ function DetectScreen() {
3244
3336
  }
3245
3337
 
3246
3338
  // src/screens/select.tsx
3247
- import { useState } from "react";
3339
+ import { useState as useState2 } from "react";
3248
3340
  import { Box as Box3, Text as Text4 } from "ink";
3249
3341
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
3250
3342
  function clip(s, n) {
@@ -3252,7 +3344,7 @@ function clip(s, n) {
3252
3344
  }
3253
3345
  function SelectScreen() {
3254
3346
  const { state, toggleItem, selectAll, selectNone, goConfirm, openSettings } = useMachine();
3255
- const [cursor, setCursor] = useState(0);
3347
+ const [cursor, setCursor] = useState2(0);
3256
3348
  const rows = [];
3257
3349
  for (const id of state.order) {
3258
3350
  const m = state.managers[id];
@@ -3390,7 +3482,7 @@ function Row({ e, width }) {
3390
3482
  else if (e.status === "skipped") detail = e.manualCommand ?? "manual";
3391
3483
  else if (e.status === "failed") detail = e.result?.failures[0]?.message ?? "";
3392
3484
  return /* @__PURE__ */ jsxs5(Box5, { children: [
3393
- /* @__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 }) }),
3394
3486
  /* @__PURE__ */ jsx7(Box5, { width: 16, children: /* @__PURE__ */ jsx7(Text6, { color: semantic.text, bold: e.status === "running", children: clip2(managerName(e.id), 15) }) }),
3395
3487
  /* @__PURE__ */ jsx7(Box5, { width: 13, children: /* @__PURE__ */ jsx7(Text6, { color: statusColor(e.status), children: t("status", e.status) }) }),
3396
3488
  /* @__PURE__ */ jsx7(Text6, { color: semantic.muted, children: clip2(detail, Math.max(0, width - 33)) })
@@ -3445,14 +3537,42 @@ function UpdateScreen() {
3445
3537
  // src/screens/summary.tsx
3446
3538
  import { Box as Box6, Text as Text7 } from "ink";
3447
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
+ }
3448
3568
  function SummaryScreen() {
3449
3569
  const { state, rescan } = useMachine();
3450
3570
  useSafeInput((input) => {
3451
3571
  if (input === "r" || input === "R") rescan();
3452
3572
  });
3453
- let upgraded = 0;
3454
- let failed = 0;
3455
- let skipped = 0;
3573
+ const summary = summarizeRun(state);
3574
+ const { upgraded, failed, skipped } = summary;
3575
+ const hasErrors = failed > 0;
3456
3576
  const failures = [];
3457
3577
  const manuals = [];
3458
3578
  const reboots = [];
@@ -3460,19 +3580,15 @@ function SummaryScreen() {
3460
3580
  const e = state.managers[id];
3461
3581
  if (!e) continue;
3462
3582
  if (e.status === "skipped") {
3463
- skipped++;
3464
3583
  if (e.manualCommand) manuals.push({ manager: id, command: e.manualCommand });
3465
3584
  continue;
3466
3585
  }
3467
3586
  const r = e.result;
3468
3587
  if (r) {
3469
- upgraded += r.upgraded;
3470
- failed += r.failed;
3471
3588
  for (const f of r.failures) failures.push({ manager: id, package: f.package, message: f.message, kind: f.kind });
3472
3589
  if (r.reboot) reboots.push({ manager: id, state: r.reboot });
3473
3590
  }
3474
3591
  }
3475
- const hasErrors = failed > 0;
3476
3592
  return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
3477
3593
  /* @__PURE__ */ jsx8(StepHeader, { phase: state.phase }),
3478
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")}` }) }),
@@ -3495,6 +3611,7 @@ function SummaryScreen() {
3495
3611
  t("ui", "skipped")
3496
3612
  ] })
3497
3613
  ] }),
3614
+ summary.managers.length > 0 && /* @__PURE__ */ jsx8(Box6, { flexDirection: "column", marginBottom: 1, children: summary.managers.map((m) => /* @__PURE__ */ jsx8(ManagerRow, { m }, m.id)) }),
3498
3615
  failures.length > 0 && /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", marginBottom: 1, children: [
3499
3616
  failures.slice(0, 8).map((f, i) => /* @__PURE__ */ jsxs6(Text7, { color: semantic.error, wrap: "truncate-end", children: [
3500
3617
  g.failed,
@@ -3528,7 +3645,7 @@ function SummaryScreen() {
3528
3645
  " Reinicio pendiente: ",
3529
3646
  reboots.map((r) => `${managerName(r.manager)} (${r.state})`).join(", ")
3530
3647
  ] }) }),
3531
- hasErrors && /* @__PURE__ */ jsxs6(Text7, { color: semantic.muted, children: [
3648
+ /* @__PURE__ */ jsxs6(Text7, { color: semantic.muted, children: [
3532
3649
  t("ui", "logAt"),
3533
3650
  " ",
3534
3651
  getLogFilePath() ?? "~/.tacuchi-updater/logs/"
@@ -3538,13 +3655,13 @@ function SummaryScreen() {
3538
3655
  }
3539
3656
 
3540
3657
  // src/screens/settings-screen.tsx
3541
- import { useState as useState2 } from "react";
3658
+ import { useState as useState3 } from "react";
3542
3659
  import { Box as Box7, Text as Text8 } from "ink";
3543
3660
  import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
3544
3661
  function SettingsScreen() {
3545
3662
  const { state, toggleEnabled, setLang, closeSettings } = useMachine();
3546
3663
  const ids = state.order;
3547
- const [cursor, setCursor] = useState2(0);
3664
+ const [cursor, setCursor] = useState3(0);
3548
3665
  const clamped = Math.min(cursor, Math.max(0, ids.length - 1));
3549
3666
  useSafeInput((input, key) => {
3550
3667
  if (key.escape) closeSettings();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tacuchi/updater",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "CLI multiplataforma para actualizar gestores de paquetes del sistema",
5
5
  "type": "module",
6
6
  "bin": {