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

Fix (and speed up) extension browserify post-config refactor. #499

Merged
merged 1 commit into from
Jul 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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