Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drive-by fix for minify options brokeness (replacement for PR#69) #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ function uglifyify(file, opts) {
? opts._flags.debug
: true

delete opts._flags

if (ignore(file, opts.ignore)) {
return through()
}
Expand All @@ -37,11 +35,6 @@ function uglifyify(file, opts) {
return through()
}

// remove exts before passing opts to uglify
delete opts.global
delete opts.exts
delete opts.x

return through(function write(chunk) {
buffer += chunk
}, capture(function ready() {
Expand All @@ -51,7 +44,8 @@ function uglifyify(file, opts) {
)

debug = opts.sourceMap !== false && (debug || matched)
opts = extend({}, {

var _opts = extend({}, {
compress: true,
mangle: true,
sourceMap: {
Expand All @@ -62,23 +56,31 @@ function uglifyify(file, opts) {
// map out command line options to uglify compatible ones
mapArgv(opts)

if (typeof opts.compress === 'object') {
delete opts.compress._
// remove exts before passing opts to uglify
delete _opts.global
delete _opts.exts
delete _opts.x
delete _opts._
delete _opts._flags

if (typeof _opts.compress === 'object') {
delete _opts.compress._
}

if (debug) opts.sourceMap.url = 'out.js.map'
if (debug) _opts.sourceMap.url = 'out.js.map'

// Check if incoming source code already has source map comment.
// If so, send it in to ujs.minify as the inSourceMap parameter
if (debug && matched) {
opts.sourceMap.content = convert.fromJSON(
_opts.sourceMap.content = convert.fromJSON(
new Buffer(matched[1], 'base64').toString()
).sourcemap
}

var min = ujs.minify(buffer, opts)
// we should catcch the min error if it comes back and end the stream
if (min.error) return this.emit('error', min.error.message)
var min = ujs.minify(buffer, _opts)

if (min.error)
throw (min.error instanceof Error ? min.error : new Error(min.error.message)); // will be emitted by `capture()`

// Uglify leaves a source map comment pointing back to "out.js.map",
// which we want to get rid of because it confuses browserify.
Expand All @@ -90,7 +92,7 @@ function uglifyify(file, opts) {

map.setProperty('sources', [path.basename(file)])
map.setProperty('sourcesContent', matched
? opts.sourceMap.sourcesContent
? _opts.sourceMap.sourcesContent
: [buffer]
)

Expand Down