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

clients(lr): export primary api, presets from lr bundle #14425

Merged
merged 7 commits into from
Nov 29, 2022
Merged

Conversation

paulirish
Copy link
Member

@paulirish paulirish commented Oct 4, 2022

This change allows g3 clients to consume the LR bundle as a CJS module, in addition to our existing LR use where we consume the globals.

Nov 16 update: I've changed the intent of this branch. While doing a UMD build for LR and DevTools might still be nice, the primary item is to expose the full api so the FR modes are available.

build/build-bundle.js Outdated Show resolved Hide resolved
@@ -163,4 +163,7 @@ if (typeof window !== 'undefined') {

export {
runLighthouseInLR,
lighthouse,
Copy link
Collaborator

Choose a reason for hiding this comment

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

can the above manual window assignment be removed? does umd bundle assign to global for us in browser context?

Copy link
Member Author

Choose a reason for hiding this comment

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

the window assignment can be removed if we switch our LR client from window.runLighthouseInLR to window.lightriderBundle.runLighthouseInLR.
(aka: doable)

Copy link
Collaborator

@connorjclark connorjclark Oct 4, 2022

Choose a reason for hiding this comment

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

name is necessary for umd, and also is used to namespace on the global. makes sense.

That seems like a decent change to make IMO. Although, I would just name it lightrider (or lighthouse?)

@@ -75,7 +75,7 @@ const banner = `
* @param {{minify: boolean}=} opts
* @return {Promise<void>}
*/
async function buildBundle(entryPath, distPath, opts = {minify: true}) {
async function buildLrBundle(entryPath, distPath, opts = {minify: true}) {
Copy link
Collaborator

@connorjclark connorjclark Oct 4, 2022

Choose a reason for hiding this comment

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

This function is also used to bundle CDT via the CLI. I think you need to add to opts a format that defaults to iife.

Copy link
Member Author

Choose a reason for hiding this comment

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

yupppppppp okay i see it now.
since the use wasn't picked up by TS i missed it.
roger that, i'll make it extensible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's fair, took me a second to grok why this wasn't ok b/c of that too

Copy link
Member Author

@paulirish paulirish Oct 5, 2022

Choose a reason for hiding this comment

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

since this CL is getting a lil bit more involved... i could also switch devtools to adopt the UMD pattern as well.. wdyt?

it'd mean we get to drop all of these in the devtools-entry:

  // @ts-expect-error
  self.X = X;

Copy link
Collaborator

Choose a reason for hiding this comment

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

sgtm. You'll probably need to disable the devtool CI check first? Might be weird given you can't roll latest to CDT just yet. Maybe you'd just need to cherry pick into branch-9 and roll from there to get CI to pass.

@@ -231,7 +231,8 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
await bundle.write({
file: distPath,
banner,
format: 'iife',
format: 'umd',
name: 'lightriderBundle',
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove name / make an optional param if you need it for LR bundle

@paulirish paulirish changed the title clients(lr): build lr bundle as umd clients(lr): export primary api, presets from lr bundle Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants