Skip to content

Commit

Permalink
Generate sourcemaps but omit the comment (#3120)
Browse files Browse the repository at this point in the history
* Generate sourcemaps without comment using `hidden` option (#2743)

Signed-off-by: Rohit Mohan <rohitmohan96@gmail.com>

* Added tests for hidden sourcemaps

Signed-off-by: Rohit Mohan <rohitmohan96@gmail.com>

* Added cli tests for hidden sourcemaps

Signed-off-by: Rohit Mohan <rohitmohan96@gmail.com>

* Update documentation and improve test
  • Loading branch information
rohitmohan96 authored and lukastaegert committed Sep 27, 2019
1 parent b8335db commit 962be76
Show file tree
Hide file tree
Showing 21 changed files with 149 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/999-big-list-of-options.md
Expand Up @@ -486,11 +486,11 @@ define(['https://d3js.org/d3.v4.min'], function (d3) {
```

#### output.sourcemap
Type: `boolean | 'inline'`<br>
Type: `boolean | 'inline' | 'hidden'`<br>
CLI: `-m`/`--sourcemap`/`--no-sourcemap`<br>
Default: `false`

If `true`, a separate sourcemap file will be created. If `inline`, the sourcemap will be appended to the resulting `output` file as a data URI.
If `true`, a separate sourcemap file will be created. If `"inline"`, the sourcemap will be appended to the resulting `output` file as a data URI. `"hidden"` works like `true` except that the corresponding sourcemap comments in the bundled files are suppressed.

#### output.sourcemapExcludeSources
Type: `boolean`<br>
Expand Down
4 changes: 3 additions & 1 deletion src/rollup/index.ts
Expand Up @@ -402,7 +402,9 @@ function writeOutputFile(
url = `${basename(outputFile.fileName)}.map`;
writeSourceMapPromise = writeFile(`${fileName}.map`, outputFile.map.toString());
}
source += `//# ${SOURCEMAPPING_URL}=${url}\n`;
if (outputOptions.sourcemap !== 'hidden') {
source += `//# ${SOURCEMAPPING_URL}=${url}\n`;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rollup/types.d.ts
Expand Up @@ -475,7 +475,7 @@ export interface OutputOptions {
outro?: string | (() => string | Promise<string>);
paths?: OptionsPaths;
preferConst?: boolean;
sourcemap?: boolean | 'inline';
sourcemap?: boolean | 'inline' | 'hidden';
sourcemapExcludeSources?: boolean;
sourcemapFile?: string;
sourcemapPathTransform?: (sourcePath: string) => string;
Expand Down
17 changes: 17 additions & 0 deletions test/cli/samples/sourcemap-hidden/_config.js
@@ -0,0 +1,17 @@
const fs = require('fs');
const assert = require('assert');

module.exports = {
description: 'omits sourcemap comments',
command: 'rollup -i main.js -f es -m hidden -o output.js',
test() {
assert.equal(fs.readFileSync('output.js', 'utf-8').trim(), 'console.log( 42 );');
fs.unlinkSync('output.js');
assert.equal(
fs.readFileSync('output.js.map', 'utf-8').trim(),
'{"version":3,"file":"output.js","sources":["main.js"],"sourcesContent":' +
'["console.log( 42 );\\n"],"names":[],"mappings":"AAAA,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC"}'
);
fs.unlinkSync('output.js.map');
}
};
1 change: 1 addition & 0 deletions test/cli/samples/sourcemap-hidden/main.js
@@ -0,0 +1 @@
console.log( 42 );
7 changes: 7 additions & 0 deletions test/form/samples/sourcemaps-hidden/_config.js
@@ -0,0 +1,7 @@
module.exports = {
description: 'correct sourcemaps are written (separate file) without comment',
skipIfWindows: true,
options: {
output: { sourcemap: 'hidden' }
}
};
16 changes: 16 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/amd.js
@@ -0,0 +1,16 @@
define(function () { 'use strict';

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();

});
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/amd.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/cjs.js
@@ -0,0 +1,14 @@
'use strict';

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/cjs.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/es.js
@@ -0,0 +1,12 @@
function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/es.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/iife.js
@@ -0,0 +1,17 @@
(function () {
'use strict';

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();

}());
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/iife.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/system.js
@@ -0,0 +1,21 @@
System.register([], function () {
'use strict';
return {
execute: function () {

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();

}
};
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions test/form/samples/sourcemaps-hidden/_expected/umd.js
@@ -0,0 +1,19 @@
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}(function () { 'use strict';

function foo () {
console.log( 'hello from foo.js' );
}

function bar () {
console.log( 'hello from bar.js' );
}

console.log( 'hello from main.js' );

foo();
bar();

}));
1 change: 1 addition & 0 deletions test/form/samples/sourcemaps-hidden/_expected/umd.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/form/samples/sourcemaps-hidden/bar.js
@@ -0,0 +1,3 @@
export default function bar () {
console.log( 'hello from bar.js' );
}
3 changes: 3 additions & 0 deletions test/form/samples/sourcemaps-hidden/foo.js
@@ -0,0 +1,3 @@
export default function foo () {
console.log( 'hello from foo.js' );
}
7 changes: 7 additions & 0 deletions test/form/samples/sourcemaps-hidden/main.js
@@ -0,0 +1,7 @@
import foo from './foo';
import bar from './bar';

console.log( 'hello from main.js' );

foo();
bar();

0 comments on commit 962be76

Please sign in to comment.