From 948ee098aa395c0378e7414b8df0b08bcade02ae Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Tue, 5 Nov 2019 17:50:55 -0500 Subject: [PATCH 1/9] WIP: include plugin in dt build --- build/build-bundle.js | 13 +++ clients/devtools-entry.js | 4 +- lighthouse-core/config/config-helpers.js | 4 +- package.json | 1 + yarn.lock | 125 ++++++++++++++++++++++- 5 files changed, 142 insertions(+), 5 deletions(-) diff --git a/build/build-bundle.js b/build/build-bundle.js index aa644eb7077a..6e2f84aef8ed 100644 --- a/build/build-bundle.js +++ b/build/build-bundle.js @@ -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} */ +// @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 */ @@ -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 => { @@ -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 diff --git a/clients/devtools-entry.js b/clients/devtools-entry.js index fd9e8d333f0d..395c2ccd0a74 100644 --- a/clients/devtools-entry.js +++ b/clients/devtools-entry.js @@ -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} categoryIDs * @return {LH.Config.Json} */ function getDefaultConfigForCategories(categoryIDs) { return { extends: 'lighthouse:default', + plugins: ['lighthouse-plugin-publisher-ads'], settings: { onlyCategories: categoryIDs, }, diff --git a/lighthouse-core/config/config-helpers.js b/lighthouse-core/config/config-helpers.js index fdff4420f79c..2202a0134d42 100644 --- a/lighthouse-core/config/config-helpers.js +++ b/lighthouse-core/config/config-helpers.js @@ -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)); } diff --git a/package.json b/package.json index 4523a585d918..5c4ff01b79ac 100644 --- a/package.json +++ b/package.json @@ -119,6 +119,7 @@ "isomorphic-fetch": "^2.2.1", "jest": "^24.3.0", "jsdom": "^12.2.0", + "lighthouse-plugin-publisher-ads": "^0.4.1", "npm-run-posix-or-windows": "^2.0.2", "nyc": "^13.3.0", "package-json-versionify": "^1.0.4", diff --git a/yarn.lock b/yarn.lock index 01016e45221c..c9c5ea2886da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -306,6 +306,11 @@ resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.2.tgz#54c5a964462be3d4d78af631363c18d6fa91ac26" integrity sha512-yprFYuno9FtNsSHVlSWd+nRlmGoAbqbeCwOryP6sC/zoCjhpArcRMYp19EvpSUSizJAlsXEwJv+wcWS9XaXdMw== +"@tusbar/cache-control@^0.3.1": + version "0.3.1" + resolved "https://registry.yarnpkg.com/@tusbar/cache-control/-/cache-control-0.3.1.tgz#2ee673c6a7166041b5d419f7e15cd9f16e21c8e1" + integrity sha512-qeQhWoHQqDdW+SS1TgybdOeaSo+8tZx4ZesMY0+HSLeWWa2bGDetB9wxAT/umlXuutC6QdbADd48RJ6hrYr4BQ== + "@types/archiver@^2.1.2": version "2.1.2" resolved "https://registry.yarnpkg.com/@types/archiver/-/archiver-2.1.2.tgz#e84960d4872570d7c826589cd57f2c076bf198c5" @@ -493,6 +498,13 @@ dependencies: "@types/node" "*" +"@types/intl-messageformat@^3.0.0": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@types/intl-messageformat/-/intl-messageformat-3.0.0.tgz#a405302abfa55c427cbcd374cecb12c0b90e6915" + integrity sha512-sOzBp/B4GlQZnh1ZHCJ/vVoIkhaErXHVQJnFE0P7LtEcdaIy5qCMMevXy5aOu73VWzZQ5MCv2PdOTFOpEDLQhw== + dependencies: + intl-messageformat "*" + "@types/istanbul-lib-coverage@^1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-1.1.0.tgz#2cc2ca41051498382b43157c8227fea60363f94a" @@ -860,6 +872,11 @@ ansi-regex@^4.0.0: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.0.0.tgz#70de791edf021404c3fd615aa89118ae0432e5a9" integrity sha512-iB5Dda8t/UqpPI/IjsejXu5jOGDrzn41wJyljwPH65VCIbk6+1BzFIMJGFwTNrYXT1CrD+B4l19U7awiQ8rk7w== +ansi-regex@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" + integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg== + ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" @@ -1819,6 +1836,15 @@ cliui@^4.0.0: strip-ansi "^4.0.0" wrap-ansi "^2.0.0" +cliui@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5" + integrity sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA== + dependencies: + string-width "^3.1.0" + strip-ansi "^5.2.0" + wrap-ansi "^5.1.0" + co@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" @@ -2663,6 +2689,11 @@ email-addresses@^3.0.1: resolved "https://registry.yarnpkg.com/email-addresses/-/email-addresses-3.0.2.tgz#a31280d19baf86669840a0aa45be1d7f6e7df315" integrity sha512-IMn9dnwLMsgZjdUHswB/UZ0S8LQ/u+2/qjnHJ9tCtp3QHZsIYwJCiJOo2FT0i3CwwK/dtSODYtxuvzV4D9MY5g== +emoji-regex@^7.0.1: + version "7.0.3" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" + integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA== + encoding@^0.1.11: version "0.1.12" resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb" @@ -2879,7 +2910,7 @@ esprima@^3.1.3: resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" integrity sha1-/cpRzuYTOJXjyI1TXOSdv/YqRjM= -esprima@^4.0.0: +esprima@^4.0.0, esprima@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== @@ -3339,6 +3370,11 @@ get-caller-file@^1.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5" integrity sha1-9wLmMSfn4jHBYKgMFVSstw1QR+U= +get-caller-file@^2.0.1: + version "2.0.5" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + get-pkg-repo@^1.0.0: version "1.4.0" resolved "https://registry.yarnpkg.com/get-pkg-repo/-/get-pkg-repo-1.4.0.tgz#c73b489c06d80cc5536c2c853f9e05232056972d" @@ -3889,12 +3925,30 @@ insert-module-globals@^7.0.0: undeclared-identifiers "^1.1.2" xtend "^4.0.0" +intl-format-cache@^4.2.5: + version "4.2.5" + resolved "https://registry.yarnpkg.com/intl-format-cache/-/intl-format-cache-4.2.5.tgz#6319f5707cdc766ab5c196990a6e55b0df9cc70f" + integrity sha512-xvvog/4HTVhJIg5dexcs6Ji/ROlolCgtz3std23bLEmucoGPrUVrYQPTcBWR314NM9khm4JSrdOamv9SEtvCUg== + intl-messageformat-parser@^1.8.1: version "1.8.1" resolved "https://registry.yarnpkg.com/intl-messageformat-parser/-/intl-messageformat-parser-1.8.1.tgz#0eb14c5618333be4c95c409457b66c8c33ddcc01" integrity sha512-IMSCKVf0USrM/959vj3xac7s8f87sc+80Y/ipBzdKy4ifBv5Gsj2tZ41EAaURVg01QU71fYr77uA8Meh6kELbg== -intl-messageformat@^4.4.0: +intl-messageformat-parser@^3.2.2: + version "3.2.2" + resolved "https://registry.yarnpkg.com/intl-messageformat-parser/-/intl-messageformat-parser-3.2.2.tgz#28cacc80a53823a28b5ecaf16b3b35d0a1d5f9d2" + integrity sha512-ax9639ST77YimAddTH/0Q9qhXuYS8ZVsoqOZinqnS90MbXaNuIq+KIdifaIndwI+lMEv3o+qNaGycXYvlh17rw== + +intl-messageformat@*: + version "7.5.0" + resolved "https://registry.yarnpkg.com/intl-messageformat/-/intl-messageformat-7.5.0.tgz#53582b6e911d4f41434e9d897b4789d2a2b2ff8e" + integrity sha512-s08OFUbRVUPTiXS8OOP06OhfehM1K4ughymhOazY4OhQMO+RiY4bnmsqRgYe7XorETg7mZnwJX1M34sJrzKoOA== + dependencies: + intl-format-cache "^4.2.5" + intl-messageformat-parser "^3.2.2" + +intl-messageformat@^4.1.2, intl-messageformat@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/intl-messageformat/-/intl-messageformat-4.4.0.tgz#aa196a4d04b573f4090bc417f982d81de4f74fad" integrity sha512-z+Bj2rS3LZSYU4+sNitdHrwnBhr0wO80ZJSW8EzKDBowwUe3Q/UsvgCGjrwa+HPzoGCLEb9HAjfJgo4j2Sac8w== @@ -4976,6 +5030,17 @@ lighthouse-logger@^1.0.0, lighthouse-logger@^1.2.0: debug "^2.6.8" marky "^1.2.0" +lighthouse-plugin-publisher-ads@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/lighthouse-plugin-publisher-ads/-/lighthouse-plugin-publisher-ads-0.4.1.tgz#745aa00d691d329fcf3ed58ec5ef1e4cd0798e71" + integrity sha512-ksq9VMoHS3oH4naCGm6x0oCHnm7uMvAxcQpB57wZbJUQpPNmfeXRXwKuTyAei+TyO4HzVMkhCzuYzvVRcXpYdQ== + dependencies: + "@tusbar/cache-control" "^0.3.1" + "@types/intl-messageformat" "^3.0.0" + esprima "^4.0.1" + intl-messageformat "^4.1.2" + yargs "^13.3.0" + load-json-file@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0" @@ -6475,6 +6540,11 @@ require-main-filename@^1.0.1: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE= +require-main-filename@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" + integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== + require-uncached@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3" @@ -7054,6 +7124,15 @@ string-width@^1.0.1: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" +string-width@^3.0.0, string-width@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" + integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w== + dependencies: + emoji-regex "^7.0.1" + is-fullwidth-code-point "^2.0.0" + strip-ansi "^5.1.0" + string_decoder@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.2.0.tgz#fe86e738b19544afe70469243b2a1ee9240eae8d" @@ -7089,6 +7168,13 @@ strip-ansi@^5.0.0: dependencies: ansi-regex "^4.0.0" +strip-ansi@^5.1.0, strip-ansi@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" + integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA== + dependencies: + ansi-regex "^4.1.0" + strip-bom@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-1.0.0.tgz#85b8862f3844b5a6d5ec8467a93598173a36f794" @@ -7795,6 +7881,15 @@ wrap-ansi@^2.0.0: dependencies: string-width "^1.0.1" +wrap-ansi@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-5.1.0.tgz#1fd1f67235d5b6d0fee781056001bfb694c03b09" + integrity sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q== + dependencies: + ansi-styles "^3.2.0" + string-width "^3.0.0" + strip-ansi "^5.0.0" + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" @@ -7879,7 +7974,7 @@ y18n@^3.2.0: resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" integrity sha1-bRX7qITAhnnA136I53WegR4H+kE= -"y18n@^3.2.1 || ^4.0.0": +"y18n@^3.2.1 || ^4.0.0", y18n@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w== @@ -7904,6 +7999,14 @@ yargs-parser@^11.1.1: camelcase "^5.0.0" decamelize "^1.2.0" +yargs-parser@^13.1.1: + version "13.1.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.1.tgz#d26058532aa06d365fe091f6a1fc06b2f7e5eca0" + integrity sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs@3.32.0: version "3.32.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.32.0.tgz#03088e9ebf9e756b69751611d2a5ef591482c995" @@ -7935,6 +8038,22 @@ yargs@^12.0.2, yargs@^12.0.5: y18n "^3.2.1 || ^4.0.0" yargs-parser "^11.1.1" +yargs@^13.3.0: + version "13.3.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.0.tgz#4c657a55e07e5f2cf947f8a366567c04a0dedc83" + integrity sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA== + dependencies: + cliui "^5.0.0" + find-up "^3.0.0" + get-caller-file "^2.0.1" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^3.0.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^13.1.1" + yauzl@2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.4.1.tgz#9528f442dab1b2284e58b4379bb194e22e0c4005" From 082715ba30c36e4f9394def4a82b3a6fbd524430 Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Wed, 6 Nov 2019 18:41:52 -0500 Subject: [PATCH 2/9] feedback --- build/build-bundle.js | 2 +- clients/devtools-entry.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/build-bundle.js b/build/build-bundle.js index 6e2f84aef8ed..1b93a8449560 100644 --- a/build/build-bundle.js +++ b/build/build-bundle.js @@ -88,7 +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). + // 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 => { diff --git a/clients/devtools-entry.js b/clients/devtools-entry.js index 395c2ccd0a74..1b352b58fa42 100644 --- a/clients/devtools-entry.js +++ b/clients/devtools-entry.js @@ -14,8 +14,8 @@ const {registerLocaleData, lookupLocale} = require('../lighthouse-core/lib/i18n/ /** * Return a version of the default config, filtered to only run the specified - * categories. Exclude `lighthouse-plugin-publisher-ads` to not include the - * plugin in the run. + * categories. If `lighthouse-plugin-publisher-ads` is in the list of + * `categoryIDs` the plugin will also be run. * @param {Array} categoryIDs * @return {LH.Config.Json} */ From 55839fd3b7bbaf6233b422a1d5ebf72d77e8b955 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 8 Nov 2019 19:49:07 -0800 Subject: [PATCH 3/9] bundling pubads for devtools (#9936) --- build/build-bundle.js | 3 ++- clients/devtools-entry.js | 1 + lighthouse-core/config/config-helpers.js | 12 ++++++++---- lighthouse-core/config/config.js | 4 +++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/build/build-bundle.js b/build/build-bundle.js index 1b93a8449560..aa7adf30bacd 100644 --- a/build/build-bundle.js +++ b/build/build-bundle.js @@ -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); }); } diff --git a/clients/devtools-entry.js b/clients/devtools-entry.js index 1b352b58fa42..fb81db05cee3 100644 --- a/clients/devtools-entry.js +++ b/clients/devtools-entry.js @@ -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); diff --git a/lighthouse-core/config/config-helpers.js b/lighthouse-core/config/config-helpers.js index 2202a0134d42..b716ebfb2ab5 100644 --- a/lighthouse-core/config/config-helpers.js +++ b/lighthouse-core/config/config-helpers.js @@ -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)); } diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index da29854e59a3..ce1b0c4af3eb 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -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); From b6f347a9fcc9c4e0341d7ee31f8461c093e4a588 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 8 Nov 2019 19:59:09 -0800 Subject: [PATCH 4/9] prepare to land --- build/build-bundle.js | 1 + clients/devtools-entry.js | 3 ++- lighthouse-core/config/config-helpers.js | 3 ++- lighthouse-core/config/config.js | 3 ++- types/node.d.ts | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build/build-bundle.js b/build/build-bundle.js index aa7adf30bacd..3b882f60f792 100644 --- a/build/build-bundle.js +++ b/build/build-bundle.js @@ -99,6 +99,7 @@ async function browserifyFile(entryPath, distPath) { }); // HACK: manually include the lighthouse-plugin-publisher-ads audits. + // TODO: there should be a test for this. if (isDevtools(entryPath)) { bundle.require('lighthouse-plugin-publisher-ads'); pubAdsAudits.forEach(pubAdAudit => { diff --git a/clients/devtools-entry.js b/clients/devtools-entry.js index fb81db05cee3..33ad726a1193 100644 --- a/clients/devtools-entry.js +++ b/clients/devtools-entry.js @@ -40,7 +40,8 @@ function runLighthouseInWorker(port, url, flags, categoryIDs) { // Default to 'info' logging level. flags.logLevel = flags.logLevel || 'info'; flags.channel = 'devtools'; - global.devtools = true; + // TODO: refactor and delete `global.isDevtools`. + global.isDevtools = true; const config = getDefaultConfigForCategories(categoryIDs); const connection = new RawProtocol(port); diff --git a/lighthouse-core/config/config-helpers.js b/lighthouse-core/config/config-helpers.js index b716ebfb2ab5..60d9e7fa41bb 100644 --- a/lighthouse-core/config/config-helpers.js +++ b/lighthouse-core/config/config-helpers.js @@ -138,7 +138,8 @@ function requireAudits(audits, configDir) { const coreAudit = coreList.find(a => a === auditPathJs); let requirePath = `../audits/${audit.path}`; if (!coreAudit) { - if (global.devtools) { + // TODO: refactor and delete `global.isDevtools`. + if (global.isDevtools) { requirePath = audit.path; } else { // Otherwise, attempt to find it elsewhere. This throws if not found. diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index ce1b0c4af3eb..07a89482b5a3 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -431,7 +431,8 @@ class Config { for (const pluginName of pluginNames) { assertValidPluginName(configJSON, pluginName); - const pluginPath = global.devtools ? + // TODO: refactor and delete `global.isDevtools`. + const pluginPath = global.isDevtools ? pluginName : resolveModule(pluginName, configDir, 'plugin'); const rawPluginJson = require(pluginPath); diff --git a/types/node.d.ts b/types/node.d.ts index fc365d6e5b01..834d2caafd8a 100644 --- a/types/node.d.ts +++ b/types/node.d.ts @@ -6,6 +6,7 @@ declare module NodeJS { interface Global { + isDevtools?: boolean; isLightrider?: boolean; } } From 85dbdfd966c0fca5dbbbb597483225e4aca962d4 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 8 Nov 2019 19:59:49 -0800 Subject: [PATCH 5/9] comment --- lighthouse-core/config/config-helpers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lighthouse-core/config/config-helpers.js b/lighthouse-core/config/config-helpers.js index 60d9e7fa41bb..a136a38b14a3 100644 --- a/lighthouse-core/config/config-helpers.js +++ b/lighthouse-core/config/config-helpers.js @@ -140,6 +140,7 @@ function requireAudits(audits, configDir) { if (!coreAudit) { // TODO: refactor and delete `global.isDevtools`. if (global.isDevtools) { + // This is for pubads bundling. requirePath = audit.path; } else { // Otherwise, attempt to find it elsewhere. This throws if not found. From e2fa7298d7ab95c4c00a1c4dc59e1565257ec554 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 8 Nov 2019 21:38:47 -0800 Subject: [PATCH 6/9] link --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c4ff01b79ac..5c99090c6eab 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build-all:task": "yarn build-extension & yarn build-devtools & yarn build-lr & yarn build-viewer & wait", "build-all:task:windows": "yarn build-extension && yarn build-devtools && yarn build-lr && yarn build-viewer", "build-extension": "node ./build/build-extension.js", - "build-devtools": "node ./build/build-bundle.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js && node ./build/build-dt-report-resources.js", + "build-devtools": "yarn link && yarn link lighthouse && node ./build/build-bundle.js clients/devtools-entry.js dist/lighthouse-dt-bundle.js && node ./build/build-dt-report-resources.js", "build-lr": "node ./build/build-lightrider-bundles.js", "build-viewer": "node ./build/build-viewer.js", "clean": "rimraf dist proto/scripts/*.json proto/scripts/*_pb2.* proto/scripts/*_pb.* proto/scripts/__pycache__ proto/scripts/*.pyc *.report.html *.report.dom.html *.report.json *.devtoolslog.json *.trace.json lighthouse-core/lib/i18n/locales/*.ctc.json || true", From fc482d1aa0d1cc1689fc14fb356a11d983ddc903 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Fri, 8 Nov 2019 22:49:31 -0800 Subject: [PATCH 7/9] bundlesize --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5c99090c6eab..087e51bf050d 100644 --- a/package.json +++ b/package.json @@ -188,7 +188,7 @@ }, { "path": "./dist/lighthouse-dt-bundle.js", - "maxSize": "400 kB" + "maxSize": "410 kB" }, { "path": "./dist/lightrider/report-generator-bundle.js", From f24f424927682a2794528db920854c6fc68e479b Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 27 Jan 2020 10:35:43 -0800 Subject: [PATCH 8/9] rm tsignore --- clients/devtools-entry.js | 1 - 1 file changed, 1 deletion(-) diff --git a/clients/devtools-entry.js b/clients/devtools-entry.js index d468d904d2f3..5b036b044a21 100644 --- a/clients/devtools-entry.js +++ b/clients/devtools-entry.js @@ -56,7 +56,6 @@ if (typeof module !== 'undefined' && module.exports) { // @ts-ignore if (typeof self !== 'undefined') { // TODO: refactor and delete `global.isDevtools`. - // @ts-ignore global.isDevtools = true; // @ts-ignore From 972191f11e66373d37e6415387239744b78a2884 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Mon, 27 Jan 2020 18:47:49 -0800 Subject: [PATCH 9/9] bundlesize bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 16f0e7e73bf4..8c597a10c749 100644 --- a/package.json +++ b/package.json @@ -190,7 +190,7 @@ }, { "path": "./dist/lighthouse-dt-bundle.js", - "maxSize": "410 kB" + "maxSize": "415 kB" }, { "path": "./dist/lightrider/report-generator-bundle.js",