Skip to content

Commit bfd155b

Browse files
asgothnmccready
authored andcommitted
Adds an clone options to gulp-sourcemaps.write()
This can be used if keeping original file history is important
1 parent 8abf069 commit bfd155b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ gulp.src(['src/test.js', 'src/testdir/test2.js'], { base: 'src' })
300300

301301
Sets the charset for inline source maps. Default: `utf8`
302302

303+
- `clone`
304+
305+
Clones the original file for creation of the map file. Could be important if file history is important. See [file.clone()](https://github.com/gulpjs/vinyl#filecloneoptions) for possible options. Default: `undefined`
306+
303307
### Plugin developers only:
304308

305309
- **How to add source map support to plugins**

test/write.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,31 @@ test('write: should write external map files', function(t) {
188188
}).write(file);
189189
});
190190

191+
test('write: should keep original file history', function(t) {
192+
var file = makeFile();
193+
var pipeline = sourcemaps.write('../maps', {destPath: 'dist', clone: true});
194+
var outFiles = [];
195+
var fileCount = 0;
196+
pipeline
197+
.on('data', function(data) {
198+
outFiles.push(data);
199+
fileCount++;
200+
if (fileCount == 2) {
201+
outFiles.reverse().map(function (data) {
202+
if (data.path === path.join(__dirname, 'maps/helloworld.js.map')) {
203+
t.equal(data.history[0], path.join(__dirname, 'assets', 'helloworld.js'), 'should keep file history');
204+
}
205+
});
206+
t.end();
207+
}
208+
})
209+
.on('error', function() {
210+
t.fail('emitted error');
211+
t.end();
212+
})
213+
.write(file);
214+
});
215+
191216
test('write: should allow to rename map file', function(t) {
192217
var file = makeFile();
193218
var pipeline = sourcemaps.write('../maps', {

0 commit comments

Comments
 (0)