From f88e22619b8dea4fbcda3d57a85ca9d1be152908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20Ja=CC=88ppinen?= Date: Wed, 27 Nov 2019 07:12:20 +0200 Subject: [PATCH] fix: improve debug logging --- bin/lint-staged | 8 ++++++-- lib/chunkFiles.js | 13 +++++++++++-- lib/runAll.js | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bin/lint-staged b/bin/lint-staged index eea0d69fc..90126cae3 100755 --- a/bin/lint-staged +++ b/bin/lint-staged @@ -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 }) diff --git a/lib/chunkFiles.js b/lib/chunkFiles.js index 824c383d7..f375a40b9 100644 --- a/lib/chunkFiles.js +++ b/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') @@ -32,9 +33,17 @@ function chunkArray(arr, chunkCount) { * @returns {Array>} */ 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) } diff --git a/lib/runAll.js b/lib/runAll.js index cbc6adaae..5039f49f6 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -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: () => {