Skip to content

Commit ad18dc9

Browse files
committed
Breaking: Avoid error in write when sourceMap property did not exist on file (closes #5)
1 parent d74d061 commit ad18dc9

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ function write(file, destPath, options, callback) {
8181
return callback(new Error(PLUGIN_NAME + '-write: Not a vinyl file'));
8282
}
8383

84-
// Throw an error if the file doesn't have a sourcemap
85-
if (!file.sourceMap) {
86-
return callback(new Error(PLUGIN_NAME + '-write: No sourcemap found'));
84+
if (file.isStream()) {
85+
return callback(new Error(PLUGIN_NAME + '-write: Streaming not supported'));
86+
}
87+
88+
if (file.isNull() || !file.sourceMap) {
89+
return callback(null, file);
8790
}
8891

8992
// TODO: don't mutate - needs test too

test/write.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@ function makeSourceMap() {
2222
};
2323
}
2424

25-
function makeFile(addSourcemap) {
26-
if (addSourcemap === undefined) {
27-
addSourcemap = true;
28-
}
25+
function makeFile() {
2926
var file = new File({
3027
cwd: __dirname,
3128
base: path.join(__dirname, 'assets'),
3229
path: path.join(__dirname, 'assets', 'helloworld.js'),
33-
contents: new Buffer(sourceContent)
30+
contents: new Buffer(sourceContent),
31+
sourceMap: makeSourceMap(),
3432
});
35-
if (addSourcemap === true) {
36-
file.sourceMap = makeSourceMap();
37-
}
3833
return file;
3934
}
4035

@@ -83,11 +78,14 @@ describe('write', function() {
8378
});
8479
});
8580

86-
it('should return an error when no sourcemap is found on the file', function(done) {
87-
var file = makeFile(false);
88-
sourcemaps.write(file, function(err) {
89-
expect(err instanceof Error && err.message === 'vinyl-sourcemap-write: No sourcemap found').toExist();
90-
done();
81+
it('calls back with the untouched file if sourceMap property does not exist', function(done) {
82+
var file = makeFile();
83+
delete file.sourceMap;
84+
sourcemaps.write(file, function(err, outFile) {
85+
expect(err).toNotExist();
86+
expect(file).toExist();
87+
expect(outFile).toEqual(file);
88+
done(err);
9189
});
9290
});
9391

0 commit comments

Comments
 (0)