Skip to content

Commit

Permalink
fix(minifer): use gulplog for the warning
Browse files Browse the repository at this point in the history
Allows `gulp-cli` to format the log line based on the user's current
options.
  • Loading branch information
terinjokes committed Aug 1, 2016
1 parent 8160697 commit 5632cee
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
15 changes: 15 additions & 0 deletions lib/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
var hasLog = require('has-gulplog');
var each = require('lodash/fp/forEach');

var levels = ['debug', 'info', 'warn', 'error'];

each(function (level) {
module.exports[level] = function () {
if (hasLog()) {
var log = require('gulplog');

log[level].apply(log, arguments);
}
};
}, levels);
4 changes: 2 additions & 2 deletions minifier.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
var through = require('through2');
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('lodash/fp/isObject');
Expand All @@ -10,6 +9,7 @@ var map = require('lodash/fp/map');
var prop = require('lodash/fp/prop');
var _ = require('lodash/fp/placeholder');
var defaultsDeep = require('lodash/fp/defaultsDeep');
var log = require('./lib/log');
var createError = require('./lib/create-error');

var reSourceMapComment = /\n\/\/# sourceMappingURL=.+?$/;
Expand All @@ -29,7 +29,7 @@ function trycatch(fn, handle) {

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

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"author": "Terin Stock <[email protected]>",
"bugs": "https://github.com/terinjokes/gulp-uglify/issues",
"dependencies": {
"fancy-log": "^1.0.0",
"gulp-util": "^3.0.0",
"gulplog": "^1.0.0",
"has-gulplog": "^0.1.0",
"lodash": "^4.13.1",
"through2": "^2.0.0",
"uglify-js": "2.7.0",
Expand Down
7 changes: 6 additions & 1 deletion test/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var test = require('tape');
var Vinyl = require('vinyl');
var uglifyjs = require('uglify-js');
var gulplog = require('gulplog');
var gulpUglify = require('../');

var testContentsInput = '"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))';
Expand Down Expand Up @@ -36,10 +37,14 @@ test('should minify files', function (t) {
});

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

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

gulplog.on('warn', function (msg) {
t.ok(msg, 'gulp-uglify expects an object, non-object provided');
});

stream.on('data', function (newFile) {
t.ok(newFile, 'emits a file');
t.ok(newFile.path, 'file has a path');
Expand Down

0 comments on commit 5632cee

Please sign in to comment.