Skip to content

Commit

Permalink
New: Allow specifying sourcemaps option as string in dest()
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound authored and phated committed Nov 30, 2017
1 parent f602e21 commit bcd55f2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ Default: `true` (always overwrite existing files)

##### `options.sourcemaps`

Enables sourcemap support on files passed through the stream. Will write inline soucemaps if specified as `true`. Uses [gulp-sourcemaps] under the hood.
Enables sourcemap support on files passed through the stream. Will write inline soucemaps if specified as `true`.
Specifying a `string` is shorthand for the path option. Uses [gulp-sourcemaps] under the hood.

Examples:

Expand All @@ -211,9 +212,7 @@ vfs.dest('./', {

// Write as files in the same folder
vfs.dest('./', {
sourcemaps: {
path: '.'
}
sourcemaps: '.'
});

// Any other options are passed through to [gulp-sourcemaps]
Expand All @@ -226,7 +225,7 @@ vfs.dest('./', {
});
```

Type: `Boolean` or `Object`
Type: `Boolean`, `String` or `Object`

Default: `undefined` (do not write sourcemaps)

Expand Down
5 changes: 5 additions & 0 deletions lib/dest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ function dest(outFolder, opt) {
if (typeof sourcemapOpt === 'boolean') {
sourcemapOpt = {};
}
if (typeof sourcemapOpt === 'string') {
sourcemapOpt = {
path: sourcemapOpt,
};
}

var mapStream = sourcemaps.write(sourcemapOpt.path, sourcemapOpt);
var outputStream = duplexify.obj(mapStream, saveStream);
Expand Down
26 changes: 26 additions & 0 deletions test/dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,32 @@ describe('dest stream', function() {
stream.end();
});

it('should not explode if the sourcemap option is string', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');

var expectedFile = new File({
base: __dirname,
cwd: __dirname,
path: inputPath,
contents: null,
});

var buffered = [];

var onEnd = function() {
buffered.length.should.equal(1);
buffered[0].should.equal(expectedFile);
done();
};

var bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);

var stream = vfs.dest(path.join(__dirname, './out-fixtures/'), { sourcemaps: '.' });
stream.pipe(bufferStream);
stream.write(expectedFile);
stream.end();
});

it('should not explode if sourcemap option is an object', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');

Expand Down
2 changes: 1 addition & 1 deletion test/not-owned/not-owned.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Something new
Something new

0 comments on commit bcd55f2

Please sign in to comment.