From a31c803e24e757c7672f0205eb3204da12476dc8 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 24 Oct 2023 13:31:44 +0200 Subject: [PATCH] fix: Fix sourcemap file lookup --- lib/get-sourcemap-content.js | 10 +++++++--- lib/source-map-url.js | 18 ++++++++++++++++++ package.json | 2 +- test/__snapshots__/test.js.snap | 21 +++++++++++++++++++++ test/fixtures/with-sourcemap-like-string.js | 19 +++++++++++++++++++ yarn.lock | 7 ++++++- 6 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 lib/source-map-url.js create mode 100644 test/fixtures/with-sourcemap-like-string.js diff --git a/lib/get-sourcemap-content.js b/lib/get-sourcemap-content.js index 102c676..81df085 100644 --- a/lib/get-sourcemap-content.js +++ b/lib/get-sourcemap-content.js @@ -2,20 +2,24 @@ const fs = require('fs'); const path = require('path'); -const srcURL = require('source-map-url'); +const srcURL = require('./source-map-url'); module.exports = function getSourceMapContent(src, inFileDirname, relativePath, silent) { let urls = []; let matchedUrl; + srcURL.reset(); while ((matchedUrl = srcURL.getFrom(src)) !== null) { urls.push(matchedUrl); - src = srcURL.removeFrom(src); } if (urls.length) { for (let i = urls.length - 1; i >= 0; --i) { let sourceMapPath = path.join(inFileDirname, urls[i]); if (fs.existsSync(sourceMapPath)) { - return JSON.parse(fs.readFileSync(sourceMapPath)); + try { + return JSON.parse(fs.readFileSync(sourceMapPath)); + } catch (e) { + console.error('[ERROR] (broccoli-terser-sourcemap) failed to parse sourcemap file', sourceMapPath, e); + } } } if (!silent) { diff --git a/lib/source-map-url.js b/lib/source-map-url.js new file mode 100644 index 0000000..a6070a7 --- /dev/null +++ b/lib/source-map-url.js @@ -0,0 +1,18 @@ +'use strict'; + +// Forked from https://github.com/lydell/source-map-url/blob/master/source-map-url.js +// We use a slightly adjusted regex here +const convertSourceMap = require('convert-source-map'); + +module.exports = { + regex: convertSourceMap.mapFileCommentRegex, + + reset() { + this.regex = convertSourceMap.mapFileCommentRegex; + }, + + getFrom(code) { + const m = this.regex.exec(code); + return m ? m[1] || m[2] : null; + }, +}; diff --git a/package.json b/package.json index 1c29712..b8abc00 100644 --- a/package.json +++ b/package.json @@ -38,10 +38,10 @@ "dependencies": { "async-promise-queue": "^1.0.5", "broccoli-plugin": "^4.0.7", + "convert-source-map": "^2.0.0", "debug": "^4.3.1", "lodash.defaultsdeep": "^4.6.1", "matcher-collection": "^2.0.1", - "source-map-url": "^0.4.1", "symlink-or-copy": "^1.3.1", "terser": "^5.7.0", "walk-sync": "^2.2.0", diff --git a/test/__snapshots__/test.js.snap b/test/__snapshots__/test.js.snap index 23e352b..af8adc1 100644 --- a/test/__snapshots__/test.js.snap +++ b/test/__snapshots__/test.js.snap @@ -16,6 +16,7 @@ Object { background: white; }", "with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}", + "with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}", } `; @@ -65,6 +66,9 @@ function third(){ "with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)} //# sourceMappingURL=with-broken-sourcemap.map", "with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}", + "with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)} +//# sourceMappingURL=with-sourcemap-like-string.map", + "with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}", } `; @@ -102,6 +106,9 @@ Object { "with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)} //# sourceMappingURL=with-broken-sourcemap.map", "with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}", + "with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)} +//# sourceMappingURL=with-sourcemap-like-string.map", + "with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}", } `; @@ -131,6 +138,9 @@ Object { "with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)} //# sourceMappingURL=with-broken-sourcemap.map", "with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}", + "with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)} +//# sourceMappingURL=with-sourcemap-like-string.map", + "with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}", } `; @@ -164,6 +174,9 @@ Object { "with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)} //# sourceMappingURL=with-broken-sourcemap.map", "with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}", + "with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)} +//# sourceMappingURL=with-sourcemap-like-string.map", + "with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}", } `; @@ -178,6 +191,7 @@ Object { "no-upstream-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"no-upstream-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\",\\"boom\\",\\"somethingElse\\",\\"fourth\\",\\"third\\"],\\"mappings\\":\\"AACA,SAASA,gBAEP,MAAM,IAAIC,MADa,IAIzB,SAASC,OACP,MAAM,IAAID,MAAM,QAGlB,SAASE,gBACP,MAAM,IAAIF,MAAM,kBAMlB,SAASG,SACP,MAAM,IAAIH,MAAM,UAGlB,SAASI,QACP,MAAM,IAAIJ,MAAM\\",\\"file\\":\\"no-upstream-sourcemap.js\\"}", "with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}", "with-multi-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"/inner/first.js\\",\\"/inner/second.js\\",\\"/other/fourth.js\\",\\"/other/third.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\",\\"boom\\",\\"somethingElse\\",\\"fourth\\",\\"third\\"],\\"mappings\\":\\"AAAA,SAAAA,gBAEA,MAAA,IAAAC,MADA,IAIA,SAAAC,OACA,MAAA,IAAAD,MAAA,QCNA,SAAAE,gBACA,MAAA,IAAAF,MAAA,kBCEA,SAAAG,SACA,MAAA,IAAAH,MAAA,UCJA,SAAAI,QACA,MAAA,IAAAJ,MAAA\\",\\"file\\":\\"with-multi-sourcemap.js\\",\\"sourcesContent\\":[\\"function meaningOfLife() {\\\\n var thisIsALongLocal = 42;\\\\n throw new Error(thisIsALongLocal);\\\\n}\\\\n\\\\nfunction boom() {\\\\n throw new Error('boom');\\\\n}\\\\n\\",\\"function somethingElse() {\\\\n throw new Error(\\\\\\"somethign else\\\\\\");\\\\n}\\\\n\\",\\"\\\\n// Hello world\\\\n\\\\nfunction fourth(){\\\\n throw new Error('fourth');\\\\n}\\\\n\\",\\"function third(){\\\\n throw new Error(\\\\\\"oh no\\\\\\");\\\\n}\\\\n\\"]}", + "with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}", "with-upstream-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"/inner/first.js\\",\\"/inner/second.js\\",\\"/other/fourth.js\\",\\"/other/third.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\",\\"boom\\",\\"somethingElse\\",\\"fourth\\",\\"third\\"],\\"mappings\\":\\"AAAA,SAAAA,gBAEA,MAAA,IAAAC,MADA,IAIA,SAAAC,OACA,MAAA,IAAAD,MAAA,QCNA,SAAAE,gBACA,MAAA,IAAAF,MAAA,kBCEA,SAAAG,SACA,MAAA,IAAAH,MAAA,UCJA,SAAAI,QACA,MAAA,IAAAJ,MAAA\\",\\"file\\":\\"with-upstream-sourcemap.js\\",\\"sourcesContent\\":[\\"function meaningOfLife() {\\\\n var thisIsALongLocal = 42;\\\\n throw new Error(thisIsALongLocal);\\\\n}\\\\n\\\\nfunction boom() {\\\\n throw new Error('boom');\\\\n}\\\\n\\",\\"function somethingElse() {\\\\n throw new Error(\\\\\\"somethign else\\\\\\");\\\\n}\\\\n\\",\\"\\\\n// Hello world\\\\n\\\\nfunction fourth(){\\\\n throw new Error('fourth');\\\\n}\\\\n\\",\\"function third(){\\\\n throw new Error(\\\\\\"oh no\\\\\\");\\\\n}\\\\n\\"]}", }, "mjs": Object { @@ -195,6 +209,8 @@ Object { }", "with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)} //# sourceMappingURL=/maps/with-broken-sourcemap.map", + "with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)} +//# sourceMappingURL=/maps/with-sourcemap-like-string.map", } `; @@ -219,6 +235,8 @@ Object { }", "with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}", "with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}", + "with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}", + "with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}", } `; @@ -248,5 +266,8 @@ Object { "with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)} //# sourceMappingURL=https://example.com/with-broken-sourcemap.map", "with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"with-broken-sourcemap.js\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}", + "with-sourcemap-like-string.js": "function createURL(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)}function createURL2(e,n,a){var i=void 0===n?null:n,t=decodeBase64(e,void 0!==a&&a),c=t.indexOf(\\"\\\\n\\",10)+1,r=t.substring(c)+(i?\\"//# sourceMappingURL=\\"+i:\\"\\"),o=new Blob([r],{type:\\"application/javascript\\"});return URL.createObjectURL(o)} +//# sourceMappingURL=https://example.com/with-sourcemap-like-string.map", + "with-sourcemap-like-string.map": "{\\"version\\":3,\\"sources\\":[\\"with-sourcemap-like-string.js\\"],\\"names\\":[\\"createURL\\",\\"base64\\",\\"sourcemapArg\\",\\"enableUnicodeArg\\",\\"sourcemap\\",\\"undefined\\",\\"source\\",\\"decodeBase64\\",\\"start\\",\\"indexOf\\",\\"body\\",\\"substring\\",\\"blob\\",\\"Blob\\",\\"type\\",\\"URL\\",\\"createObjectURL\\",\\"createURL2\\"],\\"mappings\\":\\"AAAA,SAASA,UAAUC,EAAQC,EAAcC,GACrC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA4BA,EAAY,IACtFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ,GAG/B,SAASK,WAAWhB,EAAQC,EAAcC,GACtC,IAAIC,OAA6BC,IAAjBH,EAA6B,KAAOA,EAEhDI,EAASC,aAAaN,OADeI,IAArBF,GAAyCA,GAEzDK,EAAQF,EAAOG,QAAQ,KAAM,IAAM,EACnCC,EAAOJ,EAAOK,UAAUH,IAAUJ,EAAY,wBAA0BA,EAAY,IACpFQ,EAAO,IAAIC,KAAK,CAACH,GAAO,CAAEI,KAAM,2BACpC,OAAOC,IAAIC,gBAAgBJ\\",\\"file\\":\\"with-sourcemap-like-string.js\\"}", } `; diff --git a/test/fixtures/with-sourcemap-like-string.js b/test/fixtures/with-sourcemap-like-string.js new file mode 100644 index 0000000..eacd047 --- /dev/null +++ b/test/fixtures/with-sourcemap-like-string.js @@ -0,0 +1,19 @@ +function createURL(base64, sourcemapArg, enableUnicodeArg) { + var sourcemap = sourcemapArg === undefined ? null : sourcemapArg; + var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg; + var source = decodeBase64(base64, enableUnicode); + var start = source.indexOf('\n', 10) + 1; + var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : ''); + var blob = new Blob([body], { type: 'application/javascript' }); + return URL.createObjectURL(blob); +} + +function createURL2(base64, sourcemapArg, enableUnicodeArg) { + var sourcemap = sourcemapArg === undefined ? null : sourcemapArg; + var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg; + var source = decodeBase64(base64, enableUnicode); + var start = source.indexOf('\n', 10) + 1; + var body = source.substring(start) + (sourcemap ? '//# sourceMappingURL=' + sourcemap : ''); + var blob = new Blob([body], { type: 'application/javascript' }); + return URL.createObjectURL(blob); +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 4827c36..df60fa2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1960,6 +1960,11 @@ convert-source-map@^1.6.0, convert-source-map@^1.7.0: dependencies: safe-buffer "~5.1.1" +convert-source-map@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a" + integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg== + copy-concurrently@^1.0.0: version "1.0.5" resolved "https://registry.yarnpkg.com/copy-concurrently/-/copy-concurrently-1.0.5.tgz#92297398cae34937fcafd6ec8139c18051f0b5e0" @@ -6089,7 +6094,7 @@ source-map-support@^0.5.6, source-map-support@~0.5.19: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-url@^0.4.0, source-map-url@^0.4.1: +source-map-url@^0.4.0: version "0.4.1" resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.1.tgz#0af66605a745a5a2f91cf1bbf8a7afbc283dec56" integrity sha512-cPiFOTLUKvJFIg4SKVScy4ilPPW6rFgMgfuZJPNoDuMs3nC1HbMUycBoJw77xFIp6z1UJQJOfx6C9GMH80DiTw==