@netlify/build
Version:
Netlify build module
29 lines (28 loc) • 1.01 kB
JavaScript
import { inspect } from 'util';
import supportsColor from 'supports-color';
const hasColors = () => supportsColor.stdout !== false;
/**
* Plugin child processes use `stdio: 'pipe'` so they are always
* non-interactive even if the parent is an interactive TTY. This means they
* would normally lose colors. If the parent has colors, we pass an environment
* variable to the child process to force colors.
*/
export const getParentColorEnv = function () {
if (!hasColors()) {
return {};
}
return { FORCE_COLOR: '1' };
};
/**
* Child processes and the buildbot relies on `FORCE_COLOR=1` to set colors.
* However `utils.inspect()` (used by `console.log()`) uses
* `process.stdout.hasColors` which is always `undefined` when the TTY is
* non-interactive. So we need to set `util.inspect.defaultOptions.colors`
* manually both in plugin processes.
*/
export const setInspectColors = function () {
if (!hasColors()) {
return;
}
inspect.defaultOptions.colors = true;
};