-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
misc(build): bundle pub ads plugin for devtools #9924
Changes from 9 commits
948ee09
082715b
55839fd
b6f347a
85dbdfd
e2fa729
fc482d1
4e47886
f24f424
972191f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
|
@@ -84,6 +89,7 @@ async function browserifyFile(entryPath, distPath) { | |
} | ||
|
||
// Expose the audits, gatherers, and computed artifacts so they can be dynamically loaded. | ||
// Exposed path must be a relative path from lighthouse-core/config/config-helpers.js (where loading occurs). | ||
const corePath = './lighthouse-core/'; | ||
const driverPath = `${corePath}gather/`; | ||
audits.forEach(audit => { | ||
|
@@ -93,6 +99,15 @@ async function browserifyFile(entryPath, distPath) { | |
bundle = bundle.require(gatherer, {expose: gatherer.replace(driverPath, '../gather/')}); | ||
}); | ||
|
||
// HACK: manually include the lighthouse-plugin-publisher-ads audits. | ||
// TODO: there should be a test for this. | ||
if (isDevtools(entryPath)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kinda feels like we should resolve those functions to booleans called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah, I had a similar thought. Not sure why they're like that...I assume it made sense as a one-off and we've just c/p it multiple times now |
||
bundle.require('lighthouse-plugin-publisher-ads'); | ||
pubAdsAudits.forEach(pubAdAudit => { | ||
bundle = bundle.require(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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
declare module NodeJS { | ||
interface Global { | ||
isDevtools?: boolean; | ||
isLightrider?: boolean; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or whatever is a good way to get this list...readdir doesn't work cause there's more than just the audits in that directory