cli: updated jest transform to include source maps

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-02-12 13:52:24 +01:00
parent a57621b496
commit c6bbafb516
2 changed files with 15 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Updated the default [sucrase](https://github.com/alangpierce/sucrase)-based Jest transform to include inline source maps.
+10 -2
View File
@@ -46,11 +46,17 @@ function process(source, filePath) {
}
if (transforms) {
return transform(source, {
const { code, sourceMap: map } = transform(source, {
transforms,
filePath,
disableESTransforms: true,
}).code;
sourceMapOptions: {
compiledFilename: filePath,
},
});
const b64 = Buffer.from(JSON.stringify(map), 'utf8').toString('base64');
const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${b64}`;
return `${code}\n${suffix}`;
}
return source;
@@ -64,6 +70,8 @@ function getCacheKey(sourceText) {
.update(sucrasePkg.version)
.update(Buffer.alloc(1))
.update(sucrasePluginPkg.version)
.update(Buffer.alloc(1))
.update('1') // increment whenever the transform logic in this file changes
.digest('hex');
}