-
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dependencies): update
[email protected]
- Loading branch information
Showing
8 changed files
with
251 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,61 @@ | ||
const getMainRendererOptions = ({ debug, quiet }, env) => { | ||
if (quiet) return { renderer: 'silent' } | ||
import { EOL } from 'node:os' | ||
import { Writable } from 'node:stream' | ||
|
||
import { ListrLogger, ProcessOutput } from 'listr2' | ||
|
||
const EOLRegex = new RegExp(EOL + '$') | ||
|
||
const bindLogger = (consoleLogMethod) => | ||
new Writable({ | ||
write: function (chunk, encoding, next) { | ||
consoleLogMethod(chunk.toString().replace(EOLRegex, '')) | ||
next() | ||
}, | ||
}) | ||
|
||
const getMainRendererOptions = ({ debug, quiet }, logger, env) => { | ||
if (quiet) { | ||
return { | ||
renderer: 'silent', | ||
} | ||
} | ||
|
||
if (env.NODE_ENV === 'test') { | ||
return { | ||
renderer: 'test', | ||
rendererOptions: { | ||
logger: new ListrLogger({ | ||
processOutput: new ProcessOutput(bindLogger(logger.log), bindLogger(logger.error)), | ||
}), | ||
}, | ||
} | ||
} | ||
|
||
// Better support for dumb terminals: https://en.wikipedia.org/wiki/Computer_terminal#Dumb_terminals | ||
const isDumbTerminal = env.TERM === 'dumb' | ||
if (debug || isDumbTerminal || env.NODE_ENV === 'test') return { renderer: 'verbose' } | ||
return { renderer: 'update', rendererOptions: { dateFormat: false } } | ||
} | ||
if (debug || env.TERM === 'dumb') { | ||
return { | ||
renderer: 'verbose', | ||
} | ||
} | ||
|
||
const getFallbackRenderer = ({ renderer }, { FORCE_COLOR }) => { | ||
if (renderer === 'silent') { | ||
return 'silent' | ||
return { | ||
renderer: 'update', | ||
} | ||
} | ||
|
||
// If colors are being forced, then also force non-fallback rendering | ||
if (Number(FORCE_COLOR) > 0) { | ||
const getFallbackRenderer = ({ renderer }, { FORCE_COLOR }) => { | ||
if (renderer === 'silent' || renderer === 'test' || Number(FORCE_COLOR) > 0) { | ||
return renderer | ||
} | ||
|
||
return 'verbose' | ||
} | ||
|
||
export const getRenderer = (options, env = process.env) => { | ||
const mainRendererOptions = getMainRendererOptions(options, env) | ||
export const getRenderer = (options, logger, env = process.env) => { | ||
const mainRendererOptions = getMainRendererOptions(options, logger, env) | ||
|
||
return { | ||
...mainRendererOptions, | ||
nonTTYRenderer: getFallbackRenderer(mainRendererOptions, env), | ||
fallbackRenderer: getFallbackRenderer(mainRendererOptions, env), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.