From e9ff38cecbfb0572cc9a20164fdbfef1e9d2f896 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Tue, 4 Oct 2022 16:19:09 -0700 Subject: [PATCH 1/4] clients(lr): build lr bundle as umd --- build/build-bundle.js | 9 +++++---- build/build-lightrider-bundles.js | 4 ++-- clients/lightrider/lightrider-entry.js | 3 +++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/build/build-bundle.js b/build/build-bundle.js index 43510cf79923..2d45159fa891 100644 --- a/build/build-bundle.js +++ b/build/build-bundle.js @@ -75,7 +75,7 @@ const banner = ` * @param {{minify: boolean}=} opts * @return {Promise} */ -async function buildBundle(entryPath, distPath, opts = {minify: true}) { +async function buildLrBundle(entryPath, distPath, opts = {minify: true}) { if (fs.existsSync(LH_ROOT + '/lighthouse-logger/node_modules')) { throw new Error('delete `lighthouse-logger/node_modules` because it messes up rollup bundle'); } @@ -231,7 +231,8 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) { await bundle.write({ file: distPath, banner, - format: 'iife', + format: 'umd', + name: 'lightriderBundle', sourcemap: DEBUG, // Suppress code splitting. inlineDynamicImports: true, @@ -246,7 +247,7 @@ async function cli(argv) { // Take paths relative to cwd and build. const [entryPath, distPath] = argv.slice(2) .map(filePath => path.resolve(process.cwd(), filePath)); - await buildBundle(entryPath, distPath, {minify: !process.env.DEBUG}); + await buildLrBundle(entryPath, distPath, {minify: !process.env.DEBUG}); } // Test if called from the CLI or as a module. @@ -255,5 +256,5 @@ if (esMain(import.meta)) { } export { - buildBundle, + buildLrBundle, }; diff --git a/build/build-lightrider-bundles.js b/build/build-lightrider-bundles.js index 1d0ac0f0be05..2faccb665ba8 100644 --- a/build/build-lightrider-bundles.js +++ b/build/build-lightrider-bundles.js @@ -10,7 +10,7 @@ import path from 'path'; import {rollup} from 'rollup'; import * as rollupPlugins from './rollup-plugins.js'; -import {buildBundle} from './build-bundle.js'; +import {buildLrBundle} from './build-bundle.js'; import {LH_ROOT} from '../root.js'; const distDir = path.join(LH_ROOT, 'dist', 'lightrider'); @@ -24,7 +24,7 @@ fs.mkdirSync(distDir, {recursive: true}); function buildEntryPoint() { const inFile = `${sourceDir}/${entrySourceName}`; const outFile = `${distDir}/${entryDistName}`; - return buildBundle(inFile, outFile, {minify: false}); + return buildLrBundle(inFile, outFile, {minify: false}); } async function buildReportGenerator() { diff --git a/clients/lightrider/lightrider-entry.js b/clients/lightrider/lightrider-entry.js index 1006884cc930..c967baab9567 100644 --- a/clients/lightrider/lightrider-entry.js +++ b/clients/lightrider/lightrider-entry.js @@ -163,4 +163,7 @@ if (typeof window !== 'undefined') { export { runLighthouseInLR, + lighthouse, + listenForStatus, + LR_PRESETS, }; From 69768b7e5286b7499b108ec9843179d4568e87d3 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Wed, 16 Nov 2022 15:10:19 -0800 Subject: [PATCH 2/4] revert bundle building changes --- build/build-bundle.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/build/build-bundle.js b/build/build-bundle.js index 7b9bfa9411fd..ffc6d27e088d 100644 --- a/build/build-bundle.js +++ b/build/build-bundle.js @@ -75,7 +75,7 @@ const banner = ` * @param {{minify: boolean}=} opts * @return {Promise} */ -async function buildLrBundle(entryPath, distPath, opts = {minify: true}) { +async function buildBundle(entryPath, distPath, opts = {minify: true}) { if (fs.existsSync(LH_ROOT + '/lighthouse-logger/node_modules')) { throw new Error('delete `lighthouse-logger/node_modules` because it messes up rollup bundle'); } @@ -236,8 +236,7 @@ async function buildLrBundle(entryPath, distPath, opts = {minify: true}) { await bundle.write({ file: distPath, banner, - format: 'umd', - name: 'lightriderBundle', + format: 'iife', sourcemap: DEBUG, // Suppress code splitting. inlineDynamicImports: true, @@ -252,7 +251,7 @@ async function cli(argv) { // Take paths relative to cwd and build. const [entryPath, distPath] = argv.slice(2) .map(filePath => path.resolve(process.cwd(), filePath)); - await buildLrBundle(entryPath, distPath, {minify: !process.env.DEBUG}); + await buildBundle(entryPath, distPath, {minify: !process.env.DEBUG}); } // Test if called from the CLI or as a module. @@ -261,5 +260,5 @@ if (esMain(import.meta)) { } export { - buildLrBundle, + buildBundle, }; From 9a0875e9b4e5589a99bc7cf169e46010e17b5c22 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Wed, 16 Nov 2022 15:41:16 -0800 Subject: [PATCH 3/4] clients(lr): expose primary API --- clients/lightrider/lightrider-entry.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/lightrider/lightrider-entry.js b/clients/lightrider/lightrider-entry.js index c967baab9567..927cb12ce3b6 100644 --- a/clients/lightrider/lightrider-entry.js +++ b/clients/lightrider/lightrider-entry.js @@ -12,7 +12,7 @@ import log from 'lighthouse-logger'; import {CDPBrowser} from 'puppeteer-core/lib/esm/puppeteer/common/Browser.js'; import {Connection as PptrConnection} from 'puppeteer-core/lib/esm/puppeteer/common/Connection.js'; -import lighthouse, {legacyNavigation} from '../../core/index.js'; +import lighthouse, * as api from '../../core/index.js'; import {LighthouseError} from '../../core/lib/lh-error.js'; import {processForProto} from '../../core/lib/proto-preprocessor.js'; import * as assetSaver from '../../core/lib/asset-saver.js'; @@ -105,7 +105,7 @@ async function runLighthouseInLR(connection, url, flags, lrOpts) { const page = await getPageFromConnection(connection); runnerResult = await lighthouse(url, flags, config, page); } else { - runnerResult = await legacyNavigation(url, flags, config, connection); + runnerResult = await api.legacyNavigation(url, flags, config, connection); } if (!runnerResult) throw new Error('Lighthouse finished without a runnerResult'); @@ -163,7 +163,7 @@ if (typeof window !== 'undefined') { export { runLighthouseInLR, - lighthouse, + api, listenForStatus, LR_PRESETS, }; From d39fb77c5d8b917ea89b7c1cfc8977b1ca9f5590 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Wed, 16 Nov 2022 15:42:20 -0800 Subject: [PATCH 4/4] revert bundle building changes, pt 2 --- build/build-lightrider-bundles.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/build-lightrider-bundles.js b/build/build-lightrider-bundles.js index 2faccb665ba8..1d0ac0f0be05 100644 --- a/build/build-lightrider-bundles.js +++ b/build/build-lightrider-bundles.js @@ -10,7 +10,7 @@ import path from 'path'; import {rollup} from 'rollup'; import * as rollupPlugins from './rollup-plugins.js'; -import {buildLrBundle} from './build-bundle.js'; +import {buildBundle} from './build-bundle.js'; import {LH_ROOT} from '../root.js'; const distDir = path.join(LH_ROOT, 'dist', 'lightrider'); @@ -24,7 +24,7 @@ fs.mkdirSync(distDir, {recursive: true}); function buildEntryPoint() { const inFile = `${sourceDir}/${entrySourceName}`; const outFile = `${distDir}/${entryDistName}`; - return buildLrBundle(inFile, outFile, {minify: false}); + return buildBundle(inFile, outFile, {minify: false}); } async function buildReportGenerator() {