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 fileTake 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 back1import {isVerbose, VERBOSE_VALUES, isVerboseFunction} from './values.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 2–3why, one step back23// Information computed before spawning, used by the `verbose` optionRefactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199
line 4why, one step back4export const getVerboseInfo = (verbose, escapedCommand, rawOptions) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 5why, one step back5 validateVerbose(verbose);Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199
lines 6–12why, one step back6 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 back13};14Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199
lines 15–16why, one step back15const getCommandId = verbose => isVerbose({verbose}) ? COMMAND_ID++ : undefined;16100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 17–21why, one step back17// 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 back22let COMMAND_ID = 0n;100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 23–24why, one step back2324const validateVerbose = verbose => {Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199
lines 25–26why, one step back25 for (const fdVerbose of verbose) {26 if (fdVerbose === false) {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 27–29why, one step back27 throw new TypeError('The "verbose: false" option was renamed to "verbose: \'none\'".');28 }29Refactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199
line 30why, one step back30 if (fdVerbose === true) {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 31–33why, one step back31 throw new TypeError('The "verbose: true" option was renamed to "verbose: \'short\'".');32 }33Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 34–36why, one step back34 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 back37 }38 }39};