From f504b12a8c4068e20f0d4da642d1f2423cb3a72c Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Thu, 7 Jul 2016 21:56:10 -0700 Subject: [PATCH] Fix (and speed up) extension browserify post-config refactor. --- lighthouse-core/runner.js | 4 +- .../app/src/lighthouse-background.js | 6 ++- lighthouse-extension/gulpfile.js | 43 +++++++++---------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/lighthouse-core/runner.js b/lighthouse-core/runner.js index ac233d966df1..75991aee0a30 100644 --- a/lighthouse-core/runner.js +++ b/lighthouse-core/runner.js @@ -63,7 +63,9 @@ class Runner { } // Now run the audits. - run = run.then(artifacts => Promise.all(config.audits.map(audit => audit.audit(artifacts)))); + run = run.then(artifacts => Promise.all(config.audits.map(audit => { + return audit.audit(artifacts); + }))); } else if (config.auditResults) { // If there are existing audit results, surface those here. run = run.then(_ => config.auditResults); diff --git a/lighthouse-extension/app/src/lighthouse-background.js b/lighthouse-extension/app/src/lighthouse-background.js index 9d0e14232207..080f72a5dc1c 100644 --- a/lighthouse-extension/app/src/lighthouse-background.js +++ b/lighthouse-extension/app/src/lighthouse-background.js @@ -19,7 +19,8 @@ const ExtensionProtocol = require('../../../lighthouse-core/driver/drivers/extension'); const Runner = require('../../../lighthouse-core/runner'); -const config = require('../../../lighthouse-core/config/default.json'); +const Config = require('../../../lighthouse-core/config'); +const configJSON = require('../../../lighthouse-core/config/default.json'); const log = require('../../../lighthouse-core/lib/log'); window.createPageAndPopulate = function(results) { @@ -44,6 +45,9 @@ window.runAudits = function(options) { return driver.getCurrentTabURL() .then(url => { + // Setup the run config, false == no whitelist, run all audits + const config = new Config(configJSON, false); + // Add in the URL to the options. return Runner.run(driver, Object.assign({}, options, {url, config})); }); diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index 7bc5487087a1..e20a7e33a112 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -97,37 +97,36 @@ gulp.task('browserify', () => { 'app/src/report-loader.js' ], {read: false}) .pipe(tap(file => { - let bundle = browserify(file.path) - + let bundle = browserify(file.path, {debug: true}) // Fix an issue with Babelified code that doesn't brfs well. .transform('./fs-transform', { global: true }) - // Transform the fs.readFile etc, but do so in all the modules. .transform('brfs', { global: true - }) - - // Do the additional transform to convert references to devtools-timeline-model - // to the modified version internal to Lighthouse. - .transform('./dtm-transform.js', { - global: true - }) - .ignore('chrome-remote-interface'); - - const corePath = /\.\.\/lighthouse-core\//; - const driverPath = /\.\.\/lighthouse-core\/driver\//; - - // Expose the audits and gatherers so they can be dynamically loaded. - audits.forEach(audit => { - bundle = bundle.require(audit, {expose: audit.replace(corePath, './')}); - }); - - gatherers.forEach(gatherer => { - bundle = bundle.require(gatherer, {expose: gatherer.replace(driverPath, './')}); }); + // In the case of our lighthouse-core script, we've got extra work to do + if (file.path.includes('app/src/lighthouse-background.js')){ + // Do the additional transform to convert references to devtools-timeline-model + // to the modified version internal to Lighthouse. + bundle.transform('./dtm-transform.js', { + global: true + }) + .ignore('chrome-remote-interface'); + + // Expose the audits and gatherers so they can be dynamically loaded. + const corePath = "../lighthouse-core/"; + const driverPath = `${corePath}driver/`; + audits.forEach(audit => { + bundle = bundle.require(audit, {expose: audit.replace(corePath, '../')}); + }); + gatherers.forEach(gatherer => { + bundle = bundle.require(gatherer, {expose: gatherer.replace(driverPath, './')}); + }); + } + // Inject the new browserified contents back into our gulp pipeline file.contents = bundle.bundle(); })) .pipe(gulp.dest('app/scripts'))