Skip to content

Commit

Permalink
Pass "flags" option to each transform
Browse files Browse the repository at this point in the history
Essentially, "flags" is set to the value of the bundler's
"_options" property.

This should enable more intelligent transform behaviours,
for example toggling source maps when --debug is supplied
through the CLI or module API.

Closes browserify#844
Fixes hughsk/uglifyify#16
Fixes hughsk/uglifyify#18

This should enable more intelligent transform behaviours,
for example toggling source maps when --debug is supplied
through the CLI.
  • Loading branch information
hughsk committed Sep 19, 2014
1 parent c7a918f commit e92b000
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ Browserify.prototype.transform = function (tr, opts) {
}
if (!opts) opts = {};

opts.flags = 'flags' in opts
? opts.flags
: self._options;

apply();
self.on('reset', apply);

Expand Down
36 changes: 36 additions & 0 deletions test/tr_flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var through = require('through2');
var browserify = require('../');
var test = require('tap').test;
var vm = require('vm');

test('--debug passed to transforms', function (t) {
var empty = require.resolve('../lib/_empty');

t.plan(3);

[true, false].forEach(function(debug) {
var b = browserify(empty, { debug: debug });

b.transform(function(file, opts) {
t.equal(opts.flags.debug, debug, 'debug: ' + debug);
return through();
});

b.bundle(function (err, src) {
if (err) return t.fail(err.message);
});
});

var b = browserify(empty, { debug: true });

b.transform({
flags: Infinity
}, function(file, opts) {
t.equal(opts.flags, Infinity, 'transform arguents are preserved');
return through();
});

b.bundle(function(err, src) {
if (err) return t.fail(err.message);
});
});

0 comments on commit e92b000

Please sign in to comment.