From 811daef3d35abb440a1ad044bcbf14738fc95767 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 7 Jun 2024 22:01:57 +0200 Subject: [PATCH] feat(node): Add logic for combining single sentence issues lines When not combining lines, trim them to normalize output from different NPM versions which sometimes has trailing whitespaces. Resolves #7071. Signed-off-by: Sebastian Schuberth --- .../npm-version-urls-expected-output.yml | 6 +++--- .../node/src/main/kotlin/Npm.kt | 13 +++++++++++- .../node/src/test/kotlin/NpmTest.kt | 20 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/plugins/package-managers/node/src/funTest/assets/projects/synthetic/npm-version-urls-expected-output.yml b/plugins/package-managers/node/src/funTest/assets/projects/synthetic/npm-version-urls-expected-output.yml index 808474dc33c9f..6a535394ab11f 100644 --- a/plugins/package-managers/node/src/funTest/assets/projects/synthetic/npm-version-urls-expected-output.yml +++ b/plugins/package-managers/node/src/funTest/assets/projects/synthetic/npm-version-urls-expected-output.yml @@ -5193,13 +5193,13 @@ issues: severity: "HINT" - timestamp: "1970-01-01T00:00:00Z" source: "NPM" - message: "skipping integrity check for git dependency ssh://git@github.com/jonschlinkert/gulp-format-md.git " + message: "skipping integrity check for git dependency ssh://git@github.com/jonschlinkert/gulp-format-md.git" severity: "HINT" - timestamp: "1970-01-01T00:00:00Z" source: "NPM" - message: "skipping integrity check for git dependency ssh://git@github.com/mochajs/mocha.git " + message: "skipping integrity check for git dependency ssh://git@github.com/mochajs/mocha.git" severity: "HINT" - timestamp: "1970-01-01T00:00:00Z" source: "NPM" - message: "skipping integrity check for git dependency ssh://git@github.com/tinydesk/angular-tileview.git " + message: "skipping integrity check for git dependency ssh://git@github.com/tinydesk/angular-tileview.git" severity: "HINT" diff --git a/plugins/package-managers/node/src/main/kotlin/Npm.kt b/plugins/package-managers/node/src/main/kotlin/Npm.kt index 3ad81a21f1c84..8c20e7488c939 100644 --- a/plugins/package-managers/node/src/main/kotlin/Npm.kt +++ b/plugins/package-managers/node/src/main/kotlin/Npm.kt @@ -693,8 +693,19 @@ internal fun List.groupLines(vararg markers: String): List { collapsedLines[collapsedLines.size - 1] = collapsedLines.last().removePrefix(previousPrefix).trimStart() } - return collapsedLines.takeWhile { + val nonFooterLines = collapsedLines.takeWhile { // Skip any footer as a whole. it != "A complete log of this run can be found in:" } + + // If no lines but the last end with a dot, assume the message to be a single sentence. + return if ( + nonFooterLines.size > 1 && + nonFooterLines.last().endsWith('.') && + nonFooterLines.subList(0, nonFooterLines.size - 1).none { it.endsWith('.') } + ) { + listOf(nonFooterLines.joinToString(" ")) + } else { + nonFooterLines.map { it.trim() } + } } diff --git a/plugins/package-managers/node/src/test/kotlin/NpmTest.kt b/plugins/package-managers/node/src/test/kotlin/NpmTest.kt index 57c3acd3fc98a..78d9bf39daaac 100644 --- a/plugins/package-managers/node/src/test/kotlin/NpmTest.kt +++ b/plugins/package-managers/node/src/test/kotlin/NpmTest.kt @@ -115,5 +115,25 @@ class NpmTest : WordSpec({ "deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to \"coffeescript\" (no hyphen)" ) } + + "treat a single block of errors as one issue" { + val output = """ + npm ERR! code EEXIST + npm ERR! syscall mkdir + npm ERR! path G:\Git\lsp-sample\node_modules.staging + npm ERR! errno -4075 + npm ERR! EEXIST: file already exists, mkdir 'G:\Git\lsp-sample\node_modules.staging' + npm ERR! File exists: G:\Git\lsp-sample\node_modules.staging + npm ERR! Remove the existing file and try again, or run npm + npm ERR! with --force to overwrite files recklessly. + """.trimIndent() + + output.lines().groupLines("npm ERR! ") shouldBe listOf( + "EEXIST: file already exists, mkdir 'G:\\Git\\lsp-sample\\node_modules.staging' " + + "File exists: G:\\Git\\lsp-sample\\node_modules.staging " + + "Remove the existing file and try again, or run npm " + + "with --force to overwrite files recklessly." + ) + } } })