Skip to content

Commit

Permalink
Breaking: Remove extra newline added before sourcemap comment
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Jun 17, 2017
1 parent 8363195 commit 1b2f9a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
13 changes: 6 additions & 7 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ var fs = require('graceful-fs');
var File = require('vinyl');
var async = require('async');
var convert = require('convert-source-map');
var stripBom = require('strip-bom');
var detectNewline = require('detect-newline');
var normalizePath = require('normalize-path');
var fileNormalize = require('file-normalize');

var stripBom = fileNormalize.stripBOM;
var appendBuffer = fileNormalize.appendBuffer;

var urlRegex = /^(https?|webpack(-[^:]+)?):\/\//;

Expand Down Expand Up @@ -200,9 +202,6 @@ function createSourceMapFile(opts) {

// TODO: any way to make this function not require file?
function commentFormatter(file, url) {
// TODO: can this be built into convert-source-map?
var newline = detectNewline(file.contents.toString());

// TODO: Not sure I agree with this
if (file.extname !== '.js' && file.extname !== '.css') {
return '';
Expand All @@ -212,7 +211,7 @@ function commentFormatter(file, url) {
multiline: (file.extname === '.css')
};

return newline + convert.generateMapFileComment(url, opts) + newline;
return convert.generateMapFileComment(url, opts);
}

function includeContent(file, state, options, callback) {
Expand Down Expand Up @@ -306,7 +305,7 @@ function contentIncluded(file, state, options, callback) {

// append source map comment
if (options.addComment) {
file.contents = Buffer.concat([file.contents, new Buffer(comment)]);
file.contents = appendBuffer(file.contents, comment);
}

callback();
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
"dependencies": {
"async": "^2.1.4",
"convert-source-map": "1.3.0",
"detect-newline": "^2.1.0",
"file-normalize": "^1.1.0",
"graceful-fs": "^4.1.6",
"normalize-path": "^2.1.1",
"object.defaults": "^1.0.0",
"strip-bom": "^2.0.0",
"through2": "^2.0.1",
"vinyl": "^1.2.0"
}
Expand Down
12 changes: 6 additions & 6 deletions test/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('write', function() {
// TODO: Vinyl.isVinyl
expect(updatedFile instanceof File).toExist();
expect(updatedFile).toEqual(file);
expect(String(updatedFile.contents)).toBe( sourceContent + '\n//# sourceMappingURL=' + base64JSON(updatedFile.sourceMap) + '\n');
expect(String(updatedFile.contents)).toBe( sourceContent + '//# sourceMappingURL=' + base64JSON(updatedFile.sourceMap) + '\n');
done(err);
});
});
Expand All @@ -192,7 +192,7 @@ describe('write', function() {
var file = makeFile();
file.path = file.path.replace('.js', '.css');
sourcemaps.write(file, function(err, updatedFile) {
expect(String(updatedFile.contents)).toBe(sourceContent + '\n/*# sourceMappingURL=' + base64JSON(updatedFile.sourceMap) + ' */\n');
expect(String(updatedFile.contents)).toBe(sourceContent + '/*# sourceMappingURL=' + base64JSON(updatedFile.sourceMap) + ' */\n');
done(err);
});
});
Expand All @@ -210,7 +210,7 @@ describe('write', function() {
var file = makeFile();
file.contents = new Buffer(file.contents.toString().replace(/\n/g, '\r\n'));
sourcemaps.write(file, function(err, updatedFile) {
expect(String(updatedFile.contents)).toBe(sourceContent.replace(/\n/g, '\r\n') + '\r\n//# sourceMappingURL=' + base64JSON(updatedFile.sourceMap) + '\r\n');
expect(String(updatedFile.contents)).toBe(sourceContent.replace(/\n/g, '\r\n') + '//# sourceMappingURL=' + base64JSON(updatedFile.sourceMap) + '\r\n');
done(err);
});
});
Expand All @@ -220,7 +220,7 @@ describe('write', function() {
sourcemaps.write(file, { path: '../maps', destPath: 'dist' }, function(err, updatedFile, sourceMapFile) {
expect(updatedFile instanceof File).toExist();
expect(updatedFile).toEqual(file);
expect(String(updatedFile.contents)).toBe(sourceContent + '\n//# sourceMappingURL=../maps/helloworld.js.map\n');
expect(String(updatedFile.contents)).toBe(sourceContent + '//# sourceMappingURL=../maps/helloworld.js.map\n');
expect(updatedFile.sourceMap.file).toBe('../dist/helloworld.js');
expect(sourceMapFile instanceof File).toExist();
expect(sourceMapFile.path).toBe(path.join(__dirname, 'maps/helloworld.js.map'));
Expand All @@ -239,7 +239,7 @@ describe('write', function() {
it('should create shortest path to map in file comment', function(done) {
var file = makeNestedFile();
sourcemaps.write(file, { path: 'dir1/maps' }, function(err, updatedFile) {
expect(String(updatedFile.contents)).toBe(sourceContent + '\n//# sourceMappingURL=../maps/dir1/dir2/helloworld.js.map\n');
expect(String(updatedFile.contents)).toBe(sourceContent + '//# sourceMappingURL=../maps/dir1/dir2/helloworld.js.map\n');
done(err);
});
});
Expand Down Expand Up @@ -428,7 +428,7 @@ describe('write', function() {
}
}, function(err, updatedFile) {
if (/helloworld\.js$/.test(updatedFile.path)) {
expect(String(updatedFile.contents)).toBe(sourceContent + '\n//# sourceMappingURL=http://maps.example.com/dir1/dir2/helloworld.js.map\n');
expect(String(updatedFile.contents)).toBe(sourceContent + '//# sourceMappingURL=http://maps.example.com/dir1/dir2/helloworld.js.map\n');
done(err);
}
});
Expand Down

0 comments on commit 1b2f9a4

Please sign in to comment.