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"); };