From 9359ff98e0a50b20bf9a2295a1658d3d62268a32 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 10 Oct 2024 11:54:36 +0000 Subject: [PATCH] refactor: replace `process.hrtime` with `Date.now` Switched from `process.hrtime` to `Date.now` as high-resolution timing is not required in this case. This change removes the dependency on Node.js-specific functionality, enabling the library to run in environments like Cloudflare Workers using `unenv` with Angular. --- packages/critters/src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/critters/src/index.js b/packages/critters/src/index.js index efa0f2c..1e4b156 100644 --- a/packages/critters/src/index.js +++ b/packages/critters/src/index.js @@ -158,7 +158,7 @@ export default class Critters { * Apply critical CSS processing to the html */ async process(html) { - const start = process.hrtime.bigint(); + const start = Date.now(); // Parse the generated HTML in a DOM we can mutate const document = createDocument(html); @@ -191,8 +191,8 @@ export default class Critters { // serialize the document back to HTML and we're done const output = serializeDocument(document); - const end = process.hrtime.bigint(); - this.logger.info('Time ' + parseFloat(end - start) / 1000000.0); + const end = Date.now(); + this.logger.info(`Time ${end - start}ms`); return output; } @@ -200,7 +200,7 @@ export default class Critters { * Get the style tags that need processing */ getAffectedStyleTags(document) { - const styles = [].slice.call(document.querySelectorAll('style')); + const styles = [...document.querySelectorAll('style')]; // `inline:false` skips processing of inline stylesheets if (this.options.reduceInlineStyles === false) {