@nmakarov/cli-toolkit 0.76.0 → 0.78.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/dist/index.js CHANGED
@@ -5181,6 +5181,8 @@ var Logger = class _Logger {
5181
5181
  options;
5182
5182
  transport;
5183
5183
  startTimes = {};
5184
+ /** Count at the first progress sample for each prefix (rate baseline). */
5185
+ startCounts = {};
5184
5186
  lastProgressTimes = {};
5185
5187
  constructor(context, options = {}) {
5186
5188
  this.context = context;
@@ -5316,15 +5318,17 @@ var Logger = class _Logger {
5316
5318
  total,
5317
5319
  prefix
5318
5320
  };
5319
- if (!this.startTimes[prefix ?? ""]) {
5320
- this.startTimes[prefix ?? ""] = Date.now();
5321
+ const key = prefix ?? "";
5322
+ if (this.startTimes[key] === void 0) {
5323
+ this.startTimes[key] = Date.now();
5324
+ this.startCounts[key] = count;
5321
5325
  }
5322
5326
  const wantTimes = this.options.progressTimes;
5323
5327
  const wantRate = this.options.progressRate;
5324
5328
  if (wantTimes || wantRate) {
5325
- const elapsedSeconds = (Date.now() - this.startTimes[prefix ?? ""]) / 1e3;
5326
- const intervals = count > 1 ? count - 1 : 0;
5327
- const itemsPerSec = intervals > 0 && elapsedSeconds > 0 ? intervals / elapsedSeconds : -1;
5329
+ const elapsedSeconds = (Date.now() - this.startTimes[key]) / 1e3;
5330
+ const done = count - (this.startCounts[key] ?? count);
5331
+ const itemsPerSec = done > 0 && elapsedSeconds > 0 ? done / elapsedSeconds : -1;
5328
5332
  if (wantTimes) {
5329
5333
  let remaining = -1;
5330
5334
  if (itemsPerSec > 0) {
@@ -5338,8 +5342,9 @@ var Logger = class _Logger {
5338
5342
  }
5339
5343
  }
5340
5344
  if (count >= total) {
5341
- delete this.startTimes[prefix ?? ""];
5342
- delete this.lastProgressTimes[prefix ?? ""];
5345
+ delete this.startTimes[key];
5346
+ delete this.startCounts[key];
5347
+ delete this.lastProgressTimes[key];
5343
5348
  }
5344
5349
  if (this.shouldOutputProgress(prefix ?? "", count, total)) {
5345
5350
  this.out(payload);
@@ -5903,16 +5908,28 @@ function isPidAlive(pid) {
5903
5908
  return false;
5904
5909
  }
5905
5910
  }
5911
+ function parsePm2Jlist(stdout) {
5912
+ const raw = String(stdout ?? "");
5913
+ const text = raw.split("\n").filter((line) => !line.startsWith("[PM2]")).join("\n").trim();
5914
+ if (!text) return [];
5915
+ try {
5916
+ const parsed = JSON.parse(text);
5917
+ return Array.isArray(parsed) ? parsed : [];
5918
+ } catch (err) {
5919
+ throw new Error(`pm2 jlist: invalid JSON (${err?.message ?? err})`);
5920
+ }
5921
+ }
5906
5922
  async function getPm2Process(appName, options = {}) {
5907
5923
  const { logger } = options;
5924
+ await runCapture("bash", ["-lc", "pm2 ping >/dev/null 2>&1 || true"], { logger }).catch(() => {
5925
+ });
5908
5926
  const { stdout } = await runCapture("bash", ["-lc", "pm2 jlist"], { logger });
5909
5927
  let list;
5910
5928
  try {
5911
- list = JSON.parse(stdout || "[]");
5929
+ list = parsePm2Jlist(stdout);
5912
5930
  } catch (err) {
5913
5931
  throw new Error(`pm2 jlist: invalid JSON (${err?.message ?? err})`);
5914
5932
  }
5915
- if (!Array.isArray(list)) return null;
5916
5933
  return list.find((p) => p?.name === appName) ?? null;
5917
5934
  }
5918
5935
  async function waitPm2(appName, predicate, options = {}) {
@@ -10107,6 +10124,7 @@ export {
10107
10124
  npmInstallEnv,
10108
10125
  organizeFooterMessages,
10109
10126
  parseGitHost,
10127
+ parsePm2Jlist,
10110
10128
  prepareGitHost,
10111
10129
  provisionService,
10112
10130
  pruneReleases,