Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion test/main.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(
{
Expand Down