Skip to content

Commit

Permalink
fix(minifier): detect non-object options argument
Browse files Browse the repository at this point in the history
Fixes #98.
  • Loading branch information
terinjokes committed Sep 9, 2015
1 parent f8412fd commit 557b4d2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
9 changes: 8 additions & 1 deletion minifier.js
Expand Up @@ -2,8 +2,10 @@
var through = require('through2');
var deap = require('deap');
var PluginError = require('gulp-util/lib/PluginError');
var log = require('fancy-log');
var applySourceMap = require('vinyl-sourcemaps-apply');
var saveLicense = require('uglify-save-license');
var isObject = require('isobject');
var reSourceMapComment = /\n\/\/# sourceMappingURL=.+?$/;
var pluginName = 'gulp-uglify';

Expand All @@ -16,6 +18,11 @@ function trycatch(fn, handle) {
}

function setup(opts) {
if (opts && !isObject(opts)) {
log('gulp-uglify expects an object, non-object provided');
opts = {};
}

var options = deap({}, opts, {
fromString: true,
output: {}
Expand All @@ -27,7 +34,7 @@ function setup(opts) {
// preserve comments with directives or that start with a bang (!)
options.output.comments = /^!|@preserve|@license|@cc_on/i;
} else if (options.preserveComments === 'license') {
options.output.comments = saveLicense
options.output.comments = saveLicense;
} else if (typeof options.preserveComments === 'function') {
options.output.comments = options.preserveComments;
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -6,7 +6,9 @@
"bugs": "https://github.com/terinjokes/gulp-uglify/issues",
"dependencies": {
"deap": ">=1.0.0 <2.0.0-0",
"fancy-log": ">=1.0.0 <2.0.0-0",
"gulp-util": ">=3.0.0 <4.0.0-0",
"isobject": ">=2.0.0 <3.0.0-0",
"through2": ">=2.0.0 <3.0.0-0",
"uglify-js": "2.4.24",
"uglify-save-license": ">=0.4.1 <0.5.0-0",
Expand Down
21 changes: 21 additions & 0 deletions test/minify.js
Expand Up @@ -34,3 +34,24 @@ test('should minify files', function(t) {
stream.write(testFile1);
stream.end();
});

test('should minify files when string is passed as argument', function(t) {
t.plan(7);

var stream = gulpUglify('build.min.js');

stream.on('data', function(newFile) {
t.ok(newFile, 'emits a file');
t.ok(newFile.path, 'file has a path');
t.ok(newFile.relative, 'file has relative path information');
t.ok(newFile.contents, 'file has contents');

t.ok(newFile instanceof Vinyl, 'file is Vinyl');
t.ok(newFile.contents instanceof Buffer, 'file contents are a buffer');

t.equals(String(newFile.contents), testContentsExpected);
});

stream.write(testFile1);
stream.end();
});

0 comments on commit 557b4d2

Please sign in to comment.