visual-exec 1.0.2 → 1.1.1

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { VisualExec, VisualExecOptions, ExecOutput, ExecErrorContext, VisualExecError, parsers, jsonLinesParser, keyValueParser } from "./visual-exec.js";
1
+ export { VisualExec, type VisualExecOptions, type ExecOutput, type ExecErrorContext, type VisualExecError, parsers, jsonLinesParser, keyValueParser } from "./visual-exec.js";
2
2
  export type { OnOutputCallback, OnCompleteCallback, OutputFileOptions, ProgressExtractor, OutputMatcher } from "./visual-exec.js";
3
3
  export { getDefaultLogger } from "./get-default-logger.js";
4
4
  export { VisualExec as default } from "./visual-exec.js";
@@ -1,4 +1,4 @@
1
- import VisualLogger from "visual-logger";
1
+ import VisualLogger, { type ItemOptions } from "visual-logger";
2
2
  export type OutputStream = "stdout" | "stderr";
3
3
  /** Called on each chunk of stdout/stderr during execution */
4
4
  export type OnOutputCallback = (data: string, stream: OutputStream) => void;
@@ -40,7 +40,7 @@ export interface VisualExecOptions {
40
40
  /** Visual logger instance to use */
41
41
  visualLogger?: VisualLogger;
42
42
  /** Spinner style to use */
43
- spinner?: any;
43
+ spinner?: ItemOptions["spinner"];
44
44
  /** Title displayed during execution */
45
45
  displayTitle?: string;
46
46
  /** Label used in log messages */
@@ -192,7 +192,14 @@ export declare class VisualExec {
192
192
  abort(signal?: string): void;
193
193
  /** Alias for abort() */
194
194
  kill(signal?: string): void;
195
- show(child: ChildProcess): Promise<ExecOutput | unknown>;
195
+ /**
196
+ * Attach to an already-started child and render its output.
197
+ *
198
+ * Resolves with the command's `ExecOutput`, unless an `onComplete` callback returned a
199
+ * value - that value is passed through instead. `T` names what the caller expects back;
200
+ * it defaults to `ExecOutput`, which is what a run without an `onComplete` produces.
201
+ */
202
+ show<T = ExecOutput>(child: ChildProcess): Promise<T>;
196
203
  logResult(err: VisualExecError | null, output?: ExecOutput): void;
197
204
  checkForErrors(text: string): RegExpMatchArray | null;
198
205
  /**
@@ -200,6 +207,12 @@ export declare class VisualExec {
200
207
  * Set to a no-op function to suppress output logging.
201
208
  */
202
209
  logFinalOutput(err: VisualExecError | null, output: ExecOutput): void;
203
- execute(command?: string): Promise<ExecOutput | unknown>;
210
+ /**
211
+ * Run the command and render its output.
212
+ *
213
+ * Resolves with `ExecOutput`, or with whatever an `onComplete` callback returned in its
214
+ * place. `T` defaults to `ExecOutput` so the common case needs no cast at the call site.
215
+ */
216
+ execute<T = ExecOutput>(command?: string): Promise<T>;
204
217
  }
205
218
  export default VisualExec;
@@ -3,7 +3,7 @@ import chalk from "chalk";
3
3
  import * as fs from "fs";
4
4
  import * as path from "path";
5
5
  import { getDefaultLogger } from "./get-default-logger.js";
6
- import VisualLogger from "visual-logger";
6
+ import VisualLogger, {} from "visual-logger";
7
7
  import hasAnsi from "has-ansi";
8
8
  import stripAnsi from "strip-ansi";
9
9
  // Set xsh to use native Promise
@@ -294,6 +294,13 @@ export class VisualExec {
294
294
  kill(signal) {
295
295
  this.abort(signal);
296
296
  }
297
+ /**
298
+ * Attach to an already-started child and render its output.
299
+ *
300
+ * Resolves with the command's `ExecOutput`, unless an `onComplete` callback returned a
301
+ * value - that value is passed through instead. `T` names what the caller expects back;
302
+ * it defaults to `ExecOutput`, which is what a run without an `onComplete` produces.
303
+ */
297
304
  show(child) {
298
305
  this._stdoutKey = Symbol("visual-exec-stdout");
299
306
  this._stderrKey = Symbol("visual-exec-stderr");
@@ -336,10 +343,11 @@ export class VisualExec {
336
343
  const startTime = Date.now();
337
344
  let execPromise = child.promise
338
345
  .catch((err) => {
339
- var _a, _b, _c, _d;
340
- const output = (_a = err.output) !== null && _a !== void 0 ? _a : { stdout: "", stderr: "" };
341
- const exitCode = (_c = (_b = err.exitCode) !== null && _b !== void 0 ? _b : err.code) !== null && _c !== void 0 ? _c : 1;
342
- (_d = this._onComplete) === null || _d === void 0 ? void 0 : _d.call(this, output, exitCode);
346
+ var _a;
347
+ var _b, _c, _d;
348
+ const output = (_b = err.output) !== null && _b !== void 0 ? _b : { stdout: "", stderr: "" };
349
+ const exitCode = (_d = (_c = err.exitCode) !== null && _c !== void 0 ? _c : err.code) !== null && _d !== void 0 ? _d : 1;
350
+ (_a = this._onComplete) === null || _a === void 0 ? void 0 : _a.call(this, output, exitCode);
343
351
  this.logResult(err);
344
352
  throw err;
345
353
  })
@@ -418,6 +426,8 @@ export class VisualExec {
418
426
  });
419
427
  execPromise = Promise.race([execPromise, abortPromise]);
420
428
  }
429
+ // The runtime value is `ExecOutput` unless `onComplete` substituted its own; only the
430
+ // caller knows which, so the promise is handed back as the `T` they asked for.
421
431
  return execPromise.finally(cleanup);
422
432
  }
423
433
  logResult(err, output) {
@@ -475,6 +485,12 @@ export class VisualExec {
475
485
  logs.push(chalk.blue("\n<<<"), `End of output from ${this._outputLabel} ---`);
476
486
  this._logger.prefix(false)[level](...logs);
477
487
  }
488
+ /**
489
+ * Run the command and render its output.
490
+ *
491
+ * Resolves with `ExecOutput`, or with whatever an `onComplete` callback returned in its
492
+ * place. `T` defaults to `ExecOutput` so the common case needs no cast at the call site.
493
+ */
478
494
  execute(command) {
479
495
  this._startTime = Date.now();
480
496
  this._aborted = false;
@@ -492,22 +508,20 @@ export class VisualExec {
492
508
  child: result.child
493
509
  };
494
510
  const duration = () => Date.now() - this._startTime;
495
- const baseContext = (output) => {
496
- var _a, _b, _c, _d;
497
- return ({
498
- command: cmd,
499
- cwd: this._cwd,
500
- duration: duration(),
501
- stdout: (_a = output === null || output === void 0 ? void 0 : output.stdout) !== null && _a !== void 0 ? _a : "",
502
- stderr: (_b = output === null || output === void 0 ? void 0 : output.stderr) !== null && _b !== void 0 ? _b : "",
503
- lastLines: lastLines([...((_c = output === null || output === void 0 ? void 0 : output.stdout) !== null && _c !== void 0 ? _c : "").split("\n"), ...((_d = output === null || output === void 0 ? void 0 : output.stderr) !== null && _d !== void 0 ? _d : "").split("\n")].join("\n"), DEFAULT_LAST_LINES)
504
- });
505
- };
511
+ const baseContext = (output) => { var _a, _b, _c, _d; return ({
512
+ command: cmd,
513
+ cwd: this._cwd,
514
+ duration: duration(),
515
+ stdout: (_a = output === null || output === void 0 ? void 0 : output.stdout) !== null && _a !== void 0 ? _a : "",
516
+ stderr: (_b = output === null || output === void 0 ? void 0 : output.stderr) !== null && _b !== void 0 ? _b : "",
517
+ lastLines: lastLines([...((_c = output === null || output === void 0 ? void 0 : output.stdout) !== null && _c !== void 0 ? _c : "").split("\n"), ...((_d = output === null || output === void 0 ? void 0 : output.stderr) !== null && _d !== void 0 ? _d : "").split("\n")].join("\n"), DEFAULT_LAST_LINES)
518
+ }); };
506
519
  child.promise = child.promise.catch((err) => {
507
- var _a, _b, _c, _d, _e;
508
- const output = (_a = err.output) !== null && _a !== void 0 ? _a : { stdout: "", stderr: "" };
509
- const exitCode = (_b = err.code) !== null && _b !== void 0 ? _b : 1;
510
- const signal = (_e = (_c = err.signal) !== null && _c !== void 0 ? _c : (((_d = result.child) === null || _d === void 0 ? void 0 : _d.killed) ? "SIGTERM" : null)) !== null && _e !== void 0 ? _e : null;
520
+ var _a;
521
+ var _b, _c, _d, _e;
522
+ const output = (_b = err.output) !== null && _b !== void 0 ? _b : { stdout: "", stderr: "" };
523
+ const exitCode = (_c = err.code) !== null && _c !== void 0 ? _c : 1;
524
+ const signal = (_e = (_d = err.signal) !== null && _d !== void 0 ? _d : (((_a = result.child) === null || _a === void 0 ? void 0 : _a.killed) ? "SIGTERM" : null)) !== null && _e !== void 0 ? _e : null;
511
525
  const context = {
512
526
  ...baseContext(output),
513
527
  exitCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "visual-exec",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "homepage": "https://github.com/jchip/fynjs/tree/main/packages/visual-exec",
5
5
  "description": "Visual shell exec with spinners and progress display",
6
6
  "type": "module",
@@ -14,12 +14,12 @@
14
14
  "./package.json": "./package.json"
15
15
  },
16
16
  "engines": {
17
- "node": ">=22.12.0"
17
+ "node": ">=22.18.0"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "rm -rf dist && tsc -p tsconfig.json",
21
21
  "test": "vitest run",
22
- "ci:check": "tsc --noEmit -p tsconfig.json && npm test",
22
+ "ci:check": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.test.json && npm test",
23
23
  "test:watch": "vitest",
24
24
  "prepublishOnly": "xrun --serial build test",
25
25
  "postpack": "publish-util-postpack"
@@ -49,8 +49,8 @@
49
49
  "ci-info": "^4.4.0",
50
50
  "has-ansi": "^6.0.2",
51
51
  "strip-ansi": "^7.2.0",
52
- "visual-logger": "^2.0.1",
53
- "xsh": "^1.0.1"
52
+ "visual-logger": "^2.1.1",
53
+ "xsh": "^1.1.0"
54
54
  },
55
55
  "sideEffects": false
56
56
  }