diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index fe521f48d66b..bc8c857ce05a 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -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. diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index 3791c6a04f68..9bb647100e60 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -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. @@ -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` diff --git a/lighthouse-extension/gulpfile.js b/lighthouse-extension/gulpfile.js index 4bd5437d7d47..6a4aeec41858 100644 --- a/lighthouse-extension/gulpfile.js +++ b/lighthouse-extension/gulpfile.js @@ -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/*.*', @@ -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 => { @@ -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();