Skip to content

Commit

Permalink
fix(package): update uglify-js to version 3.3.9 (#112)
Browse files Browse the repository at this point in the history
* fix(package): update uglify-js to version 3.3.9

Closes #106

* Update for uglify-js changes

* exit on coverage as well
  • Loading branch information
ForbesLindesay committed Feb 2, 2018
1 parent 1260138 commit 9c41cfd
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
7 changes: 5 additions & 2 deletions lib/build-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ function getSource(bundle, options) {

function minify(str, options) {
if (!options || typeof options !== 'object') options = {};
options.fromString = true;
return uglify.minify(str, options);
const result = uglify.minify(str, options);
if (result.error) {
throw result.error;
}
return result;
}

function noop() {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "8.0.0",
"description": "express middleware for browserify v2",
"scripts": {
"test": "mocha -R spec -t 7000",
"test:perf": "mocha -R spec -t 7000",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- -t 7000",
"test": "mocha -R spec -t 7000 --exit",
"test:perf": "mocha -R spec -t 7000 --exit",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- -t 7000 --exit",
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls"
},
"repository": {
Expand Down Expand Up @@ -34,7 +34,7 @@
"ms": "^0.7.1",
"prepare-response": "^1.1.2",
"promise": "^7.0.3",
"uglify-js": "^2.7.3",
"uglify-js": "^3.3.9",
"watchify": "^3.3.0"
}
}
7 changes: 7 additions & 0 deletions test/directory/no-mangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function add(foo, bar) {
return foo + bar;
}
function subtract(foo, bar) {
return foo - bar;
}
console.log((Math.random() > 0.9 ? add : subtract)(1, 2));
4 changes: 0 additions & 4 deletions test/directory/no-minify.js

This file was deleted.

41 changes: 28 additions & 13 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,20 @@ app.get('/opt/dir/non-existant.js', function (req, res) {
});


app.get('/no-minify.js', browserify(__dirname + '/directory/no-minify.js', {
app.get('/no-mangle.js', browserify(__dirname + '/directory/no-mangle.js', {
cache: false,
gzip: false,
minify: {
compress: true,
mangle: false
},
debug: true
}));
app.get('/opt/no-minify.js', browserify(__dirname + '/directory/no-minify.js', {
app.get('/opt/no-mangle.js', browserify(__dirname + '/directory/no-mangle.js', {
cache: true,
gzip: true,
minify: {
compress: true,
mangle: false
},
debug: false
Expand Down Expand Up @@ -183,12 +185,13 @@ app.get('/opt/no-bundle-external.js', browserify(__dirname + '/directory/no-bund
}));

var port;
var server;
(function () {
var listeners = [];
port = function (fn) {
listeners.push(fn);
};
http.createServer(function (req, res) {
server = http.createServer(function (req, res) {
var url = require('url').parse(req.url)
var i = 0
function next(err) {
Expand All @@ -215,18 +218,22 @@ var port;
function get(path, optimised, cb) {
port(function (port) {
var erred = false;
hyperquest('http://localhost:' + port + (optimised ? '/opt' : '') + path, function (err, res) {
erred = err || res.statusCode >= 400;
if (err) return cb(err);
if (res.statusCode >= 400) {
var err = new Error('Server responded with status code ' + res.statusCode);
err.statusCode = res.statusCode;
var res;
hyperquest('http://localhost:' + port + (optimised ? '/opt' : '') + path, function (err, _res) {
if (err) {
erred = true;
return cb(err);
}
res = _res;
})
.pipe(concat(function (res) {
.pipe(concat(function (body) {
if (erred) return;
return cb(null, res.toString());
if (res.statusCode >= 400) {
var err = new Error('Server responded with status code ' + res.statusCode + ':\n\n' + body.toString());
err.statusCode = res.statusCode;
return cb(err);
}
return cb(null, body.toString());
}));
})
}
Expand Down Expand Up @@ -415,10 +422,18 @@ function test(optimised, get, it) {
});
describe('minify: options', function () {
it('passes options to uglifyjs', function (done) {
get('/no-minify.js', optimised, function (err, res) {
get('/no-mangle.js', optimised, function (err, res) {
if (err) return done(err);
assert(res.indexOf("console.log(function(foo,bar){return foo+bar}(1,2))") !== -1);
const searchString = "foo+bar";
try {
assert(res.indexOf(searchString) !== -1);
} catch (ex) {
throw new Error('Expected ' + JSON.stringify(res) + ' to contain ' + JSON.stringify(searchString));
}
vm.runInNewContext(res, {
Math: {
random: () => 0.99,
},
console: {
log: function (res) {
assert.equal(res, 3);
Expand Down

0 comments on commit 9c41cfd

Please sign in to comment.