Skip to content

Commit

Permalink
cli: updated jest transform to include source maps
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
  • Loading branch information
Rugvip committed Feb 12, 2022
1 parent a57621b commit c6bbafb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-keys-dress.md
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---

Updated the default [sucrase](https://github.com/alangpierce/sucrase)-based Jest transform to include inline source maps.
12 changes: 10 additions & 2 deletions packages/cli/config/jestSucraseTransform.js
Expand Up @@ -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;
Expand All @@ -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');
}

Expand Down

0 comments on commit c6bbafb

Please sign in to comment.