Skip to content

Commit

Permalink
inline blockly sourcemaps in development builds
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll committed Oct 10, 2024
1 parent fe96733 commit d5da6d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ function runUglify() {
return Promise.resolve();
}

function inlineBlocklySourcemaps() {
if (process.env.PXT_ENV === 'production') {
return;
}

return exec("node ./scripts/inlineBlocklySourceMaps.js");
}



/********************************************************
Expand Down Expand Up @@ -733,7 +741,7 @@ function getMochaExecutable() {
const buildAll = gulp.series(
updatestrings,
maybeUpdateWebappStrings(),
gulp.parallel(copyTypescriptServices, copyBlocklyMedia),
gulp.parallel(copyTypescriptServices, copyBlocklyMedia, inlineBlocklySourcemaps),
gulp.parallel(pxtlib, pxtweb),
gulp.parallel(pxtcompiler, pxtsim, backendutils),
pxtpy,
Expand Down
21 changes: 21 additions & 0 deletions scripts/inlineBlocklySourceMaps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fs = require("fs");
const path = require("path");

const blocklyRoot = path.resolve(__dirname, "..", "node_modules", "blockly");

const files = [
"blockly_compressed.js",
"blocks_compressed.js"
];

for (const file of files) {
const fullPath = path.join(blocklyRoot, file);
const source = fs.readFileSync(fullPath, "utf8");
const maps = fs.readFileSync(fullPath + ".map", "utf8");

const dataUri = "data:application/json;charset=utf-8;base64," + Buffer.from(maps).toString("base64");

const patched = source.replace(/\/\/# sourceMappingURL=.*/, `//# sourceMappingURL=${dataUri}`);

fs.writeFileSync(fullPath, patched, "utf8");
}

0 comments on commit d5da6d6

Please sign in to comment.