From: Jakub Pawlowicz Date: Fri, 23 Dec 2016 20:43:50 +0000 (+0100) Subject: Fixes #845 - fixes web compatibility in 4.0. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=195153b18aa35e103630221d71a2c05477604df7;p=clean-css.git Fixes #845 - fixes web compatibility in 4.0. Why: * 4.0 calculates stats by default but `process.hrtime` is not available inside browsers. However, since we don't need sub-ms resolution, `Date.now()` can be used instead. --- diff --git a/History.md b/History.md index 357559ba..2f856955 100644 --- a/History.md +++ b/History.md @@ -20,6 +20,7 @@ * Fixed issue [#839](https://github.com/jakubpawlowicz/clean-css/issues/839) - allows URIs in import inlining rules. * Fixed issue [#840](https://github.com/jakubpawlowicz/clean-css/issues/840) - allows input source map as map object. * Fixed issue [#843](https://github.com/jakubpawlowicz/clean-css/issues/843) - regression in selector handling. +* Fixed issue [#845](https://github.com/jakubpawlowicz/clean-css/issues/845) - web compatibility of 4.0 branch. * Fixed issue [#847](https://github.com/jakubpawlowicz/clean-css/issues/847) - regression in handling invalid selectors. [3.4.23 / 2016-12-17](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.22...v3.4.23) diff --git a/lib/clean.js b/lib/clean.js index 31c6a705..9e28b243 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -73,7 +73,7 @@ CleanCSS.prototype.minify = function (input, callback) { efficiency: 0, minifiedSize: 0, originalSize: 0, - startedAt: process.hrtime(), + startedAt: Date.now(), timeSpent: 0 }, errors: [], @@ -137,10 +137,11 @@ function withMetadata(output, context) { } function calculateStatsFrom(styles, context) { - var elapsed = process.hrtime(context.stats.startedAt); + var finishedAt = Date.now(); + var timeSpent = finishedAt - context.stats.startedAt; delete context.stats.startedAt; - context.stats.timeSpent = ~~(elapsed[0] * 1e3 + elapsed[1] / 1e6); + context.stats.timeSpent = timeSpent; context.stats.efficiency = 1 - styles.length / context.stats.originalSize; context.stats.minifiedSize = styles.length;