gulp-uglify
Advanced tools
Comparing version 1.5.4 to 2.0.0
'use strict'; | ||
var uglify = require('uglify-js'); | ||
var minifier = require('./minifier'); | ||
var GulpUglifyError = require('./lib/gulp-uglify-error'); | ||
@@ -8,1 +9,3 @@ module.exports = function (opts) { | ||
}; | ||
module.exports.GulpUglifyError = GulpUglifyError; |
'use strict'; | ||
var PluginError = require('gulp-util/lib/PluginError'); | ||
var curry = require('lodash/fp/curry'); | ||
var GulpUglifyError = require('./gulp-uglify-error'); | ||
var pluginName = 'gulp-uglify'; | ||
function createError(file, msg, cause) { | ||
var perr = new GulpUglifyError(msg, cause); | ||
perr.plugin = 'gulp-uglify'; | ||
perr.fileName = file.path; | ||
perr.showStack = false; | ||
return perr; | ||
} | ||
module.exports = function createError(file, err) { | ||
if (typeof err === 'string') { | ||
return new PluginError(pluginName, file.path + ': ' + err, { | ||
fileName: file.path, | ||
showStack: false | ||
}); | ||
} | ||
var msg = err.message || err.msg || 'unspecified error'; | ||
return new PluginError(pluginName, file.path + ': ' + msg, { | ||
fileName: file.path, | ||
lineNumber: err.line, | ||
stack: err.stack, | ||
showStack: false | ||
}); | ||
}; | ||
module.exports = curry(createError); |
'use strict'; | ||
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 isObject = require('lodash/fp/isObject'); | ||
var zipObject = require('lodash/fp/zipObject'); | ||
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 GulpUglifyError = require('./lib/gulp-uglify-error'); | ||
var reSourceMapComment = /\n\/\/# sourceMappingURL=.+?$/; | ||
var defaultOptions = defaultsDeep({ | ||
fromString: true, | ||
output: {} | ||
}); | ||
function trycatch(fn, handle) { | ||
@@ -23,10 +32,7 @@ try { | ||
if (opts && !isObject(opts)) { | ||
log('gulp-uglify expects an object, non-object provided'); | ||
log.warn('gulp-uglify expects an object, non-object provided'); | ||
opts = {}; | ||
} | ||
var options = deap({}, opts, { | ||
fromString: true, | ||
output: {} | ||
}); | ||
var options = defaultOptions(opts); | ||
@@ -50,2 +56,3 @@ if (options.preserveComments === 'all') { | ||
var options = setup(opts || {}); | ||
var sources; | ||
@@ -57,18 +64,25 @@ if (file.isNull()) { | ||
if (file.isStream()) { | ||
return callback(createError(file, 'Streaming not supported')); | ||
return callback(createError(file, 'Streaming not supported', null)); | ||
} | ||
if (file.sourceMap) { | ||
// UglifyJS generates broken source maps if the input source map | ||
// does not contain mappings. | ||
if (file.sourceMap.mappings) { | ||
options.inSourceMap = file.sourceMap; | ||
} | ||
options.outSourceMap = file.relative; | ||
sources = zipObject(file.sourceMap.sources, file.sourceMap.sourcesContent); | ||
} | ||
var originalContents = String(file.contents); | ||
var mangled = trycatch(function () { | ||
var m = uglify.minify(String(file.contents), options); | ||
var map = {}; | ||
map[file.relative] = String(file.contents); | ||
var m = uglify.minify(map, options); | ||
m.code = new Buffer(m.code.replace(reSourceMapComment, '')); | ||
return m; | ||
}, createError.bind(null, file)); | ||
}, createError(file, 'unable to minify JavaScript')); | ||
if (mangled instanceof PluginError) { | ||
if (mangled instanceof GulpUglifyError) { | ||
return callback(mangled); | ||
@@ -81,4 +95,4 @@ } | ||
var sourceMap = JSON.parse(mangled.map); | ||
sourceMap.sources = [file.relative]; | ||
sourceMap.sourcesContent = [originalContents]; | ||
sourceMap.sourcesContent = map(prop(_, sources), sourceMap.sources); | ||
applySourceMap(file, sourceMap); | ||
@@ -85,0 +99,0 @@ } |
{ | ||
"name": "gulp-uglify", | ||
"description": "Minify files with UglifyJS.", | ||
"version": "1.5.4", | ||
"version": "2.0.0", | ||
"author": "Terin Stock <terinjokes@gmail.com>", | ||
"bugs": "https://github.com/terinjokes/gulp-uglify/issues", | ||
"dependencies": { | ||
"deap": "^1.0.0", | ||
"fancy-log": "^1.0.0", | ||
"gulp-util": "^3.0.0", | ||
"isobject": "^2.0.0", | ||
"gulplog": "^1.0.0", | ||
"has-gulplog": "^0.1.0", | ||
"lodash": "^4.13.1", | ||
"make-error-cause": "^1.1.1", | ||
"through2": "^2.0.0", | ||
"uglify-js": "2.6.4", | ||
"uglify-js": "2.7.0", | ||
"uglify-save-license": "^0.4.1", | ||
@@ -18,8 +18,13 @@ "vinyl-sourcemaps-apply": "^0.2.0" | ||
"devDependencies": { | ||
"cmem": "^1.0.0", | ||
"coveralls": "^2.11.4", | ||
"gulp-concat": "^2.0.0", | ||
"gulp-sourcemaps": "^1.0.0", | ||
"intelli-espower-loader": "^1.0.1", | ||
"istanbul": "^0.4.0", | ||
"mississippi": "^1.2.0", | ||
"mocha": "^2.5.3", | ||
"power-assert": "^1.4.1", | ||
"semver": "^5.3.0", | ||
"tape": "^4.0.0", | ||
"testdouble": "^1.6.0", | ||
"vinyl": "^1.0.0", | ||
@@ -44,5 +49,5 @@ "xo": "^0.16.0" | ||
"scripts": { | ||
"test": "xo && istanbul cover ./node_modules/tape/bin/tape test/*.js", | ||
"test": "xo && mocha --require intelli-espower-loader", | ||
"coverage": "cat ./coverage/lcov.info | coveralls" | ||
} | ||
} |
@@ -92,8 +92,14 @@ # gulp-uglify [![][travis-shield-img]][travis-shield][![][appveyor-shield-img]][appveyor-shield][![][npm-dl-shield-img]][npm-shield][![][npm-v-shield-img]][npm-shield][![][coveralls-shield-img]][coveralls-shield] | ||
`gulp-uglify` emits an 'error' event if it is unable to minify a specific file. | ||
Wherever possible, the PluginError object will contain the following properties: | ||
The GulpUglifyError constructor is exported by this plugin for `instanceof` checks. | ||
It contains the following properties: | ||
- `fileName` | ||
- `lineNumber` | ||
- `message` | ||
- `fileName`: The full file path for the file being minified. | ||
- `cause`: The original UglifyJS error, if avialable. | ||
Most UglifyJS error messages have the following properties: | ||
- `message` (or `msg`) | ||
- `filename` | ||
- `line` | ||
## Using a Different UglifyJS | ||
@@ -107,3 +113,3 @@ | ||
// or another module (such as `uglify-js-harmony` for ES6 support) | ||
var minifer = require('gulp-uglify/minifier'); | ||
var minifier = require('gulp-uglify/minifier'); | ||
var pump = require('pump'); | ||
@@ -110,0 +116,0 @@ |
13641
9
116
140
13
+ Addedgulplog@^1.0.0
+ Addedhas-gulplog@^0.1.0
+ Addedlodash@^4.13.1
+ Addedmake-error-cause@^1.1.1
+ Addedlodash@4.17.21(transitive)
+ Addedmake-error@1.3.6(transitive)
+ Addedmake-error-cause@1.2.2(transitive)
+ Addeduglify-js@2.7.0(transitive)
- Removeddeap@^1.0.0
- Removedfancy-log@^1.0.0
- Removedgulp-util@^3.0.0
- Removedisobject@^2.0.0
- Removedansi-gray@0.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedansi-wrap@0.1.0(transitive)
- Removedarray-differ@1.0.0(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedbeeper@1.1.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedclone@1.0.4(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removeddateformat@2.2.0(transitive)
- Removeddeap@1.0.1(transitive)
- Removedduplexer2@0.0.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfancy-log@1.3.3(transitive)
- Removedgulp-util@3.0.8(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedisarray@0.0.1(transitive)
- Removedisobject@2.1.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basetostring@3.0.1(transitive)
- Removedlodash._basevalues@3.0.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash._reescape@3.0.0(transitive)
- Removedlodash._reevaluate@3.0.0(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.escape@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedlodash.template@3.6.2(transitive)
- Removedlodash.templatesettings@3.1.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmultipipe@0.1.2(transitive)
- Removedobject-assign@3.0.0(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtime-stamp@1.1.0(transitive)
- Removeduglify-js@2.6.4(transitive)
- Removedvinyl@0.5.3(transitive)
Updateduglify-js@2.7.0