From ada82fa7e10878cdbd1dacfa797267205fe6f418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Sun, 27 Mar 2016 17:09:23 +0300 Subject: [PATCH] Should fix uglify infinite loop on already uglyfied files that crashes YLT --- lib/tools/weightChecker/fileMinifier.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/tools/weightChecker/fileMinifier.js b/lib/tools/weightChecker/fileMinifier.js index 3e3f0b0..45dc14e 100644 --- a/lib/tools/weightChecker/fileMinifier.js +++ b/lib/tools/weightChecker/fileMinifier.js @@ -146,7 +146,16 @@ var FileMinifier = function() { .delay(1) .then(splittedUglifyStep2) .delay(1) - .then(splittedUglifyStep3) + .then(function(ast) { + // Only do the compression step for smaller files + // otherwise it can take a very long time compared to the gain + if (body.length < 200*1024) { + return splittedUglifyStep3(ast); + } else { + debug('Skipping step 3 because the file is too big (%d bytes)!', body.length); + return ast; + } + }) .delay(1) .then(splittedUglifyStep4) .delay(1) @@ -311,9 +320,9 @@ var FileMinifier = function() { return result; } - // Avoid loosing tome trying to compress JS files if they alreay look minified + // Avoid loosing some trying to compress JS files if they alreay look minified // by counting the number of lines compared to the total size. - // Less than 1000kb per line is suspicious + // Less than 1KB per line is suspicious function looksAlreadyMinified(code) { var linesCount = code.split(/\r\n|\r|\n/).length; var linesRatio = code.length / linesCount;