Skip to content

Commit 50c7e51

Browse files
authored
Merge pull request #126 from astronomersiva/master
Support publicUrl and hiddenSourceMap options
2 parents 7714420 + 1ff3ee6 commit 50c7e51

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ var uglified = uglify(input, {
2828
//...
2929
},
3030

31+
publicUrl: 'https://myamazingapp.com/', // value to be prepended to sourceMappingURL, defaults to ''
32+
hiddenSourceMap: false, // skips adding the reference to sourcemap in the minified JS, defaults to false
33+
3134
async: true, // run uglify in parallel, defaults to false
3235
concurrency: 3 // number of parallel workers, defaults to number of CPUs - 1
3336
});

lib/process-file.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ module.exports = function processFile(inFile, outFile, relativePath, outDir, sil
2626
let filename = path.basename(inFile);
2727
let url = _options.sourceMapDir ? `/${path.join(_options.sourceMapDir, mapName)}` : mapName;
2828

29+
let publicUrl = _options.publicUrl;
30+
if (publicUrl) {
31+
url = `${publicUrl}/${url}`;
32+
}
33+
34+
let hiddenSourceMap = _options.hiddenSourceMap;
35+
if (hiddenSourceMap) {
36+
url = '';
37+
}
38+
2939
let sourceMap = { filename, url };
3040

3141
if (srcURL.existsIn(src)) {

test/__snapshots__/test.js.snap

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,38 @@ Object {
143143
//# sourceMappingURL=/maps/with-broken-sourcemap.map",
144144
}
145145
`;
146+
147+
exports[`broccoli-uglify-sourcemap supports hidden sourcemaps 1`] = `
148+
Object {
149+
"inside": Object {
150+
"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\\")}",
151+
"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\\"]}",
152+
},
153+
"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\\")}",
154+
"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\\"}",
155+
"something.css": "#id {
156+
background: white;
157+
}",
158+
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}",
159+
"with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"0\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}",
160+
}
161+
`;
162+
163+
exports[`broccoli-uglify-sourcemap supports public URL for sourcemaps 1`] = `
164+
Object {
165+
"inside": Object {
166+
"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\\")}
167+
//# sourceMappingURL=https://example.com/with-upstream-sourcemap.map",
168+
"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\\"]}",
169+
},
170+
"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\\")}
171+
//# sourceMappingURL=https://example.com/no-upstream-sourcemap.map",
172+
"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\\"}",
173+
"something.css": "#id {
174+
background: white;
175+
}",
176+
"with-broken-sourcemap.js": "function meaningOfLife(){throw new Error(42)}
177+
//# sourceMappingURL=https://example.com/with-broken-sourcemap.map",
178+
"with-broken-sourcemap.map": "{\\"version\\":3,\\"sources\\":[\\"0\\"],\\"names\\":[\\"meaningOfLife\\",\\"Error\\"],\\"mappings\\":\\"AAAA,SAASA,gBAEP,MAAM,IAAIC,MADa\\",\\"file\\":\\"with-broken-sourcemap.js\\"}",
179+
}
180+
`;

test/test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ let { bar } = Foo.prototype;`,
6161
expect(builder.read()).toMatchSnapshot();
6262
});
6363

64+
it('supports hidden sourcemaps', async function() {
65+
builder = createBuilder(new Uglify(fixtures, { hiddenSourceMap: true }));
66+
67+
await builder.build();
68+
69+
expect(builder.read()).toMatchSnapshot();
70+
});
71+
72+
it('supports public URL for sourcemaps', async function() {
73+
builder = createBuilder(new Uglify(fixtures, { publicUrl: 'https://example.com' }));
74+
75+
await builder.build();
76+
77+
expect(builder.read()).toMatchSnapshot();
78+
});
79+
6480
it('can exclude files from getting uglified', async function() {
6581
builder = createBuilder(new Uglify(fixtures, {
6682
exclude: ['inside/with-up*'],

0 commit comments

Comments
 (0)