Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: remove util.cjs, break up util.js to shared and report utils #14378

Closed
wants to merge 7 commits into from

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Sep 9, 2022

  • deleted core/util.cjs and accompanying file creation
  • upgraded @types/node to get URL global (without needing DOM tslib)
  • moved markdown utilities to new shared/markdown.js
  • moved shared utility functions to shared/shared-utils.js
  • created report-utils.js that contains the util functions used by just the report. also does a convenience re-export
    of other util files

I tried moving some of the URL utility functions to url-utils.js, but the dependency on core's lh-error.js
and i18n.js made it a larger change than I anticipated so I dropped it. Ditto for trying to move that module to
shared.

@connorjclark connorjclark requested a review from a team as a code owner September 9, 2022 21:48
@connorjclark connorjclark requested review from adamraine and removed request for a team September 9, 2022 21:48
Comment on lines 382 to +388
export {
Util,
ReportUtils,
SharedUtils,
UIStrings,
};

export * as MarkdownUtils from '../../shared/markdown.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git mv report/renderer/util.js shared/util.js is a lot less churn/blame breakage and accomplishes essentially the same thing (and with less awkward naming/renaming). util.js is really already set up for this since it has no deps.

The markdown methods seem like the only part maybe crying out to be a separate file, though they've also been fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the churn is worth it because the weird report globals like ReportUtils.reportJson are now only visible to report code.

We can also add new dependencies to the report utils without worrying about the shared utils needing to remain standalone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the churn is worth it because the weird report globals like ReportUtils.reportJson are now only visible to report code.

that and Util.i18n are only there due to failure of architecture and we're hiding our shame instead of putting them on window. They could go in or on any global variable.

We can also add new dependencies to the report utils without worrying about the shared utils needing to remain standalone.

the shared utils still have to be standalone because they're still imported by the report.

Copy link
Collaborator Author

@connorjclark connorjclark Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unclear on how this could be just a simple mv of report/renderer/util.js -> shared/util.js, because of the existence of Util.i18n (soon to be Util.formatter #13933). That results in a module in shared/ being dependent on report/renderer/i18n.js. IIRC that's why I split the file.

I can rebase things and convince git this is a move, that would be good. I'll do a new PR, and defer the markdown changes, to make move simpler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annnnnd to reduce naming problems (so many utils), this seems like a good approach. just be honest about what we doing lol

image

yarn.lock Outdated
@@ -1520,7 +1520,12 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.1.1.tgz#e7c4f1001eefa4b8afbd1eee27a237fee3bf29c4"
integrity sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==

"@types/node@*", "@types/node@>=12.12.47", "@types/node@>=13.7.0":
"@types/node@*":
version "18.7.16"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not a huge deal, but using the 18.x types can sometimes mislead on what APIs are available. Was there a 16.x that got the URL change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like latest 16.x works, yeah

report/renderer/snippet-renderer.js Outdated Show resolved Hide resolved
Comment on lines 382 to +388
export {
Util,
ReportUtils,
SharedUtils,
UIStrings,
};

export * as MarkdownUtils from '../../shared/markdown.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the churn is worth it because the weird report globals like ReportUtils.reportJson are now only visible to report code.

We can also add new dependencies to the report utils without worrying about the shared utils needing to remain standalone.

@@ -0,0 +1,264 @@
/**
* @license Copyright 2017 The Lighthouse Authors. All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GH doesn't consider this a file move, should we update the date here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants