From 9be106bae3d3729aeabed595f308caa4de93baa5 Mon Sep 17 00:00:00 2001 From: Manas Ranjan Dikshit Date: Mon, 2 Mar 2026 15:15:38 +0530 Subject: [PATCH] Refactor setup and teardown for tsconfig.json Refactor setup and teardown functions to handle sourceMap option in tsconfig.json. --- addons/source-map.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/addons/source-map.js b/addons/source-map.js index b661a82d7b..bd640f39db 100644 --- a/addons/source-map.js +++ b/addons/source-map.js @@ -2,15 +2,26 @@ import { alterFile, revertFile } from "../lib/utils.js"; export const args = ["--devtool", "source-map"]; -export const setup = async (options) => { +export const setup = async () => { await alterFile("tsconfig.json", (content) => { - return ( - content && - content.replace(/("compilerOptions": \{)/, '$1\n "sourceMap": true,') - ); + if (typeof content !== "string") return content; + + try { + const tsconfig = JSON.parse(content); + tsconfig.compilerOptions = tsconfig.compilerOptions || {}; + tsconfig.compilerOptions.sourceMap = true; + return JSON.stringify(tsconfig, null, 2) + "\n"; + } catch { + // Fallback if JSON parsing fails + return content.replace( + /("compilerOptions"\s*:\s*\{)/, + '$1\n "sourceMap": true,' + ); + } }); }; -export const teardown = async (options) => { +export const teardown = async () => { + // Restore original tsconfig.json await revertFile("tsconfig.json"); };