Skip to content

Commit 883465c

Browse files
committed
feat: Support input source maps
1 parent 2f65cb9 commit 883465c

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/middleware-code-coverage/lib/middleware.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import path from "node:path";
1414
import serveStatic from "serve-static";
1515
import {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

packages/middleware-code-coverage/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"node": "^20.11.0 || >=22.0.0"
3434
},
3535
"dependencies": {
36+
"@jridgewell/trace-mapping": "^0.3.31",
3637
"body-parser": "^2.2.2",
3738
"istanbul-lib-coverage": "^3.2.2",
3839
"istanbul-lib-instrument": "^6.0.3",

0 commit comments

Comments
 (0)