1 | import type {FdGenericOption} from './arguments/specific.js';
|
2 | import type {Options, SyncOptions} from './arguments/options.js';
|
3 | import type {Result, SyncResult} from './return/result.js';
|
4 |
|
5 | type VerboseOption = FdGenericOption<
|
6 | | 'none'
|
7 | | 'short'
|
8 | | 'full'
|
9 | | VerboseFunction
|
10 | >;
|
11 |
|
12 | type VerboseFunction = (verboseLine: string, verboseObject: MinimalVerboseObject) => string | void;
|
13 |
|
14 | type GenericVerboseObject = {
|
15 | /**
|
16 | Event type. This can be:
|
17 | - `'command'`: subprocess start
|
18 | - `'output'`: `stdout`/`stderr` output
|
19 | - `'ipc'`: IPC output
|
20 | - `'error'`: subprocess failure
|
21 | - `'duration'`: subprocess success or failure
|
22 | */
|
23 | type: 'command' | 'output' | 'ipc' | 'error' | 'duration';
|
24 |
|
25 | /**
|
26 | Depending on `verboseObject.type`, this is:
|
27 | - `'command'`: the `result.escapedCommand`
|
28 | - `'output'`: one line from `result.stdout` or `result.stderr`
|
29 | - `'ipc'`: one IPC message from `result.ipcOutput`
|
30 | - `'error'`: the `error.shortMessage`
|
31 | - `'duration'`: the `result.durationMs`
|
32 | */
|
33 | message: string;
|
34 |
|
35 | /**
|
36 | The file and arguments that were run. This is the same as `result.escapedCommand`.
|
37 | */
|
38 | escapedCommand: string;
|
39 |
|
40 | /**
|
41 | Serial number identifying the subprocess within the current process. It is incremented from `'0'`.
|
42 |
|
43 | This is helpful when multiple subprocesses are running at the same time.
|
44 |
|
45 | This is similar to a [PID](https://en.wikipedia.org/wiki/Process_identifier) except it has no maximum limit, which means it never repeats. Also, it is usually shorter.
|
46 | */
|
47 | commandId: string;
|
48 |
|
49 | /**
|
50 | Event date/time.
|
51 | */
|
52 | timestamp: Date;
|
53 |
|
54 | /**
|
55 | Whether another subprocess is piped into this subprocess. This is `false` when `result.pipedFrom` is empty.
|
56 | */
|
57 | piped: boolean;
|
58 | };
|
59 |
|
60 | type MinimalVerboseObject = GenericVerboseObject & {
|
61 | // We cannot use the `CommonOptions` type because it would make this type recursive
|
62 | options: object;
|
63 | result?: never;
|
64 | };
|
65 |
|
66 | /**
|
67 | Subprocess event object, for logging purpose, using the `verbose` option and `execa()`.
|
68 | */
|
69 | export type VerboseObject = GenericVerboseObject & {
|
70 | /**
|
71 | The options passed to the subprocess.
|
72 | */
|
73 | options: Options;
|
74 |
|
75 | /**
|
76 | Subprocess result.
|
77 |
|
78 | This is `undefined` if `verboseObject.type` is `'command'`, `'output'` or `'ipc'`.
|
79 | */
|
80 | result?: Result;
|
81 | };
|
82 |
|
83 | /**
|
84 | Subprocess event object, for logging purpose, using the `verbose` option and `execaSync()`.
|
85 | */
|
86 | export type SyncVerboseObject = GenericVerboseObject & {
|
87 | /**
|
88 | The options passed to the subprocess.
|
89 | */
|
90 | options: SyncOptions;
|
91 |
|
92 | /**
|
93 | Subprocess result.
|
94 |
|
95 | This is `undefined` if `verboseObject.type` is `'command'`, `'output'` or `'ipc'`.
|
96 | */
|
97 | result?: SyncResult;
|
98 | };
|