@nmakarov/cli-toolkit 0.75.0 → 0.77.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
@@ -5171,7 +5171,8 @@ var LEVEL_COLORS = {
5171
5171
  silly: chalk.gray,
5172
5172
  request: chalk.green,
5173
5173
  response: chalk.yellow,
5174
- progress: chalk.green,
5174
+ // Magenta stands out from white info / green request lines.
5175
+ progress: chalk.magentaBright,
5175
5176
  results: chalk.magenta
5176
5177
  };
5177
5178
  var Logger = class _Logger {
@@ -5190,7 +5191,8 @@ var Logger = class _Logger {
5190
5191
  this.updateTransport();
5191
5192
  }
5192
5193
  /**
5193
- * Configure logger options. Accepts both LoggerOptions shape and flat param names (levels string, progressWithTimes, progressThrottleMs).
5194
+ * Configure logger options. Accepts both LoggerOptions shape and flat param names
5195
+ * (levels string, progressWithTimes, progressWithRate, progressThrottleMs).
5194
5196
  */
5195
5197
  configure(options) {
5196
5198
  if (options.mode !== void 0) {
@@ -5210,10 +5212,12 @@ var Logger = class _Logger {
5210
5212
  }
5211
5213
  if (options.progress !== void 0) {
5212
5214
  if (options.progress.withTimes !== void 0) this.options.progressTimes = options.progress.withTimes;
5215
+ if (options.progress.withRate !== void 0) this.options.progressRate = options.progress.withRate;
5213
5216
  if (options.progress.throttleMs !== void 0) this.options.progressThrottle = options.progress.throttleMs;
5214
5217
  }
5215
5218
  const flat = options;
5216
5219
  if (flat.progressWithTimes !== void 0) this.options.progressTimes = flat.progressWithTimes;
5220
+ if (flat.progressWithRate !== void 0) this.options.progressRate = flat.progressWithRate;
5217
5221
  if (flat.progressThrottleMs !== void 0) this.options.progressThrottle = flat.progressThrottleMs;
5218
5222
  }
5219
5223
  /**
@@ -5230,6 +5234,7 @@ var Logger = class _Logger {
5230
5234
  timestamp: "boolean default false",
5231
5235
  levels: "string",
5232
5236
  progressWithTimes: "boolean default false",
5237
+ progressWithRate: "boolean default false",
5233
5238
  progressThrottleMs: "number"
5234
5239
  };
5235
5240
  const discovered = context.params.getAllForModule("logger", paramDefs);
@@ -5248,6 +5253,7 @@ var Logger = class _Logger {
5248
5253
  timestamp: false,
5249
5254
  levels: DEFAULT_LEVELS,
5250
5255
  progressTimes: false,
5256
+ progressRate: false,
5251
5257
  progressThrottle: void 0
5252
5258
  };
5253
5259
  }
@@ -5313,15 +5319,23 @@ var Logger = class _Logger {
5313
5319
  if (!this.startTimes[prefix ?? ""]) {
5314
5320
  this.startTimes[prefix ?? ""] = Date.now();
5315
5321
  }
5316
- if (this.options.progressTimes) {
5322
+ const wantTimes = this.options.progressTimes;
5323
+ const wantRate = this.options.progressRate;
5324
+ if (wantTimes || wantRate) {
5317
5325
  const elapsedSeconds = (Date.now() - this.startTimes[prefix ?? ""]) / 1e3;
5318
- let remaining = -1;
5319
- if (count > 1) {
5320
- const rate = elapsedSeconds / (count - 1);
5321
- remaining = (total - count) * rate;
5326
+ const intervals = count > 1 ? count - 1 : 0;
5327
+ const itemsPerSec = intervals > 0 && elapsedSeconds > 0 ? intervals / elapsedSeconds : -1;
5328
+ if (wantTimes) {
5329
+ let remaining = -1;
5330
+ if (itemsPerSec > 0) {
5331
+ remaining = (total - count) / itemsPerSec;
5332
+ }
5333
+ payload.elapsed = this.round(elapsedSeconds, 2);
5334
+ payload.remaining = remaining >= 0 ? this.round(remaining, 2) : remaining;
5335
+ }
5336
+ if (wantRate) {
5337
+ payload.rate = itemsPerSec >= 0 ? this.round(itemsPerSec, 2) : itemsPerSec;
5322
5338
  }
5323
- payload.elapsed = this.round(elapsedSeconds, 2);
5324
- payload.remaining = remaining >= 0 ? this.round(remaining, 2) : remaining;
5325
5339
  }
5326
5340
  if (count >= total) {
5327
5341
  delete this.startTimes[prefix ?? ""];
@@ -5386,10 +5400,13 @@ var Logger = class _Logger {
5386
5400
  parts.push(formatter.bold(struct.message));
5387
5401
  }
5388
5402
  if (struct.level === "progress") {
5403
+ const formatter = LEVEL_COLORS[struct.level];
5389
5404
  if (struct.elapsed !== void 0 && struct.remaining !== void 0) {
5390
- const formatter = LEVEL_COLORS[struct.level];
5391
5405
  parts.push(formatter(`${struct.elapsed}/${struct.remaining}`));
5392
5406
  }
5407
+ if (struct.rate !== void 0) {
5408
+ parts.push(formatter(struct.rate >= 0 ? `${struct.rate}/s` : "-/s"));
5409
+ }
5393
5410
  }
5394
5411
  if (struct.chunks && struct.chunks.length) {
5395
5412
  parts.push(this.inspectChunks(struct.chunks));
@@ -5886,16 +5903,28 @@ function isPidAlive(pid) {
5886
5903
  return false;
5887
5904
  }
5888
5905
  }
5906
+ function parsePm2Jlist(stdout) {
5907
+ const raw = String(stdout ?? "");
5908
+ const text = raw.split("\n").filter((line) => !line.startsWith("[PM2]")).join("\n").trim();
5909
+ if (!text) return [];
5910
+ try {
5911
+ const parsed = JSON.parse(text);
5912
+ return Array.isArray(parsed) ? parsed : [];
5913
+ } catch (err) {
5914
+ throw new Error(`pm2 jlist: invalid JSON (${err?.message ?? err})`);
5915
+ }
5916
+ }
5889
5917
  async function getPm2Process(appName, options = {}) {
5890
5918
  const { logger } = options;
5919
+ await runCapture("bash", ["-lc", "pm2 ping >/dev/null 2>&1 || true"], { logger }).catch(() => {
5920
+ });
5891
5921
  const { stdout } = await runCapture("bash", ["-lc", "pm2 jlist"], { logger });
5892
5922
  let list;
5893
5923
  try {
5894
- list = JSON.parse(stdout || "[]");
5924
+ list = parsePm2Jlist(stdout);
5895
5925
  } catch (err) {
5896
5926
  throw new Error(`pm2 jlist: invalid JSON (${err?.message ?? err})`);
5897
5927
  }
5898
- if (!Array.isArray(list)) return null;
5899
5928
  return list.find((p) => p?.name === appName) ?? null;
5900
5929
  }
5901
5930
  async function waitPm2(appName, predicate, options = {}) {
@@ -8360,6 +8389,7 @@ var LOGGER_RUNTIME_KEYS = [
8360
8389
  "route",
8361
8390
  "prefix",
8362
8391
  "progressWithTimes",
8392
+ "progressWithRate",
8363
8393
  "progressThrottleMs"
8364
8394
  ];
8365
8395
  var DEFAULT_RUNTIME_PARAM_SPECS = [
@@ -8471,6 +8501,7 @@ function coerceRuntimeValue(key, value) {
8471
8501
  case "showLevel":
8472
8502
  case "timestamp":
8473
8503
  case "progressWithTimes":
8504
+ case "progressWithRate":
8474
8505
  if (typeof value === "boolean") return value;
8475
8506
  if (value === "true" || value === "1") return true;
8476
8507
  if (value === "false" || value === "0") return false;
@@ -10088,6 +10119,7 @@ export {
10088
10119
  npmInstallEnv,
10089
10120
  organizeFooterMessages,
10090
10121
  parseGitHost,
10122
+ parsePm2Jlist,
10091
10123
  prepareGitHost,
10092
10124
  provisionService,
10093
10125
  pruneReleases,