Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use verbose renderer when TERM=dumb #782

Merged
merged 3 commits into from Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions bin/lint-staged → bin/lint-staged.js
Expand Up @@ -3,10 +3,9 @@
'use strict'

// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
// but do this only in TTY mode
if (process.stdout.isTTY) {
// istanbul ignore next
process.env.FORCE_COLOR = '1'
const { supportsColor } = require('chalk')
if (supportsColor) {
process.env.FORCE_COLOR = supportsColor.level.toString()
}

// Do not terminate main Listr process on SIGINT
Expand Down Expand Up @@ -36,7 +35,7 @@ cmdline
'-p, --concurrent <parallel tasks>',
'the number of tasks to run concurrently, or false to run tasks serially',
true
)
)
.option('-q, --quiet', 'disable lint-staged’s own console output', false)
.option('-r, --relative', 'pass relative filepaths to tasks', false)
.option('-x, --shell', 'skip parsing of tasks for better shell support', false)
Expand Down Expand Up @@ -74,7 +73,7 @@ const options = {
maxArgLength: getMaxArgLength() / 2,
quiet: !!cmdline.quiet,
relative: !!cmdline.relative,
shell: !!cmdline.shell,
shell: !!cmdline.shell
}

debug('Options parsed from command-line:', options)
Expand Down
10 changes: 9 additions & 1 deletion lib/runAll.js
Expand Up @@ -15,6 +15,14 @@ const resolveGitRepo = require('./resolveGitRepo')

const debugLog = require('debug')('lint-staged:run')

const getRenderer = ({ debug, quiet }) => {
iiroj marked this conversation as resolved.
Show resolved Hide resolved
if (quiet) return 'silent'
// Better support for dumb terminals: https://en.wikipedia.org/wiki/Computer_terminal#Dumb_terminals
const isDumbTerminal = process.env.TERM === 'dumb'
if (debug || isDumbTerminal) return 'verbose'
return 'update'
}

/**
* Executes all tasks and either resolves or rejects the promise
*
Expand Down Expand Up @@ -74,7 +82,7 @@ module.exports = async function runAll(
const listrOptions = {
dateFormat: false,
exitOnError: false,
renderer: (quiet && 'silent') || (debug && 'verbose') || 'update'
renderer: getRenderer({ debug, quiet })
}

const listrTasks = []
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"funding": {
"url": "https://opencollective.com/lint-staged"
},
"bin": "./bin/lint-staged",
"bin": "./bin/lint-staged.js",
"main": "./lib/index.js",
"files": [
"bin",
Expand All @@ -30,7 +30,7 @@
},
"husky": {
"hooks": {
"pre-commit": "./bin/lint-staged"
"pre-commit": "./bin/lint-staged.js"
}
},
"dependencies": {
Expand Down