Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gruntjs/grunt-contrib-uglify
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.1
Choose a base ref
...
head repository: gruntjs/grunt-contrib-uglify
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.6.0
Choose a head ref
  • 16 commits
  • 15 files changed
  • 8 contributors

Commits on Jun 30, 2014

  1. Properly encode URI paths, closes #222

    UltCombo committed Jun 30, 2014
    Copy the full SHA
    88c3c71 View commit details

Commits on Jul 28, 2014

  1. Copy input source map's sourcesContent into the final source map.

    (IFF options.sourceMapIncludeSources is true)
    bobzoller committed Jul 28, 2014
    Copy the full SHA
    5b444de View commit details

Commits on Aug 2, 2014

  1. Merge pull request #208 from goodeggs/sourcemapin_sources

    Copy input source map's sourcesContent into the final source map.
    vladikoff committed Aug 2, 2014
    Copy the full SHA
    b24445a View commit details

Commits on Aug 16, 2014

  1. Merge pull request #224 from UltCombo/map-uri-path

    Properly encode URI paths, closes #222
    vladikoff committed Aug 16, 2014
    Copy the full SHA
    b5eaaea View commit details

Commits on Aug 25, 2014

  1. Copy the full SHA
    df524ba View commit details
  2. Merge pull request #251 from radkodinev/run-jshint-with-tests

    First check code with jshint upon running npm/grunt test
    vladikoff committed Aug 25, 2014
    Copy the full SHA
    fae9226 View commit details

Commits on Aug 26, 2014

  1. Update dependencies.

    XhmikosR committed Aug 26, 2014
    Copy the full SHA
    e9be500 View commit details
  2. Merge pull request #253 from XhmikosR/master

    Update dependencies.
    sindresorhus committed Aug 26, 2014
    Copy the full SHA
    e002480 View commit details

Commits on Aug 27, 2014

  1. Copy the full SHA
    9179ebc View commit details
  2. Copy the full SHA
    44102f6 View commit details
  3. force LF on JS files - #253

    sindresorhus committed Aug 27, 2014
    Copy the full SHA
    395be84 View commit details
  4. Copy the full SHA
    e75540c View commit details

Commits on Aug 28, 2014

  1. Copy the full SHA
    8049a67 View commit details
  2. Copy the full SHA
    ab671ba View commit details

Commits on Sep 7, 2014

  1. Merge pull request #255 from ZitRos/master

    maxLineLen and ASCIIOnly options support
    vladikoff committed Sep 7, 2014
    Copy the full SHA
    185cab0 View commit details

Commits on Sep 18, 2014

  1. 0.6.0

    vladikoff committed Sep 18, 2014
    Copy the full SHA
    1145011 View commit details
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.js text eol=lf
*.js.map text eol=lf
20 changes: 11 additions & 9 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
v0.5.0:
date: 2014-06-11
changes:
- added option "expression" to uglify json and single functions.
- Removes unnecessary source map function.
- Simplify default source map naming function.
- Normalizes header and footer linefeeds.
- Source map names follow specs.
- Updates sourcemapin fixture.
v0.6.0:
date: 2014-09-17
changes:
- Output fixes.
- ASCIIOnly option.
- Other fixes.
v0.5.1:
date: 2014-07-25
changes:
- Chalk updates.
- Output updates.
v0.4.0:
date: 2014-03-01
changes:
36 changes: 34 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -113,6 +113,22 @@ module.exports = function(grunt) {
wrap: 'testExport'
}
},
maxLineLen: {
src: 'test/fixtures/src/simple2.js',
dest: 'tmp/maxLineLen.js',
options: {
mangle: false,
maxLineLen: 100
}
},
ASCIIOnly: {
src: 'test/fixtures/src/localization.js',
dest: 'tmp/asciionly.js',
options: {
mangle: false,
ASCIIOnly: true
}
},
exportAll: {
src: 'test/fixtures/src/simple.js',
dest: 'tmp/exportAll.js',
@@ -198,6 +214,18 @@ module.exports = function(grunt) {
sourceMapIncludeSources: true
}
},
sourcemapin_sources: {
files: {
'tmp/sourcemapin_sources.js': ['test/fixtures/src/simple2.js']
},
options: {
sourceMap: true,
sourceMapIn: function() {
return 'test/fixtures/src/simple2.map';
},
sourceMapIncludeSources: true
}
},
expression_json: {
files: {
'tmp/expression.json': ['test/fixtures/src/simple.json']
@@ -215,7 +243,7 @@ module.exports = function(grunt) {
mangle: false,
compress: false
}
},
}
},

// Unit tests.
@@ -255,6 +283,7 @@ module.exports = function(grunt) {
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask('test', [
'jshint',
'clean',
'uglify:compress',
'uglify:compress_mangle',
@@ -266,6 +295,8 @@ module.exports = function(grunt) {
'uglify:sourcemap_sources',
'uglify:comments',
'uglify:wrap',
'uglify:maxLineLen',
'uglify:ASCIIOnly',
'uglify:exportAll',
'uglify:enclose',
'uglify:sourcemap_basic',
@@ -276,12 +307,13 @@ module.exports = function(grunt) {
'uglify:sourcemap_multipleFunctionNames',
'uglify:sourcemapin',
'uglify:sourcemap_sources',
'uglify:sourcemapin_sources',
'uglify:expression_json',
'uglify:expression_js',
'nodeunit'
]);

// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test', 'build-contrib']);
grunt.registerTask('default', ['test', 'build-contrib']);

};
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# grunt-contrib-uglify v0.5.1 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-uglify.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-uglify) <a href="https://ci.appveyor.com/project/gruntjs/grunt-contrib-uglify"><img src="https://ci.appveyor.com/api/projects/status/ybtf5vbvtenii561/branch/master" alt="Build Status: Windows" height="18" /></a>
# grunt-contrib-uglify v0.6.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-uglify.png?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-uglify) <a href="https://ci.appveyor.com/project/gruntjs/grunt-contrib-uglify"><img src="https://ci.appveyor.com/api/projects/status/ybtf5vbvtenii561/branch/master" alt="Build Status: Windows" height="18" /></a>

> Minify files with UglifyJS.
@@ -126,6 +126,18 @@ Wrap all of the code in a closure, an easy way to make sure nothing is leaking.
For variables that need to be public `exports` and `global` variables are made available.
The value of wrap is the global variable exports will be available as.

#### maxLineLen
Type: `Number`
Default: `32000`

Limit the line length in symbols. Pass maxLineLen = 0 to disable this safety feature.

#### ASCIIOnly
Type: `Boolean`
Default: `false`

Enables to encode non-ASCII characters as \uXXXX.

#### exportAll
Type: `Boolean`
Default: `false`
@@ -398,7 +410,8 @@ grunt.initConfig({

## Release History

* 2014-06-11   v0.5.0   added option "expression" to uglify json and single functions. Removes unnecessary source map function. Simplify default source map naming function. Normalizes header and footer linefeeds. Source map names follow specs. Updates sourcemapin fixture.
* 2014-09-17   v0.6.0   Output fixes. ASCIIOnly option. Other fixes.
* 2014-07-25   v0.5.1   Chalk updates. Output updates.
* 2014-03-01   v0.4.0   remove grunt-lib-contrib dependency and add more colors
* 2014-02-27   v0.3.3   remove unnecessary calls to `grunt.template.process`
* 2014-01-22   v0.3.2   fix handling of `sourceMapIncludeSources` option.
@@ -422,4 +435,4 @@ grunt.initConfig({

Task submitted by ["Cowboy" Ben Alman](http://benalman.com)

*This file was generated on Fri Jul 25 2014 12:07:55.*
*This file was generated on Wed Sep 17 2014 21:59:24.*
12 changes: 12 additions & 0 deletions docs/uglify-options.md
Original file line number Diff line number Diff line change
@@ -77,6 +77,18 @@ Wrap all of the code in a closure, an easy way to make sure nothing is leaking.
For variables that need to be public `exports` and `global` variables are made available.
The value of wrap is the global variable exports will be available as.

## maxLineLen
Type: `Number`
Default: `32000`

Limit the line length in symbols. Pass maxLineLen = 0 to disable this safety feature.

## ASCIIOnly
Type: `Boolean`
Default: `false`

Enables to encode non-ASCII characters as \uXXXX.

## exportAll
Type: `Boolean`
Default: `false`
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-contrib-uglify",
"description": "Minify files with UglifyJS.",
"version": "0.5.1",
"version": "0.6.0",
"homepage": "https://github.com/gruntjs/grunt-contrib-uglify",
"author": {
"name": "Grunt Team",
@@ -29,12 +29,13 @@
"dependencies": {
"chalk": "^0.5.1",
"lodash": "^2.4.1",
"maxmin": "^0.2.0",
"uglify-js": "^2.4.0"
"maxmin": "^1.0.0",
"uglify-js": "^2.4.0",
"uri-path": "0.0.2"
},
"devDependencies": {
"grunt": "^0.4.2",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-internal": "^0.4.2",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-nodeunit": "^0.4.0"
18 changes: 16 additions & 2 deletions tasks/lib/uglify.js
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ var path = require('path');
var fs = require('fs');
var UglifyJS = require('uglify-js');
var _ = require('lodash');
var uriPath = require('uri-path');

exports.init = function(grunt) {
var exports = {};
@@ -46,7 +47,7 @@ exports.init = function(grunt) {
var pathPrefix = relativePath ? (relativePath+path.sep) : '';

// Convert paths to use forward slashes for sourcemap use in the browser
file = (pathPrefix + basename).replace(/\\/g, '/');
file = uriPath(pathPrefix + basename);

sourcesContent[file] = code;
topLevel = UglifyJS.parse(code, {
@@ -115,7 +116,7 @@ exports.init = function(grunt) {
// Add the source map reference to the end of the file
if (options.sourceMap) {
// Set all paths to forward slashes for use in the browser
min += "\n//# sourceMappingURL="+options.destToSourceMap.replace(/\\/g, '/');
min += "\n//# sourceMappingURL=" + uriPath(options.destToSourceMap);
}

var result = {
@@ -177,13 +178,26 @@ exports.init = function(grunt) {
file: destBasename,
orig: sourceMapIn
});
if (options.sourceMapIncludeSources && sourceMapIn && sourceMapIn.sourcesContent) {
sourceMapIn.sourcesContent.forEach(function(content, idx) {
outputOptions.source_map.get().setSourceContent(sourceMapIn.sources[idx], content);
});
}

}

if (options.indentLevel !== undefined) {
outputOptions.indent_level = options.indentLevel;
}

if (options.maxLineLen !== undefined) {
outputOptions.max_line_len = options.maxLineLen;
}

if (options.ASCIIOnly !== undefined) {
outputOptions.ascii_only = options.ASCIIOnly;
}

return outputOptions;
};

26 changes: 21 additions & 5 deletions tasks/uglify.js
Original file line number Diff line number Diff line change
@@ -45,17 +45,21 @@ module.exports = function(grunt) {
mangle: {},
beautify: false,
report: 'min',
expression: false
expression: false,
maxLineLen: 32000,
ASCIIOnly: false
});

// Process banner.
var banner = normalizeLf(options.banner);
var footer = normalizeLf(options.footer);
var mapNameGenerator, mapInNameGenerator;
var createdFiles = 0;
var createdMaps = 0;

// Iterate over all src-dest file pairs.
this.files.forEach(function(f) {
var src = f.src.filter(function(filepath) {
this.files.forEach(function (f) {
var src = f.src.filter(function (filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file ' + chalk.cyan(filepath) + ' not found.');
@@ -101,7 +105,7 @@ module.exports = function(grunt) {
}
}
// If no name is passed append .map to the filename
else if ( !options.sourceMapName ) {
else if (!options.sourceMapName) {
options.generatedSourceMapName = f.dest + '.map';
} else {
options.generatedSourceMapName = options.sourceMapName;
@@ -159,10 +163,22 @@ module.exports = function(grunt) {
if (options.sourceMap) {
grunt.file.write(options.generatedSourceMapName, result.sourceMap);
grunt.verbose.writeln('File ' + chalk.cyan(options.generatedSourceMapName) + ' created (source map).');
createdMaps++;
}

grunt.verbose.writeln('File ' + chalk.cyan(f.dest) + ' created: ' +
maxmin(result.max, output, options.report === 'gzip'));
maxmin(result.max, output, options.report === 'gzip'));
createdFiles++;
});

if (createdMaps > 0) {
grunt.log.ok(createdMaps + ' source' + grunt.util.pluralize(this.files.length, 'map/maps') + ' created.');
}

if (createdFiles > 0) {
grunt.log.ok(createdFiles + ' ' + grunt.util.pluralize(this.files.length, 'file/files') + ' created.');
} else {
grunt.log.warn('No files created.');
}
});
};
1 change: 1 addition & 0 deletions test/fixtures/expected/asciionly.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/fixtures/expected/maxLineLen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/fixtures/expected/sourcemapin_sources.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/expected/sourcemapin_sources.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/src/localization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var set = [
"This is a random set of chαracters and strings.",
"这是一组随机字符和字符串。",
"Это случайный набор символов и строк",
"Цé випадковий набір символів та рядків"
], answer = set[Math.floor(Math.random()*set.length)];
2 changes: 1 addition & 1 deletion test/fixtures/src/simple2.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions test/uglify_test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict';

var grunt = require('grunt');
var path = require('path');

var tmp = 'tmp/',
fixtures = 'test/fixtures/expected/';
var read = function() {
var filepath = path.join.apply(this, Array.prototype.slice.call(arguments));
return grunt.util.normalizelf(grunt.file.read(filepath));
};

exports.contrib_uglify = {
preuglified_files: function(test) {
@@ -18,17 +21,21 @@ exports.contrib_uglify = {
'enclose.js',
'multifile.js',
'wrap.js',
'maxLineLen.js',
'asciionly.js',
'exportAll.js',
'sourcemap_basic.js',
'sourcemap_basic.js.map',
'sourcemap_customDir.js',
'sourcemap_customName.js',
'sourcemap_functionName.js',
'sourcemap_functionName.js.fn.map',
'deep/directory/location/source_map.js.map',
path.join('deep', 'directory', 'location', 'source_map.js.map'),
'sourcemapin.js',
'sourcemapin.js.map',
'sourcemap_sources.js.map',
'sourcemapin_sources.js',
'sourcemapin_sources.js.map',
'sourcemaps_multiple1.js',
'sourcemaps_multiple1.js.map',
'sourcemaps_multiple2.js',
@@ -43,9 +50,9 @@ exports.contrib_uglify = {

test.expect(files.length);

files.forEach(function(file){
var actual = grunt.file.read(tmp + file);
var expected = grunt.file.read(fixtures + file);
files.forEach(function(file) {
var actual = read('tmp', file);
var expected = read('test', 'fixtures', 'expected', file);
test.equal(actual, expected, 'task output should equal ' + file);
});