Skip to content

Commit

Permalink
Deprecate options.identityMap and export identityMap stream
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Apr 10, 2017
1 parent 8039c13 commit b42ba11
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ gulp.task('javascript', function() {
});
```
#### Generate Identity Sourcemap
The exported `identityMap` method allows you to generate a full valid source map encoding no changes (slower, only for Javascript and CSS) instead of the default empty source map (no mappings, fast). __Use this option if you get missing or incorrect mappings, e.g. when debugging.__
Example:
```javascript
gulp.task('javascript', function() {
var stream = gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
// An identity sourcemap will be generated at this step
.pipe(sourcemaps.identityMap())
.pipe(plugin1())
.pipe(plugin2())
.pipe(sourcemaps.write('../maps')
.pipe(gulp.dest('public/scripts'));
});
```
### Init Options
Expand All @@ -148,9 +165,7 @@ gulp.task('javascript', function() {
- `identityMap`
Set to true to generate a full valid source map encoding no changes (slower, only
for Javascript and CSS) instead of the default empty source map (no mappings, fast).
Use this option if you get missing or incorrect mappings, e.g. when debugging.
__This option is deprecated. Upgrade to use our [`sourcemap.identityMap`](#generate-identity-sourcemap) API.__
### Write Options
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
module.exports = {
init: require('./src/init'),
write: require('./src/write'),
mapSources: require('@gulp-sourcemaps/map-sources')
mapSources: require('@gulp-sourcemaps/map-sources'),
identityMap: require('@gulp-sourcemaps/identity-map')
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"author": "Florian Reiterer <me@florianreiterer.com>",
"license": "ISC",
"dependencies": {
"@gulp-sourcemaps/identity-map": "1.X",
"@gulp-sourcemaps/map-sources": "1.X",
"acorn": "4.X",
"convert-source-map": "1.X",
Expand Down
1 change: 1 addition & 0 deletions src/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function init(options) {
}

if (!sourceMap && options.identityMap) {
debug(function() { return '**identityMap option is deprecated, update to use sourcemap.identityMap stream**'; });
debug(function() {
return 'identityMap';
});
Expand Down
65 changes: 65 additions & 0 deletions test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var test = require('tape');
//BEGIN PRE-HOOK of debug
var yargs = require('yargs').argv;
var debug = require('debug-fabulous')();
var miss = require('mississippi');

var from = miss.from;
var pipe = miss.pipe;
var concat = miss.concat;

if (!yargs.ignoreLogTests){
debug.save('gulp-sourcemaps:*');
Expand Down Expand Up @@ -153,6 +158,66 @@ test('init: should add a valid source map for css if wished', function(t) {
}).write(makeFileCSS());
});

test('init: can replace `identityMap` option with sourcemap.identityMap stream (js file)', function(t) {
var file = makeFile();

function assert(files) {
t.ok(files[0], 'should pass something through');
t.ok(files[0] instanceof File, 'should pass a vinyl file through');
t.ok(files[0].sourceMap, 'should add a source map object');
t.equal(String(files[0].sourceMap.version), '3', 'should have version 3');
t.equal(files[0].sourceMap.sources[0], 'helloworld.js', 'should add file to sources');
t.equal(files[0].sourceMap.sourcesContent[0], sourceContent, 'should add file content to sourcesContent');
t.deepEqual(files[0].sourceMap.names, [
'helloWorld', 'console', 'log'
], 'should add correct names');
t.equal(files[0].sourceMap.mappings, 'AAAA,YAAY;;AAEZ,SAASA,UAAU,CAAC,EAAE;IAClBC,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC;AAC/B', 'should add correct mappings');
}

pipe([
from.obj([file]),
sourcemaps.init(),
sourcemaps.identityMap(),
sourcemaps.write(),
concat(assert)
], function(err) {
if (err) {
t.fail('emitted error');
}

t.end();
});
});

test('init: can replace `identityMap` option with sourcemap.identityMap stream (css file)', function(t) {
var file = makeFileCSS();

function assert(files) {
t.ok(files[0], 'should pass something through');
t.ok(files[0] instanceof File, 'should pass a vinyl file through');
t.ok(files[0].sourceMap, 'should add a source map object');
t.equal(String(files[0].sourceMap.version), '3', 'should have version 3');
t.equal(files[0].sourceMap.sources[0], 'test.css', 'should add file to sources');
t.equal(files[0].sourceMap.sourcesContent[0], sourceContentCSS, 'should add file content to sourcesContent');
t.deepEqual(files[0].sourceMap.names, [], 'should add correct names');
t.equal(files[0].sourceMap.mappings, 'CAAC;GACE;GACA', 'should add correct mappings');
}

pipe([
from.obj([file]),
sourcemaps.init(),
sourcemaps.identityMap(),
sourcemaps.write(),
concat(assert)
], function(err) {
if (err) {
t.fail('emitted error');
}

t.end();
});
});

test('init: should import an existing inline source map', function(t) {
var pipeline = sourcemaps.init({loadMaps: true});
pipeline.on('data', function(data) {
Expand Down

0 comments on commit b42ba11

Please sign in to comment.