Skip to content

Commit

Permalink
fix audit, gatherer, artifact browserify import
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Aug 26, 2016
1 parent ca444bf commit 1ddb8b1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
11 changes: 5 additions & 6 deletions lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,15 @@ function requireAudits(audits, rootPath) {
return null;
}
const Runner = require('../runner');
const coreList = Runner.getAuditList();

return audits.map(audit => {
// Firstly see if the audit is in Lighthouse itself.
const list = Runner.getAuditList();
const coreAudit = list.find(a => a === `${audit}.js`);

// Assume it's a core audit first.
let requirePath = path.resolve(__dirname, `../audits/${audit}`);
let AuditClass;

// Firstly see if the audit is in Lighthouse itself.
const coreAudit = coreList.find(a => a === `${audit}.js`);
let requirePath = `../audits/${audit}`;

// If not, see if it can be found another way.
if (!coreAudit) {
// Firstly try and see if the audit resolves naturally through the usual means.
Expand Down
14 changes: 8 additions & 6 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,14 @@ class GatherRunner {

static getGathererClass(gatherer, rootPath) {
const Runner = require('../runner');
const list = Runner.getGathererList();
const coreGatherer = list.find(a => a === `${gatherer}.js`);
const coreList = Runner.getGathererList();

// Assume it's a core gatherer first.
let requirePath = path.resolve(__dirname, `./gatherers/${gatherer}`);
let GathererClass;

// First see if it is a core gatherer in Lighthouse itself.
const coreGatherer = coreList.find(a => a === `${gatherer}.js`);
let requirePath = `./gatherers/${gatherer}`;

// If not, see if it can be found another way.
if (!coreGatherer) {
// Firstly try and see if the gatherer resolves naturally through the usual means.
Expand Down Expand Up @@ -329,8 +330,9 @@ class GatherRunner {

static instantiateComputedArtifacts() {
let computedArtifacts = {};
var normalizedPath = require('path').join(__dirname, 'computed');
require('fs').readdirSync(normalizedPath).forEach(function(file) {
require('fs').readdirSync(path.join(__dirname, 'computed')).forEach(function(file) {
// Drop `.js` suffix to keep browserify import happy.
file = file.replace(/\.js$/, '');
const ArtifactClass = require('./computed/' + file);
const artifact = new ArtifactClass();
// define the request* function that will be exposed on `artifacts`
Expand Down
10 changes: 9 additions & 1 deletion lighthouse-extension/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const gatherers = fs.readdirSync(path.join(__dirname, '../', 'lighthouse-core/ga
.filter(f => /\.js$/.test(f))
.map(f => `../lighthouse-core/gather/gatherers/${f.replace(/\.js$/, '')}`);

const computedArtifacts = fs.readdirSync(
path.join(__dirname, '../lighthouse-core/gather/computed/'))
.filter(f => /\.js$/.test(f))
.map(f => `../lighthouse-core/gather/computed/${f.replace(/\.js$/, '')}`);

gulp.task('extras', () => {
return gulp.src([
'app/*.*',
Expand Down Expand Up @@ -118,7 +123,7 @@ gulp.task('browserify', () => {
.ignore('chrome-remote-interface')
.ignore('source-map');

// Expose the audits and gatherers so they can be dynamically loaded.
// Expose the audits, gatherers, and computed artifacts so they can be dynamically loaded.
const corePath = '../lighthouse-core/';
const driverPath = `${corePath}gather/`;
audits.forEach(audit => {
Expand All @@ -127,6 +132,9 @@ gulp.task('browserify', () => {
gatherers.forEach(gatherer => {
bundle = bundle.require(gatherer, {expose: gatherer.replace(driverPath, './')});
});
computedArtifacts.forEach(artifact => {
bundle = bundle.require(artifact, {expose: artifact.replace(driverPath, './')});
});
}
// Inject the new browserified contents back into our gulp pipeline
file.contents = bundle.bundle();
Expand Down

0 comments on commit 1ddb8b1

Please sign in to comment.