Socket
Socket
Sign inDemoInstall

gulp-uglify

Package Overview
Dependencies
37
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.4 to 2.0.0

lib/gulp-uglify-error.js

3

index.js
'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;

29

lib/create-error.js
'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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc