Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(composer): implement new API for composing deps
BREAKING CHANGE: Replace the old "minifier" entry point with a new "composer" entry point. Fixes #291.
- Loading branch information
1 parent
dbbba30
commit f2b779b
Showing
8 changed files
with
103 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
var through = require('through2'); | ||
var minify = require('./lib/minify'); | ||
|
||
module.exports = function(uglify, logger) { | ||
return function(opts) { | ||
return through.obj(minify(uglify, logger)(opts)); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
'use strict'; | ||
var uglify = require('uglify-js'); | ||
var minifier = require('./minifier'); | ||
var compose = require('./composer'); | ||
var GulpUglifyError = require('./lib/gulp-uglify-error'); | ||
var logger = require('./lib/log'); | ||
|
||
module.exports = function(opts) { | ||
return minifier(opts, uglify); | ||
return compose(uglify, logger)(opts); | ||
}; | ||
|
||
module.exports.GulpUglifyError = GulpUglifyError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict'; | ||
var applySourceMap = require('vinyl-sourcemaps-apply'); | ||
var isObject = require('lodash/fp/isObject'); | ||
var defaultsDeep = require('lodash/fp/defaultsDeep'); | ||
var createError = require('./create-error'); | ||
|
||
module.exports = function(uglify, log) { | ||
function setup(opts) { | ||
if (opts && !isObject(opts)) { | ||
log.warn('gulp-uglify expects an object, non-object provided'); | ||
opts = {}; | ||
} | ||
|
||
return defaultsDeep( | ||
{ | ||
output: {} | ||
}, | ||
opts | ||
); | ||
} | ||
|
||
return function(opts) { | ||
return function(file, encoding, callback) { | ||
var options = setup(opts || {}); | ||
var hasSourceMaps = Boolean(file.sourceMap); | ||
|
||
if (file.isNull()) { | ||
return callback(null, file); | ||
} | ||
|
||
if (file.isStream()) { | ||
return callback(createError(file, 'Streaming not supported', null)); | ||
} | ||
|
||
if (hasSourceMaps) { | ||
options.sourceMap = { | ||
filename: file.sourceMap.file, | ||
includeSources: true | ||
}; | ||
|
||
// UglifyJS generates broken source maps if the input source map | ||
// does not contain mappings. | ||
if (file.sourceMap.mappings) { | ||
options.sourceMap.content = file.sourceMap; | ||
} | ||
} | ||
|
||
var fileMap = {}; | ||
fileMap[file.relative] = String(file.contents); | ||
|
||
var mangled = uglify.minify(fileMap, options); | ||
|
||
if (mangled.error) { | ||
return callback( | ||
createError(file, 'unable to minify JavaScript', mangled.error) | ||
); | ||
} | ||
|
||
if (mangled.warnings) { | ||
mangled.warnings.forEach(function(warning) { | ||
log.warn('gulp-uglify [%s]: %s', file.relative, warning); | ||
}); | ||
} | ||
|
||
file.contents = new Buffer(mangled.code); | ||
|
||
if (hasSourceMaps) { | ||
var sourceMap = JSON.parse(mangled.map); | ||
applySourceMap(file, sourceMap); | ||
} | ||
|
||
callback(null, file); | ||
}; | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters