Skip to content

Commit 1ddb8b1

Browse files
committed
fix audit, gatherer, artifact browserify import
1 parent ca444bf commit 1ddb8b1

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

lighthouse-core/config/config.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,15 @@ function requireAudits(audits, rootPath) {
142142
return null;
143143
}
144144
const Runner = require('../runner');
145+
const coreList = Runner.getAuditList();
145146

146147
return audits.map(audit => {
147-
// Firstly see if the audit is in Lighthouse itself.
148-
const list = Runner.getAuditList();
149-
const coreAudit = list.find(a => a === `${audit}.js`);
150-
151-
// Assume it's a core audit first.
152-
let requirePath = path.resolve(__dirname, `../audits/${audit}`);
153148
let AuditClass;
154149

150+
// Firstly see if the audit is in Lighthouse itself.
151+
const coreAudit = coreList.find(a => a === `${audit}.js`);
152+
let requirePath = `../audits/${audit}`;
153+
155154
// If not, see if it can be found another way.
156155
if (!coreAudit) {
157156
// Firstly try and see if the audit resolves naturally through the usual means.

lighthouse-core/gather/gather-runner.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,14 @@ class GatherRunner {
267267

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

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

274+
// First see if it is a core gatherer in Lighthouse itself.
275+
const coreGatherer = coreList.find(a => a === `${gatherer}.js`);
276+
let requirePath = `./gatherers/${gatherer}`;
277+
277278
// If not, see if it can be found another way.
278279
if (!coreGatherer) {
279280
// Firstly try and see if the gatherer resolves naturally through the usual means.
@@ -329,8 +330,9 @@ class GatherRunner {
329330

330331
static instantiateComputedArtifacts() {
331332
let computedArtifacts = {};
332-
var normalizedPath = require('path').join(__dirname, 'computed');
333-
require('fs').readdirSync(normalizedPath).forEach(function(file) {
333+
require('fs').readdirSync(path.join(__dirname, 'computed')).forEach(function(file) {
334+
// Drop `.js` suffix to keep browserify import happy.
335+
file = file.replace(/\.js$/, '');
334336
const ArtifactClass = require('./computed/' + file);
335337
const artifact = new ArtifactClass();
336338
// define the request* function that will be exposed on `artifacts`

lighthouse-extension/gulpfile.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const gatherers = fs.readdirSync(path.join(__dirname, '../', 'lighthouse-core/ga
2424
.filter(f => /\.js$/.test(f))
2525
.map(f => `../lighthouse-core/gather/gatherers/${f.replace(/\.js$/, '')}`);
2626

27+
const computedArtifacts = fs.readdirSync(
28+
path.join(__dirname, '../lighthouse-core/gather/computed/'))
29+
.filter(f => /\.js$/.test(f))
30+
.map(f => `../lighthouse-core/gather/computed/${f.replace(/\.js$/, '')}`);
31+
2732
gulp.task('extras', () => {
2833
return gulp.src([
2934
'app/*.*',
@@ -118,7 +123,7 @@ gulp.task('browserify', () => {
118123
.ignore('chrome-remote-interface')
119124
.ignore('source-map');
120125

121-
// Expose the audits and gatherers so they can be dynamically loaded.
126+
// Expose the audits, gatherers, and computed artifacts so they can be dynamically loaded.
122127
const corePath = '../lighthouse-core/';
123128
const driverPath = `${corePath}gather/`;
124129
audits.forEach(audit => {
@@ -127,6 +132,9 @@ gulp.task('browserify', () => {
127132
gatherers.forEach(gatherer => {
128133
bundle = bundle.require(gatherer, {expose: gatherer.replace(driverPath, './')});
129134
});
135+
computedArtifacts.forEach(artifact => {
136+
bundle = bundle.require(artifact, {expose: artifact.replace(driverPath, './')});
137+
});
130138
}
131139
// Inject the new browserified contents back into our gulp pipeline
132140
file.contents = bundle.bundle();

0 commit comments

Comments
 (0)