Skip to content

Commit

Permalink
WIP: include plugin in dt build
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Nov 5, 2019
1 parent 5f2b73e commit b7fee07
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 6 deletions.
13 changes: 13 additions & 0 deletions build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const gatherers = LighthouseRunner.getGathererList()
const locales = fs.readdirSync(__dirname + '/../lighthouse-core/lib/i18n/locales/')
.map(f => require.resolve(`../lighthouse-core/lib/i18n/locales/${f}`));

// HACK: manually include the lighthouse-plugin-publisher-ads audits.
/** @type {Array<string>} */
// @ts-ignore
const pubAdsAudits = require('lighthouse-plugin-publisher-ads/plugin.js').audits.map(a => a.path);

/** @param {string} file */
const isDevtools = file => path.basename(file).includes('devtools');
/** @param {string} file */
Expand Down Expand Up @@ -83,6 +88,7 @@ async function browserifyFile(entryPath, distPath) {
}

// Expose the audits, gatherers, and computed artifacts so they can be dynamically loaded.
// Exposed path relative to lighthouse-core/config/config-helpers.js (where loading occurs).
const corePath = './lighthouse-core/';
const driverPath = `${corePath}gather/`;
audits.forEach(audit => {
Expand All @@ -92,6 +98,13 @@ async function browserifyFile(entryPath, distPath) {
bundle = bundle.require(gatherer, {expose: gatherer.replace(driverPath, '../gather/')});
});

// HACK: manually include the lighthouse-plugin-publisher-ads audits.
if (isDevtools(entryPath)) {
pubAdsAudits.forEach(pubAdAudit => {
bundle = bundle.require(pubAdAudit, {expose: '../../node_modules/' + pubAdAudit});
});
}

// browerify's url shim doesn't work with .URL in node_modules,
// and within robots-parser, it does `var URL = require('url').URL`, so we expose our own.
// @see https://github.com/GoogleChrome/lighthouse/issues/5273
Expand Down
4 changes: 3 additions & 1 deletion clients/devtools-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const {registerLocaleData, lookupLocale} = require('../lighthouse-core/lib/i18n/

/**
* Return a version of the default config, filtered to only run the specified
* categories.
* categories. Exclude `lighthouse-plugin-publisher-ads` to not include the
* plugin in the run.
* @param {Array<string>} categoryIDs
* @return {LH.Config.Json}
*/
function getDefaultConfigForCategories(categoryIDs) {
return {
extends: 'lighthouse:default',
plugins: ['lighthouse-plugin-publisher-ads'],
settings: {
onlyCategories: categoryIDs,
},
Expand Down
4 changes: 3 additions & 1 deletion lighthouse-core/config/config-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ function requireAudits(audits, configDir) {
let requirePath = `../audits/${audit.path}`;
if (!coreAudit) {
// Otherwise, attempt to find it elsewhere. This throws if not found.
requirePath = resolveModule(audit.path, configDir, 'audit');
const absolutePath = resolveModule(audit.path, configDir, 'audit');
// Use a relative path so bundler can easily expose it.
requirePath = path.relative(__dirname, absolutePath);
}
implementation = /** @type {typeof Audit} */ (require(requirePath));
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
"isomorphic-fetch": "^2.2.1",
"jest": "^24.3.0",
"jsdom": "^12.2.0",
"lighthouse-plugin-publisher-ads": "./node_modules/lighthouse-plugin-publisher-ads-wrapper/lighthouse-plugin-publisher-ads/",
"lighthouse-plugin-publisher-ads-wrapper": "https://github.com/googleads/publisher-ads-lighthouse-plugin",
"npm-run-posix-or-windows": "^2.0.2",
"nyc": "^13.3.0",
"package-json-versionify": "^1.0.4",
Expand Down
Loading

0 comments on commit b7fee07

Please sign in to comment.