diff --git a/src/main.ts b/src/main.ts index 300f1a8..b64a336 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1253,10 +1253,28 @@ function insetLines(text: string): string { return text.trimEnd().replace(/(^|\n)/g, "$1> "); } -function reduceSpew(message: string): string { +export function reduceSpew(message: string): string { // These are uninteresting in general and actually problematic when there are // thousands of instances of ENOSPC (which also appears as an error anyway) - return message.replace(/npm WARN.*\n/g, ""); + const chunks: string[] = []; + let position = 0; + while (true) { + const warningStart = message.indexOf("npm WARN", position); + if (warningStart < 0) { + chunks.push(message.slice(position)); + break; + } + + const lineEnd = message.indexOf("\n", warningStart); + if (lineEnd < 0) { + chunks.push(message.slice(position)); + break; + } + + chunks.push(message.slice(position, warningStart)); + position = lineEnd + 1; + } + return chunks.join(""); } function makeMarkdownLink(url: string) { diff --git a/test/main.test.ts b/test/main.test.ts index 6675339..5a6bd16 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -1,4 +1,4 @@ -import { getTscRepoResult, detectTypeScriptImplementation, detectTypeScriptNpmImplementation, downloadTsRepoAsync, mainAsync } from '../src/main.js' +import { getTscRepoResult, detectTypeScriptImplementation, detectTypeScriptNpmImplementation, downloadTsRepoAsync, mainAsync, reduceSpew } from '../src/main.js' import * as path from "node:path" import { createCopyingOverlayFS } from '../src/utils/overlayFS.js' import type { SpawnResult } from '../src/utils/execUtils.js'; @@ -116,6 +116,13 @@ describe("main", () => { })).toBe("corsa"); }); + it("removes npm warnings in linear time", () => { + expect(reduceSpew("before npm WARN ignored\nnpm WARN also ignored\nafter")).toBe("before after"); + + const unterminatedWarnings = "npm WARN".repeat(10_000); + expect(reduceSpew(unterminatedWarnings)).toBe(unterminatedWarnings); + }); + it.skip("build-only correctly caches", async () => { const { status, summary } = await getTscRepoResult( {