From 7c182a82ff494dd979421b7a5bf7befb607c3e06 Mon Sep 17 00:00:00 2001 From: Sivasubramanyam A Date: Sun, 17 Feb 2019 16:41:54 +0530 Subject: [PATCH 1/2] Support publicUrl and hiddenSourceMap options --- lib/process-file.js | 10 ++++++++++ test/__snapshots__/test.js.snap | 35 +++++++++++++++++++++++++++++++++ test/test.js | 16 +++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/lib/process-file.js b/lib/process-file.js index 40ca04c..a908293 100644 --- a/lib/process-file.js +++ b/lib/process-file.js @@ -26,6 +26,16 @@ module.exports = function processFile(inFile, outFile, relativePath, outDir, sil let filename = path.basename(inFile); let url = _options.sourceMapDir ? `/${path.join(_options.sourceMapDir, mapName)}` : mapName; + let publicUrl = _options.publicUrl; + if (publicUrl) { + url = `${publicUrl}/${url}`; + } + + let hiddenSourceMap = _options.hiddenSourceMap; + if (hiddenSourceMap) { + url = ''; + } + let sourceMap = { filename, url }; if (srcURL.existsIn(src)) { diff --git a/test/__snapshots__/test.js.snap b/test/__snapshots__/test.js.snap index 0f52dd4..e144c73 100644 --- a/test/__snapshots__/test.js.snap +++ b/test/__snapshots__/test.js.snap @@ -143,3 +143,38 @@ Object { //# sourceMappingURL=/maps/with-broken-sourcemap.map", } `; + +exports[`broccoli-uglify-sourcemap supports hidden sourcemaps 1`] = ` +Object { + "inside": Object { + "with-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")}", + "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\\"]}", + }, + "no-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")}", + "no-upstream-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"0\\"],\\"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\\"}", + "something.css": "#id { + background: white; +}", + "with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}", + "with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"0\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}", +} +`; + +exports[`broccoli-uglify-sourcemap supports public URL for sourcemaps 1`] = ` +Object { + "inside": Object { + "with-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")} +//# sourceMappingURL=https://example.com/with-upstream-sourcemap.map", + "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\\"]}", + }, + "no-upstream-sourcemap.js": "function meaningOfLife(){throw new Error(42)}function boom(){throw new Error(\\"boom\\")}function somethingElse(){throw new Error(\\"somethign else\\")}function fourth(){throw new Error(\\"fourth\\")}function third(){throw new Error(\\"oh no\\")} +//# sourceMappingURL=https://example.com/no-upstream-sourcemap.map", + "no-upstream-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"0\\"],\\"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\\"}", + "something.css": "#id { + background: white; +}", + "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\\":[\\"0\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}", +} +`; diff --git a/test/test.js b/test/test.js index 928b4b5..32ba015 100644 --- a/test/test.js +++ b/test/test.js @@ -61,6 +61,22 @@ let { bar } = Foo.prototype;`, expect(builder.read()).toMatchSnapshot(); }); + it('supports hidden sourcemaps', async function() { + builder = createBuilder(new Uglify(fixtures, { hiddenSourceMap: true })); + + await builder.build(); + + expect(builder.read()).toMatchSnapshot(); + }); + + it('supports public URL for sourcemaps', async function() { + builder = createBuilder(new Uglify(fixtures, { publicUrl: 'https://example.com' })); + + await builder.build(); + + expect(builder.read()).toMatchSnapshot(); + }); + it('can exclude files from getting uglified', async function() { builder = createBuilder(new Uglify(fixtures, { exclude: ['inside/with-up*'], From 1ff3ee65b7f60732c9270f8c54f36e95a96aede2 Mon Sep 17 00:00:00 2001 From: Sivasubramanyam A Date: Wed, 6 Mar 2019 15:31:09 +0530 Subject: [PATCH 2/2] Updare README with publicUrl and hiddenSourceMap --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 91d4e4a..915bda2 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ var uglified = uglify(input, { //... }, + publicUrl: 'https://myamazingapp.com/', // value to be prepended to sourceMappingURL, defaults to '' + hiddenSourceMap: false, // skips adding the reference to sourcemap in the minified JS, defaults to false + async: true, // run uglify in parallel, defaults to false concurrency: 3 // number of parallel workers, defaults to number of CPUs - 1 });