diff --git a/bin/lcov-result-merger.js b/bin/lcov-result-merger.js index df14521..25631db 100755 --- a/bin/lcov-result-merger.js +++ b/bin/lcov-result-merger.js @@ -42,20 +42,36 @@ const args = yargs(hideBin(process.argv)).command( default: [], description: 'Pass globs to ignore file paths', }, + log: { + type: 'boolean', + default: false, + description: + 'Show some additional information to the console about what the process is getting up' + + 'to (fed to stderr).', + }, }); } ).argv; (async function () { + if (args.log) { + args.logger = function logger(...messages) { + process.stdout.write(`[lcov-result-merger] ${messages.join('\n')}\n`); + }; + } + const files = await fastGlob(args.pattern, { absolute: true, ignore: args.ignore, }); + args.logger?.('Matched Files', JSON.stringify(files, null, 2)); + const mergeResults = await mergeCoverageReportFiles(files, args); if (args.outFile) { await writeFile(args.outFile, mergeResults, 'utf-8'); + args.logger?.(`Results written to "${args.outFile}"`); } else { process.stdout.write(mergeResults + '\n'); } diff --git a/index.js b/index.js index b4c3cd9..7ebefb5 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,7 @@ function processFile(sourceDir, data, lcov, config) { let currentCoverageFile = null; const lines = data.toString('utf-8').split(/\r?\n/); + config.logger?.(`Read ${lines.length} lines of content`); for (let i = 0; i < lines.length; i += 1) { const line = lines[i]; @@ -53,7 +54,15 @@ function processFile(sourceDir, data, lcov, config) { fullFilePathName ); + config.logger?.( + `Re-writing source file path, Before: "${sourceFilePath}"` + ); + sourceFilePath = './' + rootRelPathName; + + config.logger?.( + `Re-writing source file path, After: "${sourceFilePath}"` + ); } currentCoverageFile = lcov.addCoverageFile(sourceFilePath); @@ -69,7 +78,10 @@ function processFile(sourceDir, data, lcov, config) { break; default: - // do nothing with not implemented prefixes + // do nothing with not implemented prefixes + config.logger?.( + `Ignoring unrecognized/unsupported entry (line #${i}): "${prefix}:${suffix}"` + ); } } @@ -90,6 +102,7 @@ async function mergeCoverageReportFiles(filePaths, options) { for (const filePath of filePaths) { const fileContent = await readFile(filePath, 'utf-8'); + config.logger?.(`Processing "${filePath}"`); processFile(path.dirname(filePath), fileContent, report, config); } diff --git a/lib/configuration.js b/lib/configuration.js index 7524551..31392aa 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -8,6 +8,9 @@ * @property {string} [prependPathFix] * @property {string} [prepend-path-fix] * @property {string[]} [ignore] + * @property {boolean} [log] + * + * @property {(...msg: string[]) => void} [logger] */ module.exports = class Configuration { @@ -17,22 +20,32 @@ module.exports = class Configuration { constructor(partial = {}) { /** * A glob pattern matching one or more lcov files to be merged. + * * @type {string} */ this.pattern = partial.pattern; /** * A file to write the merged lcov to. + * * @type {string|undefined} */ this.outFile = partial.outFile; /** * File path globs that will be ignored. + * * @type {string[]} */ this.ignore = Array.isArray(partial.ignore) ? partial.ignore : []; + /** + * An optional logger function. + * + * @type {((...msg: string[]) => void) | undefined} + */ + this.logger = partial.logger; + /** * Modify source file paths to be relative to the working directory that * the merge operation was run in.