Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-uglify

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-uglify - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

CHANGELOG.md

60

index.js

@@ -1,18 +0,56 @@

var es = require('event-stream'),
uglify = require('uglify-js');
'use strict';
var through = require('through2'),
uglify = require('uglify-js'),
merge = require('deepmerge'),
Vinyl = require('vinyl');
module.exports = function(opt) {
'use strict';
opt = opt || {};
opt.fromString = true;
function minify(file, encoding, callback) {
/*jshint validthis:true */
var options = merge(opt || {}, {
fromString: true,
output: {}
});
return es.map(function (file, callback) {
var mangled,
map;
if (options.outSourceMap === true) {
options.outSourceMap = file.relative + '.map';
}
if (options.preserveComments === 'all') {
options.output.comments = true;
} else if (options.preserveComments === 'some') {
// preserve comments with directives or that start with a bang (!)
options.output.comments = /^!|@preserve|@license|@cc_on/i;
} else if (typeof options.preserveComments === 'function') {
options.output.comments = options.preserveComments;
}
try {
file.contents = new Buffer(uglify.minify(String(file.contents), opt).code);
} catch(e) {
console.warn('Error caught from uglify: ' + e.message + '. Returning unminified code');
mangled = uglify.minify(String(file.contents), options);
file.contents = new Buffer(mangled.code);
this.push(file);
} catch (e) {
console.warn('Error caught from uglify: ' + e.message + ' in ' + file.path + '. Returning unminifed code');
this.push(file);
return callback();
}
callback(null, file);
});
if (options.outSourceMap) {
map = new Vinyl({
cwd: file.cwd,
base: file.base,
path: file.path + '.map',
contents: new Buffer(mangled.map)
});
this.push(map);
}
callback();
}
return through.obj(minify);
};

17

package.json
{
"name": "gulp-uglify",
"version": "0.1.0",
"version": "0.2.0",
"description": "Minify files with UglifyJS.",

@@ -12,9 +12,10 @@ "keywords": [

"dependencies": {
"event-stream": "~3.0.15",
"uglify-js": "~2.4.6",
"clone": "~0.1.9"
"through2": "~0.4.0",
"vinyl": "~0.2.3",
"deepmerge": "~0.2.7"
},
"main": "index.js",
"engines": {
"node": ">= 0.6"
"node": ">= 0.9"
},

@@ -27,4 +28,8 @@ "scripts": {

"chai": "~1.8.1",
"gulp": "~2.6.0"
}
"gulp": ">= 3.4.0 <3.6.0"
},
"peerDependencies": {
"gulp": ">= 3.4.0 <3.6.0"
},
"license": "MIT"
}

@@ -15,3 +15,3 @@ [![Build Status](https://travis-ci.org/terinjokes/gulp-uglify.png?branch=master)](https://travis-ci.org/terinjokes/gulp-uglify)

<td>Node Version</td>
<td>≥ 0.6</td>
<td>≥ 0.9</td>
</tr>

@@ -26,31 +26,58 @@ </table>

gulp.task('compress', function() {
gulp.files('./lib/*.js')
.pipe(uglify())
.pipe(gulp.folder('./dist/'))
gulp.src('lib/*.js')
.pipe(uglify({outSourceMaps: true))
.pipe(gulp.dest('dist'))
});
```
## LICENSE
## Options
(MIT License)
- `mangle`
> Copyright (c) 2013 Terin Stock <terinjokes@gmail.com>
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
> "Software"), to deal in the Software without restriction, including
> without limitation the rights to use, copy, modify, merge, publish,
> distribute, sublicense, and/or sell copies of the Software, and to
> permit persons to whom the Software is furnished to do so, subject to
> the following conditions:
>
> The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
> LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
> OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
> WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Pass `false` to skip mangling names.
- `output`
Pass an object if you wish to specify additional [output
options](http://lisperator.net/uglifyjs/codegen). The defaults are
optimized for best compression.
- `compress`
Pass an object to specify custom [compressor
options](http://lisperator.net/uglifyjs/compress). Pass `false` to skip
compression completely.
- `preserveComments`
A convenience option for `options.output.comments`. Defaults to preserving no
comments.
- `all`
Preserve all comments in code blocks
- `some`
Preserve comments that start with a bang (`!`) or include a Closure
Compiler directive (`@preserve`, `@license`, `@cc_on`)
- `function`
Specify your own comment preservation function. You will be passed the
current node and the current comment and are expected to return either
`true` or `false`.
You can also pass the `uglify` function any of the options [listed
here](https://github.com/mishoo/UglifyJS2#the-simple-way) to modify
UglifyJS's behavior.
### Source Maps
You can have UglifyJS’s generated source maps emitted on the stream by passing
`true` for the `outSourceMap` option. The file object’s path will be based on
the input file’s, with ‘.map’ appended.
Input source maps are no supported by this plugin at this time.

@@ -1,2 +0,2 @@

/*
/*!
* Licensed under the MIT license.

@@ -29,2 +29,2 @@ */

return a;
}())
}())
'use strict';
/* globals describe, it */
var gulp = require('gulp'),
expect = require('chai').expect,
uglify = require('../'),
uglifyjs = require('uglify-js'),
es = require('event-stream'),
fs = require('fs'),
path = require('path');
expect = require('chai').expect,
uglify = require('..'),
uglifyjs = require('uglify-js'),
through = require('through2'),
fs = require('fs'),
path = require('path');

@@ -17,5 +17,6 @@ describe('gulp-uglify minification', function() {

.pipe(uglify())
.pipe(es.map(function(file){
.pipe(through.obj(function(file, encoding, callback) {
var expected = uglifyjs.minify(filename).code;
expect(String(file.contents)).to.equal(expected);
callback();
done();

@@ -29,4 +30,5 @@ }));

.pipe(uglify())
.pipe(es.map(function(file) {
.pipe(through.obj(function(file, encoding, callback) {
expect(file.contents).to.be.an.instanceof(Buffer);
callback();
done();

@@ -40,9 +42,39 @@ }));

.pipe(uglify())
.pipe(es.map(function(file) {
.pipe(through.obj(function(file, encoding, callback) {
var expected = fs.readFileSync(filename, 'utf-8');
expect(String(file.contents)).to.equal(expected);
callback();
done();
}));
});
it('should dynamically name source map files', function(done) {
var filename = path.join(__dirname, './fixtures/data.js');
gulp.src(filename)
.pipe(uglify({outSourceMap: true}))
.pipe(through.obj(function(file, encoding, callback) {
var map;
if (/\.map/.test(file.path)) {
map = JSON.parse(file.contents);
expect(file.path).to.equal(filename + '.map');
expect(map).to.be.an.instanceof(Object);
done();
}
callback();
}));
});
it('should preserve some comments', function(done) {
var filename = path.join(__dirname, './fixtures/data.js');
gulp.src(filename)
.pipe(uglify({preserveComments: 'some'}))
.pipe(through.obj(function(file, encoding, callback) {
expect(file.contents).to.be.an.instanceof(Buffer);
expect(/MIT/.test(file.contents)).to.be.true;
callback();
done();
}));
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc