Skip to content

Commit

Permalink
Merge pull request #74 from gynzy/hidden-sourcemaps
Browse files Browse the repository at this point in the history
feat: allow none as mapCommentType
  • Loading branch information
ef4 committed Jul 19, 2023
2 parents 8b23040 + e201eb3 commit dba9de6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Type: `string`

If `'line'` is specified, `sourceMappingURL` will be written in a single-line comment (`//`).

If `'none'` is specified, no reference to the source map is included in the source file.

If anything else truthy is specified, `sourceMappingURL` will be written in a block comment (`/* */`).

If no value is given, or a falsey value is given, will default to `'line'`.
Expand Down
13 changes: 9 additions & 4 deletions lib/source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,15 @@ class SourceMap {
sourceMappingUrl = `${dataUrlPrelude}${base64Content}`;
}

if (sourceMap.mapCommentType === 'line') {
stream.write('//# sourceMappingURL=' + sourceMappingUrl + '\n');
} else {
stream.write('/*# sourceMappingURL=' + sourceMappingUrl + ' */\n');
switch (sourceMap.mapCommentType) {
case 'line':
stream.write('//# sourceMappingURL=' + sourceMappingUrl + '\n');
break;
case 'none':
break;
default:
stream.write('/*# sourceMappingURL=' + sourceMappingUrl + ' */\n');
break;
}

if (sourceMap.mapFile) {
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ describe('fast sourcemap concat', function() {
});
});

it("outputs no comments when 'mapCommentType' is 'none'", function() {
let FILE = 'tmp/mapcommenttype.css';
let s = new SourceMap({outputFile: FILE, mapCommentType: 'none'});
return s.end().then(function() {
let result = fs.readFileSync(FILE, 'utf-8');
let expected = "";
assert.equal(result, expected);
});
});

it("should warn but tolerate broken sourcemap URL", function() {
let s = new SourceMap({outputFile: 'tmp/with-broken-input-map.js', baseDir: path.join(__dirname, 'fixtures')});
s._warn = sinon.spy();
Expand Down

0 comments on commit dba9de6

Please sign in to comment.