Skip to content

Commit

Permalink
bundling for devtools
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Nov 7, 2019
1 parent 082715b commit 1a053c4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ async function browserifyFile(entryPath, distPath) {

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

Expand Down
1 change: 1 addition & 0 deletions clients/devtools-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function runLighthouseInWorker(port, url, flags, categoryIDs) {
// Default to 'info' logging level.
flags.logLevel = flags.logLevel || 'info';
flags.channel = 'devtools';
global.devtools = true;
const config = getDefaultConfigForCategories(categoryIDs);
const connection = new RawProtocol(port);

Expand Down
12 changes: 8 additions & 4 deletions lighthouse-core/config/config-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@ function requireAudits(audits, configDir) {
const coreAudit = coreList.find(a => a === auditPathJs);
let requirePath = `../audits/${audit.path}`;
if (!coreAudit) {
// Otherwise, attempt to find it elsewhere. This throws if not found.
const absolutePath = resolveModule(audit.path, configDir, 'audit');
// Use a relative path so bundler can easily expose it.
requirePath = path.relative(__dirname, absolutePath);
if (global.devtools) {
requirePath = audit.path;
} else {
// Otherwise, attempt to find it elsewhere. This throws if not found.
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
4 changes: 3 additions & 1 deletion lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ class Config {
for (const pluginName of pluginNames) {
assertValidPluginName(configJSON, pluginName);

const pluginPath = resolveModule(pluginName, configDir, 'plugin');
const pluginPath = global.devtools ?
pluginName :
resolveModule(pluginName, configDir, 'plugin');
const rawPluginJson = require(pluginPath);
const pluginJson = ConfigPlugin.parsePlugin(rawPluginJson, pluginName);

Expand Down

0 comments on commit 1a053c4

Please sign in to comment.