Skip to content

Commit

Permalink
fix: use verbose renderer when TERM=dumb (#782)
Browse files Browse the repository at this point in the history
* fix: use verbose renderer when TERM=dumb

* fix: set FORCE_COLOR only when supported

* refactor: add .js extension to bin file
  • Loading branch information
iiroj authored Jan 29, 2020
1 parent 7fac11f commit 9c08e8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
11 changes: 5 additions & 6 deletions bin/lint-staged → bin/lint-staged.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const resolveGitRepo = require('./resolveGitRepo')

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

const getRenderer = ({ debug, quiet }) => {
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
Original file line number Diff line number Diff line change
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

0 comments on commit 9c08e8e

Please sign in to comment.