@@ -14,6 +14,10 @@ import path from "node:path";
1414import serveStatic from "serve-static" ;
1515import { promisify } from "node:util" ;
1616
17+ import {
18+ AnyMap ,
19+ } from "@jridgewell/trace-mapping" ;
20+
1721/**
1822 * Custom middleware to instrument JS files with Istanbul.
1923 *
@@ -46,7 +50,10 @@ export default async function({log, middlewareUtil, options={}, resources}) {
4650
4751 // Instrumenter instance
4852 const instrumenter = createInstrumenter ( instrumenterConfig ) ;
49- const instrument = promisify ( instrumenter . instrument . bind ( instrumenter ) ) ;
53+ // Switch callback parameters to match promisify signature
54+ const callbackStyleInstrumenter = ( code , filename , inputSourceMap , callback ) =>
55+ instrumenter . instrument ( code , filename , callback , inputSourceMap ) ;
56+ const instrument = promisify ( callbackStyleInstrumenter ) ;
5057
5158 const router = new Router ( ) ;
5259
@@ -134,8 +141,18 @@ export default async function({log, middlewareUtil, options={}, resources}) {
134141 return ;
135142 }
136143
144+ // TODO: Add actual source map lookup (like in UI5 builder)
145+ const inputSourceMapResource = await resources . all . byPath ( `${ pathname } .map` ) ;
146+ let inputSourceMap = inputSourceMapResource ?
147+ JSON . parse ( await inputSourceMapResource . getString ( ) ) :
148+ null ;
149+
150+ if ( inputSourceMap ) {
151+ inputSourceMap = new AnyMap ( inputSourceMap ) ;
152+ }
153+
137154 const source = await matchedResource . getString ( ) ;
138- let instrumentedSource = await instrument ( source , pathname ) ;
155+ let instrumentedSource = await instrument ( source , pathname , inputSourceMap ) ;
139156
140157 log . verbose ( `...${ pathname } instrumented!` ) ;
141158
0 commit comments