@nmakarov/cli-toolkit 0.73.0 → 0.76.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));
@@ -5449,6 +5466,7 @@ function setup(opts = {}) {
5449
5466
  const partialContext = {
5450
5467
  emitter: new EventEmitter(),
5451
5468
  isStop: () => false,
5469
+ isKill: () => false,
5452
5470
  cleanupFunctions: [],
5453
5471
  registerCleanup: (fn) => {
5454
5472
  partialContext.cleanupFunctions.push(fn);
@@ -5470,6 +5488,7 @@ function setup(opts = {}) {
5470
5488
  logger,
5471
5489
  emitter: partialContext.emitter,
5472
5490
  isStop: partialContext.isStop,
5491
+ isKill: partialContext.isKill,
5473
5492
  cleanupFunctions: partialContext.cleanupFunctions,
5474
5493
  registerCleanup: partialContext.registerCleanup,
5475
5494
  // For long-running scripts (servers): with --showUsedParams=top, print
@@ -8358,6 +8377,7 @@ var LOGGER_RUNTIME_KEYS = [
8358
8377
  "route",
8359
8378
  "prefix",
8360
8379
  "progressWithTimes",
8380
+ "progressWithRate",
8361
8381
  "progressThrottleMs"
8362
8382
  ];
8363
8383
  var DEFAULT_RUNTIME_PARAM_SPECS = [
@@ -8469,6 +8489,7 @@ function coerceRuntimeValue(key, value) {
8469
8489
  case "showLevel":
8470
8490
  case "timestamp":
8471
8491
  case "progressWithTimes":
8492
+ case "progressWithRate":
8472
8493
  if (typeof value === "boolean") return value;
8473
8494
  if (value === "true" || value === "1") return true;
8474
8495
  if (value === "false" || value === "0") return false;