Skip to content

Commit

Permalink
Fix (and speed up) extension browserify post-config refactor. (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish authored and paullewis committed Jul 14, 2016
1 parent d34e5bb commit 563ae0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
4 changes: 3 additions & 1 deletion lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion lighthouse-extension/app/src/lighthouse-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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}));
});
Expand Down
43 changes: 21 additions & 22 deletions lighthouse-extension/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 563ae0c

Please sign in to comment.