From e84ad86a7578fb46568663aca6fe6a6f3986cc8d Mon Sep 17 00:00:00 2001 From: Rudy Mizrahi Celekli <47457359+rudycelekli@users.noreply.github.com> Date: Tue, 6 Oct 2026 21:20:51 -0500 Subject: [PATCH] fix(browser): identify NodeNext TypeScript original source artifacts (#811) Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> --- docs/browser-observation.md | 2 +- src/browser/WebSourceMapFetcher.ts | 5 +- .../browser/webSourceMapFetcher.test.ts | 67 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/docs/browser-observation.md b/docs/browser-observation.md index bd7b61bf4..b60f1a474 100644 --- a/docs/browser-observation.md +++ b/docs/browser-observation.md @@ -146,7 +146,7 @@ Disallowed-origin entries are filtered before retention. CDP discovery, WebSocket connection, and commands continue until the peer responds or the caller cancels the operation; REA has no internal byte, message-count, or pending-command quota for these exchanges. Without caller cancellation, a stalled peer can leave an operation waiting. On cancellation, REA closes only its own WebSocket, waiting up to one second before terminating it. Malformed unsolicited protocol events poison the connection so later commands fail closed. -Network and console coverage starts only after REA attaches and enables the relevant CDP domains. `prior_activity_available` is always `false`; absence from these arrays is not evidence that an event never occurred. Source maps are not fetched by inspection. Bundle analysis fetches them only when `fetch_source_maps` is selected, with exact-origin redirect checks and no credentials, cookies, or referrer. Every requested map, mapping, original source, AST node, and finding from parsed content is returned inline; failed maps remain explicitly unavailable and make bundle completeness partial. +Network and console coverage starts only after REA attaches and enables the relevant CDP domains. `prior_activity_available` is always `false`; absence from these arrays is not evidence that an event never occurred. Source maps are not fetched by inspection. Bundle analysis fetches them only when `fetch_source_maps` is selected, with exact-origin redirect checks and no credentials, cookies, or referrer. Every requested map, mapping, original source, AST node, and finding from parsed content is returned inline; failed maps remain explicitly unavailable and make bundle completeness partial. Original source artifacts with `.ts`, `.tsx`, `.mts`, or `.cts` suffixes carry `text/typescript`; other source names retain `text/javascript`. ## Non-goals and threat model diff --git a/src/browser/WebSourceMapFetcher.ts b/src/browser/WebSourceMapFetcher.ts index bf6ed1cc7..72b44439a 100644 --- a/src/browser/WebSourceMapFetcher.ts +++ b/src/browser/WebSourceMapFetcher.ts @@ -373,7 +373,10 @@ const resolveOriginalSource = ( }; const sourceMediaType = (source: string | null): string => - source?.endsWith(".ts") || source?.endsWith(".tsx") + source?.endsWith(".ts") || + source?.endsWith(".tsx") || + source?.endsWith(".mts") || + source?.endsWith(".cts") ? "text/typescript" : "text/javascript"; diff --git a/tests/boundary/browser/webSourceMapFetcher.test.ts b/tests/boundary/browser/webSourceMapFetcher.test.ts index 06cffa6ac..568629017 100644 --- a/tests/boundary/browser/webSourceMapFetcher.test.ts +++ b/tests/boundary/browser/webSourceMapFetcher.test.ts @@ -591,3 +591,70 @@ it("keeps bare original module specifiers unresolved", async () => { ?.resolved_source, ).toContain("/assets/actual.js"); }); + +describe("source-map original artifact language metadata", () => { + it.each([ + ["main.ts", "text/typescript"], + ["main.tsx", "text/typescript"], + ["main.mts", "text/typescript"], + ["main.cts", "text/typescript"], + ["main.js", "text/javascript"], + ["main.mjs", "text/javascript"], + ["main.cjs", "text/javascript"], + ])("retains the source language for %s", async (filename, mediaType) => { + const text = + mediaType === "text/typescript" + ? "export const value: number = 1;" + : "export const value = 1;"; + const server = createServer((_incoming, response) => { + response.setHeader("content-type", "application/json"); + response.end( + JSON.stringify({ + version: 3, + sources: [filename], + sourcesContent: [text], + names: [], + mappings: "AAAA", + }), + ); + }); + try { + await new Promise((resolve, reject) => { + server.once("error", reject); + server.listen(0, "127.0.0.1", resolve); + }); + const address = server.address(); + if (address === null || typeof address === "string") + throw new TypeError("Expected a TCP listener address"); + const localOrigin = `http://127.0.0.1:${String(address.port)}`; + const url = `${localOrigin}/main.js.map`; + const result = await fetchWebSourceMaps( + [{ ...request, fetchUrl: url, declaredUrl: url }], + input({ allowed_origins: [localOrigin] }), + AbortSignal.timeout(2_000), + ); + expect(result).toMatchObject({ + status: "included", + items: [ + { + original_sources: [ + { + source: `${localOrigin}/${filename}`, + artifact: { media_type: mediaType, text }, + }, + ], + mappings: [{ source: `${localOrigin}/${filename}` }], + }, + ], + }); + } finally { + server.closeAllConnections(); + if (server.listening) + await new Promise((resolve, reject) => { + server.close((error) => + error === undefined ? resolve() : reject(error), + ); + }); + } + }); +});