Skip to content
Myr

info.js

This file

Path

lib/verbose/info.js

39 lines · 1.5 KiB · JavaScript

Last changed by

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 1why, one step back
1import {isVerbose, VERBOSE_VALUES, isVerboseFunction} from './values.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 2–3why, one step back
2
3// Information computed before spawning, used by the `verbose` option

Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199

line 4why, one step back
4export const getVerboseInfo = (verbose, escapedCommand, rawOptions) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 5why, one step back
5 validateVerbose(verbose);

Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199

lines 6–12why, one step back
6 const commandId = getCommandId(verbose);
7 return {8 verbose,9 escapedCommand,10 commandId,11 rawOptions,12 };

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 13–14why, one step back
13};
14

Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199

lines 15–16why, one step back
15const getCommandId = verbose => isVerbose({verbose}) ? COMMAND_ID++ : undefined;
16

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 17–21why, one step back
17// Prepending the `pid` is useful when multiple commands print their output at the same time.
18// However, we cannot use the real PID since this is not available with `child_process.spawnSync()`.19// Also, we cannot use the real PID if we want to print it before `child_process.spawn()` is run.20// As a pro, it is shorter than a normal PID and never re-uses the same id.21// As a con, it cannot be used to send signals.

Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199

line 22why, one step back
22let COMMAND_ID = 0n;

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 23–24why, one step back
23
24const validateVerbose = verbose => {

Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199

lines 25–26why, one step back
25 for (const fdVerbose of verbose) {
26 if (fdVerbose === false) {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 27–29why, one step back
27 throw new TypeError('The "verbose: false" option was renamed to "verbose: \'none\'".');
28 }29

Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199

line 30why, one step back
30 if (fdVerbose === true) {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 31–33why, one step back
31 throw new TypeError('The "verbose: true" option was renamed to "verbose: \'short\'".');
32 }33

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 34–36why, one step back
34 if (!VERBOSE_VALUES.includes(fdVerbose) && !isVerboseFunction(fdVerbose)) {
35 const allowedValues = VERBOSE_VALUES.map(allowedValue => `'${allowedValue}'`).join(', ');36 throw new TypeError(`The "verbose" option must not be ${fdVerbose}. Allowed values are: ${allowedValues} or a function.`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 37–39why, one step back
37 }
38 }39};