diff --git a/docs/releasing.md b/docs/releasing.md index 5bad45e41277..0942ebac7967 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -93,8 +93,8 @@ git push --tags echo "Rebuild extension and viewer to get the latest, tagged master commit" yarn build-all; -# zip the extension files, but remove lh-background as it's not needed -cd lighthouse-extension; command rm -f dist/scripts/lighthouse-background.js; gulp package; cd .. +# zip the extension files, but remove lh-dt-bundle & lh-lr-bundle as it's not needed +cd lighthouse-extension; command rm -f dist/scripts/lighthouse-dt-bundle.js dist/scripts/lighthouse-lr-bundle.js; gulp package; cd .. echo "Go here: https://chrome.google.com/webstore/developer/edit/blipmdconlkpinefehnmjammfjpmpbjk " echo "Upload the package zip to CWS dev dashboard" diff --git a/lighthouse-core/gather/connections/extension.js b/lighthouse-core/gather/connections/extension.js index e97b346de42b..0c1a20a57f13 100644 --- a/lighthouse-core/gather/connections/extension.js +++ b/lighthouse-core/gather/connections/extension.js @@ -197,7 +197,7 @@ class ExtensionConnection extends Connection { } /** - * Used by lighthouse-ext-background to kick off the run on the current page + * Used by extension-entry to kick off the run on the current page * @return {Promise} */ getCurrentTabURL() { diff --git a/lighthouse-core/scripts/roll-to-devtools.sh b/lighthouse-core/scripts/roll-to-devtools.sh index c373c7276ffd..e6c83f2c63e8 100755 --- a/lighthouse-core/scripts/roll-to-devtools.sh +++ b/lighthouse-core/scripts/roll-to-devtools.sh @@ -33,13 +33,13 @@ fi report_dir="lighthouse-core/report/html" fe_lh_dir="$frontend_dir/audits2/lighthouse" -lh_bg_js="lighthouse-extension/dist/scripts/lighthouse-background.js" +lh_bg_js="lighthouse-extension/dist/scripts/lighthouse-dt-bundle.js" lh_worker_dir="$frontend_dir/audits2_worker/lighthouse" # copy report files cp -pPR $report_dir/{report-styles.css,templates.html,renderer} "$fe_lh_dir" echo -e "\033[32m ✓\033[39m Report renderer files copied." -# copy lighthouse-background (potentially stale) -cp -pPR "$lh_bg_js" "$lh_worker_dir/lighthouse-background.js" -echo -e "\033[96m ✓\033[39m (Potentially stale) lighthouse-background copied." +# copy lighthouse-dt-bundle (potentially stale) +cp -pPR "$lh_bg_js" "$lh_worker_dir/lighthouse-dt-bundle.js" +echo -e "\033[96m ✓\033[39m (Potentially stale) lighthouse-dt-bundle copied." diff --git a/lighthouse-extension/app/manifest.json b/lighthouse-extension/app/manifest.json index 5cc854f7ec55..5dfb917e5fd7 100644 --- a/lighthouse-extension/app/manifest.json +++ b/lighthouse-extension/app/manifest.json @@ -11,7 +11,7 @@ "default_locale": "en", "background": { "scripts": [ - "scripts/lighthouse-ext-background.js" + "scripts/lighthouse-ext-bundle.js" ], "persistent": false }, diff --git a/lighthouse-extension/app/src/lighthouse-background.js b/lighthouse-extension/app/src/devtools-entry.js similarity index 97% rename from lighthouse-extension/app/src/lighthouse-background.js rename to lighthouse-extension/app/src/devtools-entry.js index 8c4b7a37fe91..463a0b6fe804 100644 --- a/lighthouse-extension/app/src/lighthouse-background.js +++ b/lighthouse-extension/app/src/devtools-entry.js @@ -61,7 +61,7 @@ function listenForStatus(listenCallback) { } if (typeof module !== 'undefined' && module.exports) { - // export for lighthouse-ext-background to require (via browserify). + // export for extension-entry to require (via browserify). module.exports = { getDefaultConfigForCategories, runLighthouseInWorker, diff --git a/lighthouse-extension/app/src/lighthouse-ext-background.js b/lighthouse-extension/app/src/extension-entry.js similarity index 99% rename from lighthouse-extension/app/src/lighthouse-ext-background.js rename to lighthouse-extension/app/src/extension-entry.js index f4b81ca5199d..492ceac14907 100644 --- a/lighthouse-extension/app/src/lighthouse-ext-background.js +++ b/lighthouse-extension/app/src/extension-entry.js @@ -6,7 +6,7 @@ 'use strict'; const lighthouse = require('../../../lighthouse-core/index'); -const background = require('./lighthouse-background'); +const background = require('./devtools-entry'); const ExtensionProtocol = require('../../../lighthouse-core/gather/connections/extension'); const log = require('lighthouse-logger'); diff --git a/lighthouse-extension/app/src/lighthouse-lr-background.js b/lighthouse-extension/app/src/lightrider-entry.js similarity index 100% rename from lighthouse-extension/app/src/lighthouse-lr-background.js rename to lighthouse-extension/app/src/lightrider-entry.js diff --git a/lighthouse-extension/app/src/popup.js b/lighthouse-extension/app/src/popup.js index ae8816709486..c93fc1ceaeb1 100644 --- a/lighthouse-extension/app/src/popup.js +++ b/lighthouse-extension/app/src/popup.js @@ -5,7 +5,7 @@ */ 'use strict'; -/** @typedef {typeof import('./lighthouse-ext-background.js') & {console: typeof console}} BackgroundPage */ +/** @typedef {typeof import('./extension-entry.js') & {console: typeof console}} BackgroundPage */ /** * Error strings that indicate a problem in how Lighthouse was run, not in @@ -234,7 +234,7 @@ async function initPopup() { /** * Really the Window of the background page, but since we only want what's exposed - * on window in lighthouse-ext-background.js, use its module API as the type. + * on window in extension-entry.js, use its module API as the type. * @type {BackgroundPage} */ const background = await new Promise(resolve => chrome.runtime.getBackgroundPage(resolve)); diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index de0249793c11..2e4eb96423cd 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -3,6 +3,7 @@ 'use strict'; const fs = require('fs'); +const path = require('path'); // HACK: patch astw before it's required to use acorn with ES2018 // We add the right acorn version to package.json deps, resolve the path to it here, // and then inject the modified require statement into astw's code. @@ -36,9 +37,18 @@ const distDir = 'dist'; // list of all consumers we build for (easier to understand which file is used for which) const CONSUMERS = { - DEVTOOLS: 'lighthouse-background.js', - EXTENSION: 'lighthouse-ext-background.js', - LIGHTRIDER: 'lighthouse-lr-background.js', + DEVTOOLS: { + src: 'devtools-entry.js', + dist: 'lighthouse-dt-bundle.js', + }, + EXTENSION: { + src: 'extension-entry.js', + dist: 'lighthouse-ext-bundle.js', + }, + LIGHTRIDER: { + src: 'lightrider-entry.js', + dist: 'lighthouse-lr-bundle.js', + }, }; const VERSION = pkg.version; @@ -60,8 +70,10 @@ const computedArtifacts = LighthouseRunner.getComputedGathererList() const locales = fs.readdirSync('../lighthouse-core/lib/i18n/locales/') .map(f => require.resolve(`../lighthouse-core/lib/i18n/locales/${f}`)); -const isDevtools = file => file.endsWith(CONSUMERS.DEVTOOLS); -const isExtension = file => file.endsWith(CONSUMERS.EXTENSION); +const isDevtools = file => + file.endsWith(CONSUMERS.DEVTOOLS.src); +const isExtension = file => + file.endsWith(CONSUMERS.EXTENSION.src); gulp.task('extras', () => { return gulp.src([ @@ -109,7 +121,7 @@ gulp.task('chromeManifest', () => { const manifestOpts = { buildnumber: false, background: { - target: `scripts/${CONSUMERS.EXTENSION}`, + target: `scripts/${CONSUMERS.EXTENSION.dist}`, }, }; return gulp.src('app/manifest.json') @@ -127,10 +139,10 @@ function applyBrowserifyTransforms(bundle) { } gulp.task('browserify-lighthouse', () => { - const consumerSources = Object.values(CONSUMERS).map(consumer => `app/src/${consumer}`); + const consumerSources = Object.values(CONSUMERS).map(consumer => `app/src/${consumer.src}`); return gulp.src(consumerSources, {read: false}) .pipe(tap(file => { - let bundle = browserify(file.path, {debug: true}); // for sourcemaps + let bundle = browserify(file.path); // , {debug: true}); // for sourcemaps bundle = applyBrowserifyTransforms(bundle); // scripts will need some additional transforms, ignores and requires… @@ -176,6 +188,18 @@ gulp.task('browserify-lighthouse', () => { // Inject the new browserified contents back into our gulp pipeline file.contents = bundle.bundle(); })) + .pipe(debug({title: ''})) + .pipe(tap(file => { + // rename our bundles + const basename = path.basename(file.path); + + // find the dist file of the given file + const consumer = Object.values(CONSUMERS) + .find(consumer => consumer.src === basename); + + file.path = file.path.replace(consumer.src, consumer.dist); + })) + .pipe(debug({title: 'renamed into:'})) .pipe(gulp.dest('app/scripts')) .pipe(gulp.dest('dist/scripts')); }); @@ -212,7 +236,7 @@ gulp.task('compilejs', () => { // sourceMaps: 'both' }; - const compiledSources = Object.values(CONSUMERS).map(consumer => `dist/scripts/${consumer}`); + const compiledSources = Object.values(CONSUMERS).map(consumer => `dist/scripts/${consumer.dist}`); return gulp.src(compiledSources) .pipe(tap(file => { const minified = babel.transform(file.contents.toString(), opts).code; @@ -229,7 +253,6 @@ gulp.task('clean', () => { ); }); - gulp.task('watch', ['browserify', 'html'], () => { livereload.listen(); diff --git a/lighthouse-extension/test/app/src/lighthouse-lr-background-test.js b/lighthouse-extension/test/app/src/lightrider-entry.js similarity index 95% rename from lighthouse-extension/test/app/src/lighthouse-lr-background-test.js rename to lighthouse-extension/test/app/src/lightrider-entry.js index 757224c31305..15a617694acb 100644 --- a/lighthouse-extension/test/app/src/lighthouse-lr-background-test.js +++ b/lighthouse-extension/test/app/src/lightrider-entry.js @@ -6,12 +6,12 @@ 'use strict'; const assert = require('assert'); -const lhBackground = require('../../../app/src/lighthouse-lr-background.js'); +const lhBackground = require('../../../app/src/lightrider-entry.js'); const LHError = require('../../../../lighthouse-core/lib/lh-error.js'); /* eslint-env mocha */ -describe('lighthouse-lr-background', () => { +describe('lightrider-entry', () => { describe('#runLighthouseInLR', () => { it('returns a runtimeError LHR when lighthouse throws a runtimeError', async () => { const connectionError = new LHError(LHError.errors.FAILED_DOCUMENT_REQUEST); diff --git a/package.json b/package.json index d4cd40f10808..156375c2ea35 100644 --- a/package.json +++ b/package.json @@ -157,7 +157,7 @@ }, "bundlesize": [ { - "path": "./lighthouse-extension/dist/scripts/lighthouse-background.js", + "path": "./lighthouse-extension/dist/scripts/lighthouse-ext-bundle.js", "threshold": "520 Kb" }, {