Skip to content

Commit

Permalink
fix: improve debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Nov 27, 2019
1 parent cb43872 commit f88e226
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 6 additions & 2 deletions bin/lint-staged
Expand Up @@ -60,14 +60,18 @@ const getMaxArgLength = () => {
}
}

lintStaged({
const options = {
configPath: cmdline.config,
maxArgLength: getMaxArgLength(),
relative: !!cmdline.relative,
shell: !!cmdline.shell,
quiet: !!cmdline.quiet,
debug: !!cmdline.debug
})
}

debug('Options parsed from command-line:', options)

lintStaged(options)
.then(passed => {
process.exitCode = passed ? 0 : 1
})
Expand Down
13 changes: 11 additions & 2 deletions lib/chunkFiles.js
@@ -1,5 +1,6 @@
'use strict'

const debug = require('debug')('lint-staged:chunkFiles')
const normalize = require('normalize-path')
const path = require('path')

Expand Down Expand Up @@ -32,9 +33,17 @@ function chunkArray(arr, chunkCount) {
* @returns {Array<Array<String>>}
*/
module.exports = function chunkFiles({ files, gitDir, maxArgLength = null, relative = false }) {
if (!maxArgLength) return [files]
if (!maxArgLength) {
debug('Skip chunking files because of undefined maxArgLength')
return [files]
}

const normalizedFiles = files.map(file => normalize(relative ? file : path.resolve(gitDir, file)))
const fileListLength = normalizedFiles.join(' ').length
const chunkCount = Math.min(Math.ceil(fileListLength / maxArgLength), files.length)
debug(
`Resolved an argument string length of ${fileListLength} characters from ${normalizedFiles.length} files`
)
const chunkCount = Math.min(Math.ceil(fileListLength / maxArgLength), normalizedFiles.length)
debug(`Creating ${chunkCount} chunks for maxArgLength of ${maxArgLength}`)
return chunkArray(files, chunkCount)
}
2 changes: 1 addition & 1 deletion lib/runAll.js
Expand Up @@ -112,7 +112,7 @@ module.exports = async function runAll(
listrTasks.push({
// No need to show number of task chunks when there's only one
title:
chunkCount > 1 ? `Running tasks (chunk ${index}/${chunkCount})...` : 'Running tasks...',
chunkCount > 1 ? `Running tasks (chunk ${index + 1}/${chunkCount})...` : 'Running tasks...',
task: () =>
new Listr(chunkListrTasks, { ...listrOptions, concurrent: false, exitOnError: false }),
skip: () => {
Expand Down

0 comments on commit f88e226

Please sign in to comment.