Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
refactor: replace process.hrtime with Date.now
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alan-agius4 committed Oct 10, 2024
1 parent 05f5a48 commit 9359ff9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/critters/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -191,16 +191,16 @@ 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;
}

/**
* 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) {
Expand Down

0 comments on commit 9359ff9

Please sign in to comment.