From de678cff9f9478f8f7960fc412984cc3d1921898 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Tue, 29 Dec 2020 22:13:38 +0100 Subject: [PATCH] feat(logs): support external sourcemaps from `.map` files (#5434) * support reading sourcemaps from `.map` files * test: add external source-map tests Co-authored-by: Igor Randjelovic --- lib/services/log-source-map-service.ts | 11 +++- test/files/sourceMapBundle/.gitignore | 1 + .../sourceMapBundle/android/app/external.js | 19 +++++++ .../android/app/external.js.map | 1 + .../files/sourceMapBundle/ios/app/external.js | 19 +++++++ .../sourceMapBundle/ios/app/external.js.map | 1 + test/services/log-source-map-service.ts | 50 ++++++++++++++++++- 7 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 test/files/sourceMapBundle/.gitignore create mode 100644 test/files/sourceMapBundle/android/app/external.js create mode 100644 test/files/sourceMapBundle/android/app/external.js.map create mode 100644 test/files/sourceMapBundle/ios/app/external.js create mode 100644 test/files/sourceMapBundle/ios/app/external.js.map diff --git a/lib/services/log-source-map-service.ts b/lib/services/log-source-map-service.ts index a8ec3c8af0..6fe68e6aa0 100644 --- a/lib/services/log-source-map-service.ts +++ b/lib/services/log-source-map-service.ts @@ -67,8 +67,17 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService { public async setSourceMapConsumerForFile(filePath: string): Promise { try { if (!this.$fs.getFsStats(filePath).isDirectory()) { + const mapFile = filePath + ".map"; + let sourceMapRaw; const source = this.$fs.readText(filePath); - const sourceMapRaw = sourceMapConverter.fromSource(source); + if (this.$fs.exists(mapFile)) { + sourceMapRaw = sourceMapConverter.fromMapFileSource( + source, + path.dirname(filePath) + ); + } else { + sourceMapRaw = sourceMapConverter.fromSource(source); + } let smc: any = null; if (sourceMapRaw && sourceMapRaw.sourcemap) { const sourceMap = sourceMapRaw.sourcemap; diff --git a/test/files/sourceMapBundle/.gitignore b/test/files/sourceMapBundle/.gitignore new file mode 100644 index 0000000000..3c15e25e6b --- /dev/null +++ b/test/files/sourceMapBundle/.gitignore @@ -0,0 +1 @@ +!**/*.map diff --git a/test/files/sourceMapBundle/android/app/external.js b/test/files/sourceMapBundle/android/app/external.js new file mode 100644 index 0000000000..6ca84a64ab --- /dev/null +++ b/test/files/sourceMapBundle/android/app/external.js @@ -0,0 +1,19 @@ +module.exports = + (global["webpackJsonp"] = global["webpackJsonp"] || []).push([["external"],{ + + /***/ "./external-test.js": + /***/ (function(module, __webpack_exports__, __webpack_require__) { + + "use strict"; + __webpack_require__.r(__webpack_exports__); + /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "onTap", function() { return onTap; }); + function onTap() { + console.log("Test."); + console.trace("Test"); + throw new Error("Test"); + } + + /***/ }) + + },[["./external-test.js","runtime"]]]); +//# sourceMappingURL=external.js.map diff --git a/test/files/sourceMapBundle/android/app/external.js.map b/test/files/sourceMapBundle/android/app/external.js.map new file mode 100644 index 0000000000..2f3f621834 --- /dev/null +++ b/test/files/sourceMapBundle/android/app/external.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///./external-test.js"],"names":["onTap","console","log","trace","Error"],"mappings":";;;;;;;AAAA;AAAA;AAAO,SAASA,KAAT,GAAiB;AACpBC,SAAO,CAACC,GAAR,CAAY,OAAZ;AACAD,SAAO,CAACE,KAAR,CAAc,MAAd;AACA,QAAM,IAAIC,KAAJ,CAAU,MAAV,CAAN;AACH,C","file":"external.js","sourcesContent":["export function onTap() {\n console.log(\"Test.\");\n console.trace(\"Test\");\n throw new Error(\"Test\");\n}"],"sourceRoot":""} diff --git a/test/files/sourceMapBundle/ios/app/external.js b/test/files/sourceMapBundle/ios/app/external.js new file mode 100644 index 0000000000..6ca84a64ab --- /dev/null +++ b/test/files/sourceMapBundle/ios/app/external.js @@ -0,0 +1,19 @@ +module.exports = + (global["webpackJsonp"] = global["webpackJsonp"] || []).push([["external"],{ + + /***/ "./external-test.js": + /***/ (function(module, __webpack_exports__, __webpack_require__) { + + "use strict"; + __webpack_require__.r(__webpack_exports__); + /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "onTap", function() { return onTap; }); + function onTap() { + console.log("Test."); + console.trace("Test"); + throw new Error("Test"); + } + + /***/ }) + + },[["./external-test.js","runtime"]]]); +//# sourceMappingURL=external.js.map diff --git a/test/files/sourceMapBundle/ios/app/external.js.map b/test/files/sourceMapBundle/ios/app/external.js.map new file mode 100644 index 0000000000..2f3f621834 --- /dev/null +++ b/test/files/sourceMapBundle/ios/app/external.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///./external-test.js"],"names":["onTap","console","log","trace","Error"],"mappings":";;;;;;;AAAA;AAAA;AAAO,SAASA,KAAT,GAAiB;AACpBC,SAAO,CAACC,GAAR,CAAY,OAAZ;AACAD,SAAO,CAACE,KAAR,CAAc,MAAd;AACA,QAAM,IAAIC,KAAJ,CAAU,MAAV,CAAN;AACH,C","file":"external.js","sourcesContent":["export function onTap() {\n console.log(\"Test.\");\n console.trace(\"Test\");\n throw new Error(\"Test\");\n}"],"sourceRoot":""} diff --git a/test/services/log-source-map-service.ts b/test/services/log-source-map-service.ts index e888a93484..6e15615248 100644 --- a/test/services/log-source-map-service.ts +++ b/test/services/log-source-map-service.ts @@ -95,6 +95,23 @@ const testCases: IDictionary { const fs = testInjector.resolve("fs"); const files = fs.enumerateFilesInDirectorySync(originalFilesLocation); for (const file of files) { + if (file.endsWith(".map")) { + continue; + } + await logSourceMapService.setSourceMapConsumerForFile(file); } });